Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class WorldFormat
- {
- public class WorldInfo
- {
- public string Id { get; set; }
- public string Name { get; set; }
- public string Owner { get; set; }
- public int Plays { get; set; }
- public int Width { get; set; }
- public int Height { get; set; }
- public int Woots { get; set; }
- public int TotalWoots { get; set; }
- public bool AllowPotions { get; set; }
- public bool Visible { get; set; }
- public Color BackgroundColor { get; set; }
- public List<WorldData> WorldData { get; set; }
- public WorldInfo()
- {
- Name = "Untitled World";
- Width = 200;
- Height = 200;
- AllowPotions = true;
- Visible = true;
- WorldData = new List<WorldData>();
- }
- }
- public class WorldData
- {
- public uint Type { get; set; }
- public int Layer { get; set; }
- public uint Rotation { get; set; }
- public uint Id { get; set; }
- public uint Goal { get; set; }
- public object Target { get; set; }
- public string Text { get; set; }
- public Color TextColor { get; set; }
- public List<Point> Locations { get; set; }
- public WorldData()
- {
- Locations = new List<Point>();
- }
- }
- public static WorldInfo ConvertWorld(DatabaseObject worldObject)
- {
- WorldInfo world = new WorldInfo();
- world.Id = worldObject.Key;
- foreach (KeyValuePair<string, object> worldEntry in worldObject)
- {
- switch (worldEntry.Key)
- {
- case "name":
- world.Name = Convert.ToString(worldEntry.Value);
- break;
- case "owner":
- world.Owner = Convert.ToString(worldEntry.Value);
- break;
- case "plays":
- world.Plays = Convert.ToInt32(worldEntry.Value);
- break;
- case "width":
- world.Width = Convert.ToInt32(worldEntry.Value);
- break;
- case "height":
- world.Height = Convert.ToInt32(worldEntry.Value);
- break;
- case "woots":
- world.Woots = Convert.ToInt32(worldEntry.Value);
- break;
- case "totalwoots":
- world.TotalWoots = Convert.ToInt32(worldEntry.Value);
- break;
- case "allowpotions":
- world.AllowPotions = Convert.ToBoolean(worldEntry.Value);
- break;
- case "visible":
- world.Visible = Convert.ToBoolean(worldEntry.Value);
- break;
- case "backgroundColor":
- uint color = Convert.ToUInt32(worldEntry.Value);
- world.BackgroundColor = (color == 0) ? default(Color) : ImageFunctions.UIntToColor(color);
- break;
- case "worlddata":
- {
- foreach (DatabaseObject dataObject in (DatabaseArray)worldEntry.Value)
- {
- if (dataObject != null)
- {
- WorldData worldData = new WorldData();
- byte[] xByte = null, yByte = null;
- foreach (KeyValuePair<string, object> dataEntry in dataObject)
- {
- switch (dataEntry.Key)
- {
- case "type":
- worldData.Type = Convert.ToUInt32(dataEntry.Value);
- break;
- case "layer":
- worldData.Layer = Convert.ToInt32(dataEntry.Value);
- break;
- case "rotation":
- worldData.Rotation = Convert.ToUInt32(dataEntry.Value);
- break;
- case "id":
- worldData.Id = Convert.ToUInt32(dataEntry.Value);
- break;
- case "target":
- worldData.Target = dataEntry.Value;
- break;
- case "goal":
- worldData.Goal = Convert.ToUInt32(dataEntry.Value);
- break;
- case "text":
- worldData.Text = Convert.ToString(dataEntry.Value);
- break;
- case "text_color":
- worldData.TextColor = Utilities.ImageFunctions.HexToColor(Convert.ToString(dataEntry.Value));
- break;
- case "x":
- xByte = (byte[])dataEntry.Value;
- break;
- case "y":
- yByte = (byte[])dataEntry.Value;
- break;
- }
- }
- if (xByte != null && yByte != null)
- {
- for (int p = 0; p < Math.Min(xByte.Length, yByte.Length); p += 2)
- {
- worldData.Locations.Add(new Point(
- xByte[p] << 8 | xByte[p + 1],
- yByte[p] << 8 | yByte[p + 1]));
- }
- }
- world.WorldData.Add(worldData);
- }
- }
- }
- break;
- }
- }
- return world;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment