예제 #1
0
        public GameMap CreateGameMap(Tmx tmx, Size2 tileSize)
        {
            var tsxMap  = new Dictionary <int, Tsx>();
            var tileMap = new Dictionary <int, TsxTile>();

            tmx.Tilesets.ForEach(tsx =>
            {
                for (int i = 0; i < tsx.Tiles.Count; i++)
                {
                    tileMap[tsx.FirstId + i] = tsx.Tiles[i];
                    tsxMap[tsx.FirstId + i]  = tsx;
                }
            });

            return(new GameMap(tmx.Layers
                               .SelectMany(layer => layer.Tiles.Select(tile => new { Layer = layer, Tile = tile }))
                               .Where(x => x.Tile.TextureId != 0)
                               .GroupBy(x => new { x.Tile.Column, x.Tile.Row })
                               .Select(x => new GameTile(x.Key.Column, x.Key.Row,
                                                         new Transform2(new Rectangle(x.Key.Column * tileSize.Width, x.Key.Row * tileSize.Height,
                                                                                      tileSize.Width, tileSize.Height)),
                                                         x.Select(layerAndTile => new GameTileDetail(
                                                                      tsxMap[layerAndTile.Tile.TextureId].TileSource,
                                                                      tileMap[layerAndTile.Tile.TextureId].SourceRect,
                                                                      layerAndTile.Layer.ZIndex,
                                                                      tileMap[layerAndTile.Tile.TextureId].CustomBools["Blocking"],
                                                                      tileMap[layerAndTile.Tile.TextureId].GetEnum <Cover>("Cover"),
                                                                      tileMap[layerAndTile.Tile.TextureId].CustomBools["Hide"],
                                                                      tileMap[layerAndTile.Tile.TextureId].CustomStrings["FX"],
                                                                      tileMap[layerAndTile.Tile.TextureId].CustomStrings["Character"],
                                                                      tileMap[layerAndTile.Tile.TextureId].CustomBools["MustKill"],
                                                                      tileMap[layerAndTile.Tile.TextureId].CustomStrings["Dialog"])).ToList())).ToList()));
        }
예제 #2
0
        protected override IEnumerable <GameObject> CreateObjs()
        {
            var player = new OrthographicMovingObjectFactory()
                         .CreateMovingObject(Tsx.Create(Path.Combine("Characters", "Gareth.tsx")), _player.Transform.Location, new ZIndex(3))
                         .Add(new TopDownMovement {
                Speed = 0.2f
            });

            PlayerLocation.Current = new PlayerLocation {
                MapName = GetType().Name, Transform = player.World
            };

            yield return(player);

            var cameraPosition = Transform2.CameraZero;

            cameraPosition.Center = player.World.Center - new Vector2(800, 450);
            yield return(Entity
                         .Create("Player Camera", cameraPosition)
                         .Add(new Camera())
                         .AttachTo(player));

            foreach (var tile in new OrthographicTileMapFactory().CreateMap(Tmx.Create(Path.Combine("Maps", "Large.tmx"))))
            {
                yield return(tile);
            }
            foreach (var mapEvent in MapEventsFactory.Create(Path.Combine("Content", "Maps", "Large.events")).InstantiateEvents())
            {
                yield return(mapEvent);
            }
        }
예제 #3
0
        public List <GameObject> CreateMap(Tmx tmx)
        {
            var tileIdToGameObject = CreateTileIdToGameObjectMap(tmx);

            return(tmx.Layers.SelectMany(
                       layer => layer.Tiles.Select(
                           tile => tileIdToGameObject[tile.TileId](
                               new Transform2(
                                   new Rectangle(tile.Column * tmx.TileWidth, tile.Row * tmx.TileHeight, tmx.TileWidth, tmx.TileHeight),
                                   new ZIndex(layer.ZIndex))))).ToList());
        }
예제 #4
0
        public void Parse_InvalidTmxFile_To_TmxObject_Test()
        {
            // Assign
            TmxParser_Accessor parser = new TmxParser_Accessor();

            // Act
            Tmx result = parser.Parse(MockObjects.INVALID_TmxFilePath);

            // Assert
            Assert.IsNull(result);
        }
예제 #5
0
        public void Parse_EmptyTmxFile_To_TmxObject_Test()
        {
            // Assign
            TmxParser_Accessor parser = new TmxParser_Accessor();

            // Act
            Tmx result = parser.Parse(MockObjects.EMPTY_TmxFilePath);

            // Assert
            Assert.IsNull(result);
        }
예제 #6
0
        public void Parse_NonExistTmxFile_To_TmxObject_Test()
        {
            // Assign
            TmxParser_Accessor parser = new TmxParser_Accessor();

            // Act
            Tmx result = parser.Parse(MockObjects.NonEXIST_TmxFilePath);

            // Assert
            Assert.IsNull(result);
        }
예제 #7
0
        public TileMap CreateMap(Tmx tmx)
        {
            var details = new TileMapDetails(tmx);

            return(new TileMap(tmx.Layers.Select(x =>
                                                 new TileLayer(x.ZIndex, x.Tiles
                                                               .Where(y => y.TextureId != 0)
                                                               .Select(y =>
                                                                       new Tile(details.Get(y.TextureId),
                                                                                new Rectangle(y.Column * tmx.TileWidth, y.Row * tmx.TileHeight, tmx.TileWidth, tmx.TileHeight))).ToList())).ToList()));
        }
        protected override IEnumerable <GameObject> CreateObjs()
        {
            var tiles = new OrthographicTileMapFactory().CreateMap(Tmx.Create(_path));

            tiles.ForEach(tile => tile.Add(CreateTileMouseActions(tile)));
            var camera = Entity.Create("Map Editor Camera", Transform2.CameraZero).Add(new Camera()).Add(new MouseDrag {
                Button = MouseButton.Right
            });

            return(tiles.Concat(new List <GameObject> {
                camera
            }));
        }
예제 #9
0
        public void Parse_Valid_pseudo_TmxFile_To_TmxObject_Test()
        {
            // Assign
            TmxParser_Accessor parser = new TmxParser_Accessor();
            Tmx expected = MockObjects.VALID_pseudo_TmxObject;

            // Act
            Tmx result = parser.Parse(MockObjects.VALID_pseudo_TmxFilePath);

            // Assert
            // -- Assert version
            Assert.AreEqual(expected.Version, result.Version);
            // -- Assert header
            Assert.AreEqual(expected.Header.CreationToolVersion, result.Header.CreationToolVersion);
            Assert.AreEqual(expected.Header.DataType, result.Header.DataType);
            Assert.AreEqual(expected.Header.SegmentType, result.Header.SegmentType);
            Assert.AreEqual(expected.Header.AdminLanguage, result.Header.AdminLanguage);
            Assert.AreEqual(expected.Header.SourceLanguage, result.Header.SourceLanguage);
            Assert.AreEqual(expected.Header.OriginalTranslationMemoryFormat, result.Header.OriginalTranslationMemoryFormat);
            Assert.AreEqual(expected.Header.CreationTool, result.Header.CreationTool);
            // -- Assert body
            // ---- Assert TranslationUnits
            foreach (TranslationUnit expectedTU in expected.Body.TranslationUnits)
            {
                TranslationUnit unit = result.Body.TranslationUnits
                                       .First <TranslationUnit>(
                    tu => tu.TranslationUnitId == expectedTU.TranslationUnitId
                    );

                Assert.IsNotNull(unit);
                Assert.AreEqual(expectedTU.TranslationUnitId, unit.TranslationUnitId);

                // ---- Assert TranslationUnitVariant
                foreach (TranslationUnitVariant expectedTUV in expectedTU.TranslationUnitVariants)
                {
                    TranslationUnitVariant unitVar = unit.TranslationUnitVariants
                                                     .First <TranslationUnitVariant>(
                        tuv => tuv.Segment == expectedTUV.Segment
                        );

                    Assert.IsNotNull(unitVar);
                    Assert.AreEqual(expectedTUV.Language, unitVar.Language);
                    Assert.AreEqual(expectedTUV.Segment, unitVar.Segment);
                }
            }
        }
예제 #10
0
        private Tmx Parse(FileInfo file)
        {
            if (file.Exists && file.Extension == ".tmx")
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Tmx));
                Tmx           data       = null;
                using (StreamReader reader = new StreamReader(file.FullName))
                {
                    data = (Tmx)serializer.Deserialize(reader);
                }

                return(data);
            }
            else
            {
                return(null);
            }
        }
예제 #11
0
        protected override IEnumerable <GameObject> CreateObjs()
        {
            var player = new OrthographicMovingObjectFactory()
                         .CreateMovingObject(Tsx.Create(Path.Combine("Characters", "Gareth.tsx")), _player.Transform.Location, new ZIndex(3))
                         .Add(new TopDownMovement {
                Speed = 0.2f
            });

            PlayerLocation.Current = new PlayerLocation {
                MapName = GetType().Name, Transform = player.World
            };

            yield return(player);

            var cameraPosition = Transform2.CameraZero;

            cameraPosition.Center = player.World.Center - new Vector2(800, 450);
            yield return(Entity
                         .Create("Player Camera", cameraPosition)
                         .Add(new Camera())
                         .AttachTo(player));

            foreach (var tile in new OrthographicTileMapFactory().CreateMap(Tmx.Create(Path.Combine("Maps", "FireCave.tmx"))))
            {
                yield return(tile);
            }

            yield return(Entity.Create("Start Battle", new Transform2(new TilePosition(3, 5, 48), new Size2(48 * 3, 10)))
                         .Add(new Collision {
                IsBlocking = false
            })
                         .Add(x => new BoxCollider(x.World))
                         .Add(new StepTrigger())
                         .Add(new OnCollision {
                Action = x => x.IfEquals(player, () => Navigate.To(BattleFactory.Create()))
            }));

            foreach (var mapEvent in MapEventsFactory.Create(Path.Combine("Content", "Maps", "FireCave.events")).InstantiateEvents())
            {
                yield return(mapEvent);
            }
        }
예제 #12
0
        protected override IEnumerable <GameObject> CreateObjs()
        {
            InitTilePanel();
            InitEditPanel();
            var tiles = new OrthographicTileMapFactory().CreateMap(Tmx.Create(_path));

            tiles.ForEach(tile => tile.Add(new HighlightColor
            {
                Color      = _events.GetTileEvents(new TilePosition(tile.World)).Any() ? Event : NoTint,
                Offset     = 10,
                MinOpacity = 191,
                MaxOpacity = 255
            })
                          .Add(CreateTileMouseActions(tile)));
            _selectedTile = tiles.First();
            var camera = Entity.Create("Map Editor Camera", Transform2.CameraZero).Add(new Camera()).Add(new MouseDrag {
                Button = MouseButton.Right
            });

            return(new List <GameObject> {
                camera, _tilePanel, _editPanel
            }.Concat(tiles));
        }
예제 #13
0
        public void Parse_TmxFileNoTranslationUnits_To_TmxObject_Test()
        {
            // Assign
            TmxParser_Accessor parser = new TmxParser_Accessor();
            Tmx expected = MockObjects.VALID_en_TmxObject;

            // Act
            Tmx result = parser.Parse(MockObjects.NO_TRANSLATION_UNITS_TmxFilePath);

            // Assert
            // -- Assert version
            Assert.AreEqual(expected.Version, result.Version);
            // -- Assert header
            Assert.AreEqual(expected.Header.CreationToolVersion, result.Header.CreationToolVersion);
            Assert.AreEqual(expected.Header.DataType, result.Header.DataType);
            Assert.AreEqual(expected.Header.SegmentType, result.Header.SegmentType);
            Assert.AreEqual(expected.Header.AdminLanguage, result.Header.AdminLanguage);
            Assert.AreEqual(expected.Header.SourceLanguage, result.Header.SourceLanguage);
            Assert.AreEqual(expected.Header.OriginalTranslationMemoryFormat, result.Header.OriginalTranslationMemoryFormat);
            Assert.AreEqual(expected.Header.CreationTool, result.Header.CreationTool);
            // -- Assert body
            // ---- Assert TranslationUnits
            Assert.AreEqual(0, result.Body.TranslationUnits.Count);
        }
예제 #14
0
        public void Parse_TmxFileNoTranslationUnitVarients_To_TmxObject_Test()
        {
            // Assign
            TmxParser_Accessor parser = new TmxParser_Accessor();
            Tmx expected = MockObjects.VALID_en_TmxObject;

            // Act
            Tmx result = parser.Parse(MockObjects.NO_TRANSLATION_UNITS_VARIENTS_TmxFilePath);

            // Assert
            // -- Assert version
            Assert.AreEqual(expected.Version, result.Version);
            // -- Assert header
            Assert.AreEqual(expected.Header.CreationToolVersion, result.Header.CreationToolVersion);
            Assert.AreEqual(expected.Header.DataType, result.Header.DataType);
            Assert.AreEqual(expected.Header.SegmentType, result.Header.SegmentType);
            Assert.AreEqual(expected.Header.AdminLanguage, result.Header.AdminLanguage);
            Assert.AreEqual(expected.Header.SourceLanguage, result.Header.SourceLanguage);
            Assert.AreEqual(expected.Header.OriginalTranslationMemoryFormat, result.Header.OriginalTranslationMemoryFormat);
            Assert.AreEqual(expected.Header.CreationTool, result.Header.CreationTool);
            // -- Assert body
            // ---- Assert TranslationUnits
            foreach (TranslationUnit expectedTU in expected.Body.TranslationUnits)
            {
                TranslationUnit unit = result.Body.TranslationUnits
                                       .First <TranslationUnit>(
                    tu => tu.TranslationUnitId == expectedTU.TranslationUnitId
                    );

                Assert.IsNotNull(unit);
                Assert.AreEqual(expectedTU.TranslationUnitId, unit.TranslationUnitId);

                // ---- Assert TranslationUnitVariant
                Assert.AreEqual(0, unit.TranslationUnitVariants.Count);
            }
        }
예제 #15
0
 public TileMapDetails(Tmx tmx)
 {
     tmx.Tilesets.ForEach(AddTileset);
 }
예제 #16
0
        private Dictionary <int, Func <Transform2, GameObject> > CreateTileIdToGameObjectMap(Tmx tmx)
        {
            var map = new Dictionary <int, Func <Transform2, GameObject> >();

            tmx.Tilesets.ForEach(
                tileset => tileset.Tiles.ForEach(
                    tile => map[tileset.FirstId + tile.Id] = transform => CreateTile(tileset, tile, transform)));
            return(map);
        }