summaryrefslogtreecommitdiff
path: root/src/engine/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/systems')
-rw-r--r--src/engine/systems/Grid.ts10
-rw-r--r--src/engine/systems/LambdaFactory.ts34
-rw-r--r--src/engine/systems/Render.ts17
-rw-r--r--src/engine/systems/SystemNames.ts1
-rw-r--r--src/engine/systems/index.ts1
5 files changed, 57 insertions, 6 deletions
diff --git a/src/engine/systems/Grid.ts b/src/engine/systems/Grid.ts
index 28ca5ea..8756320 100644
--- a/src/engine/systems/Grid.ts
+++ b/src/engine/systems/Grid.ts
@@ -39,7 +39,7 @@ export class Grid extends System {
}
private highlightEntitiesLookedAt(game: Game) {
- const highlightableEntities = new Set<string>();
+ const highlightableEntities: [string, Direction][] = [];
game.forEachEntityWithComponent(
ComponentNames.FacingDirection,
@@ -64,23 +64,23 @@ export class Grid extends System {
}
this.grid[lookingAt.y][lookingAt.x].forEach((id) => {
- highlightableEntities.add(id);
+ highlightableEntities.push([id, facingDirection.currentDirection]);
});
},
);
- highlightableEntities.forEach((id) => {
+ highlightableEntities.forEach(([id, direction]) => {
const entity = game.getEntity(id)!;
if (entity.hasComponent(ComponentNames.Highlight)) {
const highlight = entity.getComponent<Highlight>(
ComponentNames.Highlight,
)!;
- highlight.highlight();
+ highlight.highlight(direction);
}
});
game.forEachEntityWithComponent(ComponentNames.Highlight, (entity) => {
- if (!highlightableEntities.has(entity.id)) {
+ if (!highlightableEntities.find(([id]) => id === entity.id)) {
const highlight = entity.getComponent<Highlight>(
ComponentNames.Highlight,
)!;
diff --git a/src/engine/systems/LambdaFactory.ts b/src/engine/systems/LambdaFactory.ts
new file mode 100644
index 0000000..1263eae
--- /dev/null
+++ b/src/engine/systems/LambdaFactory.ts
@@ -0,0 +1,34 @@
+import { System, SystemNames } from ".";
+import { Game } from "..";
+import { ComponentNames, Grid, LambdaSpawn } from "../components";
+import { FunctionBox } from "../entities";
+
+export class LambdaFactory extends System {
+ constructor() {
+ super(SystemNames.LambdaFactory);
+ }
+
+ public update(_dt: number, game: Game) {
+ game.forEachEntityWithComponent(ComponentNames.LambdaSpawn, (entity) => {
+ const lambdaSpawn = entity.getComponent<LambdaSpawn>(
+ ComponentNames.LambdaSpawn,
+ )!;
+ const hasGrid = entity.hasComponent(SystemNames.Grid);
+
+ if (!lambdaSpawn.direction || !hasGrid) {
+ return;
+ }
+
+ const grid = entity.getComponent<Grid>(SystemNames.Grid)!;
+
+ const lambda = new FunctionBox(grid.gridPosition, lambdaSpawn.code);
+ const lambdaGrid = lambda.getComponent<Grid>(SystemNames.Grid)!;
+ lambdaGrid.movingDirection = lambdaSpawn.direction;
+ lambda.addComponent(lambdaGrid);
+ game.addEntity(lambda);
+
+ lambdaSpawn.direction = null;
+ entity.addComponent(lambdaSpawn);
+ });
+ }
+}
diff --git a/src/engine/systems/Render.ts b/src/engine/systems/Render.ts
index 83daa52..f273deb 100644
--- a/src/engine/systems/Render.ts
+++ b/src/engine/systems/Render.ts
@@ -1,5 +1,11 @@
import { System, SystemNames } from ".";
-import { BoundingBox, ComponentNames, Highlight, Sprite } from "../components";
+import {
+ BoundingBox,
+ Text,
+ ComponentNames,
+ Highlight,
+ Sprite,
+} from "../components";
import { Game } from "..";
import { clamp } from "../utils";
import { DrawArgs } from "../interfaces";
@@ -50,6 +56,15 @@ export class Render extends System {
);
drawArgs.tint = highlight.isHighlighted ? "red" : undefined;
}
+ if (entity.hasComponent(ComponentNames.Text)) {
+ const text = entity.getComponent<Text>(ComponentNames.Text);
+ drawArgs.backgroundText = {
+ text: text.text,
+ font: text.font,
+ fillStyle: text.fillStyle,
+ textAlign: text.textAlign,
+ };
+ }
sprite.draw(this.ctx, drawArgs);
});
diff --git a/src/engine/systems/SystemNames.ts b/src/engine/systems/SystemNames.ts
index 0de5857..85d1539 100644
--- a/src/engine/systems/SystemNames.ts
+++ b/src/engine/systems/SystemNames.ts
@@ -3,4 +3,5 @@ export namespace SystemNames {
export const Input = "Input";
export const FacingDirection = "FacingDirection";
export const Grid = "Grid";
+ export const LambdaFactory = "LambdaFactory";
}
diff --git a/src/engine/systems/index.ts b/src/engine/systems/index.ts
index 18ffa2e..4490ee2 100644
--- a/src/engine/systems/index.ts
+++ b/src/engine/systems/index.ts
@@ -4,3 +4,4 @@ export * from "./Render";
export * from "./Input";
export * from "./FacingDirection";
export * from "./Grid";
+export * from "./LambdaFactory";