public ListStringCollection Serdes(ListStringCollection existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s.IsReading()) { ApiUtil.Assert(s.BytesRemaining % WordLength == 0, "Expected word list file length to be a whole multiple of the string size"); var strings = new List <string>(); while (!s.IsComplete()) { strings.Add(s.FixedLengthString(null, null, WordLength)); } return(new ListStringCollection(strings)); } else { if (existing == null) { throw new ArgumentNullException(nameof(existing)); } foreach (var x in existing) { if (x is { Length: > WordLength })
public CharacterHistoryUtil(IJsonUtil jsonUtil) { _jsonUtil = jsonUtil; }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => Serdes(existing as SpellData, info, mapping, s, jsonUtil);
public OplogsController(IConnection rabbitConnection, IMapper mapper, IJsonUtil jsonUtil) { _rabbitConnection = rabbitConnection; _mapper = mapper; _jsonUtil = jsonUtil; }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (jsonUtil == null) { throw new ArgumentNullException(nameof(jsonUtil)); } var bytes = s.Bytes(null, null, (int)s.BytesRemaining); return(jsonUtil.Deserialize <IntStringDictionary>(bytes)); }
public ISample Serdes(ISample w, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (s.IsWriting() && w == null) { throw new ArgumentNullException(nameof(w)); } w ??= new AlbionSample(); var tag = s.FixedLengthString("Tag", "RIFF", 4); // Container format chunk ApiUtil.Assert(tag == "RIFF", "tag == 'RIFF'"); var riffSizeOffset = s.Offset; int fullSize = s.Int32("TotalSize", 0); // Dummy write to start with, will be overwritten at the end. tag = s.FixedLengthString(null, "WAVE", 4); ApiUtil.Assert(tag == "WAVE", "tag == 'WAVE'"); SerdesFormatTag(w, s); SerdesDataTag(w, s); if (s.IsWriting()) { int offset = (int)s.Offset; s.Seek(riffSizeOffset); s.UInt32("TotalSize", (uint)s.Offset - 4); // Write actual length to container format chunk s.Seek(offset); } else { ApiUtil.Assert(fullSize == (int)s.Offset - 4, "Full size of WAV doesn't match bytes read"); } return(w); }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => Serdes((IReadOnlyTexture <byte>)existing, info, mapping, s, jsonUtil);
public TilesetData Serdes(TilesetData existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => TilesetData.Serdes(existing, s, info);
public GroupConfigUtil(IJsonUtil jsonUtil) { _jsonUtil = jsonUtil; }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => Serdes((MultiLanguageStringDictionary)existing, info, mapping, s, jsonUtil);
public MultiLanguageStringDictionary Serdes(MultiLanguageStringDictionary names, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (s.IsWriting() && names == null) { throw new ArgumentNullException(nameof(names)); } names ??= new MultiLanguageStringDictionary(); if (!names.ContainsKey(Base.Language.German)) { names[Base.Language.German] = new ListStringCollection(); } if (!names.ContainsKey(Base.Language.English)) { names[Base.Language.English] = new ListStringCollection(); } if (!names.ContainsKey(Base.Language.French)) { names[Base.Language.French] = new ListStringCollection(); }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => Serdes(existing as CharacterSheet, info, mapping, s, jsonUtil);
public CharacterSheet Serdes(CharacterSheet existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } return(CharacterSheet.Serdes(info.AssetId, existing, mapping, s, Resolve <ISpellManager>())); }
public IMapData Serdes(IMapData existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } return(BaseMapData.Serdes(info, existing, mapping, s)); }
public Script Serdes(Script script, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (s.IsReading()) { script = new Script(); foreach (var line in ReadLines(s)) { IEvent e; if (string.IsNullOrEmpty(line)) { e = new CommentEvent(null); } else if (line.StartsWith(";", StringComparison.Ordinal)) { e = new CommentEvent(line[1..]);
public ListStringCollection Serdes(ListStringCollection existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (s.IsReading()) { var stringCount = s.UInt16("StringCount", 0); var stringLengths = new int[stringCount]; for (int i = 0; i < stringCount; i++) { stringLengths[i] = s.UInt16(null, 0); } var strings = new string[stringCount]; for (int i = 0; i < stringCount; i++) { strings[i] = s.FixedLengthString(null, null, stringLengths[i]); } return(new ListStringCollection(strings)); } else { if (existing == null) { throw new ArgumentNullException(nameof(existing)); } var stringCount = s.UInt16("StringCount", (ushort)existing.Count); var byteArrays = existing.Select(FormatUtil.BytesFrom850String).ToArray(); for (int i = 0; i < stringCount; i++) { s.UInt16(null, (ushort)(byteArrays[i].Length + 1)); } for (int i = 0; i < stringCount; i++) { s.Bytes(null, byteArrays[i], byteArrays[i].Length); s.UInt8(null, 0); } return(existing); } }
public TilesetData Serdes(TilesetData 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)); } var graphicsId = ((TilesetId)info.AssetId).ToTilesetGraphics(); var graphicsTemplate = info.Get(AssetProperty.GraphicsPattern, "{0}/{0}_{1}.png"); var blankTilePath = info.Get(AssetProperty.BlankTilePath, "Blank.png"); var properties = new Tilemap2DProperties { GraphicsTemplate = graphicsTemplate, BlankTilePath = blankTilePath, TilesetId = graphicsId.Id, TileWidth = 16, TileHeight = 16 }; return(s.IsWriting() ? Save(existing, properties, s) : Load(info, properties, s)); }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => Serdes(existing as ListStringCollection, info, mapping, s, jsonUtil);
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => Serdes((ISample)existing, info, mapping, s, jsonUtil);
public MultiLanguageStringDictionary Serdes(MultiLanguageStringDictionary existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } if (s.IsWriting()) { return(existing); } var assets = Resolve <IAssetManager>(); var ids = mapping.EnumerateAssetsOfType(AssetType.ItemName) // make sure TextId->StringId resolution won't happen // and get stuck in infinite recursion .Select(x => new StringId(x, 0)) .ToArray(); var german = ids.ToDictionary(x => x.Id.Id, x => assets.LoadString(x, Base.Language.German)); var english = ids.ToDictionary(x => x.Id.Id, x => assets.LoadString(x, Base.Language.English)); var french = ids.ToDictionary(x => x.Id.Id, x => assets.LoadString(x, Base.Language.French));
public IReadOnlyTexture <byte> Serdes(IReadOnlyTexture <byte> 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)); } var paletteNum = info.Get(AssetProperty.PaletteId, 0); var paletteId = new PaletteId(AssetType.Palette, paletteNum); var palette = Resolve <IAssetManager>().LoadPalette(paletteId); if (palette == null) { throw new InvalidOperationException($"Could not load palette {paletteId} ({paletteNum}) for asset {info.AssetId} in file {info.File.Filename}"); } var unambiguousPalette = palette.GetUnambiguousPalette(); if (s.IsWriting()) { if (existing == null) { throw new ArgumentNullException(nameof(existing)); } var encoder = new PngEncoder(); PackedChunks.Pack(s, existing.Regions.Count, frameNum => Write(encoder, unambiguousPalette, existing, frameNum)); return(existing); } // Read var decoder = new PngDecoder(); var configuration = new Configuration(); var images = new List <Image <Rgba32> >(); try { foreach (var(bytes, _) in PackedChunks.Unpack(s)) { using var stream = new MemoryStream(bytes); images.Add(decoder.Decode <Rgba32>(configuration, stream)); } return(Read(info.AssetId, unambiguousPalette, images)); } finally { foreach (var image in images) { image.Dispose(); } } }
public ItemData Serdes(ItemData existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => ItemData.Serdes(info, existing, s, Resolve <ISpellManager>());
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { var oplFile = GlobalTimbreLibrary.Serdes(null, s); WoplFile wopl = new WoplFile(oplFile); return(GetRawWoplBytes(wopl)); }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) => new FlicFile(s);
public Inventory Serdes(Inventory existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } return(Inventory.SerdesMerchant(info.AssetId.ToInt32(), existing, mapping, s)); }
public GroupHistoryUtil(IJsonUtil jsonUtil) { _jsonUtil = jsonUtil; }
public SpellData Serdes(SpellData 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)); } return(SpellData.Serdes(existing, info, s)); }
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; }
public ISerializer Read(string file, AssetInfo info, IFileSystem disk, IJsonUtil jsonUtil) { throw new System.NotImplementedException(); }
public byte[] Serdes(byte[] existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (s.IsReading()) { return(s.Bytes(null, null, (int)s.BytesRemaining)); } if (existing == null) { throw new ArgumentNullException(nameof(existing)); } s.Bytes(null, existing, existing.Length); return(existing); }