public static bool TryParseDimensions(string format, out SpriteFormat spriteFormat) { spriteFormat = default; var formatContent = format.Substring(4, format.Length - 5); // snip leading "`xxx" and trailing "`" var hintSplit = formatContent.Split('|'); var dimensionsAsText = hintSplit[0].Split('x'); if (dimensionsAsText.Length != 3) { return(false); } var allowLengthErrors = dimensionsAsText[2].EndsWith("!"); if (allowLengthErrors) { dimensionsAsText[2] = dimensionsAsText[2].Substring(0, dimensionsAsText[2].Length - 1); } if (!int.TryParse(dimensionsAsText[0], out var bitsPerPixel)) { return(false); } if (!int.TryParse(dimensionsAsText[1], out var width)) { return(false); } if (!int.TryParse(dimensionsAsText[2], out var height)) { return(false); } var hint = hintSplit.Length == 2 ? hintSplit[1] : null; spriteFormat = new SpriteFormat(bitsPerPixel, width, height, hint, allowLengthErrors); return(true); }
public static bool TryParseSpriteFormat(string pointerFormat, out SpriteFormat spriteFormat) { spriteFormat = default; if (!pointerFormat.StartsWith("`lzs") || !pointerFormat.EndsWith("`")) { return(false); } return(TryParseDimensions(pointerFormat, out spriteFormat)); }
public SpriteRun(int start, SpriteFormat format, SortedSpan <int> sources = null) : base(start, sources) { SpriteFormat = format; bitsPerPixel = format.BitsPerPixel; tileWidth = format.TileWidth; tileHeight = format.TileHeight; Length = tileWidth * tileHeight * bitsPerPixel * 8; FormatString = $"`ucs{bitsPerPixel}x{tileWidth}x{tileHeight}"; if (!string.IsNullOrEmpty(format.PaletteHint)) { FormatString += "|" + format.PaletteHint; } FormatString += "`"; }
public LzSpriteRun(SpriteFormat spriteFormat, IDataModel data, int start, SortedSpan <int> sources = null) : base(data, start, spriteFormat.AllowLengthErrors, sources) { SpriteFormat = spriteFormat; if (spriteFormat.ExpectedByteLength > DecompressedLength) { InvalidateLength(); } var hintContent = string.Empty; if (!string.IsNullOrEmpty(spriteFormat.PaletteHint)) { hintContent += "|" + spriteFormat.PaletteHint; } FormatString = $"`lzs{spriteFormat.BitsPerPixel}x{spriteFormat.TileWidth}x{spriteFormat.TileHeight}{hintContent}`"; }
public TilemapRun(IDataModel model, int start, TilemapFormat format, SortedSpan <int> sources = null) : base(start, sources) { Model = model; Format = format; string hint = null; var address = Model.GetAddressFromAnchor(new NoDataChangeDeltaModel(), -1, Format.MatchingTileset); if (address >= 0 && address < Model.Count) { var tileset = Model.GetNextRun(address) as ISpriteRun; if (tileset == null) { tileset = Model.GetNextRun(arrayTilesetAddress) as ISpriteRun; } if (tileset != null && !(tileset is LzTilemapRun)) { hint = tileset.SpriteFormat.PaletteHint; } } SpriteFormat = new SpriteFormat(format.BitsPerPixel, format.TileWidth, format.TileHeight, hint); }
public LzSpriteRun IncreaseHeight(int tiles, ModelDelta token) { var data = Decompress(Model, Start); var longerData = data.Concat(new byte[SpriteFormat.ExpectedByteLength / SpriteFormat.TileHeight * tiles]).ToArray(); var newModelData = Compress(longerData, 0, longerData.Length); var newRun = Model.RelocateForExpansion(token, this, newModelData.Count); for (int i = 0; i < newModelData.Count; i++) { token.ChangeData(Model, newRun.Start + i, newModelData[i]); } for (int i = newModelData.Count; i < Length; i++) { token.ChangeData(Model, newRun.Start + i, 0xFF); } var newFormat = new SpriteFormat(SpriteFormat.BitsPerPixel, SpriteFormat.TileWidth, SpriteFormat.TileHeight + tiles, SpriteFormat.PaletteHint, SpriteFormat.AllowLengthErrors); newRun = new LzSpriteRun(newFormat, Model, newRun.Start, newRun.PointerSources); Model.ObserveRunWritten(token, newRun); return(newRun); }
public ISpriteRun Duplicate(SpriteFormat newFormat) { throw new System.NotImplementedException(); }
public ISpriteRun Duplicate(SpriteFormat format) => new LzSpriteRun(format, Model, Start, PointerSources);
public ISpriteRun Duplicate(SpriteFormat format) => new LzTilesetRun(new TilesetFormat(format.BitsPerPixel, TilesetFormat.Tiles, TilesetFormat.MaxTiles, format.PaletteHint), Model, Start, PointerSources);
public ISpriteRun Duplicate(SpriteFormat format) => new SpriteRun(Start, format, PointerSources);
public ISpriteRun Duplicate(SpriteFormat newFormat) => new SpriteRun(model, Start, newFormat, PointerSources);