Skip to content

Commit

Permalink
feat(values): added variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Iam1337 committed Aug 17, 2023
1 parent c1bd276 commit 5afe410
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 108 deletions.
14 changes: 10 additions & 4 deletions Assets/extDebug/Examples/extDebug.Menu/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public int GetLogsCount()

#region Private Vars

private string _string = "Hello, World!";
private readonly string _string = "Hello, World!";

private string _string2 = "Variant 2";

private readonly string[] _stringVariants = new string[] { "Variant 1", "Variant 2", "Variant 3" };

private byte _uint8;

Expand Down Expand Up @@ -184,10 +188,12 @@ public int GetLogsCount()
private void Start()
{
var storage = new DMPlayerStorage();

var order = 0;

// Simple Menus
DM.Add("Simple Menus/Action", action => Debug.Log("Hello, Action!"), "Simple Action", order: 0);
DM.Add("Simple Menus/String", () => _string, order: 1);
DM.Add("Simple Menus/Action", action => Debug.Log("Hello, Action!"), "Simple Action", order: -1);
DM.Add("Simple Menus/String", () => _string, order: 0);
DM.Add("Simple Menus/String Variants", () => _string2, v => _string2 = v, _stringVariants, order: 1);
DM.Add("Simple Menus/UInt8", () => _uint8, v => _uint8 = v, order: 2);
DM.Add("Simple Menus/UInt16", () => _uint16, v => _uint16 = v, order: 3);
DM.Add("Simple Menus/UInt32", () => _uint32, v => _uint32 = v, order: 4);
Expand Down
47 changes: 25 additions & 22 deletions Assets/extDebug/Scripts/Menu/DM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,53 +94,56 @@ public static DMBranch Add(string path, string description = "", int order = 0)
public static DMString Add(string path, Func<string> getter, int order = 0) =>
Container.Add(path, getter, order);

public static DMString Add(string path, Func<string> getter, Action<string> setter, string[] variants, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Action
public static DMAction Add(string path, Action<ActionEvent> action, string description = "", int order = 0) =>
Container.Add(path, action, description, order);

// Bool
public static DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, bool[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Enum
public static DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum =>
Container.Add(path, getter, setter, order);
public static DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, T[] variants = null, int order = 0) where T : struct, Enum =>
Container.Add(path, getter, setter, variants, order);

// UInt8
public static DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, byte[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// UInt16
public static DMUInt16 Add(string path, Func<UInt16> getter, Action<UInt16> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMUInt16 Add(string path, Func<UInt16> getter, Action<UInt16> setter = null, UInt16[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// UInt32
public static DMUInt32 Add(string path, Func<UInt32> getter, Action<UInt32> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMUInt32 Add(string path, Func<UInt32> getter, Action<UInt32> setter = null, UInt32[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// UInt64
public static DMUInt64 Add(string path, Func<UInt64> getter, Action<UInt64> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMUInt64 Add(string path, Func<UInt64> getter, Action<UInt64> setter = null, UInt64[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Int8
public static DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, sbyte[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Int16
public static DMInt16 Add(string path, Func<Int16> getter, Action<Int16> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMInt16 Add(string path, Func<Int16> getter, Action<Int16> setter = null, Int16[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Int32
public static DMInt32 Add(string path, Func<Int32> getter, Action<Int32> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMInt32 Add(string path, Func<Int32> getter, Action<Int32> setter = null, Int32[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Int64
public static DMInt64 Add(string path, Func<Int64> getter, Action<Int64> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMInt64 Add(string path, Func<Int64> getter, Action<Int64> setter = null, Int64[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Float
public static DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) =>
Container.Add(path, getter, setter, order);
public static DMFloat Add(string path, Func<float> getter, Action<float> setter = null, float[] variants = null, int order = 0) =>
Container.Add(path, getter, setter, variants, order);

// Vector 2
public static DMVector2 Add(string path, Func<Vector2> getter, Action<Vector2> setter = null, int order = 0) =>
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMBool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DMBool : DMValue<bool>
{
#region Public Methods

public DMBool(DMBranch parent, string path, Func<bool> getter, Action<bool> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMBool(DMBranch parent, string path, Func<bool> getter, Action<bool> setter = null, bool[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
51 changes: 27 additions & 24 deletions Assets/extDebug/Scripts/Menu/DMBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,47 @@ public void Clear()
public DMBranch Add(string path, string description = "", int order = 0) =>
Get(path) ?? new DMBranch(this, path, description, order);

public DMString Add(string path, Func<string> getter, int order = 0) =>
new DMString(this, path, getter, order);
public DMString Add(string path, Func<string> getter, int order = 0) =>
new DMString(this, path, getter, order: order);

public DMString Add(string path, Func<string> getter, Action<string> setter, string[] variants, int order = 0) =>
new DMString(this, path, getter, setter, variants, order);

public DMAction Add(string path, Action<ActionEvent> action, string description = "", int order = 0) =>
new DMAction(this, path, description, action, order);

public DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) =>
new DMBool(this, path, getter, setter, order);
public DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, bool[] variants = null, int order = 0) =>
new DMBool(this, path, getter, setter, variants, order);

public DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum =>
new DMEnum<T>(this, path, getter, setter, order);
public DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, T[] variants = null, int order = 0) where T : struct, Enum =>
new DMEnum<T>(this, path, getter, setter, variants, order);

public DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) =>
new DMUInt8(this, path, getter, setter, order);
public DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, byte[] variants = null, int order = 0) =>
new DMUInt8(this, path, getter, setter, variants, order);

public DMUInt16 Add(string path, Func<ushort> getter, Action<ushort> setter = null, int order = 0) =>
new DMUInt16(this, path, getter, setter, order);
public DMUInt16 Add(string path, Func<ushort> getter, Action<ushort> setter = null, ushort[] variants = null, int order = 0) =>
new DMUInt16(this, path, getter, setter, variants, order);

public DMUInt32 Add(string path, Func<uint> getter, Action<uint> setter = null, int order = 0) =>
new DMUInt32(this, path, getter, setter, order);
public DMUInt32 Add(string path, Func<uint> getter, Action<uint> setter = null, uint[] variants = null, int order = 0) =>
new DMUInt32(this, path, getter, setter, variants, order);

public DMUInt64 Add(string path, Func<ulong> getter, Action<ulong> setter = null, int order = 0) =>
new DMUInt64(this, path, getter, setter, order);
public DMUInt64 Add(string path, Func<ulong> getter, Action<ulong> setter = null, ulong[] variants = null, int order = 0) =>
new DMUInt64(this, path, getter, setter, variants, order);

public DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) =>
new DMInt8(this, path, getter, setter, order);
public DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, sbyte[] variants = null, int order = 0) =>
new DMInt8(this, path, getter, setter, variants, order);

public DMInt16 Add(string path, Func<short> getter, Action<short> setter = null, int order = 0) =>
new DMInt16(this, path, getter, setter, order);
public DMInt16 Add(string path, Func<short> getter, Action<short> setter = null, short[] variants = null, int order = 0) =>
new DMInt16(this, path, getter, setter, variants, order);

public DMInt32 Add(string path, Func<int> getter, Action<int> setter = null, int order = 0) =>
new DMInt32(this, path, getter, setter, order);
public DMInt32 Add(string path, Func<int> getter, Action<int> setter = null, int[] variants = null, int order = 0) =>
new DMInt32(this, path, getter, setter, variants, order);

public DMInt64 Add(string path, Func<long> getter, Action<long> setter = null, int order = 0) =>
new DMInt64(this, path, getter, setter, order);
public DMInt64 Add(string path, Func<long> getter, Action<long> setter = null, long[] variants = null, int order = 0) =>
new DMInt64(this, path, getter, setter, variants, order);

public DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) =>
new DMFloat(this, path, getter, setter, order);
public DMFloat Add(string path, Func<float> getter, Action<float> setter = null, float[] variants = null, int order = 0) =>
new DMFloat(this, path, getter, setter, variants, order);

public DMVector2 Add(string path, Func<Vector2> getter, Action<Vector2> setter = null, int order = 0) =>
new DMVector2(this, path, getter, setter, order);
Expand Down
47 changes: 25 additions & 22 deletions Assets/extDebug/Scripts/Menu/DMContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,53 +168,56 @@ public DMBranch Add(string path, string description = "", int order = 0) =>
public DMString Add(string path, Func<string> getter, int order = 0) =>
Root.Add(path, getter, order);

public DMString Add(string path, Func<string> getter, Action<string> setter, string[] variants, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Action
public DMAction Add(string path, Action<ActionEvent> action, string description = "", int order = 0) =>
Root.Add(path, action, description, order);

// Bool
public DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, bool[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Enums
public DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum =>
Root.Add(path, getter, setter, order);
public DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, T[] variants = null, int order = 0) where T : struct, Enum =>
Root.Add(path, getter, setter, variants, order);

// UInt8
public DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, byte[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// UInt16
public DMUInt16 Add(string path, Func<UInt16> getter, Action<UInt16> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMUInt16 Add(string path, Func<UInt16> getter, Action<UInt16> setter = null, UInt16[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// UInt32
public DMUInt32 Add(string path, Func<UInt32> getter, Action<UInt32> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMUInt32 Add(string path, Func<UInt32> getter, Action<UInt32> setter = null, UInt32[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// UInt64
public DMUInt64 Add(string path, Func<UInt64> getter, Action<UInt64> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMUInt64 Add(string path, Func<UInt64> getter, Action<UInt64> setter = null, UInt64[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Int8
public DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, sbyte[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Int16
public DMInt16 Add(string path, Func<Int16> getter, Action<Int16> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMInt16 Add(string path, Func<Int16> getter, Action<Int16> setter = null, Int16[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Int32
public DMInt32 Add(string path, Func<Int32> getter, Action<Int32> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMInt32 Add(string path, Func<Int32> getter, Action<Int32> setter = null, Int32[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Int64
public DMInt64 Add(string path, Func<Int64> getter, Action<Int64> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMInt64 Add(string path, Func<Int64> getter, Action<Int64> setter = null, Int64[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Float
public DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) =>
Root.Add(path, getter, setter, order);
public DMFloat Add(string path, Func<float> getter, Action<float> setter = null, float[] variants = null, int order = 0) =>
Root.Add(path, getter, setter, variants, order);

// Vector 2
public DMVector2 Add(string path, Func<Vector2> getter, Action<Vector2> setter = null, int order = 0) =>
Expand Down
4 changes: 2 additions & 2 deletions Assets/extDebug/Scripts/Menu/DMEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static T PrevEnum(T value)

#region Public Methods

public DMEnum(DMBranch parent, string path, Func<T> getter, Action<T> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMEnum(DMBranch parent, string path, Func<T> getter, Action<T> setter = null, T[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{
if (setter != null)
{
Expand All @@ -67,7 +67,7 @@ public DMEnum(DMBranch parent, string path, Func<T> getter, Action<T> setter = n
var intValue = (int)(object)value;
setter.Invoke((T)(object)(intGetter ^ intValue));
}, i);
}, order: i);
}

_flagBranch.Add("Back", BackAction, string.Empty, int.MaxValue);
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DMFloat : DMValue<float>

#region Public Methods

public DMFloat(DMBranch parent, string path, Func<float> getter, Action<float> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMFloat(DMBranch parent, string path, Func<float> getter, Action<float> setter = null, float[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{
SetPrecision(2);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMInt16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DMInt16 : DMValue<Int16>

#region Public Methods

public DMInt16(DMBranch parent, string path, Func<Int16> getter, Action<Int16> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMInt16(DMBranch parent, string path, Func<Int16> getter, Action<Int16> setter = null, Int16[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
5 changes: 2 additions & 3 deletions Assets/extDebug/Scripts/Menu/DMInt32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class DMInt32 : DMValue<Int32>

#region Public Methods

public DMInt32(DMBranch parent, string path, Func<Int32> getter, Action<Int32> setter = null, int order = 0) : base(parent, path, getter, setter, order)
{
}
public DMInt32(DMBranch parent, string path, Func<Int32> getter, Action<Int32> setter = null, Int32[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion

Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMInt64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DMInt64 : DMValue<Int64>

#region Public Methods

public DMInt64(DMBranch parent, string path, Func<Int64> getter, Action<Int64> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMInt64(DMBranch parent, string path, Func<Int64> getter, Action<Int64> setter = null, Int64[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMInt8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DMInt8 : DMValue<sbyte>

#region Public Methods

public DMInt8(DMBranch parent, string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMInt8(DMBranch parent, string path, Func<sbyte> getter, Action<sbyte> setter = null, sbyte[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DMLogs(DMBranch parent, string path, string description, IDMLogsContainer
_itemsLogs[i] = logItem;
}

_items[size] = new DMString(null, string.Empty, GetLogsPagination, int.MaxValue);
_items[size] = new DMString(null, string.Empty, GetLogsPagination, order: int.MaxValue);
}

public void RequestRepaint() => _canRepaint = true;
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DMString : DMValue<string>
{
#region Public Methods

public DMString(DMBranch parent, string path, Func<string> getter, int order = 0) : base(parent, path, getter, null, order)
public DMString(DMBranch parent, string path, Func<string> getter, Action<string> setter = null, string[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMUInt16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DMUInt16 : DMValue<UInt16>

#region Public Methods

public DMUInt16(DMBranch parent, string path, Func<UInt16> getter, Action<UInt16> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMUInt16(DMBranch parent, string path, Func<UInt16> getter, Action<UInt16> setter = null, UInt16[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMUInt32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DMUInt32 : DMValue<UInt32>

#region Public Methods

public DMUInt32(DMBranch parent, string path, Func<UInt32> getter, Action<UInt32> setter = null, int order = 0) : base(parent, path, getter, setter, order)
public DMUInt32(DMBranch parent, string path, Func<UInt32> getter, Action<UInt32> setter = null, UInt32[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order)
{ }

#endregion
Expand Down
Loading

0 comments on commit 5afe410

Please sign in to comment.