Skip to content

Latest commit

 

History

History
1818 lines (1070 loc) · 35.1 KB

docs.md

File metadata and controls

1818 lines (1070 loc) · 35.1 KB

Table of Contents

IdleTimer

start

Parameters

  • time Number time in milliseconds (optional, default 15000)

Returns void @memberof IdleTimer

reset

resets the timer, does not call subscribed functions

Returns void @memberof IdleTimer

stop

Returns void @memberof IdleTimer

dispatch

Calls all subscribed functions, and resets the timer.

Returns void @memberof IdleTimer

subscribe

Adds a function to be called when timer is dispatched

Parameters

  • callback

Returns void @memberof IdleTimer

unsubscribe

Removes a function from being called when timer is dispatched

Parameters

  • callback any

Returns void @memberof IdleTimer

IHintPlayer

Hint Player interface to help enforce minimum requirements for hint players

Properties

  • play function called by application to

UserData

Manages data between SpringRoll Container and SpringRoll

read

Gets data from SpringRoll Container

Parameters

Returns Promise

write

Sends data to SpringRoll Container

Parameters

Returns Promise

delete

Removes data from SpringRoll Container

Parameters

Point

Type: {x: Number, y: Number}

Point

Type: {x: Number, y: Number}

PositionCallback

callback to used move game entities

Type: Function

Parameters

  • position Point position relative to anchor direction

Anchor

Used to fix positions to a relative point in the viewport.

onResize

Parameters

Returns void @memberof Anchor

ScaleCallback

callback to used scale game and canvas

Type: Function

Parameters

  • width Number width canvas should be
  • height Number height canvas should be
  • scale Point x/y scale values
  • scaleRatio Number minimum aspect ratio that fit's in the screen.
  • viewArea Object Rectangle defining the total viewable area of game content.

SafeScaleManager

Handles scaling the game

Parameters

  • $0 Object
    • $0.width
    • $0.height
    • $0.safeWidth (optional, default Infinity)
    • $0.safeHeight (optional, default Infinity)
    • $0.callback (optional, default ()=>{})
  • param object

entities

Type: Array<ScaledEntity>

resizeEventData

Type: EntityResizeEvent

removeEntity

Removes an anchor

Parameters

Returns void @memberof SafeScaleManager

enable

Enables the scale manager listener. Will not be enabled if a callback is not supplied.

Parameters

  • callback ScaleCallback The function to be called on resize events.

disable

Disables the scale manager.

calcOffset

Calculates the offset for anchors.

Parameters

  • scale Point scale value

Returns Point

addEntity

Adds and anchor to be updated during resize

Parameters

ResizeHelper

Utility class that handles resize events for ScaleManager and SafeScaleManager.

Parameters

iOS

Whether or not the application is running on an iOS device.

enabled

Returns the enabled state of the ResizeHelper.

enabled

Sets the enabled state of the ResizeHelper. Forces a resize event.

Parameters

  • value

onWindowResize

Handler for window resize events. Forwards this event to the scale manager if enabled.

getWindowResolution

Sets the window width and window height values of the ResizeHelper.

ScaledEntity

onResize

Parameters

Returns void @memberof ScaledEntity

EntityResizeEvent

Type: {offset: Point, gameSize: Point, scale: Point}

ScaleManager

Simplifies listening to resize events by passing the relevant data to a provided callback.

Parameters

  • callback Function (optional, default undefined)

Properties

enable

Enables the scale manager listener. Will not be enabled if a callback is not supplied.

Parameters

  • callback Function The function to be called on resize events.

disable

Disables the scale manager.

SpeechSynth

SpeechSync makes it easy to convert text to speech. Note: This is not supported on IE11 and below because of the underlying APIs are not implemented in those browsers

Parameters

  • params object
    • params.voice number Indicates what voice to use. (optional, default 0)
    • params.rate number The rate at which the text is said. Supports a range from 0.1 to 10. (optional, default 1)
    • params.pitch number Voice Pitch. Supports a pitch from 0 to 2. (optional, default 0)
    • params.volume number Volume. Supports 0 to 1. (optional, default 1)

Properties

  • voicesLoaded boolean voices are loaded async. This is will be set to true when they are loaded.

pause

Pauses the announcer.

resume

Resumes the announcer.

cancel

Pauses the announcer and clears the queue.

say

Causes the announcer to say whatever message is passed to it. If the announcer is already saying something then it will be added to a queue.

Parameters

setVoice

Sets the voice by array index.

Parameters

getVoice

Returns the voice object.

Returns (object | null)

rate

Rate at which text is spoken.

Parameters

rate

Returns rate which text is spoken.

Returns number

pitch

Sets the pitch at which text is spoken.

Parameters

pitch

Returns the pitch at which text is spoken.

Returns number

volume

Sets the current volume of the announcer.

Parameters

volume

Returns the current volume of the announcer.

Returns number

ColorFilter

The Color filter allows you to simulate colorblindness.

applyFilter

Applies the specified filter to the element.

Parameters

changeFilter

Changes the currently applied filter to the element if the color filter has it.

Parameters

Returns any

removeFilter

Removes the filter from the element.

types

Supported filter types.

Returns object Returns an object { name, value } with the colorblindness type: (Protanopia, Protanomaly, Deuteranopia, Deuteranomaly, Tritanopia, Tritanomaly, Achromatopsia, Achromatomaly)

filterType

Type: ("protanopia" | "protanomaly" | "deuteranopia" | "deuteranomaly" | "tritanopia" | "tritanomaly" | "achromatopsia" | "achromatomaly")

KeyState

Type: (0 | 1 | 2)

Properties

Controller

Controller interface class to simplify working with key presses.

Parameters

onWindowBlur

Called on window blur, sets button state to up if button was down;

Returns void @memberof Controller

update

Calls all functions for buttons that are currently set to enabled.

onKeyDown

Called on keyup. Sets flag to 1 if key is being watched.

Parameters

onKeyUp

Called on keyup. Sets flag to 2 if key is being watched.

Parameters

assignButtons

Sets an object of button functions to the controller to be called.

Parameters

  • keys Array<KeyTemplate>

Key

Represents a single key on the keyboard and the functions related to it.

Parameters

  • key string What this object represents.
  • down Function Function to be called while the key is held down. (optional, default ()=>{})
  • up Function Function to be called when the key is lifted up. (optional, default ()=>{})

Properties

  • state (0 | 1 | 2) The current state of the key. 0 = inactive, 1 = active, 2 = to be set to inactive.
  • key string The name of the key we are targeting.
  • actions object
    • actions.down function Function to be called while the key is held down.
    • actions.up function Function to be called when the key is lifted up.

updateState

Updates the internal state of the key. Accepts a range between 0-2. Will set key state to 0 if nothing is passed.

Parameters

  • state (0 | 1 | 2) (optional, default 0)

action

Calls the relevant action for the current state of the key.

state

Returns the current state of the key.

Returns number

Application

Main entry point for a game. Provides a single focal point for plugins and functionality to attach.

Properties

  • features object A configuration object denoting which features are enabled for this application
    • features.captions boolean? A boolean value denoting that this game supports captions
    • features.sound boolean? A boolean value denoting that this game has some audio in it
    • features.vo boolean? A boolean denoting that this game has mutable voice-over audio in it
    • features.music boolean? A boolean denoting that this game has mutable music in it
    • features.sfx boolean? A boolean denoting that this game has mutable sound effects in it
    • features.soundVolume boolean? A boolean denoting that this game has adjustable sound volume in it
    • features.musicVolume boolean? A boolean denoting that this game has adjustable music volume in it
    • features.voVolume boolean? A boolean denoting that this game has adjustable voice-over volume in it
    • features.sfxVolume boolean? A boolean denoting that this game has adjustable sound effects volume in it
    • features.pointerSize boolean? A boolean denoting that this game has adjustable pointer size in it
    • features.controlSensitivity boolean? A boolean denoting that this game has adjustable control sensitivity in it
    • features.buttonSize boolean? A boolean denoting that this game has adjustable button sizes in it
    • features.removableLayers boolean? A boolean denoting that this game has removable game layers in it
    • features.hudPosition boolean? A boolean denoting that this game has custom HUD positions.
    • features.hitAreaScale boolean? A boolean denoting that this game has adjustable hit areas.
    • features.dragThresholdScale boolean? A boolean denoting that this game has adjustable drag thresholds.
    • features.health boolean? A boolean denoting that this game has adjustable health.
    • features.objectCount boolean? A boolean denoting that this game has adjustable object count requirements.
    • features.completionPercentage boolean? A boolean denoting that this game has adjustable completion percentage requirements.
    • features.speedScale boolean? A boolean denoting that this game has adjustable speed.
    • features.timersScale boolean? A boolean denoting that this game has adjustable timers.
    • features.inputCount boolean? A boolean denoting that this game has adjustable input count requirements.
    • features.keyBinding boolean? A boolean denoting that this game has re-mappable key bindings.
    • features.colorVision boolean? A boolean denoting that this game has color blindess filters

getPlugin

returns instance of a plugin.

Parameters

Returns (SpringRoll.ApplicationPlugin | undefined)

validateListeners

Validates that appropriate listeners are added for the features that were enabled in the constructor

  • Throws any Error

setStateDefaults

Sets default values of application state properties.

setupPlugins

preloads, initializes and starts plugins.

Returns Promise<void>

_plugins

The list of plugins that are currently registered to run on Applications.

uses

Registers a plugin to be used by applications, sorting it by priority order.

Parameters

  • plugin SpringRoll.ApplicationPlugin The plugin to register.

getPlugin

Finds a plugin by name.

Parameters

  • name string The name of the plugin.

Returns (SpringRoll.ApplicationPlugin | undefined)

Debugger

Type: object

Parameters

  • params Object Options
    • params.emitEnabled boolean If this should emit events to the window. (optional, default false)
    • params.minLevel ("GENERAL" | "DEBUG" | "INFO" | "WARN" | "ERROR") The starting log level for the logger. (optional, default 'GENERAL')

Properties

params

Returns the params of the debugger.

Returns DebuggerParams

minLevel

Sets the logging level of the debugger.

Parameters

Returns void

emit

If emitting is enabled for this instance, then it will dispatch an event on the window.

Parameters

  • eventName string Name of the event (optional, default 'Debugger')

LEVEL

Returns logging levels.

Returns object

log

Console logs all supplied arguments if the log level is low enough for them to be logged.

Parameters

  • type ("log" | "general" | "warn" | "error" | "debug" | "info") minimum level for this log to run at (optional, default 'log')
  • args Array<any> Arguments you wish to log.

assert

Will throw if statement is false.

Parameters

  • isTrue boolean The expression to evaluate.

isEnabled

Returns a boolean indicating if the debugger has been enabled or not.

Returns boolean

enable

Disables or enables all debugger instances. TODO: Remove the parameter here, and add a disable method as well

Parameters

Returns void

paramKey

Returns the global params key.

HintSequencePlayer

play

invokes the next hint

Returns void @memberof HintSequencePlayer

clear

removes all hints

Returns void @memberof HintSequencePlayer

add

Parameters

  • callbacks Array<function ()>

Returns void @memberof HintSequencePlayer

remove

Parameters

  • callbacks Array<function ()>

Returns void @memberof HintSequencePlayer

Property

A class for representing changeable/subscribable properties.

Properties

  • _value any the value of the property
  • listeners [] all the objects listening to this property

subscribe

Adds a subscriber to this property.

Parameters

  • callback function The callback to call whenever the property changes.

unsubscribe

Unsubscribes a listener from this property.

Parameters

  • callback function The callback to unsubscribe.

hasListeners

Whether or not this property has any subscribed listeners

Returns Boolean True if this property has at least one subscriber

value

returns the current value of the property

Returns any

value

Sets the value of the property and notifies all listeners of the change

Parameters

  • value any the new property value

Caption

Properties

update

Updates content based on time passed. This should be called every frame that the caption is active.

Parameters

  • deltaTime Number Time in seconds since last frame.

updateState

Handles calling callbacks and updating caption's current state.

Parameters

isFinished

Checks if caption has completed.

Returns Boolean

start

Sets time and line index of caption.

Parameters

  • time Number Time in milliseconds. (optional, default 0)
  • renderer (optional, default {lineBegin:()=>{},lineEnd:()=>{}})

updateTimeIndex

Updates the current time and index of the caption instance

Parameters

  • time Number (optional, default 0)

Caption

Parameters

  • lines

update

Updates content based on time passed. This should be called every frame that the caption is active.

Parameters

  • deltaTime Number Time in seconds since last frame.

updateState

Handles calling callbacks and updating caption's current state.

Parameters

isFinished

Checks if caption has completed.

Returns Boolean

start

Sets time and line index of caption.

Parameters

  • time Number Time in milliseconds. (optional, default 0)
  • renderer (optional, default {lineBegin:()=>{},lineEnd:()=>{}})

updateTimeIndex

Updates the current time and index of the caption instance

Parameters

  • time Number (optional, default 0)

CaptionFactory

Collection of functions for creating Captions

createCaptionMap

Creates a new Object<String, Caption>.

Parameters

Returns Object

createCaption

Creates a new Caption from JSON data.

Parameters

  • captionData any

Returns Caption new Caption

createLine

Creates a new TimedLine from JSON data.

Parameters

  • lineData any

Returns TimedLine new TimedLine;

CaptionPlayer

CaptionPlayer is used to start, stop and update captions. It applies the content of an active caption to a given CaptionRenderer.

update

Updates any currently playing caption. This should be called every frame.

Parameters

  • deltaTime Number Time passed in seconds since last update call.

start

Starts playing a caption.

Parameters

  • name String Name of caption.
  • time number Atart time in milliseconds. (optional, default 0)
  • args object Arguments that will get passed to the renderer (optional, default {})

stop

Stops any caption currently playing.

CaptionPlayer

Parameters

  • captions
  • renderer

update

Updates any currently playing caption. This should be called every frame.

Parameters

  • deltaTime Number Time passed in seconds since last update call.

start

Starts playing a caption.

Parameters

  • name String Name of caption.
  • time number Atart time in milliseconds. (optional, default 0)
  • args object Arguments that will get passed to the renderer (optional, default {})

stop

Stops any caption currently playing.

TimedLine

Properties

setContent

Sets line's content. Removes HTML formatting for text.

Parameters

  • content any

Returns void @memberof TimedLine

IRender

Render interface to help enforce minimum requirements for caption renderers

Properties

  • start function called when the Caption Player starts playing captions
  • stop function called when the Caption Player stops playing captions
  • lineBegin function called when rendering a new line of text
  • lineEnd function called when finished rendering a new of text

DOMRenderer

DOMRender is a incomplete renderer that is intended to supply just the basic start and stop functions

Parameters

start

Makes target element visible and ready to present captions

Parameters

  • templateVariables object Variables that can used during caption play time (optional, default {})

stop

H

HtmlRenderer

HTML Renderer is intended for rendering raw html in the use case of wanting to display styled captions

lineBegin

Called by Caption Player when a new line needs to be displayed

Parameters

  • line

lineEnd

Called by Caption Player when a line is complete

TemplateRenderer

TemplateRenderer accepts a string template e.g.The ball is {{color}} and a args object e.g. {color: 'red'} and swaps out the placeholder inside the double brackets with the matching key inside the args object

Parameters

  • template string String template that will be rendered with the supplied arguments
  • args Object //An Object contain data to be inserted into the template This will match based on key values

Returns string

TextRenderer

TextRenderer is intended for just rendering test. It will attempt to sanitize any strings passed to it by removing html syntax

lineBegin

Called by Caption Player when a new line needs to be displayed

Parameters

  • line

lineEnd

Called by Caption Player when a line is complete

sanitize

Will attempt to remove all html from a string before it's renderer to the page

Parameters

  • html any

Localizer

resolve

Parameters

  • path string
  • options any (optional, default {})

Returns {path: string, language: string}

setPrimaryLocale

Parameters

Returns boolean True if language is set.

setFallbackLocale

Parameters

Returns boolean True if fallback is set.

getLocaleKey

Parameters

Returns string

getBrowserLanguages

Localizer.Options

Type: {language: string, fallback: string}

ApplicationPlugin

Represents a single plugin for applications. Allows developers to inject code in the start up process of an application providing new features to the application.

preload

A preload method for the plugin which allows for asynchronous setup tasks. Either takes a callback as first parameter, or should return a Promise indicating that loading is finished.

Returns Promise A promise indicating when the plugin is finished loading.

init

An init method for the plugin. This method is ran synchronously in the constructor of the Application. After all plugins preloads has completed

start

A start method for the plugin. This method is ran synchronously in the constructor of the Application. After all plugins inits has completed