From e3cbc936868c4faf604258fa19fca72dbe4a4b92 Mon Sep 17 00:00:00 2001 From: Matthieu van den Biggelaar Date: Mon, 25 Sep 2023 15:43:01 +0200 Subject: [PATCH 1/3] feat: set mainNPC interactive and physical object --- scene-generator/helpers/getMainNPCCode.js | 6 +++++- tests/node/getSceneCreate.test.js | 2 ++ tests/node/helpers/getMainNPCCode.test.js | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scene-generator/helpers/getMainNPCCode.js b/scene-generator/helpers/getMainNPCCode.js index 36034d8..445d080 100644 --- a/scene-generator/helpers/getMainNPCCode.js +++ b/scene-generator/helpers/getMainNPCCode.js @@ -2,6 +2,8 @@ const getMainNPCDefaultDialogCode = require('./getMainNPCDefaultDialogCode.js'); const getMainNPCImagePositionCode = require('./getMainNPCImagePositionCode.js'); const getMainNPCDialogPositionCode = require('./getMainNPCDialogPositionCode.js'); const getMainNPCAnimationCode = require('./getMainNPCAnimationCode.js'); +const getHasPhysicsCode = require('./getHasPhysicsCode.js'); +const getSetInteractiveCode = require('./getSetInteractiveCode.js'); function getMainNPCCode(mainNPC) { if (!mainNPC) return ''; @@ -11,7 +13,9 @@ function getMainNPCCode(mainNPC) { ${getMainNPCImagePositionCode(mainNPC?.position)} ${getMainNPCDialogPositionCode(mainNPC)} ${getMainNPCAnimationCode(mainNPC?.animation)} - `; + ${getHasPhysicsCode('mainNPC?.mainNPCImage', true)} + ${getSetInteractiveCode('mainNPC?.mainNPCImage')} + `; } module.exports = getMainNPCCode; diff --git a/tests/node/getSceneCreate.test.js b/tests/node/getSceneCreate.test.js index 9078faa..435c090 100644 --- a/tests/node/getSceneCreate.test.js +++ b/tests/node/getSceneCreate.test.js @@ -98,6 +98,8 @@ describe('getSceneCreate function', () => { this.mainNPC?.create(); this.mainNPC?.mainNPCImage.setPosition(this.mainNPC?.initialPosition?.x, this.mainNPC?.initialPosition?.y); this.mainNPC?.moveTextPosition(this.mainNPC?.initialPosition?.x, this.mainNPC?.initialPosition?.y - this.mainNPC?.mainNPCImage?.height / 2); + this.physics.world.enable(this.mainNPC?.mainNPCImage); + this.mainNPC?.mainNPCImage.setInteractive(); `; const result = getSceneCreate(sceneName, sceneConfig); diff --git a/tests/node/helpers/getMainNPCCode.test.js b/tests/node/helpers/getMainNPCCode.test.js index b330c1b..4d7501b 100644 --- a/tests/node/helpers/getMainNPCCode.test.js +++ b/tests/node/helpers/getMainNPCCode.test.js @@ -47,6 +47,8 @@ describe('getMainNPCCode', () => { mockedImagePositionCode mockedDialogPositionCode mockedAnimationCode + this.physics.world.enable(this.mainNPC?.mainNPCImage); + this.mainNPC?.mainNPCImage.setInteractive(); `; expect(result.replace(/\s+/g, '')).toEqual( expectedCode.replace(/\s+/g, '') From a431e2d057ddf5f12c0c4590bd5c2ffd0890fb88 Mon Sep 17 00:00:00 2001 From: Matthieu van den Biggelaar Date: Mon, 25 Sep 2023 15:43:50 +0200 Subject: [PATCH 2/3] feat: make debugInfoContent always visible --- src/js/debug.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/js/debug.js b/src/js/debug.js index befbc18..ea2b45d 100644 --- a/src/js/debug.js +++ b/src/js/debug.js @@ -186,6 +186,14 @@ function setupWireframeMode(scene, gameObjects) { getDebugInfoStyle() ); + if (gameObject.debugInfoContent.y >= scene.game.config.height - gameObject.debugInfoContent.height) { + gameObject.debugInfoContent.y = gameObject.getBounds().y - gameObject.debugInfoContent.height - debugInfoContentPadding; + } + + if (gameObject.debugInfoContent.x >= scene.game.config.width - gameObject.debugInfoContent.width) { + gameObject.debugInfoContent.x = gameObject.getBounds().x - gameObject.debugInfoContent.width - debugInfoContentPadding; + } + gameObject.hoverBackground = scene.add.rectangle( gameObject.x, gameObject.y, @@ -227,16 +235,19 @@ function setupWireframeMode(scene, gameObjects) { if (gameObject.body) { gameObject.on('drag', () => { drawing = false; - gameObject.debugInfoContent.setPosition( - gameObject.getBounds().x, - gameObject.getBounds().y + - gameObject.height * gameObject.scale + - debugInfoContentPadding - ); - + let x = gameObject.getBounds().x; + let y = gameObject.getBounds().y + gameObject.height * gameObject.scale + debugInfoContentPadding; + x = (x >= scene.game.config.width - gameObject.debugInfoContent.width) ? gameObject.debugInfoContent.x = gameObject.getBounds().x - gameObject.debugInfoContent.width - debugInfoContentPadding : gameObject.getBounds().x; + y = (y >= scene.game.config.height - gameObject.debugInfoContent.height) ? gameObject.debugInfoContent.y = gameObject.getBounds().y - gameObject.debugInfoContent.height - debugInfoContentPadding : gameObject.getBounds().y + gameObject.height * gameObject.scale + debugInfoContentPadding; + gameObject.debugInfoContent.setPosition(x, y); gameObject.hoverBackground.setPosition(gameObject.x, gameObject.y); gameObject.wireframe.setPosition(gameObject.x, gameObject.y); gameObject.debugInfoContent.setText(getDebugInfoContent(gameObject)); + bringToFront( + gameObject.hoverBackground, + gameObject.wireframe, + gameObject.debugInfoContent + ); }); } } From 2c00cc117a9e11c0bfd3a38915f6da20b976e95c Mon Sep 17 00:00:00 2001 From: Matthieu van den Biggelaar Date: Wed, 27 Sep 2023 15:54:35 +0200 Subject: [PATCH 3/3] chore: completed MainNPC wireframe mode --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 4e4e4ed..c48f118 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,7 @@ * [x] Wireframe Mode for ActionableItems * [x] Physic Objects * [x] Hitbox Objects - * [] MainNPC + * [x] MainNPC * [x] Draw Mode * [ ] Moving sprites (ex: animate the MainNPC) * [ ] Sound Effects and Background Music