-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathToolRegistry.cs
49 lines (41 loc) · 1.83 KB
/
ToolRegistry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using Vintagestory.API.Common;
using Vintagestory.API.Datastructures;
namespace Vintagestory.ServerMods.WorldEdit
{
public class ToolRegistry
{
public static OrderedDictionary<string, Type> ToolTypes = new OrderedDictionary<string, Type>();
public static int NextFreeToolId = 1;
public static ToolBase InstanceFromType(string toolname, WorldEditWorkspace workspace, IBlockAccessor blockAccessor)
{
if (!ToolTypes.ContainsKey(toolname)) return null;
return (ToolBase)Activator.CreateInstance(ToolTypes[toolname], new object[] { workspace, blockAccessor });
}
public static void RegisterToolType(string name, Type type)
{
bool isNew = ToolTypes.ContainsKey(name);
ToolTypes[name] = type;
if (isNew) NextFreeToolId++;
}
public static bool HasTool(int toolId)
{
return ToolTypes.GetKeyAtIndex(toolId) != null;
}
public static void RegisterDefaultTools()
{
RegisterToolType("move", typeof(MoveTool));
RegisterToolType("repeat", typeof(RepeatTool));
RegisterToolType("select", typeof(SelectTool));
RegisterToolType("paintbrush", typeof(PaintBrushTool));
RegisterToolType("airbrush", typeof(AirBrushTool));
RegisterToolType("line", typeof(LineTool));
RegisterToolType("eraser", typeof(EraserTool));
RegisterToolType("floodfill", typeof(FloodFillTool));
RegisterToolType("raiselower", typeof(RaiseLowerTool));
RegisterToolType("growshrink", typeof(GrowShrinkTool));
RegisterToolType("erode", typeof(ErodeTool));
RegisterToolType("import", typeof(ImportTool));
}
}
}