Skip to content

Commit f0a2837

Browse files
committed
Fix several bugs where cell lighting values were not updated on cell level change
1 parent 2a6a224 commit f0a2837

6 files changed

Lines changed: 57 additions & 29 deletions

File tree

src/TSMapEditor/Mutations/Classes/DrawCliffMutation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ private void PlaceTile(TileImage tile, Point2D targetCellCoords)
176176

177177
mapTile.ChangeTileIndex(tile.TileID, (byte)i);
178178
mapTile.Level = (byte)Math.Min(originLevel + image.TmpImage.Height, Constants.MaxMapHeightLevel);
179+
mapTile.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
179180
}
180181
}
181182
}
@@ -191,6 +192,7 @@ public override void Undo()
191192
{
192193
mapTile.ChangeTileIndex(data.TileIndex, data.SubTileIndex);
193194
mapTile.Level = data.Level;
195+
mapTile.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
194196
}
195197
}
196198

src/TSMapEditor/Mutations/Classes/HeightMutations/AlterElevationMutationBase.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected void Process()
9292

9393
ApplyRamps();
9494

95+
RefreshLighting();
96+
9597
MutationTarget.InvalidateMap();
9698
}
9799

@@ -118,13 +120,24 @@ protected void ProcessCells()
118120

119121
protected abstract void ApplyRamps();
120122

123+
private void RefreshLighting()
124+
{
125+
for (int i = 0; i < totalProcessedCells.Count; i++)
126+
{
127+
var cellCoords = totalProcessedCells[i];
128+
var cell = Map.GetTile(cellCoords);
129+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
130+
}
131+
}
132+
121133
public override void Undo()
122134
{
123135
foreach (var entry in undoData)
124136
{
125137
var cell = Map.GetTile(entry.CellCoords);
126138
cell.ChangeTileIndex(entry.TileIndex, (byte)entry.SubTileIndex);
127139
cell.Level = (byte)entry.HeightLevel;
140+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
128141
}
129142

130143
MutationTarget.InvalidateMap();

src/TSMapEditor/Mutations/Classes/HeightMutations/LowerCellsMutation.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using TSMapEditor.GameMath;
3+
using TSMapEditor.Models;
34
using TSMapEditor.Rendering;
45
using TSMapEditor.UI;
56

@@ -32,38 +33,38 @@ public override void Perform()
3233
Point2D cellCoords = targetCellCoords + offset;
3334

3435
var cell = MutationTarget.Map.GetTile(cellCoords);
35-
if (cell == null)
36-
return;
37-
38-
if (cell.Level > 0)
39-
{
40-
cell.Level--;
41-
affectedCells.Add(cellCoords);
42-
}
36+
LowerCellLevel(cell);
4337
});
4438
}
4539
else
4640
{
4741
var targetTile = MutationTarget.Map.GetTile(targetCellCoords);
48-
49-
if (targetTile == null || targetTile.Level <= 0)
50-
return;
51-
5242
var tilesToProcess = Helpers.GetFillAreaTiles(targetTile, MutationTarget.Map, MutationTarget.TheaterGraphics);
5343

5444
// Process tiles
5545
foreach (Point2D cellCoords in tilesToProcess)
5646
{
5747
var cell = MutationTarget.Map.GetTile(cellCoords);
58-
59-
cell.Level--;
60-
affectedCells.Add(cellCoords);
48+
LowerCellLevel(cell);
6149
}
6250
}
6351

6452
MutationTarget.AddRefreshPoint(targetCellCoords);
6553
}
6654

55+
private void LowerCellLevel(MapTile cell)
56+
{
57+
if (cell == null)
58+
return;
59+
60+
if (cell.Level > 0)
61+
{
62+
cell.Level--;
63+
affectedCells.Add(cell.CoordsToPoint());
64+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
65+
}
66+
}
67+
6768
public override void Undo()
6869
{
6970
foreach (Point2D cellCoords in affectedCells)
@@ -73,7 +74,10 @@ public override void Undo()
7374
return;
7475

7576
if (cell.Level < Constants.MaxMapHeight)
77+
{
7678
cell.Level++;
79+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
80+
}
7781
}
7882

7983
MutationTarget.AddRefreshPoint(targetCellCoords);

src/TSMapEditor/Mutations/Classes/HeightMutations/RaiseCellsMutation.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using TSMapEditor.GameMath;
3+
using TSMapEditor.Models;
34
using TSMapEditor.Rendering;
45
using TSMapEditor.UI;
56

@@ -32,38 +33,39 @@ public override void Perform()
3233
Point2D cellCoords = targetCellCoords + offset;
3334

3435
var cell = MutationTarget.Map.GetTile(cellCoords);
35-
if (cell == null)
36-
return;
3736

38-
if (cell.Level < Constants.MaxMapHeightLevel)
39-
{
40-
cell.Level++;
41-
affectedCells.Add(cellCoords);
42-
}
37+
RaiseCellLevel(cell);
4338
});
4439
}
4540
else
4641
{
4742
var targetTile = MutationTarget.Map.GetTile(targetCellCoords);
48-
49-
if (targetTile == null || targetTile.Level >= Constants.MaxMapHeightLevel)
50-
return;
51-
5243
var tilesToProcess = Helpers.GetFillAreaTiles(targetTile, MutationTarget.Map, MutationTarget.TheaterGraphics);
5344

5445
// Process tiles
5546
foreach (Point2D cellCoords in tilesToProcess)
5647
{
5748
var cell = MutationTarget.Map.GetTile(cellCoords);
58-
59-
cell.Level++;
60-
affectedCells.Add(cellCoords);
49+
RaiseCellLevel(cell);
6150
}
6251
}
6352

6453
MutationTarget.AddRefreshPoint(targetCellCoords);
6554
}
6655

56+
private void RaiseCellLevel(MapTile cell)
57+
{
58+
if (cell == null)
59+
return;
60+
61+
if (cell.Level < Constants.MaxMapHeightLevel)
62+
{
63+
cell.Level++;
64+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
65+
affectedCells.Add(cell.CoordsToPoint());
66+
}
67+
}
68+
6769
public override void Undo()
6870
{
6971
foreach (Point2D cellCoords in affectedCells)
@@ -73,7 +75,10 @@ public override void Undo()
7375
return;
7476

7577
if (cell.Level > 0)
78+
{
7679
cell.Level--;
80+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
81+
}
7782
}
7883

7984
MutationTarget.AddRefreshPoint(targetCellCoords);

src/TSMapEditor/Mutations/Classes/PlaceTerrainTileMutation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public override void Perform()
116116
{
117117
mapTile.ChangeTileIndex(tile.TileID, (byte)i);
118118
mapTile.Level = (byte)Math.Min(originLevel + image.TmpImage.Height, Constants.MaxMapHeightLevel);
119+
mapTile.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
119120
}
120121
}
121122
});
@@ -309,6 +310,7 @@ public override void Undo()
309310
{
310311
mapCell.ChangeTileIndex(originalTerrainData.TileIndex, originalTerrainData.SubTileIndex);
311312
mapCell.Level = originalTerrainData.Level;
313+
mapCell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
312314
}
313315
}
314316

src/TSMapEditor/Rendering/MapView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface IMutationTarget
3434
BrushSize BrushSize { get; }
3535
Randomizer Randomizer { get; }
3636
bool AutoLATEnabled { get; }
37+
LightingPreviewMode LightingPreviewState { get; }
3738
bool OnlyPaintOnClearGround { get; }
3839
}
3940

@@ -119,6 +120,7 @@ public MapView(WindowManager windowManager, Map map, TheaterGraphics theaterGrap
119120
public BrushSize BrushSize { get => EditorState.BrushSize; set => EditorState.BrushSize = value; }
120121
public bool Is2DMode => EditorState.Is2DMode;
121122
public DeletionMode DeletionMode => EditorState.DeletionMode;
123+
public LightingPreviewMode LightingPreviewState => EditorState.LightingPreviewState;
122124
public Randomizer Randomizer => EditorState.Randomizer;
123125
public bool AutoLATEnabled => EditorState.AutoLATEnabled;
124126
public bool OnlyPaintOnClearGround => EditorState.OnlyPaintOnClearGround;

0 commit comments

Comments
 (0)