From 74fe021641eb681acb1c89531653e95c7a236593 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Mon, 21 Jan 2019 21:26:51 +0800 Subject: [PATCH] misc fix --- cocos/3d/assets/mesh.ts | 10 ++--- cocos/3d/framework/animation-component.js | 10 +++-- .../framework/physics/collider-component.ts | 40 ++++++++++--------- .../framework/physics/rigid-body-component.ts | 34 ++++++++-------- cocos/3d/framework/renderable-component.ts | 5 ++- cocos/assets/CCScripts.js | 2 +- cocos/components/component.js | 3 +- cocos/core/platform/CCSys.js | 11 +++-- cocos/load-pipeline/audio-downloader.js | 4 +- playground/gizmo.html | 8 ++-- 10 files changed, 70 insertions(+), 57 deletions(-) diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 553632a416..a6135dc2d5 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -374,7 +374,10 @@ export class Mesh extends Asset { } @property - private _struct: IMeshStruct; + private _struct: IMeshStruct = { + vertexBundles: [], + primitives: [], + }; private _data: Uint8Array | null = null; @@ -384,11 +387,6 @@ export class Mesh extends Asset { constructor () { super(); - - this._struct = { - vertexBundles: [], - primitives: [], - }; } /** diff --git a/cocos/3d/framework/animation-component.js b/cocos/3d/framework/animation-component.js index 84ab6a847b..e14eefd7e3 100644 --- a/cocos/3d/framework/animation-component.js +++ b/cocos/3d/framework/animation-component.js @@ -308,7 +308,7 @@ export default class AnimationComponent extends Component { /** * @type {AnimationClip[]} */ - @property + @property({ type: [AnimationClip] }) _clips = []; /** @@ -318,7 +318,7 @@ export default class AnimationComponent extends Component { * @property currentClip * @type {AnimationClip} */ - @property({type:AnimationClip}) + @property({ type:AnimationClip }) currentClip = null; /** @@ -333,7 +333,7 @@ export default class AnimationComponent extends Component { _preview = false; - @property({type: Boolean}) + @property({ type: Boolean }) get preview() { return this._preview; } @@ -383,7 +383,9 @@ export default class AnimationComponent extends Component { * @property clips * @type {AnimationClip[]} */ - @property([AnimationClip]) + @property({ + type: [AnimationClip], + }) get clips() { return this._clips; } diff --git a/cocos/3d/framework/physics/collider-component.ts b/cocos/3d/framework/physics/collider-component.ts index 132ecd0508..25762d8f0e 100644 --- a/cocos/3d/framework/physics/collider-component.ts +++ b/cocos/3d/framework/physics/collider-component.ts @@ -4,7 +4,7 @@ import { executeInEditMode, executionOrder, menu, - property + property, } from '../../../core/data/class-decorator'; import Vec3 from '../../../core/value-types/vec3'; import { PhysicsBoxShape, PhysicsShape, PhysicsSphereShape } from './body'; @@ -17,37 +17,39 @@ export class ColliderComponentBase extends PhysicsBasedComponent { @property private _center: Vec3 = new cc.Vec3(0, 0, 0); - constructor(shape: PhysicsShape) { + constructor (shape: PhysicsShape) { super(); this._center = new Vec3(0, 0, 0); this._shape = shape; } - public get body() { + public get body () { return this._body; } - public onLoad() { + public onLoad () { super.onLoad(); this.center = this._center; } - public onEnable() { + public onEnable () { super.onEnable(); this._body!.addShape(this._shape); } - public onDisable() { + public onDisable () { super.onDisable(); this._body!.removeShape(this._shape); } - @property(Vec3) - get center() { + @property({ + type: Vec3, + }) + get center () { return this._center; } - set center(value: Vec3) { + set center (value: Vec3) { this._center = new Vec3(value.x, value.y, value.z); this._shape.center = value; } @@ -61,24 +63,26 @@ export class BoxColliderComponent extends ColliderComponentBase { @property private _size: Vec3 = new Vec3(0, 0, 0); - constructor() { + constructor () { super(new PhysicsBoxShape(new Vec3(0, 0, 0))); } - public onLoad() { + public onLoad () { super.onLoad(); this.size = this._size; } - @property(Vec3) - get size() { + @property({ + type: Vec3, + }) + get size () { return this._size; } /** * Note, shall not specify size with component 0 */ - set size(value) { + set size (value) { this._size = value; (this._shape as PhysicsBoxShape).size = this._size; if (this._body) { @@ -95,21 +99,21 @@ export class SphereColliderComponent extends ColliderComponentBase { @property private _radius: number = 0; - constructor() { + constructor () { super(new PhysicsSphereShape(0)); } - public onLoad() { + public onLoad () { super.onLoad(); this.radius = this._radius; } @property - get radius() { + get radius () { return this._radius; } - set radius(value) { + set radius (value) { this._radius = value; (this._shape as PhysicsSphereShape).radius = value; if (this._body) { diff --git a/cocos/3d/framework/physics/rigid-body-component.ts b/cocos/3d/framework/physics/rigid-body-component.ts index 37309ba6aa..5ca06ed783 100644 --- a/cocos/3d/framework/physics/rigid-body-component.ts +++ b/cocos/3d/framework/physics/rigid-body-component.ts @@ -4,7 +4,7 @@ import { executeInEditMode, executionOrder, menu, - property + property, } from '../../../core/data/class-decorator'; import { PhysicsMaterial } from '../../assets/physics/material'; import { PhysicsBasedComponent } from './detail/physics-based-component'; @@ -26,38 +26,40 @@ export class RigidBodyComponent extends PhysicsBasedComponent { @property private _angularDamping: number = NonRigidBodyProperties.angularDamping; - constructor() { + constructor () { super(); } - public get body() { + public get body () { return this._body; } - public onLoad() { + public onLoad () { super.onLoad(); } - public onEnable() { + public onEnable () { super.onEnable(); this.mass = this._mass; this.linearDamping = this._linearDamping; this.angularDamping = this._angularDamping; } - public onDisable() { + public onDisable () { super.onDisable(); this.mass = NonRigidBodyProperties.mass; this.linearDamping = NonRigidBodyProperties.linearDamping; this.angularDamping = NonRigidBodyProperties.angularDamping; } - @property(PhysicsMaterial) - get material() { + @property({ + type: PhysicsMaterial, + }) + get material () { return this._material; } - set material(value) { + set material (value) { this._material = value; if (this._body) { this._body.material = this._material; @@ -65,11 +67,11 @@ export class RigidBodyComponent extends PhysicsBasedComponent { } @property - get mass() { + get mass () { return this._mass; } - set mass(value) { + set mass (value) { this._mass = value; if (this._body) { this._body.mass = value; @@ -77,11 +79,11 @@ export class RigidBodyComponent extends PhysicsBasedComponent { } @property - get linearDamping() { + get linearDamping () { return this._linearDamping; } - set linearDamping(value) { + set linearDamping (value) { this._linearDamping = value; if (this._body) { this._body.linearDamping = value; @@ -89,18 +91,18 @@ export class RigidBodyComponent extends PhysicsBasedComponent { } @property - get angularDamping() { + get angularDamping () { return this._angularDamping; } - set angularDamping(value) { + set angularDamping (value) { this._angularDamping = value; if (this._body) { this._body.angularDamping = value; } } - public pullTransform() { + public pullTransform () { if (this._body) { this._body.pullTransform(); } diff --git a/cocos/3d/framework/renderable-component.ts b/cocos/3d/framework/renderable-component.ts index 3a66658077..1190682be9 100644 --- a/cocos/3d/framework/renderable-component.ts +++ b/cocos/3d/framework/renderable-component.ts @@ -6,7 +6,9 @@ const { ccclass, property } = _decorator; @ccclass('cc.RenderableComponent') export class RenderableComponent extends Component { - @property([Material]) + @property({ + type: [Material], + }) private _materials: Array = []; constructor () { @@ -16,6 +18,7 @@ export class RenderableComponent extends Component { @property({ type: [Material], displayName: 'Materials', + default: [], }) get sharedMaterials () { return this._materials; diff --git a/cocos/assets/CCScripts.js b/cocos/assets/CCScripts.js index 2595134a2b..9a1bf850db 100644 --- a/cocos/assets/CCScripts.js +++ b/cocos/assets/CCScripts.js @@ -36,7 +36,7 @@ import {ccclass} from '../core/data/class-decorator'; * @private */ @ccclass('cc.Script') -class Script extends Asset { +export class Script extends Asset { } cc._Script = Script; diff --git a/cocos/components/component.js b/cocos/components/component.js index a4cbd179ee..027555d5b1 100644 --- a/cocos/components/component.js +++ b/cocos/components/component.js @@ -28,6 +28,7 @@ import { CCObject } from '../core/data/object'; import {getClassName, value} from '../core/utils/js'; import IDGenerator from '../core/utils/id-generator'; import {ccclass, property} from '../core/data/class-decorator'; +import {Script} from '../assets'; let idGenerator = new IDGenerator('Comp'); const IsOnEnableCalled = CCObject.Flags.IsOnEnableCalled; @@ -102,7 +103,7 @@ class Component extends CCObject { @property({ displayName: 'Script', - type: cc._Script, + type: Script, tooltip: CC_DEV && 'i18n:INSPECTOR.component.script' }) get __scriptAsset () { return null; } diff --git a/cocos/core/platform/CCSys.js b/cocos/core/platform/CCSys.js index 6fa19dfa61..93e9339a54 100644 --- a/cocos/core/platform/CCSys.js +++ b/cocos/core/platform/CCSys.js @@ -1022,10 +1022,13 @@ else { try { if (__audioSupport.WEB_AUDIO) { - __audioSupport.context = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)(); - if(__audioSupport.DELAY_CREATE_CTX) { - setTimeout(function(){ __audioSupport.context = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)(); }, 0); - } + __audioSupport._context = null; + Object.defineProperty(__audioSupport, 'context', { + get () { + if (this._context) return this._context; + return this._context = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)(); + } + }); } } catch(error) { __audioSupport.WEB_AUDIO = false; diff --git a/cocos/load-pipeline/audio-downloader.js b/cocos/load-pipeline/audio-downloader.js index 2852de7e41..a34643c3b2 100644 --- a/cocos/load-pipeline/audio-downloader.js +++ b/cocos/load-pipeline/audio-downloader.js @@ -29,7 +29,6 @@ import debug from '../core/platform/CCDebug'; var __audioSupport = sys.__audioSupport; var formatSupport = __audioSupport.format; -var context = __audioSupport.context; function loadDomAudio (item, callback) { var dom = document.createElement('audio'); @@ -70,6 +69,7 @@ function loadDomAudio (item, callback) { } function loadWebAudio (item, callback) { + const context = __audioSupport.context; if (!context) callback(new Error(debug.getError(4926))); @@ -115,4 +115,4 @@ export default function downloadAudio (item, callback) { } } loader(item, callback); -} \ No newline at end of file +} diff --git a/playground/gizmo.html b/playground/gizmo.html index 35cd8a4dca..399c4d44be 100644 --- a/playground/gizmo.html +++ b/playground/gizmo.html @@ -82,7 +82,7 @@ bodyModel.material.setProperty('color', color); bodyModel.material.overridePipelineStates({ primitive: cc.GFXPrimitiveMode.LINE_LIST }); return arrow; - } + }; const createBorderPlane = (color, position, rotation) => { const borderPlane = new cc.Node('borderPlane'); borderPlane.setPosition(position); @@ -112,7 +112,7 @@ borderModel.material.setProperty('color', color); borderModel.material.overridePipelineStates({ primitive: cc.GFXPrimitiveMode.LINE_LIST }); return borderPlane; - } + }; const moveTool = new cc.Node('moveTool'); moveTool.parent = scene; @@ -125,7 +125,7 @@ let vel = cc.v3(), speed = 0.1; canv.addEventListener('keydown', (e) => { - if (e.key === 'i') vel.z = speed; + if (e.key === 'i') vel.z = speed; else if (e.key === 'k') vel.z = -speed; else if (e.key === 'j') vel.x = speed; else if (e.key === 'l') vel.x = -speed; @@ -133,7 +133,7 @@ else if (e.key === 'u') vel.y = -speed; }); canv.addEventListener('keyup', (e) => { - if (e.key === 'i') vel.z = 0; + if (e.key === 'i') vel.z = 0; else if (e.key === 'k') vel.z = 0; else if (e.key === 'j') vel.x = 0; else if (e.key === 'l') vel.x = 0;