summaryrefslogtreecommitdiff
path: root/src/engine/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/components')
-rw-r--r--src/engine/components/ComponentNames.ts3
-rw-r--r--src/engine/components/GridSpawn.ts30
-rw-r--r--src/engine/components/LambdaSpawn.ts29
-rw-r--r--src/engine/components/LambdaTerm.ts11
-rw-r--r--src/engine/components/index.ts3
5 files changed, 45 insertions, 31 deletions
diff --git a/src/engine/components/ComponentNames.ts b/src/engine/components/ComponentNames.ts
index 1f41d18..a9f0c15 100644
--- a/src/engine/components/ComponentNames.ts
+++ b/src/engine/components/ComponentNames.ts
@@ -8,6 +8,7 @@ export namespace ComponentNames {
export const Interactable = "Interactable";
export const Pushable = "Pushable";
export const Colliding = "Colliding";
- export const LambdaSpawn = "LambdaSpawn";
+ export const GridSpawn = "GridSpawn";
export const Text = "Text";
+ export const LambdaTerm = "LambdaTerm";
}
diff --git a/src/engine/components/GridSpawn.ts b/src/engine/components/GridSpawn.ts
new file mode 100644
index 0000000..d2ec898
--- /dev/null
+++ b/src/engine/components/GridSpawn.ts
@@ -0,0 +1,30 @@
+import { Component, ComponentNames } from ".";
+import { Entity } from "../entities";
+import { Direction } from "../interfaces";
+
+export class GridSpawn extends Component {
+ public direction: Direction;
+ public spawnsLeft: number;
+ public spawner: () => Entity;
+
+ constructor(
+ spawnsLeft: number,
+ spawner: () => Entity,
+ direction = Direction.NONE,
+ ) {
+ super(ComponentNames.GridSpawn);
+
+ this.spawnsLeft = spawnsLeft;
+ this.direction = direction;
+ this.spawner = spawner;
+ }
+
+ public spawnEntity(direction: Direction): Entity | undefined {
+ if (this.spawnsLeft === 0) {
+ return;
+ }
+
+ this.direction = direction;
+ this.spawnsLeft -= 1;
+ }
+}
diff --git a/src/engine/components/LambdaSpawn.ts b/src/engine/components/LambdaSpawn.ts
deleted file mode 100644
index c45092a..0000000
--- a/src/engine/components/LambdaSpawn.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { Component, ComponentNames } from ".";
-import { Direction } from "../interfaces";
-
-export class LambdaSpawn extends Component {
- public direction: Direction | null;
- public spawnsLeft: number;
- public code: string = "";
-
- constructor(
- spawnsLeft: number,
- code: string,
- direction: Direction | null = null,
- ) {
- super(ComponentNames.LambdaSpawn);
-
- this.spawnsLeft = spawnsLeft;
- this.direction = direction;
- this.code = code;
- }
-
- public spawn(direction: Direction) {
- if (this.spawnsLeft <= 0) {
- return;
- }
-
- this.direction = direction;
- this.spawnsLeft -= 1;
- }
-}
diff --git a/src/engine/components/LambdaTerm.ts b/src/engine/components/LambdaTerm.ts
new file mode 100644
index 0000000..63e9889
--- /dev/null
+++ b/src/engine/components/LambdaTerm.ts
@@ -0,0 +1,11 @@
+import { Component, ComponentNames } from ".";
+
+export class LambdaTerm extends Component {
+ public code: string;
+
+ constructor(code: string) {
+ super(ComponentNames.LambdaTerm);
+
+ this.code = code;
+ }
+}
diff --git a/src/engine/components/index.ts b/src/engine/components/index.ts
index 104ba2d..a7a3cf1 100644
--- a/src/engine/components/index.ts
+++ b/src/engine/components/index.ts
@@ -9,5 +9,6 @@ export * from "./Highlight";
export * from "./Interactable";
export * from "./Pushable";
export * from "./Colliding";
-export * from "./LambdaSpawn";
+export * from "./GridSpawn";
export * from "./Text";
+export * from "./LambdaTerm";