Skip to content

Commit

Permalink
Merge pull request #16 from KSP2Community/dev
Browse files Browse the repository at this point in the history
Patchmanager 0.3.2
  • Loading branch information
cheese3660 authored Nov 8, 2023
2 parents a07e8cb + 6c46300 commit 67dae4a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
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.3.1",
"version": "0.3.2",
"version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.1.5",
Expand Down
22 changes: 13 additions & 9 deletions src/PatchManager.Core/CoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,28 @@ public override void Preload()
if (!isValid)
{
_wasCacheInvalidated = true;
SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
() => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
() => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0,() => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(1,() => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(2, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator));
// SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
// () => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
// SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
// () => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
}
else
{
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator));
}
}

/// <summary>
/// Registers the provider and locator for cached assets.
/// </summary>
public override void Load()
private void RegisterResourceLocator(Action resolve, Action<string> reject)
{

Logging.LogInfo("Registering resource locator");
Addressables.ResourceManager.ResourceProviders.Add(new ArchiveResourceProvider());
Locators.Register(new ArchiveResourceLocator());
resolve();
}

/// <inheritdoc />
public override VisualElement GetDetails()
{
Expand Down
3 changes: 2 additions & 1 deletion src/PatchManager.Core/PatchManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- References -->
<ItemGroup Label="NuGet package references">
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" />
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.1.5" PrivateAssets="all" />
<PackageReference Include="SpaceWarp" Version="1.5.2" PrivateAssets="all" />
<PackageReference Include="SpaceWarp" Version="1.5.2" PrivateAssets="all" Publicize="true"/>
</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 @@ -21,6 +21,8 @@ public override void DoAction(Action resolve, Action<string> reject)
resolve();
return;
}
List<int> toRemove = new();
int idx = 0;
foreach (var vessel in _loadGameData.SavedGame.Vessels)
{
// Lets change only a few things
Expand All @@ -29,6 +31,12 @@ public override void DoAction(Action resolve, Action<string> reject)
{
var name = part.partName;
var def = GameManager.Instance.Game.Parts.Get(name);
if (def == null)
{
Logging.LogWarning($"Invalid part {name} found on vessel {vessel.AssemblyDefinition.assemblyName}, removing vessel from save file\n");
toRemove.Add(idx);
break;
}
for (var i = part.PartModulesState.Count - 1; i >= 0; i--)
{
var i2 = i;
Expand Down Expand Up @@ -59,7 +67,16 @@ public override void DoAction(Action resolve, Action<string> reject)
}
}
}
idx += 1;
}

toRemove.Reverse();
var vesselList = _loadGameData.SavedGame.Vessels.ToList();
foreach (var removal in toRemove)
{
vesselList.RemoveAt(removal);
}
_loadGameData.SavedGame.Vessels = vesselList.ToArray();
resolve();
}
}

0 comments on commit 67dae4a

Please sign in to comment.