/// <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; }
/// <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; }