Skip to content

Commit 7034663

Browse files
committed
refactor: Cleanup
1 parent ea1dfa0 commit 7034663

File tree

7 files changed

+25
-10
lines changed

7 files changed

+25
-10
lines changed

src/Moss.NET.Sdk/Core/Extensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public static ulong GetPointer(this string str)
3030

3131
public static ulong GetPointer<T>(this T @this)
3232
{
33-
return Utils.Serialize(@this, (JsonTypeInfo<T>)JsonContext.Default.GetTypeInfo(typeof(T)));
33+
return GetPointer(@this, (JsonTypeInfo<T>)JsonContext.Default.GetTypeInfo(typeof(T)));
34+
}
35+
36+
public static ulong GetPointer<T>(this T @this, JsonTypeInfo<T> typeInfo)
37+
{
38+
return Utils.Serialize(@this, typeInfo);
3439
}
3540
}

src/Moss.NET.Sdk/FFI/JsonContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Moss.NET.Sdk.FFI;
1212
[JsonSerializable(typeof(Color))]
1313
[JsonSerializable(typeof(TextColor))]
1414
[JsonSerializable(typeof(ContextButton))]
15+
[JsonSerializable(typeof(ContextMenu))]
1516
[JsonSerializable(typeof(List<ContextButton>))]
1617
[JsonSerializable(typeof(List<string>))]
1718
[JsonSerializable(typeof(List<ConfigGetD>))]

src/Moss.NET.Sdk/UI/ContextMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ public class ContextMenu(string key, List<ContextButton> buttons)
2323

2424
public static ContextMenu Get(string name) => Cache[name];
2525

26-
public void Open(ulong x, ulong y) => OpenContextMenu(this.GetPointer(), x, y);
26+
public void Open(ulong x, ulong y) => OpenContextMenu(Key.GetPointer(), x, y);
2727
}

src/Moss.NET.Sdk/UI/ContextMenuBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ContextMenu Build()
2424
{
2525
var cm = new ContextMenu(name, _buttons);
2626
RegisterContextMenu(cm.GetPointer());
27-
ContextMenu.Cache.Add(name, cm);
27+
ContextMenu.Cache[name] = cm;
2828

2929
return cm;
3030
}

src/Moss.NET.Sdk/UI/GUI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.InteropServices;
2+
using Moss.NET.Sdk.Core;
23
using Moss.NET.Sdk.FFI;
34

45
namespace Moss.NET.Sdk.UI;
@@ -8,4 +9,8 @@ public class GUI
89
[DllImport(Functions.DLL, EntryPoint = "moss_gui_invert_icon")]
910
private static extern void InvertIcon(ulong keyPtr, ulong resultKeyPtr);
1011

12+
public static void InvertIcon(string key, string resultKey)
13+
{
14+
InvertIcon(key.GetPointer(), resultKey.GetPointer());
15+
}
1116
}

src/SamplePlugin/SampleExtension.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override ExtensionInfo Register(MossState state)
3030
Defaults.SetDefaultValue("OUTLINE_COLOR", Color.Blue);
3131
Theme.Apply(new DarkTheme());
3232

33-
Assets.Add("swap.svg");
33+
Assets.Add("Assets/swap.svg");
3434

3535
var md = Storage.GetDocumentMetadata("0ba3df9c-8ca0-4347-8d7c-07471101baad");
3636
Pdk.Log(LogLevel.Info, $"Metadata: {md.VisibleName} with {md.Hash}");
@@ -48,6 +48,10 @@ public override ExtensionInfo Register(MossState state)
4848
new ContextButton("Sample Button", "notebook", "notebook", "no_action",
4949
"no_contextmenu"));
5050

51+
ContextMenu.Create("test_cm")
52+
.AddButton("test", "swap", "notebook", "no_action")
53+
.Build();
54+
5155
return new ExtensionInfo();
5256
}
5357

@@ -64,6 +68,12 @@ public override void ExtensionLoop(MossState state)
6468
Config.Get<string>("theme");
6569
Moss.NET.Sdk.Moss.GetState();
6670

71+
var cm = ContextMenu.Get("test_cm");
72+
73+
cm.Open(10, 10);
74+
75+
GUI.InvertIcon("swap", "swap_inverted");
76+
6777
InternalFunctions.ExportStatisticalData();
6878
}
6979

src/SamplePlugin/SampleScreen.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ public override void PreLoop()
2424
ScreenManager.SetValue("hello", true);
2525

2626
ScreenManager.GetValue<bool>("hello");
27-
28-
var cm = ContextMenu.Create("test_cm")
29-
.AddButton("test", "notebook", "notebook", "no_action")
30-
.Build();
31-
32-
cm.Open(10, 10);
3327
}
3428

3529
protected override void OnLoop()

0 commit comments

Comments
 (0)