lrussell

Full World Format

Mar 23rd, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.05 KB | None | 0 0
  1. class WorldFormat
  2.     {
  3.         public class WorldInfo
  4.         {
  5.             public string Id { get; set; }
  6.             public string Name { get; set; }
  7.             public string Owner { get; set; }
  8.             public int Plays { get; set; }
  9.             public int Width { get; set; }
  10.             public int Height { get; set; }
  11.             public int Woots { get; set; }
  12.             public int TotalWoots { get; set; }
  13.             public bool AllowPotions { get; set; }
  14.             public bool Visible { get; set; }
  15.             public Color BackgroundColor { get; set; }
  16.             public List<WorldData> WorldData { get; set; }
  17.  
  18.             public WorldInfo()
  19.             {
  20.                 Name = "Untitled World";
  21.                 Width = 200;
  22.                 Height = 200;
  23.                 AllowPotions = true;
  24.                 Visible = true;
  25.                 WorldData = new List<WorldData>();
  26.             }
  27.         }
  28.  
  29.         public class WorldData
  30.         {
  31.             public uint Type { get; set; }
  32.             public int Layer { get; set; }
  33.             public uint Rotation { get; set; }
  34.             public uint Id { get; set; }
  35.             public uint Goal { get; set; }
  36.             public object Target { get; set; }
  37.             public string Text { get; set; }
  38.             public Color TextColor { get; set; }
  39.             public List<Point> Locations { get; set; }
  40.  
  41.             public WorldData()
  42.             {
  43.                 Locations = new List<Point>();
  44.             }
  45.         }
  46.  
  47.         public static WorldInfo ConvertWorld(DatabaseObject worldObject)
  48.         {
  49.             WorldInfo world = new WorldInfo();
  50.             world.Id = worldObject.Key;
  51.  
  52.             foreach (KeyValuePair<string, object> worldEntry in worldObject)
  53.             {
  54.                 switch (worldEntry.Key)
  55.                 {
  56.                     case "name":
  57.                         world.Name = Convert.ToString(worldEntry.Value);
  58.                         break;
  59.                     case "owner":
  60.                         world.Owner = Convert.ToString(worldEntry.Value);
  61.                         break;
  62.                     case "plays":
  63.                         world.Plays = Convert.ToInt32(worldEntry.Value);
  64.                         break;
  65.                     case "width":
  66.                         world.Width = Convert.ToInt32(worldEntry.Value);
  67.                         break;
  68.                     case "height":
  69.                         world.Height = Convert.ToInt32(worldEntry.Value);
  70.                         break;
  71.                     case "woots":
  72.                         world.Woots = Convert.ToInt32(worldEntry.Value);
  73.                         break;
  74.                     case "totalwoots":
  75.                         world.TotalWoots = Convert.ToInt32(worldEntry.Value);
  76.                         break;
  77.                     case "allowpotions":
  78.                         world.AllowPotions = Convert.ToBoolean(worldEntry.Value);
  79.                         break;
  80.                     case "visible":
  81.                         world.Visible = Convert.ToBoolean(worldEntry.Value);
  82.                         break;
  83.                     case "backgroundColor":
  84.                         uint color = Convert.ToUInt32(worldEntry.Value);
  85.                         world.BackgroundColor = (color == 0) ? default(Color) : ImageFunctions.UIntToColor(color);
  86.                         break;
  87.                     case "worlddata":
  88.                         {
  89.                             foreach (DatabaseObject dataObject in (DatabaseArray)worldEntry.Value)
  90.                             {
  91.                                 if (dataObject != null)
  92.                                 {
  93.                                     WorldData worldData = new WorldData();
  94.                                     byte[] xByte = null, yByte = null;
  95.  
  96.                                     foreach (KeyValuePair<string, object> dataEntry in dataObject)
  97.                                     {
  98.                                         switch (dataEntry.Key)
  99.                                         {
  100.                                             case "type":
  101.                                                 worldData.Type = Convert.ToUInt32(dataEntry.Value);
  102.                                                 break;
  103.                                             case "layer":
  104.                                                 worldData.Layer = Convert.ToInt32(dataEntry.Value);
  105.                                                 break;
  106.                                             case "rotation":
  107.                                                 worldData.Rotation = Convert.ToUInt32(dataEntry.Value);
  108.                                                 break;
  109.                                             case "id":
  110.                                                 worldData.Id = Convert.ToUInt32(dataEntry.Value);
  111.                                                 break;
  112.                                             case "target":
  113.                                                 worldData.Target = dataEntry.Value;
  114.                                                 break;
  115.                                             case "goal":
  116.                                                 worldData.Goal = Convert.ToUInt32(dataEntry.Value);
  117.                                                 break;
  118.                                             case "text":
  119.                                                 worldData.Text = Convert.ToString(dataEntry.Value);
  120.                                                 break;
  121.                                             case "text_color":
  122.                                                 worldData.TextColor = Utilities.ImageFunctions.HexToColor(Convert.ToString(dataEntry.Value));
  123.                                                 break;
  124.                                             case "x":
  125.                                                 xByte = (byte[])dataEntry.Value;
  126.                                                 break;
  127.                                             case "y":
  128.                                                 yByte = (byte[])dataEntry.Value;
  129.                                                 break;
  130.                                         }
  131.                                     }
  132.  
  133.                                     if (xByte != null && yByte != null)
  134.                                     {
  135.                                         for (int p = 0; p < Math.Min(xByte.Length, yByte.Length); p += 2)
  136.                                         {
  137.                                             worldData.Locations.Add(new Point(
  138.                                                     xByte[p] << 8 | xByte[p + 1],
  139.                                                     yByte[p] << 8 | yByte[p + 1]));
  140.                                         }
  141.                                     }
  142.  
  143.                                     world.WorldData.Add(worldData);
  144.                                 }
  145.                             }
  146.                         }
  147.                         break;
  148.                 }
  149.             }
  150.  
  151.             return world;
  152.         }
  153.     }
Advertisement
Add Comment
Please, Sign In to add comment