diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 87f2a989..6d74144a 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -30,7 +30,6 @@ declare module es { onAddedToEntity(): void; onRemovedFromEntity(): void; onEntityTransformChanged(comp: transform.Component): void; - debugRender(camera: Camera): void; onEnabled(): void; onDisabled(): void; setEnabled(isEnabled: boolean): this; @@ -116,7 +115,6 @@ declare module es { onAddedToScene(): void; onRemovedFromScene(): void; update(): void; - debugRender(camera: Camera): void; addComponent(component: T): T; getComponent(type: any): T; hasComponent(type: any): boolean; @@ -131,7 +129,6 @@ declare module es { } declare module es { class Scene { - camera: Camera; readonly entities: EntityList; readonly renderableComponents: RenderableComponentList; readonly entityProcessors: EntityProcessorList; @@ -139,7 +136,6 @@ declare module es { _renderers: Renderer[]; _didSceneBegin: any; constructor(); - static createWithDefaultRenderer(): Scene; initialize(): void; onStart(): Promise; unload(): void; @@ -345,7 +341,6 @@ declare module es { setSize(width: number, height: number): this; setWidth(width: number): BoxCollider; setHeight(height: number): void; - debugRender(camera: Camera): void; toString(): string; } } @@ -354,7 +349,6 @@ declare module es { constructor(radius: number); radius: number; setRadius(radius: number): CircleCollider; - debugRender(camera: Camera): void; toString(): string; } } @@ -451,7 +445,6 @@ declare module es { onEntityTransformChanged(comp: transform.Component): void; onEntityEnabled(): void; onEntityDisabled(): void; - debugRender(camera: Camera): void; } } declare module es { @@ -602,9 +595,6 @@ declare module es { enabled: boolean; renderLayer: number; isVisible: boolean; - isVisibleFromCamera(camera: Camera): any; - render(camera: Camera): any; - debugRender(camera: Camera): any; } class RenderableComparer { compare(self: IRenderable, other: IRenderable): number; @@ -688,24 +678,14 @@ declare module es { } declare module es { abstract class Renderer { - camera: Camera; readonly renderOrder: number; shouldDebugRender: boolean; - protected constructor(renderOrder: number, camera?: Camera); + protected constructor(renderOrder: number); onAddedToScene(scene: Scene): void; unload(): void; abstract render(scene: Scene): any; onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; compareTo(other: Renderer): number; - protected beginRender(cam: Camera): void; - protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; - protected debugRender(scene: Scene, cam: Camera): void; - } -} -declare module es { - class DefaultRenderer extends Renderer { - constructor(); - render(scene: Scene): void; } } declare module es { diff --git a/source/bin/framework.js b/source/bin/framework.js index ef9c23a9..5613c5ef 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -320,8 +320,6 @@ var es; }; Component.prototype.onEntityTransformChanged = function (comp) { }; - Component.prototype.debugRender = function (camera) { - }; Component.prototype.onEnabled = function () { }; Component.prototype.onDisabled = function () { @@ -748,9 +746,6 @@ var es; Entity.prototype.update = function () { this.components.update(); }; - Entity.prototype.debugRender = function (camera) { - this.components.debugRender(camera); - }; Entity.prototype.addComponent = function (component) { component.entity = this; this.components.add(component); @@ -814,11 +809,6 @@ var es; this.entityProcessors = new es.EntityProcessorList(); this.initialize(); } - Scene.createWithDefaultRenderer = function () { - var scene = new Scene(); - scene.addRenderer(new es.DefaultRenderer()); - return scene; - }; Scene.prototype.initialize = function () { }; Scene.prototype.onStart = function () { @@ -835,10 +825,6 @@ var es; Scene.prototype.onDeactive = function () { }; Scene.prototype.begin = function () { - if (this._renderers.length == 0) { - this.addRenderer(new es.DefaultRenderer()); - console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); - } es.Physics.reset(); this.updateResolutionScaler(); if (this.entityProcessors) @@ -860,7 +846,6 @@ var es; this._sceneComponents[i].onRemovedFromScene(); } this._sceneComponents.length = 0; - this.camera = null; if (this.entityProcessors) this.entityProcessors.end(); this.unload(); @@ -1707,8 +1692,6 @@ var es; es.Physics.updateCollider(this); } }; - BoxCollider.prototype.debugRender = function (camera) { - }; BoxCollider.prototype.toString = function () { return "[BoxCollider: bounds: " + this.bounds + "]"; }; @@ -1745,8 +1728,6 @@ var es; } return this; }; - CircleCollider.prototype.debugRender = function (camera) { - }; CircleCollider.prototype.toString = function () { return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]"; }; @@ -2179,12 +2160,6 @@ var es; for (var i = 0; i < this._components.length; i++) this._components.buffer[i].onDisabled(); }; - ComponentList.prototype.debugRender = function (camera) { - for (var i = 0; i < this._components.length; i++) { - if (this._components.buffer[i].enabled) - this._components.buffer[i].debugRender(camera); - } - }; ComponentList.compareUpdatableOrder = new es.IUpdatableComparer(); return ComponentList; }()); @@ -3389,11 +3364,9 @@ var es; var es; (function (es) { var Renderer = (function () { - function Renderer(renderOrder, camera) { - if (camera === void 0) { camera = null; } + function Renderer(renderOrder) { this.renderOrder = 0; this.shouldDebugRender = true; - this.camera = camera; this.renderOrder = renderOrder; } Renderer.prototype.onAddedToScene = function (scene) { @@ -3405,43 +3378,11 @@ var es; Renderer.prototype.compareTo = function (other) { return this.renderOrder - other.renderOrder; }; - Renderer.prototype.beginRender = function (cam) { - }; - Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { - renderable.render(cam); - }; - Renderer.prototype.debugRender = function (scene, cam) { - for (var i = 0; i < scene.entities.count; i++) { - var entity = scene.entities.buffer[i]; - if (entity.enabled) - entity.debugRender(cam); - } - }; return Renderer; }()); es.Renderer = Renderer; })(es || (es = {})); var es; -(function (es) { - var DefaultRenderer = (function (_super) { - __extends(DefaultRenderer, _super); - function DefaultRenderer() { - return _super.call(this, 0, null) || this; - } - DefaultRenderer.prototype.render = function (scene) { - var cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); - for (var i = 0; i < scene.renderableComponents.count; i++) { - var renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); - } - }; - return DefaultRenderer; - }(es.Renderer)); - es.DefaultRenderer = DefaultRenderer; -})(es || (es = {})); -var es; (function (es) { var SceneTransition = (function () { function SceneTransition(sceneLoadAction) { diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index f8b87c3c..9a6b02da 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=0;t--)this._globalManagers[t].enabled&&this._globalManagers[t].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:e.sent(),e.label=2;case 2:return[4,this.draw()];case 3:return e.sent(),[2]}})})},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.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){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=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.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},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.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},e.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()}},e.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();this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList()},e.prototype.render=function(){if(0!=this._renderers.length)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.js}}(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},e.prototype.setUpdateOrder=function(e){return this.updateOrder!=e&&(this.updateOrder=e,t.Core.scene._sceneComponents.sort(this.compareTo)),this},e.prototype.compareTo=function(t){return this.updateOrder-t.updateOrder},e}();t.SceneComponent=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}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;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=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},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 e=0,n=this._entitiesToRemove;e0;){(i=this._addToSceneEntityList.shift()).onAddedToScene()}if(this._entitiesToAdded.length>0)if(this.frameAllocate&&this._entitiesToAdded.length>this.maxAllocate){for(var r=0;r0;)this.perEntityAddToScene();this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(function(t,e){return t.compareTo(e)}),this._isEntityListUnsorted=!1),0==this._addToSceneEntityList.length&&this._unsortedTags.size>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort(function(t,e){return t.compareTo(e)})}),this._unsortedTags.clear())},e.prototype.perEntityAddToScene=function(){var t=this._entitiesToAdded.shift();this._addToSceneEntityList.push(t),-1==this._entities.findIndex(function(e){return e.id==t.id})&&(this._entities.push(t),t.scene=this.scene,this.addToTagList(t),this.scene.entityProcessors.onEntityAdded(t))},e.prototype.findEntity=function(t){for(var e=0;ethis._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.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},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.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 Math.floor(this._timeSinceSceneLoad/t)>Math.floor((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(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}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)},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("An empty results array was passed in. No results will ever be returned.")},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.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},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=[],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++){var a=this.cellAtPosition(o,s,!0);a.firstOrDefault(function(t){return t==e})||a.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.debugDraw=function(t,e){void 0===e&&(e=1);for(var n=this.gridBounds.x;n<=this.gridBounds.right;n++)for(var i=this.gridBounds.y;i<=this.gridBounds.bottom;i++){var r=this.cellAtPosition(n,i);r&&r.length>0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;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=function(r){var o=c[r];if(o==n||!t.Flags.isFlagSet(i,o.physicsLayer.value))return"continue";e.intersects(o.bounds)&&(u._tempHashSet.firstOrDefault(function(t){return t==o})||u._tempHashSet.push(o))},u=this,l=0;l=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}();!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}();t.EqualityComparer=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)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 t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}();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.js}}(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(){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}(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=0;t--)this._globalManagers[t].enabled&&this._globalManagers[t].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:e.sent(),e.label=2;case 2:return[4,this.draw()];case 3:return e.sent(),[2]}})})},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.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){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=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.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},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.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},e.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()}},e.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();this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList()},e.prototype.render=function(){if(0!=this._renderers.length)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.js}}(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},e.prototype.setUpdateOrder=function(e){return this.updateOrder!=e&&(this.updateOrder=e,t.Core.scene._sceneComponents.sort(this.compareTo)),this},e.prototype.compareTo=function(t){return this.updateOrder-t.updateOrder},e}();t.SceneComponent=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}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;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=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},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 e=0,n=this._entitiesToRemove;e0;){(i=this._addToSceneEntityList.shift()).onAddedToScene()}if(this._entitiesToAdded.length>0)if(this.frameAllocate&&this._entitiesToAdded.length>this.maxAllocate){for(var r=0;r0;)this.perEntityAddToScene();this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(function(t,e){return t.compareTo(e)}),this._isEntityListUnsorted=!1),0==this._addToSceneEntityList.length&&this._unsortedTags.size>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort(function(t,e){return t.compareTo(e)})}),this._unsortedTags.clear())},e.prototype.perEntityAddToScene=function(){var t=this._entitiesToAdded.shift();this._addToSceneEntityList.push(t),-1==this._entities.findIndex(function(e){return e.id==t.id})&&(this._entities.push(t),t.scene=this.scene,this.addToTagList(t),this.scene.entityProcessors.onEntityAdded(t))},e.prototype.findEntity=function(t){for(var e=0;ethis._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.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},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.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 Math.floor(this._timeSinceSceneLoad/t)>Math.floor((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(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}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)},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("An empty results array was passed in. No results will ever be returned.")},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.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},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=[],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++){var a=this.cellAtPosition(o,s,!0);a.firstOrDefault(function(t){return t==e})||a.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.debugDraw=function(t,e){void 0===e&&(e=1);for(var n=this.gridBounds.x;n<=this.gridBounds.right;n++)for(var i=this.gridBounds.y;i<=this.gridBounds.bottom;i++){var r=this.cellAtPosition(n,i);r&&r.length>0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;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=function(r){var o=c[r];if(o==n||!t.Flags.isFlagSet(i,o.physicsLayer.value))return"continue";e.intersects(o.bounds)&&(u._tempHashSet.firstOrDefault(function(t){return t==o})||u._tempHashSet.push(o))},u=this,l=0;l=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}();!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}();t.EqualityComparer=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)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 t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}();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.js}}(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(){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 diff --git a/source/lib/wxgame.d.ts b/source/lib/wxgame.d.ts deleted file mode 100644 index b8adb9dd..00000000 --- a/source/lib/wxgame.d.ts +++ /dev/null @@ -1,3945 +0,0 @@ -/** - * IOS及安卓不支持: - * globalCompositeOperation不支持以下值:source-in source-out destination-atop lighter copy - * isPointInPath 不支持 - */ -declare class WxRenderingContext extends CanvasRenderingContext2D { -} - -/** - * IOS及安卓不支持: - * pixelStorei 当第一个参数是 gl.UNPACK_COLORSPACE_CONVERSION_WEBGL 时不支持 - * compressedTexImage2D不支持 - * compressedTexSubImage2D不支持 - * 安卓不支持: - * getExtension - * getSupportedExtensions - */ -declare class WxWebGLRenderingContext extends WebGLRenderingContext { - /** - * 将一个Canvas对应的Texture绑定到WebGL上下文。(目前该方法仅支持 iOS 6.6.6 以上版本,Android/开发者工具暂不支持。) - * 示例:gl.wxBindCanvasTexture(gl.TEXTURE_2D, canvas) - * @param texture WebGL的纹理类型枚举值 - * @param canvas 需要绑定为Texture的Canvas - */ - wxBindCanvasTexture(texture: number, canvas: Canvas): void; -} - -declare class WxPerformance { - /** - * 时间戳 - */ - now(): number; -} - -declare class Canvas { - /** - * 画布的宽度 - */ - width: number; - /** - * 画布的高度 - */ - height: number; - /** - * 将当前 Canvas 保存为一个临时文件,并生成相应的临时文件路径。 - */ - toTempFilePath(p: wx.types.ToTempFileParams): void; - /** - * toTempFilePath 的同步版本 - */ - toTempFilePathSync(p: wx.types.ToTempFileSyncParams): string; - /** - * 获取画布对象的绘图上下文 - * @param contextType 上下文类型 - * @param contextAttributes webgl 上下文属性,仅当 contextType 为 webgl 时有效 - */ - getContext(contextType: "2d" | "webgl", contextAttributes?: wx.types.RenderingContextConfig): WxRenderingContext | WxWebGLRenderingContext; - /** - * 把画布上的绘制内容以一个 data URI 的格式返回 - */ - toDataURL(): string; -} - -declare class Stats { - /** - * 文件的类型和存取的权限,对应 POSIX stat.st_mode - */ - mode: string; - /** - * 文件大小,单位:B,对应 POSIX stat.st_size - */ - size: number; - /** - * 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime - */ - lastAccessedTime: number; - /** - * 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime - */ - lastModifiedTime: number; - - /** - * 判断当前文件是否一个目录 - */ - isDirectory(): boolean; - /** - * 判断当前文件是否一个普通文件 - */ - isFile(): boolean; -} - -/** - * 日志管理类,最多保存5M的日志内容,超过5M后,旧的日志内容会被删除。 - * 对于小程序,用户可以通过使用 button 组件的 open-type="feedback" 来上传打印的日志。 - * 对于小游戏,用户可以通过使用 wx.createFeedbackButton 来创建上传打印的日志的按钮。 - * 开发者可以通过小程序管理后台左侧菜单“反馈管理”页面查看相关打印日志。 - * 基础库默认会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志。 - */ -declare class LogManager { - /** - * 写debug日志 - * @param args 要记录的日志内容 - */ - debug(... args: any[]): void; - - /** - * 写info日志 - * @param args 要记录的日志内容 - */ - info(... args: any[]): void; - - /** - * 写log日志 - * @param args 要记录的日志内容 - */ - log(... args: any[]): void; - - /** - * 写warn日志 - * @param args 要记录的日志内容 - */ - warn(... args: any[]): void; -} - -declare class FileSystemManager { - /** - * 重命名文件,可以把文件从 oldPath 移动到 newPath - */ - rename(param: wx.types.RenameParams): void; - /** - * FileSystemManager.rename 的同步版本 - * @param oldPath 源文件路径,可以是普通文件或目录 - * @param newPath 新文件路径 - * @throws 指定源文件或目标文件没有写权限 - * @throws 源文件不存在,或目标文件路径的上层目录不存在 - */ - renameSync(oldPath: string, newPath: string): void; - - /** - * 删除目录 - */ - rmdir(param: wx.types.RmdirParams): void; - /** - * rmdir 的同步版本 - * @param dirPath 要删除的目录路径 - * @param recursive 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。 - * @throws 目录不存在, 目录不为空, 指定的 dirPath 路径没有写权限 - */ - rmdirSync(dirPath: string, recursive?: boolean): void; - - /** - * 读取目录内文件列表 - */ - readdir(param: wx.types.ReaddirParams): void; - /** - * readdir的同步版本 - * @param dirPath 要读取的目录路径 - * @throws 目录不存在 - * @throws dirPath 不是目录 - * @throws 指定的 filePath 路径没有读权限 - */ - readdirSync(dirPath: string): ReadonlyArray; - - /** - * 创建目录 - */ - mkdir(param: wx.types.MkdirParams): void; - /** - * mkdir 的同步版本 - * @param dirPath 创建的目录路径 - * @param recursive 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。 - * @throws 上级目录不存在 - * @throws 指定的 filePath 路径没有写权限 - * @throws 有同名文件或目录 - */ - mkdirSync(dirPath: string, recursive?: boolean): void; - - /** - * 解链文件 - */ - unlink(param: wx.types.UnlinkParams): void; - /** - * unlink 的同步版本 - * @param filePath 要解链的文件路径 - * @throws 指定的 path 路径没有读权限 - * @throws 文件不存在 - * @throws 传入的 filePath 是一个目录 - */ - unlinkSync(filePath: string): void; - - /** - * 解压文件 - */ - unzip(param: wx.types.UnzipParams): void; - - /** - * 读取本地文件内容 - */ - readFile(param: wx.types.ReadfileParams): void; - /** - * readFile 的同步版本,读取并返回指定路径的文件的原始二进制内容 - * @param filePath 要读取的文件的路径 - * @throws 指定的 filePath 所在目录不存在 - * @throws 指定的 filePath 路径没有读权限 - */ - readFileSync(filePath: string): ArrayBuffer; - /** - * readFile 的同步版本,读取并按指定字符编码返回字符串 - * @param filePath 要读取的文件的路径 - * @param encoding 指定读取文件的字符编码 - * @throws 指定的 filePath 所在目录不存在 - * @throws 指定的 filePath 路径没有读权限 - */ - readFileSync(filePath: string, encoding: wx.types.FileContentEncoding): string; - - /** - * 获取文件 Stats 对象 - */ - stat(param: wx.types.StatParams): void; - /** - * stat 的同步版本 - * @param path 文件/目录路径 - * @throws 指定的 path 路径没有读权限 - * @throws 文件不存在 - */ - statSync(path: string): Stats; - - /** - * 写文件 - */ - writeFile(param: wx.types.WritefileParams): void; - /** - * writeFile 的同步版本,写入二进制原始文件数据 - * @param filePath 要写入的文件路径 - * @param data 要写入的二进制数据 - * @throws 指定的 filePath 所在目录不存在 - * @throws 指定的 filePath 路径没有写权限 - */ - writeFileSync(filePath: string, data: ArrayBuffer): void; - /** - * writeFile 的同步版本,写入文本字符串数据至文件 - * @param filePath 要写入的文件路径 - * @param data 要写入的文本内容 - * @param encoding 指定写入的文本的字符编码格式 - * @throws 指定的 filePath 所在目录不存在 - * @throws 指定的 filePath 路径没有写权限 - */ - writeFileSync(filePath: string, data: string, encoding: wx.types.FileContentEncoding): void; - - /** - * 判断文件/目录是否存在 - */ - access(param: wx.types.AccessfileParams): void; - /** - * access的同步版本 - * @param path 要判断是否存在的文件/目录路径 - * @throws 文件/目录不存在 - */ - accessSync(path: string): void; - - /** - * 复制文件 - */ - copyFile(param: wx.types.CopyfileParams): void; - /** - * copyFile 的同步版本 - * @param srcPath 源文件路径,只可以是普通文件 - * @param destPath 目标文件路径 - * @throws 指定目标文件路径没有写权限 - * @throws 源文件不存在,或目标文件路径的上层目录不存在 - */ - copyFileSync(srcPath: string, destPath: string): void; - - /** - * 获取该小程序下已保存的本地缓存文件列表 - * @param res.fileList.filePath 本地路径 - * @param res.fileList.size 本地文件大小,以字节为单位 - * @param res.fileList.createTime 文件创建时间 - */ - getSavedFileList(param: wx.types.CallbacksWithType): void; - - /** - * 获取该小程序下的 本地临时文件 或 本地缓存文件 信息 - */ - getFileInfo(param: wx.types.FileinfoParams): void; - - /** - * 删除该小程序下已保存的本地缓存文件(新版本应使用unlink) - */ - removeSavedFile(param: wx.types.RemovefileParams): void; - - /** - * 保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。 - */ - saveFile(param: wx.types.SavefileParams): void; - /** - * saveFile的同步版本 - * @param tempFilePath 临时存储文件路径 - * @param filePath 要存储的文件路径 - * @throws 指定的 tempFilePath 找不到文件 - * @throws 指定的 filePath 路径没有写权限 - * @throws 上级目录不存在 - */ - saveFileSync(tempFilePath: string, filePath?: string): string; - - /** - * 在文件结尾追加内容 - */ - appendFile(param: wx.types.AppendfileParams): void; - /** - * appendFile的同步版本 - * @param filePath 要追加内容的文件路径 - * @param data 要追加的文本或二进制数据 - * @param encoding 指定写入文件的字符编码 - * @throws 指定的 filePath 文件不存在 - * @throws 指定的 filePath 是一个已经存在的目录 - * @throws 指定的 filePath 路径没有写权限 - * @throws 指定的 filePath 是一个已经存在的目录 - */ - appendFileSync(filePath: string, data: string | ArrayBuffer, encoding: wx.types.FileContentEncoding): void; -} - -declare class DownloadTask { - /** - * 中断下载任务 - */ - abort(): void; - /** - * 监听下载进度变化事件 - * @param res.progress 下载进度百分比,值为0至100 - * @param res.totalBytesWritten 已经下载的数据长度,单位 Bytes - * @param res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes - */ - onProgressUpdate(callback: (res: { progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number }) => void): void; -} - -declare class RequestTask { - /** - * 中断请求任务 - */ - abort(): void; -} - -declare class SocketTask { - /** - * 通过WebSocket发送数据 - */ - send(param: wx.types.SocketSendParams): void; - /** - * 关闭WebSocket连接 - */ - close(param: wx.types.SocketCloseParams): void; - /** - * 监听WebSocket 连接打开事件 - */ - onOpen(callback: wx.types.SocketOpenCallback): void; - /** - * 监听WebSocket 连接关闭事件 - */ - onClose(callback: () => void): void; - /** - * 监听WebSocket 错误事件 - */ - onError(callback: wx.types.SocketErrorCallback): void; - /** - * 监听WebSocket 接受到服务器的消息事件 - */ - onMessage(callback: wx.types.SocketMessageCallback): void; -} - -/** - * 一个 UDP Socket 实例,默认使用 IPv4 协议。 - * 错误码: - * -1 系统错误 - * -2 socket接口错误 - * -3 发送失败,无接口权限 - * 1 发送失败,参数错误,address不合法 - * 2 发送失败,参数错误,port不合法 - */ -declare class UDPSocket { - /** - * 绑定一个系统随机分配的可用端口,或绑定一个指定的端口号 - * @param port 需要绑定的端口号,不指定时使用随机端口 - * @returns 绑定成功的端口号 - */ - bind(port?: number): number; - - /** - * 向指定的 IP 和 port 发送消息 - */ - send(param: wx.types.UDPSendParams): void; - - /** - * 关闭 UDP Socket 实例,相当于销毁。 在关闭之后,UDP Socket 实例不能再发送消息,每次调用 UDPSocket.send 将会触发错误事件, - * 并且 message 事件回调函数也不会再执行。在 UDPSocket 实例被创建后将被 Native 强引用,保证其不被 GC。在 UDPSocket.close 后 - * 将解除对其的强引用,让 UDPSocket 实例遵从 GC。 - */ - close(): void; - - /** - * 设置监听关闭事件回调 - * @param callback 关闭事件的回调函数 - */ - onClose(callback: () => void): void; - - /** - * 清除监听关闭事件回调 - * @param callback 之前监听的函数 - */ - offClose(callback: () => void): void; - - /** - * 监听错误事件 - * @param callback 错误回调函数 - */ - onError(callback: (res: { - /** - * 错误信息 - */ - errMsg: string; - }) => void): void; - - /** - * 取消监听错误事件 - * @param callback 之前设置的错误回调函数 - */ - offError(callback: (res: { - /** - * 错误信息 - */ - errMsg: string; - }) => void): void; - - /** - * 监听开始监听数据包消息的事件 - * @param callback 回调函数 - */ - onListening(callback: () => void): void; - - /** - * 取消监听开始监听数据包消息的事件 - * @param callback 之前设置的回调函数 - */ - offListening(callback: () => void): void; - - /** - * 监听收到消息的事件 - * @param callback 回调函数 - */ - onMessage(callback: (res: wx.types.UDPMessage) => void): void; - - /** - * 取消监听收到消息的事件 - * @param callback 之前设置的回调函数 - */ - offMessage(callback: (res: wx.types.UDPMessage) => void): void; -} - -declare class UploadTask { - /** - * 中断上传任务 - */ - abort(): void; - /** - * 监听上传进度变化事件 - * @param callback.res.progress 上传进度百分比 - * @param callback.res.totalBytesSent 已经上传的数据长度,单位 Bytes - * @param callback.res.totalBytesExpectedToSend 预期需要上传的数据总长度,单位 Bytes - */ - onProgressUpdate(callback: (res: { progress: number, totalBytesSent: number, totalBytesExpectedToSend: number }) => void): void; -} - -declare class KVData { - key: string; - value: string; -} - -declare class UserGameData { - /** - * 用户的微信头像 url - */ - avatarUrl: string; - /** - * 用户的微信昵称 - */ - nickname: string; - /** - * 用户的openid - */ - openid: string; - /** - * 用户的托管 KV 数据列表 - */ - KVDataList: ReadonlyArray; -} - -declare class CreatedButton { - type: wx.types.ButtonType; - text: string; - image: string; - style: wx.types.ButtonStyle; - show(): void; - hide(): void; - onTap(callback: (res?: any) => void): void; // res参数会被具体按钮的API定义覆盖为具体信息 - offTap(callback: (res?: any) => void): void; - destroy(): void; -} -declare class UserInfoButton extends CreatedButton { - onTap(callback: (res: { - /** - * 用户信息对象,不包含 openid 等敏感信息 - */ - userInfo: wx.types.UserInfo, - /** - * 不包括敏感信息的原始数据字符串,用于计算签名 - */ - rawData: string, - /** - * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822) - */ - signature: string, - /** - * 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) - */ - encryptedData: string, - /** - * 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) - */ - iv: string, - errMsg: string - }) => void): void; -} -declare class OpenSettingButton extends CreatedButton { - onTap(callback: () => void): void; - offTap(callback: () => void): void; -} -declare class GameClubButton extends CreatedButton { - icon: wx.types.GameClubButtonIcon; - onTap(callback: (res: { - errMsg: string; - }) => void): void; -} -declare class FeedbackButton extends CreatedButton { - onTap(callback: (res: { - errMsg: string; - }) => void): void; -} - -declare class OpenDataContext { - /** - * 开放数据域和主域共享的 sharedCanvas,注意在开放数据域内时getContext只能使用2d模式 - */ - canvas: Canvas; - /** - * 向开放数据域发送消息 - * @param message 要发送的消息,message 中及嵌套对象中 key 的 value 只能是 primitive value。即 number、string、boolean、null、undefined。 - */ - postMessage(message: any): void; -} - -declare class LoadSubpackageTask { - /** - * 监听分包加载进度变化事件 - * @param callback.res.progress 分包下载进度百分比 - * @param callback.res.totalBytesWritten 已经下载的数据长度,单位 Bytes - * @param callback.res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes - */ - onProgressUpdate(callback: (res: { progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number }) => void): void; -} - -declare class UpdateManager { - /** - * 应用更新包并重启 - */ - applyUpdate(): void; - /** - * 监听检查更新结果回调 - */ - onCheckForUpdate(callback: () => void): void; - /** - * 监听更新包下载成功回调 - */ - onUpdateReady(callback: () => void): void; - /** - * 监听更新包下载失败回调 - */ - onUpdateFailed(callback: () => void): void; -} - -declare class WxWorker { - /** - * 向主线程或Worker线程发送的消息。 - * @param message 需要发送的消息,必须是一个可序列化的 JavaScript 对象。 - */ - postMessage(message: any): void; - /** - * 结束当前 worker 线程,仅限在主线程 worker 对象上调用。 - */ - terminate(): void; - /** - * 监听接收主线程/Worker 线程向当前线程发送的消息 - * @param callback.res.message 接收主线程/Worker 线程向当前线程发送的消息 - */ - onMessage(callback: (res: { message: any }) => void): void; -} - -/** - * InnerAudioContext 实例,可通过 wx.createInnerAudioContext 接口获取实例。 - */ -declare class InnerAudioContext { - /** - * 音频资源的地址 - */ - src: string; - /** - * 是否自动播放 - */ - autoplay: boolean; - /** - * 是否循环播放 - */ - loop: boolean; - /** - * 是否遵循系统静音开关,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音 - */ - obeyMuteSwitch: boolean; - /** - * 当前音频的长度,单位 s。只有在当前有合法的 src 时返回 - */ - readonly duration: number; - /** - * 当前音频的播放位置,单位 s。只有在当前有合法的 src 时返回,时间不取整,保留小数点后 6 位 - */ - readonly currentTime: number; - /** - * 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播放 - */ - paused: boolean; - /** - * 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲 - */ - readonly buffered: number; - /** - * 音量。范围 0~1。 - */ - volume: number; - - /** - * 播放 - */ - play(): void; - /** - * 暂停。暂停后的音频再播放会从暂停处开始播放 - */ - pause(): void; - /** - * 停止。停止后的音频再播放会从头开始播放。 - */ - stop(): void; - /** - * 跳转到指定位置,单位 s - * @param position 跳转的时间 - */ - seek(position: number): void; - /** - * 销毁当前实例 - */ - destroy(): void; - /** - * 监听音频进入可以播放状态的事件 - */ - onCanplay(callback: () => void): void; - /** - * 取消监听音频进入可以播放状态的事件 - */ - offCanplay(callback: () => void): void; - /** - * 监听音频播放事件 - */ - onPlay(callback: () => void): void; - /** - * 取消监听音频播放事件 - */ - offPlay(callback: () => void): void; - /** - * 监听音频暂停事件 - */ - onPause(callback: () => void): void; - /** - * 取消监听音频暂停事件 - */ - offPause(callback: () => void): void; - /** - * 监听音频停止事件 - */ - onStop(callback: () => void): void; - /** - * 取消监听音频停止事件 - */ - offStop(callback: () => void): void; - /** - * 监听音频自然播放至结束的事件 - */ - onEnded(callback: () => void): void; - /** - * 取消监听音频自然播放至结束的事件 - */ - offEnded(callback: () => void): void; - /** - * 监听音频播放进度更新事件 - */ - onTimeUpdate(callback: () => void): void; - /** - * 取消监听音频播放进度更新事件 - */ - offTimeUpdate(callback: () => void): void; - /** - * 监听音频播放错误事件 - */ - onError(callback: () => void): void; - /** - * 取消监听音频播放错误事件 - */ - offError(callback: () => void): void; - /** - * 监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 - */ - onWaiting(callback: () => void): void; - /** - * 取消监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 - */ - offWaiting(callback: () => void): void; - /** - * 监听音频进行跳转操作的事件 - */ - onSeeking(callback: () => void): void; - /** - * 取消监听音频进行跳转操作的事件 - */ - offSeeking(callback: () => void): void; - /** - * 监听音频完成跳转操作的事件 - */ - onSeeked(callback: () => void): void; - /** - * 取消监听音频完成跳转操作的事件 - */ - offSeeked(callback: () => void): void; -} - -declare class RecorderManager { - /** - * 开始录音 - */ - start(param: { - /** - * 录音的时长,单位 ms,最大值 600000(10 分钟),默认值60000(1 分钟) - */ - duration?: number, - /** - * 采样率 - */ - sampleRate: 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000, - /** - * 录音通道数 - */ - numberOfChannels: 1 | 2, - /** - * 编码码率 - */ - encodeBitRate: number, - /** - * 音频格式 - */ - format: "mp3" | "aac", - /** - * 指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调 - */ - frameSize: number, - /** - * 指定录音的音频源,可通过 wx.getAvailableAudioSources() 获取当前可用的音频源,默认值auto - */ - audioSource?: wx.types.AudioSourceType - }): void; - /** - * 暂停录音 - */ - pause(): void; - /** - * 继续录音 - */ - resume(): void; - /** - * 停止录音 - */ - stop(): void; - /** - * 监听录音开始事件 - */ - onStart(callback: () => void): void; - /** - * 监听录音继续事件 - */ - onResume(callback: () => void): void; - /** - * 监听录音暂停事件 - */ - onPause(callback: () => void): void; - /** - * 监听录音结束事件 - * @param callback.res.tempFilePath 录音文件的临时路径 - */ - onStop(callback: (res: { tempFilePath: string }) => void): void; - /** - * 监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。 - * @param callback.res.frameBuffer 录音分片数据 - * @param callback.res.isLastFrame 当前帧是否正常录音结束前的最后一帧 - */ - onFrameRecorded(callback: (res: { frameBuffer: ArrayBuffer, isLastFrame: boolean }) => void): void; - /** - * 监听录音错误事件 - */ - onError(callback: (res: { errMsg: string }) => void): void; -} - -declare class ImageFile { - /** - * 本地文件路径 - */ - path: string; - /** - * 本地文件大小,单位 B - */ - size: number; -} - -declare class Video { - /** - * 视频的左上角横坐标 - */ - x: number; - /** - * 视频的左上角纵坐标 - */ - y: number; - /** - * 视频的宽度,默认值300 - */ - width: number; - /** - * 默认值150 - */ - height: number; - /** - * 视频的资源地址 - */ - src: string; - /** - * 视频的封面 - */ - poster: string; - /** - * 视频的初始播放位置,单位为 s 秒,默认值0 - */ - initialTime: number; - /** - * 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0 - */ - playbackRate: number; - /** - * 视频是否为直播,默认值0 - */ - live?: number; - /** - * 视频的缩放模式 - * fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例 - * contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白 - * cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见 - */ - objectFit: "contain" | "cover" | "fill"; - /** - * 视频是否显示控件,默认true - */ - controls: boolean; - /** - * 视频是否自动播放,默认false - */ - autoplay: boolean; - /** - * 视频是否是否循环播放,默认值false - */ - loop: boolean; - /** - * 视频是否禁音播放,默认值false - */ - muted: boolean; - - /** - * 视频开始缓冲时触发的回调函数 - */ - onwaiting: () => void; - /** - * 视频开始播放时触发的回调函数 - */ - onplay: () => void; - /** - * 视频暂停时触发的回调函数 - */ - onpause: () => void; - /** - * 视频播放到末尾时触发的回调函数 - */ - onended: () => void; - /** - * 每当视频播放进度更新时触发的回调函数 - */ - ontimeupdate: () => void; - /** - * 视频发生错误时触发的回调函数 - */ - onerror: () => void; - - /** - * 销毁视频 - */ - destroy(): void; - /** - * 监听视频缓冲事件 - */ - onWaiting(callback: () => void): void; - /** - * 取消监听视频缓冲事件 - */ - offWaiting(callback: () => void): void; - - /** - * 监听视频播放事件 - */ - onPlay(callback: () => void): void; - /** - * 取消监听视频播放事件 - */ - offPlay(callback: () => void): void; - /** - * 监听视频暂停事件 - */ - onPause(callback: () => void): void; - /** - * 取消监听视频暂停事件 - */ - offPause(callback: () => void): void; - /** - * 监听视频播放到末尾事件 - */ - onEnded(callback: () => void): void; - /** - * 取消监听视频播放到末尾事件 - */ - offEnded(callback: () => void): void; - /** - * 监听视频播放进度更新事件 - * @param callback.res.position 当前的播放位置,单位为秒 - * @param callback.res.duration 视频的总时长,单位为秒 - */ - onTimeUpdate(callback: (res: { position: number, duration: number }) => void): void; - /** - * 取消监听视频播放进度更新事件 - */ - offTimeUpdate(callback: (res: { position: number, duration: number }) => void): void; - /** - * 监听视频错误事件 - * @param callback.res.errMsg 错误信息,有如下值 - * MEDIA_ERR_NETWORK - 当下载时发生错误 - * MEDIA_ERR_DECODE - 当解码时发生错误 - * MEDIA_ERR_SRC_NOT_SUPPORTED - video 的 src 属性是不支持的资源类型 - */ - onError(callback: (res: { errMsg: string }) => void): void; - /** - * 取消监听视频错误事件 - */ - offError(callback: (res: { errMsg: string }) => void): void; - - /** - * 播放视频 - */ - play(): Promise; - /** - * 暂停视频 - */ - pause(): Promise; - /** - * 停止视频 - */ - stop(): Promise; - /** - * 视频跳转 - * @param time 视频跳转到指定位置,单位为 s 秒 - */ - seek(time: number): Promise; - - /** - * 视频全屏 - */ - requestFullScreen(): Promise; - - /** - * 视频退出全屏 - */ - exitFullScreen(): Promise; -} -/** - * 相机对象 - */ -declare class Camera { - /** - * 相机的左上角横坐标 - */ - x: number; - - /** - * 相机的左上角纵坐标 - */ - y: number; - - /** - * 相机的宽度 - */ - width: number; - - /** - * 相机的高度 - */ - height: number; - - /** - * 摄像头朝向 - */ - devicePosition: "front" | "back"; - - /** - * 闪光灯状态 - */ - flash: "auto" | "on" | "off"; - - /** - * 帧数据图像尺寸 - */ - size: "small" | "medium" | "large"; - - /** - * 拍照,可指定质量,成功则返回图片 - * @param quality 图片质量 - */ - takePhoto(quality?: "high" | "normal" | "low"): Promise<{ - /** - * 临时图片路径 - */ - tempImagePath: string, - /** - * 图片宽度 - */ - width: string, - /** - * 图片高度 - */ - height: string - }>; - - /** - * 开始录像 - */ - startRecord(): Promise; - - /** - * 结束录像,成功则返回封面与视频 - * @param compressed 是否压缩录制视频 - */ - stopRecord(compressed: boolean): Promise<{ - /** - * 临时视频路径 - */ - tempThumbPath: string, - /** - * 临时封面路径 - */ - tempVideoPath: string - }>; - - /** - * 监听用户不允许授权使用摄像头的情况 - * @param callback 回调函数 - */ - onAuthCancel(callback: () => void): void; - - /** - * 监听摄像头非正常终止事件,如退出后台等情况 - * @param callback 回调函数 - */ - onStop(callback: () => void): void; - - /** - * 监听摄像头实时帧数据 - */ - onCameraFrame(callback: (res: { - /** - * 图像数据矩形的宽度 - */ - width: number, - /** - * 图像数据矩形的高度 - */ - height: number, - /** - * 图像像素点数据,一维数组,每四项表示一个像素点的 rgba - */ - data: ArrayBuffer - }) => void): void; - - /** - * 开启监听帧数据 - */ - listenFrameChange(): void; - - /** - * 关闭监听帧数据 - */ - closeFrameChange(): void; - - /** - * 销毁相机 - */ - destroy(): void; -} -/** - * banner 广告组件。banner 广告组件是一个原生组件,层级比上屏 Canvas 高,会覆盖在上屏 Canvas 上。banner 广告组件默认是隐藏的,需要调用 BannerAd.show() 将其显示。banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的尺寸将通过 BannerAd.onResize() 事件中提供。 - */ -declare class BannerAd { - /** - * 广告单元 id - */ - adUnitId: string; - /** - * banner 广告组件的样式。style 上的属性的值仅为开发者设置的值,banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的真实尺寸需要通过 BannerAd.onResize() 事件获得。 - */ - style: wx.types.AdStyle; - - /** - * 显示 banner 广告。 - */ - show(): Promise; - /** - * 隐藏 banner 广告 - */ - hide(): void; - /** - * 销毁 banner 广告 - */ - destroy(): void; - /** - * 监听 banner 广告缩放 - */ - onResize(callback: (res: { width: number, height: number }) => void): void; - /** - * 取消监听隐藏 banner 广告缩放 - */ - offResize(callback: (res: { width: number, height: number }) => void): void; - /** - * 监听banner 广告加载事件 - */ - onLoad(callback: () => void): void; - /** - * 取消监听banner 广告加载事件 - */ - offLoad(callback: () => void): void; - /** - * 监听banner 广告错误事件 - */ - onError(callback: (res: { errMsg: string }) => void): void; - /** - * 取消监听banner 广告错误事件 - */ - offError(callback: (res: { errMsg: string }) => void): void; -} - -declare class InterstitialAd extends BannerAd { - /** - * 加载视频广告 - */ - load(): Promise; - /** - * 监听用户点击 关闭广告 按钮的事件 - */ - onClose(callback: (res: { isEnded: boolean }) => void): void; - /** - * 监听用户点击 关闭广告 按钮的事件 - */ - offClose(callback: (res: { isEnded: boolean }) => void): void; -} - -declare class RewardedVideoAd extends InterstitialAd { -} - -// --定时器 -declare function clearTimeout(timeoutID: number): void; -declare function clearInterval(intervalID: number): void; -declare function setTimeout(fn: () => void, delay: number, ...rest: any[]): number; -declare function setInterval(fn: () => void, delay: number, ...rest: any[]): number; - -// --渲染 -declare function cancelAnimationFrame(requestID: number): void; -declare function requestAnimationFrame(callback: () => void): number; - -declare namespace wx { - namespace types { - interface Callbacks { - success?: () => void; - fail?: () => void; - complete?: () => void; - } - - interface CallbacksWithType { - success?: (res: T) => void; - fail?: () => void; - complete?: () => void; - } - - interface CallbacksWithType2 { - success?: (res: T) => void; - fail?: (res: F) => void; - complete?: () => void; - } - - interface RenderingContextConfig { - /** - * 表示是否抗锯齿 - */ - antialias?: boolean; - /** - * 表示是否绘图完成后是否保留绘图缓冲区 - */ - preserveDrawingBuffer?: boolean; - /** - * 抗锯齿样本数。最小值为 2,最大不超过系统限制数量,仅 iOS 支持 - */ - antialiasSamples?: number; - } - - interface ToTempFileSyncParams { - /** - * 截取 canvas 的左上角横坐标 - */ - x?: number; - /** - * 截取 canvas 的左上角纵坐标 - */ - y?: number; - /** - * 截取 canvas 的宽度 - */ - width?: number; - /** - * 截取 canvas 的高度 - */ - height?: number; - /** - * 目标文件的宽度,会将截取的部分拉伸或压缩至该数值 - */ - destWidth?: number; - /** - * 目标文件的高度,会将截取的部分拉伸或压缩至该数值 - */ - destHeight?: number; - /** - * 目标文件的类型 - */ - fileType?: "jpg" | "png"; - /** - * jpg图片的质量,仅当 fileType 为 jpg 时有效。取值范围为 0.0(最低)- 1.0(最高),不含 0。不在范围内时当作 1.0 - */ - quality?: number; - } - - interface ToTempFileParams extends ToTempFileSyncParams { - success?: (res: { tempFilePath: string }) => void; - fail?: () => void; - complete?: () => void; - } - - interface RenameParams { - oldPath: string; - newPath: string; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface RmdirParams { - dirPath: string; - recursive?: boolean; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface ReaddirParams { - dirPath: string; - success?: (res: { files: ReadonlyArray }) => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface MkdirParams { - dirPath: string; - recursive?: boolean; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - type FileContentEncoding = "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"; - - interface ReadfileParams { - filePath: string; - encoding?: FileContentEncoding; - success?: (res: { data: string | ArrayBuffer }) => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface StatParams { - path: string; - success?: (res: { stat: Stats }) => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface WritefileParams { - filePath: string; - data: string | ArrayBuffer; - encoding?: FileContentEncoding; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface UnlinkParams { - filePath: string; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface UnzipParams { - zipFilePath: string; - targetPath: string; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface AccessfileParams { - path: string; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface SavedfileList { - fileList: { - filePath: string; - size: number; - createTime: number; - }; - } - - interface CopyfileParams { - srcPath: string; - destPath: string; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface FileinfoParams { - filePath: string; - success?: (res: { size: number, digest: string }) => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface RemovefileParams { - filePath: string; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - - interface SavefileParams { - tempFilePath: string; - filePath?: string; - success?: (res: { savedFilePath: string }) => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface AppendfileParams { - filePath: string; - data: string | ArrayBuffer; - encoding?: FileContentEncoding; - success?: () => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - interface LineHeightParams { - fontStyle?: "normal" | "italic"; - fontWeight?: "normal" | "bold"; - fontSize?: number; - fontFamily: string; - text: string; - success?: (res: { lineHeight: number }) => void; - fail?: () => void; - complete?: () => void; - } - - interface Image { - src: string; - width: number; - height: number; - onload: () => void; - onerror: (e?: any) => void; - } - - // --启动参数 - interface LaunchOption { - /** - * 场景值 - */ - scene: number; - /** - * 启动参数 - */ - query: any; - /** - * 当前小游戏是否被显示在聊天顶部 - */ - isSticky: boolean; - /** - * 票据 - */ - shareTicket: string; - } - - // --系统信息 - interface SystemInfo { - /** - * 手机品牌 - */ - brand: string; - /** - * 手机型号 - */ - model: string; - /** - * 设备像素比 - */ - pixelRatio: number; - /** - * 屏幕宽度 - */ - screenWidth: number; - /** - * 屏幕高度 - */ - screenHeight: number; - /** - * 可使用窗口宽度 - */ - windowWidth: number; - /** - * 可使用窗口高度 - */ - windowHeight: number; - /** - * 微信设置的语言 - */ - language: string; - /** - * 微信版本号 - */ - version: string; - /** - * 操作系统版本 - */ - system: string; - /** - * 客户端平台 - */ - platform: string; - /** - * 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位 px。 - */ - fontSizeSetting: string; - /** - * 客户端基础库版本 - */ - SDKVersion: string; - /** - * 性能等级 - */ - benchmarkLevel: number; - /** - * 电量,范围 1 - 100 - */ - battery: number; - /** - * wifi 信号强度,范围 0 - 4 - */ - wifiSignal: number; - } - - // --触摸对象 - interface Touch { - /** - * Touch 对象的唯一标识符,只读属性。一次触摸动作(我们值的是手指的触摸)在平面上移动的整个过程中, 该标识符不变。可以根据它来判断跟踪的是否是同一次触摸过程。 - */ - identifier: number; - /** - * 触点相对于整体页面的 X 轴距离。 - */ - pageX: number; - /** - * 触点相对于整体页面的 Y 轴距离。 - */ - pageY: number; - /** - * 触点相对于游戏窗口的 X 轴距离。 - */ - clientX: number; - /** - * 触点相对于游戏窗口的 Y 轴距离。 - */ - clientY: number; - } - - interface TouchData { - /** - * 当前事件的类型 - */ - type: string; - /** - * 当前所有触摸点的列表 - */ - touches: ReadonlyArray; - /** - * 触发此次事件的触摸点列表 - */ - changedTouches: ReadonlyArray; - /** - * 事件触发时的时间戳 - */ - timeStamp: number; - } - - // --iBeacon(TODO) - /** - * 停止搜索附近的 iBeacon 设备 - */ - function stopBeaconDiscovery(param: any): void; - /** - * 开始搜索附近的 iBeacon 设备 - */ - function startBeaconDiscovery(param: any): void; - /** - * 监听 iBeacon 设备更新事件,仅能注册一个监听 - */ - function onBeaconUpdate(callback: any): void; - /** - * 监听 iBeacon 服务状态变化事件,仅能注册一个监听 - */ - function onBeaconServiceChange(callback: any): void; - /** - * 取消监听 iBeacon 设备更新事件 - */ - function offBeaconUpdate(callback: any): void; - /** - * 取消监听 iBeacon 服务状态变化事件 - */ - function offBeaconServiceChange(callback: any): void; - /** - * 获取所有已搜索到的 iBeacon 设备 - */ - function getBeacons(param: any): void; - /* - IBeaconInfo - 属性 - string uuid - iBeacon 设备广播的 uuid - string major - iBeacon 设备的主 id - string minor - iBeacon 设备的次 id - number proximity - 表示设备距离的枚举值 - number accuracy - iBeacon 设备的距离 - number rssi - 表示设备的信号强度 - */ - - // --低功耗蓝牙(TODO) - function writeBLECharacteristicValue(): void; - function readBLECharacteristicValue(): void; - function onBLEConnectionStateChange(): void; - function onBLECharacteristicValueChange(): void; - function notifyBLECharacteristicValueChange(): void; - function getBLEDeviceServices(): void; - function getBLEDeviceCharacteristics(): void; - function createBLEConnection(): void; - function closeBLEConnection(): void; - - // --蓝牙(TODO) - function stopBluetoothDevicesDiscovery(): void; - function startBluetoothDevicesDiscovery(): void; - function openBluetoothAdapter(): void; - function onBluetoothDeviceFound(): void; - function onBluetoothAdapterStateChange(): void; - function getConnectedBluetoothDevices(): void; - function getBluetoothDevices(): void; - function getBluetoothAdapterState(): void; - function closeBluetoothAdapter(): void; - - // --电量 - interface BatteryInfo { - /** - * 设备电量,范围 1 - 100 - */ - level: string; - /** - * 是否正在充电 - */ - isCharging: boolean; - } - - // --剪切板 - interface ClipboardData { - data: string; - } - - interface SetClipboardDataParams { - success?: () => void; - fail?: () => void; - complete?: () => void; - data: string; - } - - interface SetKeepScreenOnParams { - success?: () => void; - fail?: () => void; - complete?: () => void; - keepScreenOn: boolean; - } - - interface SetScreenBrightnessParams { - success?: () => void; - fail?: () => void; - complete?: () => void; - /** - * 屏幕亮度值,范围 0 ~ 1,0 最暗,1 最亮 - */ - value: number; - } - - interface DownfileParams { - url: string; - /** - * 在指定filePath之后success回调中将不会有res.tempFilePath路径值,下载的文件会直接写入filePath指定的路径(有写入权限的情况下,根目录请使用wx.env.USER_DATA_PATH,路径文件夹必须存在,否则写入失败) - */ - filePath?: string; - /** - * HTTP 请求的 Header,Header 中不能设置 Referer - */ - header?: { [key: string]: string }; - /** - * res.tempFilePath 临时文件路径。如果没传入 filePath 指定文件存储路径,则下载后的文件会存储到一个临时文件 - * res.statusCode 开发者服务器返回的 HTTP 状态码 - */ - success?: (res: { tempFilePath?: string, statusCode: number }) => void; - fail?: (res: { errMsg: string }) => void; - complete?: () => void; - } - - type NetworkType = "wifi" | "2g" | "3g" | "4g" | "any" | "none"; - - type RequestMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT"; - - interface RequestParams { - /** - * 开发者服务器接口地址 - */ - url: string; - /** - * 请求的参数 - */ - data?: string | { [key: string]: any }; - /** - * 设置请求的 header,header 中不能设置 Referer - */ - header?: { [name: string]: string }; - /** - * HTTP 请求方法 - */ - method?: RequestMethod; - /** - * 返回的数据格式 - */ - dataType?: "json" | "arraybuffer"; - /** - * res.data usually can be string or ArrayBuffer - */ - success?: (res: { data: any, statusCode: number, header?: { [key: string]: string } }) => void; - fail?: () => void; - complete?: () => void; - } - - interface SocketSendParams { - data: string | ArrayBuffer; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - interface SocketConnectParams { - url: string; - protocols?: string[]; - header?: { [key: string]: string }; - method?: RequestMethod; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - interface SocketCloseParams { - /** - * 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。如果这个参数没有被指定,默认的取值是1000 (表示正常连接关闭) - */ - code?: number; - /** - * 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于123字节的UTF-8 文本(不是字符) - */ - reason?: string; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - - type SocketOpenCallback = (res: { header?: { [key: string]: string } }) => void; - type SocketMessageCallback = (res: { data: string | ArrayBuffer }) => void; - type SocketErrorCallback = (res: { errMsg: string }) => void; - - interface UDPSendParams { - /** - * 要发消息的地址。可以是一个和本机同网段的 IP 地址,也可以是在安全域名列表内的域名地址 - */ - address: string; - /** - * 要发送消息的端口号 - */ - port: number; - /** - * 要发送的数据 - */ - message: string | ArrayBuffer; - /** - * 发送数据的偏移量,仅当 message 为 ArrayBuffer 类型时有效,默认值0 - */ - offset?: number; - /** - * 发送数据的长度,仅当 message 为 ArrayBuffer 类型时有效,默认值message.byteLength - */ - length?: number; - } - interface UDPMessage { - /** - * 收到的消息 - */ - message: ArrayBuffer; - /** - * 消息来源的结构化信息 - */ - remoteInfo: { - /** - * 发送消息的 socket 的地址 - */ - address: string; - /** - * 使用的协议族,为 IPv4 或者 IPv6 - */ - family: string; - /** - * 端口号 - */ - port: number; - /** - * message 的大小,单位:字节 - */ - size: number; - }; - } - - /** - * wx.getUserInfo的旧版本API参数,随时会被删除,不推荐使用 - */ - interface OldUserInfoParam { - /** - * 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。 - */ - withCredentials?: boolean; - /** - * 显示用户信息的语言 - */ - lang?: "en" | "zh_CN" | "zh_TW"; - success?: (res: { - /** - * 用户信息对象,不包含 openid 等敏感信息 - */ - userInfo: UserInfo, - /** - * 不包括敏感信息的原始数据字符串,用于计算签名 - */ - rawData: string, - /** - * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822) - */ - signature: string, - /** - * 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) - */ - encryptedData: string, - /** - * 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) - */ - iv: string, - errMsg: string - }) => void; - fail?: () => void; - complete?: () => void; - } - - /** - * 新版本wx.getUserInfo的参数,需要在开放数据域内调用 - */ - interface NewUserInfoParam { - /** - * 要获取信息的用户的 openId 数组,如果要获取当前用户信息,则将数组中的一个元素设为 'selfOpenId' - */ - openIdList?: string[]; - /** - * 显示用户信息的语言 - */ - lang?: "en" | "zh_CN" | "zh_TW"; - success?: (res: { data: ReadonlyArray }) => void; - fail?: () => void; - complete?: () => void; - } - - interface UserInfo { - language: string; - nickName: string; - avatarUrl: string; - /** - * 0:未知、1:男、2:女 - */ - gender: 0 | 1 | 2; - country: string; - province: string; - city: string; - } - - type ButtonType = "text" | "image"; - interface ButtonStyle { - left?: number; - top?: number; - width?: number; - height?: number; - /** - * 格式#ff0000 - */ - backgroundColor?: string; - /** - * 格式#ff0000 - */ - borderColor?: string; - borderWidth?: number; - borderRadius?: number; - textAlign?: "left" | "center" | "right"; - fontSize?: number; - lineHeight?: number; - } - - type GameClubButtonIcon = "green" | "white" | "dark" | "light"; - - // --设置 - interface AuthSetting { - /** - * 用户信息,对应接口 wx.getUserInfo - */ - "scope.userInfo"?: boolean; - /** - * 地理位置,对应接口 wx.getLocation wx.chooseLocation - */ - "scope.userLocation"?: boolean; - /** - * 通讯地址,对应接口 wx.chooseAddress - */ - "scope.address"?: boolean; - /** - * 发票抬头,对应接口 wx.chooseInvoiceTitle - */ - "scope.invoiceTitle"?: boolean; - /** - * 微信运动步数,对应接口 wx.getWeRunData - */ - "scope.werun"?: boolean; - /** - * 录音功能,对应接口 wx.startRecord - */ - "scope.record"?: boolean; - /** - * 保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum - */ - "scope.writePhotosAlbum"?: boolean; - /** - * 摄像头 wx.camera - */ - "scope.camera"?: boolean; - } - - interface SetStorageParams { - key: string; - data: any; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - interface RemoveStorageParams { - key: string; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - interface GetStorageParams { - key: string; - success?: (res: { data: any }) => void; - fail?: () => void; - complete?: () => void; - } - - interface StorageInfo { - /** - * 当前 storage 中所有的 key - */ - keys: ReadonlyArray; - /** - * 当前占用的空间大小, 单位 KB - */ - currentSize: number; - /** - * 限制的空间大小,单位 KB - */ - limitSize: number; - } - - interface ShareOption { - /** - * 转发标题,不传则默认使用当前小游戏的昵称。 - */ - title?: string; - /** - * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5:4 - */ - imageUrl?: string; - /** - * 查询字符串,必须是 key1=val1&key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionsSync() 或 wx.onShow 获取启动参数中的 query。 - */ - query?: string; - } - - interface AccelerometerParams { - interval: "game" | "ui" | "normal"; - success?: () => void; - fail?: () => void; - complete?: () => void; - } - - type AudioSourceType = "auto" | "buildInMic" | "headsetMic" | "mic" | "camcorder"; - - interface AdStyle { - /** - * 广告组件的左上角横坐标 - */ - left: number; - /** - * banner 广告组件的左上角纵坐标 - */ - top: number; - /** - * banner 广告组件的宽度。最小 300,最大至 屏幕宽度(屏幕宽度可以通过 wx.getSystemInfoSync() 获取)。 - */ - width: number; - /** - * banner 广告组件的高度 - */ - height: number; - /** - * banner 广告组件经过缩放后真实的宽度 - */ - realWidth: number; - /** - * banner 广告组件经过缩放后真实的高度 - */ - realHeight: number; - } - } - - /** - * 创建一个画布对象。首次调用创建的是显示在屏幕上的画布,之后调用创建的都是离屏画布。 - */ - function createCanvas(): Canvas; - - /** - * 只有开放数据域能调用,获取主域和开放数据域共享的 sharedCanvas - */ - function getSharedCanvas(): Canvas; - - /** - * 创建一个图片对象 - */ - function createImage(): types.Image; - - /** - * 获取一行文本的行高 - * @param p 字体参数 - */ - function getTextLineHeight(p: types.LineHeightParams): number; - - /** - * 加载自定义字体文件 - * @param path 字体文件路径。可以是代码包文件路径,也可以是 wxfile:// 协议的本地文件路径。 - */ - function loadFont(path: string): string; - - /** - * 可以修改渲染帧率。默认渲染帧率为 60 帧每秒。修改后,requestAnimationFrame 的回调频率会发生改变。 - * @param fps 帧率,有效范围 1 - 60。 - */ - function setPreferredFramesPerSecond(fps: number): void; - - // --生命周期 - function exitMiniProgram(cb?: types.Callbacks): void; - function getLaunchOptionsSync(): types.LaunchOption; - function onHide(cb: () => void): void; - function offHide(cb: () => void): void; - function onShow(cb: (res: { scene: string, query: any, shareTicket: string }) => void): void; - function offShow(cb: (res: { scene: string, query: any, shareTicket: string }) => void): void; - - // --系统信息 - function getSystemInfo(cb: types.CallbacksWithType): void; - function getSystemInfoSync(): types.SystemInfo; - - /** - * 监听音频中断结束,在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功 - */ - function onAudioInterruptionEnd(cb: () => void): void; - /** - * 取消监听音频中断结束,在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功 - */ - function offAudioInterruptionEnd(cb: () => void): void; - /** - * 监听音频因为受到系统占用而被中断开始,以下场景会触发此事件:闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天。此事件触发后,小程序内所有音频会暂停。 - */ - function onAudioInterruptionBegin(cb: () => void): void; - /** - * 取消监听音频因为受到系统占用而被中断开始,以下场景会触发此事件:闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天。此事件触发后,小程序内所有音频会暂停。 - */ - function offAudioInterruptionBegin(cb: () => void): void; - /** - * 监听全局错误事件 - */ - function onError(cb: (res: { message: string, stack: string }) => void): void; - function offError(cb: (res: { message: string, stack: string }) => void): void; - - // --触摸事件 - /** - * 监听开始始触摸事件 - */ - function onTouchStart(cb: (res: types.TouchData) => void): void; - function offTouchStart(cb: (res: types.TouchData) => void): void; - /** - * 监听触点移动事件 - */ - function onTouchMove(cb: (res: types.TouchData) => void): void; - function offTouchMove(cb: (res: types.TouchData) => void): void; - /** - * 监听触摸结束事件 - */ - function onTouchEnd(cb: (res: types.TouchData) => void): void; - function offTouchEnd(cb: (res: types.TouchData) => void): void; - /** - * 监听触点失效事件 - */ - function onTouchCancel(cb: (res: types.TouchData) => void): void; - function offTouchCancel(cb: (res: types.TouchData) => void): void; - - // --加速计 - /** - * 监听加速度数据,频率:5次/秒,接口调用后会自动开始监听,可使用 wx.stopAccelerometer 停止监听。 - */ - function onAccelerometerChange(cb: (res: { x: number, y: number, z: number }) => void): void; - /** - * 开始监听加速度数据。 - */ - function startAccelerometer(cb: types.AccelerometerParams): void; - /** - * 停止监听加速度数据。 - */ - function stopAccelerometer(cb?: types.Callbacks): void; - - // --电量 - /** - * 获取设备电量。同步 API wx.getBatteryInfoSync 在 iOS 上不可用。 - */ - function getBatteryInfo(cb: types.CallbacksWithType): void; - /** - * IOS上这个同步API无法使用 - */ - function getBatteryInfoSync(): types.BatteryInfo; - - // --剪贴板 - /** - * 取得系统剪贴板的内容 - */ - function getClipboardData(cb: types.CallbacksWithType): void; - /** - * 设置系统剪贴板的内容 - */ - function setClipboardData(p: types.SetClipboardDataParams): void; - - // --罗盘 - /** - * 监听罗盘数据,频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。 - * @param cb.res.direction 面对的方向度数 - */ - function onCompassChange(cb: (res: { direction: number }) => void): void; - /** - * 开始监听罗盘数据 - */ - function startCompass(cb?: types.Callbacks): void; - /** - * 停止监听罗盘数据 - */ - function stopCompass(cb?: types.Callbacks): void; - - // --网络 - /** - * 获取网络类型 - */ - function getNetworkType(cb: types.CallbacksWithType<{ isConnected: boolean, networkType: types.NetworkType }>): void; - /** - * 监听网络状态变化事件 - */ - function onNetworkStatusChange(cb: (res: { - /** - * 当前是否有网络链接 - */ - isConnected: boolean, - /** - * none - 无网络, any - Android 下不常见的网络类型 - */ - networkType: types.NetworkType - }) => void): void; - - // --屏幕 - /** - * 获取屏幕亮度 - */ - function getScreenBrightness(cb: types.CallbacksWithType<{ value: number }>): void; - /** - * 设置是否保持常亮状态。仅在当前小程序生效,离开小程序后设置失效。 - */ - function setKeepScreenOn(p: types.SetKeepScreenOnParams): void; - /** - * 设置屏幕亮度 - */ - function setScreenBrightness(p: types.SetScreenBrightnessParams): void; - - // --转屏 - /** - * 监听横竖屏切换事件 - */ - function onDeviceOrientationChange(callback: (res: { value: string }) => void): void; - /** - * 取消监听横竖屏切换事件 - */ - function offDeviceOrientationChange(callback: (res: { value: string }) => void): void; - - // --设备方向 - /** - * 停止监听设备方向的变化。 - */ - function stopDeviceMotionListening(cb?: types.Callbacks): void; - /** - * 开始监听设备方向的变化 - */ - function startDeviceMotionListening(param: { - /** - * 开始监听设备方向的变化。默认值normal, - * game - 适用于更新游戏的回调频率,在 20ms/次 左右 - * ui - 适用于更新 UI 的回调频率,在 60ms/次 左右 - * normal - 普通的回调频率,在 200ms/次 左右 - */ - interval: "game" | "ui" | "normal" - } & types.Callbacks): void; - /** - * 监听设备方向变化事件。频率根据 wx.startDeviceMotionListening() 的 interval 参数。可以使用 wx.stopDeviceMotionListening() 停止监听。 - */ - function onDeviceMotionChange(callback: (res: { - /** - * 当 手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。 - */ - alpha: number, - /** - * 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 - */ - beta: number, - /** - * 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 - */ - gamma: number - }) => void): void; - /** - * 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。 - * @param callback 之前添加过的监听回调函数,如果不指定,则清空所有 - */ - function offDeviceMotionChange(callback?: any): void; - - // --陀螺仪 - /** - * 停止监听陀螺仪数据 - */ - function stopGyroscope(cb?: types.Callbacks): void; - /** - * 开始监听陀螺仪数据。 - */ - function startGyroscope(param: { - /** - * 开始监听设备方向的变化。默认值normal, - * game - 适用于更新游戏的回调频率,在 20ms/次 左右 - * ui - 适用于更新 UI 的回调频率,在 60ms/次 左右 - * normal - 普通的回调频率,在 200ms/次 左右 - */ - interval: "game" | "ui" | "normal" - } & types.Callbacks): void; - /** - * 监听陀螺仪数据变化事件。频率根据 wx.startGyroscope() 的 interval 参数。可以使用 wx.stopGyroscope() 停止监听。 - * @param callback 监听函数 - */ - function onGyroscopeChange(callback: (res: { - /** - * x 轴的角速度 - */ - x: number, - /** - * y 轴的角速度 - */ - y: number, - /** - * z 轴的角速度 - */ - z: number - }) => void): void; - /** - * 取消监听陀螺仪数据变化事件。 - * @param callback 之前监听的回调函数 - */ - function offGyroscopeChange(callback: any): void; - - // --振动 - /** - * 使手机发生较短时间的振动(15 ms) - */ - function vibrateShort(cb?: types.Callbacks): void; - /** - * 使手机发生较长时间的振动(400 ms) - */ - function vibrateLong(cb?: types.Callbacks): void; - - // --文件系统 - function getFileSystemManager(): FileSystemManager; - - // --推荐弹窗 - /** - * 创建小游戏推荐弹窗组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.7.5 后再使用该 API。每次调用该方法都会返回一个全新的实例。 - */ - function createGamePortal(param: { - /** - * 推荐单元 id - */ - adUnitId: string - }): any /* GamePortal */; // TODO: GamePortal - /** - * 创建小游戏推荐icon组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.8.2 后再使用该 API。每次调用该方法都会返回一个全新的实例。 - */ - function createGameIcon(param: { - /** - * 推荐单元 id - */ - adUnitId: string, - /** - * 游戏icon的数量,请注意,正式版下面渲染出来的icon数量会小于等于count,请注册做好样式兼容 - */ - count: number, - /** - * 数组的每一项可以针对对应的icon设置位置和样式等信息,style的每一项称为styleItem - */ - style: ReadonlyArray<{ - /** - * 游戏名称是否隐藏 - */ - appNameHidden: boolean, - /** - * 游戏名称的颜色色值 - */ - color: string, - /** - * 游戏icon的宽高值 - */ - size: number, - /** - * 游戏icon的border尺寸 - */ - borderWidth: number, - /** - * 游戏icon的border颜色色值 - */ - borderColor: string, - /** - * 游戏icon的X轴坐标 - */ - left: number, - /** - * 游戏icon的Y轴坐标 - */ - top: number - }> - }): any /* GameIcon */; // TODO: GameIcon - /** - * 创建小游戏推荐banner组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.7.5 后再使用该 API。每次调用该方法都会返回一个全新的实例。 - */ - function createGameBanner(param: { - /** - * 推荐单元 id - */ - adUnitId: string, - /** - * 小游戏推荐banner组件样式 - */ - style: { - /** - * 小游戏推荐banner组件左上角横坐标 - */ - left: number, - /** - * 小游戏推荐banner组件左上角纵坐标 - */ - top: number - } - }): any /* GameBanner */; // TODO: GameBanner - - // --游戏对局回放 - /** - * 获取全局唯一的游戏画面录制对象 - */ - function getGameRecorder(): any /* GameRecorder */; // TODO: GameRecorder - /** - * 创建游戏对局回放分享按钮,返回一个单例对象。按钮在被用户点击后会发起对最近一次录制完成的游戏对局回放的分享。 - */ - function createGameRecorderShareButton(): any /* GameRecorderShareButton */; // TODO: GameRecorderShareButton - - // --第三方平台 - /** - * 获取第三方平台自定义的数据字段。 - * Tips: 本接口暂时无法通过 wx.canIUse 判断是否兼容,开发者需要自行判断 wx.getExtConfig 是否存在来兼容,示例: - * if (wx.getExtConfig) { - * wx.getExtConfig({ - * success (res) { - * console.log(res.extConfig) - * } - * }) - * } - */ - function getExtConfig(callbacks: types.CallbacksWithType<{ - /** - * 第三方平台自定义的数据 - */ - extConfig: any - }>): void; - /** - * wx.getExtConfig 的同步版本。 - */ - function getExtConfigSync(): any; - - /** - * 系统环境变量 - */ - const env: { - /** - * 用户下载数据根目录 - */ - USER_DATA_PATH: string - }; - - // --位置 - /** - * 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。 - */ - function getLocation(param: { - /** - * wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 - */ - type?: "wgs84" | "gcj02", - /** - * 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度 >= 1.6.0 - */ - altitude?: boolean, - success?: (res: { - /** - * 纬度,范围为 -90~90,负数表示南纬 - */ - latitude: number, - /** - * 经度,范围为 -180~180,负数表示西经 - */ - longitude: number, - /** - * 速度,单位 m/s - */ - speed: number, - /** - * 位置的精确度 - */ - accuracy: number, - /** - * 高度,单位 m - */ - altitude: number, - /** - * 垂直精度,单位 m(Android 无法获取,返回 0) - */ - verticalAccuracy: number, - /** - * 水平精度,单位 m - */ - horizontalAccuracy: number - }) => void, - fail?: () => void, - complete?: () => void - }): void; - - // --网络 - /** - * 下载文件 - */ - function downloadFile(param: types.DownfileParams): DownloadTask; - - // --发起请求 - function request(param: types.RequestParams): RequestTask; - - // --websocket - /** - * 创建一个 WebSocket 连接。最多同时存在 5 个 WebSocket 连接。 - */ - function connectSocket(param: types.SocketConnectParams): SocketTask; - /** - * 关闭WebSocket - */ - function closeSocket(param: types.SocketCloseParams): void; - /** - * 监听WebSocket 连接打开事件 - */ - function onSocketOpen(callback: types.SocketOpenCallback): void; - /** - * 监听WebSocket 连接关闭事件 - */ - function onSocketClose(callback: () => void): void; - /** - * 监听WebSocket 接受到服务器的消息事件 - */ - function onSocketMessage(callback: types.SocketMessageCallback): void; - /** - * 监听WebSocket 错误事件 - */ - function onSocketError(callback: types.SocketErrorCallback): void; - /** - * 通过 WebSocket 连接发送数据,需要先 wx.connectSocket,并在 wx.onSocketOpen 回调之后才能发送。 - */ - function sendSocketMessage(param: types.SocketSendParams): void; - - // --UDP通信 - /** - * 创建一个 UDP Socket 实例 - */ - function createUDPSocket(): UDPSocket; - - // --上传 - function uploadFile(param: { - /** - * 开发者服务器地址 - */ - url: string, - /** - * 要上传文件资源的路径 - */ - filePath: string, - /** - * 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容 - */ - name: string, - /** - * HTTP 请求 Header,Header 中不能设置 Referer - */ - header?: { [key: string]: string }, - /** - * HTTP 请求中其他额外的 form data - */ - formData?: { [key: string]: any }, - success?: (res: { data: string, statusCode: number }) => void, - fail?: () => void, - complete?: () => void - }): UploadTask; - - // --开放数据 - /** - * 拉取当前用户所有同玩好友的托管数据。该接口只可在开放数据域下使用 - */ - function getFriendCloudStorage(param: { - /** - * 要拉取的 key 列表 - */ - keyList: string[], - success?: (res: { data: ReadonlyArray }) => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 获取当前用户托管数据当中对应 key 的数据。该接口只可在开放数据域下使用 - */ - function getUserCloudStorage(param: { - /** - * 要拉取的 key 列表 - */ - keyList: string[], - success?: (res: { KVDataList: ReadonlyArray }) => void, - fail?: () => void, - complete?: () => void - }): void; - - /** - * 在无须用户授权的情况下,批量获取用户信息。该接口只在开放数据域下可用 - * 请注意!!旧版本的该接口已过期,微信不允许主动弹出授权框,旧版本API会被逐渐作废,请使用wx.createUserInfoButton或在隔离数据区取得用户信息 - * 如使用旧接口取得用户信息,withCredentials 为 true 时需要先调用 wx.login 接口。需要用户授权 scope.userInfo - */ - function getUserInfo(param: types.NewUserInfoParam | types.OldUserInfoParam): void; - /** - * 在小游戏是通过群分享卡片打开的情况下,可以通过调用该接口获取群同玩成员的游戏数据。该接口只可在开放数据域下使用。 - */ - function getGroupCloudStorage(param: { - /** - * 群分享对应的 shareTicket - */ - shareTicket: string, - /** - * 要拉取的 key 列表 - */ - keyList: string[], - success?: (res: { data: ReadonlyArray }) => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 删除用户托管数据当中对应 key 的数据。 - */ - function removeUserCloudStorage(param: { - /** - * 要删除掉 key 列表 - */ - keyList: string[], - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 对用户托管数据进行写数据操作,允许同时写多组 KV 数据。 - * 托管数据的限制 - * > 每个openid所标识的微信用户在每个游戏上托管的数据不能超过128个key-value对。 - * > 上报的key-value列表当中每一项的key+value长度都不能超过1K(1024)字节。 - * > 上报的key-value列表当中每一个key长度都不能超过128字节。 - */ - function setUserCloudStorage(param: { - /** - * 要修改的 KV 数据列表 - */ - KVDataList: ReadonlyArray, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 监听成功修改好友的互动型托管数据事件,该接口在游戏主域使用 - * @param callback 事件发生的回调函数,只有一个参数为 wx.modifyFriendInteractiveStorage 传入的 key - */ - function onInteractiveStorageModified(callback: (key: string) => void): void; - /** - * 修改好友的互动型托管数据,该接口只可在开放数据域下使用,示例代码: - * wx.modifyFriendInteractiveStorage({ - * key: '1', - * opNum: 1, - * operation: 'add', - * toUser: '', // 好友的 openId - * title: '送你 10 个金币,赶快打开游戏看看吧', // 2.9.0 支持 - * imageUrl: 'image/xxx' // 2.9.0 支持 - * }); - * - * 赠送动作的校验: - * 调用该接口需要上传 JSServer 函数 "checkInteractiveData",该函数可用于执行赠送动作的校验逻辑,校验通过后返回结果表示本次赠送是否合法。只有 checkInteractiveData 返回了 {ret: true},此次修改才会成功。 - * - * 使用模板规则进行交互: - * 每次调用该接口会弹窗询问用户是否确认执行该操作,2.9.0 之后版本,需要在 game.json 中设置 modifyFriendInteractiveStorageTemplates 来定制交互的文案。 - * modifyFriendInteractiveStorageTemplates是一个模板数组,每一个模板需要有 key, action, object 参数,还有一个可选参数 ratio,详细说明见示例配置: - * { - * "modifyFriendInteractiveStorageTemplates": [ - * { - * "key": "1", // 这个 key 与接口中同名参数相对应,不同的 key 对应不同的模板 - * "action": "赠送", // 互动行为 - * "object": "金币", // 互动物品 - * "ratio": 10 // 物品比率,opNum * ratio 代表物品个数 - * } - * ] - * } - * 最后生成的文案为 "确认 ${action} ${nickname} ${object}?",或者 "确认 ${action} ${nickname} ${object} x ${opNum * ratio}?" - * - * 使用自定义文案进行交互: - * 2.7.7 之后,2.9.0 之前的版本,文案通过 game.json 的 modifyFriendInteractiveStorageConfirmWording 字段配置。 配置内容可包含 nickname 变量,用 ${nickname} 表示,实际调用时会被替换成好友的昵称。示例配置: - * { - * "modifyFriendInteractiveStorageConfirmWording": "确认送给${nickname}一个体力?" - * } - * 2.9.0 之后,在 modifyFriendInteractiveStorageTemplates 和 modifyFriendInteractiveStorageConfirmWording 都存在的情况下,会优先使用前者。 - */ - function modifyFriendInteractiveStorage(param: { - /** - * 需要修改的数据的 key,目前可以为 '1' - '50' - */ - key: string, - /** - * 需要修改的数值,目前只能为 1 - */ - opNum: number, - /** - * 修改类型 - */ - operation: "add", - /** - * 目标好友的 openId - */ - toUser?: string - /** - * 分享标题,如果设置了这个值,则在交互成功后自动询问用户是否分享给好友(需要配置模板规则) - */ - title?: string - /** - * 分享图片地址,详见 wx.shareMessageToFriend 同名参数(需要配置模板规则) - */ - imageUrl?: string, - /** - * 分享图片 ID,详见 wx.shareMessageToFriend 同名参数(需要配置模板规则) - */ - imageUrlId?: string, - /** - * 是否静默修改(不弹框),静默修改需要用户通过快捷分享消息卡片进入才有效,代表分享反馈操作,无需填写 toUser,直接修改分享者与被分享者交互数据 - * 默认值false - */ - quiet?: boolean, - success?: () => void; - fail?: (res: { - /** - * 错误信息 - */ - errMsg: string, - /** - * 错误码 - * -17006 非好友关系 - * -17007 非法的 toUser openId - * -17008 非法的 key - * -17009 非法的 operation - * -17010 非法的操作数 - * -17011 JSServer 校验写操作失败 - */ - errCode: number - }) => void; - complete?: () => void; - }): void; - /** - * 获取当前用户互动型托管数据对应 key 的数据 - */ - function getUserInteractiveStorage(param: { - /** - * 要获取的 key 列表 - */ - keyList: string[] - } & types.CallbacksWithType2<{ - /** - * 加密数据,包含互动型托管数据的值。解密后的结果为一个 KVDataList,每一项为一个 KVData。 用户数据的签名验证和加解密 - */ - encryptedData: string, - /** - * 敏感数据对应的云 ID,开通云开发的小程序才会返回,可通过云调用直接获取开放数据,详细见云调用直接获取开放数据 - */ - cloudID: string - }, { - /** - * 错误信息 - */ - errMsg: string, - /** - * 错误码 - * -17008 非法的 key - */ - errCode: number - }>): void; - /** - * 获取可能对游戏感兴趣的未注册的好友名单。每次调用最多可获得 5 个好友,此接口只能在开放数据域中使用 - */ - function getPotentialFriendList(callback: types.CallbacksWithType<{ - /** - * 可能对游戏感兴趣的未注册好友名单 - */ - list: ReadonlyArray<{ - /** - * 用户的微信头像 url - */ - avatarUrl: string, - /** - * 用户的微信昵称 - */ - nickname: string, - /** - * 用户 openid - */ - openid: string - }> - }>): void; - - // --登录 - /** - * 通过 wx.login 接口获得的用户登录态拥有一定的时效性。用户越久未使用小程序,用户登录态越有可能失效。反之如果用户一直在使用小程序,则用户登录态一直保持有效。具体时效逻辑由微信维护,对开发者透明。开发者只需要调用 wx.checkSession 接口检测当前用户登录态是否有效。登录态过期后开发者可以再调用 wx.login 获取新的用户登录态。 - */ - function checkSession(cb: types.Callbacks): void; - /** - * 调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。 - */ - function login(cb: types.CallbacksWithType<{ - /** - * 用户登录凭证(有效期五分钟)。开发者需要在开发者服务器后台调用 code2accessToken,使用 code 换取 openid 和 session_key 等信息 - */ - code: string - }>): void; - - // --防沉迷 - /** - * 根据用户当天游戏时间判断用户是否需要休息 - */ - function checkIsUserAdvisedToRest(param: { - /** - * 今天已经玩游戏的时间,单位:秒 - */ - todayPlayedTime: number, - success?: (res: { - /** - * 是否建议用户休息 - */ - result: boolean - }) => void, - fail?: () => void, - complete?: () => void - }): void; - - // --小程序跳转 - /** - * 打开另一个小程序 - * @param param 跳转参数 - */ - function navigateToMiniProgram(param: { - /** - * 要打开的小程序 appId - */ - appId: string, - /** - * 打开的页面路径,如果为空则打开首页。path 中 ? 后面的部分会成为 query,在小程序的 App.onLaunch、App.onShow - * 和 Page.onLoad 的回调函数或小游戏的 wx.onShow 回调函数、wx.getLaunchOptionsSync 中可以获取到 query 数据。 - * 对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。 - */ - path?: string, - /** - * 需要传递给目标小程序的数据,目标小程序可在 App.onLaunch,App.onShow 中获取到这份数据。如果跳转的是小游戏,可以在 wx.onShow、wx.getLaunchOptionsSync 中可以获取到这份数据数据。 - */ - extraData?: any, - /** - * 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。默认值release - * develop 开发版 - * trial 体验版 - * release 正式版 - */ - envVersion?: "develop" | "trial" | "release" - } & types.Callbacks): void; - - // --用户信息 - function createUserInfoButton(param: { - /** - * 按钮类型 - */ - type: types.ButtonType, - /** - * 按钮上的文本,仅当 type 为 text 时有效 - */ - text?: string, - /** - * 按钮的背景图片,仅当 type 为 image 时有效 - */ - image?: string, - /** - * 按钮的样式 - */ - style?: types.ButtonStyle, - /** - * 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。 - */ - withCredentials?: boolean, - lang?: "en" | "zh_CN" | "zh_TW" - }): UserInfoButton; - - // --设置 - /** - * 创建打开设置页面的按钮 - */ - function createOpenSettingButton(param: { - /** - * 按钮类型 - */ - type: types.ButtonType, - /** - * 按钮上的文本,仅当 type 为 text 时有效 - */ - text?: string, - /** - * 按钮的背景图片,仅当 type 为 image 时有效 - */ - image?: string, - /** - * 按钮的样式 - */ - style?: types.ButtonStyle - }): OpenSettingButton; - /** - * 获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 - */ - function getSetting(p: types.CallbacksWithType<{ authSetting: types.AuthSetting }>): void; - /** - * 调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 - * @deprecated - */ - function openSetting(p: types.CallbacksWithType<{ authSetting: types.AuthSetting }>): void; - - // --微信运动 - /** - * 获取用户过去三十天微信运动步数,需要先调用 wx.login 接口。需要用户授权 scope.werun。 - */ - function getWeRunData(p: types.CallbacksWithType<{ - /** - * 包括敏感数据在内的完整用户信息的加密数据,详细见加密数据解密算法 - */ - encryptedData: string, - /** - * 加密算法的初始向量 - */ - iv: string - }>): void; - - // --卡券 - /** - * 查看微信卡包中的卡券。只有通过 认证 的小程序或文化互动类目的小游戏才能使用。更多文档请参考:微信卡券接口文档(https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2) - */ - function openCard(param: { - /** - * 需要打开的卡券列表 - */ - cardList: ReadonlyArray<{ - /** - * 卡券 ID - */ - cardId: string, - /** - * 由 wx.addCard 的返回对象中的加密 code 通过解密后得到,解密请参照:code 解码接口(https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Coupons-Mini_Program_Start_Up.html) - */ - code: string - }> - } & types.CallbacksWithType): void; // TODO: success回调里的res的结构官方文档没写 - /** - * 批量添加卡券。只有通过 认证 的小程序或文化互动类目的小游戏才能使用。更多文档请参考 微信卡券接口文档(https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2)。 - */ - function addCard(param: { - /** - * 需要添加的卡券列表 - */ - cardList: ReadonlyArray<{ - /** - * 卡券 ID - */ - cardId: string, - /** - * 卡券的扩展参数。需将 CardExt 对象 JSON 序列化为字符串传入 - */ - cardExt: string - }> - } & types.CallbacksWithType<{ - /** - * 卡券添加结果列表 - */ - cardList: ReadonlyArray<{ - /** - * 加密 code,为用户领取到卡券的code加密后的字符串,解密请参照:code 解码接口 - */ - code: string, - /** - * 用户领取到卡券的 ID - */ - cardId: string, - /** - * 卡券的扩展参数,值为一个 JSON 字符串 - */ - cardExt: string, - /** - * 是否成功 - */ - isSuccess: boolean - }> - }>): void; - - // --授权 - /** - * 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。 - */ - function authorize(param: { - /** - * 需要获取权限的 scope - */ - scope: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --游戏圈 - /** - * 创建游戏圈按钮。游戏圈按钮被点击后会跳转到小游戏的游戏圈。更多关于游戏圈的信息见 游戏圈使用指南 - */ - function createGameClubButton(param: { - type: types.ButtonType, - text?: string, - image?: string, - style?: types.ButtonStyle, - /** - * 游戏圈按钮的图标,仅当 object.type 参数为 image 时有效 - */ - icon?: types.GameClubButtonIcon - }): GameClubButton; - - // --意见反馈 - /** - * 用户点击后打开意见反馈页面的按钮 - */ - function createFeedbackButton(param: { - type: types.ButtonType, - text?: string, - image?: string, - style?: types.ButtonStyle - }): FeedbackButton; - - // --客服消息 - /** - * 进入客服会话,要求在用户发生过至少一次 touch 事件后才能调用。后台接入方式与小程序一致,详见 客服消息接入 - */ - function openCustomerServiceConversation(param: { - /** - * 会话来源 - */ - sessionFrom?: string, - /** - * 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话之后会收到一个消息卡片,通过以下三个参数设置卡片的内容 - */ - showMessageCard?: boolean, - /** - * 会话内消息卡片标题 - */ - sendMessageTitle?: string, - /** - * 会话内消息卡片路径 - */ - sendMessagePath?: string, - /** - * 会话内消息卡片图片路径 - */ - sendMessageImg?: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --开放数据域 - /** - * 获取开放数据域 - */ - function getOpenDataContext(): OpenDataContext; - /** - * 监听主域发送的消息 - */ - function onMessage(callback: (data: any) => void): void; - - // --转发 - /** - * 获取转发详细信息 - */ - function getShareInfo(param: { - shareTicket: string, - success?: (res: { - /** - * 错误信息 - */ - errMsg: string, - /** - * 包括敏感数据在内的完整转发信息的加密数据 - */ - encryptedData: string, - /** - * 加密算法的初始向量 - */ - iv: string - }) => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 隐藏转发按钮 - */ - function hideShareMenu(cb?: types.Callbacks): void; - /** - * 监听用户点击右上角菜单的“转发”按钮时触发的事件 - */ - function onShareAppMessage(cb: () => types.ShareOption): void; - /** - * 取消监听用户点击右上角菜单的“转发”按钮时触发的事件 - */ - function offShareAppMessage(cb: () => types.ShareOption): void; - /** - * 显示当前页面的转发按钮 - */ - function showShareMenu(param?: { - /** - * 是否使用带 shareTicket 的转发 - */ - withShareTicket: boolean, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 主动拉起转发,进入选择通讯录界面。 - */ - function shareAppMessage(param: types.ShareOption): void; - /** - * 设置 wx.shareMessageToFriend 接口 query 字段的值 - * @param param 设置参数 - * @returns 是否设置成功 - */ - function setMessageToFriendQuery(param: { - /** - * 需要传递的代表场景的数字,需要在 0 - 50 之间 - */ - shareMessageToFriendScene: number; - }): boolean; - /** - * 给指定的好友分享游戏信息,该接口只可在开放数据域下使用 - * 定向分享不允许直接在开放数据域设置 query 参数 需要设置时请参见游戏域 wx.setMessageToFriendQuery 接口 - * @param param 分享参数 - */ - function shareMessageToFriend(param: { - /** - * 发送对象的 openId - */ - openId: string, - /** - * 转发标题,不传则默认使用当前小游戏的昵称。 - */ - title?: string, - /** - * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5:4 - */ - imageUrl?: string - /** - * 审核通过的图片 ID,详见 使用审核通过的转发图片(https://developers.weixin.qq.com/minigame/dev/guide/open-ability/sh - * are/share.html#%E4%BD%BF%E7%94%A8%E5%AE%A1%E6%A0%B8%E9%80%9A%E8%BF%87%E7%9A%84%E8%BD%AC%E5%8F%91%E5%9B%BE%E7%89%87) - */ - imageUrlId?: string - }): void; - /** - * 更新转发属性 - */ - function updateShareMenu(param: { - /** - * 是否使用带 shareTicket 的转发详情 - */ - withShareTicket: boolean, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --性能 - /** - * 获取性能管理器 - */ - function getPerformance(): WxPerformance; - /** - * 加快触发 JavaScriptCore Garbage Collection(垃圾回收),GC 时机是由 JavaScriptCore 来控制的,并不能保证调用后马上触发 GC。 - */ - function triggerGC(): void; - /** - * 监听内存不足告警 - * @param callback.res.level 内存告警等级,只有 Android 才有,对应系统宏定义: - * 10 TRIM_MEMORY_RUNNING_LOW - * 15 TRIM_MEMORY_RUNNING_CRITICAL - */ - function onMemoryWarning(callback: (res: { level: number }) => void): void; - - /** - * 标记自定义场景 - * @param sceneId 在管理后台配置过的场景ID - */ - function markScene(sceneId: number): void; - - // --调试 - function setEnableDebug(p: { - enableDebug: boolean, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - /** - * 获取日志管理器对象 - * @param param 初始化时的参数 - */ - function getLogManager(param?: { - /** - * 取值为0或1,取值为0时会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志,取值为1则不会。 - * 默认值是 0 - */ - level?: 0 | 1 - }): LogManager; - - // --数据上报 - /** - * 自定义业务数据监控上报接口。 - * 使用前,需要在「小程序管理后台-运维中心-性能监控-业务数据监控」中新建监控事件,配置监控描述与告警类型。每一个监控事件对应唯一的监控ID,开发者最多可以创建128个监控事件。 - * @param name 监控ID,在「小程序管理后台」新建数据指标后获得 - * @param value 上报数值,经处理后会在「小程序管理后台」上展示每分钟的上报总量 - */ - function reportMonitor(name: string, value: number): void; - - // --订阅消息 - /** - * 调起小游戏订阅消息界面,返回用户订阅消息的操作结果。(需要在 touchend 事件的回调中调用) - */ - function requestSubscribeMessage(param: { - /** - * 需要订阅的消息模板的id的集合(注意:iOS客户端7.0.6版本、Android客户端7.0.7版本之后的一次订阅才支持多个模板消息,iOS客户端7.0.5版本、Android客户端7.0.6版本之前的一次订阅 - * 只支持一个模板消息)消息模板id在[微信公众平台(mp.weixin.qq.com)-功能-订阅消息]中配置 - */ - tmplIds: ReadonlyArray; - } & types.CallbacksWithType2<{ - /** - * 接口调用成功时errMsg值为'requestSubscribeMessage:ok' - */ - errMsg: string; - /** - * [TEMPLATE_ID]是动态的键,即模板id,值包括'accept'、'reject'、'ban'。'accept'表示用户同意订阅该条id对应的模板消息,'reject'表示用户拒绝订阅该条id对应的模板消息,'ban'表示 - * 已被后台封禁。例如 { errMsg: "requestSubscribeMessage:ok", zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept"} 表示用户同意订阅zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE这条消息 - */ - [TEMPLATE_ID: string]: 'accept' | 'reject' | 'ban' | string; - }, { - /** - * 接口调用失败错误信息 - */ - errMsg: string; - /** - * 接口调用失败错误码 - */ - errCode: number; - }>): void; - - // --数据缓存 - /** - * 清理本地数据缓存 - */ - function clearStorage(param: types.Callbacks): void; - /** - * clearStorage的同步版本 - */ - function clearStorageSync(): void; - /** - * 从本地缓存中异步获取指定 key 的内容 - */ - function getStorage(param: types.GetStorageParams): void; - /** - * getStorage 的同步版本 - */ - function getStorageSync(key: string): any; - /** - * 异步获取当前storage的相关信息 - */ - function getStorageInfo(param: types.CallbacksWithType): void; - /** - * getStorageInfo 的同步版本 - */ - function getStorageInfoSync(): types.StorageInfo; - /** - * 从本地缓存中移除指定 key - */ - function removeStorage(param: types.RemoveStorageParams): void; - /** - * removeStorage 的同步版本 - * @param key 本地缓存中指定的 key - */ - function removeStorageSync(key: string): void; - /** - * 将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容。 - */ - function setStorage(param: types.SetStorageParams): void; - /** - * setStorage 的同步版本 - * @param key 本地缓存中指定的 key - * @param data 需要存储的内容 - */ - function setStorageSync(key: string, data: any): void; - - // --分包加载 - /** - * 触发分包加载,详见 分包加载 - */ - function loadSubpackage(param: { - /** - * 分包的名字,可以填 name 或者 root - */ - name: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): LoadSubpackageTask; - - // --菜单 - /** - * 获取菜单按钮的布局置信息 - */ - function getMenuButtonBoundingClientRect(): { - /** - * 宽度 - */ - width: number, - /** - * 高度 - */ - height: number, - /** - * 上边界坐标 - */ - top: number, - /** - * 右边界坐标 - */ - right: number, - /** - * 下边界坐标 - */ - bottom: number, - /** - * 左边界坐标 - */ - left: number - }; - function setMenuStyle(param: { - /** - * 样式风格 - */ - style: "light" | "dark", - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --交互 - /** - * 显示消息提示框 - */ - function showToast(param: { - /** - * 提示的内容 - */ - title?: string, - /** - * 图标 - */ - icon?: "success" | "loading", - /** - * 自定义图标的本地路径,image 的优先级高于 icon - */ - image?: string, - /** - * 提示的延迟时间 - */ - duration?: number, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 隐藏消息提示框 - */ - function hideToast(cb?: types.Callbacks): void; - /** - * 显示模态对话框 - */ - function showModal(param: { - /** - * 提示的标题 - */ - title?: string, - /** - * 提示的内容 - */ - content?: string, - /** - * 是否显示取消按钮,默认true - */ - showCancel?: boolean, - /** - * 取消按钮的文字,最多 4 个字符串 - */ - cancelText?: string, - /** - * 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值#000000 - */ - cancelColor?: string, - /** - * 确认按钮的文字,最多 4 个字符串 - */ - confirmText?: string, - /** - * 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值#3cc51f - */ - confirmColor?: string, - success?: (res: { confirm?: boolean, cancel?: boolean }) => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 显示 loading 提示框, 需主动调用 wx.hideLoading 才能关闭提示框 - */ - function showLoading(prms?: { - /** - * 提示的内容 - */ - title?: string, - /** - * 是否显示透明蒙层 - */ - mask?: boolean, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 隐藏 loading 提示框 - */ - function hideLoading(cb?: types.Callbacks): void; - /** - * 显示选择器 - */ - function showActionSheet(params: { - /** - * 按钮的文字数组,数组长度最大为 6 - */ - itemList: string[], - /** - * 按钮的文字颜色,默认值#000000 - */ - itemColor?: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --键盘 - function hideKeyboard(): void; - /** - * 监听键盘输入事件 - * @param callback.res.value 键盘输入的当前值 - */ - function onKeyboardInput(callback: (res: { value: string }) => void): void; - /** - * 取消监听键盘输入事件 - */ - function offKeyboardInput(callback: (res: { value: string }) => void): void; - /** - * 监听用户点击键盘 Confirm 按钮时的事件 - * @param callback.res.value 键盘输入的当前值 - */ - function onKeyboardConfirm(callback: (res: { value: string }) => void): void; - /** - * 取消监听用户点击键盘 Confirm 按钮时的事件 - */ - function offKeyboardConfirm(callback: (res: { value: string }) => void): void; - /** - * 监听监听键盘收起的事件 - * @param callback.res.value 键盘输入的当前值 - */ - function onKeyboardComplete(callback: (res: { value: string }) => void): void; - /** - * 取消监听监听键盘收起的事件 - */ - function offKeyboardComplete(callback: (res: { value: string }) => void): void; - /** - * 显示键盘 - */ - function showKeyboard(param: { - /** - * 键盘输入框显示的默认值 - */ - defaultValue: string, - /** - * 键盘中文本的最大长度 - */ - maxLength?: number, - /** - * 是否为多行输入 - */ - multiple?: boolean, - /** - * 当点击完成时键盘是否收起 - */ - confirmHold?: boolean, - /** - * 键盘右下角 confirm 按钮的类型,只影响按钮的文本内容 - */ - confirmType?: "done" | "next" | "search" | "go" | "send" - }): void; - /** - * 更新键盘,只有当键盘处于拉起状态时才会产生效果 - */ - function updateKeyboard(param: { - /** - * 键盘输入框的当前值 - */ - value: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --状态栏 - /** - * 当在配置中设置 showStatusBarStyle 时,屏幕顶部会显示状态栏。此接口可以修改状态栏的样式。 - */ - function setStatusBarStyle(param: { - style: "white" | "black", - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --窗口 - /** - * 监听窗口尺寸变化事件 - */ - function onWindowResize(cb: (res: { windowWidth: number, windowHeight: number }) => void): void; - /** - * 取消监听窗口尺寸变化事件 - */ - function offWindowResize(cb: (res: { windowWidth: number, windowHeight: number }) => void): void; - - // --更新 - function getUpdateManager(): UpdateManager; - - // --Worker - /** - * 创建一个 Worker 线程,目前限制最多只能创建一个 Worker,创建下一个 Worker 前请调用 Worker.terminate - */ - function createWorker(): WxWorker; - - // --音频 - /** - * 创建一个 InnerAudioContext 实例 - */ - function createInnerAudioContext(): InnerAudioContext; - /** - * 获取当前支持的音频输入源 - */ - function getAvailableAudioSources(param: types.CallbacksWithType<{ - /** - * 音频输入源,每一项对应一种音频输入源 - */ - audioSources: ReadonlyArray - }>): void; - - // --录音 - function getRecorderManager(): RecorderManager; - - // --图片 - /** - * 从本地相册选择图片或使用相机拍照。 - */ - function chooseImage(param: { - count: number, - /** - * 所选的图片的尺寸 - */ - sizeType: ['original'] | ['compressed'] | ['original', 'compressed'], - /** - * 选择图片的来源 - */ - sourceType: ['album'] | ['camera'] | ['album', 'camera'], - success?: (res: { tempFilePaths: ReadonlyArray, tempFiles: ReadonlyArray }) => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 预览图片,调用之后会在新打开的页面中全屏预览传入的图片,预览的过程中用户可以进行保存图片、发送给朋友等操作 - */ - function previewImage(param: { - /** - * 需要预览的图片链接列表 - */ - urls: string[], - /** - * 当前显示图片的链接,默认为urls的第一张 - */ - current?: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - /** - * 保存图片到系统相册。需要用户授权 scope.writePhotosAlbum - */ - function saveImageToPhotosAlbum(param: { - /** - * 图片文件路径,可以是临时文件路径也可以是永久文件路径,不支持网络图片路径 - */ - filePath: string, - success?: () => void, - fail?: () => void, - complete?: () => void - }): void; - - // --视频 - function createVideo(param: { - /** - * 视频的左上角横坐标 - */ - x?: number, - /** - * 视频的左上角纵坐标 - */ - y?: number, - /** - * 视频的宽度,默认值300 - */ - width?: number, - /** - * 默认值150 - */ - height?: number, - /** - * 视频的资源地址 - */ - src: string, - /** - * 视频的封面 - */ - poster?: string, - /** - * 视频的初始播放位置,单位为 s 秒,默认值0 - */ - initialTime?: number, - /** - * 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0 - */ - playbackRate?: number, - /** - * 视频是否为直播,默认值0 - */ - live?: number, - /** - * 视频的缩放模式 - * fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例 - * contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白 - * cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见 - */ - objectFit?: "contain" | "cover" | "fill", - /** - * 视频是否显示控件,默认true - */ - controls?: boolean, - /** - * 视频是否自动播放,默认false - */ - autoplay?: boolean, - /** - * 视频是否是否循环播放,默认值false - */ - loop?: boolean, - /** - * 视频是否禁音播放,默认值false - */ - muted?: boolean - }): Video; - - // --相机 - /** - * 创建相机 - * @param param 创建相机所需的初始化信息 - */ - function createCamera(param?: types.Callbacks & { - /** - * 相机的左上角横坐标,默认值0 - */ - x?: number; - /** - * 相机的左上角纵坐标,默认值0 - */ - y?: number; - /** - * 相机的宽度,默认值300 - */ - width?: number; - /** - * 相机的高度,默认值150 - */ - height?: number; - /** - * 摄像头朝向,值为 front, back,默认值back - */ - devicePosition?: "front" | "back"; - /** - * 闪光灯,值为 auto, on, off,默认值auto - */ - flash?: "auto" | "on" | "off"; - /** - * 帧数据图像尺寸,值为 small, medium, large,默认值small - */ - size?: "small" | "medium" | "large"; - }): Camera; - - // -- VoIP - /** - * 更新实时语音静音设置 - * @param param 静音设置 - */ - function updateVoIPChatMuteConfig(param: types.Callbacks & { - /** - * 静音设置 - */ - muteConfig: { - /** - * 是否静音麦克风,默认值false - */ - muteMicrophone?: boolean, - /** - * 是否静音耳机,默认值false - */ - muteEarphone?: boolean - } - }): void; - /** - * 监听实时语音通话成员通话状态变化事件。有成员开始/停止说话时触发回调 - * @param callback 实时语音通话成员通话状态变化事件的回调函数 - */ - function onVoIPChatSpeakersChanged(callback: (res: { - /** - * 还在实时语音通话中的成员 openId 名单 - */ - openIdList: ReadonlyArray, - /** - * 错误码 - */ - errCode: number, - /** - * 调用结果(错误原因) - */ - errMsg: string - }) => void): void; - /** - * 取消监听实时语音通话成员通话状态变化事件。 - * @param callback 之前监听的回调函数 - */ - function offVoIPChatSpeakersChanged(callback: any): void; - /** - * 监听实时语音通话成员在线状态变化事件。有成员加入/退出通话时触发回调 - * @param callback 实时语音通话成员在线状态变化事件的回调函数 - */ - function onVoIPChatMembersChanged(callback: (res: { - /** - * 还在实时语音通话中的成员 openId 名单 - */ - openIdList: ReadonlyArray, - /** - * 错误码 - */ - errCode: number, - /** - * 调用结果(错误原因) - */ - errMsg: string - }) => void): void; - /** - * 取消监听实时语音通话成员在线状态变化事件。 - * @param callback 之前监听的回调函数 - */ - function offVoIPChatMembersChanged(callback: any): void; - /** - * 监听被动断开实时语音通话事件。包括小游戏切入后端时断开 - * @param callback 被动断开实时语音通话事件的回调函数 - */ - function onVoIPChatInterrupted(callback: (res: { - /** - * 错误码 - */ - errCode: number, - /** - * 调用结果(错误原因) - */ - errMsg: string - }) => void): void; - /** - * 取消监听被动断开实时语音通话事件。 - * @param callback 之前监听的回调函数 - */ - function offVoIPChatInterrupted(callback: any): void; - /** - * 加入 (创建) 实时语音通话,更多信息可见:实时语音指南(https://developers.weixin.qq.com/minigame/dev/guide/open-ability/voip-chat.html) - * 错误码 - * -1 当前已在房间内 - * -2 录音设备被占用,可能是当前正在使用微信内语音通话或系统通话 - * -3 加入会话期间退出(可能是用户主动退出,或者退后台、来电等原因),因此加入失败 - * -1000 系统错误 - * @param param 加入语音聊天时的初始化参数 - */ - function joinVoIPChat(param: types.CallbacksWithType<{ - /** - * 在此通话中的成员 openId 名单 - */ - openIdList: ReadonlyArray, - /** - * 错误码 - */ - errCode: number, - /** - * 调用结果 - */ - errMsg: string - }> & { - /** - * 签名,用于验证小游戏的身份 - */ - signature: string, - /** - * 验证所需的随机字符串 - */ - nonceStr: string, - /** - * 验证所需的时间戳 - */ - timeStamp: number, - /** - * 小游戏内此房间/群聊的 ID。同一时刻传入相同 groupId 的用户会进入到同个实时语音房间。 - */ - groupId: string, - /** - * 静音设置 - */ - muteConfig?: { - /** - * 是否静音麦克风,默认值false - */ - muteMicrophone?: boolean, - /** - * 是否静音耳机,默认值false - */ - muteEarphone?: boolean - } - }): void; - /** - * 退出(销毁)实时语音通话 - */ - function exitVoIPChat(callbacks?: types.Callbacks): void; - - // --广告 - /** - * 创建 banner 广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.0.4 后再使用该 API。同时,开发者工具上暂不支持调试该 API,请直接在真机上进行调试。 - */ - function createBannerAd(param: { - /** - * 广告单元 id - */ - adUnitId: string, - /** - * banner 广告组件的样式 - */ - style: types.AdStyle - }): BannerAd; - /** - * 创建激励视频广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.0.4 后再使用该 API。同时,开发者工具上暂不支持调试该 API,请直接在真机上进行调试。 - */ - function createRewardedVideoAd(param: { - /** - * 广告单元 id - */ - adUnitId: string - }): RewardedVideoAd; - /** - * 创建插屏广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号后再使用该 API。每次调用该方法创建插屏广告都会返回一个全新的实例(小程序端的插屏广告实例不允许跨页面使用)。 - */ - function createInterstitialAd(param: { - /** - * 广告单元 id - */ - adUnitId: string - }): InterstitialAd; - - // --虚拟支付 - /** - * 发起米大师支付 - */ - function requestMidasPayment(param: { - /** - * 支付的类型,不同的支付类型有各自额外要传的附加参数。 - * game - 购买游戏币 - */ - mode: "game", - /** - * 环境配置,默认值0 - * 0 - 米大师正式环境 - * 1 - 米大师沙箱环境 - */ - env?: 0 | 1, - /** - * 在米大师侧申请的应用 id - */ - offerId: string, - /** - * 币种 - */ - currencyType: "CNY", - /** - * 申请接入时的平台,platform 与应用id有关。 - */ - platform?: "android", - /** - * 购买数量。mode=game 时必填。购买数量。详见 buyQuantity 限制说明。 - * mode为game(购买游戏币)时,buyQuantity不可任意填写。需满足 buyQuantity * 游戏币单价 = 限定的价格等级。如:游戏币单价为 0.1 元,一次购买最少数量是 10。 - * 有效价格等级如下: - * 价格等级(单位:人民币) - * 1 - * 3 - * 6 - * 8 - * 12 - * 18 - * 25 - * 30 - * 40 - * 45 - * 50 - * 60 - * 68 - * 73 - * 78 - * 88 - * 98 - * 108 - * 118 - * 128 - * 148 - * 168 - * 188 - * 198 - * 328 - * 648 - */ - buyQuantity?: number, - /** - * 分区 ID - */ - zoneId?: string, - success?: () => void, - /** - * @param res.errCode 有如下值: - * -1 系统失败 - * -2 支付取消 - * -15001 虚拟支付接口错误码,缺少参数 - * -15002 虚拟支付接口错误码,参数不合法 - * -15003 虚拟支付接口错误码,订单重复 - * -15004 虚拟支付接口错误码,后台错误 - * -15006 虚拟支付接口错误码,appId 权限被封禁 - * -15006 虚拟支付接口错误码,货币类型不支持 - * -15007 虚拟支付接口错误码,订单已支付 - * 1 虚拟支付接口错误码,用户取消支付 - * 2 虚拟支付接口错误码,客户端错误, 判断到小程序在用户处于支付中时,又发起了一笔支付请求 - * 3 虚拟支付接口错误码,Android 独有错误:用户使用 Google Play 支付,而手机未安装 Google Play - * 4 虚拟支付接口错误码,用户操作系统支付状态异常 - * 5 虚拟支付接口错误码,操作系统错误 - * 6 虚拟支付接口错误码,其他错误 - * 1000 参数错误 - * 1003 米大师 Portal 错误 - */ - fail?: (res: { errMsg: string, errCode: number }) => void, - complete?: () => void - }): void; -} \ No newline at end of file diff --git a/source/src/ECS/Component.ts b/source/src/ECS/Component.ts index fe7b133b..35cf9d54 100644 --- a/source/src/ECS/Component.ts +++ b/source/src/ECS/Component.ts @@ -78,12 +78,6 @@ module es { public onEntityTransformChanged(comp: transform.Component) { } - /** - * - */ - public debugRender(camera: Camera) { - } - /** *当父实体或此组件启用时调用 */ diff --git a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts index f4c14b03..7689b0b3 100644 --- a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts @@ -74,9 +74,6 @@ module es { } } - public debugRender(camera: Camera) { - } - public toString() { return `[BoxCollider: bounds: ${this.bounds}]`; } diff --git a/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts b/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts index eb8c4300..aa2267fb 100644 --- a/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts @@ -36,10 +36,6 @@ module es { return this; } - public debugRender(camera: Camera) { - - } - public toString() { return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]` } diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 4b3b0be1..a36e865a 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -302,13 +302,6 @@ module es { this.components.update(); } - /** - * 在默认渲染器中,如果Core.debugRenderEnabled为true,则调用。自定义渲染器可以选择是否调用它。 - */ - public debugRender(camera: Camera){ - this.components.debugRender(camera); - } - /** * 将组件添加到组件列表中。返回组件。 * @param component diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index 86abc5ba..bdc5473d 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -1,10 +1,6 @@ module es { /** 场景 */ export class Scene { - /** - * 默认场景摄像机 - */ - public camera: Camera; /** * 这个场景中的实体列表 */ @@ -31,15 +27,6 @@ module es { this.initialize(); } - /** - * 辅助器,创建一个场景与DefaultRenderer附加并准备使用 - */ - public static createWithDefaultRenderer() { - let scene = new Scene(); - scene.addRenderer(new DefaultRenderer()); - return scene; - } - /** * 在场景子类中重写这个并在这里进行加载。在场景设置好之后,在调用begin之前,从构造器中调用。 */ @@ -72,11 +59,6 @@ module es { } public begin() { - if (this._renderers.length == 0) { - this.addRenderer(new DefaultRenderer()); - console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); - } - Physics.reset(); this.updateResolutionScaler(); @@ -108,8 +90,6 @@ module es { } this._sceneComponents.length = 0; - this.camera = null; - if (this.entityProcessors) this.entityProcessors.end(); diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 4bb007e9..740ec29f 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -250,12 +250,5 @@ module es { for (let i = 0; i < this._components.length; i++) this._components.buffer[i].onDisabled(); } - - public debugRender(camera: Camera){ - for (let i = 0; i < this._components.length; i ++){ - if (this._components.buffer[i].enabled) - this._components.buffer[i].debugRender(camera); - } - } } } diff --git a/source/src/Graphics/Renderers/DefaultRenderer.ts b/source/src/Graphics/Renderers/DefaultRenderer.ts deleted file mode 100644 index 5a839623..00000000 --- a/source/src/Graphics/Renderers/DefaultRenderer.ts +++ /dev/null @@ -1,19 +0,0 @@ -/// -module es { - export class DefaultRenderer extends Renderer { - constructor() { - super(0, null); - } - - public render(scene: Scene) { - let cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); - - for (let i = 0; i < scene.renderableComponents.count; i++) { - let renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); - } - } - } -} diff --git a/source/src/Graphics/Renderers/IRenderable.ts b/source/src/Graphics/Renderers/IRenderable.ts index 8a42c803..a6f8c733 100644 --- a/source/src/Graphics/Renderers/IRenderable.ts +++ b/source/src/Graphics/Renderers/IRenderable.ts @@ -20,25 +20,6 @@ module es { * 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法 */ isVisible: boolean; - - /** - * 如果renderableComponent的边界与camera.bounds相交 返回true - * 用于处理isVisible标志的状态开关 - * 在渲染方法中使用这个方法来决定是否渲染 - * @param camera - */ - isVisibleFromCamera(camera: Camera); - - /** - * 由渲染器调用。可以使用摄像机进行剔除 - * @param camera - */ - render(camera: Camera); - - /** - * 只有在没有碰撞器时才呈现边界。总是在原点上渲染一个正方形。 - */ - debugRender(camera: Camera); } /** diff --git a/source/src/Graphics/Renderers/Renderer.ts b/source/src/Graphics/Renderers/Renderer.ts index 3b29536f..f54628c6 100644 --- a/source/src/Graphics/Renderers/Renderer.ts +++ b/source/src/Graphics/Renderers/Renderer.ts @@ -3,12 +3,6 @@ module es { * 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用 */ export abstract class Renderer { - /** - * 渲染器用于渲染的摄像机(实际上是用于剔除的变换矩阵和边界) - * 不是必须的 - * Renderer子类可以选择调用beginRender时使用的摄像头 - */ - public camera: Camera; /** * 指定场景调用渲染器的顺序 */ @@ -20,8 +14,7 @@ module es { */ public shouldDebugRender: boolean = true; - protected constructor(renderOrder: number, camera: Camera = null) { - this.camera = camera; + protected constructor(renderOrder: number) { this.renderOrder = renderOrder; } @@ -52,34 +45,5 @@ module es { public compareTo(other: Renderer): number { return this.renderOrder - other.renderOrder; } - - /** - * - * @param cam - */ - protected beginRender(cam: Camera) { - } - - /** - * - * @param renderable - * @param cam - */ - protected renderAfterStateCheck(renderable: IRenderable, cam: Camera) { - renderable.render(cam); - } - - /** - * 默认debugRender方法只循环遍历所有实体并调用entity.debugRender - * @param scene - * @param cam - */ - protected debugRender(scene: Scene, cam: Camera){ - for (let i = 0; i < scene.entities.count; i ++){ - let entity = scene.entities.buffer[i]; - if (entity.enabled) - entity.debugRender(cam); - } - } } }