public void LoadMap(string filename) { ClearMap (); map = Map.LoadMap(filename); List<Map.Tile> tileList = map.GetTiles(); foreach(Map.Tile t in tileList) { CreateTileAt(t.hexCoord, (int)t.spriteType); } List<Map.Town> townList = map.GetTowns(); foreach(Map.Town t in townList) { CreateTownAt(t.hexCoord, t.team); } /* // Change Minimap camera's w and h Rect r = map.GetMapRect(); minimapCamera.orthographicSize = Mathf.Max (r.width, r.height) / 2; minimapCamera.transform.position = new Vector3(r.xMin + r.width / 2, r.yMin + r.height / 2, minimapCamera.transform.position.z); */ }
public static string JMap(Map m) { LitJson.JsonWriter js = new LitJson.JsonWriter(); js.PrettyPrint = true; js.IndentValue = 2; js.WriteObjectStart(); js.WritePropertyName("min"); js.WriteObjectStart(); js.WritePropertyName("x"); js.Write(m.min.x); js.WritePropertyName("y"); js.Write(m.min.y); js.WriteObjectEnd(); js.WritePropertyName("max"); js.WriteObjectStart(); js.WritePropertyName("x"); js.Write(m.max.x); js.WritePropertyName("y"); js.Write(m.max.y); js.WriteObjectEnd(); js.WritePropertyName("tiles"); js.WriteArrayStart(); List<Map.Tile> tiles = m.GetTiles(); foreach(Map.Tile t in tiles) { js.WriteObjectStart(); // Key js.WritePropertyName("key"); js.WriteObjectStart(); js.WritePropertyName("x"); js.Write(t.hexCoord.x); js.WritePropertyName("y"); js.Write (t.hexCoord.y); js.WriteObjectEnd(); //End of Key // Value js.WritePropertyName("value"); js.WriteObjectStart(); js.WritePropertyName("tileType"); js.Write(t.spriteType.ToString()); js.WritePropertyName("penalty"); js.Write(t.penalty.ToString()); js.WritePropertyName("visibility"); js.Write(t.visibility.ToString()); js.WriteObjectEnd(); // End of Value js.WriteObjectEnd(); } js.WriteArrayEnd(); js.WritePropertyName("towns"); js.WriteArrayStart(); List<Map.Town> towns = m.GetTowns(); foreach (Map.Town t in towns) { js.WriteObjectStart(); // Key js.WritePropertyName("key"); js.WriteObjectStart(); js.WritePropertyName("x"); js.Write(t.hexCoord.x); js.WritePropertyName("y"); js.Write (t.hexCoord.y); js.WriteObjectEnd(); // End of Key // Value js.WritePropertyName("value"); js.WriteObjectStart(); js.WritePropertyName("playerSide"); js.Write(t.team); js.WriteObjectEnd(); // End of Value js.WriteObjectEnd(); } js.WriteArrayEnd(); // TODO Units js.WriteObjectEnd(); return js.ToString(); }