UNPKG

dotup-ts-node-skills-game

Version:
74 lines (72 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // tslint:disable:newline-before-return const Enumerations_1 = require("../Constants/Enumerations"); class PatternBuilder { constructor(action, repeat) { this.pattern = {}; this.pattern.action = action; this.pattern.repeat = repeat; } static ButtonGroupDown(gadgetIds, colors, repeat = 1) { const result = { action: Enumerations_1.ButtonActionMode.down, repeat: repeat }; if (gadgetIds !== undefined) { result.gadgetIds = gadgetIds; } if (colors !== undefined) { result.colors = colors; } if (gadgetIds !== undefined) { result.gadgetIds = gadgetIds; } return result; } WithAction(buttonActionMode) { this.pattern.action = buttonActionMode; return this; } WithRepeat(repeat) { this.pattern.repeat = repeat; return this; } WithColor(color) { if (this.pattern.colors === undefined) { this.pattern.colors = []; } this.pattern.colors.push(color); return this; } WithGadger(gadgetId) { this.pattern.gadgetIds = Array.isArray(gadgetId) ? gadgetId : [gadgetId]; return this; } Build() { const result = this.pattern; this.pattern = {}; return result; } } exports.PatternBuilder = PatternBuilder; // const builder = new PatternBuilder(); // const x = builder // .WithAction(ButtonActionMode.down) // .WithGadger('peter'); // .WithEventName('ButtonAssigned') // .ForRecognizer('peter') // .ForRecognizer('lena') // .FailsWhen('timeout') // .Build(); // const y = builder // .ForRecognizer('peter') // .ForRecognizer('lena') // .FailsWhen('timeout') // .Build(); // console.log(JSON.stringify(x, undefined, 2)); // console.log(JSON.stringify(y, undefined, 2)); // const all = ObjectTools.CopyEachSource(x, y); // console.log(JSON.stringify(y, undefined, 2)); // console.log(''); //# sourceMappingURL=PatternBuilder.js.map