Undo system made
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
namespace Darkmatter.Core.Contracts.Features.History
|
||||
{
|
||||
public interface ICommand
|
||||
{
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Features.History",
|
||||
"rootNamespace": "Darkmatter.Features.History",
|
||||
"references": [
|
||||
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3aa6224adf551496497bf0c866e704b5
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Darkmatter/Code/Features/History/Installers.meta
Normal file
8
Assets/Darkmatter/Code/Features/History/Installers.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cc86805d75dc4f3781d17d7c65ac1c8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using Darkmatter.Core.Contracts.Features.History;
|
||||
using Darkmatter.Libs.Installers;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Features.History
|
||||
{
|
||||
public class HistoryServiceModule : MonoBehaviour,IServiceModule
|
||||
{
|
||||
public void Register(IContainerBuilder builder)
|
||||
{
|
||||
builder.Register<IUndoStack, UndoStack>(Lifetime.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45c42e41a28d34b01a364a3c2631ba73
|
||||
8
Assets/Darkmatter/Code/Features/History/Stack.meta
Normal file
8
Assets/Darkmatter/Code/Features/History/Stack.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 352fce035805a47c4aec94d870adea6d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Darkmatter/Code/Features/History/Stack/UndoStack.cs
Normal file
47
Assets/Darkmatter/Code/Features/History/Stack/UndoStack.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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 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();
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if (!CanUndo) return;
|
||||
var cmd = _undo.Last!.Value;
|
||||
_undo.RemoveLast();
|
||||
cmd.Undo();
|
||||
_redo.Push(cmd);
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
if (!CanRedo) return;
|
||||
var cmd = _redo.Pop();
|
||||
cmd.Execute();
|
||||
_undo.AddLast(cmd);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_undo.Clear();
|
||||
_redo.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a9ed946cf48e4bd582992ca4ca662a3
|
||||
@@ -461,6 +461,51 @@ MonoBehaviour:
|
||||
autoInjectGameObjects: []
|
||||
serviceModules:
|
||||
- {fileID: 1594774441}
|
||||
- {fileID: 1551649429}
|
||||
--- !u!1 &1551649427
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1551649428}
|
||||
- component: {fileID: 1551649429}
|
||||
m_Layer: 0
|
||||
m_Name: HistoryServiceModule
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1551649428
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1551649427}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1965442263}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1551649429
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1551649427}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 45c42e41a28d34b01a364a3c2631ba73, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Features.History::Darkmatter.Features.History.HistoryServiceModule
|
||||
--- !u!1 &1594774439
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -538,6 +583,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1594774440}
|
||||
- {fileID: 1551649428}
|
||||
m_Father: {fileID: 1224714932}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &2069155637
|
||||
|
||||
Reference in New Issue
Block a user