Skip to content

Commit

Permalink
Make usages of Computer.postAllLoadedActions use event subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows10CE committed Sep 11, 2021
1 parent b08c3ad commit dbc2d66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
27 changes: 13 additions & 14 deletions PathfinderAPI/BaseGameFixes/MissionListingServerLoadTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,23 @@ internal static void FixMissionLoadTimes(ILContext il)
c.Emit(OpCodes.Ldloc_1);
c.EmitDelegate<Action<MissionListingServer, bool>>((listingDaemon, shouldGen) =>
{
ComputerLoader.postAllLoadedActions = (System.Action)Delegate.Combine(ComputerLoader.postAllLoadedActions, (System.Action)(
() =>
ComputerLoader.postAllLoadedActions += () =>
{
foreach (var file in Directory.GetFiles(listingDaemon.CustomFolderLoadPath, "*.xml"))
{
foreach (var file in Directory.GetFiles(listingDaemon.CustomFolderLoadPath, "*.xml"))
{
OS.currentInstance.branchMissions = new List<ActiveMission>();
listingDaemon.addMisison(MissionLoader.LoadContentMission(file));
}
OS.currentInstance.branchMissions = new List<ActiveMission>();
listingDaemon.addMisison(MissionLoader.LoadContentMission(file));
}
if (shouldGen)
if (shouldGen)
{
for (int i = 0; i < 2; i++)
{
for (int i = 0; i < 2; i++)
{
OS.currentInstance.branchMissions = new List<ActiveMission>();
listingDaemon.addMisison((ActiveMission)MissionGenerator.generate(2));
}
OS.currentInstance.branchMissions = new List<ActiveMission>();
listingDaemon.addMisison((ActiveMission)MissionGenerator.generate(2));
}
}));
}
};
});
}
}
Expand Down
31 changes: 14 additions & 17 deletions PathfinderAPI/Replacements/ContentLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ static ContentLoader()
var sourceComp = comp;
var origOs = os;
ComputerLoader.postAllLoadedActions = (System.Action) Delegate.Combine(
ComputerLoader.postAllLoadedActions,
(System.Action)(() =>
{
var nearNode = Programs.getComputer(os, nearNodeId);
if (nearNode != null)
sourceComp.location = nearNode.location + Corporation.getNearbyNodeOffset(nearNode.location, position, total, origOs.netMap, extraDistance, force);
}));
ComputerLoader.postAllLoadedActions += () =>
{
var nearNode = Programs.getComputer(os, nearNodeId);
if (nearNode != null)
sourceComp.location = nearNode.location + Corporation.getNearbyNodeOffset(nearNode.location, position, total, origOs.netMap, extraDistance, force);
};
});
executor.RegisterExecutor("Computer.proxy", (exec, info) =>
{
Expand Down Expand Up @@ -295,14 +293,13 @@ static ContentLoader()
var linked = info.Attributes.GetString("target");
var source = comp;
var origOS = os;
ComputerLoader.postAllLoadedActions = (System.Action)Delegate.Combine(
ComputerLoader.postAllLoadedActions,
(System.Action) (() =>
{
var linkedNode = Programs.getComputer(os, linked);
if (linkedNode != null)
source.links.Add(origOS.netMap.nodes.IndexOf(linkedNode));
}));
ComputerLoader.postAllLoadedActions += () =>
{
var linkedNode = Programs.getComputer(os, linked);
if (linkedNode != null)
source.links.Add(origOS.netMap.nodes.IndexOf(linkedNode));
};
});
executor.RegisterExecutor("Computer.trace", (exec, info) =>
{
Expand Down

0 comments on commit dbc2d66

Please sign in to comment.