From 940fed41be23c019bf36dae5c968f37283acca98 Mon Sep 17 00:00:00 2001 From: Savya Bikram Shah Date: Fri, 29 May 2026 17:14:51 +0545 Subject: [PATCH] snap fix --- .../Systems/ShapeBuilderController.cs | 23 +++++++++++++++++-- .../Features/ShapeBuilder/UI/ShapePiece.cs | 22 ++++++++---------- .../Features/ShapeBuilder/UI/SlotMarker.cs | 5 ++++ Assets/Darkmatter/Scenes/GamePlay.unity | 8 +++---- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Assets/Darkmatter/Code/Features/ShapeBuilder/Systems/ShapeBuilderController.cs b/Assets/Darkmatter/Code/Features/ShapeBuilder/Systems/ShapeBuilderController.cs index 7abbb84..106ce9f 100644 --- a/Assets/Darkmatter/Code/Features/ShapeBuilder/Systems/ShapeBuilderController.cs +++ b/Assets/Darkmatter/Code/Features/ShapeBuilder/Systems/ShapeBuilderController.cs @@ -108,14 +108,31 @@ namespace Darkmatter.Features.ShapeBuilder.Systems _bus.Publish(new ShapeBuilderStartedSignal(template.Id)); - CreateShapePieceInstances(template, preSnappedIds, count, slots, pitch, trayW); + var colorByShapeId = BuildColorMap(template, slots); + foreach (var s in slots) + 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); CheckIfShapeAssembled(); } + private static Dictionary BuildColorMap(IDrawingTemplate template, SlotMarker[] slots) + { + var map = new Dictionary(); + foreach (var p in template.Pieces) + if (p != null && !string.IsNullOrEmpty(p.Id) && !map.ContainsKey(p.Id)) + map[p.Id] = Color.HSVToRGB(UnityEngine.Random.value, 0.7f, 0.95f); + foreach (var s in slots) + if (s != null && s.Shape != null && !string.IsNullOrEmpty(s.Shape.Id) && !map.ContainsKey(s.Shape.Id)) + map[s.Shape.Id] = Color.HSVToRGB(UnityEngine.Random.value, 0.7f, 0.95f); + return map; + } + private void CreateShapePieceInstances(IDrawingTemplate template, IReadOnlyCollection preSnappedIds, int count, - SlotMarker[] slots, float pitch, float trayW) + SlotMarker[] slots, float pitch, float trayW, Dictionary colorByShapeId) { var preSnapCounts = new Dictionary(); if (preSnappedIds != null) @@ -137,6 +154,8 @@ namespace Darkmatter.Features.ShapeBuilder.Systems var trayPos = new Vector2(pitch * (i + 1) - trayW * 0.5f, 0f); var piece = _factory.Create(_piecePrefab, shape, candidates, trayPos); + if (colorByShapeId != null && colorByShapeId.TryGetValue(shape.Id, out var c)) + piece.SetColor(c); _pieces.Add(piece); if (preSnapCounts.TryGetValue(shape.Id, out var remaining) && remaining > 0) diff --git a/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/ShapePiece.cs b/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/ShapePiece.cs index bdc778c..69e5ccd 100644 --- a/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/ShapePiece.cs +++ b/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/ShapePiece.cs @@ -59,6 +59,11 @@ namespace Darkmatter.Features.ShapeBuilder.UI public void ReassignActiveSlot(SlotMarker slot) => _activeSlot = slot; + public void SetColor(Color color) + { + if (image != null) image.color = color; + } + public void Setup( ShapeSO shape, SlotMarker[] candidateSlots, @@ -227,27 +232,18 @@ namespace Darkmatter.Features.ShapeBuilder.UI { StopPreviewTweens(); Lock(); - var slot = _activeSlot.RectTransform; - - Sequence.Create() - .Group(Tween.Position(RectTransform, slot.position, _cfg.SnapDuration, Ease.OutBack)) - .Group(Tween.Rotation(RectTransform, slot.rotation, _cfg.SnapDuration, Ease.OutBack)) - .Group(Tween.LocalScale(RectTransform, slot.localScale, _cfg.SnapDuration, Ease.OutBack)) - .Group(Tween.UISizeDelta(RectTransform, slot.sizeDelta, _cfg.SnapDuration, Ease.OutBack)) - .ChainCallback(AlignRectToSlot); + FillSlot(); _sfx.Play(SfxId.ShapeSnap); _bus.Publish(new PieceSnappedSignal(_shape.Id)); } - private void AlignRectToSlot() + private void FillSlot() { - if (this == null || _activeSlot == null) return; var rt = RectTransform; - var slot = _activeSlot.RectTransform; rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; - rt.pivot = slot.pivot; + rt.pivot = new Vector2(0.5f, 0.5f); rt.anchoredPosition = Vector2.zero; rt.sizeDelta = Vector2.zero; rt.localRotation = Quaternion.identity; @@ -283,7 +279,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI { _activeSlot = slot; Lock(); - AlignRectToSlot(); + FillSlot(); } private void ReturnToTray() diff --git a/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/SlotMarker.cs b/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/SlotMarker.cs index 076a9d8..0ad972c 100644 --- a/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/SlotMarker.cs +++ b/Assets/Darkmatter/Code/Features/ShapeBuilder/UI/SlotMarker.cs @@ -20,5 +20,10 @@ namespace Darkmatter.Features.ShapeBuilder.UI { if (outline != null) outline.enabled = visible; } + + public void SetColor(Color color) + { + if (outline != null) outline.color = color; + } } } diff --git a/Assets/Darkmatter/Scenes/GamePlay.unity b/Assets/Darkmatter/Scenes/GamePlay.unity index b382707..8d23c14 100644 --- a/Assets/Darkmatter/Scenes/GamePlay.unity +++ b/Assets/Darkmatter/Scenes/GamePlay.unity @@ -1395,8 +1395,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Features.GameplayFlow::Darkmatter.Features.GameplayFlow.GameplayFlowFeatureModule sceneRefs: {fileID: 396806867} - nextButtonView: {fileID: 0} - backButtonView: {fileID: 0} + nextButtonView: {fileID: 259035382} + backButtonView: {fileID: 1130088203} --- !u!1 &1129540368 GameObject: m_ObjectHideFlags: 0 @@ -2944,8 +2944,8 @@ MonoBehaviour: m_Calls: [] m_text: Artbook m_isRightToLeft: 0 - m_fontAsset: {fileID: 11400000, guid: f282e17aebd2cf547bdab7be22e5c474, type: 2} - m_sharedMaterial: {fileID: 6332886355625335628, guid: f282e17aebd2cf547bdab7be22e5c474, type: 2} + m_fontAsset: {fileID: 11400000, guid: dde468a43b0440f4a9d121fb1d8f290e, type: 2} + m_sharedMaterial: {fileID: -1548830327015913602, guid: dde468a43b0440f4a9d121fb1d8f290e, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: []