public DumpProperties(IAssetManager assets, PaletteHints hints, string tilesetDir, string exportDir, Func <string, TextWriter> getWriter) { Assets = assets; Hints = hints; TilesetDir = tilesetDir; ExportDir = exportDir; GetWriter = getWriter; }
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(); * } * //*/ }