Conditions table

Introduction

Check conditions to find passed tests listed in a csv table.

  • Author: Rex
  • Member of scene

Usage

Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.plugin('rexconditionstableplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexconditionstableplugin.min.js', true);
    
  • Add conditions-table object
    var conditionstable = scene.plugins.get('rexconditionstableplugin').add();
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import ConditionsTablePlugin from 'phaser3-rex-plugins/plugins/conditionstable-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexConditionsTable',
                plugin: ConditionsTablePlugin,
                start: true
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Add conditions-table object
    var conditionstable = scene.plugins.get('rexConditionsTable').add();
    

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import class
    import ConditionsTable from 'phaser3-rex-plugins/plugins/conditionstable.js';
    
  • Add conditions-table object
    var conditionstable = new ConditionsTable();
    

Create instance

var table = scene.plugins.get('rexConditionsTable').add();

Load table from csv string

table.loadCSV(csvString, {
    // delimiter: ','
});

For exameple, csv string

name A A B
Test1 >= 10 <= 20
Test2 3
,A,A,B
Test1,>= 10,<= 20,
Test2,,,3

means that:

Test1: (A>=10) && (A<=20)
Test2: (B==3)

Test

Get first pass test name

table.anyPassTest(values, function(testName){

}, scope);
  • values : Inputs in Key-value pairs

or

var testName = table.anyPassTest(values);

Get each pass test name

table.eachPassTest(values, function(testName){

}, scope);

Get result of each test

table.eachTest(values, function(testName, result){

}, scope);