isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
308 lines (296 loc) • 16.2 kB
text/typescript
import type { ModCallbackCustomToClass } from "./callbacks";
import { CustomGridEntities } from "./classes/features/callbackLogic/CustomGridEntities";
import { CustomRevive } from "./classes/features/callbackLogic/CustomRevive";
import { EsauJrDetection } from "./classes/features/callbackLogic/EsauJrDetection";
import { FlipDetection } from "./classes/features/callbackLogic/FlipDetection";
import { GameReorderedCallbacks } from "./classes/features/callbackLogic/GameReorderedCallbacks";
import { GridEntityCollisionDetection } from "./classes/features/callbackLogic/GridEntityCollisionDetection";
import { GridEntityRenderDetection } from "./classes/features/callbackLogic/GridEntityRenderDetection";
import { GridEntityUpdateDetection } from "./classes/features/callbackLogic/GridEntityUpdateDetection";
import { ItemPickupDetection } from "./classes/features/callbackLogic/ItemPickupDetection";
import { PickupChangeDetection } from "./classes/features/callbackLogic/PickupChangeDetection";
import { PlayerCollectibleDetection } from "./classes/features/callbackLogic/PlayerCollectibleDetection";
import { PlayerReorderedCallbacks } from "./classes/features/callbackLogic/PlayerReorderedCallbacks";
import { SlotDestroyedDetection } from "./classes/features/callbackLogic/SlotDestroyedDetection";
import { SlotRenderDetection } from "./classes/features/callbackLogic/SlotRenderDetection";
import { SlotUpdateDetection } from "./classes/features/callbackLogic/SlotUpdateDetection";
import { CharacterHealthConversion } from "./classes/features/other/CharacterHealthConversion";
import { CharacterStats } from "./classes/features/other/CharacterStats";
import { CollectibleItemPoolType } from "./classes/features/other/CollectibleItemPoolType";
import { CustomHotkeys } from "./classes/features/other/CustomHotkeys";
import { CustomItemPools } from "./classes/features/other/CustomItemPools";
import { CustomPickups } from "./classes/features/other/CustomPickups";
import { CustomStages } from "./classes/features/other/CustomStages";
import { CustomTrapdoors } from "./classes/features/other/CustomTrapdoors";
import { DebugDisplay } from "./classes/features/other/DebugDisplay";
import { DeployJSONRoom } from "./classes/features/other/DeployJSONRoom";
import { DisableAllSound } from "./classes/features/other/DisableAllSound";
import { DisableInputs } from "./classes/features/other/DisableInputs";
import { EdenStartingStatsHealth } from "./classes/features/other/EdenStartingStatsHealth";
import { ExtraConsoleCommands } from "./classes/features/other/ExtraConsoleCommands";
import { FadeInRemover } from "./classes/features/other/FadeInRemover";
import { FastReset } from "./classes/features/other/FastReset";
import { FlyingDetection } from "./classes/features/other/FlyingDetection";
import { ForgottenSwitch } from "./classes/features/other/ForgottenSwitch";
import { ItemPoolDetection } from "./classes/features/other/ItemPoolDetection";
import { ModdedElementDetection } from "./classes/features/other/ModdedElementDetection";
import { ModdedElementSets } from "./classes/features/other/ModdedElementSets";
import { NoSirenSteal } from "./classes/features/other/NoSirenSteal";
import { Pause } from "./classes/features/other/Pause";
import { PersistentEntities } from "./classes/features/other/PersistentEntities";
import { PickupIndexCreation } from "./classes/features/other/PickupIndexCreation";
import { PlayerCollectibleTracking } from "./classes/features/other/PlayerCollectibleTracking";
import { PonyDetection } from "./classes/features/other/PonyDetection";
import { PressInput } from "./classes/features/other/PressInput";
import { PreventChildEntities } from "./classes/features/other/PreventChildEntities";
import { PreventGridEntityRespawn } from "./classes/features/other/PreventGridEntityRespawn";
import { RerunDetection } from "./classes/features/other/RerunDetection";
import { RoomClearFrame } from "./classes/features/other/RoomClearFrame";
import { RoomHistory } from "./classes/features/other/RoomHistory";
import { RunInNFrames } from "./classes/features/other/RunInNFrames";
import { RunNextRoom } from "./classes/features/other/RunNextRoom";
import { RunNextRun } from "./classes/features/other/RunNextRun";
import { SaveDataManager } from "./classes/features/other/SaveDataManager";
import { SpawnRockAltRewards } from "./classes/features/other/SpawnRockAltRewards";
import { StageHistory } from "./classes/features/other/StageHistory";
import { StartAmbush } from "./classes/features/other/StartAmbush";
import { TaintedLazarusPlayers } from "./classes/features/other/TaintedLazarusPlayers";
import { UnlockAchievementsDetection } from "./classes/features/other/UnlockAchievementsDetection";
import type { Feature } from "./classes/private/Feature";
import { ISCFeature } from "./enums/ISCFeature";
import { ModCallbackCustom } from "./enums/ModCallbackCustom";
import { interfaceSatisfiesEnum } from "./functions/enums";
import type { ModUpgradedInterface } from "./interfaces/private/ModUpgradedInterface";
export interface ISCFeatureToClass {
// Callback logic
[]: CustomRevive;
[]: EsauJrDetection;
[]: FlipDetection;
[]: GridEntityCollisionDetection;
[]: GridEntityRenderDetection;
[]: GridEntityUpdateDetection;
[]: GameReorderedCallbacks;
[]: ItemPickupDetection;
[]: PickupChangeDetection;
[]: PlayerCollectibleDetection;
[]: PlayerReorderedCallbacks;
[]: SlotDestroyedDetection;
[]: SlotRenderDetection;
[]: SlotUpdateDetection;
// Extra features
[]: CharacterHealthConversion;
[]: CharacterStats;
[]: CollectibleItemPoolType;
[]: CustomGridEntities;
[]: CustomItemPools;
[]: CustomHotkeys;
[]: CustomPickups;
[]: CustomStages;
[]: CustomTrapdoors;
[]: DebugDisplay;
[]: DeployJSONRoom;
[]: DisableAllSound;
[]: DisableInputs;
[]: EdenStartingStatsHealth;
[]: FadeInRemover;
[]: FastReset;
[]: FlyingDetection;
[]: ForgottenSwitch;
[]: ExtraConsoleCommands;
[]: ItemPoolDetection;
[]: ModdedElementDetection;
[]: ModdedElementSets;
[]: NoSirenSteal;
[]: Pause;
[]: PersistentEntities;
[]: PickupIndexCreation;
[]: PlayerCollectibleTracking;
[]: PonyDetection;
[]: PressInput;
[]: PreventChildEntities;
[]: PreventGridEntityRespawn;
[]: RerunDetection;
[]: RoomClearFrame;
[]: RoomHistory;
[]: RunInNFrames;
[]: RunNextRoom;
[]: RunNextRun;
[]: SaveDataManager;
[]: SpawnRockAltRewards;
[]: StageHistory;
[]: StartAmbush;
[]: TaintedLazarusPlayers;
[]: UnlockAchievementsDetection;
}
interfaceSatisfiesEnum<ISCFeatureToClass, ISCFeature>();
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getFeatures(
mod: ModUpgradedInterface,
callbacks: ModCallbackCustomToClass,
) {
// Some features rely on other features; we must initialize those first.
const gameReorderedCallbacks = new GameReorderedCallbacks(
callbacks[ModCallbackCustom.POST_GAME_STARTED_REORDERED],
callbacks[ModCallbackCustom.POST_NEW_LEVEL_REORDERED],
callbacks[ModCallbackCustom.POST_NEW_ROOM_REORDERED],
callbacks[ModCallbackCustom.POST_GAME_STARTED_REORDERED_LAST],
);
const disableAllSound = new DisableAllSound();
const disableInputs = new DisableInputs();
const moddedElementDetection = new ModdedElementDetection();
const ponyDetection = new PonyDetection();
const pressInput = new PressInput();
const roomClearFrame = new RoomClearFrame();
const roomHistory = new RoomHistory();
const runNextRoom = new RunNextRoom();
const saveDataManager = new SaveDataManager(mod);
const stageHistory = new StageHistory();
const runInNFrames = new RunInNFrames(roomHistory);
const pickupIndexCreation = new PickupIndexCreation(
roomHistory,
saveDataManager,
);
const customGridEntities = new CustomGridEntities(runInNFrames);
const moddedElementSets = new ModdedElementSets(moddedElementDetection);
const itemPoolDetection = new ItemPoolDetection(moddedElementSets);
const pause = new Pause(disableInputs);
const preventGridEntityRespawn = new PreventGridEntityRespawn(runInNFrames);
const customTrapdoors = new CustomTrapdoors(
customGridEntities,
disableInputs,
ponyDetection,
roomClearFrame,
runInNFrames,
runNextRoom,
stageHistory,
);
const features = {
// Callback logic
[]: new CustomRevive(
callbacks[ModCallbackCustom.PRE_CUSTOM_REVIVE],
callbacks[ModCallbackCustom.POST_CUSTOM_REVIVE],
runInNFrames,
),
[]: new EsauJrDetection(
callbacks[ModCallbackCustom.POST_ESAU_JR],
callbacks[ModCallbackCustom.POST_FIRST_ESAU_JR],
),
[]: new FlipDetection(
callbacks[ModCallbackCustom.POST_FLIP],
callbacks[ModCallbackCustom.POST_FIRST_FLIP],
),
[]:
new GridEntityCollisionDetection(
callbacks[ModCallbackCustom.POST_GRID_ENTITY_COLLISION],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_COLLISION],
customGridEntities,
),
[]: new GridEntityUpdateDetection(
callbacks[ModCallbackCustom.POST_GRID_ENTITY_INIT],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_INIT],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_UPDATE],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_UPDATE],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_REMOVE],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_REMOVE],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_STATE_CHANGED],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_STATE_CHANGED],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_BROKEN],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_BROKEN],
customGridEntities,
),
[]: new GridEntityRenderDetection(
callbacks[ModCallbackCustom.POST_GRID_ENTITY_RENDER],
callbacks[ModCallbackCustom.POST_GRID_ENTITY_CUSTOM_RENDER],
customGridEntities,
),
[]: gameReorderedCallbacks,
[]: new ItemPickupDetection(
callbacks[ModCallbackCustom.POST_ITEM_PICKUP],
callbacks[ModCallbackCustom.PRE_ITEM_PICKUP],
),
[]: new PickupChangeDetection(
callbacks[ModCallbackCustom.POST_PICKUP_CHANGED],
pickupIndexCreation,
),
[]: new PlayerCollectibleDetection(
callbacks[ModCallbackCustom.POST_PLAYER_COLLECTIBLE_ADDED],
callbacks[ModCallbackCustom.POST_PLAYER_COLLECTIBLE_REMOVED],
moddedElementSets,
runInNFrames,
),
[]: new PlayerReorderedCallbacks(
callbacks[ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED],
callbacks[ModCallbackCustom.POST_PLAYER_RENDER_REORDERED],
callbacks[ModCallbackCustom.POST_PLAYER_UPDATE_REORDERED],
),
[]: new SlotDestroyedDetection(
callbacks[ModCallbackCustom.POST_SLOT_DESTROYED],
roomHistory,
),
[]: new SlotRenderDetection(
callbacks[ModCallbackCustom.POST_SLOT_RENDER],
callbacks[ModCallbackCustom.POST_SLOT_ANIMATION_CHANGED],
),
[]: new SlotUpdateDetection(
callbacks[ModCallbackCustom.POST_SLOT_INIT],
callbacks[ModCallbackCustom.POST_SLOT_UPDATE],
),
// Extra features
[]: new CharacterHealthConversion(),
[]: new CharacterStats(),
[]: new CollectibleItemPoolType(
pickupIndexCreation,
),
[]: customGridEntities,
[]: new CustomItemPools(),
[]: new CustomHotkeys(),
[]: new CustomPickups(),
[]: new CustomStages(
customGridEntities,
customTrapdoors,
disableAllSound,
gameReorderedCallbacks,
pause,
runInNFrames,
),
[]: customTrapdoors,
[]: new DebugDisplay(mod),
[]: new DeployJSONRoom(preventGridEntityRespawn),
[]: disableAllSound,
[]: disableInputs,
[]: new EdenStartingStatsHealth(),
[]: new FadeInRemover(),
[]: new FastReset(),
[]: new FlyingDetection(moddedElementSets),
[]: new ForgottenSwitch(pressInput),
[]: new ExtraConsoleCommands(),
[]: itemPoolDetection,
[]: moddedElementDetection,
[]: moddedElementSets,
[]: new NoSirenSteal(),
[]: pause,
[]: new PersistentEntities(roomHistory),
[]: pickupIndexCreation,
[]: new PlayerCollectibleTracking(),
[]: ponyDetection,
[]: pressInput,
[]: new PreventChildEntities(),
[]: preventGridEntityRespawn,
[]: new RerunDetection(),
[]: roomClearFrame,
[]: roomHistory,
[]: runInNFrames,
[]: runNextRoom,
[]: new RunNextRun(),
[]: saveDataManager,
[]: new SpawnRockAltRewards(
itemPoolDetection,
),
[]: stageHistory,
[]: new StartAmbush(runInNFrames),
[]: new TaintedLazarusPlayers(),
[]:
new UnlockAchievementsDetection(),
} as const satisfies Record<ISCFeature, Feature>;
return features;
}