All files / src/lib/modules variables.ts

100% Statements 19/19
50% Branches 1/2
100% Functions 9/9
100% Lines 19/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 472x 2x   2x 2x           2x   11x       5x     2x     2x 1x 1x 1x 1x 1x   1x                   2x 2x 2x   2x      
import {Module} from "../module";
import {Util} from "../util";
import {PuzzleJs} from "../puzzle";
import {EVENT, LOG_COLORS} from "../enums";
import {on} from "../decorators";
 
export interface IPageVariables {
  [fragmentName: string]: { [name: string]: any };
}
 
export class Variables extends Module {
  static get variables(): IPageVariables {
    return Variables.__variables;
  }
 
  static set variables(value: IPageVariables) {
    Variables.__variables = value;
  }
 
  private static __variables: IPageVariables = {};
 
  @on(EVENT.ON_PAGE_LOAD)
  static print() {
    Util.wrapGroup('PuzzleJs', 'Debug Mode - Variables', () => {
      Object.keys(Variables.variables).forEach(fragmentName => {
        Util.wrapGroup('PuzzleJs', fragmentName, () => {
          Object.keys(Variables.variables[fragmentName]).forEach(configKey => {
            Util.wrapGroup('PuzzleJs', configKey, () => {
 
              Util.log(Variables.variables[fragmentName][configKey]);
            }, LOG_COLORS.YELLOW);
          });
        }, LOG_COLORS.BLUE);
      });
    });
  }
 
 
  @on(EVENT.ON_VARIABLES)
  static set(fragmentName: string, varName: string, configData: object) {
    Eif (!Variables.variables[fragmentName]) {
      Variables.variables[fragmentName] = {};
    }
    Variables.variables[fragmentName][varName] = configData;
  }
}