@game-vir/entity
Version:
Entity system for game development.
47 lines (46 loc) • 1.34 kB
JavaScript
import { Application, Container, Rectangle, Ticker } from 'pixi.js';
/**
* Create a mock Pixi.js Application. Additional Application mocks can be provided that will be
* merged with the base mock. (Clashing properties will be overridden by what is provided in the
* additional mocks.)
*
* @category Mock
*/
export function createMockPixi({ mocks, options, } = {}) {
const mock = new MockPixiApp(options);
if (mocks) {
Object.assign(mock, mocks);
}
return mock;
}
/**
* Mock Pixi.js Application. This is not a complete mock (yet) and only implements partial
* functionality.
*
* @category Internal
*/
export class MockPixiApp {
/** A live Pixi.js Ticker so it can be used to trigger updates. */
ticker = new Ticker();
stage = new Container();
screen = new Rectangle(0, 0, 1000, 1000);
constructor(options) {
this.ticker.autoStart = false;
if (options?.width != undefined) {
this.screen.width = options.width;
}
if (options?.height != undefined) {
this.screen.height = options.height;
}
}
}
/**
* Create an initialize a Pixi.js app all in one call.
*
* @category Util
*/
export async function createPixi(options) {
const instance = new Application();
await instance.init(options);
return instance;
}