Skip to content

Commit 90bbe60

Browse files
committed
feat: replace smf.modIsInstalled with new helpers
1 parent 2160d8c commit 90bbe60

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

components/smfSupport.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ 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"
@@ -216,11 +221,54 @@ export class SMFSupport {
216221
*
217222
* @param modId The mod's ID.
218223
* @returns If the mod is available (or the `overrideFrameworkChecks` flag is set). You should probably abort initialisation if false is returned.
224+
* @deprecated since v8.9.0, use `controller.smf.modEnabledForUser` or `controller.smf.modEnabledForGame`
219225
*/
220226
public modIsInstalled(modId: string): boolean {
221227
return (
222228
this.lastDeploy?.loadOrder.includes(modId) ||
223229
getFlag("overrideFrameworkChecks") === true
224230
)
225231
}
232+
233+
/**
234+
* Returns whether a mod is enabled for the given user, by checking the deployments from Simple Mod Framework.
235+
* Note that if the user has not yet logged in, this function will return null.
236+
*
237+
* @param userId The user ID to check against.
238+
* @param modRef The mod ID and SemVer version range, in the form `id@version`.
239+
* @returns If the mod is enabled (or the `overrideFrameworkChecks` flag is set).
240+
*/
241+
public modEnabledForUser(userId: string, modRef: string): boolean | null {
242+
const modId = modRef.split("@")[0]
243+
244+
// Until SMFv3, we don't have the necessary information to
245+
// actually check more than whether the mod is installed.
246+
return (
247+
this.lastDeploy?.loadOrder.includes(modId) ||
248+
getFlag("overrideFrameworkChecks") === true
249+
)
250+
}
251+
252+
/**
253+
* Returns whether a mod is enabled for the given game version and platform, by checking the deployments from Simple Mod Framework.
254+
*
255+
* @param gameVersion The game version to check against.
256+
* @param platform The platform to check against.
257+
* @param modRef The mod ID and SemVer version range, in the form `id@version`.
258+
* @returns If the mod is enabled (or the `overrideFrameworkChecks` flag is set).
259+
*/
260+
public modEnabledForGame(
261+
gameVersion: GameVersion,
262+
platform: JwtData["platform"],
263+
modRef: string,
264+
): boolean {
265+
const modId = modRef.split("@")[0]
266+
267+
// Until SMFv3, we don't have the necessary information to
268+
// actually check more than whether the mod is installed.
269+
return (
270+
this.lastDeploy?.loadOrder.includes(modId) ||
271+
getFlag("overrideFrameworkChecks") === true
272+
)
273+
}
226274
}

0 commit comments

Comments
 (0)