Skip to content

Commit 20f1224

Browse files
authored
Merge pull request #37 from KSP2Community/dev
0.10.0 Indexer Changes
2 parents 82b7302 + f0c991b commit 20f1224

File tree

29 files changed

+1919
-2202
lines changed

29 files changed

+1919
-2202
lines changed

.github/workflows/on-release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,35 @@ jobs:
7676
version: ${{ env.version }}
7777
zipball: ${{ env.zip }}
7878
changelog: ./changelog.md
79+
80+
- name: Update mod topic
81+
uses: Kerbalight/ksp2-forum-post-action@latest
82+
with:
83+
username: ${{ secrets.FORUM_USER }}
84+
password: ${{ secrets.FORUM_PASSWORD }}
85+
forum_topic_url: https://forum.kerbalspaceprogram.com/topic/221179-093-patch-manager/
86+
forum_topic_title: '[{version}] Patch Manager'
87+
spacedock_url: https://spacedock.info/mod/3482/Patch%20Manager
88+
version: ${{ env.version }}
89+
swinfo_path: 'plugin_template/swinfo.json'
90+
changelog: ./changelog.md
91+
92+
- name: Prepare content for discord
93+
shell: bash
94+
run: |
95+
echo -e "## Release v${version}\n" > ./content.md
96+
cat ./changelog.md >> ./content.md
97+
{
98+
echo 'discord_message<<EOF'
99+
cat ./content.md
100+
echo EOF
101+
} >> "$GITHUB_ENV"
102+
103+
- name: Publish update to Discord
104+
uses: tsickert/[email protected]
105+
with:
106+
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
107+
content: ${{ env.discord_message }}
108+
thread-id: '1171826066692776028'
109+
username: "Patch Manager"
110+
avatar-url: "https://spacedock.info/content/cheese3660_103715/Patch_Manager/thumb_Patch_Manager-1703507804.jpg"

plugin_template/swinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Patch Manager",
66
"description": "A mod for generic patching needs similar to KSP 1's Module Manager.",
77
"source": "https://github.com/KSP2Community/PatchManager",
8-
"version": "0.9.4",
8+
"version": "0.10.0",
99
"version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json",
1010
"ksp2_version": {
1111
"min": "0.2.0",

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)