From 7ca1bdd0a96104e9811c2754ff5b0fec73a2a5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ademir=20S=C3=A1nchez?= Date: Mon, 20 Mar 2023 17:22:32 -0600 Subject: [PATCH] fix(dialogs) & meta(versioning): yielding removed, fixed a lot of issues --- package.json | 2 +- src/runtime/index.ts | 7 ++++++- src/runtime/types.d.ts | 8 +++++--- src/runtime/visitor/index.ts | 12 ++++-------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5340ae8..2cf5966 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aethergames/scribe", - "version": "0.2.1", + "version": "0.2.2-beta.1", "description": "Scribe, a scripting language used to describe Dialogues or Quests behavior.", "main": "out/init.lua", "scripts": { diff --git a/src/runtime/index.ts b/src/runtime/index.ts index bc6a5a4..56688fc 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -99,6 +99,12 @@ export class Runtime implements ScribeRuntimeImplementation { } public async interact(id: string): Promise { + const interaction = this.interpreter.records.interactions[id]; + + if (!interaction) { + throw `Scene specified [${id}] isn't defined on the Scribe's program.`; + } + if (this.interactions.has(id) === false) { this.interactions.set(id, { lastInteraction: 0, @@ -109,7 +115,6 @@ export class Runtime implements ScribeRuntimeImplementation { // eslint-disable-next-line prefer-const let { lastInteraction, queue } = this.interactions.get(id)!; - const interaction = this.interpreter.records.interactions[id]; if (os.clock() - lastInteraction > this.interactionsCooldown && queue.size() === 0) { lastInteraction = os.clock(); diff --git a/src/runtime/types.d.ts b/src/runtime/types.d.ts index f956173..f126ad9 100644 --- a/src/runtime/types.d.ts +++ b/src/runtime/types.d.ts @@ -2,6 +2,8 @@ import { Statement } from "@aethergames/mkscribe"; import { TokenLiteral } from "@aethergames/mkscribe/out/mkscribe/scanner/types"; import { StatusInterpretationCode } from "./visitor"; +export declare type ScribeMetadata = Array; + export declare type InteractionJob = { lastInteraction: number; queue: Array; @@ -20,7 +22,7 @@ export declare type ScribeProgramProperties = Record; step: (id?: number) => void; @@ -43,7 +45,7 @@ export declare type ObjectiveChangeCallbackInput = { export declare type PipeToCallbackInput = { identifier: string; data: unknown; - metadata: Array; + metadata: ScribeMetadata; }; export interface ScribeRuntimeImplementation { diff --git a/src/runtime/visitor/index.ts b/src/runtime/visitor/index.ts index 71cb722..d515470 100644 --- a/src/runtime/visitor/index.ts +++ b/src/runtime/visitor/index.ts @@ -288,7 +288,7 @@ export class ScribeVisitor implements Interpreter { } public visitLiteralExpression(expr: LiteralExpression): TokenLiteral { - return expr.value; + return expr.dataType !== "number" ? expr.value : tonumber(expr.value); } public visitGroupingExpression(expr: GroupingExpression): TokenLiteral { @@ -418,13 +418,13 @@ export class ScribeVisitor implements Interpreter { this.resolve(stmt.body); } - public visitDialogueStatement(stmt: DialogueStatement): never { + public visitDialogueStatement(stmt: DialogueStatement): void { const characterIdentifier = stmt.actor.lexeme as string; const text = this.evaluate(stmt.text) as string; - let metadata: TokenLiteral; + let metadata: Array; if (stmt.metadata !== undefined) { - metadata = this.evaluate(stmt.metadata); + metadata = this.evaluate(stmt.metadata) as never; } // eslint-disable-next-line prefer-const @@ -443,13 +443,9 @@ export class ScribeVisitor implements Interpreter { if (id !== undefined) { this.resolve(options[id - 1]._body); } - - return coroutine.resume(this.interpreterCoroutine); }, }); }); - - return coroutine.yield() as never; } public visitConditionStatement(stmt: ConditionStatement): void {