Skip to content

Commit bce583f

Browse files
Refactor
1 parent c2a3b88 commit bce583f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+592
-1492
lines changed

toolkitcore/About/About.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<name>ToolkitCore</name>
44
<author>hodlhodl</author>
55
<supportedVersions>
6-
<li>1.1</li>
6+
<li>1.3</li>
77
</supportedVersions>
88
<packageId>hodlhodl.toolkitcore</packageId>
99
<description>Base mod for twitch toolkit integration</description>

toolkitcore/AddonMenu.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,15 @@ public class AddonMenu : IAddonMenu
3333
Find.WindowStack.TryRemove(window.GetType());
3434
Find.WindowStack.Add(window);
3535
}),
36-
new FloatMenuOption("Mixer", delegate ()
37-
{
38-
Window_Services window = new Window_Services(Window_Services.Tab.Mixer);
39-
Find.WindowStack.TryRemove(window.GetType());
40-
Find.WindowStack.Add(window);
41-
}),
42-
new FloatMenuOption("TestingMixer", delegate()
36+
new FloatMenuOption("Message Log", delegate()
4337
{
44-
Dialog_MixerAuthWizard window = new Dialog_MixerAuthWizard();
38+
Window_MessageLog window = new Window_MessageLog();
4539
Find.WindowStack.TryRemove(window.GetType());
4640
Find.WindowStack.Add(window);
4741
}),
48-
new FloatMenuOption("Message Log", delegate()
42+
new FloatMenuOption("Commands", delegate()
4943
{
50-
Window_MessageLog window = new Window_MessageLog();
44+
Window_Commands window = new Window_Commands();
5145
Find.WindowStack.TryRemove(window.GetType());
5246
Find.WindowStack.Add(window);
5347
}),
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
7+
using ToolkitCore.Database;
68
using ToolkitCore.Models;
79
using ToolkitCore.Utilities;
810
using Verse;
911

1012
namespace ToolkitCore.Controllers
1113
{
14+
[StaticConstructorOnStartup]
1215
public static class ChatCommandController
1316
{
14-
public static ToolkitChatCommand GetChatCommand(string commandText)
17+
static List<ToolkitChatCommandWrapper> toolkitChatCommandWrappers = new List<ToolkitChatCommandWrapper>();
18+
static ChatCommandController()
19+
{
20+
LoadCommandMethodSettings();
21+
LoadNewCommandMethods();
22+
}
23+
public static ToolkitChatCommandWrapper GetChatCommand(string commandText)
1524
{
1625
string baseCommand = CommandFilter.Parse(commandText).FirstOrDefault();
1726

@@ -20,9 +29,101 @@ public static ToolkitChatCommand GetChatCommand(string commandText)
2029
return null;
2130
}
2231

32+
return toolkitChatCommandWrappers.FirstOrDefault(
33+
c => c.CommandText.EqualsIgnoreCase(baseCommand)
34+
);
35+
}
36+
37+
public static List<ToolkitChatCommandWrapper> GetAllChatCommands()
38+
{
39+
return toolkitChatCommandWrappers;
40+
}
41+
42+
public static ToolkitChatCommand GetChatCommandDef(string commandText)
43+
{
2344
return DefDatabase<ToolkitChatCommand>.AllDefsListForReading.FirstOrDefault(
24-
c => c.commandText.EqualsIgnoreCase(baseCommand)
45+
c => c.commandText.EqualsIgnoreCase(commandText)
2546
);
26-
}
47+
}
48+
49+
static void LoadCommandMethodSettings()
50+
{
51+
DatabaseController.LoadObject(
52+
"CommandMethods",
53+
LoadedModManager.GetMod<ToolkitCore>(),
54+
out CommandMethodWrapper loadedCommands
55+
);
56+
if (loadedCommands == null) return;
57+
foreach (ToolkitChatCommandWrapper loadedCommand in loadedCommands.Commands)
58+
{
59+
ToolkitChatCommand def = DefDatabase<ToolkitChatCommand>.AllDefsListForReading.FirstOrDefault(
60+
c => c.defName.EqualsIgnoreCase(loadedCommand.DefName));
61+
if (def == null)
62+
{
63+
continue;
64+
}
65+
loadedCommand.DefName = def.defName;
66+
loadedCommand.Def = def;
67+
toolkitChatCommandWrappers.Add(loadedCommand);
68+
}
69+
}
70+
71+
static void LoadNewCommandMethods()
72+
{
73+
foreach(ToolkitChatCommand toolkitChatCommand in DefDatabase<ToolkitChatCommand>.AllDefs)
74+
{
75+
ToolkitChatCommandWrapper wrapper =
76+
toolkitChatCommandWrappers.Find((c) => c.DefName == toolkitChatCommand.defName);
77+
if (wrapper == null)
78+
{
79+
toolkitChatCommandWrappers.Add(new ToolkitChatCommandWrapper()
80+
{
81+
Def = toolkitChatCommand,
82+
DefName = toolkitChatCommand.defName,
83+
CommandText = toolkitChatCommand.commandText,
84+
Enabled = toolkitChatCommand.enabled,
85+
PermissionRole = toolkitChatCommand.permissionRole
86+
});
87+
}
88+
else
89+
{
90+
Log.Message(wrapper.CommandText);
91+
}
92+
}
93+
}
94+
95+
public static void SaveCommandMethodSettings()
96+
{
97+
DatabaseController.SaveObject(
98+
new CommandMethodWrapper()
99+
{
100+
Commands = toolkitChatCommandWrappers
101+
},
102+
"CommandMethods",
103+
LoadedModManager.GetMod<ToolkitCore>()
104+
); ;
105+
}
106+
107+
public static void ResetCommandMethodToDefaultSettings()
108+
{
109+
toolkitChatCommandWrappers = new List<ToolkitChatCommandWrapper>();
110+
foreach (ToolkitChatCommand def in DefDatabase<ToolkitChatCommand>.AllDefsListForReading)
111+
{
112+
toolkitChatCommandWrappers.Add(new ToolkitChatCommandWrapper()
113+
{
114+
Def = def,
115+
DefName = def.defName,
116+
CommandText = def.commandText,
117+
Enabled = def.enabled,
118+
PermissionRole = def.permissionRole
119+
});
120+
}
121+
}
122+
}
123+
124+
[Serializable]
125+
public class CommandMethodWrapper
126+
{
127+
public IEnumerable<ToolkitChatCommandWrapper> Commands { get; set; }
27128
}
28129
}

toolkitcore/Defs/Addon.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<defName>ToolkitCore</defName>
55
<label>ToolkitCore</label>
66
<menuClass>ToolkitCore.AddonMenu</menuClass>
7+
<permissionsClass>ToolkitCore.ToolkitCorePermissions</permissionsClass>
78
</ToolkitCore.Models.ToolkitAddon>
89
</Defs>

toolkitcore/Defs/Commands/Commands.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<commandText>hello</commandText>
66
<enabled>true</enabled>
77
<commandClass>ToolkitCore.CommandMethods.HelloWorld</commandClass>
8-
<requiresMod>false</requiresMod>
9-
<requiresBroadcaster>true</requiresBroadcaster>
8+
<permissionRole>Broadcaster</permissionRole>
109
</ToolkitCore.Models.ToolkitChatCommand>
1110
</Defs>

0 commit comments

Comments
 (0)