Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #34

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
"extensions": [
"esbenp.prettier-vscode",
"kavod-io.vscode-jest-test-adapter"
]
],
"settings": {
"window.menuBarVisibility": "classic",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true,
"typescript.surveys.enabled": false
}
}
}
}
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:

- name: Test
run: |
npx prettier --check src
npm run jest

- name: Build documentation
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Alan & Ada kids programming

Play the [game](https://wimyedema.github.io/alan-and-ada/) and
Play the [game](https://wimyedema.github.io/alan-and-ada/), read the [docs](https://wimyedema.github.io/alan-and-ada/docs/) and
start [editing](https://vscode.dev/github/WimYedema/alan-and-ada)!



## Running locally

- Using [nodejs](https://nodejs.org/en/) and [npm](https://www.npmjs.com/)
Expand Down
2 changes: 1 addition & 1 deletion src/actors/docs.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Player, PlayerState} from "./player";
export { Player, PlayerState } from "./player";
2 changes: 1 addition & 1 deletion src/core/cutScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface iSceneNode {
thisScene: string;

/**
* The name of the next scene, the scene the player will go to after passing
* The name of the next scene, the scene the player will go to after passing
* the exit gate.
*/
nextScene: string;
Expand Down
10 changes: 8 additions & 2 deletions src/core/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ export { loader } from "./resources";
export { Stats, stats } from "./stats";
export { iSceneNode } from "./cutScene";
export { iArtifact } from "./iartifact";
export { iLocation, iBox, iFloor} from "./location";
export { Actor, ActorState, ActorWithState, SceneActor, GameActor} from "./actor";
export { iLocation, iBox, iFloor } from "./location";
export {
Actor,
ActorState,
ActorWithState,
SceneActor,
GameActor,
} from "./actor";
export { LevelLayout } from "./levelLayout";
16 changes: 8 additions & 8 deletions src/core/levelLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Floor, Wall } from "../actors/ground";
*
* The sub-classes only need to implement {@link layoutLevel} to create the actors
* and artifacts of the level.
*
*
* @noInheritDoc
*/
export abstract class LevelLayout extends ex.Scene implements iSceneNode {
Expand Down Expand Up @@ -43,10 +43,10 @@ export abstract class LevelLayout extends ex.Scene implements iSceneNode {
}
/**
* @experimental
*
* Initialize the camera for this level. Defaults to an elastic focus on the
*
* Initialize the camera for this level. Defaults to an elastic focus on the
* player.
*
*
* @param player The player actor
*/
initCamera(player: ex.Actor) {
Expand Down Expand Up @@ -105,20 +105,20 @@ export abstract class LevelLayout extends ex.Scene implements iSceneNode {
0,
0,
this.levelSize.x * tileSize,
this.levelSize.y * tileSize
)
this.levelSize.y * tileSize,
),
);
engine.add(new Floor({ x: -1, y: -1, right: this.levelSize.x + 2 }));
engine.add(
new Floor({
x: -1,
y: this.levelSize.y,
right: this.levelSize.x + 2,
})
}),
);
engine.add(new Wall({ x: -1, y: 0, down: this.levelSize.y }));
engine.add(
new Wall({ x: this.levelSize.x, y: 0, down: this.levelSize.y })
new Wall({ x: this.levelSize.x, y: 0, down: this.levelSize.y }),
);
}
}
Expand Down
31 changes: 15 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ addNode(new Level3());
addNode(new Finish());
addNode(new GameOver());

const st = JSON.parse(window.localStorage.getItem("stats")||"{}");
const st = JSON.parse(window.localStorage.getItem("stats") || "{}");
stats.load(st);
engine.goToScene(stats.currentNode);
let showDebug = false;
Expand All @@ -64,15 +64,15 @@ engine.on("preupdate", () => {
showDebug = !showDebug;
engine.showDebug(showDebug);
} else if (showDebug) {
if(engine.input.keyboard.wasPressed(ex.Input.Keys.KeyN)) {
if (engine.input.keyboard.wasPressed(ex.Input.Keys.KeyN)) {
stats.nextScene = true;
} else if(engine.input.keyboard.wasPressed(ex.Input.Keys.KeyR)) {
} else if (engine.input.keyboard.wasPressed(ex.Input.Keys.KeyR)) {
stats.currentNode = "playerSelect";
engine.goToScene(nodes[stats.currentNode].thisScene);
window.localStorage.setItem("stats", JSON.stringify(stats));
}
}

if (stats.nextScene) {
console.log("switching from ", stats.currentNode);
stats.currentNode = nodes[stats.currentNode].nextScene;
Expand All @@ -89,21 +89,20 @@ engine.on("gameover", () => {
console.log("Game over reset");
stats.reset();
});
// Detect hidden and visible outside of excalibur: it blocks events when the
// engine is stopped so we cannot detect when to resume.
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
console.log("Window hidden");
engine.stop();
} else if (document.visibilityState === "visible") {
console.log("Window visible");
engine.start();
}
});

// Start the engine
engine.start(loader).then(() => {
console.log("game start");
// Detect hidden and visible outside of excalibur: it blocks events when the
// engine is stopped so we cannot detect when to resume.
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
console.log("Window hidden");
engine.stop();
} else if (document.visibilityState === "visible") {
console.log("Window visible");
engine.start();
}
});
});

// For test hook
Expand Down
6 changes: 1 addition & 5 deletions src/scenes/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ export { Example } from "./example";
export { GameOver } from "./gameover";
export { PlayerSelect } from "./playerSelect";
export { Level1 } from "./level1";
export {
BeforeLevel1,
BeforeLevel2,
BeforeLevel3,
} from "./beforeScenes";
export { BeforeLevel1, BeforeLevel2, BeforeLevel3 } from "./beforeScenes";
export { Level2 } from "./level2";
export { Finish } from "./finish";
export { Level3 } from "./level3";