mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
add cc.Float, cc.Boolean, cc.String, cc.Integer
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -250,7 +250,7 @@ var _metaClass = {
|
||||
*/
|
||||
extend: function (options) {
|
||||
options.extends = this;
|
||||
return FireClass(options);
|
||||
return CCClass(options);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -428,7 +428,7 @@ function define (className, baseClasses, mixins, constructor, options) {
|
||||
|
||||
function _checkCtor (ctor) {
|
||||
if (CC_DEV) {
|
||||
if (FireClass._isCCClass(ctor)) {
|
||||
if (CCClass._isCCClass(ctor)) {
|
||||
cc.error("Constructor can not be another CCClass");
|
||||
return;
|
||||
}
|
||||
@@ -437,8 +437,8 @@ function _checkCtor (ctor) {
|
||||
return;
|
||||
}
|
||||
if (ctor.length > 0) {
|
||||
// fireball-x/dev#138: To make a unified FireClass serialization process,
|
||||
// we don't allow parameters for constructor when creating instances of FireClass.
|
||||
// fireball-x/dev#138: To make a unified CCClass serialization process,
|
||||
// we don't allow parameters for constructor when creating instances of CCClass.
|
||||
// For advance user, construct arguments can still get from 'arguments'.
|
||||
cc.warn("Can not instantiate CCClass with arguments.");
|
||||
return;
|
||||
@@ -506,7 +506,7 @@ function _createCtor (ctor, baseClass, mixins, className, options) {
|
||||
for (var b = 0; b < baseOrMixins.length; b++) {
|
||||
var baseOrMixin = baseOrMixins[b];
|
||||
if (baseOrMixin) {
|
||||
if (FireClass._isCCClass(baseOrMixin)) {
|
||||
if (CCClass._isCCClass(baseOrMixin)) {
|
||||
var baseCtors = baseOrMixin.__ctors__;
|
||||
if (baseCtors) {
|
||||
ctors = ctors.concat(baseCtors);
|
||||
@@ -632,8 +632,8 @@ function boundSuperCalls (baseClass, options) {
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en Defines a FireClass using the given specification, please see [Class](/en/scripting/class/) for details.
|
||||
* !#zh 定义一个 FireClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/zh/scripting/class/)。
|
||||
* !#en Defines a CCClass using the given specification, please see [Class](/en/scripting/class/) for details.
|
||||
* !#zh 定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/zh/scripting/class/)。
|
||||
*
|
||||
* @class Class
|
||||
* @param {Object} options
|
||||
@@ -684,7 +684,7 @@ function boundSuperCalls (baseClass, options) {
|
||||
// ...
|
||||
};
|
||||
*/
|
||||
function FireClass (options) {
|
||||
function CCClass (options) {
|
||||
if (arguments.length === 0) {
|
||||
return define();
|
||||
}
|
||||
@@ -796,7 +796,7 @@ function FireClass (options) {
|
||||
* @return {Boolean}
|
||||
* @private
|
||||
*/
|
||||
FireClass._isCCClass = function (constructor) {
|
||||
CCClass._isCCClass = function (constructor) {
|
||||
return !!constructor && (constructor.prop === _metaClass.prop);
|
||||
};
|
||||
|
||||
@@ -805,7 +805,7 @@ FireClass._isCCClass = function (constructor) {
|
||||
// @param {Function} constructor
|
||||
// @private
|
||||
//
|
||||
//FireClass._convertToFireClass = function (constructor) {
|
||||
//CCClass._convertToFireClass = function (constructor) {
|
||||
// constructor.prop = _metaClass.prop;
|
||||
//};
|
||||
|
||||
@@ -826,7 +826,7 @@ function fastDefine (className, constructor, serializableFields) {
|
||||
}
|
||||
}
|
||||
|
||||
FireClass.attr = Attr.attr;
|
||||
CCClass.attr = Attr.attr;
|
||||
|
||||
var tmpAttrs = [];
|
||||
function parseAttributes (attrs, className, propName) {
|
||||
@@ -988,26 +988,6 @@ function parseAttributes (attrs, className, propName) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CC_DEV) {
|
||||
var watch = attrs.watch;
|
||||
if (watch) {
|
||||
if (typeof watch === 'object') {
|
||||
for (var watchKey in watch) {
|
||||
var watchCallback = watch[watchKey];
|
||||
if (typeof watchCallback === 'function') {
|
||||
result.push(Attr.Watch(watchKey.split(' '), watchCallback));
|
||||
}
|
||||
else {
|
||||
cc.error(ERR_Type, 'value', 'watch object', 'function');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
cc.error(ERR_Type, 'watch', className + '.' + propName, 'object');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1016,9 +996,9 @@ function parseAttributes (attrs, className, propName) {
|
||||
* @return {Function}
|
||||
* @deprecated
|
||||
*/
|
||||
FireClass.extend = FireClass;
|
||||
CCClass.extend = CCClass;
|
||||
|
||||
cc.Class = FireClass;
|
||||
cc.Class = CCClass;
|
||||
|
||||
module.exports = {
|
||||
instantiateProps: instantiateProps,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
var JS = require('./js');
|
||||
var isPlainEmptyObj = require('./utils').isPlainEmptyObj_DEV;
|
||||
|
||||
/**
|
||||
* @class Class
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tag the class with any meta attributes, then return all current attributes assigned to it.
|
||||
* This function holds only the attributes, not their implementations.
|
||||
@@ -36,6 +40,8 @@ var isPlainEmptyObj = require('./utils').isPlainEmptyObj_DEV;
|
||||
* @param {String} propertyName - the name of property or function, used to retrieve the attributes
|
||||
* @param {Object} [attributes] - the attribute table to mark, new attributes will merged with existed attributes. Attribute whose key starts with '_' will be ignored.
|
||||
* @return {Object|Undefined} return all attributes associated with the property. if none undefined will be returned
|
||||
* @static
|
||||
* @private
|
||||
* @example {@link utils/api/engine/docs/cocos2d/core/platform/attribute/attr.js}
|
||||
*/
|
||||
function attr (constructor, propertyName, attributes) {
|
||||
@@ -101,6 +107,39 @@ function attr (constructor, propertyName, attributes) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specify that the input value must be integer in Inspector.
|
||||
* Also used to indicates that the elements in array should be type integer.
|
||||
* @property {string} Integer
|
||||
* @readonly
|
||||
*/
|
||||
cc.Integer = 'Integer';
|
||||
|
||||
/**
|
||||
* Indicates that the elements in array should be type double.
|
||||
* @property {string} Float
|
||||
* @readonly
|
||||
*/
|
||||
cc.Float = 'Float';
|
||||
|
||||
/**
|
||||
* Indicates that the elements in array should be type boolean.
|
||||
* @property {string} Boolean
|
||||
* @readonly
|
||||
*/
|
||||
cc.Boolean = 'Boolean';
|
||||
|
||||
/**
|
||||
* Indicates that the elements in array should be type string.
|
||||
* @property {string} String
|
||||
* @readonly
|
||||
*/
|
||||
cc.String = 'String';
|
||||
|
||||
/*
|
||||
BuiltinAttributes: {
|
||||
default: defaultValue,
|
||||
@@ -267,22 +306,6 @@ function Nullable (boolPropName, hasValueByDefault) {
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// @method Watch
|
||||
// @param {String} names - the name of target property to watch, array is also acceptable.
|
||||
// @param {Function} callback - the callback function to invoke when target property(s) is changed.
|
||||
// @param {Object} callback.param object - the instance object which contains watching property(s).
|
||||
// @param {Object} callback.param element - the property element which displays watching property(s).
|
||||
// @return {object} the attribute
|
||||
// @private
|
||||
//
|
||||
function Watch (names, callback) {
|
||||
return {
|
||||
watch: [].concat(names), // array of property name to watch
|
||||
watchCallback: callback
|
||||
};
|
||||
}
|
||||
|
||||
function Range (min, max) {
|
||||
return { min: min, max: max };
|
||||
}
|
||||
@@ -296,6 +319,5 @@ module.exports = {
|
||||
RawType: RawType,
|
||||
ScriptUuid: {}, // the value will be represented as a uuid string
|
||||
Nullable: Nullable,
|
||||
Watch: Watch,
|
||||
Range: Range
|
||||
};
|
||||
|
||||
@@ -402,7 +402,7 @@ var _Deserializer = (function () {
|
||||
var klass = null;
|
||||
if (serialized.__type__) {
|
||||
|
||||
// Type Object (including FireClass)
|
||||
// Type Object (including CCClass)
|
||||
|
||||
klass = self._classFinder(serialized.__type__);
|
||||
if (!klass) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
var Attr = require('./attribute');
|
||||
|
||||
// 增加预处理属性这个步骤的目的是降低 FireClass 的实现难度,将比较稳定的通用逻辑和一些需求比较灵活的属性需求分隔开。
|
||||
// 增加预处理属性这个步骤的目的是降低 CCClass 的实现难度,将比较稳定的通用逻辑和一些需求比较灵活的属性需求分隔开。
|
||||
|
||||
var SerializableAttrs = {
|
||||
url: {
|
||||
|
||||
Reference in New Issue
Block a user