Files
esengine/demo/libs/framework/framework.min.js

1 line
12 KiB
JavaScript
Raw Normal View History

2020-06-08 16:23:48 +08:00
window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),Array.prototype.findIndex=function(t){return function(t,n){for(var e=0,r=t.length;e<r;e++)if(n.call(arguments[2],t[e],e,t))return e;return-1}(this,t)},Array.prototype.any=function(t){return function(t,n){return t.findIndex(n)>-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,n){var e=t.findIndex(n);return-1==e?null:t[e]}(this,t)},Array.prototype.find=function(t){return function(t,n){return t.firstOrDefault(n)}(this,t)},Array.prototype.where=function(t){return function(t,n){if("function"==typeof t.reduce)return t.reduce(function(e,r,i){return n.call(arguments[2],r,i,t)&&e.push(r),e},[]);for(var e=[],r=0,i=t.length;r<i;r++){var o=t[r];n.call(arguments[2],o,r,t)&&e.push(o)}return e}(this,t)},Array.prototype.count=function(t){return function(t,n){return t.where(n).length}(this,t)},Array.prototype.findAll=function(t){return function(t,n){return t.where(n)}(this,t)},Array.prototype.contains=function(t){return function(t,n){for(var e=0,r=t.length;e<r;e++)if(JSON.stringify(t[e])==JSON.stringify(n))return!0;return!1}(this,t)},Array.prototype.removeAll=function(t){!function(t,n){var e;do{(e=t.findIndex(n))>=0&&t.splice(e,1)}while(e>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,n){var e=t.findIndex(function(t){return t===n});return e>=0&&(t.splice(e,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,n){t.splice(n,1)}(this,t)},Array.prototype.removeRange=function(t,n){return function(t,n,e){t.splice(n,e)}(this,t,n)},Array.prototype.select=function(t){return function(t,n){if("function"==typeof t.reduce)return t.reduce(function(e,r,i){return e.push(n.call(arguments[2],r,i,t)),e},[]);for(var e=[],r=0,i=t.length;r<i;r++)e.push(n.call(arguments[2],t[r],r,t));return e}(this,t)},Array.prototype.orderBy=function(t,n){return function(t,n,e){return t.sort(function(t,r){var i=n(t),o=n(r);return e?e(i,o):i>o?1:-1}),t}(this,t,n)},Array.prototype.orderByDescending=function(t,n){return function(t,n,e){return t.sort(function(t,r){var i=n(t),o=n(r);return e?-e(i,o):i<o?1:-1}),t}(this,t,n)},Array.prototype.groupBy=function(t){return function(t,n){if("function"==typeof t.reduce){var e=[];return t.reduce(function(r,i,o){var s=JSON.stringify(n.call(arguments[1],i,o,t)),a=e.findIndex(function(t){return t===s});return a<0&&(a=e.push(s)-1),r[a]||(r[a]=[]),r[a].push(i),r},[])}for(var r=[],i=[],o=function(e,o){var a=JSON.stringify(n.call(s[1],t[e],e,t)),c=i.findIndex(function(t){return t===a});c<0&&(c=i.push(a)-1),r[c]||(r[c]=[]),r[c].push(t[e])},s=arguments,a=0,c=t.length;a<c;a++)o(a);return r}(this,t)},Array.prototype.sum=function(t){return function(t,n){for(var e,r=0,i=t.length;r<i;r++)0==r?e=n?n.call(arguments[2],t[r],r,t):t[r]:e+=n?n.call(arguments[2],t[r],r,t):t[r];return e}(this,t)};var Component=function(){function t(){}return t.prototype.update=function(){},t.prototype.bind=function(t){return this.displayRender=t,this},t}(),Entity=function(){function t(t){this._updateOrder=0,this.name=t,this.transform=new Transform(this),this.components=[]}return Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.push(this);for(var n=0;n<this.transform.childCount;n++)this.transform.getChild(n).entity.attachToScene(t)},t.prototype.addComponent=function(t){return t.entity=this,this.components.push(t),t.initialize(),t},t.prototype.update=function(){this.components.forEach(function(t){return t.update()})},t.prototype.destory=function(){this.scene.entities.remove(this),this.trans