Class: ChoicekitEngineBuilder<TGenerics, TArgs>
Class: ChoicekitEngineBuilder<TGenerics, TArgs>
Section titled “Class: ChoicekitEngineBuilder<TGenerics, TArgs>”Defined in: engine/builder.ts:34
To enforce type safety and work around typescript limitations with advanced generics, a builder for the engine is more convenient.
If you need a reset builder, simply instantiate a new instance.
Type Parameters
Section titled “Type Parameters”TGenerics
Section titled “TGenerics”TGenerics extends ChoicekitEngineGenerics
TArgs extends ChoicekitEngineArguments = ChoicekitEngineArguments<TGenerics>
Implements
Section titled “Implements”BuilderMethods
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ChoicekitEngineBuilder<
TGenerics,TArgs>():ChoicekitEngineBuilder<TGenerics,TArgs>
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics, TArgs>
Methods
Section titled “Methods”build()
Section titled “build()”build():
Promise<ChoicekitEngine<TGenerics>>
Defined in: engine/builder.ts:159
Use the given configuration to create a new typesafe engine for use
Returns
Section titled “Returns”Promise<ChoicekitEngine<TGenerics>>
withAchievements()
Section titled “withAchievements()”withAchievements<
TAchievements>(achievements):ChoicekitEngineBuilder<TGenerics&object>
Defined in: engine/builder.ts:93
Set an object containing the achievements to be used in the story via the engine.
Unlike the story variables, this is persisted seperately from saved states.
Type Parameters
Section titled “Type Parameters”TAchievements
Section titled “TAchievements”TAchievements extends GenericSerializableObject
Parameters
Section titled “Parameters”achievements
Section titled “achievements”TAchievements
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics & object>
withClasses()
Section titled “withClasses()”withClasses(…
classes):ChoicekitEngineBuilder<TGenerics>
Defined in: engine/builder.ts:114
A list of compatible class constructors to allow userland-classes to be cloned and persisted without issue
Parameters
Section titled “Parameters”classes
Section titled “classes”…TArgs["classes"]
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics>
withConfig()
Section titled “withConfig()”withConfig(
config):ChoicekitEngineBuilder<TGenerics>
Defined in: engine/builder.ts:121
Special Choicekit configuration
Parameters
Section titled “Parameters”config
Section titled “config”TArgs["config"]
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics>
withMigrators()
Section titled “withMigrators()”withMigrators(
migrations):ChoicekitEngineBuilder<TGenerics>
Defined in: engine/builder.ts:128
Add save migrations for to update older saves
Parameters
Section titled “Parameters”migrations
Section titled “migrations”TArgs["migrations"]
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics>
withName()
Section titled “withName()”withName<
TName>(name):ChoicekitEngineBuilder<TGenerics&object>
Defined in: engine/builder.ts:55
Set the engine name.
Multiple engines with the same name share the same save data.
Type Parameters
Section titled “Type Parameters”TName extends string
Parameters
Section titled “Parameters”TName
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics & object>
withPassages()
Section titled “withPassages()”withPassages<
TPassage>(…passages):ChoicekitEngineBuilder<TGenerics&object>
Defined in: engine/builder.ts:81
Add the crucial initial set of pasasges, where the first element is the starting passage.
If the tags / name / data type is too strict, just cast a string entry to the desired widened type using as like:
Type Parameters
Section titled “Type Parameters”TPassage
Section titled “TPassage”TPassage extends Readonly<{ data: unknown; name: string; tags: readonly string[]; }>
Parameters
Section titled “Parameters”passages
Section titled “passages”…[TPassage, ...TPassage[]]
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics & object>
Example
Section titled “Example”const engine = await new ChoicekitEngineBuilder().withPassages({name: "Start Passage" as string, data: "Lorem Ipsum" as string, tags: ["Start" as string]})withPlugin()
Section titled “withPlugin()”withPlugin<
TPlugin>(plugin,config):ChoicekitEngineBuilder<TGenerics&object>
Defined in: engine/builder.ts:141
Register a plugin with its configuration.
Call this method multiple times to register multiple plugins. Each plugin’s mutations will be properly typed and accumulated.
Type Parameters
Section titled “Type Parameters”TPlugin
Section titled “TPlugin”TPlugin extends ChoicekitPlugin
Parameters
Section titled “Parameters”plugin
Section titled “plugin”TPlugin
config
Section titled “config”TPlugin extends ChoicekitPlugin<RGenerics> ? RGenerics["config"] : never
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics & object>
Implementation of
Section titled “Implementation of”BuilderMethods.withPlugin
withSettings()
Section titled “withSettings()”withSettings<
TSettings>(settings):ChoicekitEngineBuilder<TGenerics&object>
Defined in: engine/builder.ts:105
Set an object containing the settings to be used in the story via the engine.
Unlike the story variables, this is persisted seperately from saved states.
Type Parameters
Section titled “Type Parameters”TSettings
Section titled “TSettings”TSettings extends GenericSerializableObject
Parameters
Section titled “Parameters”settings
Section titled “settings”TSettings
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics & object>
withVars()
Section titled “withVars()”withVars<
TVars>(vars):ChoicekitEngineBuilder<TGenerics&object>
Defined in: engine/builder.ts:64
Set an object containing the variables to be used in the story via the engine
Type Parameters
Section titled “Type Parameters”TVars extends GenericSerializableObject
Parameters
Section titled “Parameters”TVars | ((init) => TVars)
Returns
Section titled “Returns”ChoicekitEngineBuilder<TGenerics & object>