Skip to content

Commit da564c2

Browse files
feat: Run all contracts added by plugins through controller.fixContract
For plugins that for some reason do not want their contracts automatically fixed a new possible return type for the getContractManifest hook was added. Plugins can tap the hook and return a [MissionManifest, true] to not have their contracts altered by fixContract.
1 parent 01133d4 commit da564c2

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

components/controller.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class Controller {
333333
>
334334
getContractManifest: SyncBailHook<
335335
[contractId: string, gameVersion: GameVersion, isGroup: boolean],
336-
MissionManifest | undefined
336+
MissionManifest | [MissionManifest, boolean] | undefined
337337
>
338338
fixContract: SyncHook<
339339
[contract: MissionManifest, gameVersion: GameVersion]
@@ -750,19 +750,33 @@ export class Controller {
750750
log(LogLevel.TRACE, `No game version.`, "Contracts")
751751
}
752752

753-
const optionalPluginJson = this.hooks.getContractManifest.call(
753+
let optionalPluginJson = this.hooks.getContractManifest.call(
754754
id,
755755
gameVersion,
756756
getGroup,
757757
)
758758

759759
if (optionalPluginJson) {
760-
// We skip fixing plugins as we assume they know what they're doing.
761-
return fastClone(
762-
getGroup
763-
? this.getGroupContract(optionalPluginJson, gameVersion)
764-
: optionalPluginJson,
765-
)
760+
// If a plugin returns [MissionManifest, true] instead of MissionManifest, do not fix the MissionManifest
761+
if ((optionalPluginJson as [MissionManifest, boolean])[1]) {
762+
optionalPluginJson = (
763+
optionalPluginJson as [MissionManifest, boolean]
764+
)[0]
765+
} else {
766+
optionalPluginJson = this.fixContract(
767+
optionalPluginJson as MissionManifest,
768+
gameVersion,
769+
)
770+
}
771+
772+
if (getGroup) {
773+
optionalPluginJson = this.getGroupContract(
774+
optionalPluginJson as MissionManifest,
775+
gameVersion,
776+
)
777+
}
778+
779+
return fastClone(optionalPluginJson as MissionManifest)
766780
}
767781

768782
const registryJson: MissionManifest | undefined = internalContracts[id]

0 commit comments

Comments
 (0)