Skip to content

Commit b7e1f6e

Browse files
committed
#1 : find GameObjects by path via field rather than node name since it can have slashes and spaces
1 parent 2b9a32f commit b7e1f6e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

GameData/Mutiny/test.cfg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ SCENE_PATCH
44
type = ModifyObject
55
scene = VABmodern
66

7-
VABmodern
7+
GameObject
88
{
9+
path = VABmodern/VAB_interior_modern/Day Lights/Shadow Light
10+
911
Components
1012
{
11-
Transform
13+
Light
1214
{
13-
localScale = 0.1, 0.1, 0.1
15+
color = 1,0,0
1416
}
1517
}
1618
}

Source/ModifyObject.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ public override void Load(ConfigNode configNode)
1818

1919
foreach (var childNode in configNode.nodes.nodes)
2020
{
21-
m_gameObjectMutators.Add(childNode.name, CreateMutators(childNode, typeof(GameObject)));
21+
if (childNode.name == "GameObject")
22+
{
23+
string path = childNode.GetValue("path");
24+
childNode.RemoveValue("path");
25+
26+
if (path == null)
27+
{
28+
Log.Error("ModifyObject patch must have a `path` field for each GameObject node");
29+
}
30+
31+
m_gameObjectMutators.Add(path, CreateMutators(childNode, typeof(GameObject)));
32+
}
2233
}
2334
}
2435

@@ -91,10 +102,11 @@ private static void CreateObjectMutators(ConfigNode configNode, Type objectType,
91102
}
92103
}
93104

105+
// these should probably be wrapped up in a factory class or something
94106
static Dictionary<Type, Dictionary<string, Action<ConfigNode, Type, List<Action<object>>>>> x_customNodeHandlers = new()
95107
{
96108
{
97-
typeof(GameObject), new Dictionary<string, Action<ConfigNode, Type, List<Action<object>>>>
109+
typeof(GameObject), new ()
98110
{
99111
{ "Components", CreateComponentMutators },
100112
}

0 commit comments

Comments
 (0)