예제 #1
0
        static void DumpNpcTileset(DumpProperties props, string gfxDirName, string tilesetName, IEnumerable <AssetId> assetIds)
        {
            var spriteDir = Path.Combine(props.TilesetDir, gfxDirName);

            if (!Directory.Exists(spriteDir))
            {
                Directory.CreateDirectory(spriteDir);
            }

            var tiles = new List <Tiled.TileProperties>();

            foreach (var id in assetIds)
            {
                var info = DumpGraphics.ExportImage(id, props.Assets, props.Hints, spriteDir, DumpFormats.Png, (frame, palFrame) => frame == 9 && palFrame == 0).SingleOrDefault();
                if (info == null)
                {
                    continue;
                }
                tiles.Add(new Tiled.TileProperties
                {
                    Name   = id.ToString(),
                    Frames = 1,
                    Width  = info.Width,
                    Height = info.Height,
                    Source = info.Path,
                });
            }

            var tilemap = Tiled.Tileset.FromSprites(tilesetName, "NPC", tiles);

            tilemap.Save(Path.Combine(props.TilesetDir, tilesetName + ".tsx"));
        }
예제 #2
0
        public static void Dump(string baseDir, IAssetManager assets, ISet <AssetType> types, AssetId[] dumpIds)
        {
            if (assets == null)
            {
                throw new ArgumentNullException(nameof(assets));
            }
            if (types == null)
            {
                throw new ArgumentNullException(nameof(types));
            }
            var disposeList = new List <IDisposable>();
            var exportDir   = Path.Combine(baseDir, "data", "exported", "tiled");

            if (!Directory.Exists(exportDir))
            {
                Directory.CreateDirectory(exportDir);
            }

            var tilesetDir = Path.Combine(exportDir, "tilesets");

            if (!Directory.Exists(tilesetDir))
            {
                Directory.CreateDirectory(tilesetDir);
            }

            TextWriter Writer(string filename)
            {
                var stream = File.Open(filename, FileMode.Create);
                var writer = new StreamWriter(stream);

                disposeList.Add(writer);
                disposeList.Add(stream);
                return(writer);
            }

            var hints = PaletteHints.Load(Path.Combine(baseDir, "mods", "Base", "palette_hints.json"));
            var props = new DumpProperties(assets, hints, tilesetDir, exportDir, Writer);

            void Flush()
            {
                foreach (var d in disposeList)
                {
                    d.Dispose();
                }
                disposeList.Clear();
            }

            if (types.Contains(AssetType.SmallNpcGraphics))
            {
                DumpNpcTileset(props, "smallnpc", "SmallNPCs", AssetId.EnumerateAll(AssetType.SmallNpcGraphics));
            }
            Flush();

            if (types.Contains(AssetType.LargeNpcGraphics))
            {
                DumpNpcTileset(props, "largenpc", "LargeNPCs", AssetId.EnumerateAll(AssetType.LargeNpcGraphics));
            }
            Flush();

            if (types.Contains(AssetType.Object3D))
            {
            }

            if (types.Contains(AssetType.Floor))
            {
            }

            if (types.Contains(AssetType.Wall))
            {
            }

            if (types.Contains(AssetType.WallOverlay))
            {
            }

            if (types.Contains(AssetType.AutomapGraphics))
            {
            }

            if (types.Contains(AssetType.TilesetData))
            {
                foreach (TilesetId id in DumpUtil.All(AssetType.TilesetData, dumpIds))
                {
                    Dump2DTilemap(props, id);
                }

                Flush();
            }

            if (types.Contains(AssetType.Map))
            {
                foreach (var id in DumpUtil.All(AssetType.Map, dumpIds))
                {
                    if (assets.LoadMap(id) is MapData2D map2d)
                    {
                        Dump2DMap(map2d, assets, props);
                    }
                    //if (assets.LoadMap(id) is MapData3D map3d)
                    //    Dump3DMap(map3d, assets, props);
                }

                Flush();
            }

            /* TODO
             * if (types.Contains(AssetType.BlockList))
             * {
             *  foreach (var id in DumpUtil.All(AssetType.BlockList))
             *  {
             *      IList<Block> asset = assets.LoadBlockList(id);
             *      if (asset == null) continue;
             *      tw = Writer($"blocks/blocklist{id.Id}.json");
             *      s.Serialize(tw, asset);
             *  }
             *  Flush();
             * }
             * //*/
        }
예제 #3
0
 static void Dump2DTilemap(DumpProperties props, in TilesetId id)