summaryrefslogtreecommitdiff
path: root/src/engine/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/entities')
-rw-r--r--src/engine/entities/FunctionApplication.ts33
-rw-r--r--src/engine/entities/FunctionBox.ts16
-rw-r--r--src/engine/entities/LambdaFactory.ts18
-rw-r--r--src/engine/entities/Sign.ts16
4 files changed, 43 insertions, 40 deletions
diff --git a/src/engine/entities/FunctionApplication.ts b/src/engine/entities/FunctionApplication.ts
index ac07f88..4d5729f 100644
--- a/src/engine/entities/FunctionApplication.ts
+++ b/src/engine/entities/FunctionApplication.ts
@@ -30,7 +30,10 @@ import {
interpret,
} from "../../interpreter";
-const APPLICATION_RESULTS: Record<string, (gridPosition: Coord2D) => null | Entity> = {
+const APPLICATION_RESULTS: Record<
+ string,
+ (gridPosition: Coord2D) => null | Entity
+> = {
_KEY: (gridPosition: Coord2D) => new Key(gridPosition),
_EMPTY: (_gridPosition: Coord2D) => null,
};
@@ -59,8 +62,8 @@ export class FunctionApplication extends Entity {
y: 0,
},
dimension,
- 0
- )
+ 0,
+ ),
);
this.addComponent(new Grid(gridPosition));
@@ -73,14 +76,14 @@ export class FunctionApplication extends Entity {
{ x: 0, y: 0 },
dimension,
FunctionApplication.spriteSpec.msPerFrame,
- FunctionApplication.spriteSpec.frames
- )
+ FunctionApplication.spriteSpec.frames,
+ ),
);
this.addComponent(new Colliding(this.handleCollision.bind(this)));
this.addComponent(
- new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this))
+ new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this)),
);
}
@@ -94,7 +97,7 @@ export class FunctionApplication extends Entity {
return { consumed: true };
};
const { last, code } = this.getComponent<LambdaTerm>(
- ComponentNames.LambdaTerm
+ ComponentNames.LambdaTerm,
);
this.addComponent(
new Modal({
@@ -108,7 +111,7 @@ export class FunctionApplication extends Entity {
data: last?.data && `Last Result: ${emitNamed(last.data)}`,
},
},
- })
+ }),
);
}
@@ -132,7 +135,7 @@ export class FunctionApplication extends Entity {
const gridSystem = game.getSystem<GridSystem>(SystemNames.Grid);
const fail = () => {
entityGrid.movingDirection = gridSystem.oppositeDirection(
- entityGrid.previousDirection
+ entityGrid.previousDirection,
);
entity.addComponent(entityGrid);
@@ -141,10 +144,10 @@ export class FunctionApplication extends Entity {
};
const applicationTerm = this.getComponent<LambdaTerm>(
- ComponentNames.LambdaTerm
+ ComponentNames.LambdaTerm,
);
const functionTerm = entity.getComponent<LambdaTerm>(
- ComponentNames.LambdaTerm
+ ComponentNames.LambdaTerm,
);
const newCode = applicationTerm.code.replace("_INPUT", functionTerm.code);
@@ -158,7 +161,7 @@ export class FunctionApplication extends Entity {
const nextPosition = gridSystem.getNewGridPosition(
grid.gridPosition,
- entityGrid.previousDirection
+ entityGrid.previousDirection,
);
let applicationResultingEntity: Entity | null = null; // this should be its own function
@@ -167,7 +170,7 @@ export class FunctionApplication extends Entity {
// if we get an application that means we didn't interpret correctly.
// this should "not" happen and should be fatal.
throw new InvalidLambdaTermError(
- "produced term should not be an application"
+ "produced term should not be an application",
);
}
if ("abstraction" in data) {
@@ -178,7 +181,7 @@ export class FunctionApplication extends Entity {
const { name } = data;
const entityFactory = APPLICATION_RESULTS[name];
if (entityFactory) {
- const entity = entityFactory(nextPosition)
+ const entity = entityFactory(nextPosition);
entity && game.addEntity(entity);
}
}
@@ -186,7 +189,7 @@ export class FunctionApplication extends Entity {
game.removeEntity(entity.id);
if (applicationResultingEntity) {
const grid = applicationResultingEntity.getComponent<Grid>(
- ComponentNames.Grid
+ ComponentNames.Grid,
);
grid.movingDirection = entityGrid.previousDirection;
applicationResultingEntity.addComponent(grid);
diff --git a/src/engine/entities/FunctionBox.ts b/src/engine/entities/FunctionBox.ts
index 9cba029..7493c8a 100644
--- a/src/engine/entities/FunctionBox.ts
+++ b/src/engine/entities/FunctionBox.ts
@@ -15,12 +15,12 @@ import { Coord2D } from "../interfaces";
export class FunctionBox extends Entity {
private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
- Sprites.FUNCTION_BOX
+ Sprites.FUNCTION_BOX,
) as SpriteSpec;
constructor(
gridPosition: Coord2D,
- private readonly code: string
+ private readonly code: string,
) {
super(EntityNames.FunctionBox);
@@ -34,8 +34,8 @@ export class FunctionBox extends Entity {
width: FunctionBox.spriteSpec.width,
height: FunctionBox.spriteSpec.height,
},
- 0
- )
+ 0,
+ ),
);
this.addComponent(new Pushable());
@@ -51,14 +51,14 @@ export class FunctionBox extends Entity {
height: FunctionBox.spriteSpec.height,
},
FunctionBox.spriteSpec.msPerFrame,
- FunctionBox.spriteSpec.frames
- )
+ FunctionBox.spriteSpec.frames,
+ ),
);
this.addComponent(new LambdaTerm(code));
this.addComponent(
- new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this))
+ new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this)),
);
}
@@ -79,7 +79,7 @@ export class FunctionBox extends Entity {
error: last?.error && `Error: ${last.error.message}`,
},
},
- })
+ }),
);
}
diff --git a/src/engine/entities/LambdaFactory.ts b/src/engine/entities/LambdaFactory.ts
index 61a3b0a..ca91298 100644
--- a/src/engine/entities/LambdaFactory.ts
+++ b/src/engine/entities/LambdaFactory.ts
@@ -26,7 +26,7 @@ import { parse } from "../../interpreter";
export class LambdaFactory extends Entity {
private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
- Sprites.LAMBDA_FACTORY
+ Sprites.LAMBDA_FACTORY,
) as SpriteSpec;
private spawns: number;
@@ -48,8 +48,8 @@ export class LambdaFactory extends Entity {
width: LambdaFactory.spriteSpec.width,
height: LambdaFactory.spriteSpec.height,
},
- 0
- )
+ 0,
+ ),
);
this.addComponent(new Text(spawns.toString()));
@@ -59,8 +59,8 @@ export class LambdaFactory extends Entity {
this.addComponent(
new GridSpawn(
this.spawns,
- () => new FunctionBox({ x: 0, y: 0 }, this.code)
- )
+ () => new FunctionBox({ x: 0, y: 0 }, this.code),
+ ),
);
this.addComponent(new Grid(gridPosition));
@@ -74,12 +74,12 @@ export class LambdaFactory extends Entity {
height: LambdaFactory.spriteSpec.height,
},
LambdaFactory.spriteSpec.msPerFrame,
- LambdaFactory.spriteSpec.frames
- )
+ LambdaFactory.spriteSpec.frames,
+ ),
);
this.addComponent(
- new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this))
+ new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this)),
);
}
@@ -113,7 +113,7 @@ export class LambdaFactory extends Entity {
code: this.code,
codeConsumer: this.codeConsumer.bind(this),
},
- })
+ }),
);
}
diff --git a/src/engine/entities/Sign.ts b/src/engine/entities/Sign.ts
index c85ad40..b5bbfd4 100644
--- a/src/engine/entities/Sign.ts
+++ b/src/engine/entities/Sign.ts
@@ -14,12 +14,12 @@ import { Coord2D } from "../interfaces";
export class Sign extends Entity {
private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
- Sprites.SIGN
+ Sprites.SIGN,
) as SpriteSpec;
constructor(
private readonly text: string,
- gridPosition: Coord2D
+ gridPosition: Coord2D,
) {
super(EntityNames.Sign);
@@ -34,8 +34,8 @@ export class Sign extends Entity {
{ x: 0, y: 0 },
dimension,
Sign.spriteSpec.msPerFrame,
- Sign.spriteSpec.frames
- )
+ Sign.spriteSpec.frames,
+ ),
);
this.addComponent(
@@ -45,8 +45,8 @@ export class Sign extends Entity {
y: 0,
},
dimension,
- 0
- )
+ 0,
+ ),
);
this.addComponent(new Grid(gridPosition));
@@ -54,7 +54,7 @@ export class Sign extends Entity {
this.addComponent(new Colliding());
this.addComponent(
- new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this))
+ new Highlight(this.onHighlight.bind(this), this.onUnhighlight.bind(this)),
);
}
@@ -78,7 +78,7 @@ export class Sign extends Entity {
contentInit: {
content: `<p>${this.text}</p>`,
},
- })
+ }),
);
}
}