@scml/sc2-modloader

TypeScript type definitions for SugarCube 2 Mod Loader, providing type support for mod and game data management.

Installation

npm
yarn
pnpm
bun
deno
npm install -D @scml/sc2-modloader

Quick Start

Add type reference

Add triple-slash directive in your project to bring in global types:

/// <reference types="@scml/sc2-modloader" />

Use global objects

Mod Loader mounts core objects on window; access directly:

window.modSC2DataManager;   // Data manager
window.modUtils;            // Mod utilities
window.modAddonPluginManager; // Addon plugin manager

Import types on demand

import type { ModInfo, ModLoader } from '@scml/sc2-modloader/ModLoader';
import type { AddonPluginHookPointEx } from '@scml/sc2-modloader/AddonPlugin';

Global Types global

Main entry extends Window via /// <reference types="..." />. global The following properties are on window:

PropertyTypeDescription
jQuery / $JQueryStaticjQuery instance
modSC2DataManagerSC2DataManagerMod and game data manager
modUtilsModUtilsMod Loader utilities (get mod, passage, etc.)
jsPreloaderJsPreloaderScript preloader
modModLoadControllerModLoadControllerMod load lifecycle controller
modAddonPluginManagerAddonPluginManagerAddon plugin manager
modSC2JsEvalContextSC2JsEvalContextMod JS eval context
Main entry
Subpath import example
/// <reference types="@scml/sc2-modloader" />

Subpath Exports

SubpathDescription
.Main entry, augments Window/global
./AddonPluginAddon plugin interfaces and manager
./ModLoaderModLoader, ModInfo, ModBootJson, etc.
./SC2DataManagerSC2DataManager central data manager
./ModLoadControllerLoad controller, LogWrapper
./ModZipReaderModZipReader, LocalLoader, RemoteLoader, etc.
./ModOrderContainerModOrderContainer, ModOrderItem, ModLoadFromSourceType
./SC2DataInfoCacheSC2DataInfo, PassageDataItem, CacheRecord, etc.
./SugarCube2Passage types
./UtilsModUtils utility class
./ReplacePatcherPatch/replace utilities
./ModPack/*ModPack, ModMeta, etc.
./SemVer/InfiniteSemVerInfiniteSemVer version parsing
and more...See package exports

API Reference

./AddonPlugin

AddonPluginHookPointEx interface

Interface for addon plugins; must implement registerMod(), optional lifecycle hooks.

AddonPluginManager class

registerAddonPlugin(), getAddonPlugin().

./SC2DataManager

SC2DataManager class

Mod and game data manager. Methods: getModUtils(), getModLoadController(), getSC2DataInfoCache(), getSC2DataInfoAfterPatch(), etc.

./ModLoader

ModInfo interface

PropertyTypeDescription
namestringMod name
versionstringVersion
aliasstring[]Aliases
cacheSC2DataInfoCache data
imgsModImg[]Image list
scriptFileList_preload[string, string][]Preload scripts

./Utils

ModUtils class

Methods: getModListName(), getMod(), getModZip(), getPassageData(), getAllPassageData(), createNewSC2DataInfoFromNow(), updatePassageData(), updatePassageDataMany(), etc.

Other subpaths

./ModZipReader, ./SC2DataInfoCache, ./SugarCube2, ./ReplacePatcher, ./ModOrderContainer, ./ModPack/*, ./SemVer/InfiniteSemVer.

Type Definition Source

INFO