Ejemplo n.º 1
0
        /// <summary>
        /// Unserializes the BigDB database world object.
        /// </summary>
        /// <param name="worlddata">The world data.</param>
        /// <param name="width">The width of the world.</param>
        /// <param name="height">The height of the world.</param>
        public static void UnserializeFromComplexObject(DatabaseArray worlddata, int width, int height)
        {
            Minimap minimap = new Minimap();
            minimap.width = width;
            minimap.height = height;
            minimap.initialize();

            Console.WriteLine("Unserializing complex object...");

            foreach (DatabaseObject ct in worlddata) {
                if (ct.Count == 0) continue;
                uint blockId = ct.GetUInt("type");
                int layer = ct.GetInt("layer");
                byte[] xs = ct.GetBytes("x"),
                    ys = ct.GetBytes("y");

                for (var b = 0; b < xs.Length; b += 2) {
                    int nx = (xs[b] << 8) | xs[b + 1],
                        ny = (ys[b] << 8) | ys[b + 1];

                    minimap.drawBlock(layer, nx, ny, blockId);
                }
            }

            // Write them "on top" of backgrounds
            minimap.rewriteForegroundBlocks();

            minimap.Save(worldID + "_bigdb.png");
            generating_minimap = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unserializes the BigDB database world object.
        /// </summary>
        /// <param name="worlddata">The world data.</param>
        /// <param name="width">The width of the world.</param>
        /// <param name="height">The height of the world.</param>
        public static void UnserializeFromComplexObject(DatabaseObject input, int width, int height, string worldID)
        {
            Minimap minimap = new Minimap();
            minimap.width = width;
            minimap.height = height;
            minimap.initialize();

            if (input.Contains("worlddata"))
            {
                foreach (DatabaseObject ct in input.GetArray("worlddata").Reverse())
                {
                    if (ct.Count == 0) continue;
                    uint blockId = ct.GetUInt("type");
                    int layer = ct.GetInt("layer", 0);

                    byte[] x = ct.GetBytes("x", new byte[0]), y = ct.GetBytes("y", new byte[0]),
                           x1 = ct.GetBytes("x1", new byte[0]), y1 = ct.GetBytes("y1", new byte[0]);

                    for (int j = 0; j < x1.Length; j++)
                    {
                        byte nx = x1[j];
                        byte ny = y1[j];

                        minimap.drawBlock(layer, nx, ny, blockId);
                    }
                    for (int k = 0; k < x.Length; k += 2)
                    {
                        uint nx2 = (uint)(((int)x[k] << 8) + (int)x[k + 1]);
                        uint ny2 = (uint)(((int)y[k] << 8) + (int)y[k + 1]);

                        minimap.drawBlock(layer, (int)nx2, (int)ny2, blockId);
                    }
                }
            }
            else if (input.Contains("world"))
            {

            }

            minimap.Save(worldID + "_bigdb.png", histogram);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles all incoming PlayerIO messages
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="m">The message.</param>
        static void Connection_OnMessage(object sender, Message m)
        {
            if (m.Type != "init")
                return;

            Console.WriteLine("Inited");
            globalConn.Disconnect();

            Minimap minimap = new Minimap();
            minimap.width = m.GetInt(15);
            minimap.height = m.GetInt(16);

            minimap.initialize();

            Console.WriteLine("Parsing init data...");

            uint p = 22;
            while (m[p] as string != "ws") p++;

            p++;
            // Parse world data
            while (p < m.Count) {
                uint blockId = m.GetUInt(p);
                int layer = m.GetInt(p + 1);
                byte[] xs = m.GetByteArray(p + 2),
                    ys = m.GetByteArray(p + 3);

                for (var b = 0; b < xs.Length; b += 2) {
                    int nx = (xs[b] << 8) | xs[b + 1],
                        ny = (ys[b] << 8) | ys[b + 1];

                    minimap.drawBlock(layer, nx, ny, blockId);
                }

                p += 4;

                if (m[p] as string == "we")
                    break;

                while (p + 3 < m.Count) {
                    if (m[p + 2] is byte[])
                        break;
                    p++;
                }
            }

            minimap.rewriteForegroundBlocks();
            minimap.Save(worldID + ".png");
            generating_minimap = false;
        }