-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugs fixing
- Loading branch information
Showing
24 changed files
with
415 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
/include | ||
/build | ||
*.tsbuildinfo | ||
|
||
# misc | ||
.DS_Store | ||
*.pem |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
export = (): void => {} | ||
/// <reference types="@rbxts/testez/globals" /> | ||
|
||
import { Scribe } from "." | ||
|
||
export = (): void => { | ||
describe("creating a new ScribeRuntime", () => { | ||
const ScribeRuntime = Scribe.load(` | ||
actor BEATRIZ "beatriz_id" | ||
default objective hello "My objective!" | ||
echo $test | ||
interact BEATRIZ { | ||
echo "Interacted with Beatriz!" | ||
} | ||
`, { | ||
test: "Hello, world!" | ||
}) | ||
|
||
it("should not throw when instantiating a new ScribeRuntime.", () => { | ||
expect(() => Scribe.load("", {})).never.to.throw() | ||
}) | ||
|
||
it("should not throw when retrieving an objective.", () => { | ||
expect(() => { | ||
ScribeRuntime.getCurrentObjective() | ||
ScribeRuntime.getObjective("hello") | ||
}).never.to.throw() | ||
}) | ||
|
||
it("should interact correctly with the actor", () => { | ||
expect(() => { | ||
ScribeRuntime.interact("beatriz_id") | ||
}).never.to.throw() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { MkScribe } from "@aethergames/mkscribe"; | ||
import { ScribeEnviroment } from "../types"; | ||
import { | ||
DialogCallbackInput, | ||
InteractionJob, | ||
Objective, | ||
ObjectiveChangeCallbackInput, | ||
PipeToCallbackInput, | ||
ScribeProgramProperties, | ||
ScribeRuntimeImplementation, | ||
} 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; | ||
public objectiveChangeCallback!: (input: ObjectiveChangeCallbackInput) => void; | ||
public pipeTo!: (config: PipeToCallbackInput) => void; | ||
|
||
private interpreter!: ScribeVisitor; | ||
|
||
private interactions: Map<string, InteractionJob> = new Map(); | ||
private interactionsCooldown = 1 / 60; | ||
|
||
constructor(private readonly source: string, private readonly env: ScribeEnviroment) {} | ||
|
||
public start(): StatusInterpretationCode { | ||
this.interpreter = new ScribeVisitor( | ||
MkScribe.build(this.source), | ||
{ | ||
onDialog: this.dialogCallback, | ||
onStoreChange: this.pipeTo, | ||
onObjectiveChange: this.objectiveChangeCallback, | ||
}, | ||
this.env, | ||
); | ||
|
||
return this.interpreter.interpret(); | ||
} | ||
|
||
public getObjective(objective: string): Objective | undefined { | ||
return this.interpreter.records.objectives[objective]; | ||
} | ||
|
||
public getCurrentObjective(): Objective | undefined { | ||
const current = this.interpreter.records.objectives.current; | ||
|
||
if (current !== undefined) { | ||
return this.interpreter.records.objectives[current]; | ||
} | ||
} | ||
|
||
public getProperty(property: string): TokenLiteral { | ||
return this.interpreter.programProperties[property]; | ||
} | ||
|
||
public getProperties(): ScribeProgramProperties { | ||
return this.interpreter.programProperties; | ||
} | ||
|
||
public incrementStore(valueTo: string, increment: number): void { | ||
let head = this.interpreter.refs[valueTo]; | ||
|
||
while (head !== undefined) { | ||
const { ref } = head; | ||
|
||
if (typeOf(this.interpreter.records.stores[ref][0]) === "number") { | ||
(this.interpreter.records.stores[ref][0] as number) += increment; | ||
} else { | ||
warn(`[Interpreter:incrementValue]: ${ref} isn't of type number, it can't be incremented.`); | ||
} | ||
|
||
head = head._next; | ||
} | ||
} | ||
|
||
public setStore(valueTo: string, value: unknown): void { | ||
let head = this.interpreter.refs[valueTo]; | ||
|
||
while (head !== undefined) { | ||
this.interpreter.records.stores[head.ref][0] = value as TokenLiteral; | ||
|
||
head = head._next; | ||
} | ||
} | ||
|
||
public setCurrentObjective(objective: string): void { | ||
this.interpreter.records.objectives.current = objective; | ||
} | ||
|
||
public play(id: string): void { | ||
const scene = this.interpreter.records.scenes[id]; | ||
|
||
if (scene !== undefined) { | ||
this.interpreter.resolve(this.interpreter.records.scenes[id]); | ||
} else { | ||
throw `Scene specified [${id}] isn't defined on the Scribe's program.`; | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
|
||
const interaction = this.interpreter.records.interactions[id]; | ||
if (os.clock() - lastInteraction > this.interactionsCooldown && queue.size() === 0) { | ||
lastInteraction = os.clock(); | ||
|
||
return this.interpreter.resolve(interaction); | ||
} else { | ||
queue.push(interaction); | ||
|
||
// 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(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.