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 static TileData InterpretTile(Tile tile, Tilemap2DProperties properties) { var result = new TileData { Index = (ushort)tile.Id, ImageNumber = SourceStringToImageNumber(tile.Image?.Source, properties), FrameCount = (byte)(tile.Frames?.Count ?? 0) }; if (result.FrameCount == 0 && tile.Image != null) { result.FrameCount = 1; } result.Layer = (TileLayer)Enum.Parse(typeof(TileLayer), PropString(tile, Prop.Layer) ?? "0"); result.Type = (TileType)Enum.Parse(typeof(TileType), PropString(tile, Prop.Type) ?? "0"); result.Collision = (Passability)Enum.Parse(typeof(Passability), PropString(tile, Prop.Collision) ?? "0"); result.SitMode = (SitMode)Enum.Parse(typeof(SitMode), PropString(tile, Prop.SitMode) ?? "0"); result.Unk7 = (byte)(PropInt(tile, Prop.Unk7) ?? 0); result.Unk12 = PropBool(tile, Prop.Unk12) ?? false; result.Unk18 = PropBool(tile, Prop.Unk18) ?? false; result.NoDraw = PropBool(tile, Prop.NoDraw) ?? false; result.DebugDot = PropBool(tile, Prop.DebugDot) ?? false; return(result); }
public static Tileset FromAlbion(TilesetData tileset, Tilemap2DProperties properties) { if (tileset == null) { throw new ArgumentNullException(nameof(tileset)); } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } List <Tile> tiles = tileset.Tiles .Where(x => !x.IsBlank) .Select(x => TileMapping.BuildTile( tileset.Id.Id, x.Index, x.FrameCount > 0 ? x.ImageNumber : null, TileMapping.BuildTileProperties(x), properties)) .ToList(); // Add tiles for the extra frames of animated tiles int nextId = tileset.Tiles[^ 1].Index + 1;
static TilesetData Load(AssetInfo info, Tilemap2DProperties properties, ISerializer serializer) { var xmlBytes = serializer.Bytes(null, null, (int)serializer.BytesRemaining); using var ms = new MemoryStream(xmlBytes); var tileset = Tileset.Parse(ms); return(tileset.ToAlbion(info.AssetId, properties)); }
static TilesetData Save(TilesetData tileset, Tilemap2DProperties properties, ISerializer s) { if (tileset == null) { throw new ArgumentNullException(nameof(tileset)); } var tiledTileset = Tileset.FromAlbion(tileset, properties); var bytes = FormatUtil.BytesFromTextWriter(tiledTileset.Serialize); s.Bytes(null, bytes, bytes.Length); return(tileset); }
static ushort SourceStringToImageNumber(string source, Tilemap2DProperties properties) { if (string.IsNullOrEmpty(source)) { return(0); } if (source == properties.BlankTilePath) { return(0xffff); } var(_, subId, _, _) = AssetInfo.ParseFilename(properties.GraphicsTemplate, source); return((ushort)subId); }
public static Tile BuildTile(int id, int index, ushort?imageNumber, List <TiledProperty> tileProperties, Tilemap2DProperties properties) { var source = imageNumber switch { null => null, 0xffff => properties.BlankTilePath, _ => string.Format(CultureInfo.InvariantCulture, properties.GraphicsTemplate, id, imageNumber ) }; return(new Tile { Id = index, Properties = tileProperties, Image = source == null ? null : new TilesetImage { Width = properties.TileWidth, Height = properties.TileHeight, Source = source } }); }
public static (Map, string) FromAlbionMap2D( MapData2D map, TilesetData tileset, Tilemap2DProperties properties, string tilesetPath, Tileset npcTileset, EventFormatter eventFormatter) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (tileset == null) { throw new ArgumentNullException(nameof(tileset)); } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } if (npcTileset == null) { throw new ArgumentNullException(nameof(npcTileset)); } int npcGidOffset = tileset.Tiles.Count; var(script, functionsByEventId) = BuildScript(map, eventFormatter); (int?tileId, int w, int h) GetNpcTileInfo(AssetId id) { var assetName = id.ToString(); var tile = npcTileset.Tiles.FirstOrDefault(x => x.Properties.Any(p => p.Name == NpcMapping.Prop.Visual && p.Value == assetName)); return( tile?.Id + npcGidOffset ?? 0, tile?.Image.Width ?? properties.TileWidth, tile?.Image.Height ?? properties.TileHeight); } int nextObjectId = 1; int nextLayerId = 1; var result = new Map { TiledVersion = "1.4.2", Version = "1.4", Width = map.Width, Height = map.Height, TileWidth = properties.TileWidth, TileHeight = properties.TileHeight, Infinite = 0, Orientation = "orthogonal", RenderOrder = "right-down", BackgroundColor = "#000000", Properties = MapMapping.BuildMapProperties(map), Tilesets = new List <MapTileset> { new() { FirstGid = 0, Source = tilesetPath, }, new() { FirstGid = npcGidOffset, Source = npcTileset.Filename } },