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.
const success = instance.addListener('onGameStart',
(totalCards) => {
// code
})
Example
Consult Callbacks for an overview of all available listeners.
dumpListeners
dumpListeners()
Lists all listeners in the console and how often they were called.
instance.dumpListeners()
Example
getBuild
const version = getBuild()
Returns a string containing the FSI ImageTwins software build number.
const version = instance.getBuild()
Example
getConfigValue
const value = getConfigValue(name)
Returns the value of any configuration parameter addressed with `name`.
const value = instance.getConfigValue('columns')
Example
getInitDone
const success = getInitDone()
Returns if the initialization process is done.
const success = instance.getInitDone()
Example
getInstanceID
const getID = getInstanceID()
Returns the number of the viewer object.
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.
const name = instance.getInstanceName()
Example
getParameters
const param = getParameters()
Returns an object containing all parameters set via javascript or custom tag attributes.
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.
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.
const version = instance.getVersion()
Example
init
const success = init(id, options, debug)
Initialises the chosen viewer element.
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.
instance.printAPI()
Example
removeListener
const success = removeListener(listenerName, fn)
Removes a specific listener.
const success = instance.removeListener('onDestroy', yourFunction)
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.
const show = instance.traceConfigValue('columns')
// return example:
// Tracing parameter "columns"
// By Parameter/Attribute:
// 4
// RESULT:
// columns = "4"
Example