Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eva/plugin-renderer

Package Overview
Dependencies
Maintainers
2
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eva/plugin-renderer - npm Package Compare versions

Comparing version 1.0.0-alpha.10 to 1.0.0-mini.0

dist/miniprogram.js

890

dist/plugin-renderer.cjs.js

@@ -1,889 +0,1 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var eva_js = require('@eva/eva.js');
var rendererAdapter = require('@eva/renderer-adapter');
var lodash = require('lodash');
var pixi_js = require('pixi.js');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
var RendererManager = /** @class */ (function () {
function RendererManager(_a) {
var game = _a.game, rendererSystem = _a.rendererSystem;
this.renderers = [];
this.game = game;
this.rendererSystem = rendererSystem;
}
RendererManager.prototype.register = function () {
var e_1, _a;
var renderers = [];
for (var _i = 0; _i < arguments.length; _i++) {
renderers[_i] = arguments[_i];
}
try {
for (var renderers_1 = __values(renderers), renderers_1_1 = renderers_1.next(); !renderers_1_1.done; renderers_1_1 = renderers_1.next()) {
var renderer = renderers_1_1.value;
renderer.game = this.game;
renderer.rendererManager = this.rendererSystem.rendererManager;
renderer.containerManager = this.rendererSystem.containerManager;
this.renderers.push(renderer);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (renderers_1_1 && !renderers_1_1.done && (_a = renderers_1.return)) _a.call(renderers_1);
}
finally { if (e_1) throw e_1.error; }
}
};
RendererManager.prototype.componentChanged = function (changes) {
var e_2, _a;
var _loop_1 = function (changed) {
var e_3, _a;
try {
for (var _b = (e_3 = void 0, __values(this_1.renderers)), _c = _b.next(); !_c.done; _c = _b.next()) {
var renderer = _c.value;
var props = renderer.observerInfo[changed.componentName];
if (props) {
if ([eva_js.OBSERVER_TYPE.ADD, eva_js.OBSERVER_TYPE.REMOVE].indexOf(changed.type) > -1) {
try {
renderer.componentChanged && renderer.componentChanged(changed);
}
catch (e) {
console.error("gameObject: " + changed.gameObject.name + ", " + changed.componentName + " is error.", changed, e);
}
continue;
}
var index = props.findIndex(function (prop) {
return lodash.isEqual(prop, changed.prop);
});
if (index > -1) {
try {
renderer.componentChanged && renderer.componentChanged(changed);
}
catch (e) {
console.error("gameObject: " + (changed.gameObject && changed.gameObject.name) + ", " + changed.componentName + " is componentChanged error.", changed, e);
}
}
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
};
var this_1 = this;
try {
for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
var changed = changes_1_1.value;
_loop_1(changed);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
}
finally { if (e_2) throw e_2.error; }
}
};
RendererManager.prototype.update = function (gameObject) {
var e_4, _a, e_5, _b;
try {
for (var _c = __values(gameObject.components), _d = _c.next(); !_d.done; _d = _c.next()) {
var component = _d.value;
try {
for (var _e = (e_5 = void 0, __values(this.renderers)), _f = _e.next(); !_f.done; _f = _e.next()) {
var renderer = _f.value;
var cache = [];
var props = renderer.observerInfo[component.name];
if (props && cache.indexOf(gameObject) === -1) {
cache.push(gameObject);
try {
renderer.rendererUpdate && renderer.rendererUpdate(gameObject);
}
catch (e) {
console.info("gameObject: " + gameObject.name + ", " + component.name + " is update error", e);
}
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_5) throw e_5.error; }
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_4) throw e_4.error; }
}
};
return RendererManager;
}());
var ContainerManager = /** @class */ (function () {
function ContainerManager() {
this.containerMap = {};
}
ContainerManager.prototype.addContainer = function (_a) {
var name = _a.name, container = _a.container;
this.containerMap[name] = container;
};
ContainerManager.prototype.getContainer = function (name) {
return this.containerMap[name];
};
ContainerManager.prototype.removeContainer = function (name) {
delete this.containerMap[name];
};
ContainerManager.prototype.updateTransform = function (_a) {
var name = _a.name, transform = _a.transform;
var container = this.containerMap[name];
if (!container)
return;
var anchor = transform.anchor, origin = transform.origin, position = transform.position, rotation = transform.rotation, scale = transform.scale, size = transform.size, skew = transform.skew;
container.rotation = rotation;
container.scale = scale;
container.pivot.x = size.width * origin.x;
container.pivot.y = size.height * origin.y;
container.skew = skew;
var x = position.x;
var y = position.y;
if (transform.parent) {
var parent_1 = transform.parent;
x = x + parent_1.size.width * anchor.x;
y = y + parent_1.size.height * anchor.y;
}
container.position = { x: x, y: y };
};
return ContainerManager;
}());
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var _eventemitter3_3_1_2_eventemitter3 = createCommonjsModule(function (module) {
var has = Object.prototype.hasOwnProperty
, prefix = '~';
/**
* Constructor to create a storage for our `EE` objects.
* An `Events` instance is a plain object whose properties are event names.
*
* @constructor
* @private
*/
function Events() {}
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
if (Object.create) {
Events.prototype = Object.create(null);
//
// This hack is needed because the `__proto__` property is still inherited in
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
//
if (!new Events().__proto__) prefix = false;
}
/**
* Representation of a single event listener.
*
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
* @constructor
* @private
*/
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
/**
* Add a listener for a given event.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} once Specify if the listener is a one-time listener.
* @returns {EventEmitter}
* @private
*/
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== 'function') {
throw new TypeError('The listener must be a function');
}
var listener = new EE(fn, context || emitter, once)
, evt = prefix ? prefix + event : event;
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
/**
* Clear event by name.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} evt The Event name.
* @private
*/
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();
else delete emitter._events[evt];
}
/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*
* @constructor
* @public
*/
function EventEmitter() {
this._events = new Events();
this._eventsCount = 0;
}
/**
* Return an array listing the events for which the emitter has registered
* listeners.
*
* @returns {Array}
* @public
*/
EventEmitter.prototype.eventNames = function eventNames() {
var names = []
, events
, name;
if (this._eventsCount === 0) return names;
for (name in (events = this._events)) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
/**
* Return the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Array} The registered listeners.
* @public
*/
EventEmitter.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event
, handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i].fn;
}
return ee;
};
/**
* Return the number of listeners listening to a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Number} The number of listeners.
* @public
*/
EventEmitter.prototype.listenerCount = function listenerCount(event) {
var evt = prefix ? prefix + event : event
, listeners = this._events[evt];
if (!listeners) return 0;
if (listeners.fn) return 1;
return listeners.length;
};
/**
* Calls each of the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Boolean} `true` if the event had listeners, else `false`.
* @public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return false;
var listeners = this._events[evt]
, len = arguments.length
, args
, i;
if (listeners.fn) {
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
switch (len) {
case 1: return listeners.fn.call(listeners.context), true;
case 2: return listeners.fn.call(listeners.context, a1), true;
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
}
for (i = 1, args = new Array(len -1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length
, j;
for (i = 0; i < length; i++) {
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
switch (len) {
case 1: listeners[i].fn.call(listeners[i].context); break;
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
default:
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
/**
* Add a listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
/**
* Add a one-time listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
/**
* Remove the listeners of a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn Only remove the listeners that match this function.
* @param {*} context Only remove the listeners that have this context.
* @param {Boolean} once Only remove one-time listeners.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return this;
if (!fn) {
clearEvent(this, evt);
return this;
}
var listeners = this._events[evt];
if (listeners.fn) {
if (
listeners.fn === fn &&
(!once || listeners.once) &&
(!context || listeners.context === context)
) {
clearEvent(this, evt);
}
} else {
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
if (
listeners[i].fn !== fn ||
(once && !listeners[i].once) ||
(context && listeners[i].context !== context)
) {
events.push(listeners[i]);
}
}
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
else clearEvent(this, evt);
}
return this;
};
/**
* Remove all listeners, or those of the specified event.
*
* @param {(String|Symbol)} [event] The event name.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
var evt;
if (event) {
evt = prefix ? prefix + event : event;
if (this._events[evt]) clearEvent(this, evt);
} else {
this._events = new Events();
this._eventsCount = 0;
}
return this;
};
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
//
// Expose the prefix.
//
EventEmitter.prefixed = prefix;
//
// Allow `EventEmitter` to be imported as module namespace.
//
EventEmitter.EventEmitter = EventEmitter;
//
// Expose the module.
//
{
module.exports = EventEmitter;
}
});
var Transform = /** @class */ (function (_super) {
__extends(Transform, _super);
function Transform(_a) {
var system = _a.system, containerManager = _a.containerManager;
var _this = _super.call(this) || this;
_this.name = 'Transform';
_this.waitRemoveIds = [];
_this.waitChangeScenes = [];
_this.containerManager = containerManager;
_this.init(system);
return _this;
}
Transform.prototype.init = function (system) {
var _this = this;
this.system = system;
this.on('changeScene', function (_a) {
var scene = _a.scene, mode = _a.mode, application = _a.application;
// switch (mode) {
// case LOAD_SCENE_MODE.SINGLE:
_this.waitChangeScenes.push({ scene: scene, mode: mode, application: application });
// break;
// case LOAD_SCENE_MODE.MULTI_CANVAS:
// }
});
};
Transform.prototype.update = function () {
var e_1, _a, e_2, _b;
try {
for (var _c = __values(this.waitRemoveIds), _d = _c.next(); !_d.done; _d = _c.next()) {
var id = _d.value;
this.containerManager.removeContainer(id);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
this.waitRemoveIds = [];
try {
for (var _e = __values(this.waitChangeScenes), _f = _e.next(); !_f.done; _f = _e.next()) {
var sceneInfo = _f.value;
// set scene
var container = this.containerManager.getContainer(sceneInfo.scene.id);
if (container) {
sceneInfo.application.stage.removeChildren();
sceneInfo.application.stage.addChild(container);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
this.waitChangeScenes = [];
};
Transform.prototype.componentChanged = function (changed) {
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
this.addContainer(changed);
}
else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
this.change(changed);
}
else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
this.waitRemoveIds.push(changed.gameObject.id);
}
};
Transform.prototype.addContainer = function (changed) {
var container = new rendererAdapter.Container();
container.name = changed.gameObject.name;
this.containerManager.addContainer({
name: changed.gameObject.id,
container: container,
});
var transform = changed.component;
transform.worldTransform = container.transform.worldTransform;
};
Transform.prototype.change = function (changed) {
var transform = changed.component;
if (transform.parent) {
var parentContainer = this.containerManager.getContainer(transform.parent.gameObject.id);
parentContainer.addChild(this.containerManager.getContainer(changed.gameObject.id));
var render = changed.gameObject.transform.parent &&
changed.gameObject.transform.parent.gameObject.getComponent('Render');
if (render) {
render.sortDirty = true;
}
}
else {
var container = this.containerManager.getContainer(changed.gameObject.id);
container.parent && container.parent.removeChild(container);
}
};
Transform.prototype.destroy = function () {
this.removeAllListeners();
this.waitRemoveIds = null;
this.waitChangeScenes = null;
this.system = null;
this.containerManager = null;
};
Transform = __decorate([
eva_js.decorators.componentObserver({
Transform: ['_parent'],
})
], Transform);
return Transform;
}(_eventemitter3_3_1_2_eventemitter3));
(function (RENDERER_TYPE) {
RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
})(exports.RENDERER_TYPE || (exports.RENDERER_TYPE = {}));
var Renderer = /** @class */ (function (_super) {
__extends(Renderer, _super);
function Renderer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.multiApps = [];
return _this;
}
Renderer.prototype.init = function (params) {
var _this = this;
this.params = params;
this.application = this.createApplication(params);
this.containerManager = new ContainerManager();
this.rendererManager = new RendererManager({
game: this.game,
rendererSystem: this,
});
this.game.canvas = this.application.view;
this.transform = new Transform({
system: this,
containerManager: this.containerManager,
});
this.game.on('sceneChanged', function (_a) {
var scene = _a.scene, mode = _a.mode, params = _a.params;
var application;
switch (mode) {
case eva_js.LOAD_SCENE_MODE.SINGLE:
application = _this.application;
break;
case eva_js.LOAD_SCENE_MODE.MULTI_CANVAS:
application = _this.createMultiApplication({ params: params });
break;
}
scene.canvas = application.view;
_this.transform.emit('changeScene', {
scene: scene,
mode: mode,
application: application,
});
});
};
Renderer.prototype.registerObserver = function (observerInfo) {
var _a;
// @ts-ignore
var thisObserverInfo = this.constructor.observerInfo;
for (var key in observerInfo) {
if (!thisObserverInfo[key]) {
thisObserverInfo[key] = [];
}
(_a = thisObserverInfo[key]).push.apply(_a, __spread(observerInfo[key]));
}
};
Renderer.prototype.createMultiApplication = function (_a) {
var params = _a.params;
var app = this.createApplication(params);
this.multiApps.push(app);
return app;
};
Renderer.prototype.createApplication = function (params) {
params.view = params.canvas;
if (params.renderType === exports.RENDERER_TYPE.CANVAS) {
params.forceCanvas = true;
}
pixi_js.ticker.shared.autoStart = false;
pixi_js.ticker.shared.stop();
var app = new rendererAdapter.Application(__assign({ sharedTicker: true }, params));
if (params.preventScroll !== false) {
app.renderer.plugins.interaction.autoPreventDefault = false;
app.renderer.view.style.touchAction = 'auto';
}
return app;
};
Renderer.prototype.update = function (e) {
var e_1, _a, e_2, _b;
var changes = this.componentObserver.clear();
try {
for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
var changed = changes_1_1.value;
this.transform.componentChanged(changed);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
}
finally { if (e_1) throw e_1.error; }
}
try {
for (var _c = __values(this.game.gameObjects), _d = _c.next(); !_d.done; _d = _c.next()) {
var gameObject = _d.value;
this.containerManager.updateTransform({
name: gameObject.id,
transform: gameObject.transform,
});
this.rendererManager.update(gameObject);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
this.application.ticker.update(e.time);
};
Renderer.prototype.lateUpdate = function () {
this.transform.update();
};
Renderer.prototype.onDestroy = function () {
var e_3, _a;
this.application.destroy();
try {
for (var _b = __values(this.multiApps), _c = _b.next(); !_c.done; _c = _b.next()) {
var app = _c.value;
app && app.destroy();
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
this.transform.destroy();
this.transform = null;
this.params = null;
this.rendererManager = null;
this.containerManager = null;
this.application = null;
this.game = null;
this.multiApps = null;
};
Renderer.systemName = 'Renderer';
Renderer = __decorate([
eva_js.decorators.componentObserver({
Transform: ['_parent'],
})
], Renderer);
return Renderer;
}(eva_js.System));
var Renderer$1 = /** @class */ (function (_super) {
__extends(Renderer, _super);
function Renderer() {
var _this = _super.call(this) || this;
// @ts-ignore
_this.observerInfo = _this.constructor.observerInfo;
return _this;
}
Renderer.prototype.update = function () {
var e_1, _a;
var changes = this.componentObserver.clear();
try {
for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
var changed = changes_1_1.value;
this.componentChanged(changed);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
}
finally { if (e_1) throw e_1.error; }
}
};
return Renderer;
}(eva_js.System));
exports.ContainerManager = ContainerManager;
exports.Renderer = Renderer$1;
exports.RendererManager = RendererManager;
exports.RendererSystem = Renderer;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/renderer-adapter"),r=require("lodash"),n=require("pixi.js"),o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function a(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var i=function(){return(i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function s(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}function c(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function p(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,a=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(o)throw o.error}}return i}function l(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(p(arguments[t]));return e}var f=function(){function t(e){var t=e.game,r=e.rendererSystem;this.renderers=[],this.game=t,this.rendererSystem=r}return t.prototype.register=function(){for(var e,t,r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];try{for(var o=c(r),a=o.next();!a.done;a=o.next()){var i=a.value;i.game=this.game,i.rendererManager=this.rendererSystem.rendererManager,i.containerManager=this.rendererSystem.containerManager,this.renderers.push(i)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}},t.prototype.componentChanged=function(t){var n,o,a=function(t){var n,o;try{for(var a=(n=void 0,c(i.renderers)),s=a.next();!s.done;s=a.next()){var p=s.value,l=p.observerInfo[t.componentName];if(l){if([e.OBSERVER_TYPE.ADD,e.OBSERVER_TYPE.REMOVE].indexOf(t.type)>-1){try{p.componentChanged&&p.componentChanged(t)}catch(e){console.error("gameObject: "+t.gameObject.name+", "+t.componentName+" is error.",t,e)}continue}if(l.findIndex((function(e){return r.isEqual(e,t.prop)}))>-1)try{p.componentChanged&&p.componentChanged(t)}catch(e){console.error("gameObject: "+(t.gameObject&&t.gameObject.name)+", "+t.componentName+" is componentChanged error.",t,e)}}}}catch(e){n={error:e}}finally{try{s&&!s.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}},i=this;try{for(var s=c(t),p=s.next();!p.done;p=s.next()){a(p.value)}}catch(e){n={error:e}}finally{try{p&&!p.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e){var t,r,n,o;try{for(var a=c(e.components),i=a.next();!i.done;i=a.next()){var s=i.value;try{for(var p=(n=void 0,c(this.renderers)),l=p.next();!l.done;l=p.next()){var f=l.value,h=[];if(f.observerInfo[s.name]&&-1===h.indexOf(e)){h.push(e);try{f.rendererUpdate&&f.rendererUpdate(e)}catch(t){console.info("gameObject: "+e.name+", "+s.name+" is update error",t)}}}}catch(e){n={error:e}}finally{try{l&&!l.done&&(o=p.return)&&o.call(p)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}},t}(),h=function(){function e(){this.containerMap={}}return e.prototype.addContainer=function(e){var t=e.name,r=e.container;this.containerMap[t]=r},e.prototype.getContainer=function(e){return this.containerMap[e]},e.prototype.removeContainer=function(e){delete this.containerMap[e]},e.prototype.updateTransform=function(e){var t=e.name,r=e.transform,n=this.containerMap[t];if(n){var o=r.anchor,a=r.origin,i=r.position,s=r.rotation,c=r.scale,p=r.size,l=r.skew;n.rotation=s,n.scale=c,n.pivot.x=p.width*a.x,n.pivot.y=p.height*a.y,n.skew=l;var f=i.x,h=i.y;if(r.parent){var u=r.parent;f+=u.size.width*o.x,h+=u.size.height*o.y}n.position={x:f,y:h}}},e}();var u,v,y=function(r){function n(e){var t=e.system,n=e.containerManager,o=r.call(this)||this;return o.name="Transform",o.waitRemoveIds=[],o.waitChangeScenes=[],o.containerManager=n,o.init(t),o}return a(n,r),n.prototype.init=function(e){var t=this;this.system=e,this.on("changeScene",(function(e){var r=e.scene,n=e.mode,o=e.application;t.waitChangeScenes.push({scene:r,mode:n,application:o})}))},n.prototype.update=function(){var e,t,r,n;try{for(var o=c(this.waitRemoveIds),a=o.next();!a.done;a=o.next()){var i=a.value;this.containerManager.removeContainer(i)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}this.waitRemoveIds=[];try{for(var s=c(this.waitChangeScenes),p=s.next();!p.done;p=s.next()){var l=p.value,f=this.containerManager.getContainer(l.scene.id);f&&(l.application.stage.removeChildren(),l.application.stage.addChild(f))}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}this.waitChangeScenes=[]},n.prototype.componentChanged=function(t){t.type===e.OBSERVER_TYPE.ADD?this.addContainer(t):t.type===e.OBSERVER_TYPE.CHANGE?this.change(t):t.type===e.OBSERVER_TYPE.REMOVE&&this.waitRemoveIds.push(t.gameObject.id)},n.prototype.addContainer=function(e){var r=new t.Container;r.name=e.gameObject.name,this.containerManager.addContainer({name:e.gameObject.id,container:r}),e.component.worldTransform=r.transform.worldTransform},n.prototype.change=function(e){var t=e.component;if(t.parent){this.containerManager.getContainer(t.parent.gameObject.id).addChild(this.containerManager.getContainer(e.gameObject.id));var r=e.gameObject.transform.parent&&e.gameObject.transform.parent.gameObject.getComponent("Render");r&&(r.sortDirty=!0)}else{var n=this.containerManager.getContainer(e.gameObject.id);n.parent&&n.parent.removeChild(n)}},n.prototype.destroy=function(){this.removeAllListeners(),this.waitRemoveIds=null,this.waitChangeScenes=null,this.system=null,this.containerManager=null},n=s([e.decorators.componentObserver({Transform:["_parent"]})],n)}((function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function a(e,t,n,a,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new o(n,a||e,i),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function s(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),s.prototype.eventNames=function(){var e,n,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},s.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,a=n.length,i=new Array(a);o<a;o++)i[o]=n[o].fn;return i},s.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},s.prototype.emit=function(e,t,n,o,a,i){var s=r?r+e:e;if(!this._events[s])return!1;var c,p,l=this._events[s],f=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),f){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,o),!0;case 5:return l.fn.call(l.context,t,n,o,a),!0;case 6:return l.fn.call(l.context,t,n,o,a,i),!0}for(p=1,c=new Array(f-1);p<f;p++)c[p-1]=arguments[p];l.fn.apply(l.context,c)}else{var h,u=l.length;for(p=0;p<u;p++)switch(l[p].once&&this.removeListener(e,l[p].fn,void 0,!0),f){case 1:l[p].fn.call(l[p].context);break;case 2:l[p].fn.call(l[p].context,t);break;case 3:l[p].fn.call(l[p].context,t,n);break;case 4:l[p].fn.call(l[p].context,t,n,o);break;default:if(!c)for(h=1,c=new Array(f-1);h<f;h++)c[h-1]=arguments[h];l[p].fn.apply(l[p].context,c)}}return!0},s.prototype.on=function(e,t,r){return a(this,e,t,r,!1)},s.prototype.once=function(e,t,r){return a(this,e,t,r,!0)},s.prototype.removeListener=function(e,t,n,o){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return i(this,a),this;var s=this._events[a];if(s.fn)s.fn!==t||o&&!s.once||n&&s.context!==n||i(this,a);else{for(var c=0,p=[],l=s.length;c<l;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&p.push(s[c]);p.length?this._events[a]=1===p.length?p[0]:p:i(this,a)}return this},s.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&i(this,t)):(this._events=new n,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=r,s.EventEmitter=s,e.exports=s}(u={exports:{}},u.exports),u.exports));(v=exports.RENDERER_TYPE||(exports.RENDERER_TYPE={}))[v.UNKNOWN=0]="UNKNOWN",v[v.WEBGL=1]="WEBGL",v[v.CANVAS=2]="CANVAS";var d=function(r){function o(){var e=null!==r&&r.apply(this,arguments)||this;return e.multiApps=[],e}return a(o,r),o.prototype.init=function(t){var r=this;this.params=t,this.application=this.createApplication(t),this.containerManager=new h,this.rendererManager=new f({game:this.game,rendererSystem:this}),this.game.canvas=this.application.view,this.transform=new y({system:this,containerManager:this.containerManager}),this.game.on("sceneChanged",(function(t){var n,o=t.scene,a=t.mode,i=t.params;switch(a){case e.LOAD_SCENE_MODE.SINGLE:n=r.application;break;case e.LOAD_SCENE_MODE.MULTI_CANVAS:n=r.createMultiApplication({params:i})}o.canvas=n.view,r.transform.emit("changeScene",{scene:o,mode:a,application:n})}))},o.prototype.registerObserver=function(e){var t,r=this.constructor.observerInfo;for(var n in e)r[n]||(r[n]=[]),(t=r[n]).push.apply(t,l(e[n]))},o.prototype.createMultiApplication=function(e){var t=e.params,r=this.createApplication(t);return this.multiApps.push(r),r},o.prototype.createApplication=function(e){e.view=e.canvas,e.renderType===exports.RENDERER_TYPE.CANVAS&&(e.forceCanvas=!0),n.ticker.shared.autoStart=!1,n.ticker.shared.stop();var r=new t.Application(i({sharedTicker:!0},e));return!1!==e.preventScroll&&(r.renderer.plugins.interaction.autoPreventDefault=!1,r.renderer.view.style.touchAction="auto"),r},o.prototype.update=function(e){var t,r,n,o,a=this.componentObserver.clear();try{for(var i=c(a),s=i.next();!s.done;s=i.next()){var p=s.value;this.transform.componentChanged(p)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}try{for(var l=c(this.game.gameObjects),f=l.next();!f.done;f=l.next()){var h=f.value;this.containerManager.updateTransform({name:h.id,transform:h.transform}),this.rendererManager.update(h)}}catch(e){n={error:e}}finally{try{f&&!f.done&&(o=l.return)&&o.call(l)}finally{if(n)throw n.error}}this.application.ticker.update(e.time)},o.prototype.lateUpdate=function(){this.transform.update()},o.prototype.onDestroy=function(){var e,t;this.application.destroy();try{for(var r=c(this.multiApps),n=r.next();!n.done;n=r.next()){var o=n.value;o&&o.destroy()}}catch(t){e={error:t}}finally{try{n&&!n.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}this.transform.destroy(),this.transform=null,this.params=null,this.rendererManager=null,this.containerManager=null,this.application=null,this.game=null,this.multiApps=null},o.systemName="Renderer",o=s([e.decorators.componentObserver({Transform:["_parent"]})],o)}(e.System),m=function(e){function t(){var t=e.call(this)||this;return t.observerInfo=t.constructor.observerInfo,t}return a(t,e),t.prototype.update=function(){var e,t,r=this.componentObserver.clear();try{for(var n=c(r),o=n.next();!o.done;o=n.next()){var a=o.value;this.componentChanged(a)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},t}(e.System);exports.ContainerManager=h,exports.Renderer=m,exports.RendererManager=f,exports.RendererSystem=d;
{
"name": "@eva/plugin-renderer",
"version": "1.0.0-alpha.10",
"version": "1.0.0-mini.0",
"description": "@eva/plugin-renderer",

@@ -18,9 +18,6 @@ "main": "index.js",

"license": "MIT",
"bugs": {
"url": "https://github.com/eva-engine/eva-engine.github.io/issues"
},
"homepage": "https://eva.js.org",
"dependencies": {
"@eva/eva.js": "^1.0.0-alpha.10",
"@eva/renderer-adapter": "^1.0.0-alpha.10",
"@eva/eva.js": "^1.0.0-mini.0",
"@eva/renderer-adapter": "^1.0.0-mini.0",
"eventemitter3": "^3.1.2",

@@ -27,0 +24,0 @@ "pixi.js": "^4.8.7"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc