Skip to content

Commit

Permalink
Merge pull request #108 from devshareacademy/GH-86-saving-and-loading
Browse files Browse the repository at this point in the history
[GH-86] handling saving and loading
  • Loading branch information
scottwestover authored Jan 23, 2024
2 parents a01940f + dd75c31 commit 9d06947
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/scenes/world-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ export class WorldScene extends Phaser.Scene {
}

const wasSpaceKeyPressed = this.#controls.wasSpaceKeyPressed();
const selectedDirectionHelDown = this.#controls.getDirectionKeyPressedDown();
const selectedDirectionHeldDown = this.#controls.getDirectionKeyPressedDown();
const selectedDirectionPressedOnce = this.#controls.getDirectionKeyJustPressed();
if (selectedDirectionHelDown !== DIRECTION.NONE && !this.#isPlayerInputLocked()) {
this.#player.moveCharacter(selectedDirectionHelDown);
if (selectedDirectionHeldDown !== DIRECTION.NONE && !this.#isPlayerInputLocked()) {
this.#player.moveCharacter(selectedDirectionHeldDown);
}

if (wasSpaceKeyPressed && !this.#player.isMoving && !this.#menu.isVisible) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Controls {

/** @returns {boolean} */
wasEnterKeyPressed() {
if (this.#cursorKeys === undefined) {
if (this.#enterKey === undefined) {
return false;
}
return Phaser.Input.Keyboard.JustDown(this.#enterKey);
Expand Down
12 changes: 10 additions & 2 deletions src/world/menu/menu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Phaser from '../../lib/phaser.js';
import { UI_ASSET_KEYS } from '../../assets/asset-keys.js';
import { KENNEY_FUTURE_NARROW_FONT_NAME } from '../../assets/font-keys.js';
import { DIRECTION } from '../../common/direction.js';
import Phaser from '../../lib/phaser.js';
import { DATA_MANAGER_STORE_KEYS, dataManager } from '../../utils/data-manager.js';
import { exhaustiveGuard } from '../../utils/guard.js';
import { MENU_COLOR } from './menu-config.js';
Expand Down Expand Up @@ -96,6 +96,9 @@ export class Menu {
return this.#selectedMenuOption;
}

/**
* @returns {void}
*/
show() {
const { right, top } = this.#scene.cameras.main.worldView;
const startX = right - this.#padding * 2 - this.#width;
Expand All @@ -106,6 +109,9 @@ export class Menu {
this.#isVisible = true;
}

/**
* @returns {void}
*/
hide() {
this.#container.setAlpha(0);
this.#selectedMenuOptionIndex = 0;
Expand All @@ -132,6 +138,9 @@ export class Menu {
this.#moveMenuCursor(input);
}

/**
* @returns {Phaser.GameObjects.Graphics}
*/
#createGraphics() {
const g = this.#scene.add.graphics();
const menuColor = this.#getMenuColorsFromDataManager();
Expand Down Expand Up @@ -171,7 +180,6 @@ export class Menu {
default:
exhaustiveGuard(direction);
}

const x = 20 + this.#padding;
const y = 28 + this.#padding + this.#selectedMenuOptionIndex * 50;

Expand Down

0 comments on commit 9d06947

Please sign in to comment.