Initial files

This commit is contained in:
2024-04-21 16:38:26 +02:00
parent c69c668ae6
commit cf04700131
554 changed files with 131197 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using Debug = UnityEngine.Debug;
namespace CommandUndoRedo
{
public class CommandGroup : ICommand
{
List<ICommand> commands = new List<ICommand>();
public CommandGroup() {}
public CommandGroup(List<ICommand> commands)
{
this.commands.AddRange(commands);
}
public void Set(List<ICommand> commands)
{
this.commands = commands;
}
public void Add(ICommand command)
{
commands.Add(command);
}
public void Remove(ICommand command)
{
commands.Remove(command);
}
public void Clear()
{
commands.Clear();
}
public void Execute()
{
for(int i = 0; i < commands.Count; i++)
{
Debug.Log("Executing " + commands[i].GetType().Name);
commands[i].Execute();
}
}
public void UnExecute()
{
for(int i = commands.Count - 1; i >= 0; i--)
{
Debug.Log("Executing " + commands[i].GetType().Name);
commands[i].UnExecute();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da819dbd08b38eb45a35dbdb0fe78711
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
namespace CommandUndoRedo
{
public class DropoutStack<T> : LinkedList<T>
{
int _maxLength = int.MaxValue;
public int maxLength {get {return _maxLength;} set {SetMaxLength(value);}}
public DropoutStack() {}
public DropoutStack(int maxLength)
{
this.maxLength = maxLength;
}
public void Push(T item)
{
if(this.Count > 0 && this.Count + 1 > maxLength)
{
this.RemoveLast();
}
if(this.Count + 1 <= maxLength)
{
this.AddFirst(item);
}
}
public T Pop()
{
T item = this.First.Value;
this.RemoveFirst();
return item;
}
void SetMaxLength(int max)
{
_maxLength = max;
if(this.Count > _maxLength)
{
int leftover = this.Count - _maxLength;
for(int i = 0; i < leftover; i++)
{
this.RemoveLast();
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c376afccd664f4e42b36d3a99300037d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
{
"name": "UndoManager",
"rootNamespace": "",
"references": [
"GUID:aee7fa92e14bf364ebccdd24623e1764"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

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

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
namespace CommandUndoRedo
{
public class UndoRedo
{
public int maxUndoStored {get {return undoCommands.maxLength;} set {SetMaxLength(value);}}
DropoutStack<ICommand> undoCommands = new DropoutStack<ICommand>();
DropoutStack<ICommand> redoCommands = new DropoutStack<ICommand>();
public UndoRedo() {}
public UndoRedo(int maxUndoStored)
{
this.maxUndoStored = maxUndoStored;
}
public void Clear()
{
undoCommands.Clear();
redoCommands.Clear();
}
public void Undo()
{
if(undoCommands.Count > 0)
{
ICommand command = undoCommands.Pop();
command.UnExecute();
redoCommands.Push(command);
}
}
public void Redo()
{
if(redoCommands.Count > 0)
{
ICommand command = redoCommands.Pop();
command.Execute();
undoCommands.Push(command);
}
}
public void Insert(ICommand command)
{
if(maxUndoStored <= 0) return;
undoCommands.Push(command);
redoCommands.Clear();
}
public void Execute(ICommand command)
{
command.Execute();
Insert(command);
}
void SetMaxLength(int max)
{
undoCommands.maxLength = max;
redoCommands.maxLength = max;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ed1af1a5fc734b49894376597a9c723
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
using System;
namespace CommandUndoRedo
{
public static class UndoRedoManager
{
static UndoRedo undoRedo = new UndoRedo();
public static int maxUndoStored {get {return undoRedo.maxUndoStored;} set {undoRedo.maxUndoStored = value;}}
public static void Clear()
{
undoRedo.Clear();
}
public static void Undo()
{
undoRedo.Undo();
}
public static void Redo()
{
undoRedo.Redo();
}
public static void Insert(ICommand command)
{
undoRedo.Insert(command);
}
public static void Execute(ICommand command)
{
undoRedo.Execute(command);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ace2ece517a3a1c4f898c0fc635a5dd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: