pokerogue/test/testUtils/mocks/mockTextureManager.ts
NightKev 4dca988823
[Dev] Update packages (#6088)
* Update packages

* Add default values for tweens

* Add mocks for `InputText` and `BBCodeText`

* Delete deprecated `vitest.workspace.ts`

* Replace `new InputText` with `globalScene.add.rexInputText`

* Disable broken Magic Bounce test

* Disable broken test in `stockpiling.test.ts`
2025-07-16 22:28:17 -07:00

132 lines
3.9 KiB
TypeScript

import type { MockGameObject } from "#test/testUtils/mocks/mockGameObject";
import { MockBBCodeText } from "#test/testUtils/mocks/mocksContainer/mock-bbcode-text";
import { MockInputText } from "#test/testUtils/mocks/mocksContainer/mock-input-text";
import { MockContainer } from "#test/testUtils/mocks/mocksContainer/mockContainer";
import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage";
import { MockNineslice } from "#test/testUtils/mocks/mocksContainer/mockNineslice";
import { MockPolygon } from "#test/testUtils/mocks/mocksContainer/mockPolygon";
import { MockRectangle } from "#test/testUtils/mocks/mocksContainer/mockRectangle";
import { MockSprite } from "#test/testUtils/mocks/mocksContainer/mockSprite";
import { MockText } from "#test/testUtils/mocks/mocksContainer/mockText";
import { MockTexture } from "#test/testUtils/mocks/mocksContainer/mockTexture";
import { MockVideoGameObject } from "#test/testUtils/mocks/mockVideoGameObject";
/**
* Stub class for Phaser.Textures.TextureManager
*/
export class MockTextureManager {
private textures: Map<string, any>;
private scene;
public add;
public displayList;
public list: MockGameObject[] = [];
constructor(scene) {
this.scene = scene;
this.textures = new Map();
this.displayList = new Phaser.GameObjects.DisplayList(scene);
this.add = {
container: this.container.bind(this),
sprite: this.sprite.bind(this),
tileSprite: this.sprite.bind(this),
existing: this.existing.bind(this),
rectangle: this.rectangle.bind(this),
nineslice: this.nineslice.bind(this),
image: this.image.bind(this),
polygon: this.polygon.bind(this),
text: this.text.bind(this),
rexBBCodeText: this.rexBBCodeText.bind(this),
rexInputText: this.rexInputText.bind(this),
bitmapText: this.text.bind(this),
displayList: this.displayList,
video: () => new MockVideoGameObject(),
};
}
container(x, y) {
const container = new MockContainer(this, x, y);
this.list.push(container);
return container;
}
sprite(x, y, texture) {
const sprite = new MockSprite(this, x, y, texture);
this.list.push(sprite);
return sprite;
}
existing(_obj) {
// const whitelist = ["ArenaBase", "PlayerPokemon", "EnemyPokemon"];
// const key = obj.constructor.name;
// if (whitelist.includes(key) || obj.texture?.key?.includes("trainer_")) {
// this.containers.push(obj);
// }
}
/**
* Returns a mock texture
* @param key
*/
get(key) {
return new MockTexture(this, key, null);
}
rectangle(x, y, width, height, fillColor) {
const rectangle = new MockRectangle(this, x, y, width, height, fillColor);
this.list.push(rectangle);
return rectangle;
}
nineslice(x, y, texture, frame, width, height, leftWidth, rightWidth, topHeight, bottomHeight) {
const nineSlice = new MockNineslice(
this,
x,
y,
texture,
frame,
width,
height,
leftWidth,
rightWidth,
topHeight,
bottomHeight,
);
this.list.push(nineSlice);
return nineSlice;
}
image(x, y, texture) {
const image = new MockImage(this, x, y, texture);
this.list.push(image);
return image;
}
text(x, y, content, styleOptions) {
const text = new MockText(this, x, y, content, styleOptions);
this.list.push(text);
return text;
}
rexBBCodeText(x, y, content, styleOptions) {
const text = new MockBBCodeText(this, x, y, content, styleOptions);
this.list.push(text);
return text;
}
rexInputText(x, y, w, h, content, styleOptions) {
const text = new MockInputText(this, x, y, w, h, content, styleOptions);
this.list.push(text);
return text;
}
polygon(x, y, content, fillColor, fillAlpha) {
const polygon = new MockPolygon(this, x, y, content, fillColor, fillAlpha);
this.list.push(polygon);
return polygon;
}
exists(key: string): boolean {
return this.textures.has(key);
}
}