mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge branch '3d' of https://github.com/cocos-creator/engine into 3d
This commit is contained in:
@@ -255,9 +255,9 @@ export class AnimationSampler {
|
||||
propertyAnimation.values[index * 3 + 1],
|
||||
propertyAnimation.values[index * 3 + 2]);
|
||||
const getRotationAt = (index: number, out: Quat) => quat.set(out,
|
||||
propertyAnimation.values[index * 4 + 0],
|
||||
propertyAnimation.values[index * 4 + 1],
|
||||
propertyAnimation.values[index * 4 + 2],
|
||||
propertyAnimation.values[index * 4 + 0],
|
||||
propertyAnimation.values[index * 4 + 1],
|
||||
propertyAnimation.values[index * 4 + 2],
|
||||
propertyAnimation.values[index * 4 + 3]);
|
||||
const getScaleAt = getPositionAt;
|
||||
const keys = clip.keysList[propertyAnimation.indexOfKeys];
|
||||
@@ -296,7 +296,6 @@ export class AnimationSampler {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,12 +320,7 @@ export default class ParticleSystemRenderer extends RenderableComponent {
|
||||
} else {
|
||||
console.warn(`particle system renderMode ${this._renderMode} not support.`);
|
||||
}
|
||||
const ea = mat!.effectAsset;
|
||||
mat!.destroy();
|
||||
mat!.initialize({
|
||||
defines: this._defines,
|
||||
effectAsset: ea,
|
||||
});
|
||||
for (const pass of mat!.passes) { pass.tryCompile(this._defines); }
|
||||
|
||||
if (this.particleSystem.textureAnimationModule.enable) {
|
||||
mat!.setProperty('frameTile_velLenScale', vec2.set(this.frameTile_velLenScale, this.particleSystem.textureAnimationModule.numTilesX, this.particleSystem.textureAnimationModule.numTilesY));
|
||||
|
||||
@@ -25,15 +25,17 @@
|
||||
|
||||
// @ts-check
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
|
||||
import { Mat4 } from '../../core/value-types';
|
||||
import { mat4 } from '../../core/vmath';
|
||||
import { GFXDevice, GFXFeature } from '../../gfx/device';
|
||||
import { __FORCE_USE_UNIFORM_STORAGE__, SkinningModel, useJointsTexture } from '../../renderer/models/skinning-model';
|
||||
import { GFXDevice } from '../../gfx/device';
|
||||
import { SkinningModel, useJointsTexture } from '../../renderer/models/skinning-model';
|
||||
import { Node } from '../../scene-graph/node';
|
||||
import { Material } from '../assets/material';
|
||||
import Skeleton from '../assets/skeleton';
|
||||
import { ModelComponent } from './model-component';
|
||||
|
||||
const _m4_tmp = mat4.create();
|
||||
const _m4_tmp = new Mat4();
|
||||
const _m4_tmp2 = new Mat4();
|
||||
|
||||
type SkinningTarget = Map<string, Node>;
|
||||
|
||||
@@ -110,7 +112,7 @@ export class SkinningModelComponent extends ModelComponent {
|
||||
const skeleton = this._skeleton;
|
||||
const skinningTarget = this._skinningTarget;
|
||||
|
||||
const cancelThisNodeTransform = this.node.getWorldMatrix();
|
||||
const cancelThisNodeTransform = this.node.getWorldMatrix(_m4_tmp2);
|
||||
mat4.invert(cancelThisNodeTransform, cancelThisNodeTransform);
|
||||
this._skeleton.joints.forEach((joint, index) => {
|
||||
// If target joint doesn't exists in scene graph, skip it.
|
||||
@@ -123,7 +125,7 @@ export class SkinningModelComponent extends ModelComponent {
|
||||
// 3. because it has been in world space, just cancel this mesh's original local-world transform
|
||||
const bindpose = skeleton.bindposes[index];
|
||||
const jointMatrix = _m4_tmp;
|
||||
mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix());
|
||||
mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix(_m4_tmp));
|
||||
mat4.multiply(jointMatrix, jointMatrix, bindpose);
|
||||
skinningModel.updateJointMatrix(index, jointMatrix);
|
||||
});
|
||||
@@ -142,14 +144,12 @@ export class SkinningModelComponent extends ModelComponent {
|
||||
}
|
||||
|
||||
protected _onMaterialModified (index: number, material: Material) {
|
||||
super._onMaterialModified(index, material);
|
||||
|
||||
const device = _getGlobalDevice();
|
||||
const useJointTexture = device !== null && useJointsTexture(device);
|
||||
const mat = this.getMaterial(index, CC_EDITOR)!;
|
||||
const effectAsset = mat.effectAsset;
|
||||
mat.destroy();
|
||||
mat.initialize({ effectAsset, defines: { CC_USE_SKINNING: true, CC_USE_JOINTS_TEXTURE: useJointTexture } });
|
||||
const defines = { CC_USE_SKINNING: true, CC_USE_JOINTS_TEXTURE: useJointTexture };
|
||||
for (const pass of mat.passes) { pass.tryCompile(defines); }
|
||||
super._onMaterialModified(index, mat);
|
||||
}
|
||||
|
||||
private _bindSkeleton () {
|
||||
|
||||
@@ -10,11 +10,11 @@ import {
|
||||
ILockConstraintOptions,
|
||||
IPointToPointConstraintOptions,
|
||||
IRaycastOptions, LockConstraintBase, PhysicsWorldBase,
|
||||
PointToPointConstraintBase, RigidBodyBase, ShapeBase, SphereShapeBase
|
||||
PointToPointConstraintBase, RigidBodyBase, ShapeBase, SphereShapeBase,
|
||||
} from './api';
|
||||
import { ERigidBodyType } from './instance';
|
||||
import { RaycastResult } from './raycast-result';
|
||||
import { stringfyQuat, stringfyVec3 } from './util';
|
||||
import { ERigidBodyType } from './instance';
|
||||
|
||||
const defaultCannonMaterial = new CANNON.Material('');
|
||||
const defaultCannonContactMaterial = new CANNON.ContactMaterial(
|
||||
|
||||
@@ -188,8 +188,6 @@ export class CanvasComponent extends Component {
|
||||
this._camera!.resize(device.width, device.height);
|
||||
}
|
||||
|
||||
cc.director.root.ui.addScreen(this);
|
||||
|
||||
// if (CC_DEV) {
|
||||
// var Flags = cc.Object.Flags;
|
||||
// this._objFlags |= (Flags.IsPositionLocked | Flags.IsAnchorLocked | Flags.IsSizeLocked);
|
||||
@@ -219,14 +217,19 @@ export class CanvasComponent extends Component {
|
||||
this.alignWithScreen();
|
||||
}
|
||||
|
||||
public onEnable (){
|
||||
cc.director.root.ui.addScreen(this);
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
if (this._camera) {
|
||||
this._getRenderScene().destroyCamera(this._camera);
|
||||
}
|
||||
cc.director.root.ui.removeScreen(this);
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
if (this._camera) {
|
||||
this._getRenderScene().destroyCamera(this._camera);
|
||||
}
|
||||
|
||||
if (CC_EDITOR) {
|
||||
cc.director.off(cc.Director.EVENT_AFTER_UPDATE, this.alignWithScreen, this);
|
||||
// cc.engine.off('design-resolution-changed', this._thisOnResized);
|
||||
@@ -238,6 +241,7 @@ export class CanvasComponent extends Component {
|
||||
// cc.view.off('design-resolution-changed', this._thisOnResized);
|
||||
// }
|
||||
// }
|
||||
|
||||
cc.view.off('design-resolution-changed', this._thisOnResized);
|
||||
|
||||
if (CanvasComponent.instance === this) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LegacyAnimationComponent } from '../components/lagacy-animation-component';
|
||||
import { LegacyAnimationComponent } from '../components/legacy-animation-component';
|
||||
import { binarySearchEpsilon as binarySearch } from '../core/data/utils/binary-search';
|
||||
import { MutableForwardIterator } from '../core/utils/array';
|
||||
import { Node } from '../scene-graph';
|
||||
|
||||
@@ -54,7 +54,7 @@ export class LegacyAnimationState extends Playable {
|
||||
* @default: WrapMode.Normal
|
||||
*/
|
||||
get wrapMode () {
|
||||
return this.wrapMode;
|
||||
return this._wrapMode;
|
||||
}
|
||||
|
||||
set wrapMode (value: WrapMode) {
|
||||
|
||||
@@ -119,7 +119,7 @@ export class SpriteAtlas extends Asset {
|
||||
const frames = data.spriteFrames;
|
||||
this.spriteFrames = js.createMap();
|
||||
for (let i = 0; i < frames.length; i += 2) {
|
||||
handle.result.push(this.spriteFrames, frames[i], frames[i + 1]);
|
||||
handle.result.push(this.spriteFrames, i, frames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,3 +27,4 @@
|
||||
export { Component } from './component';
|
||||
export { EventHandler } from './component-event-handler';
|
||||
export {default as MissingScript} from './missing-script';
|
||||
export { LegacyAnimationComponent } from './legacy-animation-component';
|
||||
+24
@@ -73,6 +73,22 @@ ccenum(EventType);
|
||||
@menu('Components/AnimationComponent')
|
||||
export class LegacyAnimationComponent extends EventTargetFactory(Component) {
|
||||
|
||||
@property({ type: Boolean })
|
||||
get preview () {
|
||||
return this._preview;
|
||||
}
|
||||
|
||||
set preview (value) {
|
||||
this._preview = value;
|
||||
if (value) {
|
||||
cc.engine.animatingInEditMode = true;
|
||||
this.play();
|
||||
} else {
|
||||
cc.engine.animatingInEditMode = false;
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en Animation will play the default clip when start game.
|
||||
* !#zh 在勾选自动播放或调用 play() 时默认播放的动画剪辑。
|
||||
@@ -115,6 +131,11 @@ export class LegacyAnimationComponent extends EventTargetFactory(Component) {
|
||||
set currentClip (value) {
|
||||
this._currentClip = value;
|
||||
}
|
||||
|
||||
@property({ type: [LegacyAnimationClip] })
|
||||
get clips () {
|
||||
return this._clips;
|
||||
}
|
||||
public static EventType = EventType;
|
||||
|
||||
/**
|
||||
@@ -123,6 +144,7 @@ export class LegacyAnimationComponent extends EventTargetFactory(Component) {
|
||||
*/
|
||||
@property
|
||||
public playOnLoad = false;
|
||||
private _preview = false;
|
||||
|
||||
private _animator: AnimationAnimator | null = null;
|
||||
private _nameToState = createMap(true);
|
||||
@@ -584,6 +606,8 @@ export class LegacyAnimationComponent extends EventTargetFactory(Component) {
|
||||
}
|
||||
}
|
||||
|
||||
cc.LegacyAnimationComponent = LegacyAnimationComponent;
|
||||
|
||||
function equalClips (clip1: LegacyAnimationClip | null, clip2: LegacyAnimationClip | null) {
|
||||
if (clip1 === clip2) {
|
||||
return true;
|
||||
@@ -196,6 +196,15 @@ class Director extends EventTarget {
|
||||
eventManager.setEnabled(true);
|
||||
}
|
||||
|
||||
// Animation manager
|
||||
if (cc.AnimationManager) {
|
||||
this._animationManager = new cc.AnimationManager();
|
||||
this._scheduler.scheduleUpdate(this._animationManager, Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
else {
|
||||
this._animationManager = null;
|
||||
}
|
||||
|
||||
// widgetManager
|
||||
widgetManager.init(this);
|
||||
|
||||
@@ -385,6 +394,11 @@ class Director extends EventTarget {
|
||||
if (eventManager)
|
||||
eventManager.setEnabled(true);
|
||||
|
||||
// Animation manager
|
||||
if (this._animationManager) {
|
||||
this._scheduler.scheduleUpdate(this._animationManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
|
||||
this._systems.forEach((sys) => {
|
||||
this._scheduler.scheduleUpdate(sys, sys._priority, false);
|
||||
});
|
||||
@@ -882,6 +896,15 @@ class Director extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en Returns the cc.AnimationManager associated with this director.
|
||||
* !#zh 获取和 director 相关联的 cc.AnimationManager(动画管理器)。
|
||||
* @method getAnimationManager
|
||||
*/
|
||||
getAnimationManager () {
|
||||
return this._animationManager;
|
||||
}
|
||||
|
||||
// Loop management
|
||||
/*
|
||||
* Starts Animation
|
||||
|
||||
@@ -23,33 +23,32 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// ID generator for runtime
|
||||
|
||||
let NonUuidMark = '.';
|
||||
const NonUuidMark = '.';
|
||||
|
||||
/**
|
||||
* ID generator for runtime.
|
||||
*/
|
||||
export default class IDGenerator {
|
||||
/*
|
||||
* @method constructor
|
||||
* @param {string} [category] - You can specify a unique category to avoid id collision with other instance of IdGenerator
|
||||
* The global id generator might have a conflict problem once every 365 days,
|
||||
* if the game runs at 60 FPS and each frame 4760273 counts of new id are requested.
|
||||
*/
|
||||
public static global = new IDGenerator('global');
|
||||
|
||||
public id: number;
|
||||
|
||||
public prefix: string;
|
||||
|
||||
/**
|
||||
* @param [category] You can specify a unique category to avoid id collision with other instance of IdGenerator.
|
||||
*/
|
||||
constructor (category) {
|
||||
// init with a random id to emphasize that the returns id should not be stored in persistence data
|
||||
constructor (category?: string) {
|
||||
// Tnit with a random id to emphasize that the returns id should not be stored in persistence data.
|
||||
this.id = 0 | (Math.random() * 998);
|
||||
|
||||
this.prefix = category ? (category + NonUuidMark) : '';
|
||||
}
|
||||
|
||||
/*
|
||||
* @method getNewId
|
||||
* @return {string}
|
||||
*/
|
||||
getNewId () {
|
||||
public getNewId () {
|
||||
return this.prefix + (++this.id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The global id generator might have a conflict problem once every 365 days,
|
||||
* if the game runs at 60 FPS and each frame 4760273 counts of new id are requested.
|
||||
*/
|
||||
IDGenerator.global = new IDGenerator('global');
|
||||
@@ -1,3 +1,118 @@
|
||||
import { warnID } from '../platform/CCDebug';
|
||||
|
||||
const tempCIDGenerator = new IDGenerator('TmpCId.');
|
||||
import IDGenerator from './id-generator';
|
||||
|
||||
type Getter = () => any;
|
||||
|
||||
type Setter = (value: any) => void;
|
||||
|
||||
/**
|
||||
* Check the object whether is number or not
|
||||
* If a number is created by using 'new Number(10086)', the typeof it will be "object"...
|
||||
* Then you can use this function if you care about this case.
|
||||
*/
|
||||
export function isNumber (object: any) {
|
||||
return typeof object === 'number' || object instanceof Number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the object whether is string or not.
|
||||
* If a string is created by using 'new String("blabla")', the typeof it will be "object"...
|
||||
* Then you can use this function if you care about this case.
|
||||
*/
|
||||
export function isString (object: any) {
|
||||
return typeof object === 'string' || object instanceof String;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define value, just help to call Object.defineProperty.<br>
|
||||
* The configurable will be true.
|
||||
* @param [writable=false]
|
||||
* @param [enumerable=false]
|
||||
*/
|
||||
export const value = (() => {
|
||||
const descriptor: PropertyDescriptor = {
|
||||
value: undefined,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: true,
|
||||
};
|
||||
return (object: Object, propertyName: string, value_: any, writable?: boolean, enumerable?: boolean) => {
|
||||
descriptor.value = value_;
|
||||
descriptor.writable = writable;
|
||||
descriptor.enumerable = enumerable;
|
||||
Object.defineProperty(object, propertyName, descriptor);
|
||||
descriptor.value = undefined;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Define get set accessor, just help to call Object.defineProperty(...).
|
||||
* @param [setter=null]
|
||||
* @param [enumerable=false]
|
||||
* @param [configurable=false]
|
||||
*/
|
||||
export const getset = (() => {
|
||||
const descriptor: PropertyDescriptor = {
|
||||
get: undefined,
|
||||
set: undefined,
|
||||
enumerable: false,
|
||||
};
|
||||
return (object: Object, propertyName: string, getter: Getter, setter?: Setter, enumerable?: boolean, configurable?: boolean) => {
|
||||
if (typeof setter !== 'function') {
|
||||
enumerable = setter;
|
||||
setter = undefined;
|
||||
}
|
||||
descriptor.get = getter;
|
||||
descriptor.set = setter;
|
||||
descriptor.enumerable = enumerable;
|
||||
descriptor.configurable = configurable;
|
||||
Object.defineProperty(object, propertyName, descriptor);
|
||||
descriptor.get = undefined;
|
||||
descriptor.set = undefined;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Define get accessor, just help to call Object.defineProperty(...).
|
||||
* @param [enumerable=false]
|
||||
* @param [configurable=false]
|
||||
*/
|
||||
export const get = (() => {
|
||||
const descriptor: PropertyDescriptor = {
|
||||
get: undefined,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
};
|
||||
return (object: Object, propertyName: string, getter: Getter, enumerable?: boolean, configurable?: boolean) => {
|
||||
descriptor.get = getter;
|
||||
descriptor.enumerable = enumerable;
|
||||
descriptor.configurable = configurable;
|
||||
Object.defineProperty(object, propertyName, descriptor);
|
||||
descriptor.get = undefined;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Define set accessor, just help to call Object.defineProperty(...).
|
||||
* @param [enumerable=false]
|
||||
* @param [configurable=false]
|
||||
*/
|
||||
export const set = (() => {
|
||||
const descriptor: PropertyDescriptor = {
|
||||
set: undefined,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
};
|
||||
return (object: Object, propertyName: string, setter: Setter, enumerable?: boolean, configurable?: boolean) => {
|
||||
descriptor.set = setter;
|
||||
descriptor.enumerable = enumerable;
|
||||
descriptor.configurable = configurable;
|
||||
Object.defineProperty(object, propertyName, descriptor);
|
||||
descriptor.set = undefined;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* !#en
|
||||
@@ -26,3 +141,449 @@ export function createMap (forceDictMode?: boolean) {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class name of the object, if object is just a {} (and which class named 'Object'), it will return "".
|
||||
* (modified from <a href="http://stackoverflow.com/questions/1249531/how-to-get-a-javascript-objects-class">the code from this stackoverflow post</a>)
|
||||
* @param objOrCtor instance or constructor
|
||||
*/
|
||||
export function getClassName (objOrCtor: Object | Function): string {
|
||||
if (typeof objOrCtor === 'function') {
|
||||
const prototype = objOrCtor.prototype;
|
||||
if (prototype && prototype.hasOwnProperty('__classname__') && prototype.__classname__) {
|
||||
return prototype.__classname__;
|
||||
}
|
||||
let retval = '';
|
||||
// for browsers which have name property in the constructor of the object, such as chrome
|
||||
if (objOrCtor.name) {
|
||||
retval = objOrCtor.name;
|
||||
}
|
||||
if (objOrCtor.toString) {
|
||||
let arr;
|
||||
const str = objOrCtor.toString();
|
||||
if (str.charAt(0) === '[') {
|
||||
// str is "[object objectClass]"
|
||||
arr = str.match(/\[\w+\s*(\w+)\]/);
|
||||
}
|
||||
else {
|
||||
// str is function objectClass () {} for IE Firefox
|
||||
arr = str.match(/function\s*(\w+)/);
|
||||
}
|
||||
if (arr && arr.length === 2) {
|
||||
retval = arr[1];
|
||||
}
|
||||
}
|
||||
return retval !== 'Object' ? retval : '';
|
||||
} else if (objOrCtor && objOrCtor.constructor) {
|
||||
return getClassName(objOrCtor.constructor);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a polyfill field for obsoleted codes.
|
||||
* @param object - YourObject or YourClass.prototype
|
||||
* @param obsoleted - "OldParam" or "YourClass.OldParam"
|
||||
* @param newExpr - "NewParam" or "YourClass.NewParam"
|
||||
* @param [writable=false]
|
||||
*/
|
||||
export function obsolete (object: any, obsoleted: string, newExpr: string, writable?: boolean) {
|
||||
const extractPropName = /([^.]+)$/;
|
||||
const oldProp = extractPropName.exec(obsoleted)[0];
|
||||
const newProp = extractPropName.exec(newExpr)[0];
|
||||
function getter (this: any) {
|
||||
if (CC_DEV) {
|
||||
warnID(5400, obsoleted, newExpr);
|
||||
}
|
||||
return this[newProp];
|
||||
}
|
||||
function setter (this: any, value_: any) {
|
||||
if (CC_DEV) {
|
||||
warnID(5401, obsoleted, newExpr);
|
||||
}
|
||||
this[newProp] = value_;
|
||||
}
|
||||
|
||||
if (writable) {
|
||||
getset(object, oldProp, getter, setter);
|
||||
}
|
||||
else {
|
||||
get(object, oldProp, getter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines all polyfill fields for obsoleted codes corresponding to the enumerable properties of props.
|
||||
* @method obsoletes
|
||||
* @param {any} obj - YourObject or YourClass.prototype
|
||||
* @param {any} objName - "YourObject" or "YourClass"
|
||||
* @param {Object} props
|
||||
* @param {Boolean} [writable=false]
|
||||
*/
|
||||
export function obsoletes (obj, objName, props, writable) {
|
||||
for (const obsoleted in props) {
|
||||
const newName = props[obsoleted];
|
||||
obsolete(obj, objName + '.' + obsoleted, newName, writable);
|
||||
}
|
||||
}
|
||||
|
||||
const REGEXP_NUM_OR_STR = /(%d)|(%s)/;
|
||||
const REGEXP_STR = /%s/;
|
||||
|
||||
/**
|
||||
* A string tool to construct a string with format string.
|
||||
* @param msg - A JavaScript string containing zero or more substitution strings (%s).
|
||||
* @param subst - JavaScript objects with which to replace substitution strings within msg.
|
||||
* This gives you additional control over the format of the output.
|
||||
* @example
|
||||
* cc.js.formatStr("a: %s, b: %s", a, b);
|
||||
* cc.js.formatStr(a, b, c);
|
||||
*/
|
||||
export function formatStr (msg: string | any, ...subst: any[]) {
|
||||
if (arguments.length === 0) {
|
||||
return '';
|
||||
}
|
||||
if (subst.length === 0) {
|
||||
return '' + msg;
|
||||
}
|
||||
|
||||
const hasSubstitution = typeof msg === 'string' && REGEXP_NUM_OR_STR.test(msg);
|
||||
if (hasSubstitution) {
|
||||
for (const arg of subst) {
|
||||
const regExpToTest = typeof arg === 'number' ? REGEXP_NUM_OR_STR : REGEXP_STR;
|
||||
if (regExpToTest.test(msg)) {
|
||||
msg = msg.replace(regExpToTest, arg);
|
||||
}
|
||||
else {
|
||||
msg += ' ' + arg;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const arg of subst) {
|
||||
msg += ' ' + arg;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
// see https://github.com/petkaantonov/bluebird/issues/1389
|
||||
export function shiftArguments () {
|
||||
const len = arguments.length - 1;
|
||||
const args = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
args[i] = arguments[i + 1];
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property descriptor in object and all its ancestors.
|
||||
*/
|
||||
export function getPropertyDescriptor (object: any, propertyName: string) {
|
||||
while (object) {
|
||||
const pd = Object.getOwnPropertyDescriptor(object, propertyName);
|
||||
if (pd) {
|
||||
return pd;
|
||||
}
|
||||
object = Object.getPrototypeOf(object);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function _copyprop (name: string, source: any, target: any) {
|
||||
const pd = getPropertyDescriptor(source, name);
|
||||
if (pd) {
|
||||
Object.defineProperty(target, name, pd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all properties not defined in object from arguments[1...n].
|
||||
* @param object Object to extend its properties.
|
||||
* @param sources Source object to copy properties from.
|
||||
* @return The result object.
|
||||
*/
|
||||
export function addon (object?: any, ...sources: any[]) {
|
||||
object = object || {};
|
||||
for (const source of sources) {
|
||||
if (source) {
|
||||
if (typeof source !== 'object') {
|
||||
cc.errorID(5402, source);
|
||||
continue;
|
||||
}
|
||||
for (const name in source) {
|
||||
if (!(name in object)) {
|
||||
_copyprop(name, source, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all properties from arguments[1...n] to object.
|
||||
* @return The result object.
|
||||
*/
|
||||
export function mixin (object?: any, ...sources: any[]) {
|
||||
object = object || {};
|
||||
for (const source of sources) {
|
||||
if (source) {
|
||||
if (typeof source !== 'object') {
|
||||
cc.errorID(5403, source);
|
||||
continue;
|
||||
}
|
||||
for (const name in source) {
|
||||
_copyprop(name, source, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive the class from the supplied base class.
|
||||
* Both classes are just native javascript constructors, not created by cc.Class, so
|
||||
* usually you will want to inherit using {{#crossLink "cc/Class:method"}}cc.Class {{/crossLink}} instead.
|
||||
* @param base The baseclass to inherit.
|
||||
* @return The result class.
|
||||
*/
|
||||
export function extend (cls: Function, base: Function) {
|
||||
if (CC_DEV) {
|
||||
if (!base) {
|
||||
cc.errorID(5404);
|
||||
return;
|
||||
}
|
||||
if (!cls) {
|
||||
cc.errorID(5405);
|
||||
return;
|
||||
}
|
||||
if (Object.keys(cls.prototype).length > 0) {
|
||||
cc.errorID(5406);
|
||||
}
|
||||
}
|
||||
for (const p in base) { if (base.hasOwnProperty(p)) { cls[p] = base[p]; } }
|
||||
cls.prototype = Object.create(base.prototype, {
|
||||
constructor: {
|
||||
value: cls,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
},
|
||||
});
|
||||
return cls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get super class.
|
||||
* @param constructor The constructor of subclass.
|
||||
*/
|
||||
export function getSuper (constructor: Function) {
|
||||
const proto = constructor.prototype; // binded function do not have prototype
|
||||
const dunderProto = proto && Object.getPrototypeOf(proto);
|
||||
return dunderProto && dunderProto.constructor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether subclass is child of superclass or equals to superclass.
|
||||
*/
|
||||
export function isChildClassOf (subclass: Function, superclass: Function) {
|
||||
if (subclass && superclass) {
|
||||
if (typeof subclass !== 'function') {
|
||||
return false;
|
||||
}
|
||||
if (typeof superclass !== 'function') {
|
||||
if (CC_DEV) {
|
||||
warnID(3625, superclass);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (subclass === superclass) {
|
||||
return true;
|
||||
}
|
||||
for (; ;) {
|
||||
subclass = getSuper(subclass);
|
||||
if (!subclass) {
|
||||
return false;
|
||||
}
|
||||
if (subclass === superclass) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all enumerable properties from object.
|
||||
*/
|
||||
export function clear (object: {}) {
|
||||
for (const key of Object.keys(object)) {
|
||||
delete object[key];
|
||||
}
|
||||
}
|
||||
|
||||
function isTempClassId (id) {
|
||||
return typeof id !== 'string' || id.startsWith(tempCIDGenerator.prefix);
|
||||
}
|
||||
|
||||
// id 注册
|
||||
const _idToClass = {};
|
||||
const _nameToClass = {};
|
||||
|
||||
/**
|
||||
* Register the class by specified id, if its classname is not defined, the class name will also be set.
|
||||
* @method _setClassId
|
||||
* @param {String} classId
|
||||
* @param {Function} constructor
|
||||
* @private
|
||||
*/
|
||||
export function _setClassId (id, constructor) {
|
||||
const key = '__cid__';
|
||||
const table = _idToClass;
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(key)) {
|
||||
delete table[constructor.prototype[key]];
|
||||
}
|
||||
value(constructor.prototype, key, id);
|
||||
// register class
|
||||
if (id) {
|
||||
const registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
let error = 'A Class already exists with the same ' + key + ' : "' + id + '".';
|
||||
if (CC_TEST) {
|
||||
error += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
cc.js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
cc.error(error);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
// if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
function doSetClassName (id, constructor) {
|
||||
const key = '__classname__';
|
||||
const table = _nameToClass;
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(key)) {
|
||||
delete table[constructor.prototype[key]];
|
||||
}
|
||||
value(constructor.prototype, key, id);
|
||||
// register class
|
||||
if (id) {
|
||||
const registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
let error = 'A Class already exists with the same ' + key + ' : "' + id + '".';
|
||||
if (CC_TEST) {
|
||||
error += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
cc.js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
cc.error(error);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
// if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the class by specified name manually
|
||||
* @method setClassName
|
||||
* @param {String} className
|
||||
* @param {Function} constructor
|
||||
*/
|
||||
export function setClassName (className, constructor) {
|
||||
doSetClassName(className, constructor);
|
||||
// auto set class id
|
||||
if (!constructor.prototype.hasOwnProperty('__cid__')) {
|
||||
const id = className || tempCIDGenerator.getNewId();
|
||||
if (id) {
|
||||
_setClassId(id, constructor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a class from fireball.
|
||||
*
|
||||
* If you dont need a registered class anymore, you should unregister the class so that Fireball will not keep its reference anymore.
|
||||
* Please note that its still your responsibility to free other references to the class.
|
||||
*
|
||||
* @method unregisterClass
|
||||
* @param {Function} ...constructor - the class you will want to unregister, any number of classes can be added
|
||||
*/
|
||||
export function unregisterClass (...constructors: Function[]) {
|
||||
for (const constructor of constructors) {
|
||||
const p = constructor.prototype;
|
||||
const classId = p.__cid__;
|
||||
if (classId) {
|
||||
delete _idToClass[classId];
|
||||
}
|
||||
const classname = p.__classname__;
|
||||
if (classname) {
|
||||
delete _nameToClass[classname];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registered class by id
|
||||
* @method _getClassById
|
||||
* @param {String} classId
|
||||
* @return {Function} constructor
|
||||
* @private
|
||||
*/
|
||||
export function _getClassById (classId) {
|
||||
return _idToClass[classId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registered class by name
|
||||
* @method getClassByName
|
||||
* @param {String} classname
|
||||
* @return {Function} constructor
|
||||
*/
|
||||
export function getClassByName (classname) {
|
||||
return _nameToClass[classname];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class id of the object
|
||||
* @method _getClassId
|
||||
* @param {Object|Function} obj - instance or constructor
|
||||
* @param {Boolean} [allowTempId=true] - can return temp id in editor
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
export function _getClassId (obj, allowTempId) {
|
||||
allowTempId = (typeof allowTempId !== 'undefined' ? allowTempId : true);
|
||||
|
||||
let res;
|
||||
if (typeof obj === 'function' && obj.prototype.hasOwnProperty('__cid__')) {
|
||||
res = obj.prototype.__cid__;
|
||||
if (!allowTempId && (CC_DEV || CC_EDITOR) && isTempClassId(res)) {
|
||||
return '';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
if (obj && obj.constructor) {
|
||||
const prototype = obj.constructor.prototype;
|
||||
if (prototype && prototype.hasOwnProperty('__cid__')) {
|
||||
res = obj.__cid__;
|
||||
if (!allowTempId && (CC_DEV || CC_EDITOR) && isTempClassId(res)) {
|
||||
return '';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -1,716 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import * as jsarray from './array';
|
||||
import IDGenerator from './id-generator';
|
||||
import Pool from './pool';
|
||||
import { createMap } from './js-typed';
|
||||
|
||||
export * from './js-typed';
|
||||
|
||||
let tempCIDGenerator = new IDGenerator('TmpCId.');
|
||||
|
||||
const REGEXP_NUM_OR_STR = /(%d)|(%s)/;
|
||||
const REGEXP_STR = /%s/;
|
||||
|
||||
var _tmpValueDesc = {
|
||||
value: undefined,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: true
|
||||
};
|
||||
|
||||
var _tmpGetSetDesc = {
|
||||
get: null,
|
||||
set: null,
|
||||
enumerable: false,
|
||||
};
|
||||
|
||||
var _tmpGetDesc = {
|
||||
get: null,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
};
|
||||
|
||||
var _tmpSetDesc = {
|
||||
set: null,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
};
|
||||
|
||||
/**
|
||||
* This module provides some JavaScript utilities.
|
||||
* All members can be accessed with "cc.js".
|
||||
* @submodule js
|
||||
* @module js
|
||||
*/
|
||||
|
||||
export {default as IDGenerator} from './id-generator';
|
||||
export {default as Pool} from './pool';
|
||||
export const array = jsarray;
|
||||
|
||||
/**
|
||||
* Check the obj whether is number or not
|
||||
* If a number is created by using 'new Number(10086)', the typeof it will be "object"...
|
||||
* Then you can use this function if you care about this case.
|
||||
* @method isNumber
|
||||
* @param {*} obj
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function isNumber (obj) {
|
||||
return typeof obj === 'number' || obj instanceof Number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check the obj whether is string or not.
|
||||
* If a string is created by using 'new String("blabla")', the typeof it will be "object"...
|
||||
* Then you can use this function if you care about this case.
|
||||
* @method isString
|
||||
* @param {*} obj
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function isString (obj) {
|
||||
return typeof obj === 'string' || obj instanceof String;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get property descriptor in object and all its ancestors
|
||||
* @method getPropertyDescriptor
|
||||
* @param {Object} obj
|
||||
* @param {String} name
|
||||
* @return {Object}
|
||||
*/
|
||||
export function getPropertyDescriptor (obj, name) {
|
||||
while (obj) {
|
||||
var pd = Object.getOwnPropertyDescriptor(obj, name);
|
||||
if (pd) {
|
||||
return pd;
|
||||
}
|
||||
obj = Object.getPrototypeOf(obj);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
function _copyprop(name, source, target) {
|
||||
var pd = getPropertyDescriptor(source, name);
|
||||
Object.defineProperty(target, name, pd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all properties not defined in obj from arguments[1...n]
|
||||
* @method addon
|
||||
* @param {Object} obj object to extend its properties
|
||||
* @param {Object} ...sourceObj source object to copy properties from
|
||||
* @return {Object} the result obj
|
||||
*/
|
||||
export function addon (obj) {
|
||||
'use strict';
|
||||
obj = obj || {};
|
||||
for (var i = 1, length = arguments.length; i < length; i++) {
|
||||
var source = arguments[i];
|
||||
if (source) {
|
||||
if (typeof source !== 'object') {
|
||||
cc.errorID(5402, source);
|
||||
continue;
|
||||
}
|
||||
for ( var name in source) {
|
||||
if ( !(name in obj) ) {
|
||||
_copyprop( name, source, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* copy all properties from arguments[1...n] to obj
|
||||
* @method mixin
|
||||
* @param {Object} obj
|
||||
* @param {Object} ...sourceObj
|
||||
* @return {Object} the result obj
|
||||
*/
|
||||
export function mixin (obj) {
|
||||
'use strict';
|
||||
obj = obj || {};
|
||||
for (var i = 1, length = arguments.length; i < length; i++) {
|
||||
var source = arguments[i];
|
||||
if (source) {
|
||||
if (typeof source !== 'object') {
|
||||
cc.errorID(5403, source);
|
||||
continue;
|
||||
}
|
||||
for ( var name in source) {
|
||||
_copyprop( name, source, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Derive the class from the supplied base class.
|
||||
* Both classes are just native javascript constructors, not created by cc.Class, so
|
||||
* usually you will want to inherit using {{#crossLink "cc/Class:method"}}cc.Class {{/crossLink}} instead.
|
||||
* @method extend
|
||||
* @param {Function} cls
|
||||
* @param {Function} base - the baseclass to inherit
|
||||
* @return {Function} the result class
|
||||
*/
|
||||
export function extend (cls, base) {
|
||||
if (CC_DEV) {
|
||||
if (!base) {
|
||||
cc.errorID(5404);
|
||||
return;
|
||||
}
|
||||
if (!cls) {
|
||||
cc.errorID(5405);
|
||||
return;
|
||||
}
|
||||
if (Object.keys(cls.prototype).length > 0) {
|
||||
cc.errorID(5406);
|
||||
}
|
||||
}
|
||||
for (var p in base) if (base.hasOwnProperty(p)) cls[p] = base[p];
|
||||
cls.prototype = Object.create(base.prototype, {
|
||||
constructor: {
|
||||
value: cls,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
return cls;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get super class
|
||||
* @method getSuper
|
||||
* @param {Function} ctor - the constructor of subclass
|
||||
* @return {Function}
|
||||
*/
|
||||
export function getSuper (ctor) {
|
||||
var proto = ctor.prototype; // binded function do not have prototype
|
||||
var dunderProto = proto && Object.getPrototypeOf(proto);
|
||||
return dunderProto && dunderProto.constructor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether subclass is child of superclass or equals to superclass
|
||||
*
|
||||
* @method isChildClassOf
|
||||
* @param {Function} subclass
|
||||
* @param {Function} superclass
|
||||
* @return {Boolean}
|
||||
*/
|
||||
export function isChildClassOf (subclass, superclass) {
|
||||
if (subclass && superclass) {
|
||||
if (typeof subclass !== 'function') {
|
||||
return false;
|
||||
}
|
||||
if (typeof superclass !== 'function') {
|
||||
if (CC_DEV) {
|
||||
cc.warnID(3625, superclass);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (subclass === superclass) {
|
||||
return true;
|
||||
}
|
||||
for (;;) {
|
||||
subclass = getSuper(subclass);
|
||||
if (!subclass) {
|
||||
return false;
|
||||
}
|
||||
if (subclass === superclass) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes all enumerable properties from object
|
||||
* @method clear
|
||||
* @param {any} obj
|
||||
*/
|
||||
export function clear (obj) {
|
||||
var keys = Object.keys(obj);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
delete obj[keys[i]];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Define value, just help to call Object.defineProperty.<br>
|
||||
* The configurable will be true.
|
||||
* @method value
|
||||
* @param {Object} obj
|
||||
* @param {String} prop
|
||||
* @param {any} value
|
||||
* @param {Boolean} [writable=false]
|
||||
* @param {Boolean} [enumerable=false]
|
||||
*/
|
||||
export function value (obj, prop, value, writable, enumerable) {
|
||||
_tmpValueDesc.value = value;
|
||||
_tmpValueDesc.writable = writable;
|
||||
_tmpValueDesc.enumerable = enumerable;
|
||||
Object.defineProperty(obj, prop, _tmpValueDesc);
|
||||
_tmpValueDesc.value = undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Define get set accessor, just help to call Object.defineProperty(...)
|
||||
* @method getset
|
||||
* @param {Object} obj
|
||||
* @param {String} prop
|
||||
* @param {Function} getter
|
||||
* @param {Function} [setter=null]
|
||||
* @param {Boolean} [enumerable=false]
|
||||
* @param {Boolean} [configurable=false]
|
||||
*/
|
||||
export function getset (obj, prop, getter, setter, enumerable, configurable) {
|
||||
if (typeof setter !== 'function') {
|
||||
enumerable = setter;
|
||||
setter = undefined;
|
||||
}
|
||||
_tmpGetSetDesc.get = getter;
|
||||
_tmpGetSetDesc.set = setter;
|
||||
_tmpGetSetDesc.enumerable = enumerable;
|
||||
_tmpGetSetDesc.configurable = configurable;
|
||||
Object.defineProperty(obj, prop, _tmpGetSetDesc);
|
||||
_tmpGetSetDesc.get = null;
|
||||
_tmpGetSetDesc.set = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Define get accessor, just help to call Object.defineProperty(...)
|
||||
* @method get
|
||||
* @param {Object} obj
|
||||
* @param {String} prop
|
||||
* @param {Function} getter
|
||||
* @param {Boolean} [enumerable=false]
|
||||
* @param {Boolean} [configurable=false]
|
||||
*/
|
||||
export function get (obj, prop, getter, enumerable, configurable) {
|
||||
_tmpGetDesc.get = getter;
|
||||
_tmpGetDesc.enumerable = enumerable;
|
||||
_tmpGetDesc.configurable = configurable;
|
||||
Object.defineProperty(obj, prop, _tmpGetDesc);
|
||||
_tmpGetDesc.get = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Define set accessor, just help to call Object.defineProperty(...)
|
||||
* @method set
|
||||
* @param {Object} obj
|
||||
* @param {String} prop
|
||||
* @param {Function} setter
|
||||
* @param {Boolean} [enumerable=false]
|
||||
* @param {Boolean} [configurable=false]
|
||||
*/
|
||||
export function set (obj, prop, setter, enumerable, configurable) {
|
||||
_tmpSetDesc.set = setter;
|
||||
_tmpSetDesc.enumerable = enumerable;
|
||||
_tmpSetDesc.configurable = configurable;
|
||||
Object.defineProperty(obj, prop, _tmpSetDesc);
|
||||
_tmpSetDesc.set = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get class name of the object, if object is just a {} (and which class named 'Object'), it will return "".
|
||||
* (modified from <a href="http://stackoverflow.com/questions/1249531/how-to-get-a-javascript-objects-class">the code from this stackoverflow post</a>)
|
||||
* @method getClassName
|
||||
* @param {Object|Function} objOrCtor - instance or constructor
|
||||
* @return {String}
|
||||
*/
|
||||
export function getClassName (objOrCtor) {
|
||||
if (typeof objOrCtor === 'function') {
|
||||
var prototype = objOrCtor.prototype;
|
||||
if (prototype && prototype.hasOwnProperty('__classname__') && prototype.__classname__) {
|
||||
return prototype.__classname__;
|
||||
}
|
||||
var retval = '';
|
||||
// for browsers which have name property in the constructor of the object, such as chrome
|
||||
if (objOrCtor.name) {
|
||||
retval = objOrCtor.name;
|
||||
}
|
||||
if (objOrCtor.toString) {
|
||||
var arr, str = objOrCtor.toString();
|
||||
if (str.charAt(0) === '[') {
|
||||
// str is "[object objectClass]"
|
||||
arr = str.match(/\[\w+\s*(\w+)\]/);
|
||||
}
|
||||
else {
|
||||
// str is function objectClass () {} for IE Firefox
|
||||
arr = str.match(/function\s*(\w+)/);
|
||||
}
|
||||
if (arr && arr.length === 2) {
|
||||
retval = arr[1];
|
||||
}
|
||||
}
|
||||
return retval !== 'Object' ? retval : '';
|
||||
}
|
||||
else if (objOrCtor && objOrCtor.constructor) {
|
||||
return getClassName(objOrCtor.constructor);
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
function isTempClassId (id) {
|
||||
return typeof id !== 'string' || id.startsWith(tempCIDGenerator.prefix);
|
||||
}
|
||||
|
||||
// id 注册
|
||||
let _idToClass = {};
|
||||
let _nameToClass = {};
|
||||
|
||||
/**
|
||||
* Register the class by specified id, if its classname is not defined, the class name will also be set.
|
||||
* @method _setClassId
|
||||
* @param {String} classId
|
||||
* @param {Function} constructor
|
||||
* @private
|
||||
*/
|
||||
export function _setClassId (id, constructor) {
|
||||
let key = '__cid__';
|
||||
let table = _idToClass;
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(key)) {
|
||||
delete table[constructor.prototype[key]];
|
||||
}
|
||||
value(constructor.prototype, key, id);
|
||||
// register class
|
||||
if (id) {
|
||||
var registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
var error = 'A Class already exists with the same ' + key + ' : "' + id + '".';
|
||||
if (CC_TEST) {
|
||||
error += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
cc.js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
cc.error(error);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
//if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
//}
|
||||
}
|
||||
};
|
||||
|
||||
function doSetClassName (id, constructor) {
|
||||
let key = '__classname__';
|
||||
let table = _nameToClass;
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(key)) {
|
||||
delete table[constructor.prototype[key]];
|
||||
}
|
||||
value(constructor.prototype, key, id);
|
||||
// register class
|
||||
if (id) {
|
||||
var registered = table[id];
|
||||
if (registered && registered !== constructor) {
|
||||
var error = 'A Class already exists with the same ' + key + ' : "' + id + '".';
|
||||
if (CC_TEST) {
|
||||
error += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
cc.js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
cc.error(error);
|
||||
}
|
||||
else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
//if (id === "") {
|
||||
// console.trace("", table === _nameToClass);
|
||||
//}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Register the class by specified name manually
|
||||
* @method setClassName
|
||||
* @param {String} className
|
||||
* @param {Function} constructor
|
||||
*/
|
||||
export function setClassName (className, constructor) {
|
||||
doSetClassName(className, constructor);
|
||||
// auto set class id
|
||||
if (!constructor.prototype.hasOwnProperty('__cid__')) {
|
||||
var id = className || tempCIDGenerator.getNewId();
|
||||
if (id) {
|
||||
_setClassId(id, constructor);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Unregister a class from fireball.
|
||||
*
|
||||
* If you dont need a registered class anymore, you should unregister the class so that Fireball will not keep its reference anymore.
|
||||
* Please note that its still your responsibility to free other references to the class.
|
||||
*
|
||||
* @method unregisterClass
|
||||
* @param {Function} ...constructor - the class you will want to unregister, any number of classes can be added
|
||||
*/
|
||||
export function unregisterClass () {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var p = arguments[i].prototype;
|
||||
var classId = p.__cid__;
|
||||
if (classId) {
|
||||
delete _idToClass[classId];
|
||||
}
|
||||
var classname = p.__classname__;
|
||||
if (classname) {
|
||||
delete _nameToClass[classname];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the registered class by id
|
||||
* @method _getClassById
|
||||
* @param {String} classId
|
||||
* @return {Function} constructor
|
||||
* @private
|
||||
*/
|
||||
export function _getClassById (classId) {
|
||||
return _idToClass[classId];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the registered class by name
|
||||
* @method getClassByName
|
||||
* @param {String} classname
|
||||
* @return {Function} constructor
|
||||
*/
|
||||
export function getClassByName (classname) {
|
||||
return _nameToClass[classname];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get class id of the object
|
||||
* @method _getClassId
|
||||
* @param {Object|Function} obj - instance or constructor
|
||||
* @param {Boolean} [allowTempId=true] - can return temp id in editor
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
export function _getClassId (obj, allowTempId) {
|
||||
allowTempId = (typeof allowTempId !== 'undefined' ? allowTempId: true);
|
||||
|
||||
var res;
|
||||
if (typeof obj === 'function' && obj.prototype.hasOwnProperty('__cid__')) {
|
||||
res = obj.prototype.__cid__;
|
||||
if (!allowTempId && (CC_DEV || CC_EDITOR) && isTempClassId(res)) {
|
||||
return '';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
if (obj && obj.constructor) {
|
||||
var prototype = obj.constructor.prototype;
|
||||
if (prototype && prototype.hasOwnProperty('__cid__')) {
|
||||
res = obj.__cid__;
|
||||
if (!allowTempId && (CC_DEV || CC_EDITOR) && isTempClassId(res)) {
|
||||
return '';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines a polyfill field for obsoleted codes.
|
||||
* @method obsolete
|
||||
* @param {any} obj - YourObject or YourClass.prototype
|
||||
* @param {String} obsoleted - "OldParam" or "YourClass.OldParam"
|
||||
* @param {String} newExpr - "NewParam" or "YourClass.NewParam"
|
||||
* @param {Boolean} [writable=false]
|
||||
*/
|
||||
export function obsolete (obj, obsoleted, newExpr, writable) {
|
||||
var extractPropName = /([^.]+)$/;
|
||||
var oldProp = extractPropName.exec(obsoleted)[0];
|
||||
var newProp = extractPropName.exec(newExpr)[0];
|
||||
function getter () {
|
||||
if (CC_DEV) {
|
||||
cc.warnID(5400, obsoleted, newExpr);
|
||||
}
|
||||
return this[newProp];
|
||||
}
|
||||
function setter (value) {
|
||||
if (CC_DEV) {
|
||||
cc.warnID(5401, obsoleted, newExpr);
|
||||
}
|
||||
this[newProp] = value;
|
||||
}
|
||||
|
||||
if (writable) {
|
||||
getset(obj, oldProp,getter,setter);
|
||||
}
|
||||
else {
|
||||
get(obj, oldProp, getter);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines all polyfill fields for obsoleted codes corresponding to the enumerable properties of props.
|
||||
* @method obsoletes
|
||||
* @param {any} obj - YourObject or YourClass.prototype
|
||||
* @param {any} objName - "YourObject" or "YourClass"
|
||||
* @param {Object} props
|
||||
* @param {Boolean} [writable=false]
|
||||
*/
|
||||
export function obsoletes (obj, objName, props, writable) {
|
||||
for (var obsoleted in props) {
|
||||
var newName = props[obsoleted];
|
||||
obsolete(obj, objName + '.' + obsoleted, newName, writable);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A string tool to construct a string with format string.
|
||||
* @method formatStr
|
||||
* @param {String|any} msg - A JavaScript string containing zero or more substitution strings (%s).
|
||||
* @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
* @returns {String}
|
||||
* @example
|
||||
* cc.js.formatStr("a: %s, b: %s", a, b);
|
||||
* cc.js.formatStr(a, b, c);
|
||||
*/
|
||||
export function formatStr () {
|
||||
var argLen = arguments.length;
|
||||
if (argLen === 0) {
|
||||
return '';
|
||||
}
|
||||
var msg = arguments[0];
|
||||
if (argLen === 1) {
|
||||
return '' + msg;
|
||||
}
|
||||
|
||||
var hasSubstitution = typeof msg === 'string' && REGEXP_NUM_OR_STR.test(msg);
|
||||
if (hasSubstitution) {
|
||||
for (let i = 1; i < argLen; ++i) {
|
||||
var arg = arguments[i];
|
||||
var regExpToTest = typeof arg === 'number' ? REGEXP_NUM_OR_STR : REGEXP_STR;
|
||||
if (regExpToTest.test(msg))
|
||||
msg = msg.replace(regExpToTest, arg);
|
||||
else
|
||||
msg += ' ' + arg;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i = 1; i < argLen; ++i) {
|
||||
msg += ' ' + arguments[i];
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
// see https://github.com/petkaantonov/bluebird/issues/1389
|
||||
export function shiftArguments () {
|
||||
var len = arguments.length - 1;
|
||||
var args = new Array(len);
|
||||
for(var i = 0; i < len; ++i) {
|
||||
args[i] = arguments[i + 1];
|
||||
}
|
||||
return args;
|
||||
};
|
||||
|
||||
// fix submodule pollute ...
|
||||
/**
|
||||
* @submodule cc
|
||||
*/
|
||||
|
||||
cc.js = {
|
||||
IDGenerator,
|
||||
Pool,
|
||||
array,
|
||||
isNumber,
|
||||
isString,
|
||||
getPropertyDescriptor,
|
||||
addon,
|
||||
mixin,
|
||||
extend,
|
||||
getSuper,
|
||||
isChildClassOf,
|
||||
clear,
|
||||
value,
|
||||
getset,
|
||||
get,
|
||||
set,
|
||||
unregisterClass,
|
||||
getClassName,
|
||||
setClassName,
|
||||
getClassByName,
|
||||
_getClassId,
|
||||
_setClassId,
|
||||
_getClassById,
|
||||
obsolete,
|
||||
obsoletes,
|
||||
formatStr,
|
||||
shiftArguments,
|
||||
createMap
|
||||
};
|
||||
|
||||
if (CC_DEV) {
|
||||
cc.js.getset(cc.js, '_registeredClassIds',
|
||||
function () {
|
||||
var dump = {};
|
||||
for (var id in _idToClass) {
|
||||
dump[id] = _idToClass[id];
|
||||
}
|
||||
return dump;
|
||||
},
|
||||
function (value) {
|
||||
clear(_idToClass);
|
||||
for (var id in value) {
|
||||
_idToClass[id] = value[id];
|
||||
}
|
||||
}
|
||||
);
|
||||
cc.js.getset(cc.js, '_registeredClassNames',
|
||||
function () {
|
||||
var dump = {};
|
||||
for (var id in _nameToClass) {
|
||||
dump[id] = _nameToClass[id];
|
||||
}
|
||||
return dump;
|
||||
},
|
||||
function (value) {
|
||||
clear(_nameToClass);
|
||||
for (var id in value) {
|
||||
_nameToClass[id] = value[id];
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import * as jsarray from './array';
|
||||
import IDGenerator from './id-generator';
|
||||
import {
|
||||
_getClassById,
|
||||
_getClassId,
|
||||
_setClassId,
|
||||
addon,
|
||||
clear,
|
||||
createMap,
|
||||
extend,
|
||||
formatStr,
|
||||
get,
|
||||
getClassByName,
|
||||
getClassName,
|
||||
getPropertyDescriptor,
|
||||
getset,
|
||||
getSuper,
|
||||
isChildClassOf,
|
||||
isNumber,
|
||||
isString,
|
||||
mixin,
|
||||
obsolete,
|
||||
obsoletes,
|
||||
set,
|
||||
setClassName,
|
||||
shiftArguments,
|
||||
unregisterClass,
|
||||
value,
|
||||
} from './js-typed';
|
||||
import Pool from './pool';
|
||||
|
||||
export * from './js-typed';
|
||||
export {default as IDGenerator} from './id-generator';
|
||||
export {default as Pool} from './pool';
|
||||
export const array = jsarray;
|
||||
|
||||
/**
|
||||
* This module provides some JavaScript utilities.
|
||||
* All members can be accessed with "cc.js".
|
||||
*/
|
||||
cc.js = {
|
||||
IDGenerator,
|
||||
Pool,
|
||||
array: jsarray,
|
||||
isNumber,
|
||||
isString,
|
||||
getPropertyDescriptor,
|
||||
addon,
|
||||
mixin,
|
||||
extend,
|
||||
getSuper,
|
||||
isChildClassOf,
|
||||
clear,
|
||||
value,
|
||||
getset,
|
||||
get,
|
||||
set,
|
||||
unregisterClass,
|
||||
getClassName,
|
||||
setClassName,
|
||||
getClassByName,
|
||||
_getClassId,
|
||||
_setClassId,
|
||||
_getClassById,
|
||||
obsolete,
|
||||
obsoletes,
|
||||
formatStr,
|
||||
shiftArguments,
|
||||
createMap,
|
||||
};
|
||||
|
||||
// if (CC_DEV) {
|
||||
// cc.js.getset(cc.js, '_registeredClassIds',
|
||||
// function () {
|
||||
// var dump = {};
|
||||
// for (var id in _idToClass) {
|
||||
// dump[id] = _idToClass[id];
|
||||
// }
|
||||
// return dump;
|
||||
// },
|
||||
// function (value) {
|
||||
// clear(_idToClass);
|
||||
// for (var id in value) {
|
||||
// _idToClass[id] = value[id];
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// cc.js.getset(cc.js, '_registeredClassNames',
|
||||
// function () {
|
||||
// var dump = {};
|
||||
// for (var id in _nameToClass) {
|
||||
// dump[id] = _nameToClass[id];
|
||||
// }
|
||||
// return dump;
|
||||
// },
|
||||
// function (value) {
|
||||
// clear(_nameToClass);
|
||||
// for (var id in value) {
|
||||
// _nameToClass[id] = value[id];
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
@@ -17,10 +17,10 @@ import { GFXSampler } from '../../gfx/sampler';
|
||||
import { GFXShader } from '../../gfx/shader';
|
||||
import { GFXTextureView } from '../../gfx/texture-view';
|
||||
import { RenderPassStage, RenderPriority } from '../../pipeline/define';
|
||||
import { getPhaseID } from '../../pipeline/pass-phase';
|
||||
import { RenderPipeline } from '../../pipeline/render-pipeline';
|
||||
import { programLib } from './program-lib';
|
||||
import { samplerLib } from './sampler-lib';
|
||||
import { getPhaseID } from '../../pipeline/pass-phase';
|
||||
|
||||
export interface IDefineMap { [name: string]: number | boolean | string; }
|
||||
export interface IPassInfoFull extends IPassInfo {
|
||||
@@ -276,7 +276,8 @@ export class Pass {
|
||||
}
|
||||
}
|
||||
|
||||
public tryCompile () {
|
||||
public tryCompile (defines?: IDefineMap) {
|
||||
if (defines) { Object.assign(this._defines, defines); }
|
||||
const pipeline = cc.director.root.pipeline as RenderPipeline | null;
|
||||
if (!pipeline) { return false; }
|
||||
this._renderPass = pipeline.getRenderPass(this._stage);
|
||||
@@ -363,8 +364,8 @@ export class Pass {
|
||||
if (info.priority !== undefined) { this._priority = info.priority; }
|
||||
if (info.primitive !== undefined) { this._primitive = info.primitive; }
|
||||
if (info.stage !== undefined) { this._stage = info.stage; }
|
||||
if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics; }
|
||||
if (info.customizations) { this._customizations = info.customizations; }
|
||||
if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics as GFXDynamicState[]; }
|
||||
if (info.customizations) { this._customizations = info.customizations as string[]; }
|
||||
if (this._phase === 0) {
|
||||
const phaseName = info.phase || 'default';
|
||||
this._phase = getPhaseID(phaseName);
|
||||
|
||||
@@ -35,7 +35,7 @@ function isUniformStorage (storage: JointStorage): storage is IJointUniformsStor
|
||||
return !('texture' in storage);
|
||||
}
|
||||
|
||||
export const __FORCE_USE_UNIFORM_STORAGE__ = true;
|
||||
export const __FORCE_USE_UNIFORM_STORAGE__ = false;
|
||||
|
||||
export class SkinningModel extends Model {
|
||||
private _jointStorage: JointStorage | null = null;
|
||||
@@ -168,7 +168,7 @@ function _createJointsTexture (skinning: { joints: any[]; }) {
|
||||
}
|
||||
}
|
||||
if (textureExtent < 0) {
|
||||
throw new Error('To many joints.');
|
||||
throw new Error('Too many joints.');
|
||||
}
|
||||
|
||||
const texture = new Texture2D();
|
||||
|
||||
@@ -136,6 +136,18 @@ class Node extends BaseNode {
|
||||
this._eventProcessor = new cc.NodeEventProcessor(this);
|
||||
}
|
||||
|
||||
set position (value: vec3) {
|
||||
this.setPosition(value.x, value.y, value.z);
|
||||
}
|
||||
|
||||
set scale (value: vec3) {
|
||||
this.setScale(value.x, value.y, value.z);
|
||||
}
|
||||
|
||||
set rotation (value: quat) {
|
||||
this.setRotation(value.x, value.y, value.z, value.w);
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// hierarchy
|
||||
// ===============================
|
||||
|
||||
@@ -179,10 +179,6 @@ else {
|
||||
defineMacro('CC_SUPPORT_JIT', !(CC_WECHATGAME || CC_QQPLAY || CC_RUNTIME));
|
||||
}
|
||||
|
||||
//#begin test code for wechat
|
||||
// _global['CC_SUPPORT_JIT'] = false;
|
||||
//#end
|
||||
|
||||
//
|
||||
|
||||
if (CC_DEV) {
|
||||
|
||||
@@ -63,6 +63,7 @@ interface IGlobaldefines {
|
||||
CC_SUPPORT_JIT?: boolean;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line: no-shadowed-variable
|
||||
function getGlobalDefs (platform: Platform, flags?: IFlags): object {
|
||||
const PLATFORM_MACROS = ['CC_EDITOR', 'CC_PREVIEW', 'CC_BUILD', 'CC_TEST'];
|
||||
|
||||
|
||||
+36
-13
@@ -83,19 +83,42 @@ async function _doBundle (options: IBuildOptions) {
|
||||
|
||||
code = generated.code;
|
||||
|
||||
// console.log(`Doing uglify...`);
|
||||
|
||||
// const minifyOutput = minify(code, {
|
||||
// compress: {
|
||||
// global_defs: options.globalDefines,
|
||||
// },
|
||||
// });
|
||||
// if (minifyOutput.error) {
|
||||
// console.error(minifyOutput.error.stack);
|
||||
// return null;
|
||||
// } else {
|
||||
// code = minifyOutput.code;
|
||||
// }
|
||||
console.log(`Doing uglify...`);
|
||||
|
||||
const minifyOutput = minify(code, {
|
||||
compress: {
|
||||
global_defs: options.globalDefines,
|
||||
// sequences : true, // join consecutive statemets with the “comma operator”
|
||||
// properties : true, // optimize property access: a["foo"] → a.foo
|
||||
// dead_code : true, // discard unreachable code
|
||||
// drop_debugger : true, // discard “debugger” statements
|
||||
// unsafe : false, // some unsafe optimizations (see below)
|
||||
// conditionals : true, // optimize if-s and conditional expressions
|
||||
// comparisons : true, // optimize comparisons
|
||||
// evaluate : true, // evaluate constant expressions
|
||||
// booleans : true, // optimize boolean expressions
|
||||
// loops : true, // optimize loops
|
||||
// unused : true, // drop unused variables/functions
|
||||
// hoist_funs : true, // hoist function declarations
|
||||
// hoist_vars : false, // hoist variable declarations
|
||||
// if_return : true, // optimize if-s followed by return/continue
|
||||
// join_vars : true, // join var declarations
|
||||
// side_effects : true, // drop side-effect-free statements
|
||||
// warnings : true, // warn about potentially dangerous optimizations/code
|
||||
},
|
||||
mangle: false,
|
||||
keep_fnames: true,
|
||||
output: {
|
||||
beautify: true,
|
||||
},
|
||||
sourceMap: true,
|
||||
});
|
||||
if (minifyOutput.error) {
|
||||
console.error(minifyOutput.error.stack);
|
||||
return null;
|
||||
} else {
|
||||
code = minifyOutput.code;
|
||||
}
|
||||
|
||||
return {
|
||||
code,
|
||||
|
||||
Reference in New Issue
Block a user