UNPKG

dotup-ts-node-skills-game

Version:
120 lines (118 loc) 5.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const dotup_ts_ssml_builder_1 = require("dotup-ts-ssml-builder"); const AnimationBuilder_1 = require("../Builder/AnimationBuilder"); const GadgetBuilder_1 = require("../Builder/GadgetBuilder"); const RollcallBuilder_1 = require("../Builder/RollcallBuilder"); const Enumerations_1 = require("../Constants/Enumerations"); const Rollcall_1 = require("./Rollcall"); const RollcallState_1 = require("./RollcallState"); class AssignToPlayerRollcall extends Rollcall_1.Rollcall { constructor(context, requirements) { super(context, requirements); } createStartDirective() { const rollcallBuilder = new RollcallBuilder_1.RollCallBuilder(); const session = this.context.request.getSessionAttributes(); const buttonGroups = session.rollcall.rollcallButtonGroups; const currentGroup = buttonGroups.find(group => { return group.buttons.some(button => { return button.id === undefined; }); }); if (currentGroup === undefined) { throw new Error('No button group found.'); } // Prepare rollcall builder rollcallBuilder .WithColor(Enumerations_1.TriggerEvent.none, Enumerations_1.ButtonColor.off) .WithColor(Enumerations_1.TriggerEvent.buttonDown, Enumerations_1.ButtonColor.green); // Add name to rollcall builder rollcallBuilder.WithProxy(currentGroup.buttons.map(b => b.name)); // Get start directive const startDirective = rollcallBuilder.BuildButtonGroup(currentGroup.name, // EventNames.ButtonGroupPressed, this.requirements.rollcallDuration, () => { this.context.SaveRequestId(); }); const sb = new dotup_ts_ssml_builder_1.AmazonSsmlBuilder(); sb.AddText(`${currentGroup.name} drücke jetzt nacheinander`); currentGroup.buttons.forEach((button, index) => { sb.AddText(`den ${button.name}`); if (index === currentGroup.buttons.length - 2) { sb.AddText(`und`); } }); sb.AddText(`Button`); this.context.Speak(sb); // this.context.Speak(`${currentGroup.name} drücke jetzt ${currentGroup.buttons.length} Buttons.`); this.context.Speak(`Du hast ${this.requirements.rollcallDuration / 1000} Sekunden zeit.`); // this.context.Speak(`Wenn du fertig bist sage einfach ja.`); // this.context.Reprompt('hast du alle Buttons gedrückt?'); this.context.AddDirective(startDirective); } YesIntent() { throw new Error('YesIntent not supported.'); } NoIntent() { throw new Error('NoIntent not supported.'); } OnTimeout(item) { // Try to stop the rollcall switch (this.model.state) { case RollcallState_1.RollcallState.Active: if (this.isValid()) { this.StopRollcall(); } else { this.createStartDirective(); this.model.state = RollcallState_1.RollcallState.RepeatRollcall; } break; case RollcallState_1.RollcallState.RepeatRollcall: if (this.isValid()) { this.StopRollcall(); } else { this.context.Speak('Na vielleicht beim nächsten mal. Tschüss.'); this.context.shouldEndSession(true); this.CancelRollcall(); } break; case RollcallState_1.RollcallState.Cancelled: this.context.Speak('Na vielleicht beim nächsten mal. Tschüss.'); this.context.shouldEndSession(true); this.CancelRollcall(); break; default: // It's already handled } } OnButtonFound(name, id, nextButton) { // const currentGroup = this.model.rollcallButtonGroups.find(group => group.name === name); // const currentButton = currentGroup.buttons.find(button => button.name === nextButton.name); // currentButton.id = nextButton.id; // Notify user by light const light = GadgetBuilder_1.GadgetBuilder.setLight(id, AnimationBuilder_1.AnimationBuilder.GetFadeAnimation(Enumerations_1.ButtonColor.green), Enumerations_1.TriggerEvent.none); this.context.AddDirective(light); this.context.shouldEndSession(undefined); } isValid() { if (this.model.rollcallButtonGroups === undefined) { return false; } // Test each button group const result = this.model.rollcallButtonGroups.some(group => { // Buttons without id const withIds = group.buttons.filter(button => { return button.id !== undefined; }); if (withIds.length < this.requirements.numberOfButtonsPerButtonGroupMin) { return true; } if (withIds.length > this.requirements.numberOfButtonsPerButtonGroupMax) { return true; } }); return !result; } } exports.AssignToPlayerRollcall = AssignToPlayerRollcall; //# sourceMappingURL=AssignToPlayerRollcall.js.map