UNPKG

@geckos.io/phaser-on-nodejs

Version:

Allows you to run Phaser 3 games (including Phaser's physics engines) on Node.js.

44 lines 1.74 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.requestAnimationFrame = exports.animationFrame = void 0; const canvas_1 = __importDefault(require("canvas")); const jsdom_1 = __importDefault(require("jsdom")); const fakeXMLHttpRequest_1 = __importDefault(require("./fakeXMLHttpRequest")); require("./fakeScreen"); const { JSDOM } = jsdom_1.default; const dom = new JSDOM(`<!DOCTYPE html><body></body>`); const noop = () => { }; const document = dom.window.document; const window = dom.window; window.focus = () => { }; global.document = document; global.window = window; global.window.Element = undefined; global.navigator ??= { userAgent: 'node' }; global.Image = canvas_1.default.Image; global.XMLHttpRequest = fakeXMLHttpRequest_1.default; global.HTMLCanvasElement = window.HTMLCanvasElement; global.HTMLVideoElement = window.HTMLVideoElement; // @ts-ignore global.URL = URL || noop; global.URL.createObjectURL = (base64) => `data:image/png;base64,${base64}`; global.URL.revokeObjectURL = () => { }; // phaser on node variables global.phaserOnNodeFPS = 60; const animationFrame = (cb) => { const now = performance.now(); if (typeof cb !== 'function') return 0; // this line saves a lot of cpu window.setTimeout(() => cb(now), 1000 / global.phaserOnNodeFPS); return 0; }; exports.animationFrame = animationFrame; window.requestAnimationFrame = cb => { return animationFrame(cb); }; const requestAnimationFrame = window.requestAnimationFrame; exports.requestAnimationFrame = requestAnimationFrame; //# sourceMappingURL=index.js.map