fixes and confetti

This commit is contained in:
Savya Bikram Shah
2026-05-29 17:35:25 +05:45
parent 67c8507fd6
commit 2d519a37b4
12 changed files with 297 additions and 65 deletions

View File

@@ -6,7 +6,8 @@ namespace Darkmatter.Features.GameplayFlow.SceneRefs
public class GameplaySceneRefs : MonoBehaviour, IGameplaySceneRefs
{
[SerializeField] private RectTransform paperRoot;
[SerializeField] private ParticleSystem confetti;
public RectTransform PaperRoot => paperRoot;
public ParticleSystem Confetti => confetti;
}
}
}

View File

@@ -34,6 +34,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
private readonly ISceneService _scenes;
private readonly ICaptureFeature _capture;
private readonly ILoadingScreen _loadingScreen;
private readonly IGameplaySceneRefs _refs;
private readonly IEventBus _bus;
private IDrawingTemplate _template;
@@ -53,6 +54,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
ISceneService scenes,
ICaptureFeature capture,
ILoadingScreen loadingScreen,
IGameplaySceneRefs refs,
IEventBus bus)
{
_progression = progression;
@@ -62,6 +64,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
_scenes = scenes;
_capture = capture;
_loadingScreen = loadingScreen;
_refs = refs;
_bus = bus;
}
@@ -123,6 +126,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
public async UniTask NextAsync(CancellationToken ct)
{
await SaveCurrentAsync(ct);
_refs.Confetti.Play();
await _coloring.PlayCompletionAnimationAsync(ct);
_progression.MarkCompleted(_templateId);
@@ -147,7 +151,6 @@ namespace Darkmatter.Features.GameplayFlow.Systems
public void OnApplicationPaused()
{
// Fire-and-forget — pause window is small; PlayerPrefs write is sync under the hood.
SaveCurrentAsync(CancellationToken.None).Forget();
}

View File

@@ -99,8 +99,6 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
ct.ThrowIfCancellationRequested();
int count = template.Pieces.Count;
float trayW = _holder.SpawnWidth;
float pitch = trayW / (count + 1);
_currentTemplateId = template.Id;
_expected = count;
@@ -113,7 +111,7 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
if (s != null && s.Shape != null && colorByShapeId.TryGetValue(s.Shape.Id, out var c))
s.SetColor(c);
CreateShapePieceInstances(template, preSnappedIds, count, slots, pitch, trayW, colorByShapeId);
CreateShapePieceInstances(template, preSnappedIds, count, slots, colorByShapeId);
CheckIfShapeAssembled();
}
@@ -132,7 +130,7 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
private void CreateShapePieceInstances(IDrawingTemplate template, IReadOnlyCollection<string> preSnappedIds,
int count,
SlotMarker[] slots, float pitch, float trayW, Dictionary<string, Color> colorByShapeId)
SlotMarker[] slots, Dictionary<string, Color> colorByShapeId)
{
var preSnapCounts = new Dictionary<string, int>();
if (preSnappedIds != null)
@@ -152,8 +150,7 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
continue;
}
var trayPos = new Vector2(pitch * (i + 1) - trayW * 0.5f, 0f);
var piece = _factory.Create(_piecePrefab, shape, candidates, trayPos);
var piece = _factory.Create(_piecePrefab, shape, candidates, Vector2.zero);
if (colorByShapeId != null && colorByShapeId.TryGetValue(shape.Id, out var c))
piece.SetColor(c);
_pieces.Add(piece);

View File

@@ -34,6 +34,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
private Vector2 _origAnchorMin;
private Vector2 _origAnchorMax;
private Vector2 _origPivot;
private bool _origPreserveAspect;
// Per-drag state
private RectTransform _rt;
@@ -90,6 +91,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
_origAnchorMin = RectTransform.anchorMin;
_origAnchorMax = RectTransform.anchorMax;
_origPivot = RectTransform.pivot;
_origPreserveAspect = image != null && image.preserveAspect;
image.sprite = shape.Sprite;
ApplyTrayPose();
@@ -112,6 +114,8 @@ namespace Darkmatter.Features.ShapeBuilder.UI
_dragLocalScale = RectTransform.localScale;
_grabOffset = RectTransform.anchoredPosition - ScreenToLocal(e.position);
_inPreview = false;
Tween.LocalScale(RectTransform, _dragLocalScale * _cfg.DragScale, _cfg.SnapDuration, Ease.OutQuad);
}
public void OnDrag(PointerEventData e)
@@ -182,16 +186,18 @@ namespace Darkmatter.Features.ShapeBuilder.UI
if (toSlot && _activeSlot != null)
{
var slot = _activeSlot.RectTransform;
if (image != null) image.preserveAspect = false;
_previewSeq = Sequence.Create()
.Group(Tween.UIAnchoredPosition(RectTransform, SlotPosInDragSpace(), _cfg.SnapDuration, Ease.OutQuad))
.Group(Tween.LocalScale(RectTransform, SlotScaleInDragSpace(), _cfg.SnapDuration, Ease.OutQuad))
.Group(Tween.LocalRotation(RectTransform, SlotRotInDragSpace(), _cfg.SnapDuration, Ease.OutQuad))
.Group(Tween.UISizeDelta(RectTransform, slot.sizeDelta, _cfg.SnapDuration, Ease.OutQuad));
.Group(Tween.UISizeDelta(RectTransform, slot.rect.size, _cfg.SnapDuration, Ease.OutQuad));
}
else
{
if (image != null) image.preserveAspect = true;
_previewSeq = Sequence.Create()
.Group(Tween.LocalScale(RectTransform, _dragLocalScale, _cfg.SnapDuration, Ease.OutQuad))
.Group(Tween.LocalScale(RectTransform, _dragLocalScale * _cfg.DragScale, _cfg.SnapDuration, Ease.OutQuad))
.Group(Tween.LocalRotation(RectTransform, Quaternion.identity, _cfg.SnapDuration, Ease.OutQuad))
.Group(Tween.UISizeDelta(RectTransform, _dragSizeDelta, _cfg.SnapDuration, Ease.OutQuad));
}
@@ -241,13 +247,15 @@ namespace Darkmatter.Features.ShapeBuilder.UI
private void FillSlot()
{
var rt = RectTransform;
rt.anchorMin = Vector2.zero;
rt.anchorMax = Vector2.one;
var slot = _activeSlot.RectTransform;
rt.anchorMin = new Vector2(0.5f, 0.5f);
rt.anchorMax = new Vector2(0.5f, 0.5f);
rt.pivot = new Vector2(0.5f, 0.5f);
rt.anchoredPosition = Vector2.zero;
rt.sizeDelta = Vector2.zero;
rt.anchoredPosition = slot.rect.center;
rt.sizeDelta = slot.rect.size;
rt.localRotation = Quaternion.identity;
rt.localScale = Vector3.one;
if (image != null) image.preserveAspect = false;
}
internal void UnsnapInternal(Transform parent, int siblingIndex, Vector2 pos, Vector2 size, Quaternion rot)
@@ -270,6 +278,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
RectTransform.sizeDelta = size;
RectTransform.localRotation = rot;
RectTransform.localScale = Vector3.one;
if (image != null) image.preserveAspect = _origPreserveAspect;
_sfx.Play(SfxId.ShapeReturn);
_bus.Publish(new PieceUnsnappedSignal(_shape.Id));
@@ -315,9 +324,8 @@ namespace Darkmatter.Features.ShapeBuilder.UI
private void ApplyTrayPose()
{
RectTransform.anchoredPosition = _trayPos;
RectTransform.sizeDelta = _traySize;
RectTransform.localRotation = Quaternion.identity;
RectTransform.sizeDelta = _traySize;
RectTransform.localRotation = Quaternion.identity;
}
private Vector2 ScreenToLocal(Vector2 screenPos)

View File

@@ -12,6 +12,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
public ShapeSO Shape => shape;
public string SlotId => shape != null ? shape.Id : null;
public RectTransform RectTransform => (RectTransform)transform;
public RectTransform FitRect => outline != null ? outline.rectTransform : (RectTransform)transform;
public bool IsOccupied { get; private set; }
public void SetOccupied(bool value) => IsOccupied = value;