Skip to main content

Methods

Initialization:
// create the FSI ImageTwins Element and set parameters
const instance = document.createElement("fsi-image-twins-game")
instance.setAttribute('id', 'myGame')
instance.setAttribute('dir', 'images/samples/grid')
instance.setAttribute('columns', '4')
instance.setAttribute('rows', '4')
instance.style.width = '100%'
instance.style.height = '800px'

document.body.appendChild(instance)

// start instance
instance.start()

// Example method, offering a "sneak peek" to the cards
// uncoverCards uncovers them briefly
setTimeout(() => {
instance.uncoverCards()
}, 800)

// coverCards covers them again afterwards
setTimeout(() => {
instance.coverCards()
}, 1400)

// example listener which fires on game end, showing stats
instance.addListener('onGameEnd', (stats) => {
console.log('Your stats are: ', stats)
})

addListener

const success = addListener(listenerName, fn, iScope)
Calls a specific listener. Listeners which are added via addListener(), remain valid when changeConfig() is called.

listenerName
string
Name of listener
fn
string
Name of function executed when listener is called
iScope
string
The scope of variables in which the callback function is called. This determines what the variable `this` means within the specified callback function. If iScope is not passed, iScope will be the instance of the viewer to which the listener has been added.
RETURN
boolean
Returns `true` if successful.
const success = instance.addListener('onGameStart',
(totalCards) => {
// code
})
Example

Consult Callbacks for an overview of all available listeners.

coverCards

coverCards()
Covers all cards.

RETURN
void
This function does not return a value.
instance.coverCards()
Example

destroy

destroy()
Destroys the given FSI ImageTwins object.

RETURN
void
This function does not return a value.
instance.destroy()
Example

dumpListeners

dumpListeners()
Lists all listeners in the console and how often they were called.

RETURN
void
This function does not return a value.
instance.dumpListeners()
Example

getBuild

const version = getBuild()
Returns a string containing the FSI ImageTwins software build number.

RETURN
string
software build number
const version = instance.getBuild()
Example

getConfigValue

const value = getConfigValue(name)
Returns the value of any configuration parameter addressed with `name`.

name
string
Any FSI ImageTwins parameter, e.g. `dir` or `columns`
RETURN
mixed
Requested parameter value
const value = instance.getConfigValue('columns')
Example

getInitDone

const success = getInitDone()
Returns if the initialization process is done.

RETURN
boolean
`true` = initialization process completed
const success = instance.getInitDone()
Example

getInstanceID

const getID = getInstanceID()
Returns the number of the viewer object.

RETURN
integer
Viewer ID
const getID = instance.getInstanceID()
Example

getInstanceName

const name = getInstanceName()
Returns the type of the viewer (e.g. FSI Image Twins Game) and the id attribute of the viewer object.

RETURN
string
Viewer ID attribute
const name = instance.getInstanceName()
Example

getParameters

const param = getParameters()
Returns an object containing all parameters set via javascript or custom tag attributes.

RETURN
object
Object containing all parameters currently set
const param = instance.getParameters()

// return example:
/*
{
columns: "4"
debug: "true"
dir: "images/samples/grid/game"
height: "100%"
id: "myViewer"
rows: "4"
style: "width: 100%; height: 100%;"
width: "100%"
}
*/
Example

getStatistics

const stat = getStatistics()
Returns an object containing statistics of the game.

RETURN
object
Object containing statistics
const param = instance.getStatistics()

// return example:
/*
{
nLuckyOnes: 2
nPairs: 8
nPairsFound: 8
nTimeElapsed: 24155
nTotalCards: 16
nTurns: 13
strTime: "00:00:24"
}
*/
Example

getVersion

const version = getVersion()
Returns a string containing the FSI Viewer software version number.

RETURN
string
Software version number
const version = instance.getVersion()
Example

init

const success = init(id, options, debug)
Initialises the chosen viewer element.

id
string
FSI Viewer Element ID
options
object
Object with start parameters. The same parameters as in configuration files can be used
debug
boolean
debug mode at initialization
RETURN
boolean
Returns `true` if the initialization succeeded.

This method is only needed if an FSI Viewer has not been started automatically (default).

const success = instance.init('fsi-123', {
columns: 6,
rows: 4,
imagemargin: 10,
naturalrotation: 5
}, true)
Example

printAPI

printAPI()
Shows all API methods, listeners and button IDs in the console in alphabetical order.

RETURN
void
This function does not return a value.
instance.printAPI()
Example

removeListener

const success = removeListener(listenerName, fn)
Removes a specific listener.

listenerName
string
Name of listener.
fn
string
Name of function executed when listener is called
RETURN
boolean
Returns `true` if successful.
const success = instance.removeListener('onDestroy', yourFunction)
Example

restartGame

restartGame()
Restarts the game.

RETURN
void
This function does not return a value.
instance.restartGame()
Example

start

start()
Starts the game.

RETURN
void
This function does not return a value.
instance.start()
Example

traceConfigValue

const show = traceConfigValue(strName)
Traces a config value and enables you to see where (by parameter/attribute, in config files, the _default.xml, etc) a specific value is set.

name
string
Any FSI Viewer parameter e.g. `columns` or `naturalRotation`
RETURN
mixed
Returns where parameter is set
const show = instance.traceConfigValue('columns')

// return example:
// Tracing parameter "columns"
// By Parameter/Attribute:
// 4
// RESULT:
// columns = "4"
Example

uncoverCards

uncoverCards()
Uncovers all cards.

RETURN
void
This function does not return a value.

instance.uncoverCards()
Example