run prettier

This commit is contained in:
Elizabeth Hunt 2025-03-02 16:32:01 -07:00
parent 16eb0ad4d5
commit d8511f4ad3
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
20 changed files with 93 additions and 84 deletions

View File

@ -21,7 +21,11 @@ export const App = () => {
<div className="footer">
<span>
built by{" "}
<a href="https://git.simponic.xyz/simponic" target="_blank" className="tf">
<a
href="https://git.simponic.xyz/simponic"
target="_blank"
className="tf"
>
simponic
</a>{" "}
| inspired by{" "}

View File

@ -13,7 +13,9 @@ export const GameCanvas = ({ width, height }: GameCanvasProps) => {
const [game, setGame] = useState<TheAbstractionEngine>();
// TODO: go back to this after done
// const [ready, setReady] = useState(false);
const [ready, setReady] = useState(document.location.hostname.includes("localhost"));
const [ready, setReady] = useState(
document.location.hostname.includes("localhost"),
);
const [loading, setLoading] = useState(true);
useEffect(() => {

View File

@ -18,8 +18,8 @@ export const Title = ({ setReady }: TitleProps) => {
</p>
<br />
<h3 className="warning">
WASD/arrow keys to move. SPACE/ENTER to interact after highlighting
with the mouse.
WASD/arrow keys to move. SPACE/ENTER to interact after highlighting with
the mouse.
</h3>
<br />

View File

@ -20,7 +20,8 @@ body {
margin: 0;
width: 100%;
height: 100%;
background: radial-gradient(ellipse at top, var(--bg), transparent),
background:
radial-gradient(ellipse at top, var(--bg), transparent),
radial-gradient(ellipse at left, var(--blue), transparent),
radial-gradient(ellipse at right, var(--purple), transparent),
radial-gradient(ellipse at bottom, var(--bg), transparent);

View File

@ -1,13 +0,0 @@
import { Component, ComponentNames } from ".";
import { Game } from "..";
import { Entity } from "../entities";
export class Colliding extends Component {
public onCollision?: (game: Game, entity: Entity) => void;
constructor(onCollision?: (game: Game, entity: Entity) => void) {
super(ComponentNames.Colliding);
this.onCollision = onCollision;
}
}

View File

@ -7,7 +7,7 @@ export namespace ComponentNames {
export const Highlight = "Highlight";
export const Interactable = "Interactable";
export const Pushable = "Pushable";
export const Colliding = "Colliding";
export const RadialObserve = "RadialObserve";
export const GridSpawn = "GridSpawn";
export const Text = "Text";
export const LambdaTerm = "LambdaTerm";

View File

@ -2,9 +2,7 @@ import { Component, ComponentNames } from ".";
import { ModalInitState } from "../systems";
export class Modal extends Component {
constructor(
public initState: ModalInitState
) {
constructor(public initState: ModalInitState) {
super(ComponentNames.Modal);
}
}

View File

@ -0,0 +1,14 @@
import { Component, ComponentNames } from ".";
import { Game } from "..";
import { Entity } from "../entities";
export class RadialObserve extends Component {
constructor(
public onObservation?: (game: Game, entity: Entity) => void,
public radius: number = 0,
) {
super(ComponentNames.RadialObserve);
this.onObservation = onObservation;
}
}

View File

@ -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);

View File

@ -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}`,
},
},
})
}),
);
}

View File

@ -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),
},
})
}),
);
}

View File

@ -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>`,
},
})
}),
);
}
}

View File

@ -75,4 +75,4 @@ export class CarCadr extends Level {
entities.forEach((entity) => game.addEntity(entity));
}
}
}

View File

@ -20,7 +20,7 @@ export class LevelSelection extends Level {
const unlocked = levelSystem.getUnlockedLevels();
const renderableLevels = LEVELS.filter(
({ name }) => name !== LevelNames.LevelSelection
({ name }) => name !== LevelNames.LevelSelection,
);
const radiansPerLevel = (2 * Math.PI) / renderableLevels.length;
renderableLevels
@ -44,10 +44,10 @@ export class LevelSelection extends Level {
// random grass
return new Grass({
x: Math.floor(
normalRandom(dimensions.width / 2, dimensions.width / 4, 1.5)
normalRandom(dimensions.width / 2, dimensions.width / 4, 1.5),
),
y: Math.floor(
normalRandom(dimensions.height / 2, dimensions.height / 4, 1.5)
normalRandom(dimensions.height / 2, dimensions.height / 4, 1.5),
),
});
})

View File

@ -43,7 +43,7 @@ export class Modal extends System {
game.forEachEntityWithComponent(ComponentNames.Modal, (entity) => {
const modalComponent = entity.getComponent<ModalComponent>(
ComponentNames.Modal
ComponentNames.Modal,
);
if (this.openingEntity) {
return;

View File

@ -9,4 +9,4 @@ export * from "./Collision";
export * from "./Life";
export * from "./Music";
export * from "./Level";
export * from "./Modal";
export * from "./Modal";

View File

@ -36,7 +36,7 @@ interface CodeEditorState {
export class CodeEditorInstance {
constructor(
private modalInstance: ModalInstance = ModalSingleton,
private codeEditorState: CodeEditorState | null = null
private codeEditorState: CodeEditorState | null = null,
) {}
public close() {
@ -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.");
@ -87,7 +87,7 @@ export class CodeEditorInstance {
const resultElement = document.getElementById("result")!;
const closeButton = document.getElementById(
"close-modal"
"close-modal",
) as HTMLButtonElement;
closeButton.addEventListener("click", () => this.onSave());

View File

@ -42,4 +42,4 @@ export class ModalInstance {
}
}
export const ModalSingleton = new ModalInstance();
export const ModalSingleton = new ModalInstance();

View File

@ -3,6 +3,6 @@ export * from "./dotProduct";
export * from "./rotateVector";
export * from "./colors";
export * from "./random";
export * from './tryWrap';
export * from "./tryWrap";
export * from "./Modal";
export * from "./CodeEditor";
export * from "./CodeEditor";

View File

@ -34,7 +34,7 @@ export type DebrujinifiedLambdaTerm =
export const debrujinify = (
term: LambdaTerm,
symbolTable: SymbolTable
symbolTable: SymbolTable,
): DebrujinifiedLambdaTerm => {
if (isVariable(term)) {
if (!symbolTable.has(term)) {
@ -67,14 +67,14 @@ export const debrujinify = (
}
throw new InvalidLambdaTermError(
`Invalid lambda term: ${JSON.stringify(term)}`
`Invalid lambda term: ${JSON.stringify(term)}`,
);
};
export const substitute = (
inTerm: DebrujinifiedLambdaTerm,
index: number,
withTerm: DebrujinifiedLambdaTerm
withTerm: DebrujinifiedLambdaTerm,
): DebrujinifiedLambdaTerm => {
if ("index" in inTerm) {
if (inTerm.index > index) {
@ -110,13 +110,13 @@ export const substitute = (
}
throw new InvalidLambdaTermError(
`Invalid lambda term: ${JSON.stringify(inTerm)}`
`Invalid lambda term: ${JSON.stringify(inTerm)}`,
);
};
export const adjustIndices = (
term: DebrujinifiedLambdaTerm,
delta: number
delta: number,
): DebrujinifiedLambdaTerm => {
if ("index" in term) {
return {
@ -148,7 +148,7 @@ export const adjustIndices = (
}
throw new InvalidLambdaTermError(
`Invalid lambda term: ${JSON.stringify(term)}`
`Invalid lambda term: ${JSON.stringify(term)}`,
);
};
@ -177,7 +177,7 @@ export const betaReduce = (
if ("application" in term) {
const { left } = term.application;
const args = term.application.args.map((term) =>
betaReduce(term, maxDepth - 1)
betaReduce(term, maxDepth - 1),
);
return args.reduce((acc: DebrujinifiedLambdaTerm, x) => {
@ -202,7 +202,7 @@ export const betaReduce = (
}
throw new InvalidLambdaTermError(
`Invalid lambda term: ${JSON.stringify(term)}`
`Invalid lambda term: ${JSON.stringify(term)}`,
);
};
@ -222,7 +222,7 @@ export const emitDebrujin = (term: DebrujinifiedLambdaTerm): string => {
}
throw new InvalidLambdaTermError(
`Invalid lambda term: ${JSON.stringify(term)}`
`Invalid lambda term: ${JSON.stringify(term)}`,
);
};
@ -233,7 +233,7 @@ export const emitNamed = (term: DebrujinifiedLambdaTerm): string => {
if ("abstraction" in term) {
return `(λ (${term.abstraction.param}) . ${emitNamed(
term.abstraction.body
term.abstraction.body,
)})`;
}