protected override void Subscribed() { Raise(new LoadPaletteEvent(_logicalMap.PaletteId)); if (_tilemap != null) { return; } var assets = Resolve <IAssetManager>(); _properties.TileCount = _logicalMap.Width * _logicalMap.Height; _properties.DayPalette = assets.LoadPalette(_logicalMap.PaletteId); if (NightPalettes.TryGetValue(_logicalMap.PaletteId, out var nightPaletteId)) { _properties.NightPalette = assets.LoadPalette(nightPaletteId); } var etmManager = Resolve <IEtmManager>(); _tilemap = etmManager.CreateTilemap(_properties); for (int i = 0; i < _labyrinthData.FloorAndCeilings.Count; i++) { var floorInfo = _labyrinthData.FloorAndCeilings[i]; _tilemap.DefineFloor(i + 1, assets.LoadTexture(floorInfo?.SpriteId ?? AssetId.None)); } for (int i = 0; i < _labyrinthData.Walls.Count; i++) { var wallInfo = _labyrinthData.Walls[i]; if (wallInfo == null) { continue; } ITexture wall = assets.LoadTexture(wallInfo.SpriteId); if (wall == null) { continue; } bool isAlphaTested = (wallInfo.Properties & Wall.WallFlags.AlphaTested) != 0; _tilemap.DefineWall(i + 1, wall, 0, 0, wallInfo.TransparentColour, isAlphaTested); foreach (var overlayInfo in wallInfo.Overlays) { if (overlayInfo.SpriteId.IsNone) { continue; } var overlay = assets.LoadTexture(overlayInfo.SpriteId); _tilemap.DefineWall(i + 1, overlay, overlayInfo.XOffset, overlayInfo.YOffset, wallInfo.TransparentColour, isAlphaTested); } } _fullUpdate = true; }
public void Load(LabyrinthData labyrinthData, AssetInfo info, IsometricMode mode, TilemapRequest request, int?paletteNumber, IAssetManager assets) { if (labyrinthData == null) { throw new ArgumentNullException(nameof(labyrinthData)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (assets == null) { throw new ArgumentNullException(nameof(assets)); } RemoveAllChildren(); bool floors = mode is IsometricMode.Floors or IsometricMode.All; bool ceilings = mode is IsometricMode.Ceilings or IsometricMode.All; bool walls = mode is IsometricMode.Walls or IsometricMode.All; bool contents = mode is IsometricMode.Contents or IsometricMode.All; paletteNumber ??= info.Get(AssetProperty.PaletteId, 0); var paletteId = new PaletteId(AssetType.Palette, paletteNumber.Value); var palette = assets.LoadPalette(paletteId); if (palette == null) { Error($"Could not load palette {paletteNumber}"); palette = assets.LoadPalette(Base.Palette.Common); } else { Raise(new LoadPaletteEvent(paletteId)); } var etmManager = Resolve <IEtmManager>(); request.Pipeline = DungeonTilemapPipeline.NoCulling; request.DayPalette = palette; _tilemap = etmManager.CreateTilemap(request /*labyrinthData.Id, 0, request, palette, null, DungeonTilemapPipeline.NoCulling */); // Layout: // [Empty] [First frame of all floors] [First frame of all ceilings] [First frame of all walls] [Additional floor frames] [Additional ceiling frames] [Additional wall frames] int totalTiles = 1; if (floors || ceilings) { for (int i = 0; i < labyrinthData.FloorAndCeilings.Count; i++) { var floorInfo = labyrinthData.FloorAndCeilings[i]; var floor = floorInfo == null ? null : assets.LoadTexture(floorInfo.SpriteId); _tilemap.DefineFloor(i + 1, floor); if (floors) { totalTiles += _tilemap.DayFloors.GetFrameCountForLogicalId(i + 1); } if (ceilings) { totalTiles += _tilemap.DayFloors.GetFrameCountForLogicalId(i + 1); } } } if (walls) { for (int i = 0; i < labyrinthData.Walls.Count; i++) { var wallInfo = labyrinthData.Walls[i]; bool isAlphaTested = wallInfo != null && (wallInfo.Properties & Wall.WallFlags.AlphaTested) != 0; var wall = wallInfo == null ? null : assets.LoadTexture(wallInfo.SpriteId); _tilemap.DefineWall(i + 1, wall, 0, 0, wallInfo?.TransparentColour ?? 0, isAlphaTested); foreach (var overlayInfo in wallInfo?.Overlays ?? Array.Empty <Overlay>()) { if (overlayInfo.SpriteId.IsNone) { continue; } var overlay = assets.LoadTexture(overlayInfo.SpriteId); _tilemap.DefineWall(i + 1, overlay, overlayInfo.XOffset, overlayInfo.YOffset, wallInfo?.TransparentColour ?? 0, isAlphaTested); } totalTiles += _tilemap.DayWalls.GetFrameCountForLogicalId(i + 1); } } if (contents) { var transparent = new SimpleTexture <byte>(AssetId.None, "Transparent", 1, 1, new byte[] { 0 }) .AddRegion(Vector2.Zero, Vector2.One, 0); for (byte i = 1; i <= labyrinthData.ObjectGroups.Count; i++) { _tilemap.DefineWall(i, transparent, 0, 0, 0, true); } totalTiles += labyrinthData.ObjectGroups.Count; } _wallCount = labyrinthData.Walls.Count; _floors = new byte[totalTiles]; _ceilings = new byte[totalTiles]; _contents = new byte[totalTiles]; var frames = new int[totalTiles]; int index = 1; // Add initial frames if (floors) { FloorFrames = new List <int> [labyrinthData.FloorAndCeilings.Count + 1]; FloorFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { _floors[index] = i; FloorFrames[i] = new List <int> { index }; index++; } } if (ceilings) { CeilingFrames = new List <int> [labyrinthData.FloorAndCeilings.Count + 1]; CeilingFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { _ceilings[index] = i; CeilingFrames[i] = new List <int> { index }; index++; } } if (walls) { WallFrames = new List <int> [labyrinthData.Walls.Count + 1]; WallFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.Walls.Count; i++) { _contents[index] = (byte)(i + 100); WallFrames[i] = new List <int> { index }; index++; } } if (contents) { ContentsFrames = new List <int> [labyrinthData.ObjectGroups.Count + 1]; ContentsFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.ObjectGroups.Count; i++) { _contents[index] = i; ContentsFrames[i] = new List <int> { index }; index++; } } // Add animation frames if (floors) { for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { int frameCount = _tilemap.DayFloors.GetFrameCountForLogicalId(i); for (int j = 1; j < frameCount; j++) { _floors[index] = i; FloorFrames[i].Add(index); frames[index++] = j; } } } if (ceilings) { for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { int frameCount = _tilemap.DayFloors.GetFrameCountForLogicalId(i); for (int j = 1; j < frameCount; j++) { _ceilings[index] = i; CeilingFrames[i].Add(index); frames[index++] = j; } } } if (walls) { for (byte i = 1; i <= labyrinthData.Walls.Count; i++) { int frameCount = _tilemap.DayWalls.GetFrameCountForLogicalId(i); for (int j = 1; j < frameCount; j++) { _contents[index] = (byte)(i + 100); WallFrames[i].Add(index); frames[index++] = j; } } } _tilemap.TileCount = totalTiles; for (int i = 0; i < totalTiles; i++) { SetTile(i, i, frames[i]); } for (int i = 0; i < totalTiles; i++) { AddSprites(labyrinthData, i, request); } }