Skip to content

Commit

Permalink
Merge pull request #3 from AetherInteractiveLtd/dialogs-fixes
Browse files Browse the repository at this point in the history
fix(dialogs) & meta(versioning): yielding removed, fixed a lot of issues
  • Loading branch information
siriuslatte authored Mar 21, 2023
2 parents e2a058d + 7ca1bdd commit 94c79f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export class Runtime implements ScribeRuntimeImplementation {
}

public async interact(id: string): Promise<void> {
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,
Expand All @@ -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();

Expand Down
8 changes: 5 additions & 3 deletions src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>;

export declare type InteractionJob = {
lastInteraction: number;
queue: Array<Statement>;
Expand All @@ -20,7 +22,7 @@ export declare type ScribeProgramProperties = Record<string | ScribeProperties,

export declare type OptionStructure = {
text?: TokenLiteral;
metadata?: TokenLiteral;
metadata?: ScribeMetadata;

/** @hidden */
_body: Statement;
Expand All @@ -29,7 +31,7 @@ export declare type OptionStructure = {
export declare type DialogCallbackInput = {
characterIdentifier: string;
text: TokenLiteral;
metadata: TokenLiteral;
metadata: ScribeMetadata;
options: Array<OptionStructure>;

step: (id?: number) => void;
Expand All @@ -43,7 +45,7 @@ export declare type ObjectiveChangeCallbackInput = {
export declare type PipeToCallbackInput = {
identifier: string;
data: unknown;
metadata: Array<unknown>;
metadata: ScribeMetadata;
};

export interface ScribeRuntimeImplementation {
Expand Down
12 changes: 4 additions & 8 deletions src/runtime/visitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<unknown>;
if (stmt.metadata !== undefined) {
metadata = this.evaluate(stmt.metadata);
metadata = this.evaluate(stmt.metadata) as never;
}

// eslint-disable-next-line prefer-const
Expand All @@ -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 {
Expand Down

0 comments on commit 94c79f5

Please sign in to comment.