From 35f522fd9944e896d47500e884a8796a6930ee93 Mon Sep 17 00:00:00 2001 From: EmberCM Date: Wed, 28 Aug 2024 19:17:18 -0500 Subject: [PATCH 1/5] Fix text disappearing while in transferMode (#3740) Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> --- src/ui/party-ui-handler.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 66c777944d1..e7c4069c16e 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -5,7 +5,7 @@ import { Command } from "./command-ui-handler"; import MessageUiHandler from "./message-ui-handler"; import { Mode } from "./ui"; import * as Utils from "../utils"; -import { PokemonBaseStatModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier, SwitchEffectTransferModifier } from "../modifier/modifier"; +import { PokemonFormChangeItemModifier, PokemonHeldItemModifier, SwitchEffectTransferModifier } from "../modifier/modifier"; import { allMoves, ForceSwitchOutAttr } from "../data/move"; import { getGenderColor, getGenderSymbol } from "../data/gender"; import { StatusEffect } from "../data/status-effect"; @@ -989,14 +989,8 @@ export default class PartyUiHandler extends MessageUiHandler { optionText.setOrigin(0, 0); /** For every item that has stack bigger than 1, display the current quantity selection */ - if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && this.transferQuantitiesMax[option] > 1) { - const itemModifier = itemModifiers[option]; - - /** Not sure why getMaxHeldItemCount had an error, but it only checks the Pokemon parameter if the modifier is PokemonBaseStatModifier */ - if (itemModifier === undefined || itemModifier instanceof PokemonBaseStatModifier) { - continue; - } - + const itemModifier = itemModifiers[option]; + if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && this.transferQuantitiesMax[option] > 1 && !this.transferMode && itemModifier !== undefined && itemModifier.type.name === optionName) { let amountText = ` (${this.transferQuantities[option]})`; /** If the amount held is the maximum, display the count in red */ From 781e25848d2fc5822d43c26a77c2b3d7b1509d39 Mon Sep 17 00:00:00 2001 From: Mumble <171087428+frutescens@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:44:26 -0700 Subject: [PATCH 2/5] fixed infinite loop (#3887) Co-authored-by: frutescens --- src/system/game-data.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/system/game-data.ts b/src/system/game-data.ts index e7bc85d9037..d10d6288696 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -635,13 +635,13 @@ export class GameData { async saveRunHistory(scene: BattleScene, runEntry : SessionSaveData, isVictory: boolean): Promise { const runHistoryData = await this.getRunHistoryData(scene); // runHistoryData should always return run history or {} empty object - const timestamps = Object.keys(runHistoryData); - const timestampsNo = timestamps.map(Number); + let timestamps = Object.keys(runHistoryData).map(Number); // Arbitrary limit of 25 entries per user --> Can increase or decrease while (timestamps.length >= RUN_HISTORY_LIMIT ) { - const oldestTimestamp = Math.min.apply(Math, timestampsNo); + const oldestTimestamp = (Math.min.apply(Math, timestamps)).toString(); delete runHistoryData[oldestTimestamp]; + timestamps = Object.keys(runHistoryData).map(Number); } const timestamp = (runEntry.timestamp).toString(); From 8f2699e6ead79e3bfd1e09c96f37d27125776442 Mon Sep 17 00:00:00 2001 From: Blitzy <118096277+Blitz425@users.noreply.github.com> Date: Thu, 29 Aug 2024 02:38:21 -0400 Subject: [PATCH 3/5] [Enhancement] Update Team Skull Sprites (#3886) * Update Team Skull Sprites * Add files via upload * Update skull_grunt_f.json * Update skull_grunt_m.json * Fix eol --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- public/images/trainer/guzma.png | Bin 848 -> 2312 bytes public/images/trainer/skull_grunt_f.json | 22 +++++++++++----------- public/images/trainer/skull_grunt_f.png | Bin 792 -> 905 bytes public/images/trainer/skull_grunt_m.json | 22 +++++++++++----------- public/images/trainer/skull_grunt_m.png | Bin 723 -> 966 bytes 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/public/images/trainer/guzma.png b/public/images/trainer/guzma.png index 97dadfbe6fddff6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y7NdV;@@J25fgX%fpzkz6gLwhk{6W}O_7}b<^Pzr;{>oWO% za@^aVGygJ?r%kt|AZY9OwK$J^bI|h~NHLIi*wcQq2JLW{U|-cmUxOd%64L7xe*uL~ z?RtO6N{=J)z(7L0A2(Ts)5;MLF0wiAAXHI^Gck@=yCf^f7zm{Ox=*$%#U>l}Aib-* zIXwiHo@29?%-Q-eL0)XuGOk#7K-d&1lp?s z=awEKz4XI+a_<9=NSiae+lI`2z2A<#*gO-A`g0o%dz+3-kzX{XFG@?cqpFjw0w&vy Br?~(C delta 666 zcmV;L0%iTi2h#;(iBL{Q4GJ0x0000DNk~Le0000(0000(2m=5B0Pqw@K>z>%Hc(7d zMF0Q*0000B2n7uc4GxmS6%`dNEGaoSHcm}RY-wbBN?NrvBfWcL$c}B!&d%PYd;ih3 z|Ns9Ndk|)kZzO*L97#k$R9M5U*wJ?EAP5D}P*M#vqw@bhdjXwxUUR&zKJ+Df9SLfj zU^L743r;zCr^Y{wAkV~liALwa}P?&CZ~F+=+u z1X&D)o#u#21@a<|E+;5ZOtwK9HTQfn-wIP!G|Jc{U}Ji(s&_3c*gK; z#Met8ucv>A#<`Gd#;%xz0u@m|r;5}xco~li;$2z-v6==M(5od{U1B>7!w+!-TD5pV z;`6}~3gbf79oLri@TaLlo4XrrZp(J5K{0$MTZAX*!w}+_Yc7e`z;?rfbA+R#gXcEa z>d!l) Date: Thu, 29 Aug 2024 03:57:22 -0500 Subject: [PATCH 4/5] [Sprite] Update Rose Sprite (#3890) --- public/images/trainer/rose.png | Bin 864 -> 1088 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/public/images/trainer/rose.png b/public/images/trainer/rose.png index a79a754e21b995ef415a2a1e2aa4d3e84a3f9ff4..f90da7568d4d58279b1186035a2f1ad429bdc440 100644 GIT binary patch delta 1067 zcmV+`1l0TB2EYiAB!2;OQb$4nuFf3k00004XF*Lt006O%3;baP0000sP)t-sCnhF8 zJUm!aQ@w~@pl3wdsC|G+F{Yx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TY5gu9VHXQr_O?_WJgvTdP_C0004WQchCmUpU zU~Di;o51_O?XexQ%~Wa!e54{xJ6B(SLs)`yFB@#l88z(9Mg;KMR5S?3lvXPuSa1Nn zS_=?8Y#4vRd=Cnj56ziRT~>f)L}6eCmyY%Eeng z8I2?0$6yFS4w3QjdcLR+%MtL?qgHr6pFyU+mdhWSZ_|4!0in^le#A8adA4@1=i9vw zLMtnOtwe8k6^X~|9SO+g#%uqb-3HKBY9u@J8<3N=mVlRcK8)&mcX^&K!vGwPPY&<$ z@rj4qLW#J)H_xNLdIv~y>MC!y+O!b=$>{ZRS6uxIPj}__hX#PIsh2koWodz*9+&X} z=#CdF_Vif4>iPc2cL_)W(&saTH^_ZB;^`fKi;E^CH|k;jwO0M8he^QPV!Oi^pj>@8FHgrroZ^^*6@y0lc^n-y#nd{NlnM6bzGBCbw%Rqf7To=09C& z{{s?+BZi(Hq}>1j01jnXNoGw=04e|g00;m8000000Mb*F00000NkvXXu0mjfl+}ZK From 59ff4e9941cf4e1f262d279bddd87c52b58631b0 Mon Sep 17 00:00:00 2001 From: Opaque02 <66582645+Opaque02@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:22:01 +1000 Subject: [PATCH 5/5] Admin panel beta (#3846) * feat: Add hasAdminRole property to UserInfo interface and update initLoggedInUser and updateUserInfo functions This commit adds the hasAdminRole property to the UserInfo interface in the account.ts file. The initLoggedInUser function is updated to set the hasAdminRole property to false by default. The updateUserInfo function is also updated to set the hasAdminRole property to false when bypassLogin is true. This change allows for better management of user roles and permissions. Co-authored-by: frutescens Co-authored-by: Frederico Santos * Updated UI for admin panel and menu * Remove random blank line from merge * Fix imports in `src/ui/ui.ts` --------- Co-authored-by: Frederico Santos Co-authored-by: frutescens Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/account.ts | 5 +- src/ui/admin-ui-handler.ts | 85 +++++++++++++++++++++++++++++++++ src/ui/form-modal-ui-handler.ts | 4 +- src/ui/menu-ui-handler.ts | 32 ++++++++++--- src/ui/ui.ts | 8 +++- 5 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 src/ui/admin-ui-handler.ts diff --git a/src/account.ts b/src/account.ts index 6682e3e0b7c..c6d2f85489a 100644 --- a/src/account.ts +++ b/src/account.ts @@ -6,6 +6,7 @@ export interface UserInfo { lastSessionSlot: integer; discordId: string; googleId: string; + hasAdminRole: boolean; } export let loggedInUser: UserInfo | null = null; @@ -13,13 +14,13 @@ export let loggedInUser: UserInfo | null = null; export const clientSessionId = Utils.randomString(32); export function initLoggedInUser(): void { - loggedInUser = { username: "Guest", lastSessionSlot: -1, discordId: "", googleId: ""}; + loggedInUser = { username: "Guest", lastSessionSlot: -1, discordId: "", googleId: "", hasAdminRole: false }; } export function updateUserInfo(): Promise<[boolean, integer]> { return new Promise<[boolean, integer]>(resolve => { if (bypassLogin) { - loggedInUser = { username: "Guest", lastSessionSlot: -1, discordId: "", googleId: "" }; + loggedInUser = { username: "Guest", lastSessionSlot: -1, discordId: "", googleId: "", hasAdminRole: false}; let lastSessionSlot = -1; for (let s = 0; s < 5; s++) { if (localStorage.getItem(`sessionData${s ? s : ""}_${loggedInUser.username}`)) { diff --git a/src/ui/admin-ui-handler.ts b/src/ui/admin-ui-handler.ts new file mode 100644 index 00000000000..371604c00a2 --- /dev/null +++ b/src/ui/admin-ui-handler.ts @@ -0,0 +1,85 @@ +import BattleScene from "#app/battle-scene.js"; +import { ModalConfig } from "./modal-ui-handler"; +import { Mode } from "./ui"; +import * as Utils from "../utils"; +import { FormModalUiHandler } from "./form-modal-ui-handler"; +import { Button } from "#app/enums/buttons.js"; + +export default class AdminUiHandler extends FormModalUiHandler { + + constructor(scene: BattleScene, mode: Mode | null = null) { + super(scene, mode); + } + + setup(): void { + super.setup(); + } + + getModalTitle(config?: ModalConfig): string { + return "Admin panel"; + } + + getFields(config?: ModalConfig): string[] { + return ["Username", "Discord ID"]; + } + + getWidth(config?: ModalConfig): number { + return 160; + } + + getMargin(config?: ModalConfig): [number, number, number, number] { + return [0, 0, 48, 0]; + } + + getButtonLabels(config?: ModalConfig): string[] { + return ["Link account", "Cancel"]; + } + + processInput(button: Button): boolean { + if (button === Button.SUBMIT && this.submitAction) { + this.submitAction(); + return true; + } + + return false; + } + + show(args: any[]): boolean { + if (super.show(args)) { + const config = args[0] as ModalConfig; + const originalSubmitAction = this.submitAction; + this.submitAction = (_) => { + this.submitAction = originalSubmitAction; + this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); + const onFail = error => { + this.scene.ui.setMode(Mode.ADMIN, Object.assign(config, { errorMessage: error?.trim() })); + this.scene.ui.playError(); + }; + if (!this.inputs[0].text) { + return onFail("Username is required"); + } + if (!this.inputs[1].text) { + return onFail("Discord Id is required"); + } + Utils.apiPost("admin/account/discord-link", `username=${encodeURIComponent(this.inputs[0].text)}&discordId=${encodeURIComponent(this.inputs[1].text)}`, "application/x-www-form-urlencoded", true) + .then(response => { + if (!response.ok) { + return response.text(); + } + return response.json(); + }) + .then(response => { + this.scene.ui.setMode(Mode.ADMIN, config); + }); + return false; + }; + return true; + } + return false; + + } + + clear(): void { + super.clear(); + } +} diff --git a/src/ui/form-modal-ui-handler.ts b/src/ui/form-modal-ui-handler.ts index 4516e39675c..8c4ea5f6768 100644 --- a/src/ui/form-modal-ui-handler.ts +++ b/src/ui/form-modal-ui-handler.ts @@ -6,7 +6,7 @@ import { WindowVariant, addWindow } from "./ui-theme"; import InputText from "phaser3-rex-plugins/plugins/inputtext"; import * as Utils from "../utils"; import i18next from "i18next"; -import {Button} from "#enums/buttons"; +import { Button } from "#enums/buttons"; export interface FormModalConfig extends ModalConfig { errorMessage?: string; @@ -60,7 +60,7 @@ export abstract class FormModalUiHandler extends ModalUiHandler { const inputBg = addWindow(this.scene, 0, 0, 80, 16, false, false, 0, 0, WindowVariant.XTHIN); const isPassword = field.includes(i18next.t("menu:password")) || field.includes(i18next.t("menu:confirmPassword")); - const input = addTextInputObject(this.scene, 4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 16 }); + const input = addTextInputObject(this.scene, 4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 18 }); input.setOrigin(0, 0); inputContainer.add(inputBg); diff --git a/src/ui/menu-ui-handler.ts b/src/ui/menu-ui-handler.ts index 6fdf98d14a3..0bbfe21e4f9 100644 --- a/src/ui/menu-ui-handler.ts +++ b/src/ui/menu-ui-handler.ts @@ -306,16 +306,34 @@ export default class MenuUiHandler extends MessageUiHandler { return true; }, keepOpen: true - }, - { - label: i18next.t("menuUiHandler:cancel"), + }]; + if (!bypassLogin && loggedInUser?.hasAdminRole) { + communityOptions.push({ + label: "Admin", handler: () => { - this.scene.ui.revertMode(); + ui.playSelect(); + ui.setOverlayMode(Mode.ADMIN, { + buttonActions: [ + () => { + ui.revertMode(); + }, + () => { + ui.revertMode(); + } + ] + }); return true; - } + }, + keepOpen: true + }); + } + communityOptions.push({ + label: i18next.t("menuUiHandler:cancel"), + handler: () => { + this.scene.ui.revertMode(); + return true; } - ]; - + }); this.communityConfig = { xOffset: 98, options: communityOptions diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 250a21544dc..5e1c28eda2d 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -23,7 +23,7 @@ import OptionSelectUiHandler from "./settings/option-select-ui-handler"; import EggHatchSceneHandler from "./egg-hatch-scene-handler"; import EggListUiHandler from "./egg-list-ui-handler"; import EggGachaUiHandler from "./egg-gacha-ui-handler"; -import {addWindow} from "./ui-theme"; +import { addWindow } from "./ui-theme"; import LoginFormUiHandler from "./login-form-ui-handler"; import RegistrationFormUiHandler from "./registration-form-ui-handler"; import LoadingModalUiHandler from "./loading-modal-ui-handler"; @@ -46,6 +46,7 @@ import SettingsAudioUiHandler from "./settings/settings-audio-ui-handler"; import { PlayerGender } from "#enums/player-gender"; import BgmBar from "#app/ui/bgm-bar"; import RenameFormUiHandler from "./rename-form-ui-handler"; +import AdminUiHandler from "./admin-ui-handler"; import RunHistoryUiHandler from "./run-history-ui-handler"; import RunInfoUiHandler from "./run-info-ui-handler"; @@ -86,6 +87,7 @@ export enum Mode { OUTDATED, CHALLENGE_SELECT, RENAME_POKEMON, + ADMIN, RUN_HISTORY, RUN_INFO, } @@ -124,7 +126,8 @@ const noTransitionModes = [ Mode.SESSION_RELOAD, Mode.UNAVAILABLE, Mode.OUTDATED, - Mode.RENAME_POKEMON + Mode.RENAME_POKEMON, + Mode.ADMIN, ]; export default class UI extends Phaser.GameObjects.Container { @@ -188,6 +191,7 @@ export default class UI extends Phaser.GameObjects.Container { new RenameFormUiHandler(scene), new RunHistoryUiHandler(scene), new RunInfoUiHandler(scene), + new AdminUiHandler(scene), ]; }