Exemplo n.º 1
0
        public void JsonDeserializesToTile()
        {
            string source = "{\"MovementFlags\":5,\"Id\":123}";
            Tile   tile   = TileSerializer.Deserialize(source);

            Assert.That(tile.Id, Is.EqualTo(123));
            Assert.That(tile.MovementFlags, Is.EqualTo(TileMovementFlags.BulletPassable | TileMovementFlags.Passable));
        }
Exemplo n.º 2
0
 public ActionResult <string> GetTiles()
 {
     if (MasterGameController.TheGame.Tiles == null)
     {
         return(NotFound());
     }
     return(TileSerializer.SerializeList(MasterGameController.TheGame.Tiles));
 }
Exemplo n.º 3
0
        public void TileSerializesToJson()
        {
            Tile   tile       = new Tile(123, TileMovementFlags.BulletPassable | TileMovementFlags.Passable);
            string serialized = TileSerializer.Serialize(tile);

            string expected = "{\"MovementFlags\":5,\"Id\":123}";

            Assert.That(serialized, Is.EqualTo(expected));
        }
Exemplo n.º 4
0
        public ActionResult <string> GetTile([FromRoute] int id)
        {
            Tile tile = MasterGameController.TheGame.Tiles?.Find(t => t.Id == id);

            if (tile == null)
            {
                return(NotFound());
            }
            return(TileSerializer.Serialize(tile));
        }
Exemplo n.º 5
0
        public static List <Tile> Load(string filepath)
        {
            if (!File.Exists(filepath))
            {
                throw new FileNotFoundException("Failure to load tiles from provided file. File not found.", filepath);
            }
            string fileData = File.ReadAllText(filepath);

            return(TileSerializer.DeserializeList(fileData));
        }
Exemplo n.º 6
0
        public void JsonDeserializesToTileList()
        {
            string      source = "[{\"MovementFlags\":5,\"Id\":123},{\"MovementFlags\":4,\"Id\":127}]";
            List <Tile> tiles  = TileSerializer.DeserializeList(source);

            Assert.That(tiles, Has.Count.EqualTo(2));
            Assert.That(tiles[0].Id, Is.EqualTo(123));
            Assert.That(tiles[0].MovementFlags, Is.EqualTo(TileMovementFlags.BulletPassable | TileMovementFlags.Passable));
            Assert.That(tiles[1].Id, Is.EqualTo(127));
            Assert.That(tiles[1].MovementFlags, Is.EqualTo(TileMovementFlags.BulletPassable));
        }
Exemplo n.º 7
0
        public void TileListSerializesToJson()
        {
            Tile        tile  = new Tile(123, TileMovementFlags.BulletPassable | TileMovementFlags.Passable);
            Tile        tile2 = new Tile(127, TileMovementFlags.BulletPassable);
            List <Tile> list  = new List <Tile> {
                tile, tile2
            };
            string serialized = TileSerializer.SerializeList(list);

            string expected = "[{\"MovementFlags\":5,\"Id\":123},{\"MovementFlags\":4,\"Id\":127}]";

            Assert.That(serialized, Is.EqualTo(expected));
        }
Exemplo n.º 8
0
 public DictSerializer(Vector2Serializer serializer, TileSerializer tileSerializer)
 {
     _serializer = serializer;
     _tileSerializer = tileSerializer;
 }