Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.10.0 Indexer Changes #37

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,35 @@ jobs:
version: ${{ env.version }}
zipball: ${{ env.zip }}
changelog: ./changelog.md

- name: Update mod topic
uses: Kerbalight/ksp2-forum-post-action@latest
with:
username: ${{ secrets.FORUM_USER }}
password: ${{ secrets.FORUM_PASSWORD }}
forum_topic_url: https://forum.kerbalspaceprogram.com/topic/221179-093-patch-manager/
forum_topic_title: '[{version}] Patch Manager'
spacedock_url: https://spacedock.info/mod/3482/Patch%20Manager
version: ${{ env.version }}
swinfo_path: 'plugin_template/swinfo.json'
changelog: ./changelog.md

- name: Prepare content for discord
shell: bash
run: |
echo -e "## Release v${version}\n" > ./content.md
cat ./changelog.md >> ./content.md
{
echo 'discord_message<<EOF'
cat ./content.md
echo EOF
} >> "$GITHUB_ENV"

- name: Publish update to Discord
uses: tsickert/[email protected]
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
content: ${{ env.discord_message }}
thread-id: '1171826066692776028'
username: "Patch Manager"
avatar-url: "https://spacedock.info/content/cheese3660_103715/Patch_Manager/thumb_Patch_Manager-1703507804.jpg"
2 changes: 1 addition & 1 deletion plugin_template/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Patch Manager",
"description": "A mod for generic patching needs similar to KSP 1's Module Manager.",
"source": "https://github.com/KSP2Community/PatchManager",
"version": "0.9.4",
"version": "0.10.0",
"version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.2.0",
Expand Down
59 changes: 11 additions & 48 deletions src/PatchManager.Parts/Modifiables/PartModifiable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using PatchManager.Parts.Selectables;
using PatchManager.SassyPatching;
using PatchManager.SassyPatching.Modifiables;
using Enumerable = UniLinq.Enumerable;

namespace PatchManager.Parts.Modifiables;

Expand All @@ -14,63 +15,25 @@ public sealed class PartModifiable : CustomJTokenModifiable
internal PartModifiable(PartSelectable selectable) : base(selectable.JObject["data"],selectable.SetModified)
{
_selectable = selectable;
CustomIndexAdaptors = new();
CustomElementAdaptors = new();
CustomClassAdaptors = new()
{
["resourceContainers"] = ResourceContainerClassAdapter,
["attachNodes"] = AttachNodesClassAdaptor
};
}


private static bool ResourceContainerClassAdapter(JToken resourceContainer, string className) =>
resourceContainer.Contains("name") && (string)resourceContainer["name"] == className;

private static bool AttachNodesClassAdaptor(JToken attachNode, string className) =>
attachNode.Contains("nodeID") && (string)attachNode["nodeID"] == className;

private static JToken ModuleElementAdaptor(JToken module, string elementName)
{
var moduleData = module["ModuleData"];
return moduleData.FirstOrDefault(data => (string)data["Name"] == elementName);
}

private static JToken ModuleIndexAdaptor(JToken module, ulong index)
{
return module["ModuleData"][(int)index];
}

/// <inheritdoc />
protected override bool CustomFieldAdaptor(string fieldName, out JToken field, out Func<JToken, string, bool> classAdaptor, out Func<JToken, ulong, JToken> indexAdaptor,
out Func<JToken, string, JToken> elementAdaptor)
public override DataValue GetFieldValue(string fieldName)
{
classAdaptor = null;
elementAdaptor = null;
indexAdaptor = null;
field = null;
var repl = fieldName.Replace("PartComponent", "");
foreach (var module in JToken["serializedPartModules"])
if (JToken is not JObject jObject)
return DataValue.Null;
if(!jObject.ContainsKey("serializedPartModules"))
return DataValue.Null;
foreach (var module in jObject["serializedPartModules"])
{
if (((string)module["Name"]).Replace("PartComponent", "") != repl) continue;
classAdaptor = null; // As modules have a weird childing system, so we can't easily just do this w/ our custom json adapter
elementAdaptor = ModuleElementAdaptor;
indexAdaptor = ModuleIndexAdaptor;
field = module;
return true;
if (module is not JObject moduleObject)continue;
if (moduleObject.ContainsKey("Name") && ((string)moduleObject["Name"])!.Replace("PartComponent", "") == repl)
return DataValue.FromJToken(module);
}
return false;
return DataValue.Null;
}

/// <inheritdoc />
protected override Dictionary<string, Func<JToken, string, bool>> CustomClassAdaptors { get; }

/// <inheritdoc />
protected override Dictionary<string, Func<JToken, ulong, JToken>> CustomIndexAdaptors { get; }

/// <inheritdoc />
protected override Dictionary<string, Func<JToken, string, JToken>> CustomElementAdaptors { get; }

/// <inheritdoc />
public override void Set(DataValue dataValue)
{
Expand Down
Loading
Loading