Skip to content

Commit

Permalink
Merge pull request #11 from KSP2Community/0.1.1
Browse files Browse the repository at this point in the history
Add `@require` functionality
  • Loading branch information
jan-bures authored Sep 2, 2023
2 parents 109df58 + ab2ca7d commit 045d805
Show file tree
Hide file tree
Showing 27 changed files with 128 additions and 70 deletions.
10 changes: 6 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@
<PackageReference Include="JsonPeek" Version="1.2.0" PrivateAssets="all"/>
</ItemGroup>

<!-- Define the main target -->
<Target Label="Reading properties from swinfo.json" Name="ReadPropertiesFromJson" BeforeTargets="PreBuildEvent">
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$">
<Output TaskParameter="Result" ItemName="Swinfo"/>
</JsonPeek>
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$.dependencies">
<Output TaskParameter="Result" ItemName="Dependencies"/>
</JsonPeek>

<!-- Extract properties from the JSON -->
<PropertyGroup>
Expand All @@ -56,4 +52,10 @@
<RepositoryUrl>@(Swinfo -> '%(source)')</RepositoryUrl>
</PropertyGroup>
</Target>

<Target Name="ReadPackageVersionFromJson" BeforeTargets="PostBuild">
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$.version">
<Output TaskParameter="Result" PropertyName="Version"/>
</JsonPeek>
</Target>
</Project>
24 changes: 24 additions & 0 deletions PatchManager.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://raw.githubusercontent.com/KSP2Community/PatchManager/main/LICENSE</licenseUrl>
<description>$description$</description>
<tags>ksp ksp2 mod patching library</tags>
<projectUrl>https://github.com/KSP2Community/PatchManager/wiki</projectUrl>
<repository type="$repositoryType$" url="$repositoryUrl$" />
<readme>README.md</readme>
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
<files>
<file src="README.md" target="" />
<file src="LICENSE" target="LICENSE" />
<file src="temp_nuget\*.dll" target="lib/netstandard2.0/" />
<file src="temp_nuget\*.xml" target="lib/netstandard2.0/" />
</files>
</package>
2 changes: 1 addition & 1 deletion StandalonePatchTester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void AddGenerator(ITextAssetGenerator generator)

}

var universe = new Universe(Add, Console.WriteLine, Console.WriteLine, AddGenerator);
var universe = new Universe(Add, Console.WriteLine, Console.WriteLine, AddGenerator, new());
universe.LoadPatchesInDirectory(new DirectoryInfo("patches"), "test");

Console.WriteLine($"{universe.AllLibraries.Count} libraries loaded!");
Expand Down
1 change: 1 addition & 0 deletions StandalonePatchTester/StandalonePatchTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Nullable>enable</Nullable>
<BaseOutputPath>$(SolutionDir)/build/bin/testing/$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$(SolutionDir)build/obj/testing/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<NoWarn>$(NoWarn);MSB3539</NoWarn>
</PropertyGroup>

<!-- References -->
Expand Down
12 changes: 6 additions & 6 deletions plugin_template/swinfo.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"spec": "1.3",
"mod_id": "PatchManager",
"author": "munix",
"author": "KSP2 Community",
"name": "Patch Manager",
"description": "A mod for generic patching needs similar to KSP 1's Module Manager.",
"source": "https://github.com/jan-bures/PatchManager",
"version": "0.1.0",
"version_check": "https://raw.githubusercontent.com/jan-bures/PatchManager/main/plugin_template/swinfo.json",
"source": "https://github.com/KSP2Community/PatchManager",
"version": "0.1.1",
"version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.1.3",
"min": "0.1.4",
"max": "*"
},
"dependencies": [
{
"id": "com.github.x606.spacewarp",
"version": {
"min": "1.3.0",
"min": "1.4.2",
"max": "*"
}
}
Expand Down
25 changes: 15 additions & 10 deletions src/PatchManager.Core/Assets/PatchingManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections;
using HarmonyLib;
using System.Reflection;
using KSP.Game;
using KSP.Game.Flow;
using PatchManager.Core.Cache;
Expand All @@ -9,10 +9,10 @@
using PatchManager.SassyPatching.Execution;
using PatchManager.Shared;
using PatchManager.Shared.Interfaces;
using SpaceWarp.API.Mods;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Coroutine = MoonSharp.Interpreter.Coroutine;

namespace PatchManager.Core.Assets;

Expand All @@ -22,8 +22,6 @@ internal static class PatchingManager
private static readonly List<ITextAssetGenerator> Generators = new();
private static Universe _universe;



private static readonly PatchHashes CurrentPatchHashes = PatchHashes.CreateDefault();

private static int _initialLibraryCount;
Expand All @@ -32,7 +30,14 @@ internal static class PatchingManager
internal static int TotalPatchCount;
public static void GenerateUniverse()
{
_universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo,RegisterGenerator);
// Need to do some reflection here as I forgot to make something public :3
var manager = typeof(BaseSpaceWarpPlugin).Assembly.GetTypes()
.FirstOrDefault(type => type.Name == "SpaceWarpManager")!;
var field = manager.GetFields(BindingFlags.Static|BindingFlags.NonPublic)
.FirstOrDefault(x => x.Name == "AllPlugins")!;
var plugins = (List<SpaceWarpPluginDescriptor>)field.GetValue(null);
_universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo, RegisterGenerator,
plugins.Select(x => x.Guid).ToList());
_initialLibraryCount = _universe.AllLibraries.Count;
}

Expand Down Expand Up @@ -184,7 +189,7 @@ private static AsyncOperationHandle<IList<TextAsset>> RebuildCache(string label)
{
Label = name,
ArchiveFilename = archiveFilename,
Assets = new List<string> { name }
Assets = new List<string> { name }
});
}
createdAsset.Clear();
Expand Down Expand Up @@ -269,7 +274,7 @@ public static void CreateNewAssets(Action resolve, Action<string> reject)
{
var text = generator.Create(out var label, out var name);
Logging.LogInfo($"Generated an asset with the label {label}, and name {name}:\n{text}");

if (!_createdAssets.ContainsKey(label))
_createdAssets[label] = new List<(string name, string text)>();
_createdAssets[label].Add((name, text));
Expand All @@ -285,8 +290,8 @@ public static void CreateNewAssets(Action resolve, Action<string> reject)

public static void RebuildAllCache(Action resolve, Action<string> reject)
{


var distinctKeys = _universe.LoadedLabels.Concat(_createdAssets.Keys).Distinct().ToList();

LoadingBarPatch.InjectPatchManagerTips = true;
Expand Down Expand Up @@ -326,7 +331,7 @@ bool killLoadingBarTips
{
while (!handle.IsDone)
{
// "Shuffle" it
// "Shuffle" it
GameManager.Instance.Game.UI.LoadingBar.ShuffleLoadingTip();
yield return null;
}
Expand Down
1 change: 0 additions & 1 deletion src/PatchManager.Core/GlobalUsings.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/PatchManager.Core/PatchManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- References -->
<ItemGroup Label="NuGet package references">
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.1.4" PrivateAssets="all" />
<PackageReference Include="SpaceWarp" Version="1.4" PrivateAssets="all" />
<PackageReference Include="SpaceWarp" Version="1.4.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Label="Project references">
<ProjectReference Include="$(SolutionDir)/src/PatchManager.SassyPatching/PatchManager.SassyPatching.csproj" Private="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ISelectable ConvertToSelectable(string type, string name, string jsonData
return new JTokenSelectable(() => { }, JToken.Parse(jsonData), name, type);
}

/// <inheritdoc />
public INewAsset CreateNew(List<DataValue> dataValues)
{
var label = dataValues[0].String;
Expand Down
7 changes: 6 additions & 1 deletion src/PatchManager.Parts/PartsModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using PatchManager.Shared.Modules;
using JetBrains.Annotations;
using PatchManager.Shared.Modules;

namespace PatchManager.Parts;

/// <summary>
/// Part patching module.
/// </summary>
[UsedImplicitly]
public class PartsModule : BaseModule
{
}
8 changes: 5 additions & 3 deletions src/PatchManager.Parts/PartsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

namespace PatchManager.Parts;

/// <summary>
/// Utilities for parts patching.
/// </summary>
public static class PartsUtilities
{

private static Dictionary<string, (Type componentModule, Type behaviour)> _componentModules;

private static void BuildComponentModuleDictionary()
Expand Down Expand Up @@ -35,7 +37,7 @@ private static void BuildComponentModuleDictionary()
}
}
}

internal static IReadOnlyDictionary<string, (Type componentModule, Type behaviour)> ComponentModules
{
get
Expand Down Expand Up @@ -70,7 +72,7 @@ private static void BuildDataModuleDictionary()
}
}
}

internal static IReadOnlyDictionary<string, Type> DataModules
{
get
Expand Down
1 change: 1 addition & 0 deletions src/PatchManager.Parts/Rulesets/PartsRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public ISelectable ConvertToSelectable(string type, string name, string jsonData
return new PartSelectable(jsonData);
}

/// <inheritdoc />
public INewAsset CreateNew(List<DataValue> dataValues) => throw new NotImplementedException();
}
1 change: 1 addition & 0 deletions src/PatchManager.Parts/Selectables/ModuleSelectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ public override ISelectable AddElement(string elementType)
/// <inheritdoc />
public override string Serialize() => _jToken.ToString();

/// <inheritdoc />
public override DataValue GetValue() => DataValue.FromJToken(_jToken);
}
1 change: 1 addition & 0 deletions src/PatchManager.Parts/Selectables/PartSelectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ public override ISelectable AddElement(string elementType)
/// <inheritdoc />
public override string Serialize() => _modified ? _deleted ? "" : JObject.ToString() : _originalData;

/// <inheritdoc />
public override DataValue GetValue() => OpenModification().Get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class ResourceContainersSelectable : BaseSelectable
{
private readonly JArray _containers;
private PartSelectable _selectable;

internal ResourceContainersSelectable(JArray containers, PartSelectable selectable)
{
_containers = containers;
Expand Down Expand Up @@ -67,5 +67,6 @@ public override ISelectable AddElement(string elementType)
/// <inheritdoc />
public override string Serialize() => _containers.ToString();

/// <inheritdoc />
public override DataValue GetValue() => DataValue.FromJToken(_containers);
}
7 changes: 6 additions & 1 deletion src/PatchManager.Resources/ResourcesModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using PatchManager.Shared.Modules;
using JetBrains.Annotations;
using PatchManager.Shared.Modules;

namespace PatchManager.Resources;

/// <summary>
/// Resource patching module.
/// </summary>
[UsedImplicitly]
public class ResourcesModule : BaseModule
{
}
8 changes: 4 additions & 4 deletions src/PatchManager.Resources/Selectables/RecipeSelectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace PatchManager.Resources.Selectables;
/// </summary>
public sealed class RecipeSelectable : BaseSelectable
{
private bool _modified = false;
private bool _deleted = false;

private bool _modified;
private bool _deleted;
private readonly string _originalData;
internal readonly JObject JObject;
internal readonly JArray Ingredients;

/// <summary>
/// Marks this resource selectable as having been modified any level down
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>PatchManager.SassyPatching.Tests</RootNamespace>
<NoWarn>$(NoWarn);NU1701</NoWarn>
</PropertyGroup>

<!-- References -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class ArgumentValidator : ParseValidator<Argument>
/// A field that is used to match against the corresponding field in a node of type <see cref="Argument"/>
/// </summary>
public string Name = "";

/// <summary>
/// A validator that is used to match against the corresponding node in a node of type <see cref="Argument"/>
/// </summary>
public ParseValidator? Value = null;
public ParseValidator Value = null;

/// <summary>
/// Determines if a node matches the tree defined by this validator
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CallArgumentValidator : ParseValidator<CallArgument>
/// <summary>
/// A field that is used to match against the corresponding field in a node of type <see cref="CallArgument"/>
/// </summary>
public string? ArgumentName = null;
public string ArgumentName = null;
/// <summary>
/// A validator that is used to match against the corresponding node in a node of type <see cref="CallArgument"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class ConditionalValidator : ParseValidator<Conditional>
/// </summary>
public ParseValidator Condition = new FalseValidator();
/// <summary>
/// A list of validators used to match against the corresponding list of nodes in a value of type <see cref="Conditional"/>
/// A list of validators used to match against the corresponding list of nodes in a value of type <see cref="Conditional"/>
/// </summary>
public List<ParseValidator> Body = new();
/// <summary>
/// A validator that is used to match against the corresponding node in a node of type <see cref="Conditional"/>
/// </summary>
public ParseValidator? Else = null;
public ParseValidator Else = null;
/// <summary>
/// Determines if a node matches the tree defined by this validator
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FieldValidator : ParseValidator<Field>
/// <summary>
/// A validator that is used to match against the corresponding node in a node of type <see cref="Field"/>
/// </summary>
public ParseValidator? Indexer = null;
public ParseValidator Indexer = null;
/// <summary>
/// A validator that is used to match against the corresponding node in a node of type <see cref="Field"/>
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/PatchManager.SassyPatching/Execution/Universe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ static Universe()
/// <param name="registerPatcher">This action receives patchers and registers them for later execution</param>
/// <param name="errorLogger">The action to be taken to log an error</param>
/// <param name="messageLogger">The action to be taken to log a message</param>
public Universe(Action<ITextPatcher> registerPatcher, Action<string> errorLogger, Action<string> messageLogger, Action<ITextAssetGenerator> registerGenerator)
public Universe(Action<ITextPatcher> registerPatcher, Action<string> errorLogger, Action<string> messageLogger, Action<ITextAssetGenerator> registerGenerator, List<string> allMods)
{
RegisterPatcher = registerPatcher;
_errorLogger = errorLogger;
MessageLogger = messageLogger;
RegisterGenerator = registerGenerator;
LoadedLabels = new List<string>(_preloadedLabels);
AllMods = allMods;
}

// TODO: Fix this so that other mods stages get their guids working
Expand Down
Loading

0 comments on commit 045d805

Please sign in to comment.