Skip to content
Draft
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
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion scene-generator/helpers/getMainNPCCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand All @@ -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;
25 changes: 18 additions & 7 deletions src/js/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/node/getSceneCreate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/node/helpers/getMainNPCCode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand Down