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

# Conflicts:
#	Packages/manifest.json
This commit is contained in:
Mausham
2026-05-27 19:54:47 +05:45
308 changed files with 46615 additions and 1189 deletions

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f555e5ed9c45e44cd804a598d08efc6c
guid: 4be5b3e61465b42a597ff023501b4d87
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,19 @@
{
"name": "Features.Colorbook",
"rootNamespace": "Darkmatter.Features.Colorbook",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c54b3e6267ecb41b68cc06079d4b39f2
guid: ce866130b4c60406994fd723c6f571d9
AssemblyDefinitionImporter:
externalObjects: {}
userData:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ecba85ae080a44ef9b1a1d55f3f86659
guid: 1fc9de3024c914935af320d954bfe829
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,16 @@
using Darkmatter.Features.Colorbook.System;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Features.Colorbook.Installers
{
public class ColorbookFlowFeatureModule : MonoBehaviour, IModule
{
public void Register(IContainerBuilder builder)
{
builder.RegisterEntryPoint<ColorbookFlowController>(Lifetime.Singleton);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f7c0cf8383e144b9096adb577b377263

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f26c384b6ed9f482b8b3f325ba5e06f5
guid: e78bbba3617a14cd1b33c5df9068920f
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,16 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using VContainer.Unity;
namespace Darkmatter.Features.Colorbook.System;
public class ColorbookFlowController : IAsyncStartable
{
private readonly IDrawingCatalogController _drawingCatalog;
public async UniTask StartAsync(CancellationToken cancellation = new CancellationToken())
{
await _drawingCatalog.InitializeAsync(cancellation);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 46c37747ebcd4d0aa9ff3bf9fe9e26fd
timeCreated: 1779888455

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1543e11e36b1a414588e088a16a3e88e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
{
"name": "Features.DrawingCatalog",
"rootNamespace": "Darkmatter.Features.DrawingCatalog",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b4c9f7fbf1e144933a1797dc208ece5f",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: eb9b7ee4936ff42bebd83ca110182103
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 364ed66782700401dbf48ad43c2792aa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using Darkmatter.Features.DrawingCatalog.Systems;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Features.DrawingCatalog.Installers
{
public class DrawingCatalogFeatureModule : MonoBehaviour, IModule
{
[SerializeField] private DrawingCatalogView drawingCatalogView;
public void Register(IContainerBuilder builder)
{
builder.Register<IDrawingCatalogController, DrawingCatalogController>(Lifetime.Singleton);
if(drawingCatalogView != null)
builder.RegisterEntryPoint<DrawingCatalogPresenter>().WithParameter(drawingCatalogView);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a27ff086c35c847439a25f41463be16f

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 387876bf9c3cf4aa58cefa4845801ca1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using Darkmatter.Core.Contracts.Features.Progression;
using Darkmatter.Core.Data.Signals.Features.Drawing;
using Darkmatter.Libs.Observer;
using ZLinq;
namespace Darkmatter.Features.DrawingCatalog.Systems;
public sealed class DrawingCatalogController : IDrawingCatalogController
{
private readonly IDrawingTemplateCatalog _catalog;
private readonly IEventBus _bus;
private readonly IProgressionSystem _progression;
private readonly List<string> _visible = new();
public IReadOnlyList<string> VisibleIds => _visible;
public event Action ListChanged;
public DrawingCatalogController(
IDrawingTemplateCatalog catalog,
IProgressionSystem progression,
IEventBus bus)
{
_catalog = catalog;
_progression = progression;
_bus = bus;
}
public async UniTask InitializeAsync(CancellationToken ct)
{
await _catalog.FetchAsync();
Refresh();
}
public void OnTemplateSelected(string id)
{
_bus.Publish(new DrawingSelectedSignal(id));
}
private void Refresh()
{
_visible.Clear();
var all = _catalog.AllTemplateIds;
foreach (var id in all)
if (!_progression.CompletedTemplateIds.AsValueEnumerable().Contains(id))
_visible.Add(id);
foreach (var id in all)
if (_progression.CompletedTemplateIds.AsValueEnumerable().Contains(id))
_visible.Add(id);
ListChanged?.Invoke();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1252b78470d594aa58188c32f552c52a

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ae468b5d4d3624234848298a64d4c1e1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using UnityEngine;
namespace Darkmatter.Features.DrawingCatalog;
public struct CatalogItemVM
{
public string Id { get; }
public Sprite Thumbnail { get; }
public CatalogItemVM(string id, Sprite thumbnail)
{
Id = id;
Thumbnail = thumbnail;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b4274f9a3304610b13c6d01280139dc
timeCreated: 1779881383

View File

@@ -0,0 +1,18 @@
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.DrawingCatalog;
public class DrawingCatalogButton : MonoBehaviour
{
public string Id { get; private set; }
[SerializeField] private Image thumbnail;
[SerializeField] private Button button;
public void Initialize(string id,Sprite thumbnailSprite, UnityEngine.Events.UnityAction onClick)
{
Id = id;
thumbnail.sprite = thumbnailSprite;
button.onClick.AddListener(onClick);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: da23f33bd6fc4bf99f251714180406f1
timeCreated: 1779880745

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using Darkmatter.Features.DrawingCatalog.Systems;
using VContainer.Unity;
namespace Darkmatter.Features.DrawingCatalog
{
public class DrawingCatalogPresenter : IStartable, IDisposable
{
private readonly DrawingCatalogView _view;
private readonly IDrawingCatalogController _controller;
private readonly IDrawingTemplateCatalog _catalog;
private readonly CancellationTokenSource _cts = new();
public DrawingCatalogPresenter(DrawingCatalogView view, DrawingCatalogController controller,
IDrawingTemplateCatalog catalog)
{
_view = view;
_controller = controller;
_catalog = catalog;
}
public void Start()
{
_view.OnItemClicked += OnItemClicked;
_controller.ListChanged += OnListChanged;
}
private void OnItemClicked(string id) =>
_controller.OnTemplateSelected(id);
private void OnListChanged() =>
RefreshAsync(_cts.Token).Forget();
private async UniTask RefreshAsync(CancellationToken ct)
{
var ids = _controller.VisibleIds;
var vms = new List<CatalogItemVM>(ids.Count);
foreach (var id in ids)
{
if (ct.IsCancellationRequested) return;
var thumb = await _catalog.GetThumbnailAsync(id);
vms.Add(new CatalogItemVM(id, thumb));
}
if (ct.IsCancellationRequested) return;
_view.SetItems(vms);
}
public void Dispose()
{
_view.OnItemClicked -= OnItemClicked;
_controller.ListChanged -= OnListChanged;
_cts.Cancel();
_cts.Dispose();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0e2adf581811040fd86a5cd0d11cdca0

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
namespace Darkmatter.Features.DrawingCatalog
{
public class DrawingCatalogView : MonoBehaviour
{
[SerializeField] private RectTransform content;
[SerializeField] private DrawingCatalogButton buttonPrefab;
private readonly List<DrawingCatalogButton> _buttons = new();
public event Action<string> OnItemClicked;
public void SetItems(IReadOnlyList<CatalogItemVM> items)
{
while (_buttons.Count < items.Count)
{
var button = Instantiate(buttonPrefab, content);
var item = items[_buttons.Count];
button.Initialize(item.Id, item.Thumbnail,
() => { OnItemClicked?.Invoke(item.Id); });
_buttons.Add(button);
}
while (_buttons.Count > items.Count)
{
var last = _buttons[^1];
_buttons.RemoveAt(_buttons.Count - 1);
Destroy(last.gameObject);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 37f3d6f10bf1349a382f7ff96cc510b7

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bd0e94708f3eb4fafbc7048b8c1fb5d6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
{
"name": "Features.DrawingTemplates",
"rootNamespace": "Darkmatter.Features.DrawingTemplates",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:efcaa22887a6b4471829c3b3878147a2",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6a005d98aed1c4439bc4689802fa2e3b
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6935767e9490e43e299d8fc639db3c13
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using Darkmatter.Features.DrawingTemplates.Systems;
using UnityEngine;
using Darkmatter.Libs.Installers;
using VContainer;
namespace Darkmatter.Features.DrawingTemplates
{
public class DrawingTemplateFeatureModule : MonoBehaviour, IModule
{
public void Register(IContainerBuilder builder)
{
builder.Register<IDrawingTemplateCatalog, AddressableDrawingTemplateCatalog>(Lifetime.Singleton);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: aa578cd62ad074dbf91b5228c3ac667e

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bcb041f2ec610494198cc9b6a367d0f5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,112 @@
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using Darkmatter.Core.Contracts.Features.Progression;
using Darkmatter.Core.Contracts.Services.Assets;
using Darkmatter.Core.Data.Static.Features.DrawingTemplate;
using UnityEngine;
namespace Darkmatter.Features.DrawingTemplates.Systems
{
public sealed class AddressableDrawingTemplateCatalog : IDrawingTemplateCatalog
{
private const string DrawingLabel = "drawing";
private readonly IAssetProviderService _assets;
private readonly IProgressionSystem _progression;
private readonly List<string> _allIds = new();
private readonly Dictionary<string, DrawingTemplateSO> _byId = new();
private bool _initialized;
public IReadOnlyList<string> AllTemplateIds => _allIds;
public AddressableDrawingTemplateCatalog(
IAssetProviderService assets,
IProgressionSystem progression)
{
_assets = assets;
_progression = progression;
}
public async UniTask FetchAsync()
{
if (_initialized) return;
var templates = await _assets.LoadAssetsAsync<DrawingTemplateSO>(
key: DrawingLabel,
progress: null,
cancellationToken: CancellationToken.None);
_allIds.Clear();
_byId.Clear();
foreach (var t in templates)
{
if (t == null || string.IsNullOrEmpty(t.Id)) continue;
_allIds.Add(t.Id);
_byId[t.Id] = t;
}
_allIds.Sort();
_initialized = true;
}
public UniTask<Sprite> GetThumbnailAsync(string id)
{
if (!_byId.TryGetValue(id, out var t))
throw new KeyNotFoundException($"Template '{id}' not in catalog. Did InitializeAsync run?");
return UniTask.FromResult(t.DefaultThumbnail);
}
public UniTask<IDrawingTemplate> LoadAsync(string id)
{
if (_byId.TryGetValue(id, out var t))
return UniTask.FromResult<IDrawingTemplate>(t);
return LoadIndividualAsync(id);
}
private async UniTask<IDrawingTemplate> LoadIndividualAsync(string id)
{
var t = await _assets.LoadAssetAsync<DrawingTemplateSO>(
id, progress: null, cancellationToken: CancellationToken.None);
if (t == null)
throw new KeyNotFoundException($"No drawing template at address '{id}'.");
_byId[id] = t;
if (!_allIds.Contains(id))
{
_allIds.Add(id);
_allIds.Sort();
}
return t;
}
public void ReleaseAll()
{
if (!_initialized) return;
_assets.UnloadAsset(DrawingLabel);
_byId.Clear();
_allIds.Clear();
_initialized = false;
}
public string GetNextTemplate(string currentId)
{
if (_allIds.Count == 0) return null;
int startIdx = currentId != null ? _allIds.IndexOf(currentId) : -1;
for (int i = 1; i <= _allIds.Count; i++)
{
var idx = (startIdx + i) % _allIds.Count;
var candidate = _allIds[idx];
if (!_progression.IsCompleted(candidate))
return candidate;
}
return _allIds[(startIdx + 1) % _allIds.Count];
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: efec7b2f8603443098cb058487c51f2d

View File

@@ -1,6 +1,6 @@
{
"name": "Features.PaperRig",
"rootNamespace": "Darkmatter.Features.PaperRig",
"name": "Features.History",
"rootNamespace": "Darkmatter.Features.History",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3aa6224adf551496497bf0c866e704b5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9cc86805d75dc4f3781d17d7c65ac1c8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using Darkmatter.Core.Contracts.Features.History;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Features.History
{
public class HistoryFeatureModule : MonoBehaviour, IModule
{
[SerializeField] private HistoryButtonsView historyButtonsView;
public void Register(IContainerBuilder builder)
{
builder.Register<IUndoStack, UndoStack>(Lifetime.Singleton);
if (historyButtonsView != null)
builder.RegisterEntryPoint<HistoryButtonsPresenter>().WithParameter(historyButtonsView);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 45c42e41a28d34b01a364a3c2631ba73

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 352fce035805a47c4aec94d870adea6d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using Darkmatter.Core.Contracts.Features.History;
namespace Darkmatter.Features.History
{
public sealed class UndoStack : IUndoStack
{
private const int Capacity = 20;
private readonly LinkedList<ICommand> _undo = new();
private readonly Stack<ICommand> _redo = new();
public event Action OnStackChanged;
public bool CanUndo => _undo.Count > 0;
public bool CanRedo => _redo.Count > 0;
public void Push(ICommand cmd)
{
cmd.Execute();
_undo.AddLast(cmd);
if (_undo.Count > Capacity) _undo.RemoveFirst();
_redo.Clear();
OnStackChanged?.Invoke();
}
public void Undo()
{
if (!CanUndo) return;
var cmd = _undo.Last!.Value;
_undo.RemoveLast();
cmd.Undo();
_redo.Push(cmd);
OnStackChanged?.Invoke();
}
public void Redo()
{
if (!CanRedo) return;
var cmd = _redo.Pop();
cmd.Execute();
_undo.AddLast(cmd);
OnStackChanged?.Invoke();
}
public void Clear()
{
foreach (var cmd in _undo) cmd.Undo();
_undo.Clear();
_redo.Clear();
OnStackChanged?.Invoke();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1a9ed946cf48e4bd582992ca4ca662a3

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 659176aa2d382465cbb2c6bc8446d655
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
using System;
using Darkmatter.Core.Contracts.Features.History;
using VContainer.Unity;
namespace Darkmatter.Features.History
{
public class HistoryButtonsPresenter : IStartable, IDisposable
{
private readonly HistoryButtonsView _view;
private readonly IUndoStack _undoStack;
public HistoryButtonsPresenter(IUndoStack undoStack, HistoryButtonsView view)
{
_undoStack = undoStack;
_view = view;
}
public void Start()
{
_view.OnUndoClicked += HandleUndoClicked;
_view.OnRedoClicked += HandleRedoClicked;
_view.OnClearClicked += HandleClearClicked;
UpdateButtonUI();
_undoStack.OnStackChanged += UpdateButtonUI;
}
private void HandleClearClicked()
{
_undoStack.Clear();
}
private void HandleRedoClicked()
{
_undoStack.Redo();
}
private void HandleUndoClicked()
{
_undoStack.Undo();
}
private void UpdateButtonUI()
{
_view.SetUndoInteractable(_undoStack.CanUndo);
_view.SetRedoInteractable(_undoStack.CanRedo);
_view.SetClearInteractable(_undoStack.CanUndo || _undoStack.CanRedo);
}
public void Dispose()
{
_view.OnUndoClicked -= HandleUndoClicked;
_view.OnRedoClicked -= HandleRedoClicked;
_view.OnClearClicked -= HandleClearClicked;
_undoStack.OnStackChanged -= UpdateButtonUI;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 57867eec53ed04b9a93f0fd65639c98e

View File

@@ -0,0 +1,35 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.History
{
public class HistoryButtonsView : MonoBehaviour
{
[SerializeField] private Button undoButton;
[SerializeField] private Button redoButton;
[SerializeField] private Button clearButton;
public event System.Action OnUndoClicked;
public event System.Action OnRedoClicked;
public event System.Action OnClearClicked;
void Start()
{
undoButton.onClick.AddListener(() => OnUndoClicked?.Invoke());
redoButton.onClick.AddListener(() => OnRedoClicked?.Invoke());
clearButton.onClick.AddListener(() => OnClearClicked?.Invoke());
}
public void SetUndoInteractable(bool value) => undoButton.interactable = value;
public void SetRedoInteractable(bool value) => redoButton.interactable = value;
public void SetClearInteractable(bool value) => clearButton.interactable = value;
private void OnDestroy()
{
undoButton.onClick.RemoveListener(() => OnUndoClicked?.Invoke());
redoButton.onClick.RemoveListener(() => OnRedoClicked?.Invoke());
clearButton.onClick.RemoveListener(() => OnClearClicked?.Invoke());
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5b5751e64fe1947f3b800001d995f817

View File

@@ -5,7 +5,7 @@ using VContainer.Unity;
namespace Darkmatter.Features.Mainmenu
{
public class MainmenuServiceModule: MonoBehaviour, IServiceModule
public class MainmenuFeatureModule: MonoBehaviour, IModule
{
[SerializeField] private MainmenuView mainmenuView;
public void Register(IContainerBuilder builder)

View File

@@ -12,6 +12,7 @@ namespace Darkmatter.Features.Mainmenu
[Header("UI Elements")]
[SerializeField] private Button playBtn;
[SerializeField] private ParticleSystem playBtnParticle;
[SerializeField] private Animator playBtnAnimator;
[SerializeField] private SkeletonGraphic mascotSkeletonGraphic;
@@ -62,6 +63,7 @@ namespace Darkmatter.Features.Mainmenu
private void OnPlayBtnClicked()
{
playBtn.interactable = false;
playBtnAnimator.enabled = false;
PlayBtnSequenceAsync(this.GetCancellationTokenOnDestroy()).Forget();
}

View File

@@ -1,15 +0,0 @@
using System;
using Darkmatter.Core.Contracts.Features.Paper;
using UnityEngine;
namespace Darkmatter.Features.PaperRig
{
[Serializable]
public class PaperRig : IPaperRig
{
[SerializeField] private Camera artCamera;
[SerializeField] private RectTransform displayRect;
public Camera ArtCamera => artCamera;
public RectTransform DisplayRect => displayRect;
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: fd7db17694325451c8441d824b221199

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 0156c96d959344bfbf0c1212ea68d473
timeCreated: 1779859615

View File

@@ -1,45 +0,0 @@
using Darkmatter.Core.Contracts.Features.Paper;
using Darkmatter.Core.Contracts.Services.Camera;
using UnityEngine;
using CameraType = Darkmatter.Core.Enums.Services.Camera.CameraType;
namespace Darkmatter.Features.PaperRig.Darkmatter.Code.Features.PaperRig.Input
{
public class ArtInputBridge : IArtInputBridge
{
private readonly IPaperRig _paperRig;
private ICameraService _cameraService;
public ArtInputBridge(IPaperRig paperRig, ICameraService cameraService)
{
_paperRig = paperRig;
_cameraService = cameraService;
}
public bool TryScreenToArtWorld(Vector2 screenPos, out Vector2 artWorldPos)
{
var rectT = _paperRig.DisplayRect;
var uiCamera = _cameraService.GetCamera(CameraType.UICamera);
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(
rectT, screenPos, uiCamera, out var local))
{
artWorldPos = default;
return false;
}
var rect = rectT.rect;
var uv = new Vector2(
(local.x - rect.xMin) / rect.width,
(local.y - rect.yMin) / rect.height);
if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1)
{
artWorldPos = default;
return false;
}
artWorldPos = _paperRig.ArtCamera.ViewportToWorldPoint(uv);
return true;
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 0337c48e57934443887873de8e382d4e
timeCreated: 1779859625

View File

@@ -1,20 +0,0 @@
using Darkmatter.Core.Contracts.Features.Paper;
using Darkmatter.Features.PaperRig.Darkmatter.Code.Features.PaperRig.Input;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Features.PaperRig
{
public class PaperRigServiceModule : MonoBehaviour, IServiceModule
{
[SerializeField] private PaperRig paperRig;
public void Register(IContainerBuilder builder)
{
builder.RegisterComponent<IPaperRig>(paperRig);
builder.Register<IArtInputBridge, ArtInputBridge>(Lifetime.Singleton);
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: ef7eaa67fc66d48c88c8ec12d27f9b14

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d1eb9cf328d194c26af62c5ad5c37a9a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
{
"name": "Features.Progression",
"rootNamespace": "Darkmatter.Features.Progression",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:564d11c0820a9455c8821cd85e9d0fd1",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f0bb65a4e720b460289d630f2ebaf2d5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 520a33089d7d04ebcbe196f3268669d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
using Darkmatter.Core.Contracts.Features.Progression;
using Darkmatter.Features.Progression.Systems;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
namespace Darkmatter.Features.Progression.Installers
{
public class ProgressionFeatureModule : MonoBehaviour, IModule
{
public void Register(IContainerBuilder builder)
{
builder.Register<ProgressionRepository>(Lifetime.Singleton);
builder.Register<IProgressionSystem, ProgressionSystem>(Lifetime.Singleton);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d0af7651133b54f398413a7c19dfc9bb

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4c84a26f46bcb491c882e6838679d54d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Data.Dynamic.Features.Progression;
using Darkmatter.Libs.PlayerPrefs;
using UnityEngine;
namespace Darkmatter.Features.Progression.Systems;
public sealed class ProgressionRepository
{
private const string ThumbnailsFolder = "thumbnails";
private readonly Dictionary<string, DrawingProgress> _records = new();
public IEnumerable<DrawingProgress> AllProgress() => _records.Values;
public DrawingProgress? TryGet(string templateId) =>
_records.TryGetValue(templateId, out var p) ? p : (DrawingProgress?)null;
public UniTask LoadAsync()
{
_records.Clear();
var json = ProtectedPlayerPrefs.GetString(PlayerPrefsKeys.Progression, "");
if (string.IsNullOrEmpty(json)) return UniTask.CompletedTask;
ProgressionRootDto root;
try
{
root = JsonUtility.FromJson<ProgressionRootDto>(json);
}
catch (Exception e)
{
Debug.LogError($"[Progression] Failed to parse saved root: {e}");
return UniTask.CompletedTask;
}
if (root.records != null)
{
foreach (var rec in root.records)
if (!string.IsNullOrEmpty(rec.templateId))
_records[rec.templateId] = rec;
}
return UniTask.CompletedTask;
}
public UniTask SaveAsync()
{
FlushRoot();
return UniTask.CompletedTask;
}
public UniTask SaveProgressAsync(DrawingProgress p)
{
if (string.IsNullOrEmpty(p.templateId))
throw new ArgumentException("DrawingProgress.templateId must be set.");
_records[p.templateId] = p;
FlushRoot();
return UniTask.CompletedTask;
}
public UniTask DeleteProgressAsync(string templateId)
{
if (string.IsNullOrEmpty(templateId)) return UniTask.CompletedTask;
_records.Remove(templateId);
FlushRoot();
TryDeleteThumbnailFile(templateId);
return UniTask.CompletedTask;
}
public async UniTask WriteThumbnailAsync(string templateId, byte[] png)
{
if (string.IsNullOrEmpty(templateId) || png == null || png.Length == 0) return;
Directory.CreateDirectory(ThumbnailDirectory());
var path = ThumbnailPath(templateId);
var tmp = path + ".tmp";
await UniTask.RunOnThreadPool(() =>
{
File.WriteAllBytes(tmp, png);
if (File.Exists(path)) File.Delete(path);
File.Move(tmp, path);
});
}
public async UniTask<Texture2D> LoadThumbnailAsync(string templateId)
{
if (string.IsNullOrEmpty(templateId)) return null;
var path = ThumbnailPath(templateId);
if (!File.Exists(path)) return null;
byte[] bytes;
try
{
bytes = await UniTask.RunOnThreadPool(() => File.ReadAllBytes(path));
}
catch (Exception e)
{
Debug.LogWarning($"[Progression] Failed reading thumbnail '{templateId}': {e.Message}");
return null;
}
await UniTask.SwitchToMainThread();
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, mipChain: false);
if (!tex.LoadImage(bytes))
{
UnityEngine.Object.Destroy(tex);
return null;
}
return tex;
}
private void FlushRoot()
{
var root = new ProgressionRootDto
{
records = _records.Values.ToList(),
};
var json = JsonUtility.ToJson(root);
ProtectedPlayerPrefs.SetString(PlayerPrefsKeys.Progression, json);
ProtectedPlayerPrefs.Save();
}
private static void TryDeleteThumbnailFile(string templateId)
{
try
{
var path = ThumbnailPath(templateId);
if (File.Exists(path)) File.Delete(path);
}
catch (Exception e)
{
Debug.LogWarning($"[Progression] Failed deleting thumbnail '{templateId}': {e.Message}");
}
}
private static string ThumbnailDirectory() =>
Path.Combine(Application.persistentDataPath, ThumbnailsFolder);
private static string ThumbnailPath(string templateId) =>
Path.Combine(ThumbnailDirectory(), SafeFileName(templateId) + ".png");
private static string SafeFileName(string templateId) =>
templateId.Replace('/', '_').Replace('\\', '_');
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: da8d941d4aa246b495da1fe0fe4a3c37
timeCreated: 1779883906

View File

@@ -0,0 +1,95 @@
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.Progression;
using Darkmatter.Core.Data.Dynamic.Features.Progression;
using Darkmatter.Core.Enums.Features.Progression;
using Darkmatter.Features.Progression.Systems;
using UnityEngine;
public class ProgressionSystem : IProgressionSystem
{
private readonly ProgressionRepository _repository;
private readonly Dictionary<string, DrawingProgress> _records = new();
private readonly HashSet<string> _completed = new();
private readonly SemaphoreSlim _writeLock = new(1, 1);
public IReadOnlyCollection<string> CompletedTemplateIds => _completed;
public ProgressionSystem(ProgressionRepository repository)
{
_repository = repository;
}
public async UniTask LoadAsync()
{
await _repository.LoadAsync();
_records.Clear();
_completed.Clear();
foreach (var p in _repository.AllProgress())
{
_records[p.templateId] = p;
if (p.hasBeenCompleted) _completed.Add(p.templateId);
}
}
public UniTask SaveAsync() => _repository.SaveAsync();
public void MarkCompleted(string templateId)
{
if (!_records.TryGetValue(templateId, out var p))
{
p = new DrawingProgress { templateId = templateId, phase = DrawingPhase.Coloring };
}
p.hasBeenCompleted = true;
p.completionCount += 1;
_records[templateId] = p;
_completed.Add(templateId);
}
public DrawingProgress? GetProgress(string templateId) =>
_records.TryGetValue(templateId, out var p) ? p : (DrawingProgress?)null;
public UniTask SaveProgressAsync(DrawingProgress progress) =>
SaveProgressAsync(progress, thumbnailPng: null);
public async UniTask SaveProgressAsync(DrawingProgress progress, byte[] thumbnailPng)
{
await _writeLock.WaitAsync();
try
{
_records[progress.templateId] = progress;
if (progress.hasBeenCompleted) _completed.Add(progress.templateId);
await _repository.SaveProgressAsync(progress);
if (thumbnailPng != null)
await _repository.WriteThumbnailAsync(progress.templateId, thumbnailPng);
}
finally
{
_writeLock.Release();
}
}
public async UniTask ClearProgressAsync(string templateId)
{
await _writeLock.WaitAsync();
try
{
_records.Remove(templateId);
_completed.Remove(templateId);
await _repository.DeleteProgressAsync(templateId);
}
finally
{
_writeLock.Release();
}
}
public bool IsCompleted(string templateId) => _completed.Contains(templateId);
public UniTask<Texture2D> GetCachedThumbnailAsync(string templateId) =>
_repository.LoadThumbnailAsync(templateId);
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0db29bbab0cba49e487a47c8884ee6da