summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/engine/TheAbstractionEngine.ts2
-rw-r--r--src/engine/entities/FunctionApplication.ts6
-rw-r--r--src/engine/levels/CarCadr.ts44
-rw-r--r--src/engine/utils/CodeEditor.ts6
4 files changed, 40 insertions, 18 deletions
diff --git a/src/engine/TheAbstractionEngine.ts b/src/engine/TheAbstractionEngine.ts
index 96d078f..2ea3be5 100644
--- a/src/engine/TheAbstractionEngine.ts
+++ b/src/engine/TheAbstractionEngine.ts
@@ -35,7 +35,7 @@ export class TheAbstractionEngine {
[
new Modal(),
- new Level(LevelNames.LevelSelection),
+ new Level(LevelNames.CarCadr),
inputSystem,
facingDirectionSystem,
new Grid(
diff --git a/src/engine/entities/FunctionApplication.ts b/src/engine/entities/FunctionApplication.ts
index bd88bda..ac07f88 100644
--- a/src/engine/entities/FunctionApplication.ts
+++ b/src/engine/entities/FunctionApplication.ts
@@ -30,8 +30,9 @@ import {
interpret,
} from "../../interpreter";
-const APPLICATION_RESULTS: Record<string, (gridPosition: Coord2D) => Entity> = {
+const APPLICATION_RESULTS: Record<string, (gridPosition: Coord2D) => null | Entity> = {
_KEY: (gridPosition: Coord2D) => new Key(gridPosition),
+ _EMPTY: (_gridPosition: Coord2D) => null,
};
export class FunctionApplication extends Entity {
@@ -177,7 +178,8 @@ export class FunctionApplication extends Entity {
const { name } = data;
const entityFactory = APPLICATION_RESULTS[name];
if (entityFactory) {
- game.addEntity(entityFactory(nextPosition));
+ const entity = entityFactory(nextPosition)
+ entity && game.addEntity(entity);
}
}
diff --git a/src/engine/levels/CarCadr.ts b/src/engine/levels/CarCadr.ts
index e3d1eb9..07c6f11 100644
--- a/src/engine/levels/CarCadr.ts
+++ b/src/engine/levels/CarCadr.ts
@@ -38,21 +38,39 @@ export class CarCadr extends Level {
const entities = [
...grasses,
new Player({ x: 9, y: 5 }),
- new Wall({ x: 4, y: 3 }),
- new Wall({ x: 4, y: 4 }),
- new LambdaFactory({ x: 6, y: 4 }, "(\\ (x) . x)", 1),
- new FunctionApplication({ x: 5, y: 5 }, "(_INPUT _KEY)"),
+ // Cadr
+ new Wall({ x: 2, y: 3 }),
+ new Wall({ x: 2, y: 4 }),
+ new Wall({ x: 5, y: 3 }),
+ new LambdaFactory({ x: 4, y: 4 }, "(\\ (x) . x)", 1),
+ new FunctionApplication({ x: 3, y: 5 }, "(_INPUT _KEY)"),
+ new Wall({ x: 2, y: 5 }),
new Wall({ x: 4, y: 5 }),
- new Wall({ x: 6, y: 5 }),
- new FunctionApplication({ x: 4, y: 6 }, "(_INPUT _NULL)"),
- new Wall({ x: 6, y: 7 }),
- new Wall({ x: 5, y: 7 }),
+ new FunctionApplication({ x: 2, y: 6 }, "(_INPUT _EMPTY)"),
new Wall({ x: 4, y: 7 }),
- new LockedDoor({ x: 3, y: 8 }),
- new Curry({ x: 3, y: 9 }),
- new Wall({ x: 2, y: 9 }),
- new Wall({ x: 4, y: 9 }),
- new Wall({ x: 3, y: 10 }),
+ new Wall({ x: 3, y: 7 }),
+ new Wall({ x: 2, y: 7 }),
+ new Wall({ x: 9, y: 3 }),
+ // Car
+ new LambdaFactory({ x: 10, y: 4 }, "(\\ (x) . x)", 1),
+ new Wall({ x: 12, y: 4 }),
+ new FunctionApplication({ x: 11, y: 5 }, "(_INPUT _EMPTY)"),
+ new Wall({ x: 10, y: 5 }),
+ new Wall({ x: 12, y: 5 }),
+ new Wall({ x: 12, y: 3 }),
+ new FunctionApplication({ x: 12, y: 6 }, "(_INPUT _KEY)"),
+ new Wall({ x: 10, y: 7 }),
+ new Wall({ x: 11, y: 7 }),
+ new Wall({ x: 12, y: 7 }),
+ // solve!
+ new LockedDoor({ x: 7, y: 8 }),
+ new LockedDoor({ x: 7, y: 9 }),
+ new Curry({ x: 7, y: 10 }),
+ new Wall({ x: 6, y: 9 }),
+ new Wall({ x: 8, y: 9 }),
+ new Wall({ x: 6, y: 10 }),
+ new Wall({ x: 8, y: 10 }),
+ new Wall({ x: 7, y: 11 }),
];
entities.forEach((entity) => game.addEntity(entity));
diff --git a/src/engine/utils/CodeEditor.ts b/src/engine/utils/CodeEditor.ts
index e91455a..144cc29 100644
--- a/src/engine/utils/CodeEditor.ts
+++ b/src/engine/utils/CodeEditor.ts
@@ -54,7 +54,7 @@ export class CodeEditorInstance {
initCode: string,
codeConsumer: CodeEditorState["codeConsumer"],
readonly: boolean = false,
- initResult: { data?: string; error?: string } = {},
+ initResult: { data?: string; error?: string } = {}
) {
if (this.codeEditorState) {
throw new Error("code editor instance is already owned.");
@@ -163,7 +163,9 @@ export class CodeEditorInstance {
}
private setResult(result: { data?: string; error?: string }) {
- if (!this.codeEditorState) return;
+ if (!this.codeEditorState) {
+ return;
+ }
this.codeEditorState.resultElement.innerText = result.data ?? "";
this.codeEditorState.errorElement.innerText = result.error ?? "";
}