Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- using PlayerIOClient;
- using ProtoBuf;
- namespace WorldIndexer
- {
- class WorldFormat
- {
- private static string UIntToHex(uint color)
- {
- byte a = (byte)(color >> 24);
- byte r = (byte)(color >> 16);
- byte g = (byte)(color >> 8);
- byte b = (byte)(color >> 0);
- return ColorTranslator.ToHtml(Color.FromArgb(a, r, g, b));
- }
- [ProtoContract]
- public class World
- {
- [ProtoMember(1)]
- public string Id;
- [ProtoMember(2)]
- public string Name = "Untitled World";
- [ProtoMember(3)]
- public string Owner = "(unknown)";
- [ProtoMember(4)]
- public string OwnerId = "(unknown)";
- [ProtoMember(5)]
- public int Plays;
- [ProtoMember(6)]
- public int Width = 200;
- [ProtoMember(7)]
- public int Height = 200;
- [ProtoMember(8)]
- public int Woots;
- [ProtoMember(9)]
- public int TotalWoots;
- [ProtoMember(10)]
- public bool AllowPotions;
- [ProtoMember(11)]
- public bool Visible = true;
- [ProtoMember(12)]
- public string BackgroundColor;
- [ProtoMember(13)]
- public List<WorldData> WorldData = new List<WorldData>();
- }
- [ProtoContract]
- public class WorldData
- {
- [ProtoMember(1)]
- public int type;
- [ProtoMember(2)]
- public int layer;
- [ProtoMember(3)]
- public int rotation;
- [ProtoMember(4)]
- public int id;
- [ProtoMember(5)]
- public int goal;
- [ProtoMember(6)]
- public string target;
- [ProtoMember(7)]
- public string text;
- [ProtoMember(8)]
- public List<Tuple<int, int>> locs = new List<Tuple<int,int>>();
- }
- public class Converter
- {
- private World w = new World();
- public World Convert(DatabaseObject dbo)
- {
- w.Id = dbo.Key;
- foreach (KeyValuePair<string, object> wi in dbo)
- {
- switch (wi.Key)
- {
- case "width":
- w.Width = System.Convert.ToInt32(wi.Value);
- break;
- case "height":
- w.Height = System.Convert.ToInt32(wi.Value);
- break;
- case "name":
- w.Name = System.Convert.ToString(wi.Value);
- break;
- case "plays":
- w.Plays = System.Convert.ToInt32(wi.Value);
- break;
- case "owner":
- //w.Owner = EE.IdToUser(System.Convert.ToString(wi.Value)); Add your own IdToUser function or remove.
- w.OwnerId = System.Convert.ToString(wi.Value);
- break;
- case "woots":
- w.Woots = System.Convert.ToInt32(wi.Value);
- break;
- case "totalwoots":
- w.TotalWoots = System.Convert.ToInt32(wi.Value);
- break;
- case "allowpotions":
- w.AllowPotions = System.Convert.ToBoolean(wi.Value);
- break;
- case "visible":
- w.Visible = System.Convert.ToBoolean(wi.Value);
- break;
- case "backgroundColor":
- w.BackgroundColor = (System.Convert.ToUInt32(wi.Value) != 0) ? UIntToHex(System.Convert.ToUInt32(wi.Value)) : null;
- break;
- case "worlddata":
- {
- foreach (DatabaseObject obj in (DatabaseArray)wi.Value)
- {
- if (obj != null)
- {
- WorldData wd = new WorldData();
- wd.type = obj.GetInt("type", 0);
- wd.layer = obj.GetInt("layer", 0);
- wd.rotation = obj.GetInt("rotation", 0);
- wd.id = obj.GetInt("id", 0);
- wd.target = obj.GetString("target", null);
- wd.goal = obj.GetInt("goal", 0);
- wd.text = obj.GetString("text", null);
- if (obj.Contains("x") && obj.Contains("y"))
- {
- byte[] x = obj.GetBytes("x");
- byte[] y = obj.GetBytes("y");
- for (int p = 0; p < x.Length; p += 2)
- wd.locs.Add(new Tuple<int, int>(x[p] << 8 | x[p + 1], y[p] << 8 | y[p + 1]));
- }
- w.WorldData.Add(wd);
- }
- }
- }
- break;
- }
- }
- return w;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment