UNPKG

dotup-ts-node-skills-game

Version:
128 lines (126 loc) 6.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const dotup_ts_node_skills_workflows_1 = require("dotup-ts-node-skills-workflows"); const GameTextKeys_1 = require("./Constants/GameTextKeys"); const Player_1 = require("./Game/Player"); const WorkflowNames_1 = require("./Game/WorkflowNames"); var GameWorkflowQuestions; (function (GameWorkflowQuestions) { GameWorkflowQuestions.numberOfPlayers = { workflowName: WorkflowNames_1.WorkflowNames.GetNumberOfPlayer, ask: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.HowManyPlayers), reprompt: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.HowManyPlayers), askAgain: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.HowManyPlayers), handler: { GetNumberIntent: (context, wc, slotset) => { const r = context.request.getRequestAttributes().gameRequirements; let currentStep = wc.getCurrentStep(); if (slotset.hasValue('numberSlot')) { const numberOfPlayer = slotset.getNumber('numberSlot'); wc.payload.NumberOfPlayer = numberOfPlayer; if (isInRange(numberOfPlayer, r.numberOfPlayerMin, r.numberOfPlayerMax)) { for (let index = 0; index < numberOfPlayer; index += 1) { // Add workflow to get player name currentStep = wc.add(WorkflowNames_1.WorkflowNames.GetPlayerName, index + 1, currentStep); } const text = context.t.getPlural(GameTextKeys_1.GameTextKeys.SayNumberOfPlayers_0, numberOfPlayer); context.Speak(text); // context.Speak(`Okay ${numberOfPlayer} Spieler.`); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromNext; } else { context.SpeakT(GameTextKeys_1.GameTextKeys.SayNumberBetween_0_And_1, r.numberOfPlayerMin, r.numberOfPlayerMax); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromCurrent; } } else { context.SpeakT(GameTextKeys_1.GameTextKeys.DidNotUnderstand); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromCurrent; } } } }; GameWorkflowQuestions.playerNames = { workflowName: WorkflowNames_1.WorkflowNames.GetNumberOfPlayer, ask: (context, wc) => context.t.getText(GameTextKeys_1.GameTextKeys.Player_0_WhatIsYourName, wc.getCurrentPayload()), reprompt: (context, wc) => context.t.getText(GameTextKeys_1.GameTextKeys.Player_0_WhatIsYourName, wc.getCurrentPayload()), askAgain: (context, wc) => context.t.getText(GameTextKeys_1.GameTextKeys.Player_0_WhatIsYourName, wc.getCurrentPayload()), handler: { GetFirstNameIntent: (context, wc, slotset) => { const currentStep = wc.getCurrentStep(); if (slotset.hasValue('firstName')) { const name = slotset.slot('firstName').value; // Workflow item completed context.SpeakT(GameTextKeys_1.GameTextKeys.Player_0_IsCalled_1, currentStep.Payload, name); // context.Speak(`Spieler ${currentStep.Payload} heißt ${name}.`); // Store player if (wc.payload.Players === undefined) { wc.payload.Players = []; } wc.payload.Players.push(new Player_1.Player(name)); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromNext; } else { context.SpeakT(GameTextKeys_1.GameTextKeys.DidNotUnderstand); // context.Speak('Das habe ich nicht verstanden.'); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromCurrent; } } } }; GameWorkflowQuestions.roundsToPlay = { workflowName: WorkflowNames_1.WorkflowNames.GetRoundToPlay, ask: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.HowManyRoundsToPlay), reprompt: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.HowManyRoundsToPlay), askAgain: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.HowManyRoundsToPlay), handler: { GetNumberIntent: (context, wc, slotset) => { const eineSlot = slotset.getString('eineSlot'); let value = slotset.getNumber('numberSlot'); if (Number.isNaN(value)) { if (eineSlot === 'eine') { value = 1; } } if (value !== undefined) { wc.payload.RoundsToPlay = value; const text = context.t.getPlural(GameTextKeys_1.GameTextKeys.SayRoundsToPlay_0, value); context.Speak(text); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromNext; } else { context.SpeakT(GameTextKeys_1.GameTextKeys.DidNotUnderstand); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromCurrent; } } } }; GameWorkflowQuestions.readyToPlay = { workflowName: WorkflowNames_1.WorkflowNames.ReadyToPlay, ask: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.ReadyToPlay), reprompt: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.ReadyToPlay), askAgain: ctx => ctx.GetText(GameTextKeys_1.GameTextKeys.ReadyToPlay), handler: { YesIntent: (context, wc, slotset) => { // const modelService = new GameModelService(); // modelService.save(context); return dotup_ts_node_skills_workflows_1.WorkflowStepState.GetFromNext; }, NoIntent: (context, slotset) => { context.SpeakT(GameTextKeys_1.GameTextKeys.LeaveGame); context.shouldEndSession(true); return dotup_ts_node_skills_workflows_1.WorkflowStepState.Error; } } }; function isInRange(value, min, max) { if (value > max) { return false; } if (value < min) { return false; } return true; } })(GameWorkflowQuestions = exports.GameWorkflowQuestions || (exports.GameWorkflowQuestions = {})); //# sourceMappingURL=GameWorkflowQuestions.js.map