Options
All
  • Public
  • Public/Protected
  • All
Menu

A read-only Database wrapping data loaded from a JSON file exported from Articy.

Most applications will only have one global database instance containing all their story data. The easiest way to manage a database object is to export it from its own module, like so:

// Example GameDB.ts

// Import data from the exported json
import GameData from "./exported.articy.json";
import { Database } from "articy-js";

// Create a new database
const GameDB = new Database(GameData)

// Export the database
export default GameDB;

Then you can access it easily via an import statement like

import GameDB from "GameDB"

Access objects like Entities, Flow Fragments, or Locations by Id using getObject. Accessed objects will be automatically wrapped in classes registered via RegisterDatabaseTypeClass or ArticyType.

Hierarchy

  • Database

Index

Constructors

constructor

  • Creates a new database from data loaded from an Articy JSON file

    Parameters

    • data: ArticyData

      JS object parsed from a Articy JSON file

    • Optional assetResolver: ResolveAssetPath

      A function that resolves asset reference paths from the Articy JSON into real paths on the disk/web

    Returns Database

Properties

Readonly guid

guid: string

Unique database instance ID

Readonly localization

localization: Localization = ...

Localization provider. Use this to switch the active language or to manually request the localized value of a string.

Accessors

project

Methods

getAssetFilenameFromId

  • getAssetFilenameFromId(assetId: undefined | string): null | string
  • Resolves the full filename of an asset given its ID

    Parameters

    • assetId: undefined | string

      Asset Id

    Returns null | string

    Absolute path using the assetResolver passed into the database constructor.

getAssetFilenameFromRef

  • getAssetFilenameFromRef(assetRef: undefined | string): null | string
  • Resolves the full filename of an asset given its reference name

    Parameters

    • assetRef: undefined | string

      Asset Reference

    Returns null | string

    Absolute path using the assetResolver passed into the database constructor

getChildren

  • getChildren(objectId: string): string[]
  • Gets the IDs of all children of a given object

    Parameters

    • objectId: string

      Object ID

    Returns string[]

    IDs of all its children

getChildrenOfType

  • getChildrenOfType<ObjectType>(objectId: string, creator: ArticyObjectCreator<ObjectType>): ObjectType[]
  • Returns a list of children of a given node that match a given type

    Type parameters

    • ObjectType

    Parameters

    • objectId: string

      Object ID

    • creator: ArticyObjectCreator<ObjectType>

      Type class to match against

    Returns ObjectType[]

    All children of the object that match the type

getDefinition

  • Gets the definition of a given template/class type

    Parameters

    • type: string

      Type name

    Returns undefined | ObjectDefinition

    Definition from Articy JSON, including specifications for its properties and features

getEnumValueDisplayName

  • getEnumValueDisplayName(type: string, value: number): undefined | string
  • Returns the display name for a given enum value

    Parameters

    • type: string

      Enum technical name

    • value: number

      Numeric enumeration value

    Returns undefined | string

    Display name for that enum value

getModel

  • getModel<PropType, TemplateType>(id: string): undefined | ModelData<PropType, TemplateType>

getModelsOfType

  • getModelsOfType<PropType, TemplateType>(type: string | string[]): ModelData<PropType, TemplateType>[]
  • Returns all models of a given type (or that derive from that type). A model is just an object that contains both the properties block and the template block.

    Type parameters

    Parameters

    • type: string | string[]

      Type string

    Returns ModelData<PropType, TemplateType>[]

getModelsWithFeature

  • Finds all models whose template has a given feature

    Type parameters

    • Feature: FeatureProps

      Interface of the feature type

    • FeatureName: string

      Name of the feature to improve return type deduction

    Parameters

    • featureName: FeatureName

      Name of the feature in the template

    Returns ModelData<ArticyObjectProps, { FeatureName: Feature }>[]

    All models whose templates contain the feature

getObject

  • getObject<ObjectType>(id: undefined | null | string, type: ArticyObjectCreator<ObjectType>): undefined | ObjectType
  • Loads an Articy Object wrapped in a registered Javascript class associated with the type. See ArticyType and RegisterDatabaseTypeClass.

    A note about types: getObject will always return an instance of the most specific registered class type associated with the requested data, regardless of the value of the type parameter. The type parameter predominately functions as a type check. The method returns undefined if the parameter in type is not equal to or a base class of the registered type.

    Type parameters

    • ObjectType

      Type returned by the constructor in the type parameter

    Parameters

    • id: undefined | null | string

      Object ID

    • type: ArticyObjectCreator<ObjectType>

      Constructor for the registered class to wrap the object with

    Returns undefined | ObjectType

    an instance of ObjectType or undefined if there is a type-mismatch or the object can't be found

getObjectByTechnicalName

  • getObjectByTechnicalName<ObjectType>(technicalName: string, type: ArticyObjectCreator<ObjectType>): undefined | ObjectType
  • Loads an Articy Object into a given JS class by technical name (with type safety). Similar to getObject but uses the TechnicalName.

    Type parameters

    • ObjectType

    Parameters

    • technicalName: string

      Technical name to search by

    • type: ArticyObjectCreator<ObjectType>

      Object type

    Returns undefined | ObjectType

    Object, or undefined if no object has that technical name or it doesn't match the given type

getObjectsWithFeature

  • Returns objects of a given type with a given feature name. This is a special type-safe version that works only with features that are a part of the GlobalFeatures interface.

    Type parameters

    • FeatureName: never

      Name of the feature to improve return type deduction

    • ObjectType

      Object type

    Parameters

    • featureName: FeatureName

      Name of the feature to search for

    • creator: ArticyObjectCreator<ObjectType>

      Object type to return

    Returns (ObjectType & TemplateExtension<FeatureName, GlobalFeatures[FeatureName]>)[]

    All objects that have the given feature

  • Returns objects of a given type with a given feature name

    Type parameters

    • ObjectType

    Parameters

    • featureName: string

      Name of the feature to search for

    • creator: ArticyObjectCreator<ObjectType>

      Object type to return

    Returns ObjectType[]

    All objects matching the given type that have the given feature

getParent

  • getParent(objectId: string): null | string
  • Finds an object's parent in the hierarchy

    Parameters

    • objectId: string

      Id of the object to get the parent of

    Returns null | string

    That ID of that object's parent, or null if there is none.

getType

  • getType(id: undefined | null | string): undefined | string
  • Returns the type string of a given object ID

    Parameters

    • id: undefined | null | string

      Object ID to lookup

    Returns undefined | string

    Type string, like "DialogueFragment" or "MyCustomTemplate"

isOfType

  • Quick check to see if a given object is of a given type

    Parameters

    • id: string

      Object ID to check

    • type: string | ArticyObjectCreator<unknown>

      Type to check against (can either be the technical name of the type like "FlowFragment" or a registered class like FlowFragment)

    Returns boolean

    true if the object is of that type (or of a type that derives from it)

isType

  • isType(type: string, other: string | string[]): boolean
  • Checks if type is an instance of another type

    Parameters

    • type: string

      Type name

    • other: string | string[]

      Type or base type name

    Returns boolean

    If the types are equal or the type derives from the other type

newVariableStore

  • Creates a new global variable store with initial values loaded from the database.

    Returns VariableStore

    A variable store

verifyScriptFunctions

  • verifyScriptFunctions(): void

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method

Generated using TypeDoc