Skip to content

Commit

Permalink
Merge pull request #2 from AetherInteractiveLtd/modifications
Browse files Browse the repository at this point in the history
feat(visitor): dos and math
  • Loading branch information
siriuslatte authored Mar 14, 2023
2 parents d6773b5 + 59f34a6 commit e2a058d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 96 deletions.
129 changes: 84 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aethergames/scribe",
"version": "0.1.1",
"version": "0.2.1",
"description": "Scribe, a scripting language used to describe Dialogues or Quests behavior.",
"main": "out/init.lua",
"scripts": {
Expand All @@ -12,6 +12,7 @@
"test:rojo": "mkdir build & npm run test:build && rojo build -o ./build/test.rbxlx test.project.json",
"test:run": "npm run test:build && npm run test:serve",
"prepublish": "npm run build && mkdir build && npm pack --pack-destination=build",
"prepare": "husky install",
"test": "npm run test:run"
},
"keywords": [],
Expand Down Expand Up @@ -43,7 +44,7 @@
"typescript": "^4.9.5"
},
"dependencies": {
"@aethergames/mkscribe": "^0.3.0",
"@aethergames/mkscribe": "^0.3.1",
"@rbxts/services": "^1.5.1",
"@rbxts/testez": "^0.4.2-ts.0"
}
Expand Down
30 changes: 3 additions & 27 deletions src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "./types";
import { TokenLiteral } from "@aethergames/mkscribe/out/mkscribe/scanner/types";
import { ScribeVisitor, StatusInterpretationCode } from "./visitor";
import { RunService } from "@rbxts/services";

export class Runtime implements ScribeRuntimeImplementation {
public dialogCallback!: (input: DialogCallbackInput) => void;
Expand Down Expand Up @@ -102,18 +101,13 @@ export class Runtime implements ScribeRuntimeImplementation {
public async interact(id: string): Promise<void> {
if (this.interactions.has(id) === false) {
this.interactions.set(id, {
cleanup: undefined,
lastInteraction: 0,
queue: new Array(),
});
}

// eslint-disable-next-line prefer-const
let { cleanup, lastInteraction, queue } = this.interactions.get(id)!;

if (cleanup !== undefined) {
cleanup.Disconnect();
}
let { lastInteraction, queue } = this.interactions.get(id)!;

const interaction = this.interpreter.records.interactions[id];
if (os.clock() - lastInteraction > this.interactionsCooldown && queue.size() === 0) {
Expand All @@ -126,8 +120,6 @@ export class Runtime implements ScribeRuntimeImplementation {
// eslint-disable-next-line no-constant-condition
while (true) {
if (os.clock() - lastInteraction > this.interactionsCooldown && queue[1] === interaction) {
this.clean(id);

return this.interpreter.resolve(interaction);
} else {
task.wait();
Expand All @@ -136,23 +128,7 @@ export class Runtime implements ScribeRuntimeImplementation {
}
}

private clean(id: string): void {
const interactionJob = this.interactions.get(id);

if (interactionJob !== undefined) {
const { cleanup, lastInteraction, queue } = interactionJob;

if (cleanup !== undefined) {
interactionJob.cleanup = RunService.PostSimulation.Connect(() => {
if (os.clock() - lastInteraction > this.interactionsCooldown && queue.size() === 0) {
if (this.interactions.has(id)) {
this.interactions.delete(id);
}

cleanup.Disconnect();
}
});
}
}
public getRecords(): ScribeVisitor["records"] {
return this.interpreter.records;
}
}
1 change: 0 additions & 1 deletion src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TokenLiteral } from "@aethergames/mkscribe/out/mkscribe/scanner/types";
import { StatusInterpretationCode } from "./visitor";

export declare type InteractionJob = {
cleanup: RBXScriptConnection | undefined;
lastInteraction: number;
queue: Array<Statement>;
};
Expand Down
Loading

0 comments on commit e2a058d

Please sign in to comment.