Skip to content

Commit ca8e2ee

Browse files
committed
Possible nested indexer support, with map syntax
1 parent f4a6b77 commit ca8e2ee

27 files changed

+1886
-2201
lines changed

src/PatchManager.Parts/Modifiables/PartModifiable.cs

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using PatchManager.Parts.Selectables;
33
using PatchManager.SassyPatching;
44
using PatchManager.SassyPatching.Modifiables;
5+
using Enumerable = UniLinq.Enumerable;
56

67
namespace PatchManager.Parts.Modifiables;
78

@@ -14,63 +15,25 @@ public sealed class PartModifiable : CustomJTokenModifiable
1415
internal PartModifiable(PartSelectable selectable) : base(selectable.JObject["data"],selectable.SetModified)
1516
{
1617
_selectable = selectable;
17-
CustomIndexAdaptors = new();
18-
CustomElementAdaptors = new();
19-
CustomClassAdaptors = new()
20-
{
21-
["resourceContainers"] = ResourceContainerClassAdapter,
22-
["attachNodes"] = AttachNodesClassAdaptor
23-
};
24-
}
25-
26-
27-
private static bool ResourceContainerClassAdapter(JToken resourceContainer, string className) =>
28-
resourceContainer.Contains("name") && (string)resourceContainer["name"] == className;
29-
30-
private static bool AttachNodesClassAdaptor(JToken attachNode, string className) =>
31-
attachNode.Contains("nodeID") && (string)attachNode["nodeID"] == className;
32-
33-
private static JToken ModuleElementAdaptor(JToken module, string elementName)
34-
{
35-
var moduleData = module["ModuleData"];
36-
return moduleData.FirstOrDefault(data => (string)data["Name"] == elementName);
37-
}
38-
39-
private static JToken ModuleIndexAdaptor(JToken module, ulong index)
40-
{
41-
return module["ModuleData"][(int)index];
4218
}
4319

4420
/// <inheritdoc />
45-
protected override bool CustomFieldAdaptor(string fieldName, out JToken field, out Func<JToken, string, bool> classAdaptor, out Func<JToken, ulong, JToken> indexAdaptor,
46-
out Func<JToken, string, JToken> elementAdaptor)
21+
public override DataValue GetFieldValue(string fieldName)
4722
{
48-
classAdaptor = null;
49-
elementAdaptor = null;
50-
indexAdaptor = null;
51-
field = null;
5223
var repl = fieldName.Replace("PartComponent", "");
53-
foreach (var module in JToken["serializedPartModules"])
24+
if (JToken is not JObject jObject)
25+
return DataValue.Null;
26+
if(!jObject.ContainsKey("serializedPartModules"))
27+
return DataValue.Null;
28+
foreach (var module in jObject["serializedPartModules"])
5429
{
55-
if (((string)module["Name"]).Replace("PartComponent", "") != repl) continue;
56-
classAdaptor = null; // As modules have a weird childing system, so we can't easily just do this w/ our custom json adapter
57-
elementAdaptor = ModuleElementAdaptor;
58-
indexAdaptor = ModuleIndexAdaptor;
59-
field = module;
60-
return true;
30+
if (module is not JObject moduleObject)continue;
31+
if (moduleObject.ContainsKey("Name") && ((string)moduleObject["Name"])!.Replace("PartComponent", "") == repl)
32+
return DataValue.FromJToken(module);
6133
}
62-
return false;
34+
return DataValue.Null;
6335
}
6436

65-
/// <inheritdoc />
66-
protected override Dictionary<string, Func<JToken, string, bool>> CustomClassAdaptors { get; }
67-
68-
/// <inheritdoc />
69-
protected override Dictionary<string, Func<JToken, ulong, JToken>> CustomIndexAdaptors { get; }
70-
71-
/// <inheritdoc />
72-
protected override Dictionary<string, Func<JToken, string, JToken>> CustomElementAdaptors { get; }
73-
7437
/// <inheritdoc />
7538
public override void Set(DataValue dataValue)
7639
{

0 commit comments

Comments
 (0)