Skip to content

Commit ee3b894

Browse files
authored
Deprecate modIsInstalled in favour of new SMFv3-style shims (#712)
Introduces `modEnabledForUser` and `modEnabledForGame` from #710 and deprecates the existing `modIsInstalled` in favour of the new functions. SMFv2 does not actually provide the necessary data to check the mod version, or information for a specific game, so these functions currently have the exact same behaviour as `modIsInstalled`. Nonetheless, they have the same signature as the ones in #710, so will help get developers in the habit of specifying the correct information. -------- #### General - [x] I've run Prettier to format any changed files - [x] I've verified that my changes work, and included a test plan -------- #### Testing - [x] I have added or considered adding unit/integration tests that cover any code changes
2 parents 4c80f73 + 4c0a51e commit ee3b894

2 files changed

Lines changed: 68 additions & 11 deletions

File tree

components/controller.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,15 @@ export class Controller {
476476
*
477477
* @param modId The mod's ID.
478478
* @returns If the mod is unavailable. You should probably abort initialization if true is returned. Also returns true if the `overrideFrameworkChecks` flag is set.
479-
* @deprecated since v5.5.0, use `!controller.smf.modIsInstalled`
479+
* @deprecated since v5.5.0, use `!controller.smf.modEnabledForUser` or `!controller.smf.modEnabledForGame`
480480
*/
481481
public addClientSideModDependency(modId: string): boolean {
482-
log(
483-
LogLevel.WARN,
484-
"controller.addClientSideModDependency is deprecated, use !controller.smf.modIsInstalled instead!",
485-
"plugins",
482+
deprecated(
483+
"controller.addClientSideModDependency",
484+
"controller.smf.modEnabledForUser or controller.smf.modEnabledForGame",
485+
"v9",
486486
)
487+
487488
return (
488489
getFlag("overrideFrameworkChecks") === true ||
489490
!this.smf.modIsInstalled(modId)
@@ -497,14 +498,15 @@ export class Controller {
497498
*
498499
* @param modId The mod's ID.
499500
* @returns If the mod is available (or the `overrideFrameworkChecks` flag is set). You should probably abort initialisation if false is returned.
500-
* @deprecated since v7.0.0, use `controller.smf.modIsInstalled`
501+
* @deprecated since v7.0.0, use `controller.smf.modEnabledForUser` or `controller.smf.modEnabledForGame`
501502
*/
502503
public modIsInstalled(modId: string): boolean {
503-
log(
504-
LogLevel.WARN,
505-
"controller.modIsInstalled is deprecated, use controller.smf.modIsInstalled instead!",
506-
"plugins",
504+
deprecated(
505+
"controller.modIsInstalled",
506+
"controller.smf.modEnabledForUser or controller.smf.modEnabledForGame",
507+
"v9",
507508
)
509+
508510
return this.smf.modIsInstalled(modId)
509511
}
510512

components/smfSupport.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ import { Controller } from "./controller"
2020
import { existsSync, readFileSync } from "fs"
2121
import { getFlag } from "./flags"
2222
import { log, LogLevel } from "./loggingInterop"
23-
import { MissionManifest, SMFLastDeploy } from "./types/types"
23+
import {
24+
GameVersion,
25+
JwtData,
26+
MissionManifest,
27+
SMFLastDeploy,
28+
} from "./types/types"
2429
import path, { basename, join } from "path"
2530
import { readFile } from "fs/promises"
2631
import { menuSystemDatabase } from "./menus/menuSystem"
2732
import { parse } from "json5"
33+
import { deprecated } from "./utils"
2834

2935
type LastServerSideData = SMFLastDeploy["lastServerSideStates"]
3036

@@ -216,8 +222,57 @@ export class SMFSupport {
216222
*
217223
* @param modId The mod's ID.
218224
* @returns If the mod is available (or the `overrideFrameworkChecks` flag is set). You should probably abort initialisation if false is returned.
225+
* @deprecated since v8.9.0, use `controller.smf.modEnabledForUser` or `controller.smf.modEnabledForGame`
219226
*/
220227
public modIsInstalled(modId: string): boolean {
228+
deprecated(
229+
"controller.smf.modIsInstalled",
230+
"controller.smf.modEnabledForUser or controller.smf.modEnabledForGame",
231+
"v9",
232+
)
233+
234+
return (
235+
this.lastDeploy?.loadOrder.includes(modId) ||
236+
getFlag("overrideFrameworkChecks") === true
237+
)
238+
}
239+
240+
/**
241+
* Returns whether a mod is enabled for the given user, by checking the deployments from Simple Mod Framework.
242+
* Note that if the user has not yet logged in, this function will return null.
243+
*
244+
* @param userId The user ID to check against.
245+
* @param modRef The mod ID and SemVer version range, in the form `id@version`.
246+
* @returns If the mod is enabled (or the `overrideFrameworkChecks` flag is set).
247+
*/
248+
public modEnabledForUser(userId: string, modRef: string): boolean | null {
249+
const modId = modRef.split("@")[0]
250+
251+
// Until SMFv3, we don't have the necessary information to
252+
// actually check more than whether the mod is installed.
253+
return (
254+
this.lastDeploy?.loadOrder.includes(modId) ||
255+
getFlag("overrideFrameworkChecks") === true
256+
)
257+
}
258+
259+
/**
260+
* Returns whether a mod is enabled for the given game version and platform, by checking the deployments from Simple Mod Framework.
261+
*
262+
* @param gameVersion The game version to check against.
263+
* @param platform The platform to check against.
264+
* @param modRef The mod ID and SemVer version range, in the form `id@version`.
265+
* @returns If the mod is enabled (or the `overrideFrameworkChecks` flag is set).
266+
*/
267+
public modEnabledForGame(
268+
gameVersion: GameVersion,
269+
platform: JwtData["platform"],
270+
modRef: string,
271+
): boolean {
272+
const modId = modRef.split("@")[0]
273+
274+
// Until SMFv3, we don't have the necessary information to
275+
// actually check more than whether the mod is installed.
221276
return (
222277
this.lastDeploy?.loadOrder.includes(modId) ||
223278
getFlag("overrideFrameworkChecks") === true

0 commit comments

Comments
 (0)