UNPKG

dotup-ts-node-skills-game

Version:
187 lines (185 loc) 7.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // tslint:disable:newline-before-return const Enumerations_1 = require("../Constants/Enumerations"); // Define some animations that we'll use during roll call, to be played in various situations, // such as when buttons "check in" during roll call, or after both buttons were detected. // See: https://developer.amazon.com/docs/gadget-skills/control-echo-buttons.html#animate // Define two recognizers that will capture the first time each of two arbitrary buttons is pressed. // We'll use proxies to refer to the two different buttons because we don't know ahead of time // which two buttons will be used (see: https://developer.amazon.com/docs/gadget-skills/define-echo-button-events.html#proxies) // The two recogniziers will be used as triggers for two input handler events, used during roll call. // see: https://developer.amazon.com/docs/gadget-skills/define-echo-button-events.html#recognizers // Define some animations that we'll use during roll call, to be played in various situations, // such as when buttons "check in" during roll call, or after both buttons were detected. // See: https://developer.amazon.com/docs/gadget-skills/control-echo-buttons.html#animate // Define two recognizers that will capture the first time each of two arbitrary buttons is pressed. // We'll use proxies to refer to the two different buttons because we don't know ahead of time // which two buttons will be used (see: https://developer.amazon.com/docs/gadget-skills/define-echo-button-events.html#proxies) // The two recogniziers will be used as triggers for two input handler events, used during roll call. // see: https://developer.amazon.com/docs/gadget-skills/define-echo-button-events.html#recognizers var RecognizerBuilderMode; (function (RecognizerBuilderMode) { RecognizerBuilderMode[RecognizerBuilderMode["PatternForEachProxy"] = 0] = "PatternForEachProxy"; // RecognizerForEachProxy, RecognizerBuilderMode[RecognizerBuilderMode["OnePattern"] = 1] = "OnePattern"; RecognizerBuilderMode[RecognizerBuilderMode["CustomPattern"] = 2] = "CustomPattern"; })(RecognizerBuilderMode = exports.RecognizerBuilderMode || (exports.RecognizerBuilderMode = {})); class RecognizerBuilder { constructor(recognizerName, mode = RecognizerBuilderMode.OnePattern) { this.gadgetIds = []; // private timeout: number = 10000; this.action = Enumerations_1.ButtonActionMode.down; this.anchor = Enumerations_1.AnchorMode.end; this.fuzzy = false; this.recognizerType = Enumerations_1.RecognizerType.patternRecognizer; this.recognizerName = recognizerName; this.recognizerBuilderMode = mode; this.gadgetIds = []; } static ButtonDown(gadgetIds, color) { const rb = new RecognizerBuilder(); rb .WithGadgets(gadgetIds) .WithRecognizerBuilderMode(RecognizerBuilderMode.OnePattern) .WithFuzzy(true); if (color !== undefined) { rb.WithColors(color); } return rb.Build(); } static ButtonGroupDown(gadgetIds) { const rb = new RecognizerBuilder(); return rb .WithGadgets(gadgetIds) .WithRecognizerBuilderMode(RecognizerBuilderMode.PatternForEachProxy) .WithFuzzy(true) .Build(); } WithGadgets(proxyName) { if (Array.isArray(proxyName)) { this.gadgetIds = this.gadgetIds.concat(proxyName); } else { this.gadgetIds.push(proxyName); } return this; } WithColors(color) { if (Array.isArray(color)) { this.colors = color; } else { this.colors = []; this.colors.push(color); } return this; } WithName(recognizerName) { this.recognizerName = recognizerName; return this; } WithRecognizerBuilderMode(mode) { this.recognizerBuilderMode = mode; return this; } WithRecognizerType(recognizerType) { this.recognizerType = recognizerType; return this; } WithAction(action) { this.action = action; return this; } WithAnchor(anchor) { this.anchor = anchor; return this; } WithFuzzy(fuzzy) { this.fuzzy = fuzzy; return this; } // TODO: remove that shit getPattern(gadgetIds, action) { if (this.colors === undefined) { return { gadgetIds: gadgetIds.slice(), action: action }; } else { return { gadgetIds: gadgetIds.slice(), action: action, colors: this.colors.slice() }; } } Build(pattern) { let result; const patternArray = Array.isArray(pattern) ? pattern : [pattern]; if (pattern !== undefined) { this.recognizerBuilderMode = RecognizerBuilderMode.CustomPattern; } switch (this.recognizerBuilderMode) { case RecognizerBuilderMode.OnePattern: const onePattern = { type: this.recognizerType, fuzzy: this.fuzzy, anchor: this.anchor, pattern: [this.getPattern(this.gadgetIds, this.action)] }; result = onePattern; break; case RecognizerBuilderMode.PatternForEachProxy: const p = this.gadgetIds.map((proxyName, index) => { return this.getPattern([this.gadgetIds[index]], this.action); }); const rrecognizer = { type: Enumerations_1.RecognizerType.patternRecognizer, fuzzy: this.fuzzy, anchor: this.anchor, pattern: p }; result = rrecognizer; // tslint:disable-next-line:switch-final-break break; case RecognizerBuilderMode.CustomPattern: const crecognizer = { type: Enumerations_1.RecognizerType.patternRecognizer, fuzzy: this.fuzzy, anchor: this.anchor, pattern: patternArray }; if (this.gadgetIds !== undefined && this.gadgetIds.length > 0) { crecognizer.gadgetIds = this.gadgetIds; } if (this.action !== undefined) { crecognizer.actions = [this.action]; } result = crecognizer; // case RecognizerBuilderMode.RecognizerForEachProxy: // this.gadgetIds.forEach((proxyName, index) => { // const recognizer: IPatternRecognizer = { // type: RecognizerType.patternRecognizer, // fuzzy: this.fuzzy, // anchor: this.anchor, // pattern: [this.getPattern([proxyName], this.action)] // }; // result = recognizer; // }); // // tslint:disable-next-line:switch-final-break // break; } this.gadgetIds = []; return result; } } exports.RecognizerBuilder = RecognizerBuilder; // const builder = new RecognizerBuilder('done', RecognizerBuilderMode.PatternForEachProxy); // const x = builder // .WithProxy('Lena') // .WithProxy('Peter') // .Build(); // console.log(JSON.stringify(x, undefined, 2)); //# sourceMappingURL=RecognizerBuilder.js.map