Ejemplo n.º 1
0
 public void BeginStructure(Type readerType)
 {
     JsonMap map = new JsonMap();
     Write(map);
     objectReferences.Add(map);
     currentObject.Push(map);
 }
Ejemplo n.º 2
0
    public string GetJson()
    {
        JsonMap json = new JsonMap();

        json.FormatToJson(tiles);
        return(JsonUtility.ToJson(json));
    }
        public Task <JsonMap> GetJsonMap(int levelNumber, JsonMap jsonMap)
        {
            string[] lines = new string[]
            {
                "00100",
                "00000",
                "10001",
                "00000",
                "00100"
            };

            var y = 0;

            foreach (var line in lines)
            {
                var x = 0;
                foreach (var c in line)
                {
                    var ti = int.Parse(c.ToString());
                    jsonMap.layers[0].tileIndexes[y * 16 + x].ti = ti;
                    x++;
                }
                y++;
            }

            return(Task.FromResult(jsonMap));
        }
Ejemplo n.º 4
0
    private void LoadJsonMap()
    {
        cellInfo = new string[size, size];
        int       count      = 0;
        TextAsset text       = Resources.Load <TextAsset>("Map/data");
        JsonMap   rawJsonMap = JsonUtility.FromJson <JsonMap>(text.ToString());

        foreach (JsonLine line in rawJsonMap.Lines)
        {
            cellInfo[count, 0]  = line.R0;
            cellInfo[count, 1]  = line.R1;
            cellInfo[count, 2]  = line.R2;
            cellInfo[count, 3]  = line.R3;
            cellInfo[count, 4]  = line.R4;
            cellInfo[count, 5]  = line.R5;
            cellInfo[count, 6]  = line.R6;
            cellInfo[count, 7]  = line.R7;
            cellInfo[count, 8]  = line.R8;
            cellInfo[count, 9]  = line.R9;
            cellInfo[count, 10] = line.R10;
            cellInfo[count, 11] = line.R11;
            cellInfo[count, 12] = line.R12;
            cellInfo[count, 13] = line.R13;
            cellInfo[count, 14] = line.R14;
            cellInfo[count, 15] = line.R15;
            cellInfo[count, 16] = line.R16;
            cellInfo[count, 17] = line.R17;
            cellInfo[count, 18] = line.R18;
            count++;
        }
    }
Ejemplo n.º 5
0
        private void PrasePatterns(GameObject goWorld, JsonWorld jsonWorld)
        {
            using (new ChDir(assetPath))
            {
                foreach (var pattern in jsonWorld.patterns)
                {
                    // Find all files in this directory that match the pattern
                    using (new ChDir(assetPath))
                    {
                        foreach (var f in Directory.GetFiles(".", "*.tmx"))
                        {
                            var matches = Regex.Matches(f, pattern.regexp);
                            if (matches.Count >= 1 && matches[0].Groups.Count >= 3)
                            {
                                var x = matches[0].Groups[1].Value.ToInt();
                                var y = matches[0].Groups[2].Value.ToInt();

                                var map = new JsonMap
                                {
                                    fileName = f,
                                    x        = (x * pattern.multiplierX) + pattern.offsetX,
                                    y        = (y * pattern.multiplierY) + pattern.offsetY
                                };

                                InstantiateMap(goWorld, map);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 void JsonObjectVisitor.Visit(JsonMap map)
 {
     if (objectReferences.ContainsKey(map))
         ReferenceObject(objectReferences[map]);
     else
         ReadNewObject(map);
 }
        protected static DungeonTile[,] ReadTemplate(Type templateType)
        {
            var templateName = templateType.Namespace + ".template.jm";
            var stream       = templateType.Assembly.GetManifestResourceStream(templateName);

            using (var reader = new StreamReader(stream))
                return(JsonMap.Load(reader.ReadToEnd()));
        }
        public void MaintainReferences()
        {
            Writer writer = Substitute.For<Writer>();
            JsonMap map = new JsonMap();
            map["foo"] = map["bar"] = new JsonMap();

            JsonObjectReader.Read(map, writer);

            writer.Received().WriteReference(1);
        }
Ejemplo n.º 9
0
        public static TiledMap ToTiledMap(this JsonMap jsonMap)
        {
            var tiledMap = new TiledMap();

            tiledMap.Height       = jsonMap.Height;
            tiledMap.Width        = jsonMap.Width;
            tiledMap.TileWidth    = jsonMap.TileWidth;
            tiledMap.TileHeight   = jsonMap.TileHeight;
            tiledMap.NextLayerId  = jsonMap.NextLayerId;
            tiledMap.NextObjectId = jsonMap.NextObjectId;
            return(tiledMap);
        }
Ejemplo n.º 10
0
        public void ToStringTest1()
        {
            JsonMap map = JsonValue.NewMap();

            map.Put("nama", "Tantowi\rMustofa");
            map.Put("umur", 52);
            map.Put("active", true);
            map.Put("windows", "d:\\data\\radio");
            map.Put("linux", "/var/data/radio");

            File.WriteAllText("d:\\test.json", map.ToString());

            string str = map.ToString();

            Assert.AreEqual(str, "{\"nama\":\"Tantowi\\rMustofa\",\"umur\":52,\"active\":true,\"windows\":\"d:\\\\data\\\\radio\",\"linux\":\"/var/data/radio\"}");
        }
Ejemplo n.º 11
0
        private void InstantiateMap(GameObject goWorld, JsonMap jsonMap)
        {
            var path     = jsonMap.fileName;
            var superMap = RequestAssetAtPath <SuperMap>(path);

            if (superMap != null && AssetPath.TryRelativeToAsset(ref path))
            {
                // Use the importer of the map to determine Pixels Per Unit
                var   mapImporter = (TmxAssetImporter)AssetImporter.GetAtPath(path);
                float x           = mapImporter.InversePPU * jsonMap.x;
                float y           = -mapImporter.InversePPU * jsonMap.y;
                var   go          = (GameObject)PrefabUtility.InstantiatePrefab(superMap.gameObject);
                go.transform.SetParent(goWorld.transform);
                go.transform.localPosition = new Vector3(x, y, 0);
            }
        }
        public async Task <JsonMap> GetJsonMap(int levelNumber, JsonMap jsonMap)
        {
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(string.Format(@"ms-appx:///Content/Level{0:d2}.txt", levelNumber)));

            using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
            {
                var json    = sRead.ReadToEnd();
                var fileMap = Newtonsoft.Json.JsonConvert.DeserializeObject <JsonMap>(json);
                for (var i = 0; i < fileMap.layers.Count; i++)
                {
                    foreach (var tileInfo in fileMap.layers[i].tileIndexes)
                    {
                        jsonMap.layers[i].tileIndexes[tileInfo.i] = tileInfo;
                    }
                }
            }
            return(jsonMap);
        }
Ejemplo n.º 13
0
        void box_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right ||
                ras == null)
            {
                return;
            }

            var map  = ras.ExportMap();
            var json = JsonMap.Save(map);

            var sfd = new SaveFileDialog();

            sfd.Filter = "Json Map (*.json)|*.jm|All Files (*.*)|*.*";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText(sfd.FileName, json);
            }
        }
Ejemplo n.º 14
0
        public void ParseTest1()
        {
            string    str  = "{\"nama\":\"Tantowi\\rMustofa\",\"umur\":52,\"active\":true,\"windows\":\"d:\\\\data\\\\radio\",\"linux\":\"/var/data/radio\"}";
            JsonValue json = JsonValue.Parse(str);

            Assert.IsTrue(json.IsMap());

            JsonMap map     = json.GetMap();
            string  nama    = map.GetString("nama");
            int     umur    = (int)map.GetLong("umur");
            bool    active  = map.GetBoolean("active");
            string  windows = map.GetString("windows");
            string  linux   = map.GetString("linux");

            Assert.AreEqual(nama, "Tantowi\rMustofa");
            Assert.AreEqual(umur, 52);
            Assert.IsTrue(active);
            Assert.AreEqual(windows, "d:\\data\\radio");
            Assert.AreEqual(linux, "/var/data/radio");
        }
Ejemplo n.º 15
0
        private void ReadNewObject(JsonMap map)
        {
            objectReferences[map] = objectReferences.Count;

            if (((string)map[TypeKey].Value()).IsNotNullOrEmpty())
                writer.BeginStructure((string)map[TypeKey].Value(), GetType());
            else
                writer.BeginStructure(GetType());

            foreach (KeyValuePair<string, JsonObject> property in map)
            {
                string name = property.Key;
                JsonObject value = property.Value;

                if (name != TypeKey)
                {
                    writer.AddProperty(name);
                    ReadValue(value);
                }
            }

            writer.EndStructure();
        }
Ejemplo n.º 16
0
    void Awake()
    {
        hexFilter = Instantiate <HexFilter>(hexFilterPrefab);
        hexFilter.transform.SetParent(transform, false);

        hexMesh = GetComponentInChildren <HexMesh>();
        maps    = Resources.LoadAll <Sprite>("sprite/map");

        string json = File.ReadAllText("Assets/Resources/database/stage1.json");

        mapDetail = JsonUtility.FromJson <JsonMap>(json);
        width     = mapDetail.width;
        height    = mapDetail.height;

        cells = new HexCell[height * width];

        for (int y = 0, i = 0; y < mapDetail.height; y++)
        {
            for (int x = 0; x < mapDetail.width; x++)
            {
                CreateCell(x, y, i++);
            }
        }
    }
Ejemplo n.º 17
0
    public TileMap(string map)
    {
        JsonMap jsonMap = JsonUtility.FromJson <JsonMap>(map);

        tiles = jsonMap.FormatToTile(out playerPosition);
        maxX  = tiles.GetLength(1);
        maxY  = tiles.GetLength(0);

        for (int i = 0; i < maxY; i++)
        {
            for (int j = 0; j < maxX; j++)
            {
                if (tiles[i, j] == Tile.PrisonWall)
                {
                    prisonMin.x = j;
                    prisonMin.y = i;
                    prisonMax   = prisonMin + prisonSize - new Vector2Int(1, 1);

                    i = maxY;
                    break;
                }
            }
        }
    }
Ejemplo n.º 18
0
        void ProcessSvr()
        {
            try
            {
                var rdr = new NReader(dest.GetStream());
                var wtr = new NWriter(new NetworkStream(skt));
                while (true)
                {
                    int    len     = rdr.ReadInt32() - 5;
                    byte   id      = rdr.ReadByte();
                    byte[] content = rdr.ReadBytes(len);

                    wtr.Write(len + 5);
                    wtr.Write((byte)id);
                    wtr.Write(content);

                    svrPkts.Add(new Packet()
                    {
                        id = id, content = SendKey.Crypt(content)
                    });
                }
            }
            catch { }
            finally
            {
                skt.Close();
            }
            JsonMap map = new JsonMap();

            for (var i = 0; i < svrPkts.Count; i++)
            {
                File.WriteAllBytes("svr_pkt/" + i + "_" + svrPkts[i].id, svrPkts[i].content);
                if (svrPkts[i].id == 37)
                {
                    map.Init(IPAddress.NetworkToHostOrder(BitConverter.ToInt32(svrPkts[i].content, 0)),
                             IPAddress.NetworkToHostOrder(BitConverter.ToInt32(svrPkts[i].content, 4)));
                    File.WriteAllBytes("mapinfo.packet", svrPkts[i].content);
                }
                if (svrPkts[i].id == 5)
                {
                    using (NReader rdr = new NReader(new MemoryStream(svrPkts[i].content)))
                    {
                        short count = rdr.ReadInt16();
                        for (var x = 0; x < count; x++)
                        {
                            map.Tiles[rdr.ReadInt16()][rdr.ReadInt16()] = (Tile)rdr.ReadByte();
                        }
                        count = rdr.ReadInt16();
                        for (var x = 0; x < count; x++)
                        {
                            ObjectDef def = ObjectDef.Read(rdr);
                            def.Stats.Position.X -= 0.5F;
                            def.Stats.Position.Y -= 0.5F;
                            if (def.Stats.Position.X == (int)def.Stats.Position.X &&
                                def.Stats.Position.Y == (int)def.Stats.Position.Y)
                            {
                                int _x = (int)def.Stats.Position.X;
                                int _y = (int)def.Stats.Position.Y;
                                Array.Resize(ref map.Entities[_x][_y], map.Entities[_x][_y].Length + 1);
                                ObjectDef[] arr = map.Entities[_x][_y];

                                arr[arr.Length - 1] = def;
                            }
                        }
                    }
                }
            }
            File.WriteAllText("map.jm", map.ToJson());
        }
Ejemplo n.º 19
0
        public async Task <JsonMap> GetLayersAsync()
        {
            JsonMap map = await jsonMapManager.GetJsonMap(levelNumber, jsonMap);

            return(map);
        }
Ejemplo n.º 20
0
 public static JsonMap <TClassType> CreateMap <TClassType, TFieldType>(this JsonMap <TClassType> type, Expression <Func <TClassType, TFieldType> > field, string name)
 {
     type.Map(field, name);
     return(type);
 }
Ejemplo n.º 21
0
        public override void LoadJsonMap()
        {
            jsonMap = new JsonMap
            {
                layers = new List <JsonLayer>()
                {
                    new JsonLayer
                    {
                        index       = 0,
                        map         = "Layer0.png",
                        tileIndexes = new List <TileInfo>()
                    },
                    new JsonLayer
                    {
                        index       = 1,
                        map         = "Layer1.png",
                        tileIndexes = new List <TileInfo>()
                    },
                    new JsonLayer
                    {
                        index       = 2,
                        map         = "Layer1.png",
                        tileIndexes = new List <TileInfo>()
                    },
                    new JsonLayer
                    {
                        index       = 3,
                        map         = "Layer1.png",
                        tileIndexes = new List <TileInfo>()
                    },
                    new JsonLayer
                    {
                        index       = 4,
                        map         = "EnemySpriteSheet.png",
                        tileIndexes = new List <TileInfo>()
                    }
                }
            };

            var index = 0;

            for (var y = 0; y < MAP_ROWS; y++)
            {
                for (var x = 0; x < MAP_COLS; x++)
                {
                    jsonMap.layers[0].tileIndexes.Add(new TileInfo
                    {
                        i  = index,
                        ti = 0
                    });

                    jsonMap.layers[1].tileIndexes.Add(new TileInfo
                    {
                        i  = index,
                        ti = 0
                    });

                    jsonMap.layers[2].tileIndexes.Add(new TileInfo
                    {
                        i  = index,
                        ti = 0
                    });

                    jsonMap.layers[3].tileIndexes.Add(new TileInfo
                    {
                        i  = index,
                        ti = 0
                    });

                    jsonMap.layers[4].tileIndexes.Add(new TileInfo
                    {
                        i  = index,
                        ti = 0
                    });
                    index++;
                }
            }

            //if (jsonMapManager is DummyJsonMapManager)
            jsonMapManager.GetJsonMap(levelNumber, jsonMap);
            //else
            //    GetLayersAsync();
        }
Ejemplo n.º 22
0
 private void Start()
 {
     _map = JsonUtility.FromJson <JsonMap>(jsonMapAsset.text);
     UpdateNearestObjectLocation(0, 0);
 }
Ejemplo n.º 23
0
 public void saveByObj()
 {
     raw.data = JsonMap.toJsonMap(obj);
 }