Merge remote-tracking branch 'origin/savya' into work_branch

This commit is contained in:
Mausham
2026-05-29 17:49:28 +05:45
11 changed files with 296 additions and 64 deletions

View File

@@ -5,4 +5,5 @@ namespace Darkmatter.Core.Contracts.Features.GameplayFlow;
public interface IGameplaySceneRefs public interface IGameplaySceneRefs
{ {
RectTransform PaperRoot { get; } RectTransform PaperRoot { get; }
ParticleSystem Confetti { get; }
} }

View File

@@ -14,6 +14,9 @@ namespace Darkmatter.Core.Data.Static.Features.ShapeBuilder
[SerializeField] private float snapDuration = 0.25f; [SerializeField] private float snapDuration = 0.25f;
[SerializeField] private float returnDuration = 0.25f; [SerializeField] private float returnDuration = 0.25f;
[Header("Drag")]
[SerializeField, Range(1f, 2f)] private float dragScale = 1.15f;
[Header("Preview easing")] [Header("Preview easing")]
[SerializeField] private AnimationCurve previewCurve = AnimationCurve.EaseInOut(0, 0, 1, 1); [SerializeField] private AnimationCurve previewCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
@@ -21,6 +24,7 @@ namespace Darkmatter.Core.Data.Static.Features.ShapeBuilder
public float PreviewRadius => previewRadius; public float PreviewRadius => previewRadius;
public float SnapDuration => snapDuration; public float SnapDuration => snapDuration;
public float ReturnDuration => returnDuration; public float ReturnDuration => returnDuration;
public float DragScale => dragScale;
public AnimationCurve PreviewCurve => previewCurve; public AnimationCurve PreviewCurve => previewCurve;
public Vector2 DragSizeDelta(ShapeSO shape) => public Vector2 DragSizeDelta(ShapeSO shape) =>

View File

@@ -6,7 +6,8 @@ namespace Darkmatter.Features.GameplayFlow.SceneRefs
public class GameplaySceneRefs : MonoBehaviour, IGameplaySceneRefs public class GameplaySceneRefs : MonoBehaviour, IGameplaySceneRefs
{ {
[SerializeField] private RectTransform paperRoot; [SerializeField] private RectTransform paperRoot;
[SerializeField] private ParticleSystem confetti;
public RectTransform PaperRoot => paperRoot; 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 ISceneService _scenes;
private readonly ICaptureFeature _capture; private readonly ICaptureFeature _capture;
private readonly ILoadingScreen _loadingScreen; private readonly ILoadingScreen _loadingScreen;
private readonly IGameplaySceneRefs _refs;
private readonly IEventBus _bus; private readonly IEventBus _bus;
private IDrawingTemplate _template; private IDrawingTemplate _template;
@@ -53,6 +54,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
ISceneService scenes, ISceneService scenes,
ICaptureFeature capture, ICaptureFeature capture,
ILoadingScreen loadingScreen, ILoadingScreen loadingScreen,
IGameplaySceneRefs refs,
IEventBus bus) IEventBus bus)
{ {
_progression = progression; _progression = progression;
@@ -62,6 +64,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
_scenes = scenes; _scenes = scenes;
_capture = capture; _capture = capture;
_loadingScreen = loadingScreen; _loadingScreen = loadingScreen;
_refs = refs;
_bus = bus; _bus = bus;
} }
@@ -123,6 +126,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
public async UniTask NextAsync(CancellationToken ct) public async UniTask NextAsync(CancellationToken ct)
{ {
await SaveCurrentAsync(ct); await SaveCurrentAsync(ct);
_refs.Confetti.Play();
await _coloring.PlayCompletionAnimationAsync(ct); await _coloring.PlayCompletionAnimationAsync(ct);
_progression.MarkCompleted(_templateId); _progression.MarkCompleted(_templateId);
@@ -147,7 +151,6 @@ namespace Darkmatter.Features.GameplayFlow.Systems
public void OnApplicationPaused() public void OnApplicationPaused()
{ {
// Fire-and-forget — pause window is small; PlayerPrefs write is sync under the hood.
SaveCurrentAsync(CancellationToken.None).Forget(); SaveCurrentAsync(CancellationToken.None).Forget();
} }

View File

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

View File

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

View File

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

View File

@@ -68,7 +68,7 @@ MonoBehaviour:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 21300000, guid: c3293fddd457324499e794c843736653, type: 3} m_Sprite: {fileID: 21300000, guid: c3293fddd457324499e794c843736653, type: 3}
m_Type: 0 m_Type: 0
m_PreserveAspect: 0 m_PreserveAspect: 1
m_FillCenter: 1 m_FillCenter: 1
m_FillMethod: 4 m_FillMethod: 4
m_FillAmount: 1 m_FillAmount: 1

View File

@@ -68,7 +68,7 @@ MonoBehaviour:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 21300000, guid: cbc63d77c9f7c8448b6ff8900b09cc3f, type: 3} m_Sprite: {fileID: 21300000, guid: cbc63d77c9f7c8448b6ff8900b09cc3f, type: 3}
m_Type: 0 m_Type: 0
m_PreserveAspect: 0 m_PreserveAspect: 1
m_FillCenter: 1 m_FillCenter: 1
m_FillMethod: 4 m_FillMethod: 4
m_FillAmount: 1 m_FillAmount: 1

File diff suppressed because one or more lines are too long

View File

@@ -926,6 +926,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Features.GameplayFlow::Darkmatter.Features.GameplayFlow.SceneRefs.GameplaySceneRefs m_EditorClassIdentifier: Features.GameplayFlow::Darkmatter.Features.GameplayFlow.SceneRefs.GameplaySceneRefs
paperRoot: {fileID: 1143672390} paperRoot: {fileID: 1143672390}
confetti: {fileID: 1141121867}
--- !u!1 &600922870 --- !u!1 &600922870
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1844,7 +1845,7 @@ MonoBehaviour:
m_Top: 0 m_Top: 0
m_Bottom: 0 m_Bottom: 0
m_ChildAlignment: 1 m_ChildAlignment: 1
m_Spacing: 0 m_Spacing: 30
m_ChildForceExpandWidth: 0 m_ChildForceExpandWidth: 0
m_ChildForceExpandHeight: 0 m_ChildForceExpandHeight: 0
m_ChildControlWidth: 0 m_ChildControlWidth: 0