mirror of
				https://github.com/pagefaultgames/pokerogue.git
				synced 2025-10-31 16:35:52 +01:00 
			
		
		
		
	* Create battle-info directory and move battle-info.ts to it * Move player and enemy battle info to their own files * Move subclass specific parts of constructor to subclass constructor * Fixup mock gameobject methods to match phaser gameobject returns * Make statOrder specific to subclass * Create getShinyDescriptor function in utils * Move icon construction to its own function * Cleanup enemybattleinfo constructor to use chaining * Make flyout exclusive to EnemyBattleInfo * Move EnemyPokemon specific init Logic to its class * Break up initInfo into different methods * Remove hp bar segment dividers from base battle info * Move setMini to pokemoninfo * Breakup updateInfo into smaller parts * Remove hp info handling from base updateInfo * Use phaser object chaining methods * Add some docs * Add missing chain usage * Use getShinyDescriptor in pokemon-info-container * Minor cleanup of updatePokemonExp * Fixup setSizeToFrame mock * Ensure pokemon hp numbers are not visible during stat display * Update src/utils/common.ts Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com> * Make summary-ui-handler use new shinyDescriptor method * Remove `undefined` parameter pass Co-authored-by: Amani H. <109637146+xsn34kzx@users.noreply.github.com> * Address kev's review comments Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Ensure hp number display fades in/out * Ensure ribbon and caught indicator fade with stat display * Update src/ui/battle-info/battle-info.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Move construction of stats and type icons to their own methods * Make setPositionRelative return this * Improve doc comment on paddingX param * Fix mock sprite's setPositionRelative --------- Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Co-authored-by: Amani H. <109637146+xsn34kzx@users.noreply.github.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
		
			
				
	
	
		
			121 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			121 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { SESSION_ID_COOKIE_NAME } from "#app/constants";
 | |
| import { initLoggedInUser } from "#app/account";
 | |
| import { initAbilities } from "#app/data/abilities/ability";
 | |
| import { initBiomes } from "#app/data/balance/biomes";
 | |
| import { initEggMoves } from "#app/data/balance/egg-moves";
 | |
| import { initPokemonPrevolutions, initPokemonStarters } from "#app/data/balance/pokemon-evolutions";
 | |
| import { initMoves } from "#app/data/moves/move";
 | |
| import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters";
 | |
| import { initPokemonForms } from "#app/data/pokemon-forms";
 | |
| import { initSpecies } from "#app/data/pokemon-species";
 | |
| import { initAchievements } from "#app/system/achv";
 | |
| import { initVouchers } from "#app/system/voucher";
 | |
| import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
 | |
| import { setCookie } from "#app/utils/cookies";
 | |
| import { blobToString } from "#test/testUtils/gameManagerUtils";
 | |
| import { MockConsoleLog } from "#test/testUtils/mocks/mockConsoleLog";
 | |
| import { mockContext } from "#test/testUtils/mocks/mockContextCanvas";
 | |
| import { mockLocalStorage } from "#test/testUtils/mocks/mockLocalStorage";
 | |
| import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage";
 | |
| import Phaser from "phaser";
 | |
| import InputText from "phaser3-rex-plugins/plugins/inputtext";
 | |
| import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext";
 | |
| import { manageListeners } from "./listenersManager";
 | |
| import { initI18n } from "#app/plugins/i18n";
 | |
| 
 | |
| let wasInitialized = false;
 | |
| /**
 | |
|  * An initialization function that is run at the beginning of every test file (via `beforeAll()`).
 | |
|  */
 | |
| export function initTestFile() {
 | |
|   // Set the timezone to UTC for tests.
 | |
|   process.env.TZ = "UTC";
 | |
| 
 | |
|   Object.defineProperty(window, "localStorage", {
 | |
|     value: mockLocalStorage(),
 | |
|   });
 | |
|   Object.defineProperty(window, "console", {
 | |
|     value: new MockConsoleLog(false),
 | |
|   });
 | |
|   Object.defineProperty(document, "fonts", {
 | |
|     writable: true,
 | |
|     value: {
 | |
|       add: () => {},
 | |
|     },
 | |
|   });
 | |
| 
 | |
|   BBCodeText.prototype.destroy = () => null;
 | |
|   // @ts-ignore
 | |
|   BBCodeText.prototype.resize = () => null;
 | |
|   InputText.prototype.setElement = () => null as any;
 | |
|   InputText.prototype.resize = () => null as any;
 | |
|   Phaser.GameObjects.Image = MockImage as any;
 | |
|   window.URL.createObjectURL = (blob: Blob) => {
 | |
|     blobToString(blob).then((data: string) => {
 | |
|       localStorage.setItem("toExport", data);
 | |
|     });
 | |
|     return null as any;
 | |
|   };
 | |
|   navigator.getGamepads = () => [];
 | |
|   setCookie(SESSION_ID_COOKIE_NAME, "fake_token");
 | |
| 
 | |
|   window.matchMedia = () =>
 | |
|     ({
 | |
|       matches: false,
 | |
|     }) as any;
 | |
| 
 | |
|   /**
 | |
|    * Sets this object's position relative to another object with a given offset
 | |
|    * @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
 | |
|    * @param x The relative x position
 | |
|    * @param y The relative y position
 | |
|    */
 | |
|   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));
 | |
|     return this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y);
 | |
|   };
 | |
| 
 | |
|   Phaser.GameObjects.Container.prototype.setPositionRelative = setPositionRelative;
 | |
|   Phaser.GameObjects.Sprite.prototype.setPositionRelative = setPositionRelative;
 | |
|   Phaser.GameObjects.Image.prototype.setPositionRelative = setPositionRelative;
 | |
|   Phaser.GameObjects.NineSlice.prototype.setPositionRelative = setPositionRelative;
 | |
|   Phaser.GameObjects.Text.prototype.setPositionRelative = setPositionRelative;
 | |
|   Phaser.GameObjects.Rectangle.prototype.setPositionRelative = setPositionRelative;
 | |
|   HTMLCanvasElement.prototype.getContext = () => mockContext;
 | |
| 
 | |
|   // Initialize all of these things if and only if they have not been initialized yet
 | |
|   if (!wasInitialized) {
 | |
|     wasInitialized = true;
 | |
|     initI18n();
 | |
|     initVouchers();
 | |
|     initAchievements();
 | |
|     initStatsKeys();
 | |
|     initPokemonPrevolutions();
 | |
|     initBiomes();
 | |
|     initEggMoves();
 | |
|     initPokemonForms();
 | |
|     initSpecies();
 | |
|     initMoves();
 | |
|     initAbilities();
 | |
|     initLoggedInUser();
 | |
|     initMysteryEncounters();
 | |
|     // init the pokemon starters for the pokedex
 | |
|     initPokemonStarters();
 | |
|   }
 | |
| 
 | |
|   manageListeners();
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Closes the current mock server and initializes a new mock server.
 | |
|  * This is run at the beginning of every API test file.
 | |
|  */
 | |
| export async function initServerForApiTests() {
 | |
|   global.server?.close();
 | |
|   const { setupServer } = await import("msw/node");
 | |
|   global.server = setupServer();
 | |
|   global.server.listen({ onUnhandledRequest: "error" });
 | |
|   return global.server;
 | |
| }
 |