Ejemplo n.º 1
0
        void Rebuild()
        {
            var assets = Resolve <IAssetManager>();

            foreach (var id in AssetId.EnumerateAll(AssetType.Word))
            {
                var text = assets.LoadString(id);
                _lookup[text.Trim().ToUpperInvariant()] = id;
            }
        }
Ejemplo n.º 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();
             * }
             * //*/
        }
Ejemplo n.º 3
0
 public static IEnumerable <AssetId> All(AssetType type, AssetId[] dumpIds)
 => AssetId.EnumerateAll(type).Where(x => dumpIds == null || dumpIds.Contains(x));
Ejemplo n.º 4
0
        static void Labyrinths(IAssetManager assets, string baseDir)
        {
            using var sw = Open(baseDir, LabData);
            // Dump map and lab data
            for (int i = 100; i < 400; i++)
            {
                if (!(assets.LoadMap((Base.Map)i) is MapData3D map))
                {
                    continue;
                }

                sw.WriteLine($"{i} {(Base.Map)i} {map.Width}x{map.Height} L{map.LabDataId.Id} P{map.PaletteId.Id}:{map.PaletteId}");
                var floors = map.Floors.GroupBy(x => x).Select(x => (x.Key, x.Count())).OrderBy(x => x.Key);
                sw.WriteLine("    Floors: " + string.Join(" ", floors.Select(x => $"{x.Key}:{x.Item2}")));
                var ceilings = map.Ceilings.GroupBy(x => x).Select(x => (x.Key, x.Count())).OrderBy(x => x.Key);
                sw.WriteLine("    Ceilings: " + string.Join(" ", ceilings.Select(x => $"{x.Key}:{x.Item2}")));
                var contents = map.Contents.GroupBy(x => x).Select(x => (x.Key, x.Count())).OrderBy(x => x.Key);
                sw.WriteLine("    Contents: " + string.Join(" ", contents.Select(x => $"{x.Key}:{x.Item2}")));

                var l = assets.LoadLabyrinthData(map.LabDataId);
                if (l == null)
                {
                    continue;
                }

                foreach (var(content, _) in contents)
                {
                    if (content == 0 || content >= l.ObjectGroups.Count)
                    {
                        continue;
                    }

                    var objectInfo = l.ObjectGroups[content - 1];

                    sw.Write($"        {content}: ");
                    foreach (var subObject in objectInfo.SubObjects)
                    {
                        var definition = l.Objects[subObject.ObjectInfoNumber];
                        sw.Write(definition.SpriteId);
                        sw.Write(" ");
                    }

                    sw.WriteLine();
                }
            }

            var labIds = AssetId.EnumerateAll(AssetType.Labyrinth);

            foreach (var id in labIds)
            {
                var l = assets.LoadLabyrinthData(id);
                if (l == null)
                {
                    continue;
                }

                sw.WriteLine($"{id}");
                for (int j = 0; j < l.FloorAndCeilings.Count; j++)
                {
                    var fc = l.FloorAndCeilings[j];
                    sw.WriteLine($"    F/C {j}: {fc.SpriteId} {fc.AnimationCount}");
                }

                for (int j = 0; j < l.Walls.Count; j++)
                {
                    var w = l.Walls[j];
                    sw.WriteLine($"    W {j}: {w.SpriteId} {w.AnimationFrames} P{w.TransparentColour}");
                }

                for (int j = 0; j < l.ObjectGroups.Count; j++)
                {
                    var o = l.ObjectGroups[j];
                    sw.WriteLine(
                        $"    Obj {j}: {o.AutoGraphicsId} [{string.Join(", ", o.SubObjects.Select(x => x.ObjectInfoNumber.ToString(CultureInfo.InvariantCulture)))}]");
                }

                for (int j = 0; j < l.Objects.Count; j++)
                {
                    var o = l.Objects[j];
                    sw.WriteLine(
                        $"    Extra {j}: {o.SpriteId} {o.AnimationFrames} {o.Width}x{o.Height} M:{o.MapWidth}x{o.MapHeight}");
                }
            }
        }