diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index e9e5d1aa..a5027e0a 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -1,93 +1,3 @@ -declare interface Array { - /** - * 获取满足表达式的数组元素索引 - * @param predicate 表达式 - */ - findIndex(predicate: (c: T) => boolean): number; - /** - * 是否存在满足表达式的数组元素 - * @param predicate 表达式 - */ - any(predicate: (c: T) => boolean): boolean; - /** - * 获取满足表达式的第一个或默认数组元素 - * @param predicate 表达式 - */ - firstOrDefault(predicate: (c: T) => boolean): T; - /** - * 获取满足表达式的第一个数组元素 - * @param predicate 表达式 - */ - find(predicate: (c: T) => boolean): T; - /** - * 筛选满足表达式的数组元素 - * @param predicate 表达式 - */ - where(predicate: (c: T) => boolean): Array; - /** - * 获取满足表达式的数组元素的计数 - * @param predicate 表达式 - */ - count(predicate: (c: T) => boolean): number; - /** - * 获取满足表达式的数组元素的数组 - * @param predicate 表达式 - */ - findAll(predicate: (c: T) => boolean): Array; - /** - * 是否有获取满足表达式的数组元素 - * @param value 值 - */ - contains(value: T): boolean; - /** - * 移除满足表达式的数组元素 - * @param predicate 表达式 - */ - removeAll(predicate: (c: T) => boolean): void; - /** - * 移除数组元素 - * @param element 数组元素 - */ - remove(element: T): boolean; - /** - * 移除特定索引数组元素 - * @param index 索引 - */ - removeAt(index: number): void; - /** - * 移除范围数组元素 - * @param index 开始索引 - * @param count 删除的个数 - */ - removeRange(index: number, count: number): void; - /** - * 获取通过选择器转换的数组 - * @param selector 选择器 - */ - select(selector: Function): Array; - /** - * 排序(升序) - * @param keySelector key选择器 - * @param comparer 比较器 - */ - orderBy(keySelector: Function, comparer: Function): Array; - /** - * 排序(降序) - * @param keySelector key选择器 - * @param comparer 比较器 - */ - orderByDescending(keySelector: Function, comparer: Function): Array; - /** - * 分组 - * @param keySelector key选择器 - */ - groupBy(keySelector: Function): Array; - /** - * 求和 - * @param selector 选择器 - */ - sum(selector: Function): number; -} declare module es { /** * 执行顺序 @@ -199,6 +109,7 @@ declare module es { _frameCounterElapsedTime: number; _frameCounter: number; _totalMemory: number; + _titleMemory: (totalMemory: number, frameCounter: number) => void; _scene: Scene; /** * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 @@ -409,7 +320,7 @@ declare module es { * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 * @param type */ - getOrCreateComponent(type: T): T; + getOrCreateComponent(type: any): T; /** * 获取typeName类型的所有组件,但不使用列表分配 * @param typeName @@ -3876,6 +3787,319 @@ declare namespace stopwatch { readonly duration: number; } } +declare module linq { + class Enumerable { + /** + * 在指定范围内生成一个整数序列。 + */ + static range(start: number, count: number): List; + /** + * 生成包含一个重复值的序列。 + */ + static repeat(element: T, count: number): List; + } +} +declare module linq { + /** + * 检查传递的参数是否为对象 + */ + const isObj: (x: T) => boolean; + /** + * 创建一个否定谓词结果的函数 + */ + const negate: (pred: (...args: T[]) => boolean) => (...args: T[]) => boolean; + /** + * 比较器助手 + */ + const composeComparers: (previousComparer: (a: T, b: T) => number, currentComparer: (a: T, b: T) => number) => (a: T, b: T) => number; + const keyComparer: (_keySelector: (key: T) => string, descending?: boolean) => (a: T, b: T) => number; +} +declare module linq { + type PredicateType = (value?: T, index?: number, list?: T[]) => boolean; + class List { + protected _elements: T[]; + /** + * 默认为列表的元素 + */ + constructor(elements?: T[]); + /** + * 在列表的末尾添加一个对象。 + */ + add(element: T): void; + /** + * 将一个对象追加到列表的末尾。 + */ + append(element: T): void; + /** + * 在列表的开头添加一个对象。 + */ + prepend(element: T): void; + /** + * 将指定集合的元素添加到列表的末尾。 + */ + addRange(elements: T[]): void; + /** + * 对序列应用累加器函数。 + */ + aggregate(accumulator: (accum: U, value?: T, index?: number, list?: T[]) => any, initialValue?: U): any; + /** + * 确定序列的所有元素是否满足一个条件。 + */ + all(predicate: PredicateType): boolean; + /** + * 确定序列是否包含任何元素。 + */ + any(): boolean; + any(predicate: PredicateType): boolean; + /** + * 计算通过对输入序列的每个元素调用转换函数获得的一系列数值的平均值。 + */ + average(): number; + average(transform: (value?: T, index?: number, list?: T[]) => any): number; + /** + * 将序列的元素转换为指定的类型。 + */ + cast(): List; + /** + * 从列表中删除所有元素。 + */ + clear(): void; + /** + * 连接两个序列。 + */ + concat(list: List): List; + /** + * 确定一个元素是否在列表中。 + */ + contains(element: T): boolean; + /** + * 返回序列中元素的数量。 + */ + count(): number; + count(predicate: PredicateType): number; + /** + * 返回指定序列的元素,或者如果序列为空,则返回单例集合中类型参数的默认值。 + */ + defaultIfEmpty(defaultValue?: T): List; + /** + * 根据指定的键选择器从序列中返回不同的元素。 + */ + distinctBy(keySelector: (key: T) => string | number): List; + /** + * 返回序列中指定索引处的元素。 + */ + elementAt(index: number): T; + /** + * 返回序列中指定索引处的元素,如果索引超出范围,则返回默认值。 + */ + elementAtOrDefault(index: number): T | null; + /** + * 通过使用默认的相等比较器来比较值,生成两个序列的差值集。 + */ + except(source: List): List; + /** + * 返回序列的第一个元素。 + */ + first(): T; + first(predicate: PredicateType): T; + /** + * 返回序列的第一个元素,如果序列不包含元素,则返回默认值。 + */ + firstOrDefault(): T; + firstOrDefault(predicate: PredicateType): T; + /** + * 对列表中的每个元素执行指定的操作。 + */ + forEach(action: (value?: T, index?: number, list?: T[]) => any): void; + /** + * 根据指定的键选择器函数对序列中的元素进行分组。 + */ + groupBy(grouper: (key: T) => string | number, mapper?: (element: T) => TResult): { + [key: string]: TResult[]; + }; + /** + * 根据键的相等将两个序列的元素关联起来,并将结果分组。默认的相等比较器用于比较键。 + */ + groupJoin(list: List, key1: (k: T) => any, key2: (k: U) => any, result: (first: T, second: List) => R): List; + /** + * 返回列表中某个元素第一次出现的索引。 + */ + indexOf(element: T): number; + /** + * 向列表中插入一个元素在指定索引处。 + */ + insert(index: number, element: T): void | Error; + /** + * 通过使用默认的相等比较器来比较值,生成两个序列的交集集。 + */ + intersect(source: List): List; + /** + * 基于匹配的键将两个序列的元素关联起来。默认的相等比较器用于比较键。 + */ + join(list: List, key1: (key: T) => any, key2: (key: U) => any, result: (first: T, second: U) => R): List; + /** + * 返回序列的最后一个元素。 + */ + last(): T; + last(predicate: PredicateType): T; + /** + * 返回序列的最后一个元素,如果序列不包含元素,则返回默认值。 + */ + lastOrDefault(): T; + lastOrDefault(predicate: PredicateType): T; + /** + * 返回泛型序列中的最大值。 + */ + max(): number; + max(selector: (value: T, index: number, array: T[]) => number): number; + /** + * 返回泛型序列中的最小值。 + */ + min(): number; + min(selector: (value: T, index: number, array: T[]) => number): number; + /** + * 根据指定的类型筛选序列中的元素。 + */ + ofType(type: any): List; + /** + * 根据键按升序对序列中的元素进行排序。 + */ + orderBy(keySelector: (key: T) => any, comparer?: (a: T, b: T) => number): List; + /** + * 根据键值降序对序列中的元素进行排序。 + */ + orderByDescending(keySelector: (key: T) => any, comparer?: (a: T, b: T) => number): List; + /** + * 按键按升序对序列中的元素执行后续排序。 + */ + thenBy(keySelector: (key: T) => any): List; + /** + * 根据键值按降序对序列中的元素执行后续排序。 + */ + thenByDescending(keySelector: (key: T) => any): List; + /** + * 从列表中删除第一个出现的特定对象。 + */ + remove(element: T): boolean; + /** + * 删除与指定谓词定义的条件匹配的所有元素。 + */ + removeAll(predicate: PredicateType): List; + /** + * 删除列表指定索引处的元素。 + */ + removeAt(index: number): void; + /** + * 颠倒整个列表中元素的顺序。 + */ + reverse(): List; + /** + * 将序列中的每个元素投射到一个新形式中。 + */ + select(selector: (element: T, index: number) => TOut): List; + /** + * 将序列的每个元素投影到一个列表中。并将得到的序列扁平化为一个序列。 + */ + selectMany>(selector: (element: T, index: number) => TOut): TOut; + /** + * 通过使用默认的相等比较器对元素的类型进行比较,确定两个序列是否相等。 + */ + sequenceEqual(list: List): boolean; + /** + * 返回序列中唯一的元素,如果序列中没有恰好一个元素,则抛出异常。 + */ + single(predicate?: PredicateType): T; + /** + * 返回序列中唯一的元素,如果序列为空,则返回默认值;如果序列中有多个元素,此方法将抛出异常。 + */ + singleOrDefault(predicate?: PredicateType): T; + /** + * 绕过序列中指定数量的元素,然后返回剩余的元素。 + */ + skip(amount: number): List; + /** + * 省略序列中最后指定数量的元素,然后返回剩余的元素。 + */ + skipLast(amount: number): List; + /** + * 只要指定条件为真,就绕过序列中的元素,然后返回剩余的元素。 + */ + skipWhile(predicate: PredicateType): List; + /** + * 计算通过对输入序列的每个元素调用转换函数获得的数值序列的和。 + */ + sum(): number; + sum(transform: (value?: T, index?: number, list?: T[]) => number): number; + /** + * 从序列的开始返回指定数量的连续元素。 + */ + take(amount: number): List; + /** + * 从序列的末尾返回指定数目的连续元素。 + */ + takeLast(amount: number): List; + /** + * 返回序列中的元素,只要指定的条件为真。 + */ + takeWhile(predicate: PredicateType): List; + /** + * 复制列表中的元素到一个新数组。 + */ + toArray(): T[]; + /** + * 创建一个从List< T>根据指定的键选择器函数。 + */ + toDictionary(key: (key: T) => TKey): List<{ + Key: TKey; + Value: T; + }>; + toDictionary(key: (key: T) => TKey, value: (value: T) => TValue): List<{ + Key: TKey; + Value: T | TValue; + }>; + /** + * 创建一个Set从一个Enumerable.List< T>。 + */ + toSet(): Set; + /** + * 创建一个List< T>从一个Enumerable.List< T>。 + */ + toList(): List; + /** + * 创建一个查找,TElement>从一个IEnumerable< T>根据指定的键选择器和元素选择器函数。 + */ + toLookup(keySelector: (key: T) => string | number, elementSelector: (element: T) => TResult): { + [key: string]: TResult[]; + }; + /** + * 基于谓词过滤一系列值。 + */ + where(predicate: PredicateType): List; + /** + * 将指定的函数应用于两个序列的对应元素,生成结果序列。 + */ + zip(list: List, result: (first: T, second: U) => TOut): List; + } + /** + * 表示已排序的序列。该类的方法是通过使用延迟执行来实现的。 + * 即时返回值是一个存储执行操作所需的所有信息的对象。 + * 在通过调用对象的ToDictionary、ToLookup、ToList或ToArray方法枚举对象之前,不会执行由该方法表示的查询 + */ + class OrderedList extends List { + private _comparer; + constructor(elements: T[], _comparer: (a: T, b: T) => number); + /** + * 按键按升序对序列中的元素执行后续排序。 + * @override + */ + thenBy(keySelector: (key: T) => any): List; + /** + * 根据键值按降序对序列中的元素执行后续排序。 + * @override + */ + thenByDescending(keySelector: (key: T) => any): List; + } +} declare module es { interface ITimer { context: any; diff --git a/source/bin/framework.js b/source/bin/framework.js index 56630103..a16a84f8 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -43,240 +43,6 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -Array.prototype.findIndex = function (predicate) { - function findIndex(array, predicate) { - for (var i = 0, len = array.length; i < len; i++) { - if (predicate.call(arguments[2], array[i], i, array)) { - return i; - } - } - return -1; - } - return findIndex(this, predicate); -}; -Array.prototype.any = function (predicate) { - function any(array, predicate) { - return array.findIndex(predicate) > -1; - } - return any(this, predicate); -}; -Array.prototype.firstOrDefault = function (predicate) { - function firstOrDefault(array, predicate) { - var index = array.findIndex(predicate); - return index == -1 ? null : array[index]; - } - return firstOrDefault(this, predicate); -}; -Array.prototype.find = function (predicate) { - function find(array, predicate) { - return array.firstOrDefault(predicate); - } - return find(this, predicate); -}; -Array.prototype.where = function (predicate) { - function where(array, predicate) { - if (typeof (array.reduce) === "function") { - return array.reduce(function (ret, element, index) { - if (predicate.call(arguments[2], element, index, array)) { - ret.push(element); - } - return ret; - }, []); - } - else { - var ret = []; - for (var i = 0, len = array.length; i < len; i++) { - var element = array[i]; - if (predicate.call(arguments[2], element, i, array)) { - ret.push(element); - } - } - return ret; - } - } - return where(this, predicate); -}; -Array.prototype.count = function (predicate) { - function count(array, predicate) { - return array.where(predicate).length; - } - return count(this, predicate); -}; -Array.prototype.findAll = function (predicate) { - function findAll(array, predicate) { - return array.where(predicate); - } - return findAll(this, predicate); -}; -Array.prototype.contains = function (value) { - function contains(array, value) { - for (var i = 0, len = array.length; i < len; i++) { - if (array[i] == value) { - return true; - } - } - return false; - } - return contains(this, value); -}; -Array.prototype.removeAll = function (predicate) { - function removeAll(array, predicate) { - var index; - do { - index = array.findIndex(predicate); - if (index >= 0) { - array.splice(index, 1); - } - } while (index >= 0); - } - removeAll(this, predicate); -}; -Array.prototype.remove = function (element) { - function remove(array, element) { - var index = array.findIndex(function (x) { - return x === element; - }); - if (index >= 0) { - array.splice(index, 1); - return true; - } - else { - return false; - } - } - return remove(this, element); -}; -Array.prototype.removeAt = function (index) { - function removeAt(array, index) { - array.splice(index, 1); - } - return removeAt(this, index); -}; -Array.prototype.removeRange = function (index, count) { - function removeRange(array, index, count) { - array.splice(index, count); - } - return removeRange(this, index, count); -}; -Array.prototype.select = function (selector) { - function select(array, selector) { - if (typeof (array.reduce) === "function") { - return array.reduce(function (ret, element, index) { - ret.push(selector.call(arguments[2], element, index, array)); - return ret; - }, []); - } - else { - var ret = []; - for (var i = 0, len = array.length; i < len; i++) { - ret.push(selector.call(arguments[2], array[i], i, array)); - } - return ret; - } - } - return select(this, selector); -}; -Array.prototype.orderBy = function (keySelector, comparer) { - function orderBy(array, keySelector, comparer) { - array.sort(function (x, y) { - var v1 = keySelector(x); - var v2 = keySelector(y); - if (comparer) { - return comparer(v1, v2); - } - else { - return (v1 > v2) ? 1 : -1; - } - }); - return array; - } - return orderBy(this, keySelector, comparer); -}; -Array.prototype.orderByDescending = function (keySelector, comparer) { - function orderByDescending(array, keySelector, comparer) { - array.sort(function (x, y) { - var v1 = keySelector(x); - var v2 = keySelector(y); - if (comparer) { - return -comparer(v1, v2); - } - else { - return (v1 < v2) ? 1 : -1; - } - }); - return array; - } - return orderByDescending(this, keySelector, comparer); -}; -Array.prototype.groupBy = function (keySelector) { - function groupBy(array, keySelector) { - if (typeof (array.reduce) === "function") { - var keys_1 = []; - return array.reduce(function (groups, element, index) { - var key = JSON.stringify(keySelector.call(arguments[1], element, index, array)); - var index2 = keys_1.findIndex(function (x) { - return x === key; - }); - if (index2 < 0) { - index2 = keys_1.push(key) - 1; - } - if (!groups[index2]) { - groups[index2] = []; - } - groups[index2].push(element); - return groups; - }, []); - } - else { - var groups = []; - var keys = []; - var _loop_1 = function (i, len) { - var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array)); - var index = keys.findIndex(function (x) { - return x === key; - }); - if (index < 0) { - index = keys.push(key) - 1; - } - if (!groups[index]) { - groups[index] = []; - } - groups[index].push(array[i]); - }; - var arguments_1 = arguments; - for (var i = 0, len = array.length; i < len; i++) { - _loop_1(i, len); - } - return groups; - } - } - return groupBy(this, keySelector); -}; -Array.prototype.sum = function (selector) { - function sum(array, selector) { - var ret; - for (var i = 0, len = array.length; i < len; i++) { - if (i == 0) { - if (selector) { - ret = selector.call(arguments[2], array[i], i, array); - } - else { - ret = array[i]; - } - } - else { - if (selector) { - ret += selector.call(arguments[2], array[i], i, array); - } - else { - ret += array[i]; - } - } - } - return ret; - } - return sum(this, selector); -}; var es; (function (es) { /** @@ -554,6 +320,8 @@ var es; if (memoryInfo != null) { this._totalMemory = Number((memoryInfo.totalJSHeapSize / 1048576).toFixed(2)); } + if (this._titleMemory) + this._titleMemory(this._totalMemory, this._frameCounter); this._frameCounter = 0; this._frameCounterElapsedTime -= 1; } @@ -992,9 +760,9 @@ var es; * @param type */ Entity.prototype.getOrCreateComponent = function (type) { - var comp = this.components.getComponent(es.TypeUtils.getType(type), true); + var comp = this.components.getComponent(type, true); if (!comp) { - comp = this.addComponent(type); + comp = this.addComponent(new type()); } return comp; }; @@ -1163,7 +931,7 @@ var es; */ Scene.prototype.getSceneComponent = function (type) { for (var i = 0; i < this._sceneComponents.length; i++) { - var component = this._sceneComponents[i]; + var component = this._sceneComponents.buffer[i]; if (component instanceof type) return component; } @@ -1217,9 +985,10 @@ var es; * @param renderer */ Scene.prototype.removeRenderer = function (renderer) { - if (!this._renderers.contains(renderer)) + var rendererList = new linq.List(this._renderers); + if (!rendererList.contains(renderer)) return; - this._renderers.remove(renderer); + rendererList.remove(renderer); renderer.unload(); }; /** @@ -1586,8 +1355,9 @@ var es; if (this._parent == parent) return this; if (!this._parent) { - this._parent._children.remove(this); - this._parent._children.push(this); + var children = new linq.List(this._parent._children); + children.remove(this); + children.add(this); } this._parent = parent; this.setDirty(DirtyType.positionDirty); @@ -2445,7 +2215,7 @@ var es; EntitySystem.prototype.initialize = function () { }; EntitySystem.prototype.onChanged = function (entity) { - var contains = this._entities.contains(entity); + var contains = new linq.List(this._entities).contains(entity); var interest = this._matcher.isInterestedEntity(entity); if (interest && !contains) this.add(entity); @@ -2459,7 +2229,7 @@ var es; EntitySystem.prototype.onAdded = function (entity) { }; EntitySystem.prototype.remove = function (entity) { - this._entities.remove(entity); + new linq.List(this._entities).remove(entity); this.onRemoved(entity); }; EntitySystem.prototype.onRemoved = function (entity) { @@ -2717,14 +2487,16 @@ var es; this._componentsToAdd.push(component); }; ComponentList.prototype.remove = function (component) { - if (this._componentsToRemove.contains(component)) + var componentToRemove = new linq.List(this._componentsToRemove); + var componentToAdd = new linq.List(this._componentsToAdd); + if (componentToRemove.contains(component)) console.warn("\u60A8\u6B63\u5728\u5C1D\u8BD5\u5220\u9664\u4E00\u4E2A\u60A8\u5DF2\u7ECF\u5220\u9664\u7684\u7EC4\u4EF6(" + component + ")"); // 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除 - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); + if (componentToAdd.contains(component)) { + componentToAdd.remove(component); return; } - this._componentsToRemove.push(component); + componentToRemove.add(component); }; /** * 立即从组件列表中删除所有组件 @@ -3031,7 +2803,7 @@ var es; EntityList.prototype.removeFromTagList = function (entity) { var list = this._entityDict.get(entity.tag); if (list) { - list.remove(entity); + new linq.List(list).remove(entity); } }; EntityList.prototype.update = function () { @@ -3183,7 +2955,7 @@ var es; this._processors.push(processor); }; EntityProcessorList.prototype.remove = function (processor) { - this._processors.remove(processor); + new linq.List(this._processors).remove(processor); }; EntityProcessorList.prototype.onComponentAdded = function (entity) { this.notifyEntityChanged(entity); @@ -3565,7 +3337,7 @@ var es; if (index >= this.length) throw new Error("index超出范围!"); this.length--; - this.buffer.removeAt(index); + new linq.List(this.buffer).removeAt(index); }; /** * 检查项目是否在FastList中 @@ -3831,13 +3603,14 @@ var es; this.addToRenderLayerList(component, component.renderLayer); }; RenderableComponentList.prototype.remove = function (component) { - this._components.remove(component); - this._componentsByRenderLayer.get(component.renderLayer).remove(component); + new linq.List(this._components).remove(component); + new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component); }; RenderableComponentList.prototype.updateRenderableRenderLayer = function (component, oldRenderLayer, newRenderLayer) { // 需要注意的是,如果渲染层在组件update之前发生了改变 - if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) { - this._componentsByRenderLayer.get(oldRenderLayer).remove(component); + var oldRenderLayers = new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)); + if (this._componentsByRenderLayer.has(oldRenderLayer) && oldRenderLayers.contains(component)) { + oldRenderLayers.remove(component); this.addToRenderLayerList(component, newRenderLayer); } }; @@ -3846,22 +3619,24 @@ var es; * @param renderLayer */ RenderableComponentList.prototype.setRenderLayerNeedsComponentSort = function (renderLayer) { - if (!this._unsortedRenderLayers.contains(renderLayer)) - this._unsortedRenderLayers.push(renderLayer); + var unsortedRenderLayers = new linq.List(this._unsortedRenderLayers); + if (!unsortedRenderLayers.contains(renderLayer)) + unsortedRenderLayers.add(renderLayer); this.componentsNeedSort = true; }; RenderableComponentList.prototype.setNeedsComponentSort = function () { this.componentsNeedSort = true; }; RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) { - var list = this.componentsWithRenderLayer(renderLayer); + var list = new linq.List(this.componentsWithRenderLayer(renderLayer)); if (list.contains(component)) { console.warn("组件呈现层列表已经包含此组件"); return; } - list.push(component); - if (!this._unsortedRenderLayers.contains(renderLayer)) - this._unsortedRenderLayers.push(renderLayer); + list.add(component); + var unsortedRenderLayers = new linq.List(this._unsortedRenderLayers); + if (!unsortedRenderLayers.contains(renderLayer)) + unsortedRenderLayers.add(renderLayer); this.componentsNeedSort = true; }; /** @@ -6505,7 +6280,7 @@ var es; if (!cell) console.log("\u4ECE\u4E0D\u5B58\u5728\u78B0\u649E\u5668\u7684\u5355\u5143\u683C\u4E2D\u79FB\u9664\u78B0\u649E\u5668: [" + collider + "]"); else - cell.remove(collider); + new linq.List(cell).remove(collider); } } }; @@ -6690,8 +6465,9 @@ var es; */ NumberDictionary.prototype.remove = function (obj) { this._store.forEach(function (list) { - if (list.contains(obj)) - list.remove(obj); + var linqList = new linq.List(list); + if (linqList.contains(obj)) + linqList.remove(obj); }); }; NumberDictionary.prototype.tryGetValue = function (x, y) { @@ -6732,7 +6508,7 @@ var es; for (var i = 0; i < cell.length; i++) { var potential = cell[i]; // 管理我们已经处理过的碰撞器 - if (this._checkedColliders.contains(potential)) + if (new linq.List(this._checkedColliders).contains(potential)) continue; this._checkedColliders.push(potential); // 只有当我们被设置为这样做时才会点击触发器 @@ -7935,7 +7711,7 @@ var ArrayUtils = /** @class */ (function () { * @param item */ ArrayUtils.addIfNotPresent = function (list, item) { - if (list.contains(item)) + if (new linq.List(list).contains(item)) return false; list.push(item); return true; @@ -8251,7 +8027,7 @@ var es; var messageData = this._messageTable.get(eventType); var index = messageData.findIndex(function (data) { return data.func == handler; }); if (index != -1) - messageData.removeAt(index); + new linq.List(messageData).removeAt(index); }; /** * 触发该事件 @@ -9404,6 +9180,538 @@ var stopwatch; /** 所有新实例的默认“getSystemTime”实现 */ var _defaultSystemTimeGetter = Date.now; })(stopwatch || (stopwatch = {})); +var linq; +(function (linq) { + var Enumerable = /** @class */ (function () { + function Enumerable() { + } + /** + * 在指定范围内生成一个整数序列。 + */ + Enumerable.range = function (start, count) { + var result = new linq.List(); + while (count--) { + result.add(start++); + } + return result; + }; + /** + * 生成包含一个重复值的序列。 + */ + Enumerable.repeat = function (element, count) { + var result = new linq.List(); + while (count--) { + result.add(element); + } + return result; + }; + return Enumerable; + }()); + linq.Enumerable = Enumerable; +})(linq || (linq = {})); +var linq; +(function (linq) { + /** + * 检查传递的参数是否为对象 + */ + linq.isObj = function (x) { return !!x && typeof x === 'object'; }; + /** + * 创建一个否定谓词结果的函数 + */ + linq.negate = function (pred) { return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return !pred.apply(void 0, args); + }; }; + /** + * 比较器助手 + */ + linq.composeComparers = function (previousComparer, currentComparer) { return function (a, b) { + return previousComparer(a, b) || currentComparer(a, b); + }; }; + linq.keyComparer = function (_keySelector, descending) { return function (a, b) { + var sortKeyA = _keySelector(a); + var sortKeyB = _keySelector(b); + if (sortKeyA > sortKeyB) { + return !descending ? 1 : -1; + } + else if (sortKeyA < sortKeyB) { + return !descending ? -1 : 1; + } + else { + return 0; + } + }; }; +})(linq || (linq = {})); +var linq; +(function (linq) { + var List = /** @class */ (function () { + /** + * 默认为列表的元素 + */ + function List(elements) { + if (elements === void 0) { elements = []; } + this._elements = elements; + } + /** + * 在列表的末尾添加一个对象。 + */ + List.prototype.add = function (element) { + this._elements.push(element); + }; + /** + * 将一个对象追加到列表的末尾。 + */ + List.prototype.append = function (element) { + this.add(element); + }; + /** + * 在列表的开头添加一个对象。 + */ + List.prototype.prepend = function (element) { + this._elements.unshift(element); + }; + /** + * 将指定集合的元素添加到列表的末尾。 + */ + List.prototype.addRange = function (elements) { + var _a; + (_a = this._elements).push.apply(_a, elements); + }; + /** + * 对序列应用累加器函数。 + */ + List.prototype.aggregate = function (accumulator, initialValue) { + return this._elements.reduce(accumulator, initialValue); + }; + /** + * 确定序列的所有元素是否满足一个条件。 + */ + List.prototype.all = function (predicate) { + return this._elements.every(predicate); + }; + List.prototype.any = function (predicate) { + return predicate + ? this._elements.some(predicate) + : this._elements.length > 0; + }; + List.prototype.average = function (transform) { + return this.sum(transform) / this.count(transform); + }; + /** + * 将序列的元素转换为指定的类型。 + */ + List.prototype.cast = function () { + return new List(this._elements); + }; + /** + * 从列表中删除所有元素。 + */ + List.prototype.clear = function () { + this._elements.length = 0; + }; + /** + * 连接两个序列。 + */ + List.prototype.concat = function (list) { + return new List(this._elements.concat(list.toArray())); + }; + /** + * 确定一个元素是否在列表中。 + */ + List.prototype.contains = function (element) { + return this.any(function (x) { return x === element; }); + }; + List.prototype.count = function (predicate) { + return predicate ? this.where(predicate).count() : this._elements.length; + }; + /** + * 返回指定序列的元素,或者如果序列为空,则返回单例集合中类型参数的默认值。 + */ + List.prototype.defaultIfEmpty = function (defaultValue) { + return this.count() ? this : new List([defaultValue]); + }; + /** + * 根据指定的键选择器从序列中返回不同的元素。 + */ + List.prototype.distinctBy = function (keySelector) { + var groups = this.groupBy(keySelector); + return Object.keys(groups).reduce(function (res, key) { + res.add(groups[key][0]); + return res; + }, new List()); + }; + /** + * 返回序列中指定索引处的元素。 + */ + List.prototype.elementAt = function (index) { + if (index < this.count() && index >= 0) { + return this._elements[index]; + } + else { + throw new Error('ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.'); + } + }; + /** + * 返回序列中指定索引处的元素,如果索引超出范围,则返回默认值。 + */ + List.prototype.elementAtOrDefault = function (index) { + return index < this.count() && index >= 0 + ? this._elements[index] + : undefined; + }; + /** + * 通过使用默认的相等比较器来比较值,生成两个序列的差值集。 + */ + List.prototype.except = function (source) { + return this.where(function (x) { return !source.contains(x); }); + }; + List.prototype.first = function (predicate) { + if (this.count()) { + return predicate ? this.where(predicate).first() : this._elements[0]; + } + else { + throw new Error('InvalidOperationException: The source sequence is empty.'); + } + }; + List.prototype.firstOrDefault = function (predicate) { + return this.count(predicate) ? this.first(predicate) : undefined; + }; + /** + * 对列表中的每个元素执行指定的操作。 + */ + List.prototype.forEach = function (action) { + return this._elements.forEach(action); + }; + /** + * 根据指定的键选择器函数对序列中的元素进行分组。 + */ + List.prototype.groupBy = function (grouper, mapper) { + if (mapper === void 0) { mapper = function (val) { return val; }; } + var initialValue = {}; + return this.aggregate(function (ac, v) { + var key = grouper(v); + var existingGroup = ac[key]; + var mappedValue = mapper(v); + existingGroup + ? existingGroup.push(mappedValue) + : (ac[key] = [mappedValue]); + return ac; + }, initialValue); + }; + /** + * 根据键的相等将两个序列的元素关联起来,并将结果分组。默认的相等比较器用于比较键。 + */ + List.prototype.groupJoin = function (list, key1, key2, result) { + return this.select(function (x) { + return result(x, list.where(function (z) { return key1(x) === key2(z); })); + }); + }; + /** + * 返回列表中某个元素第一次出现的索引。 + */ + List.prototype.indexOf = function (element) { + return this._elements.indexOf(element); + }; + /** + * 向列表中插入一个元素在指定索引处。 + */ + List.prototype.insert = function (index, element) { + if (index < 0 || index > this._elements.length) { + throw new Error('Index is out of range.'); + } + this._elements.splice(index, 0, element); + }; + /** + * 通过使用默认的相等比较器来比较值,生成两个序列的交集集。 + */ + List.prototype.intersect = function (source) { + return this.where(function (x) { return source.contains(x); }); + }; + /** + * 基于匹配的键将两个序列的元素关联起来。默认的相等比较器用于比较键。 + */ + List.prototype.join = function (list, key1, key2, result) { + return this.selectMany(function (x) { + return list.where(function (y) { return key2(y) === key1(x); }).select(function (z) { return result(x, z); }); + }); + }; + List.prototype.last = function (predicate) { + if (this.count()) { + return predicate + ? this.where(predicate).last() + : this._elements[this.count() - 1]; + } + else { + throw Error('InvalidOperationException: The source sequence is empty.'); + } + }; + List.prototype.lastOrDefault = function (predicate) { + return this.count(predicate) ? this.last(predicate) : undefined; + }; + List.prototype.max = function (selector) { + var id = function (x) { return x; }; + return Math.max.apply(Math, this._elements.map(selector || id)); + }; + List.prototype.min = function (selector) { + var id = function (x) { return x; }; + return Math.min.apply(Math, this._elements.map(selector || id)); + }; + /** + * 根据指定的类型筛选序列中的元素。 + */ + List.prototype.ofType = function (type) { + var typeName; + switch (type) { + case Number: + typeName = typeof 0; + break; + case String: + typeName = typeof ''; + break; + case Boolean: + typeName = typeof true; + break; + case Function: + typeName = typeof function () { }; // tslint:disable-line no-empty + break; + default: + typeName = null; + break; + } + return typeName === null + ? this.where(function (x) { return x instanceof type; }).cast() + : this.where(function (x) { return typeof x === typeName; }).cast(); + }; + /** + * 根据键按升序对序列中的元素进行排序。 + */ + List.prototype.orderBy = function (keySelector, comparer) { + if (comparer === void 0) { comparer = linq.keyComparer(keySelector, false); } + // tslint:disable-next-line: no-use-before-declare + return new OrderedList(this._elements, comparer); + }; + /** + * 根据键值降序对序列中的元素进行排序。 + */ + List.prototype.orderByDescending = function (keySelector, comparer) { + if (comparer === void 0) { comparer = linq.keyComparer(keySelector, true); } + // tslint:disable-next-line: no-use-before-declare + return new OrderedList(this._elements, comparer); + }; + /** + * 按键按升序对序列中的元素执行后续排序。 + */ + List.prototype.thenBy = function (keySelector) { + return this.orderBy(keySelector); + }; + /** + * 根据键值按降序对序列中的元素执行后续排序。 + */ + List.prototype.thenByDescending = function (keySelector) { + return this.orderByDescending(keySelector); + }; + /** + * 从列表中删除第一个出现的特定对象。 + */ + List.prototype.remove = function (element) { + return this.indexOf(element) !== -1 + ? (this.removeAt(this.indexOf(element)), true) + : false; + }; + /** + * 删除与指定谓词定义的条件匹配的所有元素。 + */ + List.prototype.removeAll = function (predicate) { + return this.where(linq.negate(predicate)); + }; + /** + * 删除列表指定索引处的元素。 + */ + List.prototype.removeAt = function (index) { + this._elements.splice(index, 1); + }; + /** + * 颠倒整个列表中元素的顺序。 + */ + List.prototype.reverse = function () { + return new List(this._elements.reverse()); + }; + /** + * 将序列中的每个元素投射到一个新形式中。 + */ + List.prototype.select = function (selector) { + return new List(this._elements.map(selector)); + }; + /** + * 将序列的每个元素投影到一个列表中。并将得到的序列扁平化为一个序列。 + */ + List.prototype.selectMany = function (selector) { + var _this = this; + return this.aggregate(function (ac, _, i) { return (ac.addRange(_this.select(selector) + .elementAt(i) + .toArray()), + ac); }, new List()); + }; + /** + * 通过使用默认的相等比较器对元素的类型进行比较,确定两个序列是否相等。 + */ + List.prototype.sequenceEqual = function (list) { + return this.all(function (e) { return list.contains(e); }); + }; + /** + * 返回序列中唯一的元素,如果序列中没有恰好一个元素,则抛出异常。 + */ + List.prototype.single = function (predicate) { + if (this.count(predicate) !== 1) { + throw new Error('The collection does not contain exactly one element.'); + } + else { + return this.first(predicate); + } + }; + /** + * 返回序列中唯一的元素,如果序列为空,则返回默认值;如果序列中有多个元素,此方法将抛出异常。 + */ + List.prototype.singleOrDefault = function (predicate) { + return this.count(predicate) ? this.single(predicate) : undefined; + }; + /** + * 绕过序列中指定数量的元素,然后返回剩余的元素。 + */ + List.prototype.skip = function (amount) { + return new List(this._elements.slice(Math.max(0, amount))); + }; + /** + * 省略序列中最后指定数量的元素,然后返回剩余的元素。 + */ + List.prototype.skipLast = function (amount) { + return new List(this._elements.slice(0, -Math.max(0, amount))); + }; + /** + * 只要指定条件为真,就绕过序列中的元素,然后返回剩余的元素。 + */ + List.prototype.skipWhile = function (predicate) { + var _this = this; + return this.skip(this.aggregate(function (ac) { return (predicate(_this.elementAt(ac)) ? ++ac : ac); }, 0)); + }; + List.prototype.sum = function (transform) { + return transform + ? this.select(transform).sum() + : this.aggregate(function (ac, v) { return (ac += +v); }, 0); + }; + /** + * 从序列的开始返回指定数量的连续元素。 + */ + List.prototype.take = function (amount) { + return new List(this._elements.slice(0, Math.max(0, amount))); + }; + /** + * 从序列的末尾返回指定数目的连续元素。 + */ + List.prototype.takeLast = function (amount) { + return new List(this._elements.slice(-Math.max(0, amount))); + }; + /** + * 返回序列中的元素,只要指定的条件为真。 + */ + List.prototype.takeWhile = function (predicate) { + var _this = this; + return this.take(this.aggregate(function (ac) { return (predicate(_this.elementAt(ac)) ? ++ac : ac); }, 0)); + }; + /** + * 复制列表中的元素到一个新数组。 + */ + List.prototype.toArray = function () { + return this._elements; + }; + List.prototype.toDictionary = function (key, value) { + var _this = this; + return this.aggregate(function (dicc, v, i) { + dicc[_this.select(key) + .elementAt(i) + .toString()] = value ? _this.select(value).elementAt(i) : v; + dicc.add({ + Key: _this.select(key).elementAt(i), + Value: value ? _this.select(value).elementAt(i) : v + }); + return dicc; + }, new List()); + }; + /** + * 创建一个Set从一个Enumerable.List< T>。 + */ + List.prototype.toSet = function () { + var result = new Set(); + for (var _i = 0, _a = this._elements; _i < _a.length; _i++) { + var x = _a[_i]; + result.add(x); + } + return result; + }; + /** + * 创建一个List< T>从一个Enumerable.List< T>。 + */ + List.prototype.toList = function () { + return this; + }; + /** + * 创建一个查找,TElement>从一个IEnumerable< T>根据指定的键选择器和元素选择器函数。 + */ + List.prototype.toLookup = function (keySelector, elementSelector) { + return this.groupBy(keySelector, elementSelector); + }; + /** + * 基于谓词过滤一系列值。 + */ + List.prototype.where = function (predicate) { + return new List(this._elements.filter(predicate)); + }; + /** + * 将指定的函数应用于两个序列的对应元素,生成结果序列。 + */ + List.prototype.zip = function (list, result) { + var _this = this; + return list.count() < this.count() + ? list.select(function (x, y) { return result(_this.elementAt(y), x); }) + : this.select(function (x, y) { return result(x, list.elementAt(y)); }); + }; + return List; + }()); + linq.List = List; + /** + * 表示已排序的序列。该类的方法是通过使用延迟执行来实现的。 + * 即时返回值是一个存储执行操作所需的所有信息的对象。 + * 在通过调用对象的ToDictionary、ToLookup、ToList或ToArray方法枚举对象之前,不会执行由该方法表示的查询 + */ + var OrderedList = /** @class */ (function (_super) { + __extends(OrderedList, _super); + function OrderedList(elements, _comparer) { + var _this = _super.call(this, elements) || this; + _this._comparer = _comparer; + _this._elements.sort(_this._comparer); + return _this; + } + /** + * 按键按升序对序列中的元素执行后续排序。 + * @override + */ + OrderedList.prototype.thenBy = function (keySelector) { + return new OrderedList(this._elements, linq.composeComparers(this._comparer, linq.keyComparer(keySelector, false))); + }; + /** + * 根据键值按降序对序列中的元素执行后续排序。 + * @override + */ + OrderedList.prototype.thenByDescending = function (keySelector) { + return new OrderedList(this._elements, linq.composeComparers(this._comparer, linq.keyComparer(keySelector, true))); + }; + return OrderedList; + }(List)); + linq.OrderedList = OrderedList; +})(linq || (linq = {})); var es; (function (es) { var Timer = /** @class */ (function () { @@ -9466,7 +9774,7 @@ var es; for (var i = this._timers.length - 1; i >= 0; i--) { if (this._timers[i].tick()) { this._timers[i].unload(); - this._timers.removeAt(i); + new linq.List(this._timers).removeAt(i); } } }; diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 64b5c995..fd6b5b6c 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.es={};var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r=1){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.prototype.onGraphicsDeviceReset=function(){null!=this._graphicsDeviceChangeTimer?this._graphicsDeviceChangeTimer.reset():this._graphicsDeviceChangeTimer=e.schedule(.05,!1,this,function(n){n.context._graphicsDeviceChangeTimer=null,e.emitter.emit(t.CoreEvents.GraphicsDeviceReset)})},e.prototype.initialize=function(){},e.prototype.update=function(e){return __awaiter(this,void 0,void 0,function(){var n;return __generator(this,function(i){switch(i.label){case 0:if(null!=e&&t.Time.update(e),null!=this._scene){for(n=this._globalManagers.length-1;n>=0;n--)this._globalManagers.buffer[n].enabled&&this._globalManagers.buffer[n].update();null!=this._sceneTransition&&(null==this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return[4,this.draw()];case 1:return i.sent(),[2]}})})},e.pauseOnFocusLost=!0,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){!function(t){t[t.GraphicsDeviceReset=0]="GraphicsDeviceReset",t[t.SceneChanged=1]="SceneChanged",t[t.OrientationChanged=2]="OrientationChanged",t[t.FrameUpdated=3]="FrameUpdated"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){var n=t.updateOrder-e.updateOrder;return 0==n&&(n=t.id-e.id),n},t}();t.EntityComparer=e;var n=function(){function n(e){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=e,this.id=n._idGenerator++,t.Core.entitySystemsEnabled&&(this.componentBits=new t.BitSet)}return Object.defineProperty(n.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),n.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},n.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},n.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},n.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene&&(this.scene.entities.markEntityListUnsorted(),this.scene.entities.markTagUnsorted(this.tag)),this},n.prototype.destroy=function(){this._isDestroyed=!0,this.scene.entities.remove(this),this.transform.parent=null;for(var t=this.transform.childCount-1;t>=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList()},e.prototype.render=function(){for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.createRotation(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.createScale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),this.parent||(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;n0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e,t.isIUpdatable=function(t){return void 0!==t.update}}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(){function e(){this.updateOrder=0,this._enabled=!0}return Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.onRemovedFromScene=function(){},e.prototype.update=function(){},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.setUpdateOrder=function(e){return this.updateOrder!=e&&(this.updateOrder=e,t.Core.scene._sceneComponents.sort(this)),this},e.prototype.compare=function(t){return this.updateOrder-t.updateOrder},e}();t.SceneComponent=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){for(var i=0;i>6>>>0;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n),this._bits.fill(0)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n>>>0;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=this._bits.length;this._bits.length=t+1,this._bits.fill(0,e,t+1)}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(e){this._components=new t.FastList,this._updatableComponents=new t.FastList,this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=e}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components.buffer},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){this._componentsToRemove.contains(t)&&console.warn("您正在尝试删除一个您已经删除的组件("+t+")"),this._componentsToAdd.contains(t)?this._componentsToAdd.remove(t):this._componentsToRemove.push(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){for(var n=0;n0){for(n=0;nthis._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=5),this.length=0,this.buffer=new Array(t)}return e.prototype.clear=function(){this.buffer.length=0,this.length=0},e.prototype.reset=function(){this.length=0},e.prototype.add=function(t){this.length==this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,10)),this.buffer[this.length++]=t},e.prototype.remove=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.length)throw new Error("index超出范围!");this.length--,this.buffer.removeAt(t)},e.prototype.contains=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,this.length+t))},e.prototype.addRange=function(t){for(var e=0,n=t;e=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i=0;e=this.allSet.nextSetBit(e+1))if(!t.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;on?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.approach=function(t,e,n){return ti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return!1}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.value=Math.max(r,e.value),n=Math.min(o,n),e.value>n)return!1}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return!1}else{var a=1/t.direction.y,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if(e.value=Math.max(c,e.value),n=Math.max(h,n),e.value>n)return!1}return!0},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return this.x^this.y^this.width^this.height},e.emptyRectangle=new e,e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.floor(Math.trunc(this.remainder));return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=null!=e?e:this.x}return Object.defineProperty(e,"zero",{get:function(){return new e(0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return new e(1,1)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return new e(1,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return new e(0,1)},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.normalize=function(t){var n=new e(t.x,t.y),i=1/Math.sqrt(n.x*n.x+n.y*n.y);return n.x*=i,n.y*=i,n},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.angle=function(n,i){return n=e.normalize(n),i=e.normalize(i),Math.acos(t.MathHelper.clamp(e.dot(n,i),-1,1))*t.MathHelper.Rad2Deg},e.negate=function(t){return t.x=-t.x,t.y=-t.y,t},e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.equals=function(t){return t instanceof e&&(t.x==this.x&&t.y==this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.circleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setValues=function(t,e,n,i){this.collider=t,this.fraction=e,this.distance=n,this.point=i},e.prototype.setValuesNonCollider=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset()},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("传入了一个空的结果数组。不会返回任何结果")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i){return void 0===i&&(i=e.allLayers),this._hitArray[0].reset(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0]},e.linecastAll=function(t,n,i,r){return void 0===r&&(r=e.allLayers),0==i.length?(console.warn("传入了一个空的hits数组。没有点击会被返回"),0):this._spatialHash.linecast(t,n,i,r)},e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e._hitArray=[new t.RaycastHit],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(e,n){this.start=e,this.end=n,this.direction=t.Vector2.subtract(this.end,this.start)}}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds;e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds,n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?s.remove(t):console.log("从不存在碰撞器的单元格中移除碰撞器: ["+t+"]")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;h=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;rr&&(r=s,i=o)}return e[i]},n.getClosestPointOnPolygonToPoint=function(e,n,i,r){i.value=Number.MAX_VALUE,r.x=0,r.y=0;for(var o=new t.Vector2(0,0),s=0,a=0;at.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return!1;var a,c=t.Vector2.add(s.start,t.Vector2.add(s.direction,new t.Vector2(r.value))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals,a=n.edgeNormals,c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=new t.Ref(0),a=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,s,i.normal),c=n.containsPoint(e.position);if(s.value>e.radius*e.radius&&!c)return!1;if(c)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var h=Math.sqrt(s.value);r=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(o,a)),new t.Vector2((e.radius-s.value)/h))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(o=o.add(e).add(t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),r.distance=t.Vector2.distance(e,r.point),r.normal=t.Vector2.normalize(t.Vector2.subtract(r.point,i.position)),r.fraction=r.distance/o,!0)},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=new t.Ref(0);return!!(o.rayIntersects(a,c)&&c.value<=1)&&(r.fraction=c.value,r.distance=i.length()*c.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c.value))),!0)},e}();t.ShapeCollisions=e}(es||(es={}));var ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t.shuffle=function(t){for(var e=t.length;e>1;){e--;var n=RandomUtils.randint(0,e+1),i=t[n];t[n]=t[e],t[e]=i}},t.addIfNotPresent=function(t,e){return!t.contains(e)&&(t.push(e),!0)},t.lastItem=function(t){return t[t.length-1]},t.randomItem=function(t){return t[RandomUtils.randint(0,t.length)]},t.randomItems=function(t,e){for(var n=new Set;n.size!=e;){var i=this.randomItem(t);n.has(i)||n.add(i)}var r=es.ListPool.obtain();return n.forEach(function(t){return r.push(t)}),r},t}();!function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],c=0;c>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(c++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(c++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,c=[],h=0;h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c.push(this._keyStr.charAt(r)),c.push(this._keyStr.charAt(o)),c.push(this._keyStr.charAt(s)),c.push(this._keyStr.charAt(a));return c=c.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i>16},set:function(t){this._packedValue=4278255615&this._packedValue|t<<16},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"g",{get:function(){return this._packedValue>>8},set:function(t){this._packedValue=4294902015&this._packedValue|t<<8},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"r",{get:function(){return this._packedValue},set:function(t){this._packedValue=4294967040&this._packedValue|t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"a",{get:function(){return this._packedValue>>24},set:function(t){this._packedValue=16777215&this._packedValue|t<<24},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"packedValue",{get:function(){return this._packedValue},set:function(t){this._packedValue=t},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return this._packedValue==t._packedValue},e}();t.Color=e}(es||(es={})),function(t){var e=function(){function e(){}return e.oppositeEdge=function(e){switch(e){case t.Edge.bottom:return t.Edge.top;case t.Edge.top:return t.Edge.bottom;case t.Edge.left:return t.Edge.right;case t.Edge.right:return t.Edge.left}},e.isHorizontal=function(e){return e==t.Edge.right||e==t.Edge.left},e.isVertical=function(e){return e==t.Edge.top||e==t.Edge.bottom},e}();t.EdgeExt=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.repeat=function(t,e){for(var n=[];e--;)n.push(t);return n},t}();t.Enumerable=e}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.toNumber=function(t){return null==t?0:Number(t)},t}();t.NumberExtension=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();!function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,r.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){return function(t){this.value=t}}();t.Ref=e}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelNumber=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e.divide(new t.Vector2(n)):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.removeAt(t))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file +window.es={};var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=1){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.prototype.onGraphicsDeviceReset=function(){null!=this._graphicsDeviceChangeTimer?this._graphicsDeviceChangeTimer.reset():this._graphicsDeviceChangeTimer=e.schedule(.05,!1,this,function(n){n.context._graphicsDeviceChangeTimer=null,e.emitter.emit(t.CoreEvents.GraphicsDeviceReset)})},e.prototype.initialize=function(){},e.prototype.update=function(e){return __awaiter(this,void 0,void 0,function(){var n;return __generator(this,function(i){switch(i.label){case 0:if(null!=e&&t.Time.update(e),null!=this._scene){for(n=this._globalManagers.length-1;n>=0;n--)this._globalManagers.buffer[n].enabled&&this._globalManagers.buffer[n].update();null!=this._sceneTransition&&(null==this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return[4,this.draw()];case 1:return i.sent(),[2]}})})},e.pauseOnFocusLost=!0,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){!function(t){t[t.GraphicsDeviceReset=0]="GraphicsDeviceReset",t[t.SceneChanged=1]="SceneChanged",t[t.OrientationChanged=2]="OrientationChanged",t[t.FrameUpdated=3]="FrameUpdated"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){var n=t.updateOrder-e.updateOrder;return 0==n&&(n=t.id-e.id),n},t}();t.EntityComparer=e;var n=function(){function n(e){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=e,this.id=n._idGenerator++,t.Core.entitySystemsEnabled&&(this.componentBits=new t.BitSet)}return Object.defineProperty(n.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),n.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},n.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},n.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},n.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene&&(this.scene.entities.markEntityListUnsorted(),this.scene.entities.markTagUnsorted(this.tag)),this},n.prototype.destroy=function(){this._isDestroyed=!0,this.scene.entities.remove(this),this.transform.parent=null;for(var t=this.transform.childCount-1;t>=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList()},e.prototype.render=function(){for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.createRotation(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.createScale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),this.parent||(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;n0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e,t.isIUpdatable=function(t){return void 0!==t.update}}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(){function e(){this.updateOrder=0,this._enabled=!0}return Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.onRemovedFromScene=function(){},e.prototype.update=function(){},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.setUpdateOrder=function(e){return this.updateOrder!=e&&(this.updateOrder=e,t.Core.scene._sceneComponents.sort(this)),this},e.prototype.compare=function(t){return this.updateOrder-t.updateOrder},e}();t.SceneComponent=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){for(var i=0;i>6>>>0;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n),this._bits.fill(0)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n>>>0;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=this._bits.length;this._bits.length=t+1,this._bits.fill(0,e,t+1)}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(e){this._components=new t.FastList,this._updatableComponents=new t.FastList,this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=e}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components.buffer},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){var e=new linq.List(this._componentsToRemove),n=new linq.List(this._componentsToAdd);e.contains(t)&&console.warn("您正在尝试删除一个您已经删除的组件("+t+")"),n.contains(t)?n.remove(t):e.add(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){for(var n=0;n0){for(n=0;nthis._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=5),this.length=0,this.buffer=new Array(t)}return e.prototype.clear=function(){this.buffer.length=0,this.length=0},e.prototype.reset=function(){this.length=0},e.prototype.add=function(t){this.length==this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,10)),this.buffer[this.length++]=t},e.prototype.remove=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.length)throw new Error("index超出范围!");this.length--,new linq.List(this.buffer).removeAt(t)},e.prototype.contains=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,this.length+t))},e.prototype.addRange=function(t){for(var e=0,n=t;e=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i=0;e=this.allSet.nextSetBit(e+1))if(!t.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;on?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.approach=function(t,e,n){return ti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return!1}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.value=Math.max(r,e.value),n=Math.min(o,n),e.value>n)return!1}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return!1}else{var a=1/t.direction.y,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if(e.value=Math.max(c,e.value),n=Math.max(h,n),e.value>n)return!1}return!0},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return this.x^this.y^this.width^this.height},e.emptyRectangle=new e,e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.floor(Math.trunc(this.remainder));return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=null!=e?e:this.x}return Object.defineProperty(e,"zero",{get:function(){return new e(0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return new e(1,1)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return new e(1,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return new e(0,1)},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.normalize=function(t){var n=new e(t.x,t.y),i=1/Math.sqrt(n.x*n.x+n.y*n.y);return n.x*=i,n.y*=i,n},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.angle=function(n,i){return n=e.normalize(n),i=e.normalize(i),Math.acos(t.MathHelper.clamp(e.dot(n,i),-1,1))*t.MathHelper.Rad2Deg},e.negate=function(t){return t.x=-t.x,t.y=-t.y,t},e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.equals=function(t){return t instanceof e&&(t.x==this.x&&t.y==this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.circleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setValues=function(t,e,n,i){this.collider=t,this.fraction=e,this.distance=n,this.point=i},e.prototype.setValuesNonCollider=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset()},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("传入了一个空的结果数组。不会返回任何结果")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i){return void 0===i&&(i=e.allLayers),this._hitArray[0].reset(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0]},e.linecastAll=function(t,n,i,r){return void 0===r&&(r=e.allLayers),0==i.length?(console.warn("传入了一个空的hits数组。没有点击会被返回"),0):this._spatialHash.linecast(t,n,i,r)},e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e._hitArray=[new t.RaycastHit],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(e,n){this.start=e,this.end=n,this.direction=t.Vector2.subtract(this.end,this.start)}}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds;e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds,n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?new linq.List(s).remove(t):console.log("从不存在碰撞器的单元格中移除碰撞器: ["+t+"]")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;h=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;rr&&(r=s,i=o)}return e[i]},n.getClosestPointOnPolygonToPoint=function(e,n,i,r){i.value=Number.MAX_VALUE,r.x=0,r.y=0;for(var o=new t.Vector2(0,0),s=0,a=0;at.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return!1;var a,c=t.Vector2.add(s.start,t.Vector2.add(s.direction,new t.Vector2(r.value))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals,a=n.edgeNormals,c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(y=Math.abs(y))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=new t.Ref(0),a=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,s,i.normal),c=n.containsPoint(e.position);if(s.value>e.radius*e.radius&&!c)return!1;if(c)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var h=Math.sqrt(s.value);r=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(o,a)),new t.Vector2((e.radius-s.value)/h))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(o=o.add(e).add(t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),r.distance=t.Vector2.distance(e,r.point),r.normal=t.Vector2.normalize(t.Vector2.subtract(r.point,i.position)),r.fraction=r.distance/o,!0)},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=new t.Ref(0);return!!(o.rayIntersects(a,c)&&c.value<=1)&&(r.fraction=c.value,r.distance=i.length()*c.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c.value))),!0)},e}();t.ShapeCollisions=e}(es||(es={}));var ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t.shuffle=function(t){for(var e=t.length;e>1;){e--;var n=RandomUtils.randint(0,e+1),i=t[n];t[n]=t[e],t[e]=i}},t.addIfNotPresent=function(t,e){return!new linq.List(t).contains(e)&&(t.push(e),!0)},t.lastItem=function(t){return t[t.length-1]},t.randomItem=function(t){return t[RandomUtils.randint(0,t.length)]},t.randomItems=function(t,e){for(var n=new Set;n.size!=e;){var i=this.randomItem(t);n.has(i)||n.add(i)}var r=es.ListPool.obtain();return n.forEach(function(t){return r.push(t)}),r},t}();!function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],c=0;c>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(c++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(c++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,c=[],h=0;h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c.push(this._keyStr.charAt(r)),c.push(this._keyStr.charAt(o)),c.push(this._keyStr.charAt(s)),c.push(this._keyStr.charAt(a));return c=c.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i>16},set:function(t){this._packedValue=4278255615&this._packedValue|t<<16},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"g",{get:function(){return this._packedValue>>8},set:function(t){this._packedValue=4294902015&this._packedValue|t<<8},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"r",{get:function(){return this._packedValue},set:function(t){this._packedValue=4294967040&this._packedValue|t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"a",{get:function(){return this._packedValue>>24},set:function(t){this._packedValue=16777215&this._packedValue|t<<24},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"packedValue",{get:function(){return this._packedValue},set:function(t){this._packedValue=t},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return this._packedValue==t._packedValue},e}();t.Color=e}(es||(es={})),function(t){var e=function(){function e(){}return e.oppositeEdge=function(e){switch(e){case t.Edge.bottom:return t.Edge.top;case t.Edge.top:return t.Edge.bottom;case t.Edge.left:return t.Edge.right;case t.Edge.right:return t.Edge.left}},e.isHorizontal=function(e){return e==t.Edge.right||e==t.Edge.left},e.isVertical=function(e){return e==t.Edge.top||e==t.Edge.bottom},e}();t.EdgeExt=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&new linq.List(n).removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.repeat=function(t,e){for(var n=[];e--;)n.push(t);return n},t}();t.Enumerable=e}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.toNumber=function(t){return null==t?0:Number(t)},t}();t.NumberExtension=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();!function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,r.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){return function(t){this.value=t}}();t.Ref=e}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelNumber=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e.divide(new t.Vector2(n)):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,this._elements.map(t||function(t){return t}))},e.prototype.min=function(t){return Math.min.apply(Math,this._elements.map(t||function(t){return t}))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){for(var t=new Set,e=0,n=this._elements;ethis._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),new linq.List(this._timers).removeAt(t))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts index 7607039a..d554ac31 100644 --- a/source/src/ECS/Core.ts +++ b/source/src/ECS/Core.ts @@ -63,6 +63,7 @@ module es { public _frameCounterElapsedTime: number = 0; public _frameCounter: number = 0; public _totalMemory: number = 0; + public _titleMemory: (totalMemory: number, frameCounter: number) => void; public _scene: Scene; /** @@ -188,6 +189,7 @@ module es { if (memoryInfo != null) { this._totalMemory = Number((memoryInfo.totalJSHeapSize / 1048576).toFixed(2)); } + if (this._titleMemory) this._titleMemory(this._totalMemory, this._frameCounter); this._frameCounter = 0; this._frameCounterElapsedTime -= 1; } diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 801749ca..9c68577c 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -343,10 +343,10 @@ module es { * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 * @param type */ - public getOrCreateComponent(type: T) { - let comp = this.components.getComponent(TypeUtils.getType(type), true); + public getOrCreateComponent(type) { + let comp = this.components.getComponent(type, true); if (!comp) { - comp = this.addComponent(type); + comp = this.addComponent(new type()); } return comp; diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index db04462f..c282b964 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -147,7 +147,7 @@ module es { */ public getSceneComponent(type) { for (let i = 0; i < this._sceneComponents.length; i++) { - let component = this._sceneComponents[i]; + let component = this._sceneComponents.buffer[i]; if (component instanceof type) return component as T; } @@ -212,9 +212,10 @@ module es { * @param renderer */ public removeRenderer(renderer: Renderer) { - if (!this._renderers.contains(renderer)) + let rendererList = new linq.List(this._renderers); + if (!rendererList.contains(renderer)) return; - this._renderers.remove(renderer); + rendererList.remove(renderer); renderer.unload(); } diff --git a/source/src/ECS/Systems/EntitySystem.ts b/source/src/ECS/Systems/EntitySystem.ts index 515c05ee..b24f545a 100644 --- a/source/src/ECS/Systems/EntitySystem.ts +++ b/source/src/ECS/Systems/EntitySystem.ts @@ -28,7 +28,7 @@ module es { } public onChanged(entity: Entity) { - let contains = this._entities.contains(entity); + let contains = new linq.List(this._entities).contains(entity); let interest = this._matcher.isInterestedEntity(entity); if (interest && !contains) @@ -46,7 +46,7 @@ module es { } public remove(entity: Entity) { - this._entities.remove(entity); + new linq.List(this._entities).remove(entity); this.onRemoved(entity); } diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts index f58007d4..543aca93 100644 --- a/source/src/ECS/Transform.ts +++ b/source/src/ECS/Transform.ts @@ -268,8 +268,9 @@ module es { return this; if (!this._parent) { - this._parent._children.remove(this); - this._parent._children.push(this); + let children = new linq.List(this._parent._children); + children.remove(this); + children.add(this); } this._parent = parent; diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 02197a5b..ebcfe3bc 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -50,16 +50,18 @@ module es { } public remove(component: Component) { - if (this._componentsToRemove.contains(component)) + let componentToRemove = new linq.List(this._componentsToRemove); + let componentToAdd = new linq.List(this._componentsToAdd); + if (componentToRemove.contains(component)) console.warn(`您正在尝试删除一个您已经删除的组件(${component})`); // 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除 - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); + if (componentToAdd.contains(component)) { + componentToAdd.remove(component); return; } - this._componentsToRemove.push(component); + componentToRemove.add(component); } /** diff --git a/source/src/ECS/Utils/EntityList.ts b/source/src/ECS/Utils/EntityList.ts index 7a086725..c304b7d3 100644 --- a/source/src/ECS/Utils/EntityList.ts +++ b/source/src/ECS/Utils/EntityList.ts @@ -122,7 +122,7 @@ module es { public removeFromTagList(entity: Entity) { let list = this._entityDict.get(entity.tag); if (list) { - list.remove(entity); + new linq.List(list).remove(entity); } } diff --git a/source/src/ECS/Utils/EntityProcessorList.ts b/source/src/ECS/Utils/EntityProcessorList.ts index bd7543b0..f20a14e0 100644 --- a/source/src/ECS/Utils/EntityProcessorList.ts +++ b/source/src/ECS/Utils/EntityProcessorList.ts @@ -7,7 +7,7 @@ module es { } public remove(processor: EntitySystem) { - this._processors.remove(processor); + new linq.List(this._processors).remove(processor); } public onComponentAdded(entity: Entity) { diff --git a/source/src/ECS/Utils/FastList.ts b/source/src/ECS/Utils/FastList.ts index b6a28763..e394a7b7 100644 --- a/source/src/ECS/Utils/FastList.ts +++ b/source/src/ECS/Utils/FastList.ts @@ -71,7 +71,7 @@ module es { throw new Error("index超出范围!"); this.length --; - this.buffer.removeAt(index); + new linq.List(this.buffer).removeAt(index); } /** diff --git a/source/src/ECS/Utils/RenderableComponentList.ts b/source/src/ECS/Utils/RenderableComponentList.ts index eedc1ae9..1209aac7 100644 --- a/source/src/ECS/Utils/RenderableComponentList.ts +++ b/source/src/ECS/Utils/RenderableComponentList.ts @@ -36,14 +36,15 @@ module es { } public remove(component: IRenderable) { - this._components.remove(component); - this._componentsByRenderLayer.get(component.renderLayer).remove(component); + new linq.List(this._components).remove(component); + new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component); } public updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number) { // 需要注意的是,如果渲染层在组件update之前发生了改变 - if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) { - this._componentsByRenderLayer.get(oldRenderLayer).remove(component); + let oldRenderLayers = new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)); + if (this._componentsByRenderLayer.has(oldRenderLayer) && oldRenderLayers.contains(component)) { + oldRenderLayers.remove(component); this.addToRenderLayerList(component, newRenderLayer); } } @@ -53,8 +54,9 @@ module es { * @param renderLayer */ public setRenderLayerNeedsComponentSort(renderLayer: number) { - if (!this._unsortedRenderLayers.contains(renderLayer)) - this._unsortedRenderLayers.push(renderLayer); + let unsortedRenderLayers = new linq.List(this._unsortedRenderLayers); + if (!unsortedRenderLayers.contains(renderLayer)) + unsortedRenderLayers.add(renderLayer); this.componentsNeedSort = true; } @@ -63,15 +65,16 @@ module es { } public addToRenderLayerList(component: IRenderable, renderLayer: number) { - let list = this.componentsWithRenderLayer(renderLayer); + let list = new linq.List(this.componentsWithRenderLayer(renderLayer)); if (list.contains(component)) { console.warn("组件呈现层列表已经包含此组件"); return; } - list.push(component); - if (!this._unsortedRenderLayers.contains(renderLayer)) - this._unsortedRenderLayers.push(renderLayer); + list.add(component); + let unsortedRenderLayers = new linq.List(this._unsortedRenderLayers); + if (!unsortedRenderLayers.contains(renderLayer)) + unsortedRenderLayers.add(renderLayer); this.componentsNeedSort = true; } diff --git a/source/src/Extension.ts b/source/src/Extension.ts deleted file mode 100644 index 68a25944..00000000 --- a/source/src/Extension.ts +++ /dev/null @@ -1,378 +0,0 @@ -declare interface Array { - /** - * 获取满足表达式的数组元素索引 - * @param predicate 表达式 - */ - findIndex(predicate: (c: T)=>boolean): number; - - /** - * 是否存在满足表达式的数组元素 - * @param predicate 表达式 - */ - any(predicate: (c: T) => boolean): boolean; - - /** - * 获取满足表达式的第一个或默认数组元素 - * @param predicate 表达式 - */ - firstOrDefault(predicate: (c: T)=>boolean): T; - - /** - * 获取满足表达式的第一个数组元素 - * @param predicate 表达式 - */ - find(predicate: (c: T) => boolean): T; - - /** - * 筛选满足表达式的数组元素 - * @param predicate 表达式 - */ - where(predicate: (c: T) => boolean): Array; - - /** - * 获取满足表达式的数组元素的计数 - * @param predicate 表达式 - */ - count(predicate: (c: T) => boolean): number; - - /** - * 获取满足表达式的数组元素的数组 - * @param predicate 表达式 - */ - findAll(predicate: (c: T) => boolean): Array; - - /** - * 是否有获取满足表达式的数组元素 - * @param value 值 - */ - contains(value: T): boolean; - - /** - * 移除满足表达式的数组元素 - * @param predicate 表达式 - */ - removeAll(predicate: (c: T) => boolean): void; - - /** - * 移除数组元素 - * @param element 数组元素 - */ - remove(element: T): boolean; - - /** - * 移除特定索引数组元素 - * @param index 索引 - */ - removeAt(index: number): void; - - /** - * 移除范围数组元素 - * @param index 开始索引 - * @param count 删除的个数 - */ - removeRange(index: number, count: number): void; - - /** - * 获取通过选择器转换的数组 - * @param selector 选择器 - */ - select(selector: Function): Array; - - /** - * 排序(升序) - * @param keySelector key选择器 - * @param comparer 比较器 - */ - orderBy(keySelector: Function, comparer: Function): Array; - - /** - * 排序(降序) - * @param keySelector key选择器 - * @param comparer 比较器 - */ - orderByDescending(keySelector: Function, comparer: Function): Array; - - /** - * 分组 - * @param keySelector key选择器 - */ - groupBy(keySelector: Function): Array; - - /** - * 求和 - * @param selector 选择器 - */ - sum(selector: Function): number; -} - -Array.prototype.findIndex = function (predicate) { - function findIndex(array, predicate) { - for (let i = 0, len = array.length; i < len; i++) { - if (predicate.call(arguments[2], array[i], i, array)) { - return i; - } - } - - return -1; - } - - return findIndex(this, predicate); -}; - -Array.prototype.any = function (predicate) { - function any(array, predicate) { - return array.findIndex(predicate) > -1; - } - - return any(this, predicate); -}; - -Array.prototype.firstOrDefault = function (predicate) { - function firstOrDefault(array, predicate) { - let index = array.findIndex(predicate); - return index == -1 ? null : array[index]; - } - - return firstOrDefault(this, predicate); -}; - -Array.prototype.find = function (predicate) { - function find(array, predicate) { - return array.firstOrDefault(predicate); - } - - return find(this, predicate); -}; - -Array.prototype.where = function (predicate) { - function where(array, predicate) { - if (typeof (array.reduce) === "function") { - return array.reduce(function (ret, element, index) { - if (predicate.call(arguments[2], element, index, array)) { - ret.push(element); - } - - return ret; - }, []); - } else { - let ret = []; - for (let i = 0, len = array.length; i < len; i++) { - let element = array[i]; - if (predicate.call(arguments[2], element, i, array)) { - ret.push(element); - } - } - - return ret; - } - } - - return where(this, predicate); -}; - -Array.prototype.count = function (predicate) { - function count(array, predicate) { - return array.where(predicate).length; - } - - return count(this, predicate); -}; - -Array.prototype.findAll = function (predicate) { - function findAll(array, predicate) { - return array.where(predicate); - } - - return findAll(this, predicate); -}; - -Array.prototype.contains = function (value) { - function contains(array, value) { - for (let i = 0, len = array.length; i < len; i++) { - if (array[i] == value) { - return true; - } - } - - return false; - } - - return contains(this, value); -}; - -Array.prototype.removeAll = function (predicate) { - function removeAll(array, predicate) { - let index; - do { - index = array.findIndex(predicate); - if (index >= 0) { - array.splice(index, 1); - } - } - while (index >= 0) - } - - removeAll(this, predicate); -}; - -Array.prototype.remove = function (element) { - function remove(array, element) { - let index = array.findIndex(function (x) { - return x === element; - }); - - if (index >= 0) { - array.splice(index, 1); - return true; - } else { - return false; - } - } - - return remove(this, element); -}; - -Array.prototype.removeAt = function (index) { - function removeAt(array, index) { - array.splice(index, 1); - } - - return removeAt(this, index); -}; - -Array.prototype.removeRange = function (index, count) { - function removeRange(array, index, count) { - array.splice(index, count); - } - - return removeRange(this, index, count); -}; - -Array.prototype.select = function (selector) { - function select(array, selector) { - if (typeof (array.reduce) === "function") { - return array.reduce(function (ret, element, index) { - ret.push(selector.call(arguments[2], element, index, array)); - return ret; - }, []); - } else { - let ret = []; - for (let i = 0, len = array.length; i < len; i++) { - ret.push(selector.call(arguments[2], array[i], i, array)) - } - - return ret; - } - } - - return select(this, selector); -}; - -Array.prototype.orderBy = function (keySelector, comparer) { - function orderBy(array, keySelector, comparer) { - array.sort(function (x, y) { - let v1 = keySelector(x); - let v2 = keySelector(y); - if (comparer) { - return comparer(v1, v2); - } else { - return (v1 > v2) ? 1 : -1; - } - }); - - return array; - } - - return orderBy(this, keySelector, comparer); -}; - -Array.prototype.orderByDescending = function (keySelector, comparer) { - function orderByDescending(array, keySelector, comparer) { - array.sort(function (x, y) { - let v1 = keySelector(x); - let v2 = keySelector(y); - if (comparer) { - return -comparer(v1, v2); - } else { - return (v1 < v2) ? 1 : -1; - } - }); - - return array; - } - - return orderByDescending(this, keySelector, comparer); -}; - -Array.prototype.groupBy = function (keySelector) { - function groupBy(array, keySelector) { - if (typeof (array.reduce) === "function") { - let keys = []; - return array.reduce(function (groups, element, index) { - let key = JSON.stringify(keySelector.call(arguments[1], element, index, array)); - let index2 = keys.findIndex(function (x) { - return x === key; - }); - - if (index2 < 0) { - index2 = keys.push(key) - 1; - } - - if (!groups[index2]) { - groups[index2] = []; - } - - groups[index2].push(element); - return groups; - }, []); - } else { - let groups = []; - let keys = []; - for (let i = 0, len = array.length; i < len; i++) { - let key = JSON.stringify(keySelector.call(arguments[1], array[i], i, array)); - let index = keys.findIndex(function (x) { - return x === key; - }); - - if (index < 0) { - index = keys.push(key) - 1; - } - - if (!groups[index]) { - groups[index] = []; - } - - groups[index].push(array[i]); - } - - return groups; - } - } - - return groupBy(this, keySelector); -}; - -Array.prototype.sum = function (selector) { - function sum(array, selector) { - let ret; - for (let i = 0, len = array.length; i < len; i++) { - if (i == 0) { - if (selector) { - ret = selector.call(arguments[2], array[i], i, array); - } else { - ret = array[i]; - } - } else { - if (selector) { - ret += selector.call(arguments[2], array[i], i, array); - } else { - ret += array[i]; - } - } - } - - return ret; - } - - return sum(this, selector); -}; \ No newline at end of file diff --git a/source/src/Physics/SpatialHash.ts b/source/src/Physics/SpatialHash.ts index a2259010..6aafd53f 100644 --- a/source/src/Physics/SpatialHash.ts +++ b/source/src/Physics/SpatialHash.ts @@ -74,7 +74,7 @@ module es { if (!cell) console.log(`从不存在碰撞器的单元格中移除碰撞器: [${collider}]`); else - cell.remove(collider); + new linq.List(cell).remove(collider); } } } @@ -281,8 +281,9 @@ module es { */ public remove(obj: Collider) { this._store.forEach(list => { - if (list.contains(obj)) - list.remove(obj); + let linqList = new linq.List(list); + if (linqList.contains(obj)) + linqList.remove(obj); }) } @@ -334,7 +335,7 @@ module es { let potential = cell[i]; // 管理我们已经处理过的碰撞器 - if (this._checkedColliders.contains(potential)) + if (new linq.List(this._checkedColliders).contains(potential)) continue; this._checkedColliders.push(potential); diff --git a/source/src/Utils/ArrayUtils.ts b/source/src/Utils/ArrayUtils.ts index 74b20ec5..c5bd55ec 100644 --- a/source/src/Utils/ArrayUtils.ts +++ b/source/src/Utils/ArrayUtils.ts @@ -255,7 +255,7 @@ class ArrayUtils { * @param item */ public static addIfNotPresent(list: T[], item: T) { - if (list.contains(item)) + if (new linq.List(list).contains(item)) return false; list.push(item); diff --git a/source/src/Utils/Emitter.ts b/source/src/Utils/Emitter.ts index 2d469a9a..dffa05dd 100644 --- a/source/src/Utils/Emitter.ts +++ b/source/src/Utils/Emitter.ts @@ -51,7 +51,7 @@ module es { let messageData = this._messageTable.get(eventType); let index = messageData.findIndex(data => data.func == handler); if (index != -1) - messageData.removeAt(index); + new linq.List(messageData).removeAt(index); } /** diff --git a/source/src/Utils/Linq/enumerable.ts b/source/src/Utils/Linq/enumerable.ts new file mode 100644 index 00000000..9a2b4f36 --- /dev/null +++ b/source/src/Utils/Linq/enumerable.ts @@ -0,0 +1,25 @@ +module linq { + export class Enumerable { + /** + * 在指定范围内生成一个整数序列。 + */ + public static range(start: number, count: number): List { + let result = new List(); + while (count--) { + result.add(start++) + } + return result + } + + /** + * 生成包含一个重复值的序列。 + */ + public static repeat(element: T, count: number): List { + let result = new List(); + while (count--) { + result.add(element) + } + return result + } + } +} \ No newline at end of file diff --git a/source/src/Utils/Linq/helpers.ts b/source/src/Utils/Linq/helpers.ts new file mode 100644 index 00000000..99fa508c --- /dev/null +++ b/source/src/Utils/Linq/helpers.ts @@ -0,0 +1,38 @@ +module linq { + /** + * 检查传递的参数是否为对象 + */ + export const isObj = (x: T): boolean => !!x && typeof x === 'object'; + + /** + * 创建一个否定谓词结果的函数 + */ + export const negate = ( + pred: (...args: T[]) => boolean + ): ((...args: T[]) => boolean) => (...args) => !pred(...args); + + /** + * 比较器助手 + */ + + export const composeComparers = ( + previousComparer: (a: T, b: T) => number, + currentComparer: (a: T, b: T) => number + ): ((a: T, b: T) => number) => (a: T, b: T) => + previousComparer(a, b) || currentComparer(a, b); + + export const keyComparer = ( + _keySelector: (key: T) => string, + descending?: boolean + ): ((a: T, b: T) => number) => (a: T, b: T) => { + const sortKeyA = _keySelector(a); + const sortKeyB = _keySelector(b); + if (sortKeyA > sortKeyB) { + return !descending ? 1 : -1 + } else if (sortKeyA < sortKeyB) { + return !descending ? -1 : 1 + } else { + return 0 + } + }; +} \ No newline at end of file diff --git a/source/src/Utils/Linq/list.ts b/source/src/Utils/Linq/list.ts new file mode 100644 index 00000000..80ebb143 --- /dev/null +++ b/source/src/Utils/Linq/list.ts @@ -0,0 +1,644 @@ +module linq { + type PredicateType = (value?: T, index?: number, list?: T[]) => boolean + + export class List { + protected _elements: T[]; + + /** + * 默认为列表的元素 + */ + constructor(elements: T[] = []) { + this._elements = elements + } + + /** + * 在列表的末尾添加一个对象。 + */ + public add(element: T): void { + this._elements.push(element) + } + + /** + * 将一个对象追加到列表的末尾。 + */ + public append(element: T): void { + this.add(element) + } + + /** + * 在列表的开头添加一个对象。 + */ + public prepend(element: T): void { + this._elements.unshift(element) + } + + /** + * 将指定集合的元素添加到列表的末尾。 + */ + public addRange(elements: T[]): void { + this._elements.push(...elements) + } + + /** + * 对序列应用累加器函数。 + */ + public aggregate( + accumulator: (accum: U, value?: T, index?: number, list?: T[]) => any, + initialValue?: U + ): any { + return this._elements.reduce(accumulator, initialValue) + } + + /** + * 确定序列的所有元素是否满足一个条件。 + */ + public all(predicate: PredicateType): boolean { + return this._elements.every(predicate) + } + + /** + * 确定序列是否包含任何元素。 + */ + public any(): boolean + public any(predicate: PredicateType): boolean + public any(predicate?: PredicateType): boolean { + return predicate + ? this._elements.some(predicate) + : this._elements.length > 0 + } + + /** + * 计算通过对输入序列的每个元素调用转换函数获得的一系列数值的平均值。 + */ + public average(): number + public average( + transform: (value?: T, index?: number, list?: T[]) => any + ): number + public average( + transform?: (value?: T, index?: number, list?: T[]) => any + ): number { + return this.sum(transform) / this.count(transform) + } + + /** + * 将序列的元素转换为指定的类型。 + */ + public cast(): List { + return new List(this._elements as any) + } + + /** + * 从列表中删除所有元素。 + */ + public clear(): void { + this._elements.length = 0 + } + + /** + * 连接两个序列。 + */ + public concat(list: List): List { + return new List(this._elements.concat(list.toArray())) + } + + /** + * 确定一个元素是否在列表中。 + */ + public contains(element: T): boolean { + return this.any(x => x === element) + } + + /** + * 返回序列中元素的数量。 + */ + public count(): number + public count(predicate: PredicateType): number + public count(predicate?: PredicateType): number { + return predicate ? this.where(predicate).count() : this._elements.length + } + + /** + * 返回指定序列的元素,或者如果序列为空,则返回单例集合中类型参数的默认值。 + */ + public defaultIfEmpty(defaultValue?: T): List { + return this.count() ? this : new List([defaultValue]) + } + + /** + * 根据指定的键选择器从序列中返回不同的元素。 + */ + public distinctBy(keySelector: (key: T) => string | number): List { + const groups = this.groupBy(keySelector); + return Object.keys(groups).reduce((res, key) => { + res.add(groups[key][0] as T); + return res + }, new List()) + } + + /** + * 返回序列中指定索引处的元素。 + */ + public elementAt(index: number): T { + if (index < this.count() && index >= 0) { + return this._elements[index] + } else { + throw new Error( + 'ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.' + ) + } + } + + /** + * 返回序列中指定索引处的元素,如果索引超出范围,则返回默认值。 + */ + public elementAtOrDefault(index: number): T | null { + return index < this.count() && index >= 0 + ? this._elements[index] + : undefined + } + + /** + * 通过使用默认的相等比较器来比较值,生成两个序列的差值集。 + */ + public except(source: List): List { + return this.where(x => !source.contains(x)) + } + + /** + * 返回序列的第一个元素。 + */ + public first(): T + public first(predicate: PredicateType): T + public first(predicate?: PredicateType): T { + if (this.count()) { + return predicate ? this.where(predicate).first() : this._elements[0] + } else { + throw new Error( + 'InvalidOperationException: The source sequence is empty.' + ) + } + } + + /** + * 返回序列的第一个元素,如果序列不包含元素,则返回默认值。 + */ + public firstOrDefault(): T + public firstOrDefault(predicate: PredicateType): T + public firstOrDefault(predicate?: PredicateType): T { + return this.count(predicate) ? this.first(predicate) : undefined + } + + /** + * 对列表中的每个元素执行指定的操作。 + */ + public forEach(action: (value?: T, index?: number, list?: T[]) => any): void { + return this._elements.forEach(action) + } + + /** + * 根据指定的键选择器函数对序列中的元素进行分组。 + */ + public groupBy( + grouper: (key: T) => string | number, + mapper: (element: T) => TResult = val => (val as any) as TResult + ): { [key: string]: TResult[] } { + const initialValue: { [key: string]: TResult[] } = {}; + return this.aggregate((ac, v: any) => { + const key = grouper(v); + const existingGroup = ac[key]; + const mappedValue = mapper(v); + existingGroup + ? existingGroup.push(mappedValue) + : (ac[key] = [mappedValue]); + return ac + }, initialValue) + } + + /** + * 根据键的相等将两个序列的元素关联起来,并将结果分组。默认的相等比较器用于比较键。 + */ + public groupJoin( + list: List, + key1: (k: T) => any, + key2: (k: U) => any, + result: (first: T, second: List) => R + ): List { + return this.select(x => + result( + x, + list.where(z => key1(x) === key2(z)) + ) + ) + } + + /** + * 返回列表中某个元素第一次出现的索引。 + */ + public indexOf(element: T): number { + return this._elements.indexOf(element) + } + + /** + * 向列表中插入一个元素在指定索引处。 + */ + public insert(index: number, element: T): void | Error { + if (index < 0 || index > this._elements.length) { + throw new Error('Index is out of range.') + } + + this._elements.splice(index, 0, element) + } + + /** + * 通过使用默认的相等比较器来比较值,生成两个序列的交集集。 + */ + public intersect(source: List): List { + return this.where(x => source.contains(x)) + } + + /** + * 基于匹配的键将两个序列的元素关联起来。默认的相等比较器用于比较键。 + */ + public join( + list: List, + key1: (key: T) => any, + key2: (key: U) => any, + result: (first: T, second: U) => R + ): List { + return this.selectMany(x => + list.where(y => key2(y) === key1(x)).select(z => result(x, z)) + ) + } + + /** + * 返回序列的最后一个元素。 + */ + public last(): T + public last(predicate: PredicateType): T + public last(predicate?: PredicateType): T { + if (this.count()) { + return predicate + ? this.where(predicate).last() + : this._elements[this.count() - 1] + } else { + throw Error('InvalidOperationException: The source sequence is empty.') + } + } + + /** + * 返回序列的最后一个元素,如果序列不包含元素,则返回默认值。 + */ + public lastOrDefault(): T + public lastOrDefault(predicate: PredicateType): T + public lastOrDefault(predicate?: PredicateType): T { + return this.count(predicate) ? this.last(predicate) : undefined + } + + /** + * 返回泛型序列中的最大值。 + */ + public max(): number + public max(selector: (value: T, index: number, array: T[]) => number): number + public max( + selector?: (value: T, index: number, array: T[]) => number + ): number { + const id = x => x; + return Math.max(...this._elements.map(selector || id)) + } + + /** + * 返回泛型序列中的最小值。 + */ + public min(): number + public min(selector: (value: T, index: number, array: T[]) => number): number + public min( + selector?: (value: T, index: number, array: T[]) => number + ): number { + const id = x => x; + return Math.min(...this._elements.map(selector || id)) + } + + /** + * 根据指定的类型筛选序列中的元素。 + */ + public ofType(type: any): List { + let typeName; + switch (type) { + case Number: + typeName = typeof 0; + break; + case String: + typeName = typeof ''; + break; + case Boolean: + typeName = typeof true; + break; + case Function: + typeName = typeof function () { }; // tslint:disable-line no-empty + break; + default: + typeName = null; + break + } + return typeName === null + ? this.where(x => x instanceof type).cast() + : this.where(x => typeof x === typeName).cast() + } + + /** + * 根据键按升序对序列中的元素进行排序。 + */ + public orderBy( + keySelector: (key: T) => any, + comparer = keyComparer(keySelector, false) + ): List { + // tslint:disable-next-line: no-use-before-declare + return new OrderedList(this._elements, comparer) + } + + /** + * 根据键值降序对序列中的元素进行排序。 + */ + public orderByDescending( + keySelector: (key: T) => any, + comparer = keyComparer(keySelector, true) + ): List { + // tslint:disable-next-line: no-use-before-declare + return new OrderedList(this._elements, comparer) + } + + /** + * 按键按升序对序列中的元素执行后续排序。 + */ + public thenBy(keySelector: (key: T) => any): List { + return this.orderBy(keySelector) + } + + /** + * 根据键值按降序对序列中的元素执行后续排序。 + */ + public thenByDescending(keySelector: (key: T) => any): List { + return this.orderByDescending(keySelector) + } + + /** + * 从列表中删除第一个出现的特定对象。 + */ + public remove(element: T): boolean { + return this.indexOf(element) !== -1 + ? (this.removeAt(this.indexOf(element)), true) + : false + } + + /** + * 删除与指定谓词定义的条件匹配的所有元素。 + */ + public removeAll(predicate: PredicateType): List { + return this.where(negate(predicate as any)) + } + + /** + * 删除列表指定索引处的元素。 + */ + public removeAt(index: number): void { + this._elements.splice(index, 1) + } + + /** + * 颠倒整个列表中元素的顺序。 + */ + public reverse(): List { + return new List(this._elements.reverse()) + } + + /** + * 将序列中的每个元素投射到一个新形式中。 + */ + public select( + selector: (element: T, index: number) => TOut + ): List { + return new List(this._elements.map(selector)) + } + + /** + * 将序列的每个元素投影到一个列表中。并将得到的序列扁平化为一个序列。 + */ + public selectMany>( + selector: (element: T, index: number) => TOut + ): TOut { + return this.aggregate( + (ac, _, i) => ( + ac.addRange( + this.select(selector) + .elementAt(i) + .toArray() + ), + ac + ), + new List() + ) + } + + /** + * 通过使用默认的相等比较器对元素的类型进行比较,确定两个序列是否相等。 + */ + public sequenceEqual(list: List): boolean { + return this.all(e => list.contains(e)) + } + + /** + * 返回序列中唯一的元素,如果序列中没有恰好一个元素,则抛出异常。 + */ + public single(predicate?: PredicateType): T { + if (this.count(predicate) !== 1) { + throw new Error('The collection does not contain exactly one element.') + } else { + return this.first(predicate) + } + } + + /** + * 返回序列中唯一的元素,如果序列为空,则返回默认值;如果序列中有多个元素,此方法将抛出异常。 + */ + public singleOrDefault(predicate?: PredicateType): T { + return this.count(predicate) ? this.single(predicate) : undefined + } + + /** + * 绕过序列中指定数量的元素,然后返回剩余的元素。 + */ + public skip(amount: number): List { + return new List(this._elements.slice(Math.max(0, amount))) + } + + /** + * 省略序列中最后指定数量的元素,然后返回剩余的元素。 + */ + public skipLast(amount: number): List { + return new List(this._elements.slice(0, -Math.max(0, amount))) + } + + /** + * 只要指定条件为真,就绕过序列中的元素,然后返回剩余的元素。 + */ + public skipWhile(predicate: PredicateType): List { + return this.skip( + this.aggregate(ac => (predicate(this.elementAt(ac)) ? ++ac : ac), 0) + ) + } + + /** + * 计算通过对输入序列的每个元素调用转换函数获得的数值序列的和。 + */ + public sum(): number + public sum( + transform: (value?: T, index?: number, list?: T[]) => number + ): number + public sum( + transform?: (value?: T, index?: number, list?: T[]) => number + ): number { + return transform + ? this.select(transform).sum() + : this.aggregate((ac, v) => (ac += +v), 0) + } + + /** + * 从序列的开始返回指定数量的连续元素。 + */ + public take(amount: number): List { + return new List(this._elements.slice(0, Math.max(0, amount))) + } + + /** + * 从序列的末尾返回指定数目的连续元素。 + */ + public takeLast(amount: number): List { + return new List(this._elements.slice(-Math.max(0, amount))) + } + + /** + * 返回序列中的元素,只要指定的条件为真。 + */ + public takeWhile(predicate: PredicateType): List { + return this.take( + this.aggregate(ac => (predicate(this.elementAt(ac)) ? ++ac : ac), 0) + ) + } + + /** + * 复制列表中的元素到一个新数组。 + */ + public toArray(): T[] { + return this._elements + } + + /** + * 创建一个从List< T>根据指定的键选择器函数。 + */ + public toDictionary( + key: (key: T) => TKey + ): List<{ Key: TKey; Value: T }> + public toDictionary( + key: (key: T) => TKey, + value: (value: T) => TValue + ): List<{ Key: TKey; Value: T | TValue }> + public toDictionary( + key: (key: T) => TKey, + value?: (value: T) => TValue + ): List<{ Key: TKey; Value: T | TValue }> { + return this.aggregate((dicc, v, i) => { + dicc[ + this.select(key) + .elementAt(i) + .toString() + ] = value ? this.select(value).elementAt(i) : v; + dicc.add({ + Key: this.select(key).elementAt(i), + Value: value ? this.select(value).elementAt(i) : v + }); + return dicc + }, new List<{ Key: TKey; Value: T | TValue }>()) + } + + /** + * 创建一个Set从一个Enumerable.List< T>。 + */ + public toSet() { + let result = new Set(); + for (let x of this._elements) + result.add(x); + + return result; + } + + /** + * 创建一个List< T>从一个Enumerable.List< T>。 + */ + public toList(): List { + return this + } + + /** + * 创建一个查找,TElement>从一个IEnumerable< T>根据指定的键选择器和元素选择器函数。 + */ + public toLookup( + keySelector: (key: T) => string | number, + elementSelector: (element: T) => TResult + ): { [key: string]: TResult[] } { + return this.groupBy(keySelector, elementSelector) + } + + /** + * 基于谓词过滤一系列值。 + */ + public where(predicate: PredicateType): List { + return new List(this._elements.filter(predicate)) + } + + /** + * 将指定的函数应用于两个序列的对应元素,生成结果序列。 + */ + public zip( + list: List, + result: (first: T, second: U) => TOut + ): List { + return list.count() < this.count() + ? list.select((x, y) => result(this.elementAt(y), x)) + : this.select((x, y) => result(x, list.elementAt(y))) + } + } + + /** + * 表示已排序的序列。该类的方法是通过使用延迟执行来实现的。 + * 即时返回值是一个存储执行操作所需的所有信息的对象。 + * 在通过调用对象的ToDictionary、ToLookup、ToList或ToArray方法枚举对象之前,不会执行由该方法表示的查询 + */ + export class OrderedList extends List { + constructor(elements: T[], private _comparer: (a: T, b: T) => number) { + super(elements); + this._elements.sort(this._comparer) + } + + /** + * 按键按升序对序列中的元素执行后续排序。 + * @override + */ + public thenBy(keySelector: (key: T) => any): List { + return new OrderedList( + this._elements, + composeComparers(this._comparer, keyComparer(keySelector, false)) + ) + } + + /** + * 根据键值按降序对序列中的元素执行后续排序。 + * @override + */ + public thenByDescending(keySelector: (key: T) => any): List { + return new OrderedList( + this._elements, + composeComparers(this._comparer, keyComparer(keySelector, true)) + ) + } + } +} \ No newline at end of file diff --git a/source/src/Utils/Timers/TimerManager.ts b/source/src/Utils/Timers/TimerManager.ts index 2a69c7cf..8a4ecd39 100644 --- a/source/src/Utils/Timers/TimerManager.ts +++ b/source/src/Utils/Timers/TimerManager.ts @@ -9,7 +9,7 @@ module es { for (let i = this._timers.length - 1; i >= 0; i --){ if (this._timers[i].tick()){ this._timers[i].unload(); - this._timers.removeAt(i); + new linq.List(this._timers).removeAt(i); } } }