mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-17 13:52:18 +02:00
prevent spamming of requests
This commit is contained in:
parent
8ccd8085db
commit
4438c13f02
@ -31,12 +31,24 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container {
|
|||||||
private page: integer;
|
private page: integer;
|
||||||
private category: ScoreboardCategory;
|
private category: ScoreboardCategory;
|
||||||
|
|
||||||
|
private _isUpdating: boolean;
|
||||||
|
|
||||||
constructor(scene: BattleScene, x: number, y: number) {
|
constructor(scene: BattleScene, x: number, y: number) {
|
||||||
super(scene, x, y);
|
super(scene, x, y);
|
||||||
|
|
||||||
|
this._isUpdating = false;
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set isUpdating(value) {
|
||||||
|
this._isUpdating = value;
|
||||||
|
this.setButtonsState(!value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isUpdating() {
|
||||||
|
return this._isUpdating;
|
||||||
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
const titleWindow = addWindow(this.scene, 0, 0, 114, 18, false, false, null, null, WindowVariant.THIN);
|
const titleWindow = addWindow(this.scene, 0, 0, 114, 18, false, false, null, null, WindowVariant.THIN);
|
||||||
this.add(titleWindow);
|
this.add(titleWindow);
|
||||||
@ -141,6 +153,11 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(category: ScoreboardCategory = this.category, page: integer = this.page) {
|
update(category: ScoreboardCategory = this.category, page: integer = this.page) {
|
||||||
|
if (this.isUpdating) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isUpdating = true;
|
||||||
this.rankingsContainer.removeAll(true);
|
this.rankingsContainer.removeAll(true);
|
||||||
|
|
||||||
this.loadingLabel.setText(i18next.t('menu:loading'));
|
this.loadingLabel.setText(i18next.t('menu:loading'));
|
||||||
@ -158,16 +175,36 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container {
|
|||||||
this.page = page;
|
this.page = page;
|
||||||
this.category = category;
|
this.category = category;
|
||||||
this.titleLabel.setText(`${i18next.t(`menu:${ScoreboardCategory[category].toLowerCase()}Rankings`)}`);
|
this.titleLabel.setText(`${i18next.t(`menu:${ScoreboardCategory[category].toLowerCase()}Rankings`)}`);
|
||||||
this.prevPageButton.setAlpha(page > 1 ? 1 : 0.5);
|
|
||||||
this.nextPageButton.setAlpha(page < this.pageCount ? 1 : 0.5);
|
|
||||||
this.pageNumberLabel.setText(page.toString());
|
this.pageNumberLabel.setText(page.toString());
|
||||||
if (jsonResponse) {
|
if (jsonResponse) {
|
||||||
this.loadingLabel.setVisible(false);
|
this.loadingLabel.setVisible(false);
|
||||||
this.updateRankings(jsonResponse);
|
this.updateRankings(jsonResponse);
|
||||||
} else
|
} else
|
||||||
this.loadingLabel.setText(i18next.t('menu:noRankings'));
|
this.loadingLabel.setText(i18next.t('menu:noRankings'));
|
||||||
|
}).finally(() => {
|
||||||
|
this.isUpdating = false;
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("Failed to load daily rankings:\n", err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setButtonsState(enabled: boolean = true) {
|
||||||
|
const buttons = [
|
||||||
|
{ button: this.prevPageButton, alphaValue: enabled ? (this.page > 1 ? 1 : 0.5) : 0.5 },
|
||||||
|
{ button: this.nextPageButton, alphaValue: enabled ? (this.page < this.pageCount ? 1 : 0.5) : 0.5 },
|
||||||
|
{ button: this.nextCategoryButton, alphaValue: enabled ? 1 : 0.5 },
|
||||||
|
{ button: this.prevCategoryButton, alphaValue: enabled ? 1 : 0.5 }
|
||||||
|
];
|
||||||
|
|
||||||
|
buttons.forEach(({ button, alphaValue }) => {
|
||||||
|
if (enabled) {
|
||||||
|
button.setInteractive();
|
||||||
|
} else {
|
||||||
|
button.disableInteractive();
|
||||||
|
}
|
||||||
|
button.setAlpha(alphaValue);
|
||||||
});
|
});
|
||||||
}).catch(err => { console.error("Failed to load daily rankings:\n", err) });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user