From d8511f4ad3bc3a326de7f7af2fb8703d5f471e36 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 2 Mar 2025 16:32:01 -0700 Subject: run prettier --- src/App.tsx | 6 +++++- src/components/GameCanvas.tsx | 4 +++- src/components/Title.tsx | 4 ++-- src/css/style.css | 3 ++- src/engine/components/Colliding.ts | 13 ------------ src/engine/components/ComponentNames.ts | 2 +- src/engine/components/Modal.ts | 4 +--- src/engine/components/RadialObserve.ts | 14 +++++++++++++ src/engine/entities/FunctionApplication.ts | 33 ++++++++++++++++-------------- src/engine/entities/FunctionBox.ts | 16 +++++++-------- src/engine/entities/LambdaFactory.ts | 18 ++++++++-------- src/engine/entities/Sign.ts | 16 +++++++-------- src/engine/levels/CarCadr.ts | 2 +- src/engine/levels/LevelSelection.ts | 6 +++--- src/engine/systems/Modal.ts | 2 +- src/engine/systems/index.ts | 2 +- src/engine/utils/CodeEditor.ts | 6 +++--- src/engine/utils/Modal.ts | 2 +- src/engine/utils/index.ts | 4 ++-- src/interpreter/interpreter.ts | 20 +++++++++--------- 20 files changed, 93 insertions(+), 84 deletions(-) delete mode 100644 src/engine/components/Colliding.ts create mode 100644 src/engine/components/RadialObserve.ts diff --git a/src/App.tsx b/src/App.tsx index 89b7cbc..342b0dd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,7 +21,11 @@ export const App = () => {
built by{" "} - + simponic {" "} | inspired by{" "} diff --git a/src/components/GameCanvas.tsx b/src/components/GameCanvas.tsx index 98ba506..7d9e88f 100644 --- a/src/components/GameCanvas.tsx +++ b/src/components/GameCanvas.tsx @@ -13,7 +13,9 @@ export const GameCanvas = ({ width, height }: GameCanvasProps) => { const [game, setGame] = useState(); // 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(() => { diff --git a/src/components/Title.tsx b/src/components/Title.tsx index 4bdc298..31e8140 100644 --- a/src/components/Title.tsx +++ b/src/components/Title.tsx @@ -18,8 +18,8 @@ export const Title = ({ setReady }: TitleProps) => {


- 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.


diff --git a/src/css/style.css b/src/css/style.css index b9a00bb..6cd0761 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -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); diff --git a/src/engine/components/Colliding.ts b/src/engine/components/Colliding.ts deleted file mode 100644 index fe782df..0000000 --- a/src/engine/components/Colliding.ts +++ /dev/null @@ -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; - } -} diff --git a/src/engine/components/ComponentNames.ts b/src/engine/components/ComponentNames.ts index 241fe3f..fdf1a18 100644 --- a/src/engine/components/ComponentNames.ts +++ b/src/engine/components/ComponentNames.ts @@ -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"; diff --git a/src/engine/components/Modal.ts b/src/engine/components/Modal.ts index 9b4031f..64b2703 100644 --- a/src/engine/components/Modal.ts +++ b/src/engine/components/Modal.ts @@ -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); } } diff --git a/src/engine/components/RadialObserve.ts b/src/engine/components/RadialObserve.ts new file mode 100644 index 0000000..60962c2 --- /dev/null +++ b/src/engine/components/RadialObserve.ts @@ -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; + } +} 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 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( - 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(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( - ComponentNames.LambdaTerm + ComponentNames.LambdaTerm, ); const functionTerm = entity.getComponent( - 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( - 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: `

${this.text}

`, }, - }) + }), ); } } diff --git a/src/engine/levels/CarCadr.ts b/src/engine/levels/CarCadr.ts index 07c6f11..8875623 100644 --- a/src/engine/levels/CarCadr.ts +++ b/src/engine/levels/CarCadr.ts @@ -75,4 +75,4 @@ export class CarCadr extends Level { entities.forEach((entity) => game.addEntity(entity)); } -} \ No newline at end of file +} diff --git a/src/engine/levels/LevelSelection.ts b/src/engine/levels/LevelSelection.ts index 9e46274..d1a486b 100644 --- a/src/engine/levels/LevelSelection.ts +++ b/src/engine/levels/LevelSelection.ts @@ -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), ), }); }) diff --git a/src/engine/systems/Modal.ts b/src/engine/systems/Modal.ts index 7643a73..5d22a26 100644 --- a/src/engine/systems/Modal.ts +++ b/src/engine/systems/Modal.ts @@ -43,7 +43,7 @@ export class Modal extends System { game.forEachEntityWithComponent(ComponentNames.Modal, (entity) => { const modalComponent = entity.getComponent( - ComponentNames.Modal + ComponentNames.Modal, ); if (this.openingEntity) { return; diff --git a/src/engine/systems/index.ts b/src/engine/systems/index.ts index 75b548d..16ff911 100644 --- a/src/engine/systems/index.ts +++ b/src/engine/systems/index.ts @@ -9,4 +9,4 @@ export * from "./Collision"; export * from "./Life"; export * from "./Music"; export * from "./Level"; -export * from "./Modal"; \ No newline at end of file +export * from "./Modal"; diff --git a/src/engine/utils/CodeEditor.ts b/src/engine/utils/CodeEditor.ts index 144cc29..ecc80bc 100644 --- a/src/engine/utils/CodeEditor.ts +++ b/src/engine/utils/CodeEditor.ts @@ -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()); diff --git a/src/engine/utils/Modal.ts b/src/engine/utils/Modal.ts index d46cade..761c29f 100644 --- a/src/engine/utils/Modal.ts +++ b/src/engine/utils/Modal.ts @@ -42,4 +42,4 @@ export class ModalInstance { } } -export const ModalSingleton = new ModalInstance(); \ No newline at end of file +export const ModalSingleton = new ModalInstance(); diff --git a/src/engine/utils/index.ts b/src/engine/utils/index.ts index ffeef7a..9293baa 100644 --- a/src/engine/utils/index.ts +++ b/src/engine/utils/index.ts @@ -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"; \ No newline at end of file +export * from "./CodeEditor"; diff --git a/src/interpreter/interpreter.ts b/src/interpreter/interpreter.ts index 65a848f..c79a2cf 100644 --- a/src/interpreter/interpreter.ts +++ b/src/interpreter/interpreter.ts @@ -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, )})`; } -- cgit v1.2.3-70-g09d2