forked from anegostudios/vscreativemod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
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("Paint brush", typeof(PaintBrushTool));
RegisterToolType("Raise/lower", typeof(RaiseLowerTool));
RegisterToolType("Air brush", typeof(AirBrushTool));
RegisterToolType("Erode", typeof(ErodeTool));
RegisterToolType("Import", typeof(ImportTool));
RegisterToolType("Eraser", typeof(EraserTool));
RegisterToolType("Grow/shrink", typeof(GrowShrinkTool));
RegisterToolType("Line", typeof(LineTool));
RegisterToolType("Flood Fill", typeof(FloodFillTool));
RegisterToolType("Select", typeof(SelectTool));
RegisterToolType("Move", typeof(MoveTool));
RegisterToolType("Repeat", typeof(RepeatTool));
}
}
}