예제 #1
0
    public void Dump(string baseDir, ISet <AssetType> types, AssetId[] dumpIds)
    {
        var applier = Resolve <IModApplier>();

        void Write(string name, string content)
        {
            var filename  = Path.Combine(baseDir, "data", "exported", "annotated", name);
            var directory = Path.GetDirectoryName(filename);

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

            File.WriteAllText(filename, content);
        }

        foreach (var type in types)
        {
            foreach (var id in DumpUtil.All(type, dumpIds))
            {
                var notes = applier.LoadAssetAnnotated(id, Language.English);
                var name  = ConfigUtil.AssetName(id);
                Write($"{type}\\{id.Id}_{name}.txt", notes);
            }
        }
    }
예제 #2
0
        public BlockList Serdes(BlockList existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
        {
            if (info == null) throw new ArgumentNullException(nameof(info));
            if (s == null) throw new ArgumentNullException(nameof(s));
            if (jsonUtil == null) throw new ArgumentNullException(nameof(jsonUtil));

            if (s.IsWriting())
            {
                if (existing == null) throw new ArgumentNullException(nameof(existing));

                var blockListId = (BlockListId)info.AssetId;
                var tilesetId = blockListId.ToTileset();

                var tilesetPattern = info.Get(AssetProperty.TilesetPattern, "../Tilesets/{0}_{2}.tsx");
                var tilesetPath = string.Format(CultureInfo.InvariantCulture,
                    tilesetPattern,
                    tilesetId.Id,
                    0,
                    ConfigUtil.AssetName(tilesetId));

                var tileset = new Tileset
                {
                    Filename = tilesetPath,
                    TileWidth = 16,
                    TileHeight = 16,
                };

                PackedChunks.Pack(s, existing.Count, stampNumber =>
                {
                    if (existing[stampNumber].Width == 0 || existing[stampNumber].Height == 0)
                        return Array.Empty<byte>();
                    var stamp = new Stamp(stampNumber, existing[stampNumber], tileset);
                    return Encoding.UTF8.GetBytes(stamp.Serialize(jsonUtil));
                });

                return existing;
            }

            var list = new BlockList();
            foreach (var (jsonBytes, _) in PackedChunks.Unpack(s))
            {
                var stamp = Stamp.Parse(jsonBytes, jsonUtil);
                var block = stamp != null ? stamp.ToBlock() : new Block();
                list.Add(block);
            }

            while (list.Count < BlockList.MaxCount)
                list.Add(new Block());

            return list;
        }