From 559dce794ec58564a3291bb783ffa1bee958b2e9 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Tue, 27 May 2025 15:16:22 -0500 Subject: [PATCH] Make setPositionRelative return this --- src/main.ts | 2 +- src/typings/phaser/index.d.ts | 12 +++++----- src/ui/battle-info/battle-info.ts | 22 ++++++++++--------- src/ui/battle-info/enemy-battle-info.ts | 18 ++++++++++----- .../mocks/mocksContainer/mockContainer.ts | 3 ++- .../mocks/mocksContainer/mockGraphics.ts | 3 ++- .../mocks/mocksContainer/mockRectangle.ts | 3 ++- .../mocks/mocksContainer/mockSprite.ts | 4 ++-- .../mocks/mocksContainer/mockText.ts | 3 ++- test/testUtils/testFileInitialization.ts | 4 ++-- 10 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7db663d14c7..38bfcbe5636 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,7 +29,7 @@ window.addEventListener("unhandledrejection", event => { const setPositionRelative = function (guideObject: Phaser.GameObjects.GameObject, x: number, y: number) { const offsetX = guideObject.width * (-0.5 + (0.5 - guideObject.originX)); const offsetY = guideObject.height * (-0.5 + (0.5 - guideObject.originY)); - this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y); + return this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y); }; Phaser.GameObjects.Container.prototype.setPositionRelative = setPositionRelative; diff --git a/src/typings/phaser/index.d.ts b/src/typings/phaser/index.d.ts index ef67c107ca5..26fbcff75bd 100644 --- a/src/typings/phaser/index.d.ts +++ b/src/typings/phaser/index.d.ts @@ -20,37 +20,37 @@ declare module "phaser" { /** * Sets this object's position relative to another object with a given offset */ - setPositionRelative(guideObject: any, x: number, y: number): self; + setPositionRelative(guideObject: any, x: number, y: number): this; } interface Sprite { /** * Sets this object's position relative to another object with a given offset */ - setPositionRelative(guideObject: any, x: number, y: number): self; + setPositionRelative(guideObject: any, x: number, y: number): this; } interface Image { /** * Sets this object's position relative to another object with a given offset */ - setPositionRelative(guideObject: any, x: number, y: number): self; + setPositionRelative(guideObject: any, x: number, y: number): this; } interface NineSlice { /** * Sets this object's position relative to another object with a given offset */ - setPositionRelative(guideObject: any, x: number, y: number): self; + setPositionRelative(guideObject: any, x: number, y: number): this; } interface Text { /** * Sets this object's position relative to another object with a given offset */ - setPositionRelative(guideObject: any, x: number, y: number): self; + setPositionRelative(guideObject: any, x: number, y: number): this; } interface Rectangle { /** * Sets this object's position relative to another object with a given offset */ - setPositionRelative(guideObject: any, x: number, y: number): self; + setPositionRelative(guideObject: any, x: number, y: number): this; } } diff --git a/src/ui/battle-info/battle-info.ts b/src/ui/battle-info/battle-info.ts index 1c6f4494e3e..3758021f83c 100644 --- a/src/ui/battle-info/battle-info.ts +++ b/src/ui/battle-info/battle-info.ts @@ -98,8 +98,8 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { .setVisible(false) .setOrigin(0) .setScale(0.5) - .setInteractive(hitArea, hitCallback); - this.teraIcon.setPositionRelative(this.nameText, 0, 2); + .setInteractive(hitArea, hitCallback) + .setPositionRelative(this.nameText, 0, 2); this.shinyIcon = globalScene.add .sprite(0, 0, "shiny_star") @@ -107,8 +107,8 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { .setVisible(false) .setOrigin(0) .setScale(0.5) - .setInteractive(hitArea, hitCallback); - this.shinyIcon.setPositionRelative(this.nameText, 0, 2); + .setInteractive(hitArea, hitCallback) + .setPositionRelative(this.nameText, 0, 2); this.fusionShinyIcon = globalScene.add .sprite(0, 0, "shiny_star_2") @@ -124,8 +124,8 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { .setVisible(false) .setOrigin(0) .setScale(0.5) - .setInteractive(hitArea, hitCallback); - this.splicedIcon.setPositionRelative(this.nameText, 0, 2); + .setInteractive(hitArea, hitCallback) + .setPositionRelative(this.nameText, 0, 2); this.add([this.teraIcon, this.shinyIcon, this.fusionShinyIcon, this.splicedIcon]); } @@ -235,8 +235,10 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { .setOrigin(0); this.add(this.nameText); - this.genderText = addTextObject(0, 0, "", TextStyle.BATTLE_INFO).setName("text_gender").setOrigin(0); - this.genderText.setPositionRelative(this.nameText, 0, 2); + this.genderText = addTextObject(0, 0, "", TextStyle.BATTLE_INFO) + .setName("text_gender") + .setOrigin(0) + .setPositionRelative(this.nameText, 0, 2); this.add(this.genderText); this.constructIcons(); @@ -245,8 +247,8 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { .sprite(0, 0, getLocalizedSpriteKey("statuses")) .setName("icon_status") .setVisible(false) - .setOrigin(0); - this.statusIndicator.setPositionRelative(this.nameText, 0, 11.5); + .setOrigin(0) + .setPositionRelative(this.nameText, 0, 11.5); this.add(this.statusIndicator); this.levelContainer = globalScene.add diff --git a/src/ui/battle-info/enemy-battle-info.ts b/src/ui/battle-info/enemy-battle-info.ts index 314143b50d4..e8f5434dcf2 100644 --- a/src/ui/battle-info/enemy-battle-info.ts +++ b/src/ui/battle-info/enemy-battle-info.ts @@ -56,15 +56,19 @@ export class EnemyBattleInfo extends BattleInfo { super(140, -141, false, posParams); - this.ownedIcon = globalScene.add.sprite(0, 0, "icon_owned").setName("icon_owned").setVisible(false).setOrigin(0, 0); - this.ownedIcon.setPositionRelative(this.nameText, 0, 11.75); + this.ownedIcon = globalScene.add + .sprite(0, 0, "icon_owned") + .setName("icon_owned") + .setVisible(false) + .setOrigin(0, 0) + .setPositionRelative(this.nameText, 0, 11.75); this.championRibbon = globalScene.add .sprite(0, 0, "champion_ribbon") .setName("icon_champion_ribbon") .setVisible(false) - .setOrigin(0, 0); - this.championRibbon.setPositionRelative(this.nameText, 8, 11.75); + .setOrigin(0, 0) + .setPositionRelative(this.nameText, 8, 11.75); // Ensure these two icons are positioned below the stats container this.addAt([this.ownedIcon, this.championRibbon], this.getIndex(this.statsContainer)); @@ -73,8 +77,10 @@ export class EnemyBattleInfo extends BattleInfo { this.moveBelow(this.flyoutMenu, this.box); - this.effectivenessContainer = globalScene.add.container(0, 0).setVisible(false); - this.effectivenessContainer.setPositionRelative(this.type1Icon, 22, 4); + this.effectivenessContainer = globalScene.add + .container(0, 0) + .setVisible(false) + .setPositionRelative(this.type1Icon, 22, 4); this.add(this.effectivenessContainer); this.effectivenessText = addTextObject(5, 4.5, "", TextStyle.BATTLE_INFO); diff --git a/test/testUtils/mocks/mocksContainer/mockContainer.ts b/test/testUtils/mocks/mocksContainer/mockContainer.ts index b335305fcbd..e116e7d151a 100644 --- a/test/testUtils/mocks/mocksContainer/mockContainer.ts +++ b/test/testUtils/mocks/mocksContainer/mockContainer.ts @@ -58,8 +58,9 @@ export default class MockContainer implements MockGameObject { return this; } - setPositionRelative(_source, _x, _y) { + setPositionRelative(_source, _x, _y): this { /// Sets the position of this Game Object to be a relative position from the source Game Object. + return this; } setInteractive(): this { diff --git a/test/testUtils/mocks/mocksContainer/mockGraphics.ts b/test/testUtils/mocks/mocksContainer/mockGraphics.ts index 82fef774836..1650d2f9f60 100644 --- a/test/testUtils/mocks/mocksContainer/mockGraphics.ts +++ b/test/testUtils/mocks/mocksContainer/mockGraphics.ts @@ -57,8 +57,9 @@ export default class MockGraphics implements MockGameObject { // This callback is invoked when this Game Object is added to a Scene. } - setPositionRelative(_source, _x, _y) { + setPositionRelative(_source, _x, _y): this { /// Sets the position of this Game Object to be a relative position from the source Game Object. + return this; } destroy() { diff --git a/test/testUtils/mocks/mocksContainer/mockRectangle.ts b/test/testUtils/mocks/mocksContainer/mockRectangle.ts index 56a89e7b872..f9a92c41904 100644 --- a/test/testUtils/mocks/mocksContainer/mockRectangle.ts +++ b/test/testUtils/mocks/mocksContainer/mockRectangle.ts @@ -38,8 +38,9 @@ export default class MockRectangle implements MockGameObject { // This callback is invoked when this Game Object is added to a Scene. } - setPositionRelative(_source, _x, _y) { + setPositionRelative(_source, _x, _y): this { /// Sets the position of this Game Object to be a relative position from the source Game Object. + return this; } destroy() { diff --git a/test/testUtils/mocks/mocksContainer/mockSprite.ts b/test/testUtils/mocks/mocksContainer/mockSprite.ts index b45fa218c47..5afd211c682 100644 --- a/test/testUtils/mocks/mocksContainer/mockSprite.ts +++ b/test/testUtils/mocks/mocksContainer/mockSprite.ts @@ -140,9 +140,9 @@ export default class MockSprite implements MockGameObject { return this; } - setPositionRelative(source, x, y) { + setPositionRelative(source, x, y): this { /// Sets the position of this Game Object to be a relative position from the source Game Object. - this.phaserSprite.setPositionRelative(source, x, y); + return this.phaserSprite.setPositionRelative(source, x, y); } setY(y: number): this { diff --git a/test/testUtils/mocks/mocksContainer/mockText.ts b/test/testUtils/mocks/mocksContainer/mockText.ts index 9b8e7ec1bbe..dc648616fe6 100644 --- a/test/testUtils/mocks/mocksContainer/mockText.ts +++ b/test/testUtils/mocks/mocksContainer/mockText.ts @@ -197,9 +197,10 @@ export default class MockText implements MockGameObject { return this; } - setPositionRelative(_source, _x, _y) { + setPositionRelative(_source, _x, _y): this { /// Sets the position of this Game Object to be a relative position from the source Game Object. // return this.phaserText.setPositionRelative(source, x, y); + return this; } setShadowOffset(_offsetX, _offsetY): this { diff --git a/test/testUtils/testFileInitialization.ts b/test/testUtils/testFileInitialization.ts index 15635289e6f..ba90cba7d5b 100644 --- a/test/testUtils/testFileInitialization.ts +++ b/test/testUtils/testFileInitialization.ts @@ -70,10 +70,10 @@ export function initTestFile() { * @param x The relative x position * @param y The relative y position */ - const setPositionRelative = function (guideObject: any, x: number, y: number) { + const setPositionRelative = function (guideObject: any, x: number, y: number): any { const offsetX = guideObject.width * (-0.5 + (0.5 - guideObject.originX)); const offsetY = guideObject.height * (-0.5 + (0.5 - guideObject.originY)); - this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y); + return this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y); }; Phaser.GameObjects.Container.prototype.setPositionRelative = setPositionRelative;