Skip to main content

Atrament Core

This document describes internals of Atrament Core library.

Data structures

Scene

{
content: [],
text: [],
tags: {},
choices: [],
images: [],
sounds: [],
music: [],
uuid: Number
}
KeyDescription
contentArray of Ink paragraphs: {text: '', tags: {}, images: [], sounds: [], music: []}
textArray of all story text from all paragraphs of this scene
tagsArray of all tags from all paragraphs of this scene
choicesArray of choice objects: { id: 0, choice: 'Choice Text', tags: {}}
imagesArray of all images from all paragraphs of this scene
soundArray of all sounds from all paragraphs of this scene
musicArray of all music tracks from all paragraphs of this scene
uuidUnique ID of the scene (Date.now())

State

{
settings: {},
game: {},
metadata: {},
scenes: [],
vars: {}
}
KeyDescription
settingsSingle-level key-value store for application settings
gameSingle-level game-specific data. Atrament populates the following keys: $pathToInkFile, $inkFile, $gameUUID
metadataData loaded from Ink file global tags
scenesArray of game scenes
varsNames and values of auto-observed variables

Save

{ id, date, state, game, scenes }
KeyDescription
idSave slot ID
dateSave timestamp
stateJSON structure of Ink state
gameContent of game from Atrament state
scenesContent of scenes from Atrament state

Please note that metadata and vars from the Atrament state are not included in the save. However, they are automatically populated from the Ink state after loading from a save.

Interfaces

atrament-core uses dependency injection. It uses InkJS Story constructor 'as-is', and uses custom interfaces for other libraries.

There are four interfaces in atrament-core. Their implementation is not included, so developers can use atrament-core with the libraries they like.

loader

Interface to file operations. The function init will be called first, taking the path to the game as a parameter. The function getAssetPath should return the full path of a given file. The async function loadInk should return the content of a given Ink file, located in the folder defined at initialization time.

{
async init(path)
getAssetPath(filename)
async loadInk(filename)
}

persistent

Interface to persistent storage library.

{
init()
async exists(key)
async get()
async set(key)
async remove(key)
async keys()
}

state

Interface to state management library.

{
store()
get()
setKey(key, value)
toggleKey(key)
appendKey(key, value)
setSubkey(key, subkey, value)
toggleSubkey(key, subkey)
appendSubkey(key, subkey, value)
}

sound

Interface to sound management library.

{
init(defaultSettings)
mute(flag)
isMuted()
setVolume(volume)
getVolume()
playSound(soundFile)
stopSound(soundFile|undefined)
playMusic(musicFile)
stopMusic(musicFile|undefined)
}

Events

All events are triggered after the action is performed.

EventDescriptionParameters passed to event handler
game/initGame object is initialized.{ pathToInkFile: path, inkFile: file }
game/initInkStoryInk file is loaded.
game/startGame is started.{ saveSlot: saveslot }
game/resumeGame is resumed from a saved state.{ saveSlot: saveslot }
game/canResumeMethod canResume was called.{ saveSlot: saveslot }
game/restartGame is restarted (from beginning or from a saved state){ saveSlot: saveslot }
game/loadGame is loaded from a specified save slot.saveSlot
game/saveGame is saved. Parameter saveType can have these values: game for user saves, checkpoint for checkpoints, autosave for autosave. Autosave does not have a name.{ type: saveType, name: saveName }
game/listSavesRequested a list of saves.saveListArray
game/removeSaveSaved game is removed from a given slot.saveSlot
game/continueStoryInk story continued.
game/handleTagTag handler was called.{ [tagName]: tagValue }
game/clearGame state partial cleanup.
game/resetGame state full cleanup.
game/getSessionsRequested a list of game sessions.sessionList
game/deleteSessionA session is deleted.sessionID
ink/initInkStoryA new Ink story object is initialized.
ink/makeChoiceA choice is made in the Ink script.{ id: choiceId }
ink/getVisitCountVisit count for path was requested.{ ref: ref, visitCount: value }
ink/evaluateFunctionInk function was called from Atrament.{ function: functionName, args: argsArray, result: functionReturnValue }
ink/getGlobalTagsList of global tags was requested.{ globalTags: globalTagsObject }
ink/getVariableAn Ink variable value was requested.{ name: variableName }
ink/getVariablesA list of all Ink variables was requested.inkVariablesObject
ink/setVariableAn Ink variable value was set from Atrament.{ name: variableName, value: value }
ink/goToGo to specified path.{ knot: ref }
ink/onErrorInk script error happened.errorEvent
ink/getSceneAn Ink script scene was requested from Atrament.{ scene: sceneObject }
settings/loadApp settings were loaded from persistent storage.
settings/saveApp settings were saved to persistent storage.
settings/getApp setting value was requested.{ name: settingName }
settings/setApp setting was set.{ name: settingName, value: settingValue }