Compare commits

...

1 Commits

Author SHA1 Message Date
Savya Bikram Shah
df43824fb1 Back button bug fix 2026-07-07 15:53:13 +05:45
4 changed files with 1987 additions and 77 deletions

View File

@@ -46,6 +46,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
private string _templateId; private string _templateId;
private DrawingPhase _phase = DrawingPhase.ShapeBuilding; private DrawingPhase _phase = DrawingPhase.ShapeBuilding;
private bool _allContentReported; private bool _allContentReported;
private bool _navigating;
private float _lastThumbnailTime = float.NegativeInfinity; private float _lastThumbnailTime = float.NegativeInfinity;
private IDisposable _assembledSub; private IDisposable _assembledSub;
@@ -165,6 +166,13 @@ namespace Darkmatter.Features.GameplayFlow.Systems
} }
public async UniTask BackAsync(CancellationToken ct) public async UniTask BackAsync(CancellationToken ct)
{
// A second navigation while one runs (e.g. Back pressed during the completion
// animation inside NextAsync) would interleave two saves and two Colorbook loads,
// and Clear() would rip the celebration apart mid-flight. First navigation wins.
if (_navigating) return;
_navigating = true;
try
{ {
await SaveCurrentAsync(CancellationToken.None); await SaveCurrentAsync(CancellationToken.None);
_loadingScreen.Show(); _loadingScreen.Show();
@@ -173,6 +181,11 @@ namespace Darkmatter.Features.GameplayFlow.Systems
await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: ct); await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: ct);
await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: ct); await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: ct);
} }
finally
{
_navigating = false;
}
}
public async UniTask SaveAsync(CancellationToken ct) public async UniTask SaveAsync(CancellationToken ct)
{ {
@@ -183,6 +196,10 @@ namespace Darkmatter.Features.GameplayFlow.Systems
} }
public async UniTask NextAsync(CancellationToken ct) public async UniTask NextAsync(CancellationToken ct)
{
if (_navigating) return;
_navigating = true;
try
{ {
// Drop any debounced autosave so it can't fire during/after the completion // Drop any debounced autosave so it can't fire during/after the completion
// animation and capture the animation (or an empty paper) into the thumbnail. // animation and capture the animation (or an empty paper) into the thumbnail.
@@ -210,23 +227,19 @@ namespace Darkmatter.Features.GameplayFlow.Systems
} }
var nextId = _catalog.GetNextTemplate(_templateId); var nextId = _catalog.GetNextTemplate(_templateId);
if (string.IsNullOrEmpty(nextId))
{
_loadingScreen.Show();
_shapeBuilder.Clear();
_coloring.Clear();
await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: default);
await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default);
return;
}
_loadingScreen.Show(); _loadingScreen.Show();
_shapeBuilder.Clear(); _shapeBuilder.Clear();
_coloring.Clear(); _coloring.Clear();
await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: default); await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: default);
await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default); await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default);
if (!string.IsNullOrEmpty(nextId))
_bus.Publish(new DrawingSelectedSignal(nextId)); _bus.Publish(new DrawingSelectedSignal(nextId));
} }
finally
{
_navigating = false;
}
}
private void OnShapeAssembled(ShapeAssembledSignal signal) private void OnShapeAssembled(ShapeAssembledSignal signal)
@@ -269,6 +282,10 @@ namespace Darkmatter.Features.GameplayFlow.Systems
} }
private async UniTaskVoid EditAsync(string newTemplateId) private async UniTaskVoid EditAsync(string newTemplateId)
{
if (_navigating) return;
_navigating = true;
try
{ {
await SaveCurrentAsync(CancellationToken.None); await SaveCurrentAsync(CancellationToken.None);
_loadingScreen.Show(); _loadingScreen.Show();
@@ -278,6 +295,11 @@ namespace Darkmatter.Features.GameplayFlow.Systems
await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default); await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default);
_bus.Publish(new DrawingSelectedSignal(newTemplateId)); _bus.Publish(new DrawingSelectedSignal(newTemplateId));
} }
finally
{
_navigating = false;
}
}
private async UniTaskVoid DebouncedAutosaveAsync(CancellationToken ct) private async UniTaskVoid DebouncedAutosaveAsync(CancellationToken ct)
{ {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long