mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-21 09:02:47 +02:00
Convert egg gacha type into an object literal
This commit is contained in:
parent
f8d8a3de84
commit
792e3bb1bd
@ -1,5 +1,8 @@
|
||||
export enum GachaType {
|
||||
MOVE,
|
||||
LEGENDARY,
|
||||
SHINY
|
||||
}
|
||||
export const GachaType = {
|
||||
MOVE: 0,
|
||||
LEGENDARY: 1,
|
||||
SHINY: 2
|
||||
} as const;
|
||||
Object.freeze(GachaType);
|
||||
|
||||
export type GachaType = typeof GachaType[keyof typeof GachaType];
|
||||
|
@ -4,7 +4,7 @@ import CacheBustedLoaderPlugin from "#app/plugins/cache-busted-loader-plugin";
|
||||
import { SceneBase } from "#app/scene-base";
|
||||
import { WindowVariant, getWindowVariantSuffix } from "#app/ui/ui-theme";
|
||||
import { isMobile } from "#app/touch-controls";
|
||||
import { localPing, getEnumValues, hasAllLocalizedSprites, getEnumKeys } from "#app/utils/common";
|
||||
import { localPing, getEnumValues, hasAllLocalizedSprites } from "#app/utils/common";
|
||||
import { initPokemonPrevolutions, initPokemonStarters } from "#app/data/balance/pokemon-evolutions";
|
||||
import { initBiomes } from "#app/data/balance/biomes";
|
||||
import { initEggMoves } from "#app/data/balance/egg-moves";
|
||||
@ -270,7 +270,7 @@ export class LoadingScene extends SceneBase {
|
||||
this.loadAtlas("egg_icons", "egg");
|
||||
this.loadAtlas("egg_shard", "egg");
|
||||
this.loadAtlas("egg_lightrays", "egg");
|
||||
for (const gt of getEnumKeys(GachaType)) {
|
||||
for (const gt of Object.keys(GachaType)) {
|
||||
const key = gt.toLowerCase();
|
||||
this.loadImage(`gacha_${key}`, "egg");
|
||||
this.loadAtlas(`gacha_underlay_${key}`, "egg");
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { UiMode } from "#enums/ui-mode";
|
||||
import { TextStyle, addTextObject, getEggTierTextTint, getTextStyleOptions } from "./text";
|
||||
import MessageUiHandler from "./message-ui-handler";
|
||||
import { getEnumValues, getEnumKeys, fixedInt, randSeedShuffle } from "#app/utils/common";
|
||||
import { getEnumKeys, fixedInt, randSeedShuffle } from "#app/utils/common";
|
||||
import type { IEggOptions } from "../data/egg";
|
||||
import { Egg, getLegendaryGachaSpeciesForTimestamp } from "../data/egg";
|
||||
import { VoucherType, getVoucherTypeIcon } from "../system/voucher";
|
||||
@ -55,40 +55,9 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
this.defaultText = i18next.t("egg:selectMachine");
|
||||
}
|
||||
|
||||
setup() {
|
||||
this.gachaCursor = 0;
|
||||
this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale;
|
||||
|
||||
const ui = this.getUi();
|
||||
|
||||
this.eggGachaContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6);
|
||||
this.eggGachaContainer.setVisible(false);
|
||||
ui.add(this.eggGachaContainer);
|
||||
|
||||
const bg = globalScene.add.nineslice(0, 0, "default_bg", undefined, 320, 180, 0, 0, 16, 0);
|
||||
bg.setOrigin(0, 0);
|
||||
|
||||
this.eggGachaContainer.add(bg);
|
||||
|
||||
const hatchFrameNames = globalScene.anims.generateFrameNames("gacha_hatch", { suffix: ".png", start: 1, end: 4 });
|
||||
if (!globalScene.anims.exists("open")) {
|
||||
globalScene.anims.create({
|
||||
key: "open",
|
||||
frames: hatchFrameNames,
|
||||
frameRate: 12,
|
||||
});
|
||||
}
|
||||
if (!globalScene.anims.exists("close")) {
|
||||
globalScene.anims.create({
|
||||
key: "close",
|
||||
frames: hatchFrameNames.reverse(),
|
||||
frameRate: 12,
|
||||
});
|
||||
}
|
||||
|
||||
getEnumValues(GachaType).forEach((gachaType, g) => {
|
||||
const gachaTypeKey = GachaType[gachaType].toString().toLowerCase();
|
||||
const gachaContainer = globalScene.add.container(180 * g, 18);
|
||||
private setupGachaType(key: keyof typeof GachaType, gachaType: GachaType): void {
|
||||
const gachaTypeKey = key.toLowerCase();
|
||||
const gachaContainer = globalScene.add.container(180 * gachaType, 18);
|
||||
|
||||
const gacha = globalScene.add.sprite(0, 0, `gacha_${gachaTypeKey}`);
|
||||
gacha.setOrigin(0, 0);
|
||||
@ -131,62 +100,48 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
gachaInfoContainer.add(gachaUpLabel);
|
||||
|
||||
switch (gachaType as GachaType) {
|
||||
case GachaType.LEGENDARY: {
|
||||
case GachaType.LEGENDARY:
|
||||
{
|
||||
if (["de", "es-ES"].includes(currentLanguage)) {
|
||||
gachaUpLabel.setAlign("center");
|
||||
gachaUpLabel.setY(0);
|
||||
}
|
||||
if (["pt-BR"].includes(currentLanguage)) {
|
||||
gachaUpLabel.setX(legendaryLabelX - 2);
|
||||
} else {
|
||||
gachaUpLabel.setX(legendaryLabelX);
|
||||
}
|
||||
gachaUpLabel.setY(legendaryLabelY);
|
||||
|
||||
let xOffset = 0;
|
||||
const pokemonIcon = globalScene.add.sprite(pokemonIconX, pokemonIconY, "pokemon_icons_0");
|
||||
|
||||
// Intentionally left as "array includes" instead of an equality check to allow for future languages to reuse
|
||||
if (["pt-BR"].includes(currentLanguage)) {
|
||||
xOffset = 2;
|
||||
pokemonIcon.setX(pokemonIconX - 2);
|
||||
}
|
||||
pokemonIcon.setScale(0.5);
|
||||
pokemonIcon.setOrigin(0, 0.5);
|
||||
|
||||
gachaUpLabel.setX(legendaryLabelX - xOffset).setY(legendaryLabelY);
|
||||
pokemonIcon.setScale(0.5).setOrigin(0, 0.5);
|
||||
gachaInfoContainer.add(pokemonIcon);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GachaType.MOVE:
|
||||
if (["de", "es-ES", "fr", "pt-BR", "ru"].includes(currentLanguage)) {
|
||||
gachaUpLabel.setAlign("center");
|
||||
gachaUpLabel.setY(0);
|
||||
}
|
||||
|
||||
gachaUpLabel.setText(i18next.t("egg:moveUPGacha"));
|
||||
gachaUpLabel.setX(0);
|
||||
gachaUpLabel.setOrigin(0.5, 0);
|
||||
gachaUpLabel.setText(i18next.t("egg:moveUPGacha")).setX(0).setOrigin(0.5, 0);
|
||||
break;
|
||||
case GachaType.SHINY:
|
||||
if (["de", "fr", "ko", "ru"].includes(currentLanguage)) {
|
||||
gachaUpLabel.setAlign("center");
|
||||
gachaUpLabel.setY(0);
|
||||
gachaUpLabel.setAlign("center").setY(0);
|
||||
}
|
||||
|
||||
gachaUpLabel.setText(i18next.t("egg:shinyUPGacha"));
|
||||
gachaUpLabel.setX(0);
|
||||
gachaUpLabel.setOrigin(0.5, 0);
|
||||
gachaUpLabel.setText(i18next.t("egg:shinyUPGacha")).setX(0).setOrigin(0.5, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
const gachaKnob = globalScene.add.sprite(191, 89, "gacha_knob");
|
||||
|
||||
const gachaHatch = globalScene.add.sprite(115, 73, "gacha_hatch");
|
||||
gachaHatch.setOrigin(0, 0);
|
||||
gachaHatch.setOrigin(0, 0).setAlpha(0.9);
|
||||
|
||||
gachaContainer.add(gachaEggs);
|
||||
gachaContainer.add(gachaUnderlay);
|
||||
gachaContainer.add(gacha);
|
||||
gachaContainer.add(gachaGlass);
|
||||
gachaContainer.add(gachaKnob);
|
||||
gachaContainer.add(gachaHatch);
|
||||
gachaContainer.add(gachaInfoContainer);
|
||||
gachaContainer.add([gachaEggs, gachaUnderlay, gacha, gachaGlass, gachaKnob, gachaHatch, gachaInfoContainer]);
|
||||
|
||||
gachaGlass.setAlpha(0.5);
|
||||
gachaHatch.setAlpha(0.9);
|
||||
@ -215,15 +170,44 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
gachaContainer.add(this.legendaryExpiration);
|
||||
}
|
||||
|
||||
this.updateGachaInfo(g);
|
||||
this.updateGachaInfo(gachaType);
|
||||
}
|
||||
|
||||
setup() {
|
||||
this.gachaCursor = 0;
|
||||
this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale;
|
||||
|
||||
const ui = this.getUi();
|
||||
|
||||
this.eggGachaContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6);
|
||||
this.eggGachaContainer.setVisible(false);
|
||||
ui.add(this.eggGachaContainer);
|
||||
|
||||
const bg = globalScene.add.nineslice(0, 0, "default_bg", undefined, 320, 180, 0, 0, 16, 0);
|
||||
bg.setOrigin(0, 0);
|
||||
|
||||
this.eggGachaContainer.add(bg);
|
||||
|
||||
const hatchFrameNames = globalScene.anims.generateFrameNames("gacha_hatch", { suffix: ".png", start: 1, end: 4 });
|
||||
if (!globalScene.anims.exists("open")) {
|
||||
globalScene.anims.create({
|
||||
key: "open",
|
||||
frames: hatchFrameNames,
|
||||
frameRate: 12,
|
||||
});
|
||||
}
|
||||
if (!globalScene.anims.exists("close")) {
|
||||
globalScene.anims.create({
|
||||
key: "close",
|
||||
frames: hatchFrameNames.reverse(),
|
||||
frameRate: 12,
|
||||
});
|
||||
}
|
||||
|
||||
this.eggGachaOptionsContainer = globalScene.add.container();
|
||||
for (const [gachaTypeKey, gachaType] of Object.entries(GachaType)) {
|
||||
this.setupGachaType(gachaTypeKey as keyof typeof GachaType, gachaType);
|
||||
}
|
||||
|
||||
this.eggGachaOptionsContainer = globalScene.add.container(globalScene.game.canvas.width / 6, 148);
|
||||
this.eggGachaContainer.add(this.eggGachaOptionsContainer);
|
||||
|
||||
// Increase egg box width on certain languages
|
||||
let eggGachaOptionSelectWidth = 0;
|
||||
switch (i18next.resolvedLanguage) {
|
||||
case "ru":
|
||||
@ -233,9 +217,11 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
eggGachaOptionSelectWidth = 96;
|
||||
}
|
||||
|
||||
this.eggGachaOptionSelectBg = addWindow(0, 0, eggGachaOptionSelectWidth, 16 + 576 * this.scale);
|
||||
this.eggGachaOptionSelectBg.setOrigin(1, 1);
|
||||
this.eggGachaOptionsContainer.add(this.eggGachaOptionSelectBg);
|
||||
this.eggGachaOptionSelectBg = addWindow(0, 0, eggGachaOptionSelectWidth, 16 + 576 * this.scale).setOrigin(1);
|
||||
this.eggGachaOptionsContainer = globalScene.add
|
||||
.container(globalScene.game.canvas.width / 6, 148)
|
||||
.add(this.eggGachaOptionSelectBg);
|
||||
this.eggGachaContainer.add(this.eggGachaOptionsContainer);
|
||||
|
||||
const multiplierOne = "x1";
|
||||
const multiplierTen = "x10";
|
||||
@ -611,9 +597,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
duration: this.getDelayValue(250),
|
||||
ease: "Cubic.easeIn",
|
||||
onComplete: () => {
|
||||
this.eggGachaSummaryContainer.setVisible(false);
|
||||
this.eggGachaSummaryContainer.setAlpha(1);
|
||||
this.eggGachaSummaryContainer.removeAll(true);
|
||||
this.eggGachaSummaryContainer.setVisible(false).setAlpha(1).removeAll(true);
|
||||
this.setTransitioning(false);
|
||||
this.summaryFinished = false;
|
||||
this.eggGachaOptionsContainer.setVisible(true);
|
||||
@ -622,15 +606,13 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
}
|
||||
|
||||
updateGachaInfo(gachaType: GachaType): void {
|
||||
if (gachaType !== GachaType.LEGENDARY) {
|
||||
return;
|
||||
}
|
||||
const infoContainer = this.gachaInfoContainers[gachaType];
|
||||
switch (gachaType as GachaType) {
|
||||
case GachaType.LEGENDARY: {
|
||||
const species = getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(new Date().getTime()));
|
||||
const pokemonIcon = infoContainer.getAt(1) as Phaser.GameObjects.Sprite;
|
||||
pokemonIcon.setTexture(species.getIconAtlasKey(), species.getIconId(false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
consumeVouchers(voucherType: VoucherType, count: number): void {
|
||||
@ -813,7 +795,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||
}
|
||||
break;
|
||||
case Button.RIGHT:
|
||||
if (this.gachaCursor < getEnumKeys(GachaType).length - 1) {
|
||||
if (this.gachaCursor < Object.keys(GachaType).length - 1) {
|
||||
success = this.setGachaCursor(this.gachaCursor + 1);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user