CatalystEngine
The public facade of the engine. It coordinates the four subsystems and wires up their internal bindings.
import { CatalystEngine } from 'catalyst-engine';Constructor
new CatalystEngine(
statsConfig: Record<string, number>,
expConfig: IExperienceConfig
)| Parameter | Type | Description |
|---|---|---|
statsConfig | Record<string, number> | Map of statId → base value. Initializes the StatManager. |
expConfig | IExperienceConfig | Experience curve configuration. |
The constructor instantiates events, stats, exp, skills and wires the ExperienceManager callbacks to the Event Bus (see Architecture).
const engine = new CatalystEngine(
{ hp: 100, attack: 10, defense: 5 },
{ type: 'EXPONENTIAL', baseXP: 100, multiplier: 1.5 }
);Public properties
| Property | Type | Description |
|---|---|---|
stats | StatManager | Management of stats and modifiers. |
exp | ExperienceManager | Management of XP and levels. |
events | EngineEventBus | Typed event bus. |
skills | SkillManager | Skill tree. |
They are public: you can access the subsystems directly (e.g. engine.exp.gainExperience(...)).
Methods
addModifier()
addModifier(statId: string, modifier: IStatModifier): voidAdds a modifier to the given stat and emits STAT_CHANGED if the stat exists. It is a shortcut that combines stats.addModifier() with emitting the event.
engine.addModifier('attack', {
id: 'fire_sword_dmg',
source: 'fire_sword',
type: ModifierType.FLAT,
value: 15,
});save()
save(): IEngineSaveStateExports a minimal snapshot of the state (version, timestamp, level+XP, base stat values, unlocked skills). See Persistence.
const snapshot = engine.save();
localStorage.setItem('partita', JSON.stringify(snapshot));load()
load(saveState: IEngineSaveState): voidRestores the state from a snapshot: it resets level/XP, reapplies the base values, rebuilds the skills (re-injecting the passive modifiers) and re-emits LEVEL_UP to resync the UI.
engine.load(JSON.parse(localStorage.getItem('partita')!));TIP
Create the engine with the same initial configuration (and load the skill tree, if used) before calling load(). See the note in Persistence.