示例#1
0
        static IEnumerable <ObjectGroup> BuildTriggers(
            MapData2D map,
            TilemapProperties properties,
            EventFormatter eventFormatter,
            ref int nextObjectGroupId,
            ref int nextObjectId)
        {
            var objectGroups = new List <ObjectGroup>();

            var regions = TriggerZoneBuilder.BuildZones(map);
            var groupedByTriggerType = regions
                                       .Where(x => x.Item1.Chain != null)
                                       .GroupBy(x => x.Item1.Trigger)
                                       .OrderBy(x => x.Key);

            foreach (var triggerType in groupedByTriggerType)
            {
                objectGroups.Add(BuildTriggerObjectGroup(
                                     nextObjectGroupId++,
                                     $"T:{triggerType.Key}",
                                     triggerType,
                                     properties,
                                     eventFormatter,
                                     ref nextObjectId));
            }

            return(objectGroups);
        }
示例#2
0
        public static Tileset FromTileset(TilesetData tileset, TilemapProperties properties)
        {
            if (tileset == null)
            {
                throw new ArgumentNullException(nameof(tileset));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }
            // +1 to go from max index to count, then + another so we have a blank tile at the end.

            int count = tileset.Tiles
                        .Where(x => x.ImageNumber != 0xffff)
                        .Max(x => x.ImageNumber + x.FrameCount - 1)
                        + 2;
            int columns = (properties.SheetWidth - 2 * properties.Margin) / (properties.TileWidth + properties.Spacing);
示例#3
0
        public static Map FromAlbionMap(
            MapData2D map,
            TilesetData tileset,
            TilemapProperties properties,
            string tilesetPath,
            Tileset npcTileset,
            EventFormatter eventFormatter)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (tileset == null)
            {
                throw new ArgumentNullException(nameof(tileset));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }
            if (npcTileset == null)
            {
                throw new ArgumentNullException(nameof(npcTileset));
            }

            ushort blankTileIndex    = (ushort)(tileset.Tiles.Max(x => x.ImageNumber + x.FrameCount - 1) + 1);
            int    nextObjectId      = 1;
            int    nextObjectGroupId = 3; // 1 & 2 are always underlay & overlay.

            npcTileset.GidOffset = tileset.Tiles.Count + 1;

            return(new Map
            {
                TiledVersion = "1.4.2",
                Version = "1.4",
                Width = map.Width,
                Height = map.Height,
                TileWidth = properties.TileWidth,
                TileHeight = properties.TileHeight,
                Infinite = 0,
                NextLayerId = 5, // max(layer or objectgroup id) + 1
                NextObjectId = 1,
                Orientation = "orthogonal",
                RenderOrder = "right-down",
                BackgroundColor = "#000000",
                Tilesets = new List <MapTileset>
                {
                    new MapTileset {
                        FirstGid = 1, Source = tilesetPath,
                    },
                    new MapTileset {
                        FirstGid = npcTileset.GidOffset, Source = npcTileset.Filename
                    }
                },
                Layers = new List <MapLayer> {
                    new MapLayer
                    {
                        Id = 1,
                        Name = "Underlay",
                        Width = map.Width,
                        Height = map.Height,
                        Data = new LayerData {
                            Encoding = "csv", Content = BuildCsvData(map, tileset, false, blankTileIndex)
                        }
                    },
                    new MapLayer
                    {
                        Id = 2,
                        Name = "Overlay",
                        Width = map.Width,
                        Height = map.Height,
                        Data = new LayerData {
                            Encoding = "csv", Content = BuildCsvData(map, tileset, true, blankTileIndex)
                        }
                    }
                },
                ObjectGroups = new[] {
                    BuildTriggers(map, properties, eventFormatter, ref nextObjectGroupId, ref nextObjectId),
                    BuildNpcs(map, properties, eventFormatter, npcTileset, ref nextObjectGroupId, ref nextObjectId)
                }.SelectMany(x => x).ToList()
            });
        }