From 2192433dd5b6115c6f271c9a55aa60960b8169c3 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 13 Sep 2014 18:26:31 +0800 Subject: [PATCH 01/32] Feature #5929: Add require.js --- require.js | 2388 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2388 insertions(+) create mode 100644 require.js diff --git a/require.js b/require.js new file mode 100644 index 0000000000..4c171cb0eb --- /dev/null +++ b/require.js @@ -0,0 +1,2388 @@ +/** vim: et:ts=4:sw=4:sts=4 + * @license RequireJS 2.1.14 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved. + * Available via the MIT or new BSD license. + * see: http://github.com/jrburke/requirejs for details + */ +//Not using strict: uneven strict support in browsers, #392, and causes +//problems with requirejs.exec()/transpiler plugins that may not be strict. +/*jslint regexp: true, nomen: true, sloppy: true */ +/*global window, navigator, document, importScripts, setTimeout, opera */ + +var requirejs, require, define; +(function (global) { + var req, s, head, baseElement, dataMain, src, + interactiveScript, currentlyAddingScript, mainScript, subPath, + version = '2.1.14', + commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, + cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, + jsSuffixRegExp = /\.js$/, + currDirRegExp = /^\.\//, + op = Object.prototype, + ostring = op.toString, + hasOwn = op.hasOwnProperty, + ap = Array.prototype, + apsp = ap.splice, + isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document), + isWebWorker = !isBrowser && typeof importScripts !== 'undefined', + //PS3 indicates loaded and complete, but need to wait for complete + //specifically. Sequence is 'loading', 'loaded', execution, + // then 'complete'. The UA check is unfortunate, but not sure how + //to feature test w/o causing perf issues. + readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ? + /^complete$/ : /^(complete|loaded)$/, + defContextName = '_', + //Oh the tragedy, detecting opera. See the usage of isOpera for reason. + isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]', + contexts = {}, + cfg = {}, + globalDefQueue = [], + useInteractive = false; + + function isFunction(it) { + return ostring.call(it) === '[object Function]'; + } + + function isArray(it) { + return ostring.call(it) === '[object Array]'; + } + + /** + * Helper function for iterating over an array. If the func returns + * a true value, it will break out of the loop. + */ + function each(ary, func) { + if (ary) { + var i; + for (i = 0; i < ary.length; i += 1) { + if (ary[i] && func(ary[i], i, ary)) { + break; + } + } + } + } + + /** + * Helper function for iterating over an array backwards. If the func + * returns a true value, it will break out of the loop. + */ + function eachReverse(ary, func) { + if (ary) { + var i; + for (i = ary.length - 1; i > -1; i -= 1) { + if (ary[i] && func(ary[i], i, ary)) { + break; + } + } + } + } + + function hasProp(obj, prop) { + return hasOwn.call(obj, prop); + } + + function getOwn(obj, prop) { + return hasProp(obj, prop) && obj[prop]; + } + + /** + * Cycles over properties in an object and calls a function for each + * property value. If the function returns a truthy value, then the + * iteration is stopped. + */ + function eachProp(obj, func) { + var prop; + for (prop in obj) { + if (hasProp(obj, prop)) { + if (func(obj[prop], prop)) { + break; + } + } + } + } + + /** + * Simple function to mix in properties from source into target, + * but only if target does not already have a property of the same name. + */ + function mixin(target, source, force, deepStringMixin) { + if (source) { + eachProp(source, function (value, prop) { + if (force || !hasProp(target, prop)) { + if (deepStringMixin && typeof value === 'object' && value && + !isArray(value) && !isFunction(value) && + !(value instanceof RegExp)) { + + if (!target[prop]) { + target[prop] = {}; + } + mixin(target[prop], value, force, deepStringMixin); + } else { + target[prop] = value; + } + } + }); + } + return target; + } + + //Similar to Function.prototype.bind, but the 'this' object is specified + //first, since it is easier to read/figure out what 'this' will be. + function bind(obj, fn) { + return function () { + return fn.apply(obj, arguments); + }; + } + + function scripts() { + return document.getElementsByTagName('script'); + } + + function defaultOnError(err) { + throw err; + } + + //Allow getting a global that is expressed in + //dot notation, like 'a.b.c'. + function getGlobal(value) { + if (!value) { + return value; + } + var g = global; + each(value.split('.'), function (part) { + g = g[part]; + }); + return g; + } + + /** + * Constructs an error with a pointer to an URL with more information. + * @param {String} id the error ID that maps to an ID on a web page. + * @param {String} message human readable error. + * @param {Error} [err] the original error, if there is one. + * + * @returns {Error} + */ + function makeError(id, msg, err, requireModules) { + var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id); + e.requireType = id; + e.requireModules = requireModules; + if (err) { + e.originalError = err; + } + return e; + } + + if (typeof define !== 'undefined') { + //If a define is already in play via another AMD loader, + //do not overwrite. + return; + } + + if (typeof requirejs !== 'undefined') { + if (isFunction(requirejs)) { + //Do not overwrite an existing requirejs instance. + return; + } + cfg = requirejs; + requirejs = undefined; + } + + //Allow for a require config object + if (typeof require !== 'undefined' && !isFunction(require)) { + //assume it is a config object. + cfg = require; + require = undefined; + } + + function newContext(contextName) { + var inCheckLoaded, Module, context, handlers, + checkLoadedTimeoutId, + config = { + //Defaults. Do not set a default for map + //config to speed up normalize(), which + //will run faster if there is no default. + waitSeconds: 7, + baseUrl: './', + paths: {}, + bundles: {}, + pkgs: {}, + shim: {}, + config: {} + }, + registry = {}, + //registry of just enabled modules, to speed + //cycle breaking code when lots of modules + //are registered, but not activated. + enabledRegistry = {}, + undefEvents = {}, + defQueue = [], + defined = {}, + urlFetched = {}, + bundlesMap = {}, + requireCounter = 1, + unnormalizedCounter = 1; + + /** + * Trims the . and .. from an array of path segments. + * It will keep a leading path segment if a .. will become + * the first path segment, to help with module name lookups, + * which act like paths, but can be remapped. But the end result, + * all paths that use this function should look normalized. + * NOTE: this method MODIFIES the input array. + * @param {Array} ary the array of path segments. + */ + function trimDots(ary) { + var i, part; + for (i = 0; i < ary.length; i++) { + part = ary[i]; + if (part === '.') { + ary.splice(i, 1); + i -= 1; + } else if (part === '..') { + // If at the start, or previous value is still .., + // keep them so that when converted to a path it may + // still work when converted to a path, even though + // as an ID it is less than ideal. In larger point + // releases, may be better to just kick out an error. + if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') { + continue; + } else if (i > 0) { + ary.splice(i - 1, 2); + i -= 2; + } + } + } + } + + /** + * Given a relative module name, like ./something, normalize it to + * a real name that can be mapped to a path. + * @param {String} name the relative name + * @param {String} baseName a real name that the name arg is relative + * to. + * @param {Boolean} applyMap apply the map config to the value. Should + * only be done if this normalization is for a dependency ID. + * @returns {String} normalized name + */ + function normalize(name, baseName, applyMap) { + var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex, + foundMap, foundI, foundStarMap, starI, normalizedBaseParts, + baseParts = (baseName && baseName.split('/')), + map = config.map, + starMap = map && map['*']; + + //Adjust any relative paths. + if (name) { + name = name.split('/'); + lastIndex = name.length - 1; + + // If wanting node ID compatibility, strip .js from end + // of IDs. Have to do this here, and not in nameToUrl + // because node allows either .js or non .js to map + // to same file. + if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { + name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); + } + + // Starts with a '.' so need the baseName + if (name[0].charAt(0) === '.' && baseParts) { + //Convert baseName to array, and lop off the last part, + //so that . matches that 'directory' and not name of the baseName's + //module. For instance, baseName of 'one/two/three', maps to + //'one/two/three.js', but we want the directory, 'one/two' for + //this normalization. + normalizedBaseParts = baseParts.slice(0, baseParts.length - 1); + name = normalizedBaseParts.concat(name); + } + + trimDots(name); + name = name.join('/'); + } + + //Apply map config if available. + if (applyMap && map && (baseParts || starMap)) { + nameParts = name.split('/'); + + outerLoop: for (i = nameParts.length; i > 0; i -= 1) { + nameSegment = nameParts.slice(0, i).join('/'); + + if (baseParts) { + //Find the longest baseName segment match in the config. + //So, do joins on the biggest to smallest lengths of baseParts. + for (j = baseParts.length; j > 0; j -= 1) { + mapValue = getOwn(map, baseParts.slice(0, j).join('/')); + + //baseName segment has config, find if it has one for + //this name. + if (mapValue) { + mapValue = getOwn(mapValue, nameSegment); + if (mapValue) { + //Match, update name to the new value. + foundMap = mapValue; + foundI = i; + break outerLoop; + } + } + } + } + + //Check for a star map match, but just hold on to it, + //if there is a shorter segment match later in a matching + //config, then favor over this star map. + if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) { + foundStarMap = getOwn(starMap, nameSegment); + starI = i; + } + } + + if (!foundMap && foundStarMap) { + foundMap = foundStarMap; + foundI = starI; + } + + if (foundMap) { + nameParts.splice(0, foundI, foundMap); + name = nameParts.join('/'); + } + } + + // If the name points to a package's name, use + // the package main instead. + pkgMain = getOwn(config.pkgs, name); + + return pkgMain ? pkgMain : name; + } + + function removeScript(name) { + if (isBrowser) { + each(scripts(), function (scriptNode) { + if (scriptNode.getAttribute('data-requiremodule') === name && + scriptNode.getAttribute('data-requirecontext') === context.contextName) { + scriptNode.parentNode.removeChild(scriptNode); + return true; + } + }); + } + } + + function hasPathFallback(id) { + var pathConfig = getOwn(config.paths, id); + if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) { + //Pop off the first array value, since it failed, and + //retry + pathConfig.shift(); + context.require.undef(id); + + //Custom require that does not do map translation, since + //ID is "absolute", already mapped/resolved. + context.makeRequire(null, { + skipMap: true + })([id]); + + return true; + } + } + + //Turns a plugin!resource to [plugin, resource] + //with the plugin being undefined if the name + //did not have a plugin prefix. + function splitPrefix(name) { + var prefix, + index = name ? name.indexOf('!') : -1; + if (index > -1) { + prefix = name.substring(0, index); + name = name.substring(index + 1, name.length); + } + return [prefix, name]; + } + + /** + * Creates a module mapping that includes plugin prefix, module + * name, and path. If parentModuleMap is provided it will + * also normalize the name via require.normalize() + * + * @param {String} name the module name + * @param {String} [parentModuleMap] parent module map + * for the module name, used to resolve relative names. + * @param {Boolean} isNormalized: is the ID already normalized. + * This is true if this call is done for a define() module ID. + * @param {Boolean} applyMap: apply the map config to the ID. + * Should only be true if this map is for a dependency. + * + * @returns {Object} + */ + function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) { + var url, pluginModule, suffix, nameParts, + prefix = null, + parentName = parentModuleMap ? parentModuleMap.name : null, + originalName = name, + isDefine = true, + normalizedName = ''; + + //If no name, then it means it is a require call, generate an + //internal name. + if (!name) { + isDefine = false; + name = '_@r' + (requireCounter += 1); + } + + nameParts = splitPrefix(name); + prefix = nameParts[0]; + name = nameParts[1]; + + if (prefix) { + prefix = normalize(prefix, parentName, applyMap); + pluginModule = getOwn(defined, prefix); + } + + //Account for relative paths if there is a base name. + if (name) { + if (prefix) { + if (pluginModule && pluginModule.normalize) { + //Plugin is loaded, use its normalize method. + normalizedName = pluginModule.normalize(name, function (name) { + return normalize(name, parentName, applyMap); + }); + } else { + // If nested plugin references, then do not try to + // normalize, as it will not normalize correctly. This + // places a restriction on resourceIds, and the longer + // term solution is not to normalize until plugins are + // loaded and all normalizations to allow for async + // loading of a loader plugin. But for now, fixes the + // common uses. Details in #1131 + normalizedName = name.indexOf('!') === -1 ? + normalize(name, parentName, applyMap) : + name; + } + } else { + //A regular module. + normalizedName = normalize(name, parentName, applyMap); + + //Normalized name may be a plugin ID due to map config + //application in normalize. The map config values must + //already be normalized, so do not need to redo that part. + nameParts = splitPrefix(normalizedName); + prefix = nameParts[0]; + normalizedName = nameParts[1]; + isNormalized = true; + + url = context.nameToUrl(normalizedName); + } + } + + //If the id is a plugin id that cannot be determined if it needs + //normalization, stamp it with a unique ID so two matching relative + //ids that may conflict can be separate. + suffix = prefix && !pluginModule && !isNormalized ? + '_unnormalized' + (unnormalizedCounter += 1) : + ''; + + return { + prefix: prefix, + name: normalizedName, + parentMap: parentModuleMap, + unnormalized: !!suffix, + url: url, + originalName: originalName, + isDefine: isDefine, + id: (prefix ? + prefix + '!' + normalizedName : + normalizedName) + suffix + }; + } + + function getModule(depMap) { + var id = depMap.id, + mod = getOwn(registry, id); + + if (!mod) { + mod = registry[id] = new context.Module(depMap); + } + + return mod; + } + + function on(depMap, name, fn) { + var id = depMap.id, + mod = getOwn(registry, id); + + if (hasProp(defined, id) && + (!mod || mod.defineEmitComplete)) { + if (name === 'defined') { + fn(defined[id]); + } + } else { + mod = getModule(depMap); + if (mod.error && name === 'error') { + fn(mod.error); + } else { + mod.on(name, fn); + } + } + } + + function onError(err, errback) { + var ids = err.requireModules, + notified = false; + + if (errback) { + errback(err); + } else { + each(ids, function (id) { + var mod = getOwn(registry, id); + if (mod) { + //Set error on module, so it skips timeout checks. + mod.error = err; + if (mod.events.error) { + notified = true; + mod.emit('error', err); + } + } + }); + + if (!notified) { + req.onError(err); + } + } + } + + /** + * Internal method to transfer globalQueue items to this context's + * defQueue. + */ + function takeGlobalQueue() { + //Push all the globalDefQueue items into the context's defQueue + if (globalDefQueue.length) { + //Array splice in the values since the context code has a + //local var ref to defQueue, so cannot just reassign the one + //on context. + apsp.apply(defQueue, + [defQueue.length, 0].concat(globalDefQueue)); + globalDefQueue = []; + } + } + + handlers = { + 'require': function (mod) { + if (mod.require) { + return mod.require; + } else { + return (mod.require = context.makeRequire(mod.map)); + } + }, + 'exports': function (mod) { + mod.usingExports = true; + if (mod.map.isDefine) { + if (mod.exports) { + return (defined[mod.map.id] = mod.exports); + } else { + return (mod.exports = defined[mod.map.id] = {}); + } + } + }, + 'module': function (mod) { + if (mod.module) { + return mod.module; + } else { + return (mod.module = { + id: mod.map.id, + uri: mod.map.url, + config: function () { + return getOwn(config.config, mod.map.id) || {}; + }, + exports: mod.exports || (mod.exports = {}) + }); + } + } + }; + + function cleanRegistry(id) { + //Clean up machinery used for waiting modules. + delete registry[id]; + delete enabledRegistry[id]; + } + + function breakCycle(mod, traced, processed) { + var id = mod.map.id; + + if (mod.error) { + mod.emit('error', mod.error); + } else { + traced[id] = true; + each(mod.depMaps, function (depMap, i) { + var depId = depMap.id, + dep = getOwn(registry, depId); + + //Only force things that have not completed + //being defined, so still in the registry, + //and only if it has not been matched up + //in the module already. + if (dep && !mod.depMatched[i] && !processed[depId]) { + if (getOwn(traced, depId)) { + mod.defineDep(i, defined[depId]); + mod.check(); //pass false? + } else { + breakCycle(dep, traced, processed); + } + } + }); + processed[id] = true; + } + } + + function checkLoaded() { + var err, usingPathFallback, + waitInterval = config.waitSeconds * 1000, + //It is possible to disable the wait interval by using waitSeconds of 0. + expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(), + noLoads = [], + reqCalls = [], + stillLoading = false, + needCycleCheck = true; + + //Do not bother if this call was a result of a cycle break. + if (inCheckLoaded) { + return; + } + + inCheckLoaded = true; + + //Figure out the state of all the modules. + eachProp(enabledRegistry, function (mod) { + var map = mod.map, + modId = map.id; + + //Skip things that are not enabled or in error state. + if (!mod.enabled) { + return; + } + + if (!map.isDefine) { + reqCalls.push(mod); + } + + if (!mod.error) { + //If the module should be executed, and it has not + //been inited and time is up, remember it. + if (!mod.inited && expired) { + if (hasPathFallback(modId)) { + usingPathFallback = true; + stillLoading = true; + } else { + noLoads.push(modId); + removeScript(modId); + } + } else if (!mod.inited && mod.fetched && map.isDefine) { + stillLoading = true; + if (!map.prefix) { + //No reason to keep looking for unfinished + //loading. If the only stillLoading is a + //plugin resource though, keep going, + //because it may be that a plugin resource + //is waiting on a non-plugin cycle. + return (needCycleCheck = false); + } + } + } + }); + + if (expired && noLoads.length) { + //If wait time expired, throw error of unloaded modules. + err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads); + err.contextName = context.contextName; + return onError(err); + } + + //Not expired, check for a cycle. + if (needCycleCheck) { + each(reqCalls, function (mod) { + breakCycle(mod, {}, {}); + }); + } + + //If still waiting on loads, and the waiting load is something + //other than a plugin resource, or there are still outstanding + //scripts, then just try back later. + if ((!expired || usingPathFallback) && stillLoading) { + //Something is still waiting to load. Wait for it, but only + //if a timeout is not already in effect. + if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) { + checkLoadedTimeoutId = setTimeout(function () { + checkLoadedTimeoutId = 0; + checkLoaded(); + }, 50); + } + } + + inCheckLoaded = false; + } + + Module = function (map) { + this.events = getOwn(undefEvents, map.id) || {}; + this.map = map; + this.shim = getOwn(config.shim, map.id); + this.depExports = []; + this.depMaps = []; + this.depMatched = []; + this.pluginMaps = {}; + this.depCount = 0; + + /* this.exports this.factory + this.depMaps = [], + this.enabled, this.fetched + */ + }; + + Module.prototype = { + init: function (depMaps, factory, errback, options) { + options = options || {}; + + //Do not do more inits if already done. Can happen if there + //are multiple define calls for the same module. That is not + //a normal, common case, but it is also not unexpected. + if (this.inited) { + return; + } + + this.factory = factory; + + if (errback) { + //Register for errors on this module. + this.on('error', errback); + } else if (this.events.error) { + //If no errback already, but there are error listeners + //on this module, set up an errback to pass to the deps. + errback = bind(this, function (err) { + this.emit('error', err); + }); + } + + //Do a copy of the dependency array, so that + //source inputs are not modified. For example + //"shim" deps are passed in here directly, and + //doing a direct modification of the depMaps array + //would affect that config. + this.depMaps = depMaps && depMaps.slice(0); + + this.errback = errback; + + //Indicate this module has be initialized + this.inited = true; + + this.ignore = options.ignore; + + //Could have option to init this module in enabled mode, + //or could have been previously marked as enabled. However, + //the dependencies are not known until init is called. So + //if enabled previously, now trigger dependencies as enabled. + if (options.enabled || this.enabled) { + //Enable this module and dependencies. + //Will call this.check() + this.enable(); + } else { + this.check(); + } + }, + + defineDep: function (i, depExports) { + //Because of cycles, defined callback for a given + //export can be called more than once. + if (!this.depMatched[i]) { + this.depMatched[i] = true; + this.depCount -= 1; + this.depExports[i] = depExports; + } + }, + + fetch: function () { + if (this.fetched) { + return; + } + this.fetched = true; + + context.startTime = (new Date()).getTime(); + + var map = this.map; + + //If the manager is for a plugin managed resource, + //ask the plugin to load it now. + if (this.shim) { + context.makeRequire(this.map, { + enableBuildCallback: true + })(this.shim.deps || [], bind(this, function () { + return map.prefix ? this.callPlugin() : this.load(); + })); + } else { + //Regular dependency. + return map.prefix ? this.callPlugin() : this.load(); + } + }, + + load: function () { + var url = this.map.url; + + //Regular dependency. + if (!urlFetched[url]) { + urlFetched[url] = true; + context.load(this.map.id, url); + } + }, + + /** + * Checks if the module is ready to define itself, and if so, + * define it. + */ + check: function () { + if (!this.enabled || this.enabling) { + return; + } + + var err, cjsModule, + id = this.map.id, + depExports = this.depExports, + exports = this.exports, + factory = this.factory; + + if (!this.inited) { + this.fetch(); + } else if (this.error) { + this.emit('error', this.error); + } else if (!this.defining) { + //The factory could trigger another require call + //that would result in checking this module to + //define itself again. If already in the process + //of doing that, skip this work. + this.defining = true; + + if (this.depCount < 1 && !this.defined) { + if (isFunction(factory)) { + //If there is an error listener, favor passing + //to that instead of throwing an error. However, + //only do it for define()'d modules. require + //errbacks should not be called for failures in + //their callbacks (#699). However if a global + //onError is set, use that. + if ((this.events.error && this.map.isDefine) || + req.onError !== defaultOnError) { + try { + exports = context.execCb(id, factory, depExports, exports); + } catch (e) { + err = e; + } + } else { + exports = context.execCb(id, factory, depExports, exports); + } + + // Favor return value over exports. If node/cjs in play, + // then will not have a return value anyway. Favor + // module.exports assignment over exports object. + if (this.map.isDefine && exports === undefined) { + cjsModule = this.module; + if (cjsModule) { + exports = cjsModule.exports; + } else if (this.usingExports) { + //exports already set the defined value. + exports = this.exports; + } + } + + if (err) { + err.requireMap = this.map; + err.requireModules = this.map.isDefine ? [this.map.id] : null; + err.requireType = this.map.isDefine ? 'define' : 'require'; + return onError((this.error = err)); + } + + } else { + //Just a literal value + exports = factory; + } + + this.exports = exports; + + if (this.map.isDefine && !this.ignore) { + defined[id] = exports; + + if (req.onResourceLoad) { + req.onResourceLoad(context, this.map, this.depMaps); + } + } + + //Clean up + cleanRegistry(id); + + this.defined = true; + } + + //Finished the define stage. Allow calling check again + //to allow define notifications below in the case of a + //cycle. + this.defining = false; + + if (this.defined && !this.defineEmitted) { + this.defineEmitted = true; + this.emit('defined', this.exports); + this.defineEmitComplete = true; + } + + } + }, + + callPlugin: function () { + var map = this.map, + id = map.id, + //Map already normalized the prefix. + pluginMap = makeModuleMap(map.prefix); + + //Mark this as a dependency for this plugin, so it + //can be traced for cycles. + this.depMaps.push(pluginMap); + + on(pluginMap, 'defined', bind(this, function (plugin) { + var load, normalizedMap, normalizedMod, + bundleId = getOwn(bundlesMap, this.map.id), + name = this.map.name, + parentName = this.map.parentMap ? this.map.parentMap.name : null, + localRequire = context.makeRequire(map.parentMap, { + enableBuildCallback: true + }); + + //If current map is not normalized, wait for that + //normalized name to load instead of continuing. + if (this.map.unnormalized) { + //Normalize the ID if the plugin allows it. + if (plugin.normalize) { + name = plugin.normalize(name, function (name) { + return normalize(name, parentName, true); + }) || ''; + } + + //prefix and name should already be normalized, no need + //for applying map config again either. + normalizedMap = makeModuleMap(map.prefix + '!' + name, + this.map.parentMap); + on(normalizedMap, + 'defined', bind(this, function (value) { + this.init([], function () { return value; }, null, { + enabled: true, + ignore: true + }); + })); + + normalizedMod = getOwn(registry, normalizedMap.id); + if (normalizedMod) { + //Mark this as a dependency for this plugin, so it + //can be traced for cycles. + this.depMaps.push(normalizedMap); + + if (this.events.error) { + normalizedMod.on('error', bind(this, function (err) { + this.emit('error', err); + })); + } + normalizedMod.enable(); + } + + return; + } + + //If a paths config, then just load that file instead to + //resolve the plugin, as it is built into that paths layer. + if (bundleId) { + this.map.url = context.nameToUrl(bundleId); + this.load(); + return; + } + + load = bind(this, function (value) { + this.init([], function () { return value; }, null, { + enabled: true + }); + }); + + load.error = bind(this, function (err) { + this.inited = true; + this.error = err; + err.requireModules = [id]; + + //Remove temp unnormalized modules for this module, + //since they will never be resolved otherwise now. + eachProp(registry, function (mod) { + if (mod.map.id.indexOf(id + '_unnormalized') === 0) { + cleanRegistry(mod.map.id); + } + }); + + onError(err); + }); + + //Allow plugins to load other code without having to know the + //context or how to 'complete' the load. + load.fromText = bind(this, function (text, textAlt) { + /*jslint evil: true */ + var moduleName = map.name, + moduleMap = makeModuleMap(moduleName), + hasInteractive = useInteractive; + + //As of 2.1.0, support just passing the text, to reinforce + //fromText only being called once per resource. Still + //support old style of passing moduleName but discard + //that moduleName in favor of the internal ref. + if (textAlt) { + text = textAlt; + } + + //Turn off interactive script matching for IE for any define + //calls in the text, then turn it back on at the end. + if (hasInteractive) { + useInteractive = false; + } + + //Prime the system by creating a module instance for + //it. + getModule(moduleMap); + + //Transfer any config to this other module. + if (hasProp(config.config, id)) { + config.config[moduleName] = config.config[id]; + } + + try { + req.exec(text); + } catch (e) { + return onError(makeError('fromtexteval', + 'fromText eval for ' + id + + ' failed: ' + e, + e, + [id])); + } + + if (hasInteractive) { + useInteractive = true; + } + + //Mark this as a dependency for the plugin + //resource + this.depMaps.push(moduleMap); + + //Support anonymous modules. + context.completeLoad(moduleName); + + //Bind the value of that module to the value for this + //resource ID. + localRequire([moduleName], load); + }); + + //Use parentName here since the plugin's name is not reliable, + //could be some weird string with no path that actually wants to + //reference the parentName's path. + plugin.load(map.name, localRequire, load, config); + })); + + context.enable(pluginMap, this); + this.pluginMaps[pluginMap.id] = pluginMap; + }, + + enable: function () { + enabledRegistry[this.map.id] = this; + this.enabled = true; + + //Set flag mentioning that the module is enabling, + //so that immediate calls to the defined callbacks + //for dependencies do not trigger inadvertent load + //with the depCount still being zero. + this.enabling = true; + + //Enable each dependency + each(this.depMaps, bind(this, function (depMap, i) { + var id, mod, handler; + + if (typeof depMap === 'string') { + //Dependency needs to be converted to a depMap + //and wired up to this module. + depMap = makeModuleMap(depMap, + (this.map.isDefine ? this.map : this.map.parentMap), + false, + !this.skipMap); + this.depMaps[i] = depMap; + + handler = getOwn(handlers, depMap.id); + + if (handler) { + this.depExports[i] = handler(this); + return; + } + + this.depCount += 1; + + on(depMap, 'defined', bind(this, function (depExports) { + this.defineDep(i, depExports); + this.check(); + })); + + if (this.errback) { + on(depMap, 'error', bind(this, this.errback)); + } + } + + id = depMap.id; + mod = registry[id]; + + //Skip special modules like 'require', 'exports', 'module' + //Also, don't call enable if it is already enabled, + //important in circular dependency cases. + if (!hasProp(handlers, id) && mod && !mod.enabled) { + context.enable(depMap, this); + } + })); + + //Enable each plugin that is used in + //a dependency + eachProp(this.pluginMaps, bind(this, function (pluginMap) { + var mod = getOwn(registry, pluginMap.id); + if (mod && !mod.enabled) { + context.enable(pluginMap, this); + } + })); + + this.enabling = false; + + this.check(); + }, + + on: function (name, cb) { + var cbs = this.events[name]; + if (!cbs) { + cbs = this.events[name] = []; + } + cbs.push(cb); + }, + + emit: function (name, evt) { + each(this.events[name], function (cb) { + cb(evt); + }); + if (name === 'error') { + //Now that the error handler was triggered, remove + //the listeners, since this broken Module instance + //can stay around for a while in the registry. + delete this.events[name]; + } + } + }; + + function callGetModule(args) { + //Skip modules already defined. + if (!hasProp(defined, args[0])) { + getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]); + } + } + + function removeListener(node, func, name, ieName) { + //Favor detachEvent because of IE9 + //issue, see attachEvent/addEventListener comment elsewhere + //in this file. + if (node.detachEvent && !isOpera) { + //Probably IE. If not it will throw an error, which will be + //useful to know. + if (ieName) { + node.detachEvent(ieName, func); + } + } else { + node.removeEventListener(name, func, false); + } + } + + /** + * Given an event from a script node, get the requirejs info from it, + * and then removes the event listeners on the node. + * @param {Event} evt + * @returns {Object} + */ + function getScriptData(evt) { + //Using currentTarget instead of target for Firefox 2.0's sake. Not + //all old browsers will be supported, but this one was easy enough + //to support and still makes sense. + var node = evt.currentTarget || evt.srcElement; + + //Remove the listeners once here. + removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange'); + removeListener(node, context.onScriptError, 'error'); + + return { + node: node, + id: node && node.getAttribute('data-requiremodule') + }; + } + + function intakeDefines() { + var args; + + //Any defined modules in the global queue, intake them now. + takeGlobalQueue(); + + //Make sure any remaining defQueue items get properly processed. + while (defQueue.length) { + args = defQueue.shift(); + if (args[0] === null) { + return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1])); + } else { + //args are id, deps, factory. Should be normalized by the + //define() function. + callGetModule(args); + } + } + } + + context = { + config: config, + contextName: contextName, + registry: registry, + defined: defined, + urlFetched: urlFetched, + defQueue: defQueue, + Module: Module, + makeModuleMap: makeModuleMap, + nextTick: req.nextTick, + onError: onError, + + /** + * Set a configuration for the context. + * @param {Object} cfg config object to integrate. + */ + configure: function (cfg) { + //Make sure the baseUrl ends in a slash. + if (cfg.baseUrl) { + if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') { + cfg.baseUrl += '/'; + } + } + + //Save off the paths since they require special processing, + //they are additive. + var shim = config.shim, + objs = { + paths: true, + bundles: true, + config: true, + map: true + }; + + eachProp(cfg, function (value, prop) { + if (objs[prop]) { + if (!config[prop]) { + config[prop] = {}; + } + mixin(config[prop], value, true, true); + } else { + config[prop] = value; + } + }); + + //Reverse map the bundles + if (cfg.bundles) { + eachProp(cfg.bundles, function (value, prop) { + each(value, function (v) { + if (v !== prop) { + bundlesMap[v] = prop; + } + }); + }); + } + + //Merge shim + if (cfg.shim) { + eachProp(cfg.shim, function (value, id) { + //Normalize the structure + if (isArray(value)) { + value = { + deps: value + }; + } + if ((value.exports || value.init) && !value.exportsFn) { + value.exportsFn = context.makeShimExports(value); + } + shim[id] = value; + }); + config.shim = shim; + } + + //Adjust packages if necessary. + if (cfg.packages) { + each(cfg.packages, function (pkgObj) { + var location, name; + + pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj; + + name = pkgObj.name; + location = pkgObj.location; + if (location) { + config.paths[name] = pkgObj.location; + } + + //Save pointer to main module ID for pkg name. + //Remove leading dot in main, so main paths are normalized, + //and remove any trailing .js, since different package + //envs have different conventions: some use a module name, + //some use a file name. + config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main') + .replace(currDirRegExp, '') + .replace(jsSuffixRegExp, ''); + }); + } + + //If there are any "waiting to execute" modules in the registry, + //update the maps for them, since their info, like URLs to load, + //may have changed. + eachProp(registry, function (mod, id) { + //If module already has init called, since it is too + //late to modify them, and ignore unnormalized ones + //since they are transient. + if (!mod.inited && !mod.map.unnormalized) { + mod.map = makeModuleMap(id); + } + }); + + //If a deps array or a config callback is specified, then call + //require with those args. This is useful when require is defined as a + //config object before require.js is loaded. + if (cfg.deps || cfg.callback) { + context.require(cfg.deps || [], cfg.callback); + } + }, + + makeShimExports: function (value) { + function fn() { + var ret; + if (value.init) { + ret = value.init.apply(global, arguments); + } + return ret || (value.exports && getGlobal(value.exports)); + } + return fn; + }, + + makeRequire: function (relMap, options) { + options = options || {}; + + function localRequire(deps, callback, errback) { + var id, map, requireMod; + + if (options.enableBuildCallback && callback && isFunction(callback)) { + callback.__requireJsBuild = true; + } + + if (typeof deps === 'string') { + if (isFunction(callback)) { + //Invalid call + return onError(makeError('requireargs', 'Invalid require call'), errback); + } + + //If require|exports|module are requested, get the + //value for them from the special handlers. Caveat: + //this only works while module is being defined. + if (relMap && hasProp(handlers, deps)) { + return handlers[deps](registry[relMap.id]); + } + + //Synchronous access to one module. If require.get is + //available (as in the Node adapter), prefer that. + if (req.get) { + return req.get(context, deps, relMap, localRequire); + } + + //Normalize module name, if it contains . or .. + map = makeModuleMap(deps, relMap, false, true); + id = map.id; + + if (!hasProp(defined, id)) { + return onError(makeError('notloaded', 'Module name "' + + id + + '" has not been loaded yet for context: ' + + contextName + + (relMap ? '' : '. Use require([])'))); + } + return defined[id]; + } + + //Grab defines waiting in the global queue. + intakeDefines(); + + //Mark all the dependencies as needing to be loaded. + context.nextTick(function () { + //Some defines could have been added since the + //require call, collect them. + intakeDefines(); + + requireMod = getModule(makeModuleMap(null, relMap)); + + //Store if map config should be applied to this require + //call for dependencies. + requireMod.skipMap = options.skipMap; + + requireMod.init(deps, callback, errback, { + enabled: true + }); + + checkLoaded(); + }); + + return localRequire; + } + + mixin(localRequire, { + isBrowser: isBrowser, + + /** + * Converts a module name + .extension into an URL path. + * *Requires* the use of a module name. It does not support using + * plain URLs like nameToUrl. + */ + toUrl: function (moduleNamePlusExt) { + var ext, + index = moduleNamePlusExt.lastIndexOf('.'), + segment = moduleNamePlusExt.split('/')[0], + isRelative = segment === '.' || segment === '..'; + + //Have a file extension alias, and it is not the + //dots from a relative path. + if (index !== -1 && (!isRelative || index > 1)) { + ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length); + moduleNamePlusExt = moduleNamePlusExt.substring(0, index); + } + + return context.nameToUrl(normalize(moduleNamePlusExt, + relMap && relMap.id, true), ext, true); + }, + + defined: function (id) { + return hasProp(defined, makeModuleMap(id, relMap, false, true).id); + }, + + specified: function (id) { + id = makeModuleMap(id, relMap, false, true).id; + return hasProp(defined, id) || hasProp(registry, id); + } + }); + + //Only allow undef on top level require calls + if (!relMap) { + localRequire.undef = function (id) { + //Bind any waiting define() calls to this context, + //fix for #408 + takeGlobalQueue(); + + var map = makeModuleMap(id, relMap, true), + mod = getOwn(registry, id); + + removeScript(id); + + delete defined[id]; + delete urlFetched[map.url]; + delete undefEvents[id]; + + //Clean queued defines too. Go backwards + //in array so that the splices do not + //mess up the iteration. + eachReverse(defQueue, function(args, i) { + if(args[0] === id) { + defQueue.splice(i, 1); + } + }); + + if (mod) { + //Hold on to listeners in case the + //module will be attempted to be reloaded + //using a different config. + if (mod.events.defined) { + undefEvents[id] = mod.events; + } + + cleanRegistry(id); + } + }; + } + + return localRequire; + }, + + /** + * Called to enable a module if it is still in the registry + * awaiting enablement. A second arg, parent, the parent module, + * is passed in for context, when this method is overridden by + * the optimizer. Not shown here to keep code compact. + */ + enable: function (depMap) { + var mod = getOwn(registry, depMap.id); + if (mod) { + getModule(depMap).enable(); + } + }, + + /** + * Internal method used by environment adapters to complete a load event. + * A load event could be a script load or just a load pass from a synchronous + * load call. + * @param {String} moduleName the name of the module to potentially complete. + */ + completeLoad: function (moduleName) { + var found, args, mod, + shim = getOwn(config.shim, moduleName) || {}, + shExports = shim.exports; + + takeGlobalQueue(); + + while (defQueue.length) { + args = defQueue.shift(); + if (args[0] === null) { + args[0] = moduleName; + //If already found an anonymous module and bound it + //to this name, then this is some other anon module + //waiting for its completeLoad to fire. + if (found) { + break; + } + found = true; + } else if (args[0] === moduleName) { + //Found matching define call for this script! + found = true; + } + + callGetModule(args); + } + + //Do this after the cycle of callGetModule in case the result + //of those calls/init calls changes the registry. + mod = getOwn(registry, moduleName); + + if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) { + if (config.enforceDefine && (!shExports || !getGlobal(shExports))) { + if (hasPathFallback(moduleName)) { + return; + } else { + return onError(makeError('nodefine', + 'No define call for ' + moduleName, + null, + [moduleName])); + } + } else { + //A script that does not call define(), so just simulate + //the call for it. + callGetModule([moduleName, (shim.deps || []), shim.exportsFn]); + } + } + + checkLoaded(); + }, + + /** + * Converts a module name to a file path. Supports cases where + * moduleName may actually be just an URL. + * Note that it **does not** call normalize on the moduleName, + * it is assumed to have already been normalized. This is an + * internal API, not a public one. Use toUrl for the public API. + */ + nameToUrl: function (moduleName, ext, skipExt) { + var paths, syms, i, parentModule, url, + parentPath, bundleId, + pkgMain = getOwn(config.pkgs, moduleName); + + if (pkgMain) { + moduleName = pkgMain; + } + + bundleId = getOwn(bundlesMap, moduleName); + + if (bundleId) { + return context.nameToUrl(bundleId, ext, skipExt); + } + + //If a colon is in the URL, it indicates a protocol is used and it is just + //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?) + //or ends with .js, then assume the user meant to use an url and not a module id. + //The slash is important for protocol-less URLs as well as full paths. + if (req.jsExtRegExp.test(moduleName)) { + //Just a plain path, not module name lookup, so just return it. + //Add extension if it is included. This is a bit wonky, only non-.js things pass + //an extension, this method probably needs to be reworked. + url = moduleName + (ext || ''); + } else { + //A module that needs to be converted to a path. + paths = config.paths; + + syms = moduleName.split('/'); + //For each module name segment, see if there is a path + //registered for it. Start with most specific name + //and work up from it. + for (i = syms.length; i > 0; i -= 1) { + parentModule = syms.slice(0, i).join('/'); + + parentPath = getOwn(paths, parentModule); + if (parentPath) { + //If an array, it means there are a few choices, + //Choose the one that is desired + if (isArray(parentPath)) { + parentPath = parentPath[0]; + } + syms.splice(0, i, parentPath); + break; + } + } + + //Join the path parts together, then figure out if baseUrl is needed. + url = syms.join('/'); + url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js')); + url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url; + } + + return config.urlArgs ? url + + ((url.indexOf('?') === -1 ? '?' : '&') + + config.urlArgs) : url; + }, + + //Delegates to req.load. Broken out as a separate function to + //allow overriding in the optimizer. + load: function (id, url) { + req.load(context, id, url); + }, + + /** + * Executes a module callback function. Broken out as a separate function + * solely to allow the build system to sequence the files in the built + * layer in the right sequence. + * + * @private + */ + execCb: function (name, callback, args, exports) { + return callback.apply(exports, args); + }, + + /** + * callback for script loads, used to check status of loading. + * + * @param {Event} evt the event from the browser for the script + * that was loaded. + */ + onScriptLoad: function (evt) { + //Using currentTarget instead of target for Firefox 2.0's sake. Not + //all old browsers will be supported, but this one was easy enough + //to support and still makes sense. + if (evt.type === 'load' || + (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) { + //Reset interactive script so a script node is not held onto for + //to long. + interactiveScript = null; + + //Pull out the name of the module and the context. + var data = getScriptData(evt); + context.completeLoad(data.id); + } + }, + + /** + * Callback for script errors. + */ + onScriptError: function (evt) { + var data = getScriptData(evt); + if (!hasPathFallback(data.id)) { + return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id])); + } + } + }; + + context.require = context.makeRequire(); + return context; + } + + /** + * Main entry point. + * + * If the only argument to require is a string, then the module that + * is represented by that string is fetched for the appropriate context. + * + * If the first argument is an array, then it will be treated as an array + * of dependency string names to fetch. An optional function callback can + * be specified to execute when all of those dependencies are available. + * + * Make a local req variable to help Caja compliance (it assumes things + * on a require that are not standardized), and to give a short + * name for minification/local scope use. + */ + req = requirejs = function (deps, callback, errback, optional) { + + //Find the right context, use default + var context, config, + contextName = defContextName; + + // Determine if have config object in the call. + if (!isArray(deps) && typeof deps !== 'string') { + // deps is a config object + config = deps; + if (isArray(callback)) { + // Adjust args if there are dependencies + deps = callback; + callback = errback; + errback = optional; + } else { + deps = []; + } + } + + if (config && config.context) { + contextName = config.context; + } + + context = getOwn(contexts, contextName); + if (!context) { + context = contexts[contextName] = req.s.newContext(contextName); + } + + if (config) { + context.configure(config); + } + + return context.require(deps, callback, errback); + }; + + /** + * Support require.config() to make it easier to cooperate with other + * AMD loaders on globally agreed names. + */ + req.config = function (config) { + return req(config); + }; + + /** + * Execute something after the current tick + * of the event loop. Override for other envs + * that have a better solution than setTimeout. + * @param {Function} fn function to execute later. + */ + req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) { + setTimeout(fn, 4); + } : function (fn) { fn(); }; + + /** + * Export require as a global, but only if it does not already exist. + */ + if (!require) { + require = req; + } + + req.version = version; + + //Used to filter out dependencies that are already paths. + req.jsExtRegExp = /^\/|:|\?|\.js$/; + req.isBrowser = isBrowser; + s = req.s = { + contexts: contexts, + newContext: newContext + }; + + //Create default context. + req({}); + + //Exports some context-sensitive methods on global require. + each([ + 'toUrl', + 'undef', + 'defined', + 'specified' + ], function (prop) { + //Reference from contexts instead of early binding to default context, + //so that during builds, the latest instance of the default context + //with its config gets used. + req[prop] = function () { + var ctx = contexts[defContextName]; + return ctx.require[prop].apply(ctx, arguments); + }; + }); + + if (isBrowser) { + head = s.head = document.getElementsByTagName('head')[0]; + //If BASE tag is in play, using appendChild is a problem for IE6. + //When that browser dies, this can be removed. Details in this jQuery bug: + //http://dev.jquery.com/ticket/2709 + baseElement = document.getElementsByTagName('base')[0]; + if (baseElement) { + head = s.head = baseElement.parentNode; + } + } + + /** + * Any errors that require explicitly generates will be passed to this + * function. Intercept/override it if you want custom error handling. + * @param {Error} err the error object. + */ + req.onError = defaultOnError; + + /** + * Creates the node for the load command. Only used in browser envs. + */ + req.createNode = function (config, moduleName, url) { + var node = config.xhtml ? + document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') : + document.createElement('script'); + node.type = config.scriptType || 'text/javascript'; + node.charset = 'utf-8'; + node.async = true; + return node; + }; + + /** + * Does the request to load a module for the browser case. + * Make this a separate function to allow other environments + * to override it. + * + * @param {Object} context the require context to find state. + * @param {String} moduleName the name of the module. + * @param {Object} url the URL to the module. + */ + req.load = function (context, moduleName, url) { + var config = (context && context.config) || {}, + node; + if (isBrowser) { + //In the browser so use a script tag + node = req.createNode(config, moduleName, url); + + node.setAttribute('data-requirecontext', context.contextName); + node.setAttribute('data-requiremodule', moduleName); + + //Set up load listener. Test attachEvent first because IE9 has + //a subtle issue in its addEventListener and script onload firings + //that do not match the behavior of all other browsers with + //addEventListener support, which fire the onload event for a + //script right after the script execution. See: + //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution + //UNFORTUNATELY Opera implements attachEvent but does not follow the script + //script execution mode. + if (node.attachEvent && + //Check if node.attachEvent is artificially added by custom script or + //natively supported by browser + //read https://github.com/jrburke/requirejs/issues/187 + //if we can NOT find [native code] then it must NOT natively supported. + //in IE8, node.attachEvent does not have toString() + //Note the test for "[native code" with no closing brace, see: + //https://github.com/jrburke/requirejs/issues/273 + !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && + !isOpera) { + //Probably IE. IE (at least 6-8) do not fire + //script onload right after executing the script, so + //we cannot tie the anonymous define call to a name. + //However, IE reports the script as being in 'interactive' + //readyState at the time of the define call. + useInteractive = true; + + node.attachEvent('onreadystatechange', context.onScriptLoad); + //It would be great to add an error handler here to catch + //404s in IE9+. However, onreadystatechange will fire before + //the error handler, so that does not help. If addEventListener + //is used, then IE will fire error before load, but we cannot + //use that pathway given the connect.microsoft.com issue + //mentioned above about not doing the 'script execute, + //then fire the script load event listener before execute + //next script' that other browsers do. + //Best hope: IE10 fixes the issues, + //and then destroys all installs of IE 6-9. + //node.attachEvent('onerror', context.onScriptError); + } else { + node.addEventListener('load', context.onScriptLoad, false); + node.addEventListener('error', context.onScriptError, false); + } + node.src = url; + + //For some cache cases in IE 6-8, the script executes before the end + //of the appendChild execution, so to tie an anonymous define + //call to the module name (which is stored on the node), hold on + //to a reference to this node, but clear after the DOM insertion. + currentlyAddingScript = node; + if (baseElement) { + head.insertBefore(node, baseElement); + } else { + head.appendChild(node); + } + currentlyAddingScript = null; + + return node; + } else if (isWebWorker) { + try { + //In a web worker, use importScripts. This is not a very + //efficient use of importScripts, importScripts will block until + //its script is downloaded and evaluated. However, if web workers + //are in play, the expectation that a build has been done so that + //only one script needs to be loaded anyway. This may need to be + //reevaluated if other use cases become common. + importScripts(url); + + //Account for anonymous modules + context.completeLoad(moduleName); + } catch (e) { + context.onError(makeError('importscripts', + 'importScripts failed for ' + + moduleName + ' at ' + url, + e, + [moduleName])); + } + } + }; + + function getInteractiveScript() { + if (interactiveScript && interactiveScript.readyState === 'interactive') { + return interactiveScript; + } + + eachReverse(scripts(), function (script) { + if (script.readyState === 'interactive') { + return (interactiveScript = script); + } + }); + return interactiveScript; + } + + //Look for a data-main script attribute, which could also adjust the baseUrl. + if (isBrowser && !cfg.skipDataMain) { + //Figure out baseUrl. Get it from the script tag with require.js in it. + eachReverse(scripts(), function (script) { + //Set the 'head' where we can append children by + //using the script's parent. + if (!head) { + head = script.parentNode; + } + + //Look for a data-main attribute to set main script for the page + //to load. If it is there, the path to data main becomes the + //baseUrl, if it is not already set. + dataMain = script.getAttribute('data-main'); + if (dataMain) { + //Preserve dataMain in case it is a path (i.e. contains '?') + mainScript = dataMain; + + //Set final baseUrl if there is not already an explicit one. + if (!cfg.baseUrl) { + //Pull off the directory of data-main for use as the + //baseUrl. + src = mainScript.split('/'); + mainScript = src.pop(); + subPath = src.length ? src.join('/') + '/' : './'; + + cfg.baseUrl = subPath; + } + + //Strip off any trailing .js since mainScript is now + //like a module name. + mainScript = mainScript.replace(jsSuffixRegExp, ''); + + //If mainScript is still a path, fall back to dataMain + if (req.jsExtRegExp.test(mainScript)) { + mainScript = dataMain; + } + + //Put the data-main script in the files to load. + cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript]; + + return true; + } + }); + } + + /** + * The function that handles definitions of modules. Differs from + * require() in that a string for the module should be the first argument, + * and the function to execute after dependencies are loaded should + * return a value to define the module corresponding to the first argument's + * name. + */ + define = function (name, deps, callback) { + var node, context; + + //Allow for anonymous modules + if (typeof name !== 'string') { + //Adjust args appropriately + callback = deps; + deps = name; + name = null; + } + + //This module may not have dependencies + if (!isArray(deps)) { + callback = deps; + deps = null; + } + + //If no name, and callback is a function, then figure out if it a + //CommonJS thing with dependencies. + if (!deps && isFunction(callback)) { + deps = []; + //Remove comments from the callback string, + //look for require calls, and pull them into the dependencies, + //but only if there are function args. + if (callback.length) { + callback + .toString() + .replace(commentRegExp, '') + .replace(cjsRequireRegExp, function (match, dep) { + deps.push(dep); + }); + + //May be a CommonJS thing even without require calls, but still + //could use exports, and module. Avoid doing exports and module + //work though if it just needs require. + //REQUIRES the function to expect the CommonJS variables in the + //order listed below. + deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps); + } + } + + //If in IE 6-8 and hit an anonymous define() call, do the interactive + //work. + if (useInteractive) { + node = currentlyAddingScript || getInteractiveScript(); + if (node) { + if (!name) { + name = node.getAttribute('data-requiremodule'); + } + context = contexts[node.getAttribute('data-requirecontext')]; + } + } + + //Always save off evaluating the def call until the script onload handler. + //This allows multiple modules to be in a file without prematurely + //tracing dependencies, and allows for anonymous module support, + //where the module name is not known until the script onload event + //occurs. If no context, use the global queue, and get it processed + //in the onscript load callback. + (context ? context.defQueue : globalDefQueue).push([name, deps, callback]); + }; + + define.amd = { + jQuery: true + }; + + + /** + * Executes the text. Normally just uses eval, but can be modified + * to use a better, environment-specific call. Only used for transpiling + * loader plugins, not for plain JS modules. + * @param {String} text the text to execute/evaluate. + */ + req.exec = function (text) { + /*jslint evil: true */ + return eval(text); + }; + + //Set up with config info. + req(cfg); +}(this)); + +var require_config = { + baseUrl: 'frameworks/cocos2d-html5/modules', + + paths: { + root: '../', + cocos2d: '../cocos2d', + game: '../../../src' + }, + + shim: { + "cocos2d/core/platform/CCSAXParser" : [ + "cocos2d/core/platform/CCClass" + ], + "cocos2d/core/platform/CCTypes" : [ + "cocos2d/core/platform/CCClass" + ], + "cocos2d/core/CCScheduler" : [ + "cocos2d/core/platform/CCClass" + ], + "cocos2d/core/event-manager/CCEventListener" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/platform/CCConfig" : [ + "cocos2d/core/cocoa/CCGeometry" + ], + "cocos2d/core/platform/CCVisibleRect" : [ + "cocos2d/core/cocoa/CCGeometry" + ], + "cocos2d/core/platform/CCInputManager" : [ + "cocos2d/core/cocoa/CCGeometry" + ], + "cocos2d/core/textures/CCTexture2D" : [ + "cocos2d/core/textures/TexturesWebGL", + "cocos2d/core/textures/TexturesPropertyDefine" + ], + "cocos2d/core/textures/CCTextureAtlas" : [ + "cocos2d/core/textures/TexturesWebGL", + "cocos2d/core/textures/TexturesPropertyDefine" + ], + "cocos2d/core/CCDirector" : [ + "cocos2d/core/CCDirectorWebGL" + ], + "cocos2d/core/platform/CCInputExtension" : [ + "cocos2d/core/platform/CCInputManager" + ], + "cocos2d/core/textures/CCTexture2D": [ + "cocos2d/core/textures/TexturesWebGL", + "cocos2d/core/textures/TexturesPropertyDefine" + ], + "cocos2d/core/textures/CCTextureAtlas": [ + "cocos2d/core/textures/TexturesWebGL", + "cocos2d/core/textures/TexturesPropertyDefine" + ], + "cocos2d/core/textures/CCTextureCache": [ + "cocos2d/core/textures/TexturesWebGL", + "cocos2d/core/textures/TexturesPropertyDefine" + ], + "cocos2d/core/event-manager/CCEventExtension": [ + "cocos2d/core/event-manager/CCEvent", + "cocos2d/core/event-manager/CCEventListener" + ], + "cocos2d/core/event-manager/CCEventManager": [ + "cocos2d/core/event-manager/CCEvent", + "cocos2d/core/event-manager/CCEventListener" + ], + "cocos2d/kazmath/gl/matrix" : [ + "cocos2d/kazmath/utility", + "cocos2d/kazmath/vec2", + "cocos2d/kazmath/vec3", + "cocos2d/kazmath/vec4", + "cocos2d/kazmath/ray2", + "cocos2d/kazmath/mat3", + "cocos2d/kazmath/mat4", + "cocos2d/kazmath/plane", + "cocos2d/kazmath/quaternion", + "cocos2d/kazmath/aabb", + "cocos2d/kazmath/gl/mat4stack" + ], + + "cocos2d/core/base-nodes/CCNode" : [ + "core", + "cocos2d/core/base-nodes/BaseNodesWebGL", + "cocos2d/core/base-nodes/BaseNodesPropertyDefine" + ], + + "cocos2d/core/scenes/CCScene" : [ + "core", + "cocos2d/core/base-nodes/CCNode" + ], + + "cocos2d/core/sprites/CCSprite" : [ + "core", + "cocos2d/core/base-nodes/CCNode", + "cocos2d/core/sprites/SpritesWebGL", + "cocos2d/core/sprites/SpritesPropertyDefine" + ], + + "cocos2d/core/sprites/CCBakeSprite" : [ + "cocos2d/core/sprites/CCSprite" + ], + + "cocos2d/core/layers/CCLayer" : [ + "core", + "cocos2d/core/sprites/CCBakeSprite", + "cocos2d/core/layers/CCLayerWebGL", + "cocos2d/core/layers/CCLayerPropertyDefine" + ], + + "cocos2d/core/labelttf/CCLabelTTF" : [ + "cocos2d/core/sprites/CCSprite", + "cocos2d/core/labelttf/LabelTTFWebGL", + "cocos2d/core/labelttf/LabelTTFPropertyDefine" + ], + + "cocos2d/core/scenes/CCLoaderScene" : [ + "core", + "cocos2d/core/layers/CCLayer", + "cocos2d/core/labelttf/CCLabelTTF", + "cocos2d/core/scenes/CCScene" + ], + + "cocos2d/menus/CCMenu" : [ + "cocos2d/core/layers/CCLayer" + ], + + "cocos2d/menus/CCMenuItem" : [ + "cocos2d/core/base-nodes/CCNode" + ], + + "cocos2d/core/sprites/CCSpriteBatchNode" : [ + "cocos2d/core/sprites/CCSprite" + ], + + "cocos2d/core/actions/CCAction" : [ + "core" + ], + "cocos2d/core/actions/CCActionInterval" : [ + "cocos2d/core/actions/CCAction" + ], + "cocos2d/core/actions/CCActionInstant" : [ + "cocos2d/core/actions/CCAction" + ], + + "core" : { + deps: [ + "root/CCDebugger", + "cocos2d/core/utils/BinaryLoader", + "root/Base64Images", + "cocos2d/core/platform/CCClass", + "cocos2d/core/platform/CCCommon", + "cocos2d/core/cocoa/CCGeometry", + "cocos2d/core/platform/CCSAXParser", + "cocos2d/core/platform/CCLoaders", + "cocos2d/core/platform/CCConfig", + "cocos2d/core/platform/miniFramework", + "cocos2d/core/platform/CCMacro", + "cocos2d/core/platform/CCTypesWebGL", + "cocos2d/core/platform/CCTypesPropertyDefine", + "cocos2d/core/platform/CCTypes", + "cocos2d/core/platform/CCEGLView", + "cocos2d/core/platform/CCScreen", + "cocos2d/core/platform/CCVisibleRect", + + "cocos2d/core/platform/CCInputManager", + "cocos2d/core/platform/CCInputExtension", + + "cocos2d/core/cocoa/CCAffineTransform", + "cocos2d/core/support/CCPointExtension", + "cocos2d/core/support/CCVertex", + "cocos2d/core/support/TransformUtils", + "cocos2d/core/event-manager/CCTouch", + + "cocos2d/core/event-manager/CCEvent", + "cocos2d/core/event-manager/CCEventListener", + "cocos2d/core/event-manager/CCEventManager", + "cocos2d/core/event-manager/CCEventExtension", + + "cocos2d/core/CCConfiguration", + + "cocos2d/core/CCDirector", + + "cocos2d/core/CCCamera", + "cocos2d/core/CCScheduler", + + "cocos2d/core/CCActionManager", + + "cocos2d/core/CCDrawingPrimitivesCanvas", + "cocos2d/core/CCDrawingPrimitivesWebGL", + + "cocos2d/core/textures/CCTexture2D", + "cocos2d/core/textures/CCTextureAtlas", + "cocos2d/core/textures/CCTextureCache", + + "cocos2d/kazmath/utility", + "cocos2d/kazmath/vec2", + "cocos2d/kazmath/vec3", + "cocos2d/kazmath/vec4", + "cocos2d/kazmath/ray2", + "cocos2d/kazmath/mat3", + "cocos2d/kazmath/mat4", + "cocos2d/kazmath/plane", + "cocos2d/kazmath/quaternion", + "cocos2d/kazmath/aabb", + "cocos2d/kazmath/gl/mat4stack", + "cocos2d/kazmath/gl/matrix", + + "cocos2d/shaders/CCShaders", + "cocos2d/shaders/CCShaderCache", + "cocos2d/shaders/CCGLProgram", + "cocos2d/shaders/CCGLStateCache" + ], + exports: "cc" + }, + + "NodeAtlas" : { + deps: [ + "Node", + "cocos2d/core/base-nodes/CCAtlasNode" + ], + init: function() { + return cc.NodeAtlas; + } + }, + + "AnimationFrame" : { + deps: [ + "core", + "Sprite", + "cocos2d/core/sprites/CCAnimation" + ], + init: function() { + return cc.AnimationFrame; + } + }, + + "Animation" : { + deps: [ + "Sprite", + "cocos2d/core/sprites/CCAnimation" + ], + init: function() { + return cc.Animation; + } + }, + + "animationCache" : { + deps: [ + "Sprite", + "Animation", + "cocos2d/core/sprites/CCAnimationCache" + ], + init: function() { + return cc.animationCache; + } + }, + + "SpriteFrame" : { + deps: [ + "Sprite", + "cocos2d/core/sprites/CCSpriteFrame" + ], + init: function() { + return cc.SpriteFrame; + } + }, + + "spriteFrameCache" : { + deps: [ + "SpriteFrame", + "cocos2d/core/sprites/CCSpriteFrameCache" + ], + init: function() { + return cc.spriteFrameCache; + } + }, + + "cocos2d/actions/CCActionCamera" : { + deps: [ + "core", + "cocos2d/core/actions/CCAction", + "cocos2d/core/actions/CCActionInterval" + ], + exports: "cc" + }, + "cocos2d/actions/CCActionEase" : { + deps: [ + "core", + "cocos2d/core/actions/CCAction", + "cocos2d/core/actions/CCActionInterval" + ], + exports: "cc" + }, + "cocos2d/actions/CCActionCatmullRom" : { + deps: [ + "core", + "cocos2d/core/actions/CCAction", + "cocos2d/core/actions/CCActionInterval" + ], + exports: "cc" + }, + "cocos2d/actions/CCActionTween" : { + deps: [ + "core", + "cocos2d/core/actions/CCAction", + "cocos2d/core/actions/CCActionInterval" + ], + exports: "cc" + } + } +}; \ No newline at end of file From 8816ea68b937f9608d4a2e47f136b42c0d788e63 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 13 Sep 2014 18:27:07 +0800 Subject: [PATCH 02/32] Feature #5929: Enable loading with require.js --- CCBoot.js | 24 +++++++++++++----------- moduleConfig.json | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index a7600d98cf..43caefd92e 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -65,7 +65,7 @@ cc._addEventListener = function (element, type, listener, useCapture) { }; //is nodejs ? Used to support node-webkit. -cc._isNodeJs = typeof require !== 'undefined' && require("fs"); +//cc._isNodeJs = typeof require !== 'undefined' && require("fs"); /** * Iterate over an object or an array, executing a function for each matched element. @@ -2129,11 +2129,12 @@ cc.game = /** @lends cc.game# */{ var jsList = config[CONFIG_KEY.jsList] || []; if (cc.Class) {//is single file //load user's jsList only - loader.loadJsWithImg("", jsList, function (err) { - if (err) throw err; - self._prepared = true; - if (cb) cb(); - }); +// loader.loadJsWithImg("", jsList, function (err) { +// if (err) throw err; +// self._prepared = true; +// if (cb) cb(); +// }); + cb(); } else { //load cc's jsList first var ccModulesPath = cc.path.join(engineDir, "moduleConfig.json"); @@ -2149,11 +2150,12 @@ cc.game = /** @lends cc.game# */{ if (arr) newJsList = newJsList.concat(arr); } newJsList = newJsList.concat(jsList); - cc.loader.loadJsWithImg(newJsList, function (err) { - if (err) throw err; - self._prepared = true; - if (cb) cb(); - }); +// cc.loader.loadJsWithImg(newJsList, function (err) { +// if (err) throw err; +// self._prepared = true; +// if (cb) cb(); +// }); + cb(); }); } } diff --git a/moduleConfig.json b/moduleConfig.json index 1f8693b00b..15dcc43d29 100644 --- a/moduleConfig.json +++ b/moduleConfig.json @@ -70,6 +70,16 @@ "cocos2d/core/event-manager/CCEventManager.js", "cocos2d/core/event-manager/CCEventExtension.js", + "cocos2d/core/CCConfiguration.js", + + "cocos2d/core/CCDirectorWebGL.js", + "cocos2d/core/CCDirector.js", + + "cocos2d/core/CCCamera.js", + "cocos2d/core/CCScheduler.js", + + "cocos2d/core/CCActionManager.js", + "cocos2d/core/base-nodes/BaseNodesWebGL.js", "cocos2d/core/base-nodes/BaseNodesPropertyDefine.js", "cocos2d/core/base-nodes/CCNode.js", @@ -97,21 +107,13 @@ "cocos2d/core/sprites/CCAnimationCache.js", "cocos2d/core/sprites/CCSpriteFrame.js", "cocos2d/core/sprites/CCSpriteFrameCache.js", - "cocos2d/core/CCConfiguration.js", - - "cocos2d/core/CCDirectorWebGL.js", - "cocos2d/core/CCDirector.js", - "cocos2d/core/CCCamera.js", - "cocos2d/core/CCScheduler.js", "cocos2d/core/CCDrawingPrimitivesCanvas.js", "cocos2d/core/CCDrawingPrimitivesWebGL.js", "cocos2d/core/labelttf/LabelTTFWebGL.js", "cocos2d/core/labelttf/LabelTTFPropertyDefine.js", - "cocos2d/core/labelttf/CCLabelTTF.js", - - "cocos2d/core/CCActionManager.js" + "cocos2d/core/labelttf/CCLabelTTF.js" ], "effects" : [ "core", From 1f84b94dbb7ce2d585eff5c41cdaa6b3f49decbd Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 13 Sep 2014 18:27:27 +0800 Subject: [PATCH 03/32] Feature #5929: Add module configurations --- modules/LabelTTF.js | 6 ++++++ modules/LoaderScene.js | 5 +++++ modules/Menu.js | 7 +++++++ modules/Node.js | 6 ++++++ modules/Scene.js | 5 +++++ modules/Sprite.js | 5 +++++ modules/SpriteBatchNode.js | 5 +++++ modules/actions.js | 8 ++++++++ modules/core.js | 3 +++ modules/layers.js | 6 ++++++ modules/menuitems.js | 8 ++++++++ 11 files changed, 64 insertions(+) create mode 100644 modules/LabelTTF.js create mode 100644 modules/LoaderScene.js create mode 100644 modules/Menu.js create mode 100644 modules/Node.js create mode 100644 modules/Scene.js create mode 100644 modules/Sprite.js create mode 100644 modules/SpriteBatchNode.js create mode 100644 modules/actions.js create mode 100644 modules/core.js create mode 100644 modules/layers.js create mode 100644 modules/menuitems.js diff --git a/modules/LabelTTF.js b/modules/LabelTTF.js new file mode 100644 index 0000000000..b357c700cf --- /dev/null +++ b/modules/LabelTTF.js @@ -0,0 +1,6 @@ +define([ + "Sprite", + "cocos2d/core/labelttf/CCLabelTTF" +], function() { + return cc.LabelTTF; +}); \ No newline at end of file diff --git a/modules/LoaderScene.js b/modules/LoaderScene.js new file mode 100644 index 0000000000..7847655b11 --- /dev/null +++ b/modules/LoaderScene.js @@ -0,0 +1,5 @@ +define([ + "cocos2d/core/scenes/CCLoaderScene" +], function() { + return cc.LoaderScene; +}); \ No newline at end of file diff --git a/modules/Menu.js b/modules/Menu.js new file mode 100644 index 0000000000..922d0512ef --- /dev/null +++ b/modules/Menu.js @@ -0,0 +1,7 @@ +define([ + "core", + "actions", + "cocos2d/menus/CCMenu" +], function() { + return cc.Menu; +}); \ No newline at end of file diff --git a/modules/Node.js b/modules/Node.js new file mode 100644 index 0000000000..0e8dc4176e --- /dev/null +++ b/modules/Node.js @@ -0,0 +1,6 @@ +define([ + "core", + "cocos2d/core/base-nodes/CCNode" +], function() { + return cc.Node; +}); \ No newline at end of file diff --git a/modules/Scene.js b/modules/Scene.js new file mode 100644 index 0000000000..bdd1bff91f --- /dev/null +++ b/modules/Scene.js @@ -0,0 +1,5 @@ +define([ + "cocos2d/core/scenes/CCScene" +], function() { + return cc.Scene; +}); \ No newline at end of file diff --git a/modules/Sprite.js b/modules/Sprite.js new file mode 100644 index 0000000000..80596dc8aa --- /dev/null +++ b/modules/Sprite.js @@ -0,0 +1,5 @@ +define([ + "cocos2d/core/sprites/CCSprite" +], function() { + return cc.Sprite; +}); \ No newline at end of file diff --git a/modules/SpriteBatchNode.js b/modules/SpriteBatchNode.js new file mode 100644 index 0000000000..c4f92bc94d --- /dev/null +++ b/modules/SpriteBatchNode.js @@ -0,0 +1,5 @@ +define([ + "cocos2d/core/sprites/CCSpriteBatchNode" +], function() { + return cc.SpriteBatchNode; +}); \ No newline at end of file diff --git a/modules/actions.js b/modules/actions.js new file mode 100644 index 0000000000..a6369edcf6 --- /dev/null +++ b/modules/actions.js @@ -0,0 +1,8 @@ +define([ + "core", + "cocos2d/actions/CCAction", + "cocos2d/actions/CCActionInterval", + "cocos2d/actions/CCActionInstant" +], function(cc) { + return cc; +}); \ No newline at end of file diff --git a/modules/core.js b/modules/core.js new file mode 100644 index 0000000000..4be471e38f --- /dev/null +++ b/modules/core.js @@ -0,0 +1,3 @@ +define([], function() { + return cc; +}); \ No newline at end of file diff --git a/modules/layers.js b/modules/layers.js new file mode 100644 index 0000000000..7728565495 --- /dev/null +++ b/modules/layers.js @@ -0,0 +1,6 @@ +define([ + "Sprite", + "cocos2d/core/layers/CCLayer" +], function() { + return cc; +}); \ No newline at end of file diff --git a/modules/menuitems.js b/modules/menuitems.js new file mode 100644 index 0000000000..9cde34227a --- /dev/null +++ b/modules/menuitems.js @@ -0,0 +1,8 @@ +define([ + "core", + "actions", + "Menu", + "cocos2d/menus/CCMenuItem" +], function() { + return cc; +}); \ No newline at end of file From 3d45a0270a2e6c87c3bd2ee93d1ae10190b13619 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 13 Sep 2014 20:55:54 +0800 Subject: [PATCH 04/32] Feature #5929: Improve module configs --- modules/LabelBMFont.js | 6 ++++++ modules/audio.js | 6 ++++++ require.js | 23 ++++++----------------- 3 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 modules/LabelBMFont.js create mode 100644 modules/audio.js diff --git a/modules/LabelBMFont.js b/modules/LabelBMFont.js new file mode 100644 index 0000000000..2068ccc499 --- /dev/null +++ b/modules/LabelBMFont.js @@ -0,0 +1,6 @@ +define([ + "SpriteBatchNode", + "cocos2d/labels/CCLabelBMFont" +], function() { + return cc.LabelBMFont; +}); \ No newline at end of file diff --git a/modules/audio.js b/modules/audio.js new file mode 100644 index 0000000000..e3680aef72 --- /dev/null +++ b/modules/audio.js @@ -0,0 +1,6 @@ +define([ + "core", + "cocos2d/audio/CCAudio" +], function(cc) { + return cc.audioEngine; +}); \ No newline at end of file diff --git a/require.js b/require.js index 4c171cb0eb..43c857b9f9 100644 --- a/require.js +++ b/require.js @@ -2076,7 +2076,7 @@ var requirejs, require, define; }(this)); var require_config = { - baseUrl: 'frameworks/cocos2d-html5/modules', + baseUrl: '../../frameworks/cocos2d-html5/modules', paths: { root: '../', @@ -2290,7 +2290,7 @@ var require_config = { exports: "cc" }, - "NodeAtlas" : { + "cocos2d/core/base-nodes/CCAtlasNode" : { deps: [ "Node", "cocos2d/core/base-nodes/CCAtlasNode" @@ -2300,18 +2300,7 @@ var require_config = { } }, - "AnimationFrame" : { - deps: [ - "core", - "Sprite", - "cocos2d/core/sprites/CCAnimation" - ], - init: function() { - return cc.AnimationFrame; - } - }, - - "Animation" : { + "cocos2d/core/sprites/CCAnimation" : { deps: [ "Sprite", "cocos2d/core/sprites/CCAnimation" @@ -2321,7 +2310,7 @@ var require_config = { } }, - "animationCache" : { + "cocos2d/core/sprites/CCAnimationCache" : { deps: [ "Sprite", "Animation", @@ -2332,7 +2321,7 @@ var require_config = { } }, - "SpriteFrame" : { + "cocos2d/core/sprites/CCSpriteFrame" : { deps: [ "Sprite", "cocos2d/core/sprites/CCSpriteFrame" @@ -2342,7 +2331,7 @@ var require_config = { } }, - "spriteFrameCache" : { + "cocos2d/core/sprites/CCSpriteFrameCache" : { deps: [ "SpriteFrame", "cocos2d/core/sprites/CCSpriteFrameCache" From 41e182a68fd3661bc0c9b5dd670bff299e99110c Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Fri, 17 Oct 2014 13:41:53 +0800 Subject: [PATCH 05/32] add audio and sprite --- modules/Sprite.js | 1 + require.js | 81 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/modules/Sprite.js b/modules/Sprite.js index 80596dc8aa..11333ef6e7 100644 --- a/modules/Sprite.js +++ b/modules/Sprite.js @@ -1,4 +1,5 @@ define([ + "Node", "cocos2d/core/sprites/CCSprite" ], function() { return cc.Sprite; diff --git a/require.js b/require.js index 43c857b9f9..9e40681dee 100644 --- a/require.js +++ b/require.js @@ -2081,7 +2081,7 @@ var require_config = { paths: { root: '../', cocos2d: '../cocos2d', - game: '../../../src' + game: '../../../samples/js-moonwarriors/src' }, shim: { @@ -2097,6 +2097,31 @@ var require_config = { "cocos2d/core/event-manager/CCEventListener" : [ "cocos2d/core/platform/CCClass" ], + "cocos2d/core/event-manager/CCTouch" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/CCCamera" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/platform/CCEGLView" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/CCDrawingPrimitiveCanvas" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/CCGLProgram" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/event-manager/CCEvent" : [ + "cocos2d/core/platform/CCClass" + ], + + "cocos2d/core/platform/CCConfig" : [ "cocos2d/core/cocoa/CCGeometry" @@ -2209,16 +2234,22 @@ var require_config = { "cocos2d/core/sprites/CCSprite" ], - "cocos2d/core/actions/CCAction" : [ + "cocos2d/actions/CCAction" : [ "core" ], - "cocos2d/core/actions/CCActionInterval" : [ - "cocos2d/core/actions/CCAction" + "cocos2d/actions/CCActionInterval" : [ + "cocos2d/actions/CCAction" + ], + "cocos2d/actions/CCActionInstant" : [ + "cocos2d/actions/CCAction" ], - "cocos2d/core/actions/CCActionInstant" : [ - "cocos2d/core/actions/CCAction" + + "cocos2d/labels/CCLabelBMFont" : [ + "cocos2d/core/sprites/CCSpriteBatchNode" ], + + "core" : { deps: [ "root/CCDebugger", @@ -2290,6 +2321,16 @@ var require_config = { exports: "cc" }, + "cocos2d/core/sprites/CCSprite" : { + deps: [ + "Node", + "cocos2d/core/sprites/CCSprite" + ], + init: function() { + return cc.Sprite; + } + }, + "cocos2d/core/base-nodes/CCAtlasNode" : { deps: [ "Node", @@ -2313,7 +2354,7 @@ var require_config = { "cocos2d/core/sprites/CCAnimationCache" : { deps: [ "Sprite", - "Animation", + "cocos2d/core/sprites/CCAnimation", "cocos2d/core/sprites/CCAnimationCache" ], init: function() { @@ -2333,7 +2374,7 @@ var require_config = { "cocos2d/core/sprites/CCSpriteFrameCache" : { deps: [ - "SpriteFrame", + "cocos2d/core/sprites/CCSpriteFrame", "cocos2d/core/sprites/CCSpriteFrameCache" ], init: function() { @@ -2344,32 +2385,40 @@ var require_config = { "cocos2d/actions/CCActionCamera" : { deps: [ "core", - "cocos2d/core/actions/CCAction", - "cocos2d/core/actions/CCActionInterval" + "cocos2d/actions/CCAction", + "cocos2d/actions/CCActionInterval" ], exports: "cc" }, "cocos2d/actions/CCActionEase" : { deps: [ "core", - "cocos2d/core/actions/CCAction", - "cocos2d/core/actions/CCActionInterval" + "cocos2d/actions/CCAction", + "cocos2d/actions/CCActionInterval" ], exports: "cc" }, "cocos2d/actions/CCActionCatmullRom" : { deps: [ "core", - "cocos2d/core/actions/CCAction", - "cocos2d/core/actions/CCActionInterval" + "cocos2d/actions/CCAction", + "cocos2d/actions/CCActionInterval" ], exports: "cc" }, "cocos2d/actions/CCActionTween" : { deps: [ "core", - "cocos2d/core/actions/CCAction", - "cocos2d/core/actions/CCActionInterval" + "cocos2d/actions/CCAction", + "cocos2d/actions/CCActionInterval" + ], + exports: "cc" + }, + + "cocos2d/audio/CCAudio" : { + deps: [ + "core", + "cocos2d/core/event-manager/CCEventManager" ], exports: "cc" } From af1588d26437d032548ad1848b8c575d4964cfd5 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Fri, 17 Oct 2014 19:05:24 +0800 Subject: [PATCH 06/32] support require js --- modules/LabelBMFont.js | 2 +- modules/LabelTTF.js | 2 +- modules/LoaderScene.js | 2 +- modules/Menu.js | 2 +- modules/Node.js | 4 +- modules/Scene.js | 2 +- modules/Sprite.js | 5 +- modules/SpriteBatchNode.js | 2 +- modules/actions.js | 6 +- modules/audio.js | 2 +- modules/layers.js | 2 +- modules/menuitems.js | 2 +- require.js | 418 +++++++++++++++++++------------------ 13 files changed, 237 insertions(+), 214 deletions(-) diff --git a/modules/LabelBMFont.js b/modules/LabelBMFont.js index 2068ccc499..23aa3bf1c5 100644 --- a/modules/LabelBMFont.js +++ b/modules/LabelBMFont.js @@ -1,6 +1,6 @@ define([ "SpriteBatchNode", - "cocos2d/labels/CCLabelBMFont" + "cocos2dPath/labels/CCLabelBMFont" ], function() { return cc.LabelBMFont; }); \ No newline at end of file diff --git a/modules/LabelTTF.js b/modules/LabelTTF.js index b357c700cf..b25ea3baaf 100644 --- a/modules/LabelTTF.js +++ b/modules/LabelTTF.js @@ -1,6 +1,6 @@ define([ "Sprite", - "cocos2d/core/labelttf/CCLabelTTF" + "cocos2dPath/core/labelttf/CCLabelTTF" ], function() { return cc.LabelTTF; }); \ No newline at end of file diff --git a/modules/LoaderScene.js b/modules/LoaderScene.js index 7847655b11..a0df33adc5 100644 --- a/modules/LoaderScene.js +++ b/modules/LoaderScene.js @@ -1,5 +1,5 @@ define([ - "cocos2d/core/scenes/CCLoaderScene" + "cocos2dPath/core/scenes/CCLoaderScene" ], function() { return cc.LoaderScene; }); \ No newline at end of file diff --git a/modules/Menu.js b/modules/Menu.js index 922d0512ef..70a5084df7 100644 --- a/modules/Menu.js +++ b/modules/Menu.js @@ -1,7 +1,7 @@ define([ "core", "actions", - "cocos2d/menus/CCMenu" + "cocos2dPath/menus/CCMenu" ], function() { return cc.Menu; }); \ No newline at end of file diff --git a/modules/Node.js b/modules/Node.js index 0e8dc4176e..26c3b9af80 100644 --- a/modules/Node.js +++ b/modules/Node.js @@ -1,6 +1,8 @@ define([ "core", - "cocos2d/core/base-nodes/CCNode" + "cocos2dPath/core/base-nodes/CCNode", + "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine", + "cocos2dPath/core/base-nodes/BaseNodesWebGL" ], function() { return cc.Node; }); \ No newline at end of file diff --git a/modules/Scene.js b/modules/Scene.js index bdd1bff91f..84d6feb7fe 100644 --- a/modules/Scene.js +++ b/modules/Scene.js @@ -1,5 +1,5 @@ define([ - "cocos2d/core/scenes/CCScene" + "cocos2dPath/core/scenes/CCScene" ], function() { return cc.Scene; }); \ No newline at end of file diff --git a/modules/Sprite.js b/modules/Sprite.js index 11333ef6e7..0bf5a32577 100644 --- a/modules/Sprite.js +++ b/modules/Sprite.js @@ -1,6 +1,9 @@ define([ + "core", "Node", - "cocos2d/core/sprites/CCSprite" + "cocos2dPath/core/sprites/CCSprite", + "cocos2dPath/core/sprites/SpritesPropertyDefine", + "cocos2dPath/core/sprites/SpritesWebGL" ], function() { return cc.Sprite; }); \ No newline at end of file diff --git a/modules/SpriteBatchNode.js b/modules/SpriteBatchNode.js index c4f92bc94d..b3a6195c49 100644 --- a/modules/SpriteBatchNode.js +++ b/modules/SpriteBatchNode.js @@ -1,5 +1,5 @@ define([ - "cocos2d/core/sprites/CCSpriteBatchNode" + "cocos2dPath/core/sprites/CCSpriteBatchNode" ], function() { return cc.SpriteBatchNode; }); \ No newline at end of file diff --git a/modules/actions.js b/modules/actions.js index a6369edcf6..9ab0876f58 100644 --- a/modules/actions.js +++ b/modules/actions.js @@ -1,8 +1,8 @@ define([ "core", - "cocos2d/actions/CCAction", - "cocos2d/actions/CCActionInterval", - "cocos2d/actions/CCActionInstant" + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval", + "cocos2dPath/actions/CCActionInstant" ], function(cc) { return cc; }); \ No newline at end of file diff --git a/modules/audio.js b/modules/audio.js index e3680aef72..840640c524 100644 --- a/modules/audio.js +++ b/modules/audio.js @@ -1,6 +1,6 @@ define([ "core", - "cocos2d/audio/CCAudio" + "cocos2dPath/audio/CCAudio" ], function(cc) { return cc.audioEngine; }); \ No newline at end of file diff --git a/modules/layers.js b/modules/layers.js index 7728565495..56d0f6e452 100644 --- a/modules/layers.js +++ b/modules/layers.js @@ -1,6 +1,6 @@ define([ "Sprite", - "cocos2d/core/layers/CCLayer" + "cocos2dPath/core/layers/CCLayer" ], function() { return cc; }); \ No newline at end of file diff --git a/modules/menuitems.js b/modules/menuitems.js index 9cde34227a..83b8a24ad5 100644 --- a/modules/menuitems.js +++ b/modules/menuitems.js @@ -2,7 +2,7 @@ define([ "core", "actions", "Menu", - "cocos2d/menus/CCMenuItem" + "cocos2dPath/menus/CCMenuItem" ], function() { return cc; }); \ No newline at end of file diff --git a/require.js b/require.js index 9e40681dee..50d0ddf324 100644 --- a/require.js +++ b/require.js @@ -2080,345 +2080,363 @@ var require_config = { paths: { root: '../', - cocos2d: '../cocos2d', + cocos2dPath: '../cocos2d', game: '../../../samples/js-moonwarriors/src' }, shim: { - "cocos2d/core/platform/CCSAXParser" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/platform/CCSAXParser": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/platform/CCTypes" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/platform/CCTypes": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/CCScheduler" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/CCScheduler": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/event-manager/CCEventListener" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/event-manager/CCEventListener": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/event-manager/CCTouch" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/event-manager/CCTouch": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/CCCamera" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/CCCamera": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/platform/CCEGLView" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/platform/CCEGLView": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/CCDrawingPrimitiveCanvas" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/CCDrawingPrimitiveCanvas": [ + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/CCGLProgram" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/CCGLProgram": [ + "core", + "cocos2dPath/core/platform/CCClass" ], - "cocos2d/core/event-manager/CCEvent" : [ - "cocos2d/core/platform/CCClass" + "cocos2dPath/core/event-manager/CCEvent": [ + "cocos2dPath/core/platform/CCClass" ], - - - "cocos2d/core/platform/CCConfig" : [ - "cocos2d/core/cocoa/CCGeometry" + "cocos2dPath/core/platform/CCConfig": [ + "cocos2dPath/core/cocoa/CCGeometry" ], - "cocos2d/core/platform/CCVisibleRect" : [ - "cocos2d/core/cocoa/CCGeometry" + "cocos2dPath/core/platform/CCVisibleRect": [ + "cocos2dPath/core/cocoa/CCGeometry" ], - "cocos2d/core/platform/CCInputManager" : [ - "cocos2d/core/cocoa/CCGeometry" + "cocos2dPath/core/platform/CCInputManager": [ + "cocos2dPath/core/cocoa/CCGeometry" ], - "cocos2d/core/textures/CCTexture2D" : [ - "cocos2d/core/textures/TexturesWebGL", - "cocos2d/core/textures/TexturesPropertyDefine" + "cocos2dPath/core/textures/CCTexture2D": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" ], - "cocos2d/core/textures/CCTextureAtlas" : [ - "cocos2d/core/textures/TexturesWebGL", - "cocos2d/core/textures/TexturesPropertyDefine" + "cocos2dPath/core/textures/CCTextureAtlas": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" ], - "cocos2d/core/CCDirector" : [ - "cocos2d/core/CCDirectorWebGL" + "cocos2dPath/core/CCDirectorWebGL": [ + + //"cocos2dPath/core/labelttf/CCLabelTTF" // 循环调用 ], - "cocos2d/core/platform/CCInputExtension" : [ - "cocos2d/core/platform/CCInputManager" + "cocos2dPath/core/CCDirector": [ + "cocos2dPath/core/CCDirectorWebGL" ], - "cocos2d/core/textures/CCTexture2D": [ - "cocos2d/core/textures/TexturesWebGL", - "cocos2d/core/textures/TexturesPropertyDefine" + "cocos2dPath/core/platform/CCInputExtension": [ + "cocos2dPath/core/platform/CCInputManager" ], - "cocos2d/core/textures/CCTextureAtlas": [ - "cocos2d/core/textures/TexturesWebGL", - "cocos2d/core/textures/TexturesPropertyDefine" + "cocos2dPath/core/textures/CCTexture2D": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" ], - "cocos2d/core/textures/CCTextureCache": [ - "cocos2d/core/textures/TexturesWebGL", - "cocos2d/core/textures/TexturesPropertyDefine" + "cocos2dPath/core/textures/CCTextureAtlas": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" ], - "cocos2d/core/event-manager/CCEventExtension": [ - "cocos2d/core/event-manager/CCEvent", - "cocos2d/core/event-manager/CCEventListener" + "cocos2dPath/core/textures/CCTextureCache": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" ], - "cocos2d/core/event-manager/CCEventManager": [ - "cocos2d/core/event-manager/CCEvent", - "cocos2d/core/event-manager/CCEventListener" + "cocos2dPath/core/event-manager/CCEventExtension": [ + "cocos2dPath/core/event-manager/CCEvent", + "cocos2dPath/core/event-manager/CCEventListener" ], - "cocos2d/kazmath/gl/matrix" : [ - "cocos2d/kazmath/utility", - "cocos2d/kazmath/vec2", - "cocos2d/kazmath/vec3", - "cocos2d/kazmath/vec4", - "cocos2d/kazmath/ray2", - "cocos2d/kazmath/mat3", - "cocos2d/kazmath/mat4", - "cocos2d/kazmath/plane", - "cocos2d/kazmath/quaternion", - "cocos2d/kazmath/aabb", - "cocos2d/kazmath/gl/mat4stack" + "cocos2dPath/core/event-manager/CCEventManager": [ + "cocos2dPath/core/event-manager/CCEvent", + "cocos2dPath/core/event-manager/CCEventListener" ], - - "cocos2d/core/base-nodes/CCNode" : [ - "core", - "cocos2d/core/base-nodes/BaseNodesWebGL", - "cocos2d/core/base-nodes/BaseNodesPropertyDefine" + "cocos2dPath/kazmath/gl/matrix": [ + "cocos2dPath/kazmath/utility", + "cocos2dPath/kazmath/vec2", + "cocos2dPath/kazmath/vec3", + "cocos2dPath/kazmath/vec4", + "cocos2dPath/kazmath/ray2", + "cocos2dPath/kazmath/mat3", + "cocos2dPath/kazmath/mat4", + "cocos2dPath/kazmath/plane", + "cocos2dPath/kazmath/quaternion", + "cocos2dPath/kazmath/aabb", + "cocos2dPath/kazmath/gl/mat4stack" ], - "cocos2d/core/scenes/CCScene" : [ + "cocos2dPath/core/base-nodes/CCNode": [ "core", - "cocos2d/core/base-nodes/CCNode" + "cocos2dPath/core/base-nodes/BaseNodesWebGL", + "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine" ], - "cocos2d/core/sprites/CCSprite" : [ + "cocos2dPath/core/scenes/CCScene": [ "core", - "cocos2d/core/base-nodes/CCNode", - "cocos2d/core/sprites/SpritesWebGL", - "cocos2d/core/sprites/SpritesPropertyDefine" + "cocos2dPath/core/base-nodes/CCNode" ], - "cocos2d/core/sprites/CCBakeSprite" : [ - "cocos2d/core/sprites/CCSprite" + "cocos2dPath/core/sprites/CCBakeSprite": [ + "Sprite" ], - "cocos2d/core/layers/CCLayer" : [ + "cocos2dPath/core/layers/CCLayer": [ "core", - "cocos2d/core/sprites/CCBakeSprite", - "cocos2d/core/layers/CCLayerWebGL", - "cocos2d/core/layers/CCLayerPropertyDefine" + "cocos2dPath/core/sprites/CCBakeSprite", + "cocos2dPath/core/layers/CCLayerWebGL", + "cocos2dPath/core/layers/CCLayerPropertyDefine" ], - "cocos2d/core/labelttf/CCLabelTTF" : [ - "cocos2d/core/sprites/CCSprite", - "cocos2d/core/labelttf/LabelTTFWebGL", - "cocos2d/core/labelttf/LabelTTFPropertyDefine" + "cocos2dPath/core/labelttf/CCLabelTTF": [ + "cocos2dPath/core/sprites/CCSprite", + "cocos2dPath/core/labelttf/LabelTTFWebGL", + "cocos2dPath/core/labelttf/LabelTTFPropertyDefine" ], - "cocos2d/core/scenes/CCLoaderScene" : [ - "core", - "cocos2d/core/layers/CCLayer", - "cocos2d/core/labelttf/CCLabelTTF", - "cocos2d/core/scenes/CCScene" - ], - "cocos2d/menus/CCMenu" : [ - "cocos2d/core/layers/CCLayer" + + "cocos2dPath/menus/CCMenu" : [ + "cocos2dPath/core/layers/CCLayer" ], - "cocos2d/menus/CCMenuItem" : [ - "cocos2d/core/base-nodes/CCNode" + "cocos2dPath/menus/CCMenuItem" : [ + "cocos2dPath/core/base-nodes/CCNode" ], - "cocos2d/core/sprites/CCSpriteBatchNode" : [ - "cocos2d/core/sprites/CCSprite" + "cocos2dPath/core/sprites/CCSpriteBatchNode" : [ + "cocos2dPath/core/sprites/CCSprite" ], - "cocos2d/actions/CCAction" : [ + "cocos2dPath/actions/CCAction" : [ "core" ], - "cocos2d/actions/CCActionInterval" : [ - "cocos2d/actions/CCAction" + "cocos2dPath/actions/CCActionInterval" : [ + "cocos2dPath/actions/CCAction" ], - "cocos2d/actions/CCActionInstant" : [ - "cocos2d/actions/CCAction" + "cocos2dPath/actions/CCActionInstant" : [ + "cocos2dPath/actions/CCAction" ], - "cocos2d/labels/CCLabelBMFont" : [ - "cocos2d/core/sprites/CCSpriteBatchNode" + "cocos2dPath/labels/CCLabelBMFont" : [ + "cocos2dPath/core/sprites/CCSpriteBatchNode" ], "core" : { deps: [ + "root/CCBoot", "root/CCDebugger", - "cocos2d/core/utils/BinaryLoader", + "cocos2dPath/core/utils/BinaryLoader", "root/Base64Images", - "cocos2d/core/platform/CCClass", - "cocos2d/core/platform/CCCommon", - "cocos2d/core/cocoa/CCGeometry", - "cocos2d/core/platform/CCSAXParser", - "cocos2d/core/platform/CCLoaders", - "cocos2d/core/platform/CCConfig", - "cocos2d/core/platform/miniFramework", - "cocos2d/core/platform/CCMacro", - "cocos2d/core/platform/CCTypesWebGL", - "cocos2d/core/platform/CCTypesPropertyDefine", - "cocos2d/core/platform/CCTypes", - "cocos2d/core/platform/CCEGLView", - "cocos2d/core/platform/CCScreen", - "cocos2d/core/platform/CCVisibleRect", - - "cocos2d/core/platform/CCInputManager", - "cocos2d/core/platform/CCInputExtension", - - "cocos2d/core/cocoa/CCAffineTransform", - "cocos2d/core/support/CCPointExtension", - "cocos2d/core/support/CCVertex", - "cocos2d/core/support/TransformUtils", - "cocos2d/core/event-manager/CCTouch", - - "cocos2d/core/event-manager/CCEvent", - "cocos2d/core/event-manager/CCEventListener", - "cocos2d/core/event-manager/CCEventManager", - "cocos2d/core/event-manager/CCEventExtension", - - "cocos2d/core/CCConfiguration", - - "cocos2d/core/CCDirector", - - "cocos2d/core/CCCamera", - "cocos2d/core/CCScheduler", - - "cocos2d/core/CCActionManager", - - "cocos2d/core/CCDrawingPrimitivesCanvas", - "cocos2d/core/CCDrawingPrimitivesWebGL", - - "cocos2d/core/textures/CCTexture2D", - "cocos2d/core/textures/CCTextureAtlas", - "cocos2d/core/textures/CCTextureCache", - - "cocos2d/kazmath/utility", - "cocos2d/kazmath/vec2", - "cocos2d/kazmath/vec3", - "cocos2d/kazmath/vec4", - "cocos2d/kazmath/ray2", - "cocos2d/kazmath/mat3", - "cocos2d/kazmath/mat4", - "cocos2d/kazmath/plane", - "cocos2d/kazmath/quaternion", - "cocos2d/kazmath/aabb", - "cocos2d/kazmath/gl/mat4stack", - "cocos2d/kazmath/gl/matrix", - - "cocos2d/shaders/CCShaders", - "cocos2d/shaders/CCShaderCache", - "cocos2d/shaders/CCGLProgram", - "cocos2d/shaders/CCGLStateCache" + "cocos2dPath/core/platform/CCClass", + "cocos2dPath/core/platform/CCCommon", + "cocos2dPath/core/cocoa/CCGeometry", + "cocos2dPath/core/platform/CCSAXParser", + "cocos2dPath/core/platform/CCLoaders", + "cocos2dPath/core/platform/CCConfig", + "cocos2dPath/core/platform/miniFramework", + "cocos2dPath/core/platform/CCMacro", + "cocos2dPath/core/platform/CCTypesWebGL", + "cocos2dPath/core/platform/CCTypesPropertyDefine", + "cocos2dPath/core/platform/CCTypes", + "cocos2dPath/core/platform/CCEGLView", + "cocos2dPath/core/platform/CCScreen", + "cocos2dPath/core/platform/CCVisibleRect", + + + "cocos2dPath/core/platform/CCInputManager", + "cocos2dPath/core/platform/CCInputExtension", + + "cocos2dPath/core/cocoa/CCAffineTransform", + "cocos2dPath/core/support/CCPointExtension", + "cocos2dPath/core/support/CCVertex", + "cocos2dPath/core/support/TransformUtils", + "cocos2dPath/core/event-manager/CCTouch", + + "cocos2dPath/core/event-manager/CCEvent", + "cocos2dPath/core/event-manager/CCEventListener", + "cocos2dPath/core/event-manager/CCEventManager", + "cocos2dPath/core/event-manager/CCEventExtension", + + "cocos2dPath/core/CCConfiguration", + + "cocos2dPath/core/CCDirector", + + "cocos2dPath/core/CCCamera", + "cocos2dPath/core/CCScheduler", + + "cocos2dPath/core/CCActionManager", + + "cocos2dPath/core/CCDrawingPrimitivesCanvas", + "cocos2dPath/core/CCDrawingPrimitivesWebGL", + + "cocos2dPath/core/textures/CCTexture2D", + "cocos2dPath/core/textures/CCTextureAtlas", + "cocos2dPath/core/textures/CCTextureCache", + + "cocos2dPath/kazmath/utility", + "cocos2dPath/kazmath/vec2", + "cocos2dPath/kazmath/vec3", + "cocos2dPath/kazmath/vec4", + "cocos2dPath/kazmath/ray2", + "cocos2dPath/kazmath/mat3", + "cocos2dPath/kazmath/mat4", + "cocos2dPath/kazmath/plane", + "cocos2dPath/kazmath/quaternion", + "cocos2dPath/kazmath/aabb", + "cocos2dPath/kazmath/gl/mat4stack", + "cocos2dPath/kazmath/gl/matrix", + + "cocos2dPath/shaders/CCShaders", + "cocos2dPath/shaders/CCShaderCache", + "cocos2dPath/shaders/CCGLProgram", + "cocos2dPath/shaders/CCGLStateCache" ], exports: "cc" }, - "cocos2d/core/sprites/CCSprite" : { + "cocos2dPath/transitions/CCTransition" : [ + + "cocos2dPath/core/scenes/CCScene" + ], + + "cocos2dPath/transitions/CCTransition": { deps: [ + "cocos2dPath/core/scenes/CCScene" + ], + + init: function () { + return cc.TransitionFade; + } + }, + + "cocos2dPath/core/scenes/CCLoaderScene": { + deps: [ + "core", + "cocos2dPath/core/layers/CCLayer", + "cocos2dPath/core/labelttf/CCLabelTTF", + "cocos2dPath/core/scenes/CCScene" + ], + + init: function () { + return cc.LoaderScene; + } + }, + + "cocos2dPath/core/sprites/CCSprite" : { + deps: [ + "core", "Node", - "cocos2d/core/sprites/CCSprite" + "cocos2dPath/core/sprites/SpritesPropertyDefine", + "cocos2dPath/core/sprites/SpritesWebGL" ], init: function() { return cc.Sprite; } }, - "cocos2d/core/base-nodes/CCAtlasNode" : { + "cocos2dPath/core/base-nodes/CCAtlasNode" : { deps: [ - "Node", - "cocos2d/core/base-nodes/CCAtlasNode" + "Node" ], init: function() { return cc.NodeAtlas; } }, - "cocos2d/core/sprites/CCAnimation" : { + "cocos2dPath/core/sprites/CCAnimation" : { deps: [ - "Sprite", - "cocos2d/core/sprites/CCAnimation" + "Sprite" ], init: function() { return cc.Animation; } }, - "cocos2d/core/sprites/CCAnimationCache" : { + "cocos2dPath/core/sprites/CCAnimationCache" : { deps: [ "Sprite", - "cocos2d/core/sprites/CCAnimation", - "cocos2d/core/sprites/CCAnimationCache" + "cocos2dPath/core/sprites/CCAnimation" ], init: function() { return cc.animationCache; } }, - "cocos2d/core/sprites/CCSpriteFrame" : { + "cocos2dPath/core/sprites/CCSpriteFrame" : { deps: [ - "Sprite", - "cocos2d/core/sprites/CCSpriteFrame" + "Sprite" ], init: function() { return cc.SpriteFrame; } }, - "cocos2d/core/sprites/CCSpriteFrameCache" : { + "cocos2dPath/core/sprites/CCSpriteFrameCache" : { deps: [ - "cocos2d/core/sprites/CCSpriteFrame", - "cocos2d/core/sprites/CCSpriteFrameCache" + "cocos2dPath/core/sprites/CCSpriteFrame" ], init: function() { return cc.spriteFrameCache; } }, - "cocos2d/actions/CCActionCamera" : { + "cocos2dPath/actions/CCActionCamera" : { deps: [ "core", - "cocos2d/actions/CCAction", - "cocos2d/actions/CCActionInterval" + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" ], exports: "cc" }, - "cocos2d/actions/CCActionEase" : { + "cocos2dPath/actions/CCActionEase" : { deps: [ "core", - "cocos2d/actions/CCAction", - "cocos2d/actions/CCActionInterval" + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" ], exports: "cc" }, - "cocos2d/actions/CCActionCatmullRom" : { + "cocos2dPath/actions/CCActionCatmullRom" : { deps: [ "core", - "cocos2d/actions/CCAction", - "cocos2d/actions/CCActionInterval" + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" ], exports: "cc" }, - "cocos2d/actions/CCActionTween" : { + "cocos2dPath/actions/CCActionTween" : { deps: [ "core", - "cocos2d/actions/CCAction", - "cocos2d/actions/CCActionInterval" + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" ], exports: "cc" }, - "cocos2d/audio/CCAudio" : { + "cocos2dPath/audio/CCAudio" : { deps: [ "core", - "cocos2d/core/event-manager/CCEventManager" + "cocos2dPath/core/event-manager/CCEventManager" ], exports: "cc" } From 98b4d15ba9d54600b57778196f4e134a6b23f61e Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Fri, 24 Oct 2014 15:57:22 +0800 Subject: [PATCH 07/32] support js-moonwarriors useed in requirejs --- modules/core.js | 2 +- require.js | 825 +++++++++++++++++++++++++++++------------------- 2 files changed, 498 insertions(+), 329 deletions(-) diff --git a/modules/core.js b/modules/core.js index 4be471e38f..28acb3b34a 100644 --- a/modules/core.js +++ b/modules/core.js @@ -1,3 +1,3 @@ -define([], function() { +define(["root/CCBoot"], function() { return cc; }); \ No newline at end of file diff --git a/require.js b/require.js index 50d0ddf324..2d345f6219 100644 --- a/require.js +++ b/require.js @@ -9,6 +9,11 @@ /*global window, navigator, document, importScripts, setTimeout, opera */ var requirejs, require, define; +var requirejsSystemInfo = {}; +if (typeof sys !== "undefined") +{ + requirejsSystemInfo = sys; +} (function (global) { var req, s, head, baseElement, dataMain, src, interactiveScript, currentlyAddingScript, mainScript, subPath, @@ -23,6 +28,7 @@ var requirejs, require, define; ap = Array.prototype, apsp = ap.splice, isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document), + isNative = requirejsSystemInfo.isNative, isWebWorker = !isBrowser && typeof importScripts !== 'undefined', //PS3 indicates loaded and complete, but need to wait for complete //specifically. Sequence is 'loading', 'loaded', execution, @@ -363,6 +369,11 @@ var requirejs, require, define; } }); } + + if (isNative) + { + // do something remove + } } function hasPathFallback(id) { @@ -811,8 +822,8 @@ var requirejs, require, define; context.makeRequire(this.map, { enableBuildCallback: true })(this.shim.deps || [], bind(this, function () { - return map.prefix ? this.callPlugin() : this.load(); - })); + return map.prefix ? this.callPlugin() : this.load(); + })); } else { //Regular dependency. return map.prefix ? this.callPlugin() : this.load(); @@ -1052,7 +1063,7 @@ var requirejs, require, define; req.exec(text); } catch (e) { return onError(makeError('fromtexteval', - 'fromText eval for ' + id + + 'fromText eval for ' + id + ' failed: ' + e, e, [id])); @@ -1453,7 +1464,7 @@ var requirejs, require, define; } return context.nameToUrl(normalize(moduleNamePlusExt, - relMap && relMap.id, true), ext, true); + relMap && relMap.id, true), ext, true); }, defined: function (id) { @@ -1562,7 +1573,7 @@ var requirejs, require, define; return; } else { return onError(makeError('nodefine', - 'No define call for ' + moduleName, + 'No define call for ' + moduleName, null, [moduleName])); } @@ -1810,6 +1821,11 @@ var requirejs, require, define; } } + if (isNative) + { + // do something init + } + /** * Any errors that require explicitly generates will be passed to this * function. Intercept/override it if you want custom error handling. @@ -1919,12 +1935,20 @@ var requirejs, require, define; context.completeLoad(moduleName); } catch (e) { context.onError(makeError('importscripts', - 'importScripts failed for ' + + 'importScripts failed for ' + moduleName + ' at ' + url, e, [moduleName])); } } + else if (isNative) { + if (url.indexOf(require_config.paths.game) != -1) + { + require(url); + } + //Account for anonymous modules + context.completeLoad(moduleName); + } }; function getInteractiveScript() { @@ -2075,224 +2099,248 @@ var requirejs, require, define; req(cfg); }(this)); -var require_config = { - baseUrl: '../../frameworks/cocos2d-html5/modules', - - paths: { - root: '../', - cocos2dPath: '../cocos2d', - game: '../../../samples/js-moonwarriors/src' - }, - - shim: { - "cocos2dPath/core/platform/CCSAXParser": [ - "cocos2dPath/core/platform/CCClass" - ], - "cocos2dPath/core/platform/CCTypes": [ - "cocos2dPath/core/platform/CCClass" - ], - "cocos2dPath/core/CCScheduler": [ - "cocos2dPath/core/platform/CCClass" - ], - "cocos2dPath/core/event-manager/CCEventListener": [ - "cocos2dPath/core/platform/CCClass" - ], - "cocos2dPath/core/event-manager/CCTouch": [ - "cocos2dPath/core/platform/CCClass" - ], - - "cocos2dPath/core/CCCamera": [ - "cocos2dPath/core/platform/CCClass" - ], - - "cocos2dPath/core/platform/CCEGLView": [ - "cocos2dPath/core/platform/CCClass" - ], - - "cocos2dPath/core/CCDrawingPrimitiveCanvas": [ - "cocos2dPath/core/platform/CCClass" - ], - - "cocos2dPath/core/CCGLProgram": [ - "core", - "cocos2dPath/core/platform/CCClass" - ], - - "cocos2dPath/core/event-manager/CCEvent": [ - "cocos2dPath/core/platform/CCClass" - ], - - "cocos2dPath/core/platform/CCConfig": [ - "cocos2dPath/core/cocoa/CCGeometry" - ], - "cocos2dPath/core/platform/CCVisibleRect": [ - "cocos2dPath/core/cocoa/CCGeometry" - ], - "cocos2dPath/core/platform/CCInputManager": [ - "cocos2dPath/core/cocoa/CCGeometry" - ], - "cocos2dPath/core/textures/CCTexture2D": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/textures/CCTextureAtlas": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/CCDirectorWebGL": [ - - //"cocos2dPath/core/labelttf/CCLabelTTF" // 循环调用 - ], - "cocos2dPath/core/CCDirector": [ - "cocos2dPath/core/CCDirectorWebGL" - ], - "cocos2dPath/core/platform/CCInputExtension": [ - "cocos2dPath/core/platform/CCInputManager" - ], - "cocos2dPath/core/textures/CCTexture2D": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/textures/CCTextureAtlas": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/textures/CCTextureCache": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/event-manager/CCEventExtension": [ - "cocos2dPath/core/event-manager/CCEvent", - "cocos2dPath/core/event-manager/CCEventListener" - ], - "cocos2dPath/core/event-manager/CCEventManager": [ - "cocos2dPath/core/event-manager/CCEvent", - "cocos2dPath/core/event-manager/CCEventListener" - ], - "cocos2dPath/kazmath/gl/matrix": [ - "cocos2dPath/kazmath/utility", - "cocos2dPath/kazmath/vec2", - "cocos2dPath/kazmath/vec3", - "cocos2dPath/kazmath/vec4", - "cocos2dPath/kazmath/ray2", - "cocos2dPath/kazmath/mat3", - "cocos2dPath/kazmath/mat4", - "cocos2dPath/kazmath/plane", - "cocos2dPath/kazmath/quaternion", - "cocos2dPath/kazmath/aabb", - "cocos2dPath/kazmath/gl/mat4stack" - ], - - "cocos2dPath/core/base-nodes/CCNode": [ - "core", - "cocos2dPath/core/base-nodes/BaseNodesWebGL", - "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine" - ], - - "cocos2dPath/core/scenes/CCScene": [ - "core", - "cocos2dPath/core/base-nodes/CCNode" - ], - - "cocos2dPath/core/sprites/CCBakeSprite": [ - "Sprite" - ], - - "cocos2dPath/core/layers/CCLayer": [ - "core", - "cocos2dPath/core/sprites/CCBakeSprite", - "cocos2dPath/core/layers/CCLayerWebGL", - "cocos2dPath/core/layers/CCLayerPropertyDefine" - ], - - "cocos2dPath/core/labelttf/CCLabelTTF": [ - "cocos2dPath/core/sprites/CCSprite", - "cocos2dPath/core/labelttf/LabelTTFWebGL", - "cocos2dPath/core/labelttf/LabelTTFPropertyDefine" - ], - - - - "cocos2dPath/menus/CCMenu" : [ - "cocos2dPath/core/layers/CCLayer" - ], - - "cocos2dPath/menus/CCMenuItem" : [ - "cocos2dPath/core/base-nodes/CCNode" - ], - - "cocos2dPath/core/sprites/CCSpriteBatchNode" : [ - "cocos2dPath/core/sprites/CCSprite" - ], - - "cocos2dPath/actions/CCAction" : [ - "core" - ], - "cocos2dPath/actions/CCActionInterval" : [ - "cocos2dPath/actions/CCAction" - ], - "cocos2dPath/actions/CCActionInstant" : [ - "cocos2dPath/actions/CCAction" - ], - - "cocos2dPath/labels/CCLabelBMFont" : [ - "cocos2dPath/core/sprites/CCSpriteBatchNode" - ], - - - - "core" : { - deps: [ - "root/CCBoot", - "root/CCDebugger", - "cocos2dPath/core/utils/BinaryLoader", - "root/Base64Images", - "cocos2dPath/core/platform/CCClass", - "cocos2dPath/core/platform/CCCommon", - "cocos2dPath/core/cocoa/CCGeometry", - "cocos2dPath/core/platform/CCSAXParser", - "cocos2dPath/core/platform/CCLoaders", - "cocos2dPath/core/platform/CCConfig", - "cocos2dPath/core/platform/miniFramework", - "cocos2dPath/core/platform/CCMacro", - "cocos2dPath/core/platform/CCTypesWebGL", - "cocos2dPath/core/platform/CCTypesPropertyDefine", - "cocos2dPath/core/platform/CCTypes", - "cocos2dPath/core/platform/CCEGLView", - "cocos2dPath/core/platform/CCScreen", - "cocos2dPath/core/platform/CCVisibleRect", - - - "cocos2dPath/core/platform/CCInputManager", - "cocos2dPath/core/platform/CCInputExtension", - - "cocos2dPath/core/cocoa/CCAffineTransform", - "cocos2dPath/core/support/CCPointExtension", - "cocos2dPath/core/support/CCVertex", - "cocos2dPath/core/support/TransformUtils", - "cocos2dPath/core/event-manager/CCTouch", +var require_config = {}; +if (requirejsSystemInfo.isNative) +{ + require_config = { + baseUrl: '../../samples', - "cocos2dPath/core/event-manager/CCEvent", - "cocos2dPath/core/event-manager/CCEventListener", - "cocos2dPath/core/event-manager/CCEventManager", - "cocos2dPath/core/event-manager/CCEventExtension", + paths: { + root: '', + cocos2dPath: '', + game: 'js-moonwarriors/src' // it's the flag to mark the user source + }, + shim: { + "actions":{ + init: function () { + return cc; + } + }, + "audio":{ + init: function () { + return cc.audioEngine; + } + }, + "core":{ + init: function () { + return cc; + } + }, + "LabelBMFont":{ + init: function () { + return cc.LabelBMFont; + } + }, + "LabelTTF":{ + init: function () { + return cc.LabelTTF; + } + }, + "layers":{ + init: function () { + return cc; + } + }, + "LoaderScene":{ + init: function () { + return cc.LoaderScene; + } + }, + "Menu":{ + init: function () { + return cc.Menu + } + }, + "menuitems":{ + init: function () { + return cc; + } + }, + "Node":{ + init: function () { + return cc.Node; + } + }, + "Scene":{ + init: function () { + return cc.Scene; + } + }, + "Sprite":{ + init: function () { + return cc.Sprite; + } + }, + "SpriteBatchNode":{ + init: function () { + return cc.SpriteBatchNode; + } + }, + + "cocos2dPath/transitions/CCTransition": { + init: function () { + return cc.TransitionFade; + } + }, + + "cocos2dPath/core/scenes/CCLoaderScene": { + init: function () { + return cc.LoaderScene; + } + }, + + "cocos2dPath/core/sprites/CCSprite": { + init: function () { + return cc.Sprite; + } + }, - "cocos2dPath/core/CCConfiguration", + "cocos2dPath/core/base-nodes/CCAtlasNode": { + init: function () { + return cc.NodeAtlas; + } + }, + + "cocos2dPath/core/sprites/CCAnimation": { + init: function () { + return cc.Animation; + } + }, + + "cocos2dPath/core/sprites/CCAnimationCache": { + init: function () { + return cc.animationCache; + } + }, + + "cocos2dPath/core/sprites/CCSpriteFrame": { + init: function () { + return cc.SpriteFrame; + } + }, + + "cocos2dPath/core/sprites/CCSpriteFrameCache": { + init: function () { + return cc.spriteFrameCache; + } + }, + + "cocos2dPath/actions/CCActionCamera": { + exports: "cc" + }, + "cocos2dPath/actions/CCActionEase": { + exports: "cc" + }, + "cocos2dPath/actions/CCActionCatmullRom": { + exports: "cc" + }, + "cocos2dPath/actions/CCActionTween": { + exports: "cc" + }, + + "cocos2dPath/audio/CCAudio": { + exports: "cc" + } + } + } +} +else +{ + require_config= { + baseUrl: '../../frameworks/cocos2d-html5/modules', + + paths: { + root: '../', + cocos2dPath: '../cocos2d', + game: '../../../samples/js-moonwarriors/src' + }, - "cocos2dPath/core/CCDirector", + shim: { + "cocos2dPath/core/platform/CCSAXParser": [ + "cocos2dPath/core/platform/CCClass" + ], + "cocos2dPath/core/platform/CCTypes": [ + "cocos2dPath/core/platform/CCClass" + ], + "cocos2dPath/core/CCScheduler": [ + "cocos2dPath/core/platform/CCClass" + ], + "cocos2dPath/core/event-manager/CCEventListener": [ + "cocos2dPath/core/platform/CCClass" + ], + "cocos2dPath/core/event-manager/CCTouch": [ + "cocos2dPath/core/platform/CCClass" + ], + + "cocos2dPath/core/CCCamera": [ + "cocos2dPath/core/platform/CCClass" + ], + + "cocos2dPath/core/platform/CCEGLView": [ + "cocos2dPath/core/platform/CCClass" + ], - "cocos2dPath/core/CCCamera", - "cocos2dPath/core/CCScheduler", + "cocos2dPath/core/CCDrawingPrimitiveCanvas": [ + "cocos2dPath/core/platform/CCClass" + ], - "cocos2dPath/core/CCActionManager", + "cocos2dPath/core/CCGLProgram": [ + "core", + "cocos2dPath/core/platform/CCClass" + ], - "cocos2dPath/core/CCDrawingPrimitivesCanvas", - "cocos2dPath/core/CCDrawingPrimitivesWebGL", + "cocos2dPath/core/event-manager/CCEvent": [ + "cocos2dPath/core/platform/CCClass" + ], - "cocos2dPath/core/textures/CCTexture2D", - "cocos2dPath/core/textures/CCTextureAtlas", - "cocos2dPath/core/textures/CCTextureCache", + "cocos2dPath/core/platform/CCConfig": [ + "cocos2dPath/core/cocoa/CCGeometry" + ], + "cocos2dPath/core/platform/CCVisibleRect": [ + "cocos2dPath/core/cocoa/CCGeometry" + ], + "cocos2dPath/core/platform/CCInputManager": [ + "cocos2dPath/core/cocoa/CCGeometry" + ], + "cocos2dPath/core/textures/CCTexture2D": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" + ], + "cocos2dPath/core/textures/CCTextureAtlas": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" + ], + "cocos2dPath/core/CCDirectorWebGL": [ + //"cocos2dPath/core/labelttf/CCLabelTTF" // 循环调用 + ], + "cocos2dPath/core/CCDirector": [ + "cocos2dPath/core/CCDirectorWebGL" + ], + "cocos2dPath/core/platform/CCInputExtension": [ + "cocos2dPath/core/platform/CCInputManager" + ], + "cocos2dPath/core/textures/CCTexture2D": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" + ], + "cocos2dPath/core/textures/CCTextureAtlas": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" + ], + "cocos2dPath/core/textures/CCTextureCache": [ + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" + ], + "cocos2dPath/core/event-manager/CCEventExtension": [ + "cocos2dPath/core/event-manager/CCEvent", + "cocos2dPath/core/event-manager/CCEventListener" + ], + "cocos2dPath/core/event-manager/CCEventManager": [ + "cocos2dPath/core/event-manager/CCEvent", + "cocos2dPath/core/event-manager/CCEventListener" + ], + "cocos2dPath/kazmath/gl/matrix": [ "cocos2dPath/kazmath/utility", "cocos2dPath/kazmath/vec2", "cocos2dPath/kazmath/vec3", @@ -2303,142 +2351,263 @@ var require_config = { "cocos2dPath/kazmath/plane", "cocos2dPath/kazmath/quaternion", "cocos2dPath/kazmath/aabb", - "cocos2dPath/kazmath/gl/mat4stack", - "cocos2dPath/kazmath/gl/matrix", - - "cocos2dPath/shaders/CCShaders", - "cocos2dPath/shaders/CCShaderCache", - "cocos2dPath/shaders/CCGLProgram", - "cocos2dPath/shaders/CCGLStateCache" + "cocos2dPath/kazmath/gl/mat4stack" ], - exports: "cc" - }, - - "cocos2dPath/transitions/CCTransition" : [ - "cocos2dPath/core/scenes/CCScene" - ], - - "cocos2dPath/transitions/CCTransition": { - deps: [ - "cocos2dPath/core/scenes/CCScene" + "cocos2dPath/core/base-nodes/CCNode": [ + "core", + "cocos2dPath/core/base-nodes/BaseNodesWebGL", + "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine" ], - init: function () { - return cc.TransitionFade; - } - }, - - "cocos2dPath/core/scenes/CCLoaderScene": { - deps: [ + "cocos2dPath/core/scenes/CCScene": [ "core", - "cocos2dPath/core/layers/CCLayer", - "cocos2dPath/core/labelttf/CCLabelTTF", - "cocos2dPath/core/scenes/CCScene" + "cocos2dPath/core/base-nodes/CCNode" ], - init: function () { - return cc.LoaderScene; - } - }, + "cocos2dPath/core/sprites/CCBakeSprite": [ + "Sprite" + ], - "cocos2dPath/core/sprites/CCSprite" : { - deps: [ + "cocos2dPath/core/layers/CCLayer": [ "core", - "Node", - "cocos2dPath/core/sprites/SpritesPropertyDefine", - "cocos2dPath/core/sprites/SpritesWebGL" + "cocos2dPath/core/sprites/CCBakeSprite", + "cocos2dPath/core/layers/CCLayerWebGL", + "cocos2dPath/core/layers/CCLayerPropertyDefine" ], - init: function() { - return cc.Sprite; - } - }, - "cocos2dPath/core/base-nodes/CCAtlasNode" : { - deps: [ - "Node" + "cocos2dPath/core/labelttf/CCLabelTTF": [ + "cocos2dPath/core/sprites/CCSprite", + "cocos2dPath/core/labelttf/LabelTTFWebGL", + "cocos2dPath/core/labelttf/LabelTTFPropertyDefine" ], - init: function() { - return cc.NodeAtlas; - } - }, - "cocos2dPath/core/sprites/CCAnimation" : { - deps: [ - "Sprite" - ], - init: function() { - return cc.Animation; - } - }, - "cocos2dPath/core/sprites/CCAnimationCache" : { - deps: [ - "Sprite", - "cocos2dPath/core/sprites/CCAnimation" + + "cocos2dPath/menus/CCMenu" : [ + "cocos2dPath/core/layers/CCLayer" ], - init: function() { - return cc.animationCache; - } - }, - "cocos2dPath/core/sprites/CCSpriteFrame" : { - deps: [ - "Sprite" + "cocos2dPath/menus/CCMenuItem" : [ + "cocos2dPath/core/base-nodes/CCNode" ], - init: function() { - return cc.SpriteFrame; - } - }, - "cocos2dPath/core/sprites/CCSpriteFrameCache" : { - deps: [ - "cocos2dPath/core/sprites/CCSpriteFrame" + "cocos2dPath/core/sprites/CCSpriteBatchNode" : [ + "cocos2dPath/core/sprites/CCSprite" ], - init: function() { - return cc.spriteFrameCache; - } - }, - "cocos2dPath/actions/CCActionCamera" : { - deps: [ - "core", - "cocos2dPath/actions/CCAction", - "cocos2dPath/actions/CCActionInterval" + "cocos2dPath/actions/CCAction" : [ + "core" ], - exports: "cc" - }, - "cocos2dPath/actions/CCActionEase" : { - deps: [ - "core", - "cocos2dPath/actions/CCAction", - "cocos2dPath/actions/CCActionInterval" + "cocos2dPath/actions/CCActionInterval" : [ + "cocos2dPath/actions/CCAction" ], - exports: "cc" - }, - "cocos2dPath/actions/CCActionCatmullRom" : { - deps: [ - "core", - "cocos2dPath/actions/CCAction", - "cocos2dPath/actions/CCActionInterval" + "cocos2dPath/actions/CCActionInstant" : [ + "cocos2dPath/actions/CCAction" ], - exports: "cc" - }, - "cocos2dPath/actions/CCActionTween" : { - deps: [ - "core", - "cocos2dPath/actions/CCAction", - "cocos2dPath/actions/CCActionInterval" + + "cocos2dPath/labels/CCLabelBMFont" : [ + "cocos2dPath/core/sprites/CCSpriteBatchNode" ], - exports: "cc" - }, - "cocos2dPath/audio/CCAudio" : { - deps: [ - "core", - "cocos2dPath/core/event-manager/CCEventManager" + "core" : { + deps: [ + "root/CCDebugger", + "cocos2dPath/core/utils/BinaryLoader", + "root/Base64Images", + "cocos2dPath/core/platform/CCClass", + "cocos2dPath/core/platform/CCCommon", + "cocos2dPath/core/cocoa/CCGeometry", + "cocos2dPath/core/platform/CCSAXParser", + "cocos2dPath/core/platform/CCLoaders", + "cocos2dPath/core/platform/CCConfig", + "cocos2dPath/core/platform/miniFramework", + "cocos2dPath/core/platform/CCMacro", + "cocos2dPath/core/platform/CCTypesWebGL", + "cocos2dPath/core/platform/CCTypesPropertyDefine", + "cocos2dPath/core/platform/CCTypes", + "cocos2dPath/core/platform/CCEGLView", + "cocos2dPath/core/platform/CCScreen", + "cocos2dPath/core/platform/CCVisibleRect", + + + "cocos2dPath/core/platform/CCInputManager", + "cocos2dPath/core/platform/CCInputExtension", + + "cocos2dPath/core/cocoa/CCAffineTransform", + "cocos2dPath/core/support/CCPointExtension", + "cocos2dPath/core/support/CCVertex", + "cocos2dPath/core/support/TransformUtils", + "cocos2dPath/core/event-manager/CCTouch", + + "cocos2dPath/core/event-manager/CCEvent", + "cocos2dPath/core/event-manager/CCEventListener", + "cocos2dPath/core/event-manager/CCEventManager", + "cocos2dPath/core/event-manager/CCEventExtension", + + "cocos2dPath/core/CCConfiguration", + + "cocos2dPath/core/CCDirector", + + "cocos2dPath/core/CCCamera", + "cocos2dPath/core/CCScheduler", + + "cocos2dPath/core/CCActionManager", + + "cocos2dPath/core/CCDrawingPrimitivesCanvas", + "cocos2dPath/core/CCDrawingPrimitivesWebGL", + + "cocos2dPath/core/textures/CCTexture2D", + "cocos2dPath/core/textures/CCTextureAtlas", + "cocos2dPath/core/textures/CCTextureCache", + + "cocos2dPath/kazmath/utility", + "cocos2dPath/kazmath/vec2", + "cocos2dPath/kazmath/vec3", + "cocos2dPath/kazmath/vec4", + "cocos2dPath/kazmath/ray2", + "cocos2dPath/kazmath/mat3", + "cocos2dPath/kazmath/mat4", + "cocos2dPath/kazmath/plane", + "cocos2dPath/kazmath/quaternion", + "cocos2dPath/kazmath/aabb", + "cocos2dPath/kazmath/gl/mat4stack", + "cocos2dPath/kazmath/gl/matrix", + + "cocos2dPath/shaders/CCShaders", + "cocos2dPath/shaders/CCShaderCache", + "cocos2dPath/shaders/CCGLProgram", + "cocos2dPath/shaders/CCGLStateCache" + ], + exports: "cc" + }, + + "cocos2dPath/transitions/CCTransition" : [ + + "cocos2dPath/core/scenes/CCScene" ], - exports: "cc" + + "cocos2dPath/transitions/CCTransition": { + deps: [ + "cocos2dPath/core/scenes/CCScene" + ], + + init: function () { + return cc.TransitionFade; + } + }, + + "cocos2dPath/core/scenes/CCLoaderScene": { + deps: [ + "core", + "cocos2dPath/core/layers/CCLayer", + "cocos2dPath/core/labelttf/CCLabelTTF", + "cocos2dPath/core/scenes/CCScene" + ], + + init: function () { + return cc.LoaderScene; + } + }, + + "cocos2dPath/core/sprites/CCSprite" : { + deps: [ + "core", + "Node", + "cocos2dPath/core/sprites/SpritesPropertyDefine", + "cocos2dPath/core/sprites/SpritesWebGL" + ], + init: function() { + return cc.Sprite; + } + }, + + "cocos2dPath/core/base-nodes/CCAtlasNode" : { + deps: [ + "Node" + ], + init: function() { + return cc.NodeAtlas; + } + }, + + "cocos2dPath/core/sprites/CCAnimation" : { + deps: [ + "Sprite" + ], + init: function() { + return cc.Animation; + } + }, + + "cocos2dPath/core/sprites/CCAnimationCache" : { + deps: [ + "Sprite", + "cocos2dPath/core/sprites/CCAnimation" + ], + init: function() { + return cc.animationCache; + } + }, + + "cocos2dPath/core/sprites/CCSpriteFrame" : { + deps: [ + "Sprite" + ], + init: function() { + return cc.SpriteFrame; + } + }, + + "cocos2dPath/core/sprites/CCSpriteFrameCache" : { + deps: [ + "cocos2dPath/core/sprites/CCSpriteFrame" + ], + init: function() { + return cc.spriteFrameCache; + } + }, + + "cocos2dPath/actions/CCActionCamera" : { + deps: [ + "core", + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" + ], + exports: "cc" + }, + "cocos2dPath/actions/CCActionEase" : { + deps: [ + "core", + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" + ], + exports: "cc" + }, + "cocos2dPath/actions/CCActionCatmullRom" : { + deps: [ + "core", + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" + ], + exports: "cc" + }, + "cocos2dPath/actions/CCActionTween" : { + deps: [ + "core", + "cocos2dPath/actions/CCAction", + "cocos2dPath/actions/CCActionInterval" + ], + exports: "cc" + }, + + "cocos2dPath/audio/CCAudio" : { + deps: [ + "core", + "cocos2dPath/core/event-manager/CCEventManager" + ], + exports: "cc" + } } - } -}; \ No newline at end of file + }; +} From 021b03e8460d7ab07784540621dd6a0e333a8f69 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Fri, 24 Oct 2014 18:24:40 +0800 Subject: [PATCH 08/32] modify index.html, improve to use the requirejs. Only use the useRequireJS property in project.json --- CCBoot.js | 41 ++++++++++------ modules/LabelBMFont.js | 2 +- modules/LabelTTF.js | 2 +- modules/Menu.js | 4 +- modules/Node.js | 2 +- modules/Sprite.js | 4 +- modules/actions.js | 2 +- modules/audio.js | 2 +- modules/core.js | 2 +- modules/layers.js | 2 +- modules/menuitems.js | 6 +-- require.js | 109 +++++++++++++++++++++++------------------ 12 files changed, 103 insertions(+), 75 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 43caefd92e..d56e7ff4c3 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -1954,7 +1954,8 @@ cc.game = /** @lends cc.game# */{ id: "id", renderMode: "renderMode", jsList: "jsList", - classReleaseMode: "classReleaseMode" + classReleaseMode: "classReleaseMode", + useRequireJS:"useRequireJS" }, _prepareCalled: false,//whether the prepare function has been called @@ -2128,13 +2129,19 @@ cc.game = /** @lends cc.game# */{ var jsList = config[CONFIG_KEY.jsList] || []; if (cc.Class) {//is single file - //load user's jsList only -// loader.loadJsWithImg("", jsList, function (err) { -// if (err) throw err; -// self._prepared = true; -// if (cb) cb(); -// }); - cb(); + if (config[CONFIG_KEY.useRequireJS]) + { + if (cb) cb(); + } + else + { + //load user's jsList only + loader.loadJsWithImg("", jsList, function (err) { + if (err) throw err; + self._prepared = true; + if (cb) cb(); + }); + } } else { //load cc's jsList first var ccModulesPath = cc.path.join(engineDir, "moduleConfig.json"); @@ -2150,12 +2157,18 @@ cc.game = /** @lends cc.game# */{ if (arr) newJsList = newJsList.concat(arr); } newJsList = newJsList.concat(jsList); -// cc.loader.loadJsWithImg(newJsList, function (err) { -// if (err) throw err; -// self._prepared = true; -// if (cb) cb(); -// }); - cb(); + if (config[CONFIG_KEY.useRequireJS]) + { + if (cb) cb(); + } + else { + cc.loader.loadJsWithImg(newJsList, function (err) { + if (err) throw err; + self._prepared = true; + if (cb) cb(); + }); + } + }); } } diff --git a/modules/LabelBMFont.js b/modules/LabelBMFont.js index 23aa3bf1c5..6a0c9d498e 100644 --- a/modules/LabelBMFont.js +++ b/modules/LabelBMFont.js @@ -1,5 +1,5 @@ define([ - "SpriteBatchNode", + "cocosModule/SpriteBatchNode", "cocos2dPath/labels/CCLabelBMFont" ], function() { return cc.LabelBMFont; diff --git a/modules/LabelTTF.js b/modules/LabelTTF.js index b25ea3baaf..8807061e58 100644 --- a/modules/LabelTTF.js +++ b/modules/LabelTTF.js @@ -1,5 +1,5 @@ define([ - "Sprite", + "cocosModule/Sprite", "cocos2dPath/core/labelttf/CCLabelTTF" ], function() { return cc.LabelTTF; diff --git a/modules/Menu.js b/modules/Menu.js index 70a5084df7..15f9b0432b 100644 --- a/modules/Menu.js +++ b/modules/Menu.js @@ -1,6 +1,6 @@ define([ - "core", - "actions", + "cocosModule/core", + "cocosModule/actions", "cocos2dPath/menus/CCMenu" ], function() { return cc.Menu; diff --git a/modules/Node.js b/modules/Node.js index 26c3b9af80..46f072c8c9 100644 --- a/modules/Node.js +++ b/modules/Node.js @@ -1,5 +1,5 @@ define([ - "core", + "cocosModule/core", "cocos2dPath/core/base-nodes/CCNode", "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine", "cocos2dPath/core/base-nodes/BaseNodesWebGL" diff --git a/modules/Sprite.js b/modules/Sprite.js index 0bf5a32577..1361c68afe 100644 --- a/modules/Sprite.js +++ b/modules/Sprite.js @@ -1,6 +1,6 @@ define([ - "core", - "Node", + "cocosModule/core", + "cocosModule/Node", "cocos2dPath/core/sprites/CCSprite", "cocos2dPath/core/sprites/SpritesPropertyDefine", "cocos2dPath/core/sprites/SpritesWebGL" diff --git a/modules/actions.js b/modules/actions.js index 9ab0876f58..e67a6d4685 100644 --- a/modules/actions.js +++ b/modules/actions.js @@ -1,5 +1,5 @@ define([ - "core", + "cocosModule/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval", "cocos2dPath/actions/CCActionInstant" diff --git a/modules/audio.js b/modules/audio.js index 840640c524..c8a0f04266 100644 --- a/modules/audio.js +++ b/modules/audio.js @@ -1,5 +1,5 @@ define([ - "core", + "cocosModule/core", "cocos2dPath/audio/CCAudio" ], function(cc) { return cc.audioEngine; diff --git a/modules/core.js b/modules/core.js index 28acb3b34a..4be471e38f 100644 --- a/modules/core.js +++ b/modules/core.js @@ -1,3 +1,3 @@ -define(["root/CCBoot"], function() { +define([], function() { return cc; }); \ No newline at end of file diff --git a/modules/layers.js b/modules/layers.js index 56d0f6e452..87844b1175 100644 --- a/modules/layers.js +++ b/modules/layers.js @@ -1,5 +1,5 @@ define([ - "Sprite", + "cocosModule/Sprite", "cocos2dPath/core/layers/CCLayer" ], function() { return cc; diff --git a/modules/menuitems.js b/modules/menuitems.js index 83b8a24ad5..2a0dc5731c 100644 --- a/modules/menuitems.js +++ b/modules/menuitems.js @@ -1,7 +1,7 @@ define([ - "core", - "actions", - "Menu", + "cocosModule/core", + "cocosModule/actions", + "cocosModule/Menu", "cocos2dPath/menus/CCMenuItem" ], function() { return cc; diff --git a/require.js b/require.js index 2d345f6219..a6af5400fe 100644 --- a/require.js +++ b/require.js @@ -14,6 +14,7 @@ if (typeof sys !== "undefined") { requirejsSystemInfo = sys; } +var cocosEngineDir = cc.game.config[cc.game.CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5"; // use to mark the cocos file (function (global) { var req, s, head, baseElement, dataMain, src, interactiveScript, currentlyAddingScript, mainScript, subPath, @@ -1942,7 +1943,7 @@ if (typeof sys !== "undefined") } } else if (isNative) { - if (url.indexOf(require_config.paths.game) != -1) + if (url.indexOf(cocosEngineDir) == -1) { require(url); } @@ -2103,75 +2104,75 @@ var require_config = {}; if (requirejsSystemInfo.isNative) { require_config = { - baseUrl: '../../samples', - + baseUrl: '', paths: { - root: '', - cocos2dPath: '', - game: 'js-moonwarriors/src' // it's the flag to mark the user source + cocosModule:'../../frameworks/cocos2d-html5/modules', + root: '../../frameworks/cocos2d-html5', + cocos2dPath: '../../frameworks/cocos2d-html5/cocos2d', + game: 'src' }, shim: { - "actions":{ + "cocosModule/actions":{ init: function () { return cc; } }, - "audio":{ + "cocosModule/audio":{ init: function () { return cc.audioEngine; } }, - "core":{ + "cocosModule/core":{ init: function () { return cc; } }, - "LabelBMFont":{ + "cocosModule/LabelBMFont":{ init: function () { return cc.LabelBMFont; } }, - "LabelTTF":{ + "cocosModule/LabelTTF":{ init: function () { return cc.LabelTTF; } }, - "layers":{ + "cocosModule/layers":{ init: function () { return cc; } }, - "LoaderScene":{ + "cocosModule/LoaderScene":{ init: function () { return cc.LoaderScene; } }, - "Menu":{ + "cocosModule/Menu":{ init: function () { return cc.Menu } }, - "menuitems":{ + "cocosModule/menuitems":{ init: function () { return cc; } }, - "Node":{ + "cocosModule/Node":{ init: function () { return cc.Node; } }, - "Scene":{ + "cocosModule/Scene":{ init: function () { return cc.Scene; } }, - "Sprite":{ + "cocosModule/Sprite":{ init: function () { return cc.Sprite; } }, - "SpriteBatchNode":{ + "cocosModule/SpriteBatchNode":{ init: function () { return cc.SpriteBatchNode; } @@ -2225,6 +2226,12 @@ if (requirejsSystemInfo.isNative) } }, + "cocos2dPath/core/labelttf/CCLabelTTF": { + init: function () { + return cc.LabelTTF; + } + }, + "cocos2dPath/actions/CCActionCamera": { exports: "cc" }, @@ -2247,12 +2254,13 @@ if (requirejsSystemInfo.isNative) else { require_config= { - baseUrl: '../../frameworks/cocos2d-html5/modules', + baseUrl: '', paths: { - root: '../', - cocos2dPath: '../cocos2d', - game: '../../../samples/js-moonwarriors/src' + cocosModule:'../../frameworks/cocos2d-html5/modules', + root: '../../frameworks/cocos2d-html5', + cocos2dPath: '../../frameworks/cocos2d-html5/cocos2d', + game: 'src' }, shim: { @@ -2285,7 +2293,7 @@ else ], "cocos2dPath/core/CCGLProgram": [ - "core", + "cocosModule/core", "cocos2dPath/core/platform/CCClass" ], @@ -2355,32 +2363,28 @@ else ], "cocos2dPath/core/base-nodes/CCNode": [ - "core", + "cocosModule/core", "cocos2dPath/core/base-nodes/BaseNodesWebGL", "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine" ], "cocos2dPath/core/scenes/CCScene": [ - "core", + "cocosModule/core", "cocos2dPath/core/base-nodes/CCNode" ], "cocos2dPath/core/sprites/CCBakeSprite": [ - "Sprite" + "cocosModule/Sprite" ], "cocos2dPath/core/layers/CCLayer": [ - "core", + "cocosModule/core", "cocos2dPath/core/sprites/CCBakeSprite", "cocos2dPath/core/layers/CCLayerWebGL", "cocos2dPath/core/layers/CCLayerPropertyDefine" ], - "cocos2dPath/core/labelttf/CCLabelTTF": [ - "cocos2dPath/core/sprites/CCSprite", - "cocos2dPath/core/labelttf/LabelTTFWebGL", - "cocos2dPath/core/labelttf/LabelTTFPropertyDefine" - ], + @@ -2397,7 +2401,7 @@ else ], "cocos2dPath/actions/CCAction" : [ - "core" + "cocosModule/core" ], "cocos2dPath/actions/CCActionInterval" : [ "cocos2dPath/actions/CCAction" @@ -2410,7 +2414,7 @@ else "cocos2dPath/core/sprites/CCSpriteBatchNode" ], - "core" : { + "cocosModule/core" : { deps: [ "root/CCDebugger", "cocos2dPath/core/utils/BinaryLoader", @@ -2487,6 +2491,17 @@ else "cocos2dPath/core/scenes/CCScene" ], + "cocos2dPath/core/labelttf/CCLabelTTF": { + deps: [ + "cocos2dPath/core/sprites/CCSprite", + "cocos2dPath/core/labelttf/LabelTTFWebGL", + "cocos2dPath/core/labelttf/LabelTTFPropertyDefine" + ], + init: function () { + return cc.LabelTTF; + } + }, + "cocos2dPath/transitions/CCTransition": { deps: [ "cocos2dPath/core/scenes/CCScene" @@ -2499,7 +2514,7 @@ else "cocos2dPath/core/scenes/CCLoaderScene": { deps: [ - "core", + "cocosModule/core", "cocos2dPath/core/layers/CCLayer", "cocos2dPath/core/labelttf/CCLabelTTF", "cocos2dPath/core/scenes/CCScene" @@ -2512,8 +2527,8 @@ else "cocos2dPath/core/sprites/CCSprite" : { deps: [ - "core", - "Node", + "cocosModule/core", + "cocosModule/Node", "cocos2dPath/core/sprites/SpritesPropertyDefine", "cocos2dPath/core/sprites/SpritesWebGL" ], @@ -2524,7 +2539,7 @@ else "cocos2dPath/core/base-nodes/CCAtlasNode" : { deps: [ - "Node" + "cocosModule/Node" ], init: function() { return cc.NodeAtlas; @@ -2533,7 +2548,7 @@ else "cocos2dPath/core/sprites/CCAnimation" : { deps: [ - "Sprite" + "cocosModule/Sprite" ], init: function() { return cc.Animation; @@ -2542,7 +2557,7 @@ else "cocos2dPath/core/sprites/CCAnimationCache" : { deps: [ - "Sprite", + "cocosModule/Sprite", "cocos2dPath/core/sprites/CCAnimation" ], init: function() { @@ -2552,7 +2567,7 @@ else "cocos2dPath/core/sprites/CCSpriteFrame" : { deps: [ - "Sprite" + "cocosModule/Sprite" ], init: function() { return cc.SpriteFrame; @@ -2570,7 +2585,7 @@ else "cocos2dPath/actions/CCActionCamera" : { deps: [ - "core", + "cocosModule/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2578,7 +2593,7 @@ else }, "cocos2dPath/actions/CCActionEase" : { deps: [ - "core", + "cocosModule/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2586,7 +2601,7 @@ else }, "cocos2dPath/actions/CCActionCatmullRom" : { deps: [ - "core", + "cocosModule/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2594,7 +2609,7 @@ else }, "cocos2dPath/actions/CCActionTween" : { deps: [ - "core", + "cocosModule/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2603,7 +2618,7 @@ else "cocos2dPath/audio/CCAudio" : { deps: [ - "core", + "cocosModule/core", "cocos2dPath/core/event-manager/CCEventManager" ], exports: "cc" From 2eb2e678bb28fe5ac3f94c241621f029701f5806 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 17 Nov 2014 16:31:19 +0800 Subject: [PATCH 09/32] Fixed #15: Supported local file loading with Brackets --- CCBoot.js | 8 ++++---- cocos2d/core/utils/BinaryLoader.js | 8 ++++---- extensions/ccb-reader/CCBReader.js | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 5484d8827f..9081947526 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -665,13 +665,13 @@ cc.loader = /** @lends cc.loader# */{ xhr.setRequestHeader("Accept-Charset", "utf-8"); xhr.onreadystatechange = function () { if(xhr.readyState == 4) - xhr.status == 200 ? cb(null, xhr.responseText) : cb(errInfo); + xhr.status < 400 ? cb(null, xhr.responseText) : cb(errInfo); }; } else { if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8"); xhr.onload = function () { if(xhr.readyState == 4) - xhr.status == 200 ? cb(null, xhr.responseText) : cb(errInfo); + xhr.status < 400 ? cb(null, xhr.responseText) : cb(errInfo); }; } xhr.send(null); @@ -693,7 +693,7 @@ cc.loader = /** @lends cc.loader# */{ if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8"); } xhr.send(null); - if (!xhr.readyState == 4 || xhr.status != 200) { + if (!xhr.readyState == 4 || xhr.status >= 400) { return null; } return xhr.responseText; @@ -714,7 +714,7 @@ cc.loader = /** @lends cc.loader# */{ window.msg = arrayBuffer; } if(xhr.readyState == 4) - xhr.status == 200 ? cb(null, xhr.response) : cb("load " + url + " failed!"); + xhr.status < 400 ? cb(null, xhr.response) : cb("load " + url + " failed!"); }; xhr.send(null); diff --git a/cocos2d/core/utils/BinaryLoader.js b/cocos2d/core/utils/BinaryLoader.js index 9478bd06ae..8109235859 100644 --- a/cocos2d/core/utils/BinaryLoader.js +++ b/cocos2d/core/utils/BinaryLoader.js @@ -41,7 +41,7 @@ cc.loader.loadBinary = function (url, cb) { // IE-specific logic here xhr.setRequestHeader("Accept-Charset", "x-user-defined"); xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && xhr.status == 200) { + if (xhr.readyState == 4 && xhr.status < 400) { var fileContents = cc._convertResponseBodyToText(xhr["responseBody"]); cb(null, self._str2Uint8Array(fileContents)); } else cb(errInfo); @@ -49,7 +49,7 @@ cc.loader.loadBinary = function (url, cb) { } else { if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=x-user-defined"); xhr.onload = function () { - xhr.readyState == 4 && xhr.status == 200 ? cb(null, self._str2Uint8Array(xhr.responseText)) : cb(errInfo); + xhr.readyState == 4 && xhr.status < 400 ? cb(null, self._str2Uint8Array(xhr.responseText)) : cb(errInfo); }; } xhr.send(null); @@ -81,7 +81,7 @@ cc.loader.loadBinarySync = function (url) { if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { req.setRequestHeader("Accept-Charset", "x-user-defined"); req.send(null); - if (req.status != 200) { + if (req.status >= 400) { cc.log(errInfo); return null; } @@ -94,7 +94,7 @@ cc.loader.loadBinarySync = function (url) { if (req.overrideMimeType) req.overrideMimeType('text\/plain; charset=x-user-defined'); req.send(null); - if (req.status != 200) { + if (req.status >= 400) { cc.log(errInfo); return null; } diff --git a/extensions/ccb-reader/CCBReader.js b/extensions/ccb-reader/CCBReader.js index 98d8512233..08fe57799d 100644 --- a/extensions/ccb-reader/CCBReader.js +++ b/extensions/ccb-reader/CCBReader.js @@ -222,7 +222,7 @@ cc.BuilderReader = cc.Class.extend({ if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { req.setRequestHeader("Accept-Charset", "x-user-defined"); req.send(null); - if (req.status != 200) { + if (req.status >= 400) { cc.log(errInfo); return null; } @@ -236,7 +236,7 @@ cc.BuilderReader = cc.Class.extend({ if (req.overrideMimeType) req.overrideMimeType('text\/plain; charset=x-user-defined'); req.send(null); - if (req.status != 200) { + if (req.status >= 400) { cc.log(errInfo); return null; } From efd15388c90817d51c89b1622febc91107921977 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 19 Nov 2014 15:30:18 +0800 Subject: [PATCH 10/32] #19: Support property registration and add properties in base nodes --- .../base-nodes/BaseNodesPropertyDefine.js | 68 +++++++++---------- .../core/labelttf/LabelTTFPropertyDefine.js | 38 +++++------ cocos2d/core/layers/CCLayerPropertyDefine.js | 14 ++-- cocos2d/core/platform/CCClass.js | 9 +++ cocos2d/core/sprites/SpritesPropertyDefine.js | 22 +++--- cocos2d/core/textures/CCTextureAtlas.js | 6 +- .../core/textures/TexturesPropertyDefine.js | 20 +++--- 7 files changed, 93 insertions(+), 84 deletions(-) diff --git a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js index 4bf8e9d429..49240ecb07 100644 --- a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js +++ b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js @@ -28,77 +28,77 @@ cc._tmp.PrototypeCCNode = function () { var _p = cc.Node.prototype; - cc.defineGetterSetter(_p, "x", _p.getPositionX, _p.setPositionX); - cc.defineGetterSetter(_p, "y", _p.getPositionY, _p.setPositionY); + cc.addProperty(_p, "x", _p.getPositionX, _p.setPositionX); + cc.addProperty(_p, "y", _p.getPositionY, _p.setPositionY); /** @expose */ //_p.pos; - //cc.defineGetterSetter(_p, "pos", _p.getPosition, _p.setPosition); + //cc.addProperty(_p, "pos", _p.getPosition, _p.setPosition); /** @expose */ _p.width; - cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth); + cc.addProperty(_p, "width", _p._getWidth, _p._setWidth); /** @expose */ _p.height; - cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight); + cc.addProperty(_p, "height", _p._getHeight, _p._setHeight); /** @expose */ //_p.size; - //cc.defineGetterSetter(_p, "size", _p.getContentSize, _p.setContentSize); + //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); /** @expose */ //_p.anchor; - //cc.defineGetterSetter(_p, "anchor", _p._getAnchor, _p._setAnchor); + //cc.addProperty(_p, "anchor", _p._getAnchor, _p._setAnchor); /** @expose */ _p.anchorX; - cc.defineGetterSetter(_p, "anchorX", _p._getAnchorX, _p._setAnchorX); + cc.addProperty(_p, "anchorX", _p._getAnchorX, _p._setAnchorX); /** @expose */ _p.anchorY; - cc.defineGetterSetter(_p, "anchorY", _p._getAnchorY, _p._setAnchorY); + cc.addProperty(_p, "anchorY", _p._getAnchorY, _p._setAnchorY); /** @expose */ _p.skewX; - cc.defineGetterSetter(_p, "skewX", _p.getSkewX, _p.setSkewX); + cc.addProperty(_p, "skewX", _p.getSkewX, _p.setSkewX); /** @expose */ _p.skewY; - cc.defineGetterSetter(_p, "skewY", _p.getSkewY, _p.setSkewY); + cc.addProperty(_p, "skewY", _p.getSkewY, _p.setSkewY); /** @expose */ _p.zIndex; - cc.defineGetterSetter(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); + cc.addProperty(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); /** @expose */ _p.vertexZ; - cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); + cc.addProperty(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); /** @expose */ _p.rotation; - cc.defineGetterSetter(_p, "rotation", _p.getRotation, _p.setRotation); + cc.addProperty(_p, "rotation", _p.getRotation, _p.setRotation); /** @expose */ _p.rotationX; - cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX); + cc.addProperty(_p, "rotationX", _p.getRotationX, _p.setRotationX); /** @expose */ _p.rotationY; - cc.defineGetterSetter(_p, "rotationY", _p.getRotationY, _p.setRotationY); + cc.addProperty(_p, "rotationY", _p.getRotationY, _p.setRotationY); /** @expose */ _p.scale; - cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale); + cc.addProperty(_p, "scale", _p.getScale, _p.setScale); /** @expose */ _p.scaleX; - cc.defineGetterSetter(_p, "scaleX", _p.getScaleX, _p.setScaleX); + cc.addProperty(_p, "scaleX", _p.getScaleX, _p.setScaleX); /** @expose */ _p.scaleY; - cc.defineGetterSetter(_p, "scaleY", _p.getScaleY, _p.setScaleY); + cc.addProperty(_p, "scaleY", _p.getScaleY, _p.setScaleY); /** @expose */ _p.children; - cc.defineGetterSetter(_p, "children", _p.getChildren); + cc.addProperty(_p, "children", _p.getChildren); /** @expose */ _p.childrenCount; - cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount); + cc.addProperty(_p, "childrenCount", _p.getChildrenCount); /** @expose */ _p.parent; - cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent); + cc.addProperty(_p, "parent", _p.getParent, _p.setParent); /** @expose */ _p.visible; - cc.defineGetterSetter(_p, "visible", _p.isVisible, _p.setVisible); + cc.addProperty(_p, "visible", _p.isVisible, _p.setVisible); /** @expose */ _p.running; - cc.defineGetterSetter(_p, "running", _p.isRunning); + cc.addProperty(_p, "running", _p.isRunning); /** @expose */ _p.ignoreAnchor; - cc.defineGetterSetter(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); + cc.addProperty(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); /** @expose */ _p.tag; /** @expose */ @@ -109,28 +109,28 @@ cc._tmp.PrototypeCCNode = function () { _p.arrivalOrder; /** @expose */ _p.actionManager; - cc.defineGetterSetter(_p, "actionManager", _p.getActionManager, _p.setActionManager); + cc.addProperty(_p, "actionManager", _p.getActionManager, _p.setActionManager); /** @expose */ _p.scheduler; - cc.defineGetterSetter(_p, "scheduler", _p.getScheduler, _p.setScheduler); - //cc.defineGetterSetter(_p, "boundingBox", _p.getBoundingBox); + cc.addProperty(_p, "scheduler", _p.getScheduler, _p.setScheduler); + //cc.addProperty(_p, "boundingBox", _p.getBoundingBox); /** @expose */ _p.shaderProgram; - cc.defineGetterSetter(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram); + cc.addProperty(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram); /** @expose */ _p.opacity; - cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); + cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); /** @expose */ _p.opacityModifyRGB; - cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB); + cc.addProperty(_p, "opacityModifyRGB", _p.isOpacityModifyRGB); /** @expose */ _p.cascadeOpacity; - cc.defineGetterSetter(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); + cc.addProperty(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); /** @expose */ _p.color; - cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); + cc.addProperty(_p, "color", _p.getColor, _p.setColor); /** @expose */ _p.cascadeColor; - cc.defineGetterSetter(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); + cc.addProperty(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); }; \ No newline at end of file diff --git a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js index 71ff3a964a..2e691929c9 100644 --- a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js +++ b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js @@ -29,60 +29,60 @@ cc._tmp.PrototypeLabelTTF = function () { var _p = cc.LabelTTF.prototype; // Override properties - cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); - cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); + cc.addProperty(_p, "color", _p.getColor, _p.setColor); + cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); // Extended properties /** @expose */ _p.string; - cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); + cc.addProperty(_p, "string", _p.getString, _p.setString); /** @expose */ _p.textAlign; - cc.defineGetterSetter(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment); + cc.addProperty(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment); /** @expose */ _p.verticalAlign; - cc.defineGetterSetter(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment); + cc.addProperty(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment); /** @expose */ _p.fontSize; - cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize); + cc.addProperty(_p, "fontSize", _p.getFontSize, _p.setFontSize); /** @expose */ _p.fontName; - cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName); + cc.addProperty(_p, "fontName", _p.getFontName, _p.setFontName); /** @expose */ _p.font; - cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); + cc.addProperty(_p, "font", _p._getFont, _p._setFont); /** @expose */ _p.boundingSize; - //cc.defineGetterSetter(_p, "boundingSize", _p.getDimensions, _p.setDimensions); + //cc.addProperty(_p, "boundingSize", _p.getDimensions, _p.setDimensions); /** @expose */ _p.boundingWidth; - cc.defineGetterSetter(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth); + cc.addProperty(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth); /** @expose */ _p.boundingHeight; - cc.defineGetterSetter(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight); + cc.addProperty(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight); /** @expose */ _p.fillStyle; - cc.defineGetterSetter(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); + cc.addProperty(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); /** @expose */ _p.strokeStyle; - cc.defineGetterSetter(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); + cc.addProperty(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); /** @expose */ _p.lineWidth; - cc.defineGetterSetter(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth); + cc.addProperty(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth); /** @expose */ _p.shadowOffset; - //cc.defineGetterSetter(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); + //cc.addProperty(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); /** @expose */ _p.shadowOffsetX; - cc.defineGetterSetter(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX); + cc.addProperty(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX); /** @expose */ _p.shadowOffsetY; - cc.defineGetterSetter(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY); + cc.addProperty(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY); /** @expose */ _p.shadowOpacity; - cc.defineGetterSetter(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity); + cc.addProperty(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity); /** @expose */ _p.shadowBlur; - cc.defineGetterSetter(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur); + cc.addProperty(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur); }; \ No newline at end of file diff --git a/cocos2d/core/layers/CCLayerPropertyDefine.js b/cocos2d/core/layers/CCLayerPropertyDefine.js index 0600fa1dd6..e08f5ff20c 100644 --- a/cocos2d/core/layers/CCLayerPropertyDefine.js +++ b/cocos2d/core/layers/CCLayerPropertyDefine.js @@ -27,8 +27,8 @@ cc._tmp.PrototypeLayerColor = function () { var _p = cc.LayerColor.prototype; // Override properties - cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth); - cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight); + cc.addProperty(_p, "width", _p._getWidth, _p._setWidth); + cc.addProperty(_p, "height", _p._getHeight, _p._setHeight); }; cc._tmp.PrototypeLayerGradient = function () { @@ -36,17 +36,17 @@ cc._tmp.PrototypeLayerGradient = function () { // Extended properties /** @expose */ _p.startColor; - cc.defineGetterSetter(_p, "startColor", _p.getStartColor, _p.setStartColor); + cc.addProperty(_p, "startColor", _p.getStartColor, _p.setStartColor); /** @expose */ _p.endColor; - cc.defineGetterSetter(_p, "endColor", _p.getEndColor, _p.setEndColor); + cc.addProperty(_p, "endColor", _p.getEndColor, _p.setEndColor); /** @expose */ _p.startOpacity; - cc.defineGetterSetter(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity); + cc.addProperty(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity); /** @expose */ _p.endOpacity; - cc.defineGetterSetter(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity); + cc.addProperty(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity); /** @expose */ _p.vector; - cc.defineGetterSetter(_p, "vector", _p.getVector, _p.setVector); + cc.addProperty(_p, "vector", _p.getVector, _p.setVector); }; \ No newline at end of file diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 01b6643042..39ef3da6ac 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -282,6 +282,15 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette } }; +cc.addProperty = function(proto, prop, getter, setter) { + cc.defineGetterSetter(proto, prop, getter, setter); + + if (!proto.__props) { + proto.__props = []; + } + proto.__props.push(prop); +}; + /** * Create a new object and copy all properties in an exist object to the new object * @function diff --git a/cocos2d/core/sprites/SpritesPropertyDefine.js b/cocos2d/core/sprites/SpritesPropertyDefine.js index 20e8cc938a..5d7d617288 100644 --- a/cocos2d/core/sprites/SpritesPropertyDefine.js +++ b/cocos2d/core/sprites/SpritesPropertyDefine.js @@ -28,40 +28,40 @@ cc._tmp.PrototypeSprite = function () { var _p = cc.Sprite.prototype; // Override properties - cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); - cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); - cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); + cc.addProperty(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); + cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); + cc.addProperty(_p, "color", _p.getColor, _p.setColor); // Extended properties /** @expose */ _p.dirty; /** @expose */ _p.flippedX; - cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX); + cc.addProperty(_p, "flippedX", _p.isFlippedX, _p.setFlippedX); /** @expose */ _p.flippedY; - cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); + cc.addProperty(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); /** @expose */ _p.offsetX; - cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX); + cc.addProperty(_p, "offsetX", _p._getOffsetX); /** @expose */ _p.offsetY; - cc.defineGetterSetter(_p, "offsetY", _p._getOffsetY); + cc.addProperty(_p, "offsetY", _p._getOffsetY); /** @expose */ _p.atlasIndex; /** @expose */ _p.texture; - cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture); + cc.addProperty(_p, "texture", _p.getTexture, _p.setTexture); /** @expose */ _p.textureRectRotated; - cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated); + cc.addProperty(_p, "textureRectRotated", _p.isTextureRectRotated); /** @expose */ _p.textureAtlas; /** @expose */ _p.batchNode; - cc.defineGetterSetter(_p, "batchNode", _p.getBatchNode, _p.setBatchNode); + cc.addProperty(_p, "batchNode", _p.getBatchNode, _p.setBatchNode); /** @expose */ _p.quad; - cc.defineGetterSetter(_p, "quad", _p.getQuad); + cc.addProperty(_p, "quad", _p.getQuad); }; diff --git a/cocos2d/core/textures/CCTextureAtlas.js b/cocos2d/core/textures/CCTextureAtlas.js index c08c610078..f1b753abfb 100644 --- a/cocos2d/core/textures/CCTextureAtlas.js +++ b/cocos2d/core/textures/CCTextureAtlas.js @@ -616,13 +616,13 @@ var _p = cc.TextureAtlas.prototype; // Extended properties /** @expose */ _p.totalQuads; -cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads); +cc.addProperty(_p, "totalQuads", _p.getTotalQuads); /** @expose */ _p.capacity; -cc.defineGetterSetter(_p, "capacity", _p.getCapacity); +cc.addProperty(_p, "capacity", _p.getCapacity); /** @expose */ _p.quads; -cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads); +cc.addProperty(_p, "quads", _p.getQuads, _p.setQuads); /** *

Creates a TextureAtlas with an filename and with an initial capacity for Quads.
diff --git a/cocos2d/core/textures/TexturesPropertyDefine.js b/cocos2d/core/textures/TexturesPropertyDefine.js index fe1eef3801..b83213e43b 100644 --- a/cocos2d/core/textures/TexturesPropertyDefine.js +++ b/cocos2d/core/textures/TexturesPropertyDefine.js @@ -181,23 +181,23 @@ cc._tmp.PrototypeTexture2D = function () { // Extended properties /** @expose */ _p.name; - cc.defineGetterSetter(_p, "name", _p.getName); + cc.addProperty(_p, "name", _p.getName); /** @expose */ _p.pixelFormat; - cc.defineGetterSetter(_p, "pixelFormat", _p.getPixelFormat); + cc.addProperty(_p, "pixelFormat", _p.getPixelFormat); /** @expose */ _p.pixelsWidth; - cc.defineGetterSetter(_p, "pixelsWidth", _p.getPixelsWide); + cc.addProperty(_p, "pixelsWidth", _p.getPixelsWide); /** @expose */ _p.pixelsHeight; - cc.defineGetterSetter(_p, "pixelsHeight", _p.getPixelsHigh); - //cc.defineGetterSetter(_p, "size", _p.getContentSize, _p.setContentSize); + cc.addProperty(_p, "pixelsHeight", _p.getPixelsHigh); + //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); /** @expose */ _p.width; - cc.defineGetterSetter(_p, "width", _p._getWidth); + cc.addProperty(_p, "width", _p._getWidth); /** @expose */ _p.height; - cc.defineGetterSetter(_p, "height", _p._getHeight); + cc.addProperty(_p, "height", _p._getHeight); _c.defaultPixelFormat = _c.PIXEL_FORMAT_DEFAULT; }; @@ -209,13 +209,13 @@ cc._tmp.PrototypeTextureAtlas = function () { // Extended properties /** @expose */ _p.totalQuads; - cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads); + cc.addProperty(_p, "totalQuads", _p.getTotalQuads); /** @expose */ _p.capacity; - cc.defineGetterSetter(_p, "capacity", _p.getCapacity); + cc.addProperty(_p, "capacity", _p.getCapacity); /** @expose */ _p.quads; - cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads); + cc.addProperty(_p, "quads", _p.getQuads, _p.setQuads); }; From 28454325aa9633bb1c7677805e42553e9e5d70ff Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 19 Nov 2014 17:31:14 +0800 Subject: [PATCH 11/32] #19: Polish property defines --- .../base-nodes/BaseNodesPropertyDefine.js | 23 ++--- cocos2d/core/base-nodes/CCNode.js | 10 ++ .../core/labelttf/LabelTTFPropertyDefine.js | 2 +- cocos2d/core/platform/CCClass.js | 93 ++++++++++++++++++- cocos2d/core/sprites/SpritesPropertyDefine.js | 10 +- .../core/textures/TexturesPropertyDefine.js | 18 ++-- 6 files changed, 129 insertions(+), 27 deletions(-) diff --git a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js index 49240ecb07..bcd6467faf 100644 --- a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js +++ b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js @@ -62,19 +62,19 @@ cc._tmp.PrototypeCCNode = function () { cc.addProperty(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); /** @expose */ _p.vertexZ; - cc.addProperty(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); + cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); /** @expose */ _p.rotation; cc.addProperty(_p, "rotation", _p.getRotation, _p.setRotation); /** @expose */ _p.rotationX; - cc.addProperty(_p, "rotationX", _p.getRotationX, _p.setRotationX); + cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX); /** @expose */ _p.rotationY; - cc.addProperty(_p, "rotationY", _p.getRotationY, _p.setRotationY); + cc.defineGetterSetter(_p, "rotationY", _p.getRotationY, _p.setRotationY); /** @expose */ _p.scale; - cc.addProperty(_p, "scale", _p.getScale, _p.setScale); + cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale); /** @expose */ _p.scaleX; cc.addProperty(_p, "scaleX", _p.getScaleX, _p.setScaleX); @@ -83,10 +83,10 @@ cc._tmp.PrototypeCCNode = function () { cc.addProperty(_p, "scaleY", _p.getScaleY, _p.setScaleY); /** @expose */ _p.children; - cc.addProperty(_p, "children", _p.getChildren); + cc.addProperty(_p, "children", _p.getChildren, _p.setChildren); /** @expose */ _p.childrenCount; - cc.addProperty(_p, "childrenCount", _p.getChildrenCount); + cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount); /** @expose */ _p.parent; cc.addProperty(_p, "parent", _p.getParent, _p.setParent); @@ -95,25 +95,26 @@ cc._tmp.PrototypeCCNode = function () { cc.addProperty(_p, "visible", _p.isVisible, _p.setVisible); /** @expose */ _p.running; - cc.addProperty(_p, "running", _p.isRunning); + cc.defineGetterSetter(_p, "running", _p.isRunning); /** @expose */ _p.ignoreAnchor; cc.addProperty(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); /** @expose */ _p.tag; + cc.addProperty(_p, "tag"); /** @expose */ _p.userData; + cc.addProperty(_p, "userData"); /** @expose */ _p.userObject; /** @expose */ _p.arrivalOrder; /** @expose */ _p.actionManager; - cc.addProperty(_p, "actionManager", _p.getActionManager, _p.setActionManager); + cc.defineGetterSetter(_p, "actionManager", _p.getActionManager, _p.setActionManager); /** @expose */ _p.scheduler; - cc.addProperty(_p, "scheduler", _p.getScheduler, _p.setScheduler); - //cc.addProperty(_p, "boundingBox", _p.getBoundingBox); + cc.defineGetterSetter(_p, "scheduler", _p.getScheduler, _p.setScheduler); /** @expose */ _p.shaderProgram; cc.addProperty(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram); @@ -123,7 +124,7 @@ cc._tmp.PrototypeCCNode = function () { cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); /** @expose */ _p.opacityModifyRGB; - cc.addProperty(_p, "opacityModifyRGB", _p.isOpacityModifyRGB); + cc.addProperty(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); /** @expose */ _p.cascadeOpacity; cc.addProperty(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); diff --git a/cocos2d/core/base-nodes/CCNode.js b/cocos2d/core/base-nodes/CCNode.js index a78d1562b8..af1d94602d 100644 --- a/cocos2d/core/base-nodes/CCNode.js +++ b/cocos2d/core/base-nodes/CCNode.js @@ -785,6 +785,16 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ return this._children; }, + /** + * Returns an array of all children
+ * Composing a "tree" structure is a very important feature of CCNode + * @function + * @param {Array} children An array of children + */ + setChildren: function (children) { + + }, + /** * Returns if the node is visible * @function diff --git a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js index 2e691929c9..d3c4623ecc 100644 --- a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js +++ b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js @@ -50,7 +50,7 @@ cc._tmp.PrototypeLabelTTF = function () { cc.addProperty(_p, "fontName", _p.getFontName, _p.setFontName); /** @expose */ _p.font; - cc.addProperty(_p, "font", _p._getFont, _p._setFont); + cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); /** @expose */ _p.boundingSize; //cc.addProperty(_p, "boundingSize", _p.getDimensions, _p.setDimensions); diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 39ef3da6ac..79e4a67dc6 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -282,8 +282,17 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette } }; +/** + * Add a serializable property to a prototype + * @function + * @param {Object} proto A class prototype or an object to config
+ * @param {String} prop Property name + * @param {function} getter Getter function for the property + * @param {function} setter Setter function for the property + */ cc.addProperty = function(proto, prop, getter, setter) { - cc.defineGetterSetter(proto, prop, getter, setter); + if (getter || setter) + cc.defineGetterSetter(proto, prop, getter, setter); if (!proto.__props) { proto.__props = []; @@ -335,3 +344,85 @@ cc.clone = function (obj) { return newObj; }; +(function(cc) { + function unitSerialize (node, key) { + var value = node[key]; + // Found stringifier + if ( node.delegators && node.delegators[key] && node.delegators[key].stringifier ) { + return node.delegators[key].stringifier(value); + } + // Found type + else if ( value.type ) { + return serialization(value); + } + else { + return JSON.stringifier(value); + } + } + + function unitDeserialize (key, value, obj) { + // Found parser + if ( obj.delegators && obj.delegators[key] && obj.delegators[key].parser ) { + return obj.delegators[key].parser(value); + } + // Found type + else if (value.type) { + return deserialization(value); + } + else { + return JSON.parse(value); + } + } + + cc.serialize = function (node) { + var res = {}, + proto = node.constructor.prototype; + // Iterate until the top of prototype chain + while (proto != proto.constructor.prototype) { + // Check all properties + for (var i in proto.__props) { + // Serialize only when i is not defined yet and different from the value in prototype + if ( !res[i] && node[i] != proto[i] ) { + res[i] = unitSerialize(node, i); + } + } + proto = proto.constructor.prototype; + } + + return JSON.stringify(res); + } + + cc.deserialize = function (json) { + var obj, type = null, varsArr; + + // Create object with type + if (json.type) { + type = window; + varsArr = json.type.split("."); + for (var i in varsArr) { + if (type) { + type = type[varsArr[i]]; + } + else { + type = null; + break; + } + } + } + if (type) { + obj = new type(); + } + // Fail to initialize with type + else { + obj = {}; + } + + // Iterate all serialized properties + for (var i in json) { + obj[i] = unitDeserialize(i, json[i], obj); + } + + return obj; + } +})(cc); + diff --git a/cocos2d/core/sprites/SpritesPropertyDefine.js b/cocos2d/core/sprites/SpritesPropertyDefine.js index 5d7d617288..5d0ba240e9 100644 --- a/cocos2d/core/sprites/SpritesPropertyDefine.js +++ b/cocos2d/core/sprites/SpritesPropertyDefine.js @@ -43,10 +43,10 @@ cc._tmp.PrototypeSprite = function () { cc.addProperty(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); /** @expose */ _p.offsetX; - cc.addProperty(_p, "offsetX", _p._getOffsetX); + cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX); /** @expose */ _p.offsetY; - cc.addProperty(_p, "offsetY", _p._getOffsetY); + cc.defineGetterSetter(_p, "offsetY", _p._getOffsetY); /** @expose */ _p.atlasIndex; /** @expose */ @@ -54,14 +54,14 @@ cc._tmp.PrototypeSprite = function () { cc.addProperty(_p, "texture", _p.getTexture, _p.setTexture); /** @expose */ _p.textureRectRotated; - cc.addProperty(_p, "textureRectRotated", _p.isTextureRectRotated); + cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated); /** @expose */ _p.textureAtlas; /** @expose */ _p.batchNode; - cc.addProperty(_p, "batchNode", _p.getBatchNode, _p.setBatchNode); + cc.defineGetterSetter(_p, "batchNode", _p.getBatchNode, _p.setBatchNode); /** @expose */ _p.quad; - cc.addProperty(_p, "quad", _p.getQuad); + cc.defineGetterSetter(_p, "quad", _p.getQuad); }; diff --git a/cocos2d/core/textures/TexturesPropertyDefine.js b/cocos2d/core/textures/TexturesPropertyDefine.js index b83213e43b..42b8ec23a7 100644 --- a/cocos2d/core/textures/TexturesPropertyDefine.js +++ b/cocos2d/core/textures/TexturesPropertyDefine.js @@ -181,23 +181,23 @@ cc._tmp.PrototypeTexture2D = function () { // Extended properties /** @expose */ _p.name; - cc.addProperty(_p, "name", _p.getName); + cc.defineGetterSetter(_p, "name", _p.getName); /** @expose */ _p.pixelFormat; - cc.addProperty(_p, "pixelFormat", _p.getPixelFormat); + cc.defineGetterSetter(_p, "pixelFormat", _p.getPixelFormat); /** @expose */ _p.pixelsWidth; - cc.addProperty(_p, "pixelsWidth", _p.getPixelsWide); + cc.defineGetterSetter(_p, "pixelsWidth", _p.getPixelsWide); /** @expose */ _p.pixelsHeight; - cc.addProperty(_p, "pixelsHeight", _p.getPixelsHigh); + cc.defineGetterSetter(_p, "pixelsHeight", _p.getPixelsHigh); //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); /** @expose */ _p.width; - cc.addProperty(_p, "width", _p._getWidth); + cc.defineGetterSetter(_p, "width", _p._getWidth); /** @expose */ _p.height; - cc.addProperty(_p, "height", _p._getHeight); + cc.defineGetterSetter(_p, "height", _p._getHeight); _c.defaultPixelFormat = _c.PIXEL_FORMAT_DEFAULT; }; @@ -209,13 +209,13 @@ cc._tmp.PrototypeTextureAtlas = function () { // Extended properties /** @expose */ _p.totalQuads; - cc.addProperty(_p, "totalQuads", _p.getTotalQuads); + cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads); /** @expose */ _p.capacity; - cc.addProperty(_p, "capacity", _p.getCapacity); + cc.defineGetterSetter(_p, "capacity", _p.getCapacity); /** @expose */ _p.quads; - cc.addProperty(_p, "quads", _p.getQuads, _p.setQuads); + cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads); }; From 93113699df8795bd20de0fb286ddaf14576bd24c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 20 Nov 2014 21:29:37 +0800 Subject: [PATCH 12/32] #20: Refactor cc.Node to support serialization --- .../base-nodes/BaseNodesPropertyDefine.js | 70 ++++++++++++------- cocos2d/core/base-nodes/CCNode.js | 23 +++--- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js index bcd6467faf..74dc981d36 100644 --- a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js +++ b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js @@ -28,17 +28,17 @@ cc._tmp.PrototypeCCNode = function () { var _p = cc.Node.prototype; - cc.addProperty(_p, "x", _p.getPositionX, _p.setPositionX); - cc.addProperty(_p, "y", _p.getPositionY, _p.setPositionY); + cc.addProperty(_p, "x", 0, _p.getPositionX, _p.setPositionX); + cc.addProperty(_p, "y", 0, _p.getPositionY, _p.setPositionY); /** @expose */ //_p.pos; //cc.addProperty(_p, "pos", _p.getPosition, _p.setPosition); /** @expose */ _p.width; - cc.addProperty(_p, "width", _p._getWidth, _p._setWidth); + cc.addProperty(_p, "width", 0, _p._getWidth, _p._setWidth); /** @expose */ _p.height; - cc.addProperty(_p, "height", _p._getHeight, _p._setHeight); + cc.addProperty(_p, "height", 0, _p._getHeight, _p._setHeight); /** @expose */ //_p.size; //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); @@ -47,25 +47,25 @@ cc._tmp.PrototypeCCNode = function () { //cc.addProperty(_p, "anchor", _p._getAnchor, _p._setAnchor); /** @expose */ _p.anchorX; - cc.addProperty(_p, "anchorX", _p._getAnchorX, _p._setAnchorX); + cc.addProperty(_p, "anchorX", 0, _p._getAnchorX, _p._setAnchorX); /** @expose */ _p.anchorY; - cc.addProperty(_p, "anchorY", _p._getAnchorY, _p._setAnchorY); + cc.addProperty(_p, "anchorY", 0, _p._getAnchorY, _p._setAnchorY); /** @expose */ _p.skewX; - cc.addProperty(_p, "skewX", _p.getSkewX, _p.setSkewX); + cc.addProperty(_p, "skewX", 0, _p.getSkewX, _p.setSkewX); /** @expose */ _p.skewY; - cc.addProperty(_p, "skewY", _p.getSkewY, _p.setSkewY); + cc.addProperty(_p, "skewY", 0, _p.getSkewY, _p.setSkewY); /** @expose */ _p.zIndex; - cc.addProperty(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); + cc.addProperty(_p, "zIndex", 0, _p.getLocalZOrder, _p.setLocalZOrder); /** @expose */ _p.vertexZ; cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); /** @expose */ _p.rotation; - cc.addProperty(_p, "rotation", _p.getRotation, _p.setRotation); + cc.addProperty(_p, "rotation", 0, _p.getRotation, _p.setRotation); /** @expose */ _p.rotationX; cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX); @@ -77,10 +77,10 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale); /** @expose */ _p.scaleX; - cc.addProperty(_p, "scaleX", _p.getScaleX, _p.setScaleX); + cc.addProperty(_p, "scaleX", 1, _p.getScaleX, _p.setScaleX); /** @expose */ _p.scaleY; - cc.addProperty(_p, "scaleY", _p.getScaleY, _p.setScaleY); + cc.addProperty(_p, "scaleY", 1, _p.getScaleY, _p.setScaleY); /** @expose */ _p.children; cc.addProperty(_p, "children", _p.getChildren, _p.setChildren); @@ -89,22 +89,20 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount); /** @expose */ _p.parent; - cc.addProperty(_p, "parent", _p.getParent, _p.setParent); + cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent); /** @expose */ _p.visible; - cc.addProperty(_p, "visible", _p.isVisible, _p.setVisible); + cc.addProperty(_p, "visible", true, _p.isVisible, _p.setVisible); /** @expose */ _p.running; cc.defineGetterSetter(_p, "running", _p.isRunning); /** @expose */ _p.ignoreAnchor; - cc.addProperty(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); + cc.addProperty(_p, "ignoreAnchor", false, _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); /** @expose */ _p.tag; - cc.addProperty(_p, "tag"); /** @expose */ _p.userData; - cc.addProperty(_p, "userData"); /** @expose */ _p.userObject; /** @expose */ @@ -117,21 +115,45 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "scheduler", _p.getScheduler, _p.setScheduler); /** @expose */ _p.shaderProgram; - cc.addProperty(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram); + cc.defineGetterSetter(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram); /** @expose */ _p.opacity; - cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); + cc.addProperty(_p, "opacity", 255, _p.getOpacity, _p.setOpacity); /** @expose */ _p.opacityModifyRGB; - cc.addProperty(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); + cc.addProperty(_p, "opacityModifyRGB", false, _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); /** @expose */ _p.cascadeOpacity; - cc.addProperty(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); + cc.addProperty(_p, "cascadeOpacity", false, _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); /** @expose */ _p.color; - cc.addProperty(_p, "color", _p.getColor, _p.setColor); + cc.addProperty(_p, "color", null, _p.getColor, _p.setColor); /** @expose */ _p.cascadeColor; - cc.addProperty(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); -}; \ No newline at end of file + cc.addProperty(_p, "cascadeColor", false, _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); + + _p.__delegators = { + color : cc.__delegators.color, + children : { + parser : function(json) { + var children = []; + for (var i in json) { + // Generate one child + children.push( cc.deserialize(json[i]) ); + } + return children; + }, + stringifier : function(children) { + var json = []; + for (var i in children) { + // Generate one child + json.push( cc.serialize(children[i]) ); + } + return JSON.stringify(json); + } + } + } + +}; + diff --git a/cocos2d/core/base-nodes/CCNode.js b/cocos2d/core/base-nodes/CCNode.js index af1d94602d..7f456db24e 100644 --- a/cocos2d/core/base-nodes/CCNode.js +++ b/cocos2d/core/base-nodes/CCNode.js @@ -129,6 +129,8 @@ cc.s_globalOrderOfArrival = 1; * @property {Number} glServerState - The state of OpenGL server side */ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ + __type: "cc.Node", + _localZOrder: 0, ///< Local order (relative to its siblings) used to sort the node _globalZOrder: 0, ///< Global order used to sort the node _vertexZ: 0.0, @@ -308,7 +310,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * Sets node's dirty flag to true so that it can be updated in visit function of the next frame * @function */ - setNodeDirty: null, + //setNodeDirty: null, /** *

Properties configuration function
@@ -786,13 +788,18 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ }, /** - * Returns an array of all children
+ * Add an array of node as children of this node
* Composing a "tree" structure is a very important feature of CCNode * @function * @param {Array} children An array of children */ setChildren: function (children) { - + var i, l, child; + for (i = 0, l = children.length; i < l; i++) { + child = children[i]; + if (child instanceof cc.Node) + this.addChild(child); + } }, /** @@ -2110,27 +2117,27 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ this._componentContainer.removeAll(); }, - grid: null, + //grid: null, /** * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. * @function */ - ctor: null, + //ctor: null, /** * Recursive method that visit its children and draw them * @function * @param {CanvasRenderingContext2D|WebGLRenderingContext} ctx */ - visit: null, + //visit: null, /** * Performs view-matrix transformation based on position, scale, rotation and other attributes. * @function * @param {CanvasRenderingContext2D|WebGLRenderingContext} ctx Render context */ - transform: null, + //transform: null, /** *

Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
@@ -2149,7 +2156,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * @function * @return {cc.AffineTransform} The affine transform object */ - getNodeToParentTransform: null, + //getNodeToParentTransform: null, _setNodeDirtyForCache: function () { if (this._cacheDirty === false) { From 0f00e2a16c37b2938fad33caa160ec5ca70b878f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 20 Nov 2014 21:30:05 +0800 Subject: [PATCH 13/32] #20: Refactor cc.Layer s to support serialization --- cocos2d/core/layers/CCLayer.js | 16 ++++++++++------ cocos2d/core/layers/CCLayerPropertyDefine.js | 13 +++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cocos2d/core/layers/CCLayer.js b/cocos2d/core/layers/CCLayer.js index 792ee445d9..21bf7393aa 100644 --- a/cocos2d/core/layers/CCLayer.js +++ b/cocos2d/core/layers/CCLayer.js @@ -30,6 +30,7 @@ * @extends cc.Node */ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ + __type: "cc.Layer", _isBaked: false, _bakeSprite: null, _bakeRenderCmd: null, @@ -65,7 +66,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ * @function * @see cc.Layer#unbake */ - bake: null, + //bake: null, /** * Cancel the layer to cache all of children to a bake sprite.
@@ -73,7 +74,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ * @function * @see cc.Layer#bake */ - unbake: null, + //unbake: null, _bakeRendering: null, @@ -85,9 +86,9 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ */ isBaked: function(){ return this._isBaked; - }, + } - visit: null + //visit: null }); /** @@ -248,6 +249,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { * var yellowBox = new cc.LayerColor(cc.color(255,255,0,255), 200, 200); */ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ + __type: "cc.LayerColor", _blendFunc: null, _className: "LayerColor", @@ -317,7 +319,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ * @param {Number} [width=] * @param {Number} [height=] */ - ctor: null, + //ctor: null, /** * Initialization of the layer, please do not call this function by yourself, you should pass the parameters to constructor to initialize a layer @@ -388,7 +390,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ this._updateColor(); }, - draw: null + //draw: null }); /** @@ -585,6 +587,7 @@ delete cc._tmp.PrototypeLayerColor; * @property {Number} compresseInterpolation - Indicate whether or not the interpolation will be compressed */ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{ + __type: "cc.LayerGradient", _endColor: null, _startOpacity: 255, _endOpacity: 255, @@ -835,6 +838,7 @@ delete cc._tmp.PrototypeLayerGradient; * var multiLayer = new cc.LayerMultiple(layer1, layer2, layer3);//any number of layers */ cc.LayerMultiplex = cc.Layer.extend(/** @lends cc.LayerMultiplex# */{ + __type: "cc.LayerMultiplex", _enabledLayer: 0, _layers: null, _className: "LayerMultiplex", diff --git a/cocos2d/core/layers/CCLayerPropertyDefine.js b/cocos2d/core/layers/CCLayerPropertyDefine.js index e08f5ff20c..7ce333d430 100644 --- a/cocos2d/core/layers/CCLayerPropertyDefine.js +++ b/cocos2d/core/layers/CCLayerPropertyDefine.js @@ -27,8 +27,8 @@ cc._tmp.PrototypeLayerColor = function () { var _p = cc.LayerColor.prototype; // Override properties - cc.addProperty(_p, "width", _p._getWidth, _p._setWidth); - cc.addProperty(_p, "height", _p._getHeight, _p._setHeight); + cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth); + cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight); }; cc._tmp.PrototypeLayerGradient = function () { @@ -42,11 +42,16 @@ cc._tmp.PrototypeLayerGradient = function () { cc.addProperty(_p, "endColor", _p.getEndColor, _p.setEndColor); /** @expose */ _p.startOpacity; - cc.addProperty(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity); + cc.addProperty(_p, "startOpacity", 255, _p.getStartOpacity, _p.setStartOpacity); /** @expose */ _p.endOpacity; - cc.addProperty(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity); + cc.addProperty(_p, "endOpacity", 255, _p.getEndOpacity, _p.setEndOpacity); /** @expose */ _p.vector; cc.addProperty(_p, "vector", _p.getVector, _p.setVector); + + _p.__delegators = { + startColor : cc.__delegators.color, + endColor : cc.__delegators.color + } }; \ No newline at end of file From 8149e9e914d3a59c734148c3895764f3f7ec9718 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 20 Nov 2014 21:30:33 +0800 Subject: [PATCH 14/32] #20: Refactor cc.Sprite to support serialization --- cocos2d/core/sprites/CCSprite.js | 36 ++++++++++--------- cocos2d/core/sprites/SpritesPropertyDefine.js | 25 +++++++++---- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/cocos2d/core/sprites/CCSprite.js b/cocos2d/core/sprites/CCSprite.js index 5037609966..83aab2088f 100644 --- a/cocos2d/core/sprites/CCSprite.js +++ b/cocos2d/core/sprites/CCSprite.js @@ -301,8 +301,10 @@ cc._getCompositeOperationByBlendFunc = function(blendFunc){ * @property {cc.V3F_C4B_T2F_Quad} quad - <@readonly> The quad (tex coords, vertex coords and color) information. */ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ + __type:"cc.Sprite", + dirty:false, - atlasIndex:0, + atlasIndex:-1, textureAtlas:null, _batchNode:null, @@ -727,7 +729,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {Boolean} modify */ - setOpacityModifyRGB:null, + //setOpacityModifyRGB:null, /** * Returns whether opacity modify color or not. @@ -741,7 +743,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * Update the display opacity. * @function */ - updateDisplayedOpacity: null, + //updateDisplayedOpacity: null, // Animation @@ -804,7 +806,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _originalTexture: null, _drawSize_Canvas: null, - ctor: null, + //ctor: null, _softInit: function (fileName, rect, rotated) { if (fileName === undefined) @@ -850,7 +852,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Number|cc.BlendFunc} src * @param {Number} dst */ - setBlendFunc: null, + //setBlendFunc: null, /** * Initializes an empty sprite with nothing init.
@@ -858,7 +860,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @return {Boolean} */ - init:null, + //init:null, /** *

@@ -899,7 +901,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Boolean} [rotated] Whether or not the texture rectangle is rotated. * @return {Boolean} true if the sprite is initialized properly, false otherwise. */ - initWithTexture: null, + //initWithTexture: null, _textureLoadedCallback: null, @@ -910,14 +912,14 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Boolean} [rotated] Whether or not the texture is rotated * @param {cc.Size} [untrimmedSize] The original pixels size of the texture */ - setTextureRect:null, + //setTextureRect:null, // BatchNode methods /** * Updates the quad according the the rotation, position, scale values. * @function */ - updateTransform: null, + //updateTransform: null, /** * Add child to sprite (override cc.Node) @@ -927,7 +929,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {String} tag child's tag * @override */ - addChild: null, + //addChild: null, /** * Update sprite's color @@ -967,20 +969,20 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {Number} opacity */ - setOpacity:null, + //setOpacity:null, /** * Sets color of the sprite * @function * @param {cc.Color} color3 */ - setColor: null, + //setColor: null, /** * Updates the display color * @function */ - updateDisplayedColor: null, + //updateDisplayedColor: null, // Frames /** @@ -988,7 +990,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {cc.SpriteFrame|String} newFrame */ - setSpriteFrame: null, + //setSpriteFrame: null, /** * Sets a new display frame to the sprite. @@ -1006,7 +1008,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {cc.SpriteFrame} frame * @return {Boolean} */ - isFrameDisplayed: null, + //isFrameDisplayed: null, /** * Returns the current displayed frame. @@ -1030,7 +1032,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * batch.addChild(sprite); * layer.addChild(batch); */ - setBatchNode:null, + //setBatchNode:null, // CCTextureProtocol /** @@ -1038,7 +1040,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {cc.Texture2D|String} texture */ - setTexture: null, + //setTexture: null, // Texture protocol _updateBlendFunc:function () { diff --git a/cocos2d/core/sprites/SpritesPropertyDefine.js b/cocos2d/core/sprites/SpritesPropertyDefine.js index 5d0ba240e9..b576ca9a72 100644 --- a/cocos2d/core/sprites/SpritesPropertyDefine.js +++ b/cocos2d/core/sprites/SpritesPropertyDefine.js @@ -28,19 +28,19 @@ cc._tmp.PrototypeSprite = function () { var _p = cc.Sprite.prototype; // Override properties - cc.addProperty(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); - cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); - cc.addProperty(_p, "color", _p.getColor, _p.setColor); + cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); + cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); + cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); // Extended properties /** @expose */ _p.dirty; /** @expose */ _p.flippedX; - cc.addProperty(_p, "flippedX", _p.isFlippedX, _p.setFlippedX); + cc.addProperty(_p, "flippedX", false, _p.isFlippedX, _p.setFlippedX); /** @expose */ _p.flippedY; - cc.addProperty(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); + cc.addProperty(_p, "flippedY", false, _p.isFlippedY, _p.setFlippedY); /** @expose */ _p.offsetX; cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX); @@ -51,7 +51,7 @@ cc._tmp.PrototypeSprite = function () { _p.atlasIndex; /** @expose */ _p.texture; - cc.addProperty(_p, "texture", _p.getTexture, _p.setTexture); + cc.addProperty(_p, "texture", null, _p.getTexture, _p.setTexture); /** @expose */ _p.textureRectRotated; cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated); @@ -64,4 +64,17 @@ cc._tmp.PrototypeSprite = function () { _p.quad; cc.defineGetterSetter(_p, "quad", _p.getQuad); + _p.__type = "cc.Sprite"; + + _p.__delegators = { + "texture" : { + parser : function(json) { + return cc.textureCache.addImage(json); + }, + stringifier : function(texture) { + return cc.textureCache.getKeyByTexture(texture); + } + } + } + }; From 83cee0ed06513fafb2f1566062af9935daae543d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 20 Nov 2014 21:30:49 +0800 Subject: [PATCH 15/32] #20: Refactor cc.LabelTTF to support serialization --- cocos2d/core/labelttf/CCLabelTTF.js | 15 ++++----- .../core/labelttf/LabelTTFPropertyDefine.js | 31 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cocos2d/core/labelttf/CCLabelTTF.js b/cocos2d/core/labelttf/CCLabelTTF.js index 0fa34cc039..d657a5f310 100644 --- a/cocos2d/core/labelttf/CCLabelTTF.js +++ b/cocos2d/core/labelttf/CCLabelTTF.js @@ -64,6 +64,7 @@ * @property {Number} shadowBlur - The blur size of shadow */ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ + __type: "cc.LabelTTF", _dimensions: null, _hAlignment: cc.TEXT_ALIGNMENT_CENTER, _vAlignment: cc.VERTICAL_TEXT_ALIGNMENT_TOP, @@ -200,15 +201,15 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ return ""; }, - setColor: null, + //setColor: null, _setColorsString: null, - updateDisplayedColor: null, + //updateDisplayedColor: null, - setOpacity: null, + //setOpacity: null, - updateDisplayedOpacity: null, + //updateDisplayedOpacity: null, updateDisplayedOpacityForCanvas: function (parentOpacity) { cc.Node.prototype.updateDisplayedOpacity.call(this, parentOpacity); @@ -270,7 +271,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ * @param {cc.FontDefinition} textDefinition * @return {Boolean} */ - initWithStringAndTextDefinition: null, + //initWithStringAndTextDefinition: null, /** * Sets the text definition used by this label @@ -491,7 +492,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ * @function * @param {cc.Color} fillColor The fill color of the label */ - setFontFillColor: null, + //setFontFillColor: null, _getFillStyle: function () { return this._textFillColor; @@ -995,7 +996,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ cc.Sprite.prototype.visit.call(this, context); }, - draw: null, + //draw: null, _setTextureCoords: function (rect) { var tex = this._batchNode ? this.textureAtlas.texture : this._texture; diff --git a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js index d3c4623ecc..09b9c053af 100644 --- a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js +++ b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js @@ -29,25 +29,25 @@ cc._tmp.PrototypeLabelTTF = function () { var _p = cc.LabelTTF.prototype; // Override properties - cc.addProperty(_p, "color", _p.getColor, _p.setColor); - cc.addProperty(_p, "opacity", _p.getOpacity, _p.setOpacity); + cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); + cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); // Extended properties /** @expose */ _p.string; - cc.addProperty(_p, "string", _p.getString, _p.setString); + cc.addProperty(_p, "string", "", _p.getString, _p.setString); /** @expose */ _p.textAlign; - cc.addProperty(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment); + cc.addProperty(_p, "textAlign", 1, _p.getHorizontalAlignment, _p.setHorizontalAlignment); /** @expose */ _p.verticalAlign; - cc.addProperty(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment); + cc.addProperty(_p, "verticalAlign", 0, _p.getVerticalAlignment, _p.setVerticalAlignment); /** @expose */ _p.fontSize; - cc.addProperty(_p, "fontSize", _p.getFontSize, _p.setFontSize); + cc.addProperty(_p, "fontSize", 0, _p.getFontSize, _p.setFontSize); /** @expose */ _p.fontName; - cc.addProperty(_p, "fontName", _p.getFontName, _p.setFontName); + cc.addProperty(_p, "fontName", "Arial", _p.getFontName, _p.setFontName); /** @expose */ _p.font; cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); @@ -56,33 +56,32 @@ cc._tmp.PrototypeLabelTTF = function () { //cc.addProperty(_p, "boundingSize", _p.getDimensions, _p.setDimensions); /** @expose */ _p.boundingWidth; - cc.addProperty(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth); + cc.addProperty(_p, "boundingWidth", 0, _p._getBoundingWidth, _p._setBoundingWidth); /** @expose */ _p.boundingHeight; - cc.addProperty(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight); + cc.addProperty(_p, "boundingHeight", 0, _p._getBoundingHeight, _p._setBoundingHeight); /** @expose */ _p.fillStyle; - cc.addProperty(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); + cc.addProperty(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); /** @expose */ _p.strokeStyle; cc.addProperty(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); /** @expose */ _p.lineWidth; - cc.addProperty(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth); + cc.addProperty(_p, "lineWidth", 0, _p._getLineWidth, _p._setLineWidth); /** @expose */ _p.shadowOffset; //cc.addProperty(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); /** @expose */ _p.shadowOffsetX; - cc.addProperty(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX); + cc.addProperty(_p, "shadowOffsetX", 0, _p._getShadowOffsetX, _p._setShadowOffsetX); /** @expose */ _p.shadowOffsetY; - cc.addProperty(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY); + cc.addProperty(_p, "shadowOffsetY", 0, _p._getShadowOffsetY, _p._setShadowOffsetY); /** @expose */ _p.shadowOpacity; - cc.addProperty(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity); + cc.addProperty(_p, "shadowOpacity", 0, _p._getShadowOpacity, _p._setShadowOpacity); /** @expose */ _p.shadowBlur; - cc.addProperty(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur); - + cc.addProperty(_p, "shadowBlur", 0, _p._getShadowBlur, _p._setShadowBlur); }; \ No newline at end of file From 156aad73f7471471dee4efda246d593b48d0b2ee Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 20 Nov 2014 21:42:49 +0800 Subject: [PATCH 16/32] #20: Improve cc.Class implementation --- cocos2d/core/platform/CCClass.js | 43 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 79e4a67dc6..086555c4d5 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -103,20 +103,21 @@ ClassManager.compileSuper.ClassManager = ClassManager; * @return {function} */ cc.Class.extend = function (props) { - var _super = this.prototype; - + var _super = this.prototype, // Instantiate a base Class (but only create the instance, // don't run the init constructor) - var prototype = Object.create(_super); - - var classId = ClassManager.getNewID(); - ClassManager[classId] = _super; + prototype = Object.create(_super), + classId = ClassManager.getNewID(), // Copy the properties over onto the new prototype. We make function // properties non-eumerable as this makes typeof === 'function' check // unneccessary in the for...in loop used 1) for generating Class() // 2) for cc.clone and perhaps more. It is also required to make // these function properties cacheable in Carakan. - var desc = { writable: true, enumerable: false, configurable: true }; + desc = { writable: true, enumerable: false, configurable: true }, + i, idx, li, prop, name, isFunc, override, hasSuperCall, supportProp, + getter, setter, propertyName; + + ClassManager[classId] = _super; prototype.__instanceId = null; @@ -145,17 +146,18 @@ ClassManager.compileSuper.ClassManager = ClassManager; this.__getters__ && (Class.__getters__ = cc.clone(this.__getters__)); this.__setters__ && (Class.__setters__ = cc.clone(this.__setters__)); - for(var idx = 0, li = arguments.length; idx < li; ++idx) { - var prop = arguments[idx]; - for (var name in prop) { - var isFunc = (typeof prop[name] === "function"); - var override = (typeof _super[name] === "function"); - var hasSuperCall = fnTest.test(prop[name]); + supportProp = props.__type ? true : false; + if (supportProp) + cc.addProperty(prototype, "__type"); - if (releaseMode && isFunc && override && hasSuperCall) { - desc.value = ClassManager.compileSuper(prop[name], name, classId); - Object.defineProperty(prototype, name, desc); - } else if (isFunc && override && hasSuperCall) { + for(idx = 0, li = arguments.length; idx < li; ++idx) { + prop = arguments[idx]; + for (name in prop) { + isFunc = (typeof prop[name] === "function"); + override = (typeof _super[name] === "function"); + hasSuperCall = fnTest.test(prop[name]); + + if (isFunc && override && hasSuperCall) { desc.value = (function (name, fn) { return function () { var tmp = this._super; @@ -182,10 +184,9 @@ ClassManager.compileSuper.ClassManager = ClassManager; if (isFunc) { // Override registered getter/setter - var getter, setter, propertyName; if (this.__getters__ && this.__getters__[name]) { propertyName = this.__getters__[name]; - for (var i in this.__setters__) { + for (i in this.__setters__) { if (this.__setters__[i] == propertyName) { setter = i; break; @@ -195,7 +196,7 @@ ClassManager.compileSuper.ClassManager = ClassManager; } if (this.__setters__ && this.__setters__[name]) { propertyName = this.__setters__[name]; - for (var i in this.__getters__) { + for (i in this.__getters__) { if (this.__getters__[i] == propertyName) { getter = i; break; @@ -212,7 +213,7 @@ ClassManager.compileSuper.ClassManager = ClassManager; //add implementation method Class.implement = function (prop) { - for (var name in prop) { + for (name in prop) { prototype[name] = prop[name]; } }; From d4592603f1a3d458490f138de0e15a798e2f5e62 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 20 Nov 2014 21:43:10 +0800 Subject: [PATCH 17/32] #20 Improve serialization and addProperty --- cocos2d/core/platform/CCClass.js | 90 +++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 26 deletions(-) diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 086555c4d5..c9082a59cf 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -179,6 +179,11 @@ ClassManager.compileSuper.ClassManager = ClassManager; desc.value = prop[name]; Object.defineProperty(prototype, name, desc); } else { + // Add property + if (supportProp && name[0] != "_") { + cc.addProperty(prototype, name, prop[name]); + } + prototype[name] = prop[name]; } @@ -236,7 +241,7 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette getter && proto.__defineGetter__(prop, getter); setter && proto.__defineSetter__(prop, setter); } else if (Object.defineProperty) { - var desc = { enumerable: false, configurable: true }; + var desc = { enumerable: true, configurable: true }; getter && (desc.get = getter); setter && (desc.set = setter); Object.defineProperty(proto, prop, desc); @@ -291,14 +296,34 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette * @param {function} getter Getter function for the property * @param {function} setter Setter function for the property */ -cc.addProperty = function(proto, prop, getter, setter) { - if (getter || setter) - cc.defineGetterSetter(proto, prop, getter, setter); +cc.addProperty = function(proto, prop, value, getter, setter) { + if (typeof value == "function") { + setter = getter; + getter = value; + value = undefined; + } - if (!proto.__props) { - proto.__props = []; + var props; + if (proto.hasOwnProperty("__props")) { + props = proto.__props; + } + else { + props = proto.__props = {}; + } + + if (getter || setter) { + cc.defineGetterSetter(proto, prop, getter, setter); + if (!props[prop]) + props[prop] = value; + } + else { + if (value !== undefined) + props[prop] = value; + else if (proto[prop] !== undefined) + props[prop] = proto[prop]; + else + props[prop] = null; } - proto.__props.push(prop); }; /** @@ -346,29 +371,41 @@ cc.clone = function (obj) { }; (function(cc) { + + cc.__delegators = { + color : { + parser : function(json) { + return cc.color(json[0], json[1], json[2], json[3]); + }, + stringifier : function(color) { + return [color.r, color.g, color.b, color.a]; + } + } + }; + function unitSerialize (node, key) { var value = node[key]; // Found stringifier - if ( node.delegators && node.delegators[key] && node.delegators[key].stringifier ) { - return node.delegators[key].stringifier(value); + if ( node.__delegators && node.__delegators[key] && node.__delegators[key].stringifier ) { + return JSON.stringify(node.__delegators[key].stringifier(value)); } // Found type - else if ( value.type ) { - return serialization(value); + else if ( value && value.__type ) { + return cc.serialize(value); } - else { - return JSON.stringifier(value); + else if (typeof value != "object" || (value && Object.getPrototypeOf(value) == Object.prototype)) { + return JSON.stringify(value); } } function unitDeserialize (key, value, obj) { // Found parser - if ( obj.delegators && obj.delegators[key] && obj.delegators[key].parser ) { - return obj.delegators[key].parser(value); + if ( obj.__delegators && obj.__delegators[key] && obj.__delegators[key].parser ) { + return obj.__delegators[key].parser(JSON.parse(value)); } // Found type - else if (value.type) { - return deserialization(value); + else if (value.__type) { + return cc.deserialize(value); } else { return JSON.parse(value); @@ -376,30 +413,31 @@ cc.clone = function (obj) { } cc.serialize = function (node) { - var res = {}, + var res = {}, key, defaultVal, proto = node.constructor.prototype; // Iterate until the top of prototype chain - while (proto != proto.constructor.prototype) { + while (proto != Object.prototype) { // Check all properties - for (var i in proto.__props) { + for (key in proto.__props) { + defaultVal = proto.__props[key]; // Serialize only when i is not defined yet and different from the value in prototype - if ( !res[i] && node[i] != proto[i] ) { - res[i] = unitSerialize(node, i); + if ( res[key] === undefined && node[key] !== defaultVal ) { + res[key] = unitSerialize(node, key); } } - proto = proto.constructor.prototype; + proto = Object.getPrototypeOf(proto); } return JSON.stringify(res); } cc.deserialize = function (json) { - var obj, type = null, varsArr; + var obj, type = null, varsArr, json = JSON.parse(json); // Create object with type - if (json.type) { + if (json.__type) { type = window; - varsArr = json.type.split("."); + varsArr = JSON.parse(json.__type).split("."); for (var i in varsArr) { if (type) { type = type[varsArr[i]]; From b6f003fe01fbacd5c6165c7f37d76c4e513fa369 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 24 Nov 2014 10:08:10 +0800 Subject: [PATCH 18/32] #22: Fix end issues in cc.director --- cocos2d/core/CCDirector.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index ffbf5b7c76..290b735c02 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -390,7 +390,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ // Disable event dispatching if (cc.eventManager) - cc.eventManager.setEnabled(false); + cc.eventManager.removeAllListeners(); // don't release the event handlers // They are needed in case the director is run again @@ -408,7 +408,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ // runScene might be executed after 'end'. this._scenesStack.length = 0; - this.stopAnimation(); + //this.stopAnimation(); // Clear all caches this.purgeCachedData(); From 93252946d9131fc92babf9e2c35cf9794a64e58a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 24 Nov 2014 10:08:19 +0800 Subject: [PATCH 19/32] #22: Support pause and restart in framework And added a loadScene alias function --- CCBoot.js | 60 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 9081947526..eeab8cd31e 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2002,6 +2002,14 @@ cc.game = /** @lends cc.game# */{ */ onStop: null, + _frameCallback: function () { + var game = cc.game; + cc.director.mainLoop(); + if(game._intervalId) + window.cancelAnimationFrame(game._intervalId); + game._intervalId = window.requestAnimFrame(game._frameCallback); + }, + /** * Set frameRate of game. * @param frameRate @@ -2011,27 +2019,13 @@ cc.game = /** @lends cc.game# */{ config[CONFIG_KEY.frameRate] = frameRate; if (self._intervalId) window.cancelAnimationFrame(self._intervalId); - self._paused = true; self._runMainLoop(); }, //Run game. _runMainLoop: function () { - var self = this, callback, config = self.config, CONFIG_KEY = self.CONFIG_KEY, - director = cc.director; - - director.setDisplayStats(config[CONFIG_KEY.showFPS]); + cc.director.setDisplayStats(this.config[this.CONFIG_KEY.showFPS]); - callback = function () { - if (!self._paused) { - director.mainLoop(); - if(self._intervalId) - window.cancelAnimationFrame(self._intervalId); - self._intervalId = window.requestAnimFrame(callback); - } - }; - - window.requestAnimFrame(callback); - self._paused = false; + window.requestAnimFrame(this._frameCallback); }, /** @@ -2071,6 +2065,20 @@ cc.game = /** @lends cc.game# */{ }, false); }, + pause: function () { + window.cancelAnimationFrame(this._intervalId); + this._intervalId = null; + }, + + resume: function () { + if(!this._intervalId) + this._intervalId = window.requestAnimFrame(this._frameCallback); + }, + + restart: function () { + cc.director.popToSceneStackLevel(0); + }, + _initConfig: function () { var self = this, CONFIG_KEY = self.CONFIG_KEY; var _init = function (cfg) { @@ -2206,3 +2214,23 @@ Function.prototype.bind = Function.prototype.bind || function (oThis) { return fBound; }; + + +//+++++++++++++++++++++++++Additional for cocos.js+++++++++++++++++++++++++++++ + +cc.game.loadScene = function (resource, scene, callback) { + if (resource && scene) { + cc.LoaderScene.preload(resource, function() { + cc.director.runScene(scene); + cc.director.drawScene(scene); + cc.game.pause(); + callback && callback(); + }); + } + else if (resource instanceof cc.Scene) { + cc.director.runScene(resource); + cc.director.drawScene(resource); + cc.game.pause(); + callback && callback(); + } +}; \ No newline at end of file From 1eb34037ab3ec78e39cffb140d88eae4af0588cf Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 24 Nov 2014 10:37:18 +0800 Subject: [PATCH 20/32] #20: Revert panda version serialization --- cocos2d/core/base-nodes/CCNode.js | 90 +++++-------- cocos2d/core/labelttf/CCLabelTTF.js | 47 +++++-- cocos2d/core/layers/CCLayer.js | 38 +++--- cocos2d/core/platform/CCClass.js | 143 -------------------- cocos2d/core/sprites/CCSprite.js | 199 ++++++++++++++-------------- 5 files changed, 179 insertions(+), 338 deletions(-) diff --git a/cocos2d/core/base-nodes/CCNode.js b/cocos2d/core/base-nodes/CCNode.js index 7f456db24e..c22e4843dd 100644 --- a/cocos2d/core/base-nodes/CCNode.js +++ b/cocos2d/core/base-nodes/CCNode.js @@ -129,8 +129,6 @@ cc.s_globalOrderOfArrival = 1; * @property {Number} glServerState - The state of OpenGL server side */ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ - __type: "cc.Node", - _localZOrder: 0, ///< Local order (relative to its siblings) used to sort the node _globalZOrder: 0, ///< Global order used to sort the node _vertexZ: 0.0, @@ -249,7 +247,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ return; var i, len = array.length, node; - var nodeCallbackType = cc.Node._StateCallbackType; + var nodeCallbackType = cc.Node._stateCallbackType; switch (callbackType) { case nodeCallbackType.onEnter: for (i = 0; i < len; i++) { @@ -310,7 +308,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * Sets node's dirty flag to true so that it can be updated in visit function of the next frame * @function */ - //setNodeDirty: null, + setNodeDirty: null, /** *

Properties configuration function
@@ -787,21 +785,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ return this._children; }, - /** - * Add an array of node as children of this node
- * Composing a "tree" structure is a very important feature of CCNode - * @function - * @param {Array} children An array of children - */ - setChildren: function (children) { - var i, l, child; - for (i = 0, l = children.length; i < l; i++) { - child = children[i]; - if (child instanceof cc.Node) - this.addChild(child); - } - }, - /** * Returns if the node is visible * @function @@ -1080,7 +1063,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * @param {String} name */ setName: function(name){ - this._name = name; + this._name = name; }, /** @@ -1258,7 +1241,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ cc.eventManager.removeListeners(this); // timers - this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.cleanup); + this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.cleanup); }, // composition: GET @@ -1294,8 +1277,8 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ var locChildren = this._children; for(var i = 0, len = locChildren.length; i < len; i++){ - if(locChildren[i]._name == name) - return locChildren[i]; + if(locChildren[i]._name == name) + return locChildren[i]; } return null; }, @@ -1362,7 +1345,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * If the cleanup parameter is not passed, it will force a cleanup.
* If the node orphan, then nothing happens. * @function - * @param {Boolean} cleanup true if all actions and callbacks on this node should be removed, false otherwise. + * @param {Boolean} [cleanup=true] true if all actions and callbacks on this node should be removed, false otherwise. * @see cc.Node#removeFromParentAndCleanup */ removeFromParent: function (cleanup) { @@ -1377,7 +1360,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * Removes this node itself from its parent node.
* If the node orphan, then nothing happens. * @deprecated since v3.0, please use removeFromParent() instead - * @param {Boolean} cleanup true if all actions and callbacks on this node should be removed, false otherwise. + * @param {Boolean} [cleanup=true] true if all actions and callbacks on this node should be removed, false otherwise. */ removeFromParentAndCleanup: function (cleanup) { cc.log(cc._LogInfos.Node_removeFromParentAndCleanup); @@ -1391,7 +1374,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * to override this method

* @function * @param {cc.Node} child The child node which will be removed. - * @param {Boolean|null} [cleanup=null] true if all running actions and callbacks on the child node will be cleanup, false otherwise. + * @param {Boolean} [cleanup=true] true if all running actions and callbacks on the child node will be cleanup, false otherwise. */ removeChild: function (child, cleanup) { // explicit nil handling @@ -1412,7 +1395,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * If the cleanup parameter is not passed, it will force a cleanup.
* @function * @param {Number} tag An integer number that identifies a child node - * @param {Boolean} cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise. + * @param {Boolean} [cleanup=true] true if all running actions and callbacks on the child node will be cleanup, false otherwise. * @see cc.Node#removeChildByTag */ removeChildByTag: function (tag, cleanup) { @@ -1428,7 +1411,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ /** * Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter. - * @param {Boolean | null } cleanup + * @param {Boolean} [cleanup=true] */ removeAllChildrenWithCleanup: function (cleanup) { //cc.log(cc._LogInfos.Node_removeAllChildrenWithCleanup); //TODO It should be discuss in v3.0 @@ -1439,7 +1422,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
* If the cleanup parameter is not passed, it will force a cleanup.
* @function - * @param {Boolean | null } cleanup true if all running actions on all children nodes should be cleanup, false otherwise. + * @param {Boolean} [cleanup=true] true if all running actions on all children nodes should be cleanup, false otherwise. */ removeAllChildren: function (cleanup) { // not using detachChild improves speed here @@ -1477,7 +1460,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ } // If you don't do cleanup, the child's actions will not get removed and the - // its scheduledSelectors_ dict will not get released! if (doCleanup) child.cleanup(); @@ -1578,7 +1560,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ onEnter: function () { this._isTransitionFinished = false; this._running = true;//should be running before resumeSchedule - this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.onEnter); + this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onEnter); this.resume(); }, @@ -1592,7 +1574,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ */ onEnterTransitionDidFinish: function () { this._isTransitionFinished = true; - this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.onEnterTransitionDidFinish); + this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onEnterTransitionDidFinish); }, /** @@ -1602,7 +1584,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * @function */ onExitTransitionDidStart: function () { - this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.onExitTransitionDidStart); + this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onExitTransitionDidStart); }, /** @@ -1617,7 +1599,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ onExit: function () { this._running = false; this.pause(); - this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.onExit); + this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onExit); this.removeAllComponents(); }, @@ -1631,7 +1613,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * @return {cc.Action} An Action pointer */ runAction: function (action) { - cc.assert(action, cc._LogInfos.Node_runAction); this.actionManager.addAction(action, this, !this._running); @@ -1743,7 +1724,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ interval = interval || 0; cc.assert(callback_fn, cc._LogInfos.Node_schedule); - cc.assert(interval >= 0, cc._LogInfos.Node_schedule_2); repeat = (repeat == null) ? cc.REPEAT_FOREVER : repeat; @@ -1770,7 +1750,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * @param {function} callback_fn A function wrapped as a selector */ unschedule: function (callback_fn) { - // explicit nil handling if (!callback_fn) return; @@ -2041,7 +2020,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ */ updateTransform: function () { // Recursively iterate over children - this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.updateTransform); + this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.updateTransform); }, /** @@ -2117,27 +2096,27 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ this._componentContainer.removeAll(); }, - //grid: null, + grid: null, /** * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. * @function */ - //ctor: null, + ctor: null, /** * Recursive method that visit its children and draw them * @function * @param {CanvasRenderingContext2D|WebGLRenderingContext} ctx */ - //visit: null, + visit: null, /** * Performs view-matrix transformation based on position, scale, rotation and other attributes. * @function * @param {CanvasRenderingContext2D|WebGLRenderingContext} ctx Render context */ - //transform: null, + transform: null, /** *

Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
@@ -2156,7 +2135,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * @function * @return {cc.AffineTransform} The affine transform object */ - //getNodeToParentTransform: null, + getNodeToParentTransform: null, _setNodeDirtyForCache: function () { if (this._cacheDirty === false) { @@ -2234,7 +2213,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ * It should be set in initialize phase. *

* @function - * @param {cc.GLProgram} newShaderProgram The shader program which fetchs from CCShaderCache. + * @param {cc.GLProgram} newShaderProgram The shader program which fetches from CCShaderCache. * @example * node.setGLProgram(cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR)); */ @@ -2522,10 +2501,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ else parentColor = cc.color.WHITE; this.updateDisplayedColor(parentColor); - - /*if (color.a !== undefined && !color.a_undefined) { //setColor doesn't support changing opacity, please use setOpacity - this.setOpacity(color.a); - }*/ }, /** @@ -2629,7 +2604,7 @@ cc.Node.create = function () { return new cc.Node(); }; -cc.Node._StateCallbackType = {onEnter: 1, onExit: 2, cleanup: 3, onEnterTransitionDidFinish: 4, updateTransform: 5, onExitTransitionDidStart: 6, sortAllChildren: 7}; +cc.Node._stateCallbackType = {onEnter: 1, onExit: 2, cleanup: 3, onEnterTransitionDidFinish: 4, updateTransform: 5, onExitTransitionDidStart: 6, sortAllChildren: 7}; if (cc._renderType === cc._RENDER_TYPE_CANVAS) { //redefine cc.Node @@ -2685,7 +2660,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { }; _p._transformForRenderer = function () { - var t = this.nodeToParentTransform(), worldT = this._transformWorld; + var t = this.getNodeToParentTransform(), worldT = this._transformWorld; if(this._parent){ var pt = this._parent._transformWorld; //worldT = cc.AffineTransformConcat(t, pt); @@ -2693,16 +2668,11 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { worldT.b = t.a * pt.b + t.b * pt.d; //b worldT.c = t.c * pt.a + t.d * pt.c; //c worldT.d = t.c * pt.b + t.d * pt.d; //d - if(!this._skewX || this._skewY){ - var plt = this._parent._transform; - var xOffset = -(plt.b + plt.c) * t.ty ; - var yOffset = -(plt.b + plt.c) * t.tx; - worldT.tx = (t.tx * pt.a + t.ty * pt.c + pt.tx + xOffset); //tx - worldT.ty = (t.tx * pt.b + t.ty * pt.d + pt.ty + yOffset); //ty - }else{ - worldT.tx = (t.tx * pt.a + t.ty * pt.c + pt.tx); //tx - worldT.ty = (t.tx * pt.b + t.ty * pt.d + pt.ty); //ty - } + var plt = this._parent._transform; + var xOffset = -(plt.b + plt.c) * t.ty; + var yOffset = -(plt.b + plt.c) * t.tx; + worldT.tx = (t.tx * pt.a + t.ty * pt.c + pt.tx + xOffset); //tx + worldT.ty = (t.tx * pt.b + t.ty * pt.d + pt.ty + yOffset); //ty } else { worldT.a = t.a; worldT.b = t.b; diff --git a/cocos2d/core/labelttf/CCLabelTTF.js b/cocos2d/core/labelttf/CCLabelTTF.js index d657a5f310..7fc4511674 100644 --- a/cocos2d/core/labelttf/CCLabelTTF.js +++ b/cocos2d/core/labelttf/CCLabelTTF.js @@ -64,7 +64,6 @@ * @property {Number} shadowBlur - The blur size of shadow */ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ - __type: "cc.LabelTTF", _dimensions: null, _hAlignment: cc.TEXT_ALIGNMENT_CENTER, _vAlignment: cc.VERTICAL_TEXT_ALIGNMENT_TOP, @@ -102,6 +101,8 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ _lineWidths: null, _className: "LabelTTF", + _lineHeight: 0, + /** * Initializes the cc.LabelTTF with a font name, alignment, dimension and font size, do not call it by yourself, * you should pass the correct arguments in constructor to initialize the label. @@ -201,21 +202,29 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ return ""; }, - //setColor: null, + setColor: null, _setColorsString: null, - //updateDisplayedColor: null, + updateDisplayedColor: null, - //setOpacity: null, + setOpacity: null, - //updateDisplayedOpacity: null, + updateDisplayedOpacity: null, updateDisplayedOpacityForCanvas: function (parentOpacity) { cc.Node.prototype.updateDisplayedOpacity.call(this, parentOpacity); this._setColorsString(); }, + getLineHeight: function(){ + return this._lineHeight || this._fontClientHeight; + }, + + setLineHeight: function(lineHeight){ + this._lineHeight = lineHeight; + }, + /** * Returns the text of the label * @return {String} @@ -271,7 +280,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ * @param {cc.FontDefinition} textDefinition * @return {Boolean} */ - //initWithStringAndTextDefinition: null, + initWithStringAndTextDefinition: null, /** * Sets the text definition used by this label @@ -492,7 +501,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ * @function * @param {cc.Color} fillColor The fill color of the label */ - //setFontFillColor: null, + setFontFillColor: null, _getFillStyle: function () { return this._textFillColor; @@ -597,6 +606,9 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ } }, _updateString: function () { + if ((!this._string || this._string === "") && this._string !== this._originalText) + cc.renderer.childrenOrderDirty = true; + this._string = this._originalText; }, @@ -750,6 +762,11 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ context.textAlign = cc.LabelTTF._textAlign[locHAlignment]; var locContentWidth = this._contentSize.width - locStrokeShadowOffsetX; + + //lineHiehgt + var lineHeight = this.getLineHeight(); + var transformTop = (lineHeight - this._fontClientHeight) / 2; + if (locHAlignment === cc.TEXT_ALIGNMENT_RIGHT) xOffset += locContentWidth; else if (locHAlignment === cc.TEXT_ALIGNMENT_CENTER) @@ -759,13 +776,13 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ if (this._isMultiLine) { var locStrLen = this._strings.length; if (locVAlignment === cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM) - yOffset = locFontHeight + locContentSizeHeight - locFontHeight * locStrLen; + yOffset = lineHeight - transformTop * 2 + locContentSizeHeight - lineHeight * locStrLen; else if (locVAlignment === cc.VERTICAL_TEXT_ALIGNMENT_CENTER) - yOffset = locFontHeight / 2 + (locContentSizeHeight - locFontHeight * locStrLen) / 2; + yOffset = (lineHeight - transformTop * 2) / 2 + (locContentSizeHeight - lineHeight * locStrLen) / 2; for (var i = 0; i < locStrLen; i++) { var line = this._strings[i]; - var tmpOffsetY = -locContentSizeHeight + (locFontHeight * i) + yOffset; + var tmpOffsetY = -locContentSizeHeight + (lineHeight * i + transformTop) + yOffset; if (locStrokeEnabled) context.strokeText(line, xOffset, tmpOffsetY); context.fillText(line, xOffset, tmpOffsetY); @@ -845,6 +862,10 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ } fuzzyLen -= pushNum; + if(fuzzyLen === 0){ + fuzzyLen = 1; + sLine = sLine.substr(1); + } var sText = text.substr(0, fuzzyLen); @@ -917,9 +938,9 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ } else { if (this._dimensions.height === 0) { if (this._isMultiLine) - locSize = cc.size(0 | (locDimensionsWidth + locStrokeShadowOffsetX), 0 | ((this._fontClientHeight * this._strings.length) + locStrokeShadowOffsetY)); + locSize = cc.size(0 | (locDimensionsWidth + locStrokeShadowOffsetX), 0 | ((this.getLineHeight() * this._strings.length) + locStrokeShadowOffsetY)); else - locSize = cc.size(0 | (locDimensionsWidth + locStrokeShadowOffsetX), 0 | (this._fontClientHeight + locStrokeShadowOffsetY)); + locSize = cc.size(0 | (locDimensionsWidth + locStrokeShadowOffsetX), 0 | (this.getLineHeight() + locStrokeShadowOffsetY)); } else { //dimension is already set, contentSize must be same as dimension locSize = cc.size(0 | (locDimensionsWidth + locStrokeShadowOffsetX), 0 | (this._dimensions.height + locStrokeShadowOffsetY)); @@ -996,7 +1017,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ cc.Sprite.prototype.visit.call(this, context); }, - //draw: null, + draw: null, _setTextureCoords: function (rect) { var tex = this._batchNode ? this.textureAtlas.texture : this._texture; diff --git a/cocos2d/core/layers/CCLayer.js b/cocos2d/core/layers/CCLayer.js index 21bf7393aa..2ab1259ae3 100644 --- a/cocos2d/core/layers/CCLayer.js +++ b/cocos2d/core/layers/CCLayer.js @@ -30,7 +30,6 @@ * @extends cc.Node */ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ - __type: "cc.Layer", _isBaked: false, _bakeSprite: null, _bakeRenderCmd: null, @@ -66,7 +65,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ * @function * @see cc.Layer#unbake */ - //bake: null, + bake: null, /** * Cancel the layer to cache all of children to a bake sprite.
@@ -74,7 +73,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ * @function * @see cc.Layer#bake */ - //unbake: null, + unbake: null, _bakeRendering: null, @@ -86,9 +85,9 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ */ isBaked: function(){ return this._isBaked; - } + }, - //visit: null + visit: null }); /** @@ -147,17 +146,16 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var _t = this; var children = _t._children, locBakeSprite = this._bakeSprite; //compute the bounding box of the bake layer. + this._transformForRenderer(); var boundingBox = this._getBoundingBoxForBake(); - boundingBox.width = 0 | boundingBox.width; - boundingBox.height = 0 | boundingBox.height; + boundingBox.width = 0|(boundingBox.width+0.5); + boundingBox.height = 0|(boundingBox.height+0.5); var bakeContext = locBakeSprite.getCacheContext(); locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height); bakeContext.translate(0 - boundingBox.x, boundingBox.height + boundingBox.y); - // invert var t = cc.affineTransformInvert(this._transformWorld); - var scaleX = cc.view.getScaleX(), scaleY = cc.view.getScaleY(); - bakeContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); + bakeContext.transform(t.a, t.c, t.b, t.d, t.tx , -t.ty ); //reset the bake sprite's position var anchor = locBakeSprite.getAnchorPointInPoints(); @@ -170,6 +168,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { children[i].visit(bakeContext); } cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId); + locBakeSprite.transform(); //because bake sprite's position was changed at rendering. this._cacheDirty = false; } }; @@ -231,7 +230,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { * CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol.
* All features from CCLayer are valid, plus the following new features:
* - opacity
- * - RGB colors

+ * - RGB colors

* @class * @extends cc.Layer * @@ -249,7 +248,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { * var yellowBox = new cc.LayerColor(cc.color(255,255,0,255), 200, 200); */ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ - __type: "cc.LayerColor", _blendFunc: null, _className: "LayerColor", @@ -310,7 +308,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ this._updateColor(); }, - _blendFuncStr: "source", + _blendFuncStr: "source-over", /** * Constructor of cc.LayerColor @@ -319,7 +317,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ * @param {Number} [width=] * @param {Number} [height=] */ - //ctor: null, + ctor: null, /** * Initialization of the layer, please do not call this function by yourself, you should pass the parameters to constructor to initialize a layer @@ -390,7 +388,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ this._updateColor(); }, - //draw: null + draw: null }); /** @@ -469,8 +467,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { } // invert var t = cc.affineTransformInvert(this._transformWorld); - var scaleX = cc.view.getScaleX(), scaleY = cc.view.getScaleY(); - bakeContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); + bakeContext.transform(t.a, t.c, t.b, t.d, t.tx, -t.ty); var child; cc.renderer._turnToCacheMode(this.__instanceId); @@ -494,6 +491,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if(_t._rendererCmd) cc.renderer.pushRenderCommand(_t._rendererCmd); cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId); + locBakeSprite.transform(); this._cacheDirty = false; } }; @@ -523,8 +521,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { _p._getBoundingBoxForBake = function () { //default size var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height); - var trans = this.nodeToWorldTransform(); - rect = cc.rectApplyAffineTransform(rect, this.nodeToWorldTransform()); + var trans = this.getNodeToWorldTransform(); + rect = cc.rectApplyAffineTransform(rect, this.getNodeToWorldTransform()); //query child's BoundingBox if (!this._children || this._children.length === 0) @@ -587,7 +585,6 @@ delete cc._tmp.PrototypeLayerColor; * @property {Number} compresseInterpolation - Indicate whether or not the interpolation will be compressed */ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{ - __type: "cc.LayerGradient", _endColor: null, _startOpacity: 255, _endOpacity: 255, @@ -838,7 +835,6 @@ delete cc._tmp.PrototypeLayerGradient; * var multiLayer = new cc.LayerMultiple(layer1, layer2, layer3);//any number of layers */ cc.LayerMultiplex = cc.Layer.extend(/** @lends cc.LayerMultiplex# */{ - __type: "cc.LayerMultiplex", _enabledLayer: 0, _layers: null, _className: "LayerMultiplex", diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index c9082a59cf..fbfb92ea00 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -146,10 +146,6 @@ ClassManager.compileSuper.ClassManager = ClassManager; this.__getters__ && (Class.__getters__ = cc.clone(this.__getters__)); this.__setters__ && (Class.__setters__ = cc.clone(this.__setters__)); - supportProp = props.__type ? true : false; - if (supportProp) - cc.addProperty(prototype, "__type"); - for(idx = 0, li = arguments.length; idx < li; ++idx) { prop = arguments[idx]; for (name in prop) { @@ -179,11 +175,6 @@ ClassManager.compileSuper.ClassManager = ClassManager; desc.value = prop[name]; Object.defineProperty(prototype, name, desc); } else { - // Add property - if (supportProp && name[0] != "_") { - cc.addProperty(prototype, name, prop[name]); - } - prototype[name] = prop[name]; } @@ -288,44 +279,6 @@ cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, sette } }; -/** - * Add a serializable property to a prototype - * @function - * @param {Object} proto A class prototype or an object to config
- * @param {String} prop Property name - * @param {function} getter Getter function for the property - * @param {function} setter Setter function for the property - */ -cc.addProperty = function(proto, prop, value, getter, setter) { - if (typeof value == "function") { - setter = getter; - getter = value; - value = undefined; - } - - var props; - if (proto.hasOwnProperty("__props")) { - props = proto.__props; - } - else { - props = proto.__props = {}; - } - - if (getter || setter) { - cc.defineGetterSetter(proto, prop, getter, setter); - if (!props[prop]) - props[prop] = value; - } - else { - if (value !== undefined) - props[prop] = value; - else if (proto[prop] !== undefined) - props[prop] = proto[prop]; - else - props[prop] = null; - } -}; - /** * Create a new object and copy all properties in an exist object to the new object * @function @@ -369,99 +322,3 @@ cc.clone = function (obj) { } return newObj; }; - -(function(cc) { - - cc.__delegators = { - color : { - parser : function(json) { - return cc.color(json[0], json[1], json[2], json[3]); - }, - stringifier : function(color) { - return [color.r, color.g, color.b, color.a]; - } - } - }; - - function unitSerialize (node, key) { - var value = node[key]; - // Found stringifier - if ( node.__delegators && node.__delegators[key] && node.__delegators[key].stringifier ) { - return JSON.stringify(node.__delegators[key].stringifier(value)); - } - // Found type - else if ( value && value.__type ) { - return cc.serialize(value); - } - else if (typeof value != "object" || (value && Object.getPrototypeOf(value) == Object.prototype)) { - return JSON.stringify(value); - } - } - - function unitDeserialize (key, value, obj) { - // Found parser - if ( obj.__delegators && obj.__delegators[key] && obj.__delegators[key].parser ) { - return obj.__delegators[key].parser(JSON.parse(value)); - } - // Found type - else if (value.__type) { - return cc.deserialize(value); - } - else { - return JSON.parse(value); - } - } - - cc.serialize = function (node) { - var res = {}, key, defaultVal, - proto = node.constructor.prototype; - // Iterate until the top of prototype chain - while (proto != Object.prototype) { - // Check all properties - for (key in proto.__props) { - defaultVal = proto.__props[key]; - // Serialize only when i is not defined yet and different from the value in prototype - if ( res[key] === undefined && node[key] !== defaultVal ) { - res[key] = unitSerialize(node, key); - } - } - proto = Object.getPrototypeOf(proto); - } - - return JSON.stringify(res); - } - - cc.deserialize = function (json) { - var obj, type = null, varsArr, json = JSON.parse(json); - - // Create object with type - if (json.__type) { - type = window; - varsArr = JSON.parse(json.__type).split("."); - for (var i in varsArr) { - if (type) { - type = type[varsArr[i]]; - } - else { - type = null; - break; - } - } - } - if (type) { - obj = new type(); - } - // Fail to initialize with type - else { - obj = {}; - } - - // Iterate all serialized properties - for (var i in json) { - obj[i] = unitDeserialize(i, json[i], obj); - } - - return obj; - } -})(cc); - diff --git a/cocos2d/core/sprites/CCSprite.js b/cocos2d/core/sprites/CCSprite.js index 83aab2088f..5e205daa5c 100644 --- a/cocos2d/core/sprites/CCSprite.js +++ b/cocos2d/core/sprites/CCSprite.js @@ -228,7 +228,7 @@ cc.cutRotateImageToCanvas = function (texture, rect) { cc._getCompositeOperationByBlendFunc = function(blendFunc){ if(!blendFunc) - return "source"; + return "source-over"; else{ if(( blendFunc.src == cc.SRC_ALPHA && blendFunc.dst == cc.ONE) || (blendFunc.src == cc.ONE && blendFunc.dst == cc.ONE)) return "lighter"; @@ -237,7 +237,7 @@ cc._getCompositeOperationByBlendFunc = function(blendFunc){ else if(blendFunc.src == cc.ZERO && blendFunc.dst == cc.ONE_MINUS_SRC_ALPHA) return "destination-out"; else - return "source"; + return "source-over"; } }; @@ -301,10 +301,8 @@ cc._getCompositeOperationByBlendFunc = function(blendFunc){ * @property {cc.V3F_C4B_T2F_Quad} quad - <@readonly> The quad (tex coords, vertex coords and color) information. */ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ - __type:"cc.Sprite", - - dirty:false, - atlasIndex:-1, + dirty:false, + atlasIndex:0, textureAtlas:null, _batchNode:null, @@ -434,12 +432,12 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ return cc.p(this._offsetPosition); }, - _getOffsetX: function () { - return this._offsetPosition.x; - }, - _getOffsetY: function () { - return this._offsetPosition.y; - }, + _getOffsetX: function () { + return this._offsetPosition.x; + }, + _getOffsetY: function () { + return this._offsetPosition.y; + }, /** * Returns the blend function @@ -548,7 +546,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ } if (this._batchNode) { - this._arrayMakeObjectsPerformSelector(_children, cc.Node._StateCallbackType.sortAllChildren); + this._arrayMakeObjectsPerformSelector(_children, cc.Node._stateCallbackType.sortAllChildren); } //don't need to check children recursively, that's done in visit of each child @@ -622,39 +620,39 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ // cc.Node property overloads // - /** - * Sets recursively the dirty flag. - * Used only when parent is cc.SpriteBatchNode - * @param {Boolean} value - */ - setDirtyRecursively:function (value) { - this._recursiveDirty = value; - this.dirty = value; - // recursively set dirty - var locChildren = this._children, child, l = locChildren ? locChildren.length : 0; - for (var i = 0; i < l; i++) { - child = locChildren[i]; - (child instanceof cc.Sprite) && child.setDirtyRecursively(true); - } - }, - - /** - * Make the node dirty - * @param {Boolean} norecursive When true children will not be set dirty recursively, by default, they will be. - * @override - */ - setNodeDirty: function(norecursive) { - cc.Node.prototype.setNodeDirty.call(this); - // Lazy set dirty - if (!norecursive && this._batchNode && !this._recursiveDirty) { - if (this._hasChildren) - this.setDirtyRecursively(true); - else { - this._recursiveDirty = true; - this.dirty = true; - } - } - }, + /** + * Sets recursively the dirty flag. + * Used only when parent is cc.SpriteBatchNode + * @param {Boolean} value + */ + setDirtyRecursively:function (value) { + this._recursiveDirty = value; + this.dirty = value; + // recursively set dirty + var locChildren = this._children, child, l = locChildren ? locChildren.length : 0; + for (var i = 0; i < l; i++) { + child = locChildren[i]; + (child instanceof cc.Sprite) && child.setDirtyRecursively(true); + } + }, + + /** + * Make the node dirty + * @param {Boolean} norecursive When true children will not be set dirty recursively, by default, they will be. + * @override + */ + setNodeDirty: function(norecursive) { + cc.Node.prototype.setNodeDirty.call(this); + // Lazy set dirty + if (!norecursive && this._batchNode && !this._recursiveDirty) { + if (this._hasChildren) + this.setDirtyRecursively(true); + else { + this._recursiveDirty = true; + this.dirty = true; + } + } + }, /** * Sets whether ignore anchor point for positioning @@ -729,7 +727,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {Boolean} modify */ - //setOpacityModifyRGB:null, + setOpacityModifyRGB:null, /** * Returns whether opacity modify color or not. @@ -743,7 +741,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * Update the display opacity. * @function */ - //updateDisplayedOpacity: null, + updateDisplayedOpacity: null, // Animation @@ -802,41 +800,41 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _quadWebBuffer: null, _quadDirty: false, _colorized: false, - _blendFuncStr: "source", + _blendFuncStr: "source-over", _originalTexture: null, _drawSize_Canvas: null, - //ctor: null, - - _softInit: function (fileName, rect, rotated) { - if (fileName === undefined) - cc.Sprite.prototype.init.call(this); - else if (cc.isString(fileName)) { - if (fileName[0] === "#") { - // Init with a sprite frame name - var frameName = fileName.substr(1, fileName.length - 1); - var spriteFrame = cc.spriteFrameCache.getSpriteFrame(frameName); - this.initWithSpriteFrame(spriteFrame); - } else { - // Init with filename and rect - cc.Sprite.prototype.init.call(this, fileName, rect); - } - } else if (cc.isObject(fileName)) { - if (fileName instanceof cc.Texture2D) { - // Init with texture and rect - this.initWithTexture(fileName, rect, rotated); - } else if (fileName instanceof cc.SpriteFrame) { - // Init with a sprite frame - this.initWithSpriteFrame(fileName); - } else if ((fileName instanceof HTMLImageElement) || (fileName instanceof HTMLCanvasElement)) { - // Init with a canvas or image element - var texture2d = new cc.Texture2D(); - texture2d.initWithElement(fileName); - texture2d.handleLoadedTexture(); - this.initWithTexture(texture2d); - } - } - }, + ctor: null, + + _softInit: function (fileName, rect, rotated) { + if (fileName === undefined) + cc.Sprite.prototype.init.call(this); + else if (cc.isString(fileName)) { + if (fileName[0] === "#") { + // Init with a sprite frame name + var frameName = fileName.substr(1, fileName.length - 1); + var spriteFrame = cc.spriteFrameCache.getSpriteFrame(frameName); + this.initWithSpriteFrame(spriteFrame); + } else { + // Init with filename and rect + cc.Sprite.prototype.init.call(this, fileName, rect); + } + } else if (cc.isObject(fileName)) { + if (fileName instanceof cc.Texture2D) { + // Init with texture and rect + this.initWithTexture(fileName, rect, rotated); + } else if (fileName instanceof cc.SpriteFrame) { + // Init with a sprite frame + this.initWithSpriteFrame(fileName); + } else if ((fileName instanceof HTMLImageElement) || (fileName instanceof HTMLCanvasElement)) { + // Init with a canvas or image element + var texture2d = new cc.Texture2D(); + texture2d.initWithElement(fileName); + texture2d.handleLoadedTexture(); + this.initWithTexture(texture2d); + } + } + }, /** * Returns the quad (tex coords, vertex coords and color) information. @@ -852,7 +850,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Number|cc.BlendFunc} src * @param {Number} dst */ - //setBlendFunc: null, + setBlendFunc: null, /** * Initializes an empty sprite with nothing init.
@@ -860,7 +858,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @return {Boolean} */ - //init:null, + init:null, /** *

@@ -901,7 +899,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Boolean} [rotated] Whether or not the texture rectangle is rotated. * @return {Boolean} true if the sprite is initialized properly, false otherwise. */ - //initWithTexture: null, + initWithTexture: null, _textureLoadedCallback: null, @@ -912,14 +910,14 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Boolean} [rotated] Whether or not the texture is rotated * @param {cc.Size} [untrimmedSize] The original pixels size of the texture */ - //setTextureRect:null, + setTextureRect:null, // BatchNode methods /** * Updates the quad according the the rotation, position, scale values. * @function */ - //updateTransform: null, + updateTransform: null, /** * Add child to sprite (override cc.Node) @@ -929,7 +927,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {String} tag child's tag * @override */ - //addChild: null, + addChild: null, /** * Update sprite's color @@ -969,20 +967,20 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {Number} opacity */ - //setOpacity:null, + setOpacity:null, /** * Sets color of the sprite * @function * @param {cc.Color} color3 */ - //setColor: null, + setColor: null, /** * Updates the display color * @function */ - //updateDisplayedColor: null, + updateDisplayedColor: null, // Frames /** @@ -990,7 +988,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {cc.SpriteFrame|String} newFrame */ - //setSpriteFrame: null, + setSpriteFrame: null, /** * Sets a new display frame to the sprite. @@ -1008,7 +1006,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {cc.SpriteFrame} frame * @return {Boolean} */ - //isFrameDisplayed: null, + isFrameDisplayed: null, /** * Returns the current displayed frame. @@ -1016,10 +1014,10 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ */ displayFrame: function () { return new cc.SpriteFrame(this._texture, - cc.rectPointsToPixels(this._rect), - this._rectRotated, - cc.pointPointsToPixels(this._unflippedOffsetPositionFromCenter), - cc.sizePointsToPixels(this._contentSize)); + cc.rectPointsToPixels(this._rect), + this._rectRotated, + cc.pointPointsToPixels(this._unflippedOffsetPositionFromCenter), + cc.sizePointsToPixels(this._contentSize)); }, /** @@ -1032,7 +1030,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * batch.addChild(sprite); * layer.addChild(batch); */ - //setBatchNode:null, + setBatchNode:null, // CCTextureProtocol /** @@ -1040,7 +1038,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @function * @param {cc.Texture2D|String} texture */ - //setTexture: null, + setTexture: null, // Texture protocol _updateBlendFunc:function () { @@ -1271,7 +1269,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.Node.prototype.init.call(_t); _t.dirty = _t._recursiveDirty = false; - _t._opacityModifyRGB = true; _t._blendFunc.src = cc.BLEND_SRC; _t._blendFunc.dst = cc.BLEND_DST; @@ -1449,10 +1446,10 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { _t._shouldBeHidden = false; if (!locParent || locParent == _t._batchNode) { - _t._transformToBatch = _t.nodeToParentTransform(); + _t._transformToBatch = _t.getNodeToParentTransform(); } else { //cc.assert(_t._parent instanceof cc.Sprite, "Logic error in CCSprite. Parent must be a CCSprite"); - _t._transformToBatch = cc.affineTransformConcat(_t.nodeToParentTransform(), locParent._transformToBatch); + _t._transformToBatch = cc.affineTransformConcat(_t.getNodeToParentTransform(), locParent._transformToBatch); } } _t._recursiveDirty = false; @@ -1461,7 +1458,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { // recursively iterate over children if (_t._hasChildren) - _t._arrayMakeObjectsPerformSelector(_t._children, cc.Node._StateCallbackType.updateTransform); + _t._arrayMakeObjectsPerformSelector(_t._children, cc.Node._stateCallbackType.updateTransform); }; _p.addChild = function (child, localZOrder, tag) { From 84989eb1b6da4082548400bb86560f1b8f23ddbe Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 2 Dec 2014 14:42:24 +0800 Subject: [PATCH 21/32] #20: Revert panda version serialization --- .../base-nodes/BaseNodesPropertyDefine.js | 68 +++++++------------ .../core/labelttf/LabelTTFPropertyDefine.js | 32 ++++----- cocos2d/core/layers/CCLayerPropertyDefine.js | 15 ++-- cocos2d/core/sprites/SpritesPropertyDefine.js | 19 +----- cocos2d/core/textures/CCTextureAtlas.js | 6 +- 5 files changed, 50 insertions(+), 90 deletions(-) diff --git a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js index 74dc981d36..c14d87ffac 100644 --- a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js +++ b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js @@ -28,44 +28,44 @@ cc._tmp.PrototypeCCNode = function () { var _p = cc.Node.prototype; - cc.addProperty(_p, "x", 0, _p.getPositionX, _p.setPositionX); - cc.addProperty(_p, "y", 0, _p.getPositionY, _p.setPositionY); + cc.defineGetterSetter(_p, "x", _p.getPositionX, _p.setPositionX); + cc.defineGetterSetter(_p, "y", _p.getPositionY, _p.setPositionY); /** @expose */ //_p.pos; - //cc.addProperty(_p, "pos", _p.getPosition, _p.setPosition); + //cc.defineGetterSetter(_p, "pos", _p.getPosition, _p.setPosition); /** @expose */ _p.width; - cc.addProperty(_p, "width", 0, _p._getWidth, _p._setWidth); + cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth); /** @expose */ _p.height; - cc.addProperty(_p, "height", 0, _p._getHeight, _p._setHeight); + cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight); /** @expose */ //_p.size; - //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); + //cc.defineGetterSetter(_p, "size", _p.getContentSize, _p.setContentSize); /** @expose */ //_p.anchor; - //cc.addProperty(_p, "anchor", _p._getAnchor, _p._setAnchor); + //cc.defineGetterSetter(_p, "anchor", _p._getAnchor, _p._setAnchor); /** @expose */ _p.anchorX; - cc.addProperty(_p, "anchorX", 0, _p._getAnchorX, _p._setAnchorX); + cc.defineGetterSetter(_p, "anchorX", _p._getAnchorX, _p._setAnchorX); /** @expose */ _p.anchorY; - cc.addProperty(_p, "anchorY", 0, _p._getAnchorY, _p._setAnchorY); + cc.defineGetterSetter(_p, "anchorY", _p._getAnchorY, _p._setAnchorY); /** @expose */ _p.skewX; - cc.addProperty(_p, "skewX", 0, _p.getSkewX, _p.setSkewX); + cc.defineGetterSetter(_p, "skewX", _p.getSkewX, _p.setSkewX); /** @expose */ _p.skewY; - cc.addProperty(_p, "skewY", 0, _p.getSkewY, _p.setSkewY); + cc.defineGetterSetter(_p, "skewY", _p.getSkewY, _p.setSkewY); /** @expose */ _p.zIndex; - cc.addProperty(_p, "zIndex", 0, _p.getLocalZOrder, _p.setLocalZOrder); + cc.defineGetterSetter(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); /** @expose */ _p.vertexZ; cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); /** @expose */ _p.rotation; - cc.addProperty(_p, "rotation", 0, _p.getRotation, _p.setRotation); + cc.defineGetterSetter(_p, "rotation", _p.getRotation, _p.setRotation); /** @expose */ _p.rotationX; cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX); @@ -77,13 +77,13 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale); /** @expose */ _p.scaleX; - cc.addProperty(_p, "scaleX", 1, _p.getScaleX, _p.setScaleX); + cc.defineGetterSetter(_p, "scaleX", _p.getScaleX, _p.setScaleX); /** @expose */ _p.scaleY; - cc.addProperty(_p, "scaleY", 1, _p.getScaleY, _p.setScaleY); + cc.defineGetterSetter(_p, "scaleY", _p.getScaleY, _p.setScaleY); /** @expose */ _p.children; - cc.addProperty(_p, "children", _p.getChildren, _p.setChildren); + cc.defineGetterSetter(_p, "children", _p.getChildren, _p.setChildren); /** @expose */ _p.childrenCount; cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount); @@ -92,13 +92,13 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent); /** @expose */ _p.visible; - cc.addProperty(_p, "visible", true, _p.isVisible, _p.setVisible); + cc.defineGetterSetter(_p, "visible", _p.isVisible, _p.setVisible); /** @expose */ _p.running; cc.defineGetterSetter(_p, "running", _p.isRunning); /** @expose */ _p.ignoreAnchor; - cc.addProperty(_p, "ignoreAnchor", false, _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); + cc.defineGetterSetter(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); /** @expose */ _p.tag; /** @expose */ @@ -119,41 +119,19 @@ cc._tmp.PrototypeCCNode = function () { /** @expose */ _p.opacity; - cc.addProperty(_p, "opacity", 255, _p.getOpacity, _p.setOpacity); + cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); /** @expose */ _p.opacityModifyRGB; - cc.addProperty(_p, "opacityModifyRGB", false, _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); + cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); /** @expose */ _p.cascadeOpacity; - cc.addProperty(_p, "cascadeOpacity", false, _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); + cc.defineGetterSetter(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); /** @expose */ _p.color; - cc.addProperty(_p, "color", null, _p.getColor, _p.setColor); + cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); /** @expose */ _p.cascadeColor; - cc.addProperty(_p, "cascadeColor", false, _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); - - _p.__delegators = { - color : cc.__delegators.color, - children : { - parser : function(json) { - var children = []; - for (var i in json) { - // Generate one child - children.push( cc.deserialize(json[i]) ); - } - return children; - }, - stringifier : function(children) { - var json = []; - for (var i in children) { - // Generate one child - json.push( cc.serialize(children[i]) ); - } - return JSON.stringify(json); - } - } - } + cc.defineGetterSetter(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); }; diff --git a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js index 09b9c053af..8f0f7d7bc5 100644 --- a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js +++ b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js @@ -35,53 +35,53 @@ cc._tmp.PrototypeLabelTTF = function () { // Extended properties /** @expose */ _p.string; - cc.addProperty(_p, "string", "", _p.getString, _p.setString); + cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); /** @expose */ _p.textAlign; - cc.addProperty(_p, "textAlign", 1, _p.getHorizontalAlignment, _p.setHorizontalAlignment); + cc.defineGetterSetter(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment); /** @expose */ _p.verticalAlign; - cc.addProperty(_p, "verticalAlign", 0, _p.getVerticalAlignment, _p.setVerticalAlignment); + cc.defineGetterSetter(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment); /** @expose */ _p.fontSize; - cc.addProperty(_p, "fontSize", 0, _p.getFontSize, _p.setFontSize); + cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize); /** @expose */ _p.fontName; - cc.addProperty(_p, "fontName", "Arial", _p.getFontName, _p.setFontName); + cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName); /** @expose */ _p.font; cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); /** @expose */ _p.boundingSize; - //cc.addProperty(_p, "boundingSize", _p.getDimensions, _p.setDimensions); + //cc.defineGetterSetter(_p, "boundingSize", _p.getDimensions, _p.setDimensions); /** @expose */ _p.boundingWidth; - cc.addProperty(_p, "boundingWidth", 0, _p._getBoundingWidth, _p._setBoundingWidth); + cc.defineGetterSetter(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth); /** @expose */ _p.boundingHeight; - cc.addProperty(_p, "boundingHeight", 0, _p._getBoundingHeight, _p._setBoundingHeight); + cc.defineGetterSetter(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight); /** @expose */ _p.fillStyle; - cc.addProperty(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); + cc.defineGetterSetter(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); /** @expose */ _p.strokeStyle; - cc.addProperty(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); + cc.defineGetterSetter(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); /** @expose */ _p.lineWidth; - cc.addProperty(_p, "lineWidth", 0, _p._getLineWidth, _p._setLineWidth); + cc.defineGetterSetter(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth); /** @expose */ _p.shadowOffset; - //cc.addProperty(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); + //cc.defineGetterSetter(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); /** @expose */ _p.shadowOffsetX; - cc.addProperty(_p, "shadowOffsetX", 0, _p._getShadowOffsetX, _p._setShadowOffsetX); + cc.defineGetterSetter(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX); /** @expose */ _p.shadowOffsetY; - cc.addProperty(_p, "shadowOffsetY", 0, _p._getShadowOffsetY, _p._setShadowOffsetY); + cc.defineGetterSetter(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY); /** @expose */ _p.shadowOpacity; - cc.addProperty(_p, "shadowOpacity", 0, _p._getShadowOpacity, _p._setShadowOpacity); + cc.defineGetterSetter(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity); /** @expose */ _p.shadowBlur; - cc.addProperty(_p, "shadowBlur", 0, _p._getShadowBlur, _p._setShadowBlur); + cc.defineGetterSetter(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur); }; \ No newline at end of file diff --git a/cocos2d/core/layers/CCLayerPropertyDefine.js b/cocos2d/core/layers/CCLayerPropertyDefine.js index 7ce333d430..0600fa1dd6 100644 --- a/cocos2d/core/layers/CCLayerPropertyDefine.js +++ b/cocos2d/core/layers/CCLayerPropertyDefine.js @@ -36,22 +36,17 @@ cc._tmp.PrototypeLayerGradient = function () { // Extended properties /** @expose */ _p.startColor; - cc.addProperty(_p, "startColor", _p.getStartColor, _p.setStartColor); + cc.defineGetterSetter(_p, "startColor", _p.getStartColor, _p.setStartColor); /** @expose */ _p.endColor; - cc.addProperty(_p, "endColor", _p.getEndColor, _p.setEndColor); + cc.defineGetterSetter(_p, "endColor", _p.getEndColor, _p.setEndColor); /** @expose */ _p.startOpacity; - cc.addProperty(_p, "startOpacity", 255, _p.getStartOpacity, _p.setStartOpacity); + cc.defineGetterSetter(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity); /** @expose */ _p.endOpacity; - cc.addProperty(_p, "endOpacity", 255, _p.getEndOpacity, _p.setEndOpacity); + cc.defineGetterSetter(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity); /** @expose */ _p.vector; - cc.addProperty(_p, "vector", _p.getVector, _p.setVector); - - _p.__delegators = { - startColor : cc.__delegators.color, - endColor : cc.__delegators.color - } + cc.defineGetterSetter(_p, "vector", _p.getVector, _p.setVector); }; \ No newline at end of file diff --git a/cocos2d/core/sprites/SpritesPropertyDefine.js b/cocos2d/core/sprites/SpritesPropertyDefine.js index b576ca9a72..20e8cc938a 100644 --- a/cocos2d/core/sprites/SpritesPropertyDefine.js +++ b/cocos2d/core/sprites/SpritesPropertyDefine.js @@ -37,10 +37,10 @@ cc._tmp.PrototypeSprite = function () { _p.dirty; /** @expose */ _p.flippedX; - cc.addProperty(_p, "flippedX", false, _p.isFlippedX, _p.setFlippedX); + cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX); /** @expose */ _p.flippedY; - cc.addProperty(_p, "flippedY", false, _p.isFlippedY, _p.setFlippedY); + cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); /** @expose */ _p.offsetX; cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX); @@ -51,7 +51,7 @@ cc._tmp.PrototypeSprite = function () { _p.atlasIndex; /** @expose */ _p.texture; - cc.addProperty(_p, "texture", null, _p.getTexture, _p.setTexture); + cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture); /** @expose */ _p.textureRectRotated; cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated); @@ -64,17 +64,4 @@ cc._tmp.PrototypeSprite = function () { _p.quad; cc.defineGetterSetter(_p, "quad", _p.getQuad); - _p.__type = "cc.Sprite"; - - _p.__delegators = { - "texture" : { - parser : function(json) { - return cc.textureCache.addImage(json); - }, - stringifier : function(texture) { - return cc.textureCache.getKeyByTexture(texture); - } - } - } - }; diff --git a/cocos2d/core/textures/CCTextureAtlas.js b/cocos2d/core/textures/CCTextureAtlas.js index f1b753abfb..c08c610078 100644 --- a/cocos2d/core/textures/CCTextureAtlas.js +++ b/cocos2d/core/textures/CCTextureAtlas.js @@ -616,13 +616,13 @@ var _p = cc.TextureAtlas.prototype; // Extended properties /** @expose */ _p.totalQuads; -cc.addProperty(_p, "totalQuads", _p.getTotalQuads); +cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads); /** @expose */ _p.capacity; -cc.addProperty(_p, "capacity", _p.getCapacity); +cc.defineGetterSetter(_p, "capacity", _p.getCapacity); /** @expose */ _p.quads; -cc.addProperty(_p, "quads", _p.getQuads, _p.setQuads); +cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads); /** *

Creates a TextureAtlas with an filename and with an initial capacity for Quads.
From fdac4c54c932bd587ad3283abcf2e3faae34bff7 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 2 Dec 2014 14:44:57 +0800 Subject: [PATCH 22/32] #28: Merge require.js support --- .../base-nodes/BaseNodesPropertyDefine.js | 68 ++++------- .../core/labelttf/LabelTTFPropertyDefine.js | 32 ++--- cocos2d/core/layers/CCLayerPropertyDefine.js | 15 +-- cocos2d/core/sprites/SpritesPropertyDefine.js | 19 +-- cocos2d/core/textures/CCTexture2D.js | 14 +-- cocos2d/core/textures/CCTextureAtlas.js | 6 +- cocos2d/core/textures/TexturesWebGL.js | 6 + modules/LabelBMFont.js | 2 +- modules/LabelTTF.js | 2 +- modules/Menu.js | 4 +- modules/Node.js | 2 +- modules/Sprite.js | 4 +- modules/actions.js | 2 +- modules/audio.js | 2 +- modules/layers.js | 2 +- modules/menuitems.js | 6 +- require.js | 110 +++++++++--------- 17 files changed, 131 insertions(+), 165 deletions(-) diff --git a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js index 74dc981d36..c14d87ffac 100644 --- a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js +++ b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js @@ -28,44 +28,44 @@ cc._tmp.PrototypeCCNode = function () { var _p = cc.Node.prototype; - cc.addProperty(_p, "x", 0, _p.getPositionX, _p.setPositionX); - cc.addProperty(_p, "y", 0, _p.getPositionY, _p.setPositionY); + cc.defineGetterSetter(_p, "x", _p.getPositionX, _p.setPositionX); + cc.defineGetterSetter(_p, "y", _p.getPositionY, _p.setPositionY); /** @expose */ //_p.pos; - //cc.addProperty(_p, "pos", _p.getPosition, _p.setPosition); + //cc.defineGetterSetter(_p, "pos", _p.getPosition, _p.setPosition); /** @expose */ _p.width; - cc.addProperty(_p, "width", 0, _p._getWidth, _p._setWidth); + cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth); /** @expose */ _p.height; - cc.addProperty(_p, "height", 0, _p._getHeight, _p._setHeight); + cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight); /** @expose */ //_p.size; - //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); + //cc.defineGetterSetter(_p, "size", _p.getContentSize, _p.setContentSize); /** @expose */ //_p.anchor; - //cc.addProperty(_p, "anchor", _p._getAnchor, _p._setAnchor); + //cc.defineGetterSetter(_p, "anchor", _p._getAnchor, _p._setAnchor); /** @expose */ _p.anchorX; - cc.addProperty(_p, "anchorX", 0, _p._getAnchorX, _p._setAnchorX); + cc.defineGetterSetter(_p, "anchorX", _p._getAnchorX, _p._setAnchorX); /** @expose */ _p.anchorY; - cc.addProperty(_p, "anchorY", 0, _p._getAnchorY, _p._setAnchorY); + cc.defineGetterSetter(_p, "anchorY", _p._getAnchorY, _p._setAnchorY); /** @expose */ _p.skewX; - cc.addProperty(_p, "skewX", 0, _p.getSkewX, _p.setSkewX); + cc.defineGetterSetter(_p, "skewX", _p.getSkewX, _p.setSkewX); /** @expose */ _p.skewY; - cc.addProperty(_p, "skewY", 0, _p.getSkewY, _p.setSkewY); + cc.defineGetterSetter(_p, "skewY", _p.getSkewY, _p.setSkewY); /** @expose */ _p.zIndex; - cc.addProperty(_p, "zIndex", 0, _p.getLocalZOrder, _p.setLocalZOrder); + cc.defineGetterSetter(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); /** @expose */ _p.vertexZ; cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); /** @expose */ _p.rotation; - cc.addProperty(_p, "rotation", 0, _p.getRotation, _p.setRotation); + cc.defineGetterSetter(_p, "rotation", _p.getRotation, _p.setRotation); /** @expose */ _p.rotationX; cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX); @@ -77,13 +77,13 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale); /** @expose */ _p.scaleX; - cc.addProperty(_p, "scaleX", 1, _p.getScaleX, _p.setScaleX); + cc.defineGetterSetter(_p, "scaleX", _p.getScaleX, _p.setScaleX); /** @expose */ _p.scaleY; - cc.addProperty(_p, "scaleY", 1, _p.getScaleY, _p.setScaleY); + cc.defineGetterSetter(_p, "scaleY", _p.getScaleY, _p.setScaleY); /** @expose */ _p.children; - cc.addProperty(_p, "children", _p.getChildren, _p.setChildren); + cc.defineGetterSetter(_p, "children", _p.getChildren, _p.setChildren); /** @expose */ _p.childrenCount; cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount); @@ -92,13 +92,13 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent); /** @expose */ _p.visible; - cc.addProperty(_p, "visible", true, _p.isVisible, _p.setVisible); + cc.defineGetterSetter(_p, "visible", _p.isVisible, _p.setVisible); /** @expose */ _p.running; cc.defineGetterSetter(_p, "running", _p.isRunning); /** @expose */ _p.ignoreAnchor; - cc.addProperty(_p, "ignoreAnchor", false, _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); + cc.defineGetterSetter(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); /** @expose */ _p.tag; /** @expose */ @@ -119,41 +119,19 @@ cc._tmp.PrototypeCCNode = function () { /** @expose */ _p.opacity; - cc.addProperty(_p, "opacity", 255, _p.getOpacity, _p.setOpacity); + cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); /** @expose */ _p.opacityModifyRGB; - cc.addProperty(_p, "opacityModifyRGB", false, _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); + cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); /** @expose */ _p.cascadeOpacity; - cc.addProperty(_p, "cascadeOpacity", false, _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); + cc.defineGetterSetter(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); /** @expose */ _p.color; - cc.addProperty(_p, "color", null, _p.getColor, _p.setColor); + cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); /** @expose */ _p.cascadeColor; - cc.addProperty(_p, "cascadeColor", false, _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); - - _p.__delegators = { - color : cc.__delegators.color, - children : { - parser : function(json) { - var children = []; - for (var i in json) { - // Generate one child - children.push( cc.deserialize(json[i]) ); - } - return children; - }, - stringifier : function(children) { - var json = []; - for (var i in children) { - // Generate one child - json.push( cc.serialize(children[i]) ); - } - return JSON.stringify(json); - } - } - } + cc.defineGetterSetter(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); }; diff --git a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js index 09b9c053af..8f0f7d7bc5 100644 --- a/cocos2d/core/labelttf/LabelTTFPropertyDefine.js +++ b/cocos2d/core/labelttf/LabelTTFPropertyDefine.js @@ -35,53 +35,53 @@ cc._tmp.PrototypeLabelTTF = function () { // Extended properties /** @expose */ _p.string; - cc.addProperty(_p, "string", "", _p.getString, _p.setString); + cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); /** @expose */ _p.textAlign; - cc.addProperty(_p, "textAlign", 1, _p.getHorizontalAlignment, _p.setHorizontalAlignment); + cc.defineGetterSetter(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment); /** @expose */ _p.verticalAlign; - cc.addProperty(_p, "verticalAlign", 0, _p.getVerticalAlignment, _p.setVerticalAlignment); + cc.defineGetterSetter(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment); /** @expose */ _p.fontSize; - cc.addProperty(_p, "fontSize", 0, _p.getFontSize, _p.setFontSize); + cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize); /** @expose */ _p.fontName; - cc.addProperty(_p, "fontName", "Arial", _p.getFontName, _p.setFontName); + cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName); /** @expose */ _p.font; cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); /** @expose */ _p.boundingSize; - //cc.addProperty(_p, "boundingSize", _p.getDimensions, _p.setDimensions); + //cc.defineGetterSetter(_p, "boundingSize", _p.getDimensions, _p.setDimensions); /** @expose */ _p.boundingWidth; - cc.addProperty(_p, "boundingWidth", 0, _p._getBoundingWidth, _p._setBoundingWidth); + cc.defineGetterSetter(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth); /** @expose */ _p.boundingHeight; - cc.addProperty(_p, "boundingHeight", 0, _p._getBoundingHeight, _p._setBoundingHeight); + cc.defineGetterSetter(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight); /** @expose */ _p.fillStyle; - cc.addProperty(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); + cc.defineGetterSetter(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor); /** @expose */ _p.strokeStyle; - cc.addProperty(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); + cc.defineGetterSetter(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle); /** @expose */ _p.lineWidth; - cc.addProperty(_p, "lineWidth", 0, _p._getLineWidth, _p._setLineWidth); + cc.defineGetterSetter(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth); /** @expose */ _p.shadowOffset; - //cc.addProperty(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); + //cc.defineGetterSetter(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset); /** @expose */ _p.shadowOffsetX; - cc.addProperty(_p, "shadowOffsetX", 0, _p._getShadowOffsetX, _p._setShadowOffsetX); + cc.defineGetterSetter(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX); /** @expose */ _p.shadowOffsetY; - cc.addProperty(_p, "shadowOffsetY", 0, _p._getShadowOffsetY, _p._setShadowOffsetY); + cc.defineGetterSetter(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY); /** @expose */ _p.shadowOpacity; - cc.addProperty(_p, "shadowOpacity", 0, _p._getShadowOpacity, _p._setShadowOpacity); + cc.defineGetterSetter(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity); /** @expose */ _p.shadowBlur; - cc.addProperty(_p, "shadowBlur", 0, _p._getShadowBlur, _p._setShadowBlur); + cc.defineGetterSetter(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur); }; \ No newline at end of file diff --git a/cocos2d/core/layers/CCLayerPropertyDefine.js b/cocos2d/core/layers/CCLayerPropertyDefine.js index 7ce333d430..0600fa1dd6 100644 --- a/cocos2d/core/layers/CCLayerPropertyDefine.js +++ b/cocos2d/core/layers/CCLayerPropertyDefine.js @@ -36,22 +36,17 @@ cc._tmp.PrototypeLayerGradient = function () { // Extended properties /** @expose */ _p.startColor; - cc.addProperty(_p, "startColor", _p.getStartColor, _p.setStartColor); + cc.defineGetterSetter(_p, "startColor", _p.getStartColor, _p.setStartColor); /** @expose */ _p.endColor; - cc.addProperty(_p, "endColor", _p.getEndColor, _p.setEndColor); + cc.defineGetterSetter(_p, "endColor", _p.getEndColor, _p.setEndColor); /** @expose */ _p.startOpacity; - cc.addProperty(_p, "startOpacity", 255, _p.getStartOpacity, _p.setStartOpacity); + cc.defineGetterSetter(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity); /** @expose */ _p.endOpacity; - cc.addProperty(_p, "endOpacity", 255, _p.getEndOpacity, _p.setEndOpacity); + cc.defineGetterSetter(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity); /** @expose */ _p.vector; - cc.addProperty(_p, "vector", _p.getVector, _p.setVector); - - _p.__delegators = { - startColor : cc.__delegators.color, - endColor : cc.__delegators.color - } + cc.defineGetterSetter(_p, "vector", _p.getVector, _p.setVector); }; \ No newline at end of file diff --git a/cocos2d/core/sprites/SpritesPropertyDefine.js b/cocos2d/core/sprites/SpritesPropertyDefine.js index b576ca9a72..20e8cc938a 100644 --- a/cocos2d/core/sprites/SpritesPropertyDefine.js +++ b/cocos2d/core/sprites/SpritesPropertyDefine.js @@ -37,10 +37,10 @@ cc._tmp.PrototypeSprite = function () { _p.dirty; /** @expose */ _p.flippedX; - cc.addProperty(_p, "flippedX", false, _p.isFlippedX, _p.setFlippedX); + cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX); /** @expose */ _p.flippedY; - cc.addProperty(_p, "flippedY", false, _p.isFlippedY, _p.setFlippedY); + cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); /** @expose */ _p.offsetX; cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX); @@ -51,7 +51,7 @@ cc._tmp.PrototypeSprite = function () { _p.atlasIndex; /** @expose */ _p.texture; - cc.addProperty(_p, "texture", null, _p.getTexture, _p.setTexture); + cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture); /** @expose */ _p.textureRectRotated; cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated); @@ -64,17 +64,4 @@ cc._tmp.PrototypeSprite = function () { _p.quad; cc.defineGetterSetter(_p, "quad", _p.getQuad); - _p.__type = "cc.Sprite"; - - _p.__delegators = { - "texture" : { - parser : function(json) { - return cc.textureCache.addImage(json); - }, - stringifier : function(texture) { - return cc.textureCache.getKeyByTexture(texture); - } - } - } - }; diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index 236280cd81..de67ee4dd6 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -383,15 +383,15 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { this.removeEventListener("load", target); } }); + + cc.EventHelper.prototype.apply(cc.Texture2D.prototype); + + cc.assert(cc.isFunction(cc._tmp.PrototypeTexture2D), cc._LogInfos.MissingFile, "TexturesPropertyDefine.js"); + cc._tmp.PrototypeTexture2D(); + delete cc._tmp.PrototypeTexture2D; } else { cc.assert(cc.isFunction(cc._tmp.WebGLTexture2D), cc._LogInfos.MissingFile, "TexturesWebGL.js"); cc._tmp.WebGLTexture2D(); delete cc._tmp.WebGLTexture2D; -} - -cc.EventHelper.prototype.apply(cc.Texture2D.prototype); - -cc.assert(cc.isFunction(cc._tmp.PrototypeTexture2D), cc._LogInfos.MissingFile, "TexturesPropertyDefine.js"); -cc._tmp.PrototypeTexture2D(); -delete cc._tmp.PrototypeTexture2D; \ No newline at end of file +} \ No newline at end of file diff --git a/cocos2d/core/textures/CCTextureAtlas.js b/cocos2d/core/textures/CCTextureAtlas.js index f1b753abfb..c08c610078 100644 --- a/cocos2d/core/textures/CCTextureAtlas.js +++ b/cocos2d/core/textures/CCTextureAtlas.js @@ -616,13 +616,13 @@ var _p = cc.TextureAtlas.prototype; // Extended properties /** @expose */ _p.totalQuads; -cc.addProperty(_p, "totalQuads", _p.getTotalQuads); +cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads); /** @expose */ _p.capacity; -cc.addProperty(_p, "capacity", _p.getCapacity); +cc.defineGetterSetter(_p, "capacity", _p.getCapacity); /** @expose */ _p.quads; -cc.addProperty(_p, "quads", _p.getQuads, _p.setQuads); +cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads); /** *

Creates a TextureAtlas with an filename and with an initial capacity for Quads.
diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index abd6b53ee7..0f9258807a 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -763,6 +763,12 @@ cc._tmp.WebGLTexture2D = function () { this.removeEventListener("load", target); } }); + + cc.EventHelper.prototype.apply(cc.Texture2D.prototype); + + cc.assert(cc.isFunction(cc._tmp.PrototypeTexture2D), cc._LogInfos.MissingFile, "TexturesPropertyDefine.js"); + cc._tmp.PrototypeTexture2D(); + delete cc._tmp.PrototypeTexture2D; }; cc._tmp.WebGLTextureAtlas = function () { diff --git a/modules/LabelBMFont.js b/modules/LabelBMFont.js index 6a0c9d498e..ca67e257f4 100644 --- a/modules/LabelBMFont.js +++ b/modules/LabelBMFont.js @@ -1,5 +1,5 @@ define([ - "cocosModule/SpriteBatchNode", + "cocos/SpriteBatchNode", "cocos2dPath/labels/CCLabelBMFont" ], function() { return cc.LabelBMFont; diff --git a/modules/LabelTTF.js b/modules/LabelTTF.js index 8807061e58..5dc2bd4e12 100644 --- a/modules/LabelTTF.js +++ b/modules/LabelTTF.js @@ -1,5 +1,5 @@ define([ - "cocosModule/Sprite", + "cocos/Sprite", "cocos2dPath/core/labelttf/CCLabelTTF" ], function() { return cc.LabelTTF; diff --git a/modules/Menu.js b/modules/Menu.js index 15f9b0432b..02ac7edc62 100644 --- a/modules/Menu.js +++ b/modules/Menu.js @@ -1,6 +1,6 @@ define([ - "cocosModule/core", - "cocosModule/actions", + "cocos/core", + "cocos/actions", "cocos2dPath/menus/CCMenu" ], function() { return cc.Menu; diff --git a/modules/Node.js b/modules/Node.js index 46f072c8c9..1dae7ca8d2 100644 --- a/modules/Node.js +++ b/modules/Node.js @@ -1,5 +1,5 @@ define([ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/base-nodes/CCNode", "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine", "cocos2dPath/core/base-nodes/BaseNodesWebGL" diff --git a/modules/Sprite.js b/modules/Sprite.js index 1361c68afe..5157f79c75 100644 --- a/modules/Sprite.js +++ b/modules/Sprite.js @@ -1,6 +1,6 @@ define([ - "cocosModule/core", - "cocosModule/Node", + "cocos/core", + "cocos/Node", "cocos2dPath/core/sprites/CCSprite", "cocos2dPath/core/sprites/SpritesPropertyDefine", "cocos2dPath/core/sprites/SpritesWebGL" diff --git a/modules/actions.js b/modules/actions.js index e67a6d4685..47d3cb424c 100644 --- a/modules/actions.js +++ b/modules/actions.js @@ -1,5 +1,5 @@ define([ - "cocosModule/core", + "cocos/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval", "cocos2dPath/actions/CCActionInstant" diff --git a/modules/audio.js b/modules/audio.js index c8a0f04266..c0436a3570 100644 --- a/modules/audio.js +++ b/modules/audio.js @@ -1,5 +1,5 @@ define([ - "cocosModule/core", + "cocos/core", "cocos2dPath/audio/CCAudio" ], function(cc) { return cc.audioEngine; diff --git a/modules/layers.js b/modules/layers.js index 87844b1175..8aaffb5d9e 100644 --- a/modules/layers.js +++ b/modules/layers.js @@ -1,5 +1,5 @@ define([ - "cocosModule/Sprite", + "cocos/Sprite", "cocos2dPath/core/layers/CCLayer" ], function() { return cc; diff --git a/modules/menuitems.js b/modules/menuitems.js index 2a0dc5731c..999741c881 100644 --- a/modules/menuitems.js +++ b/modules/menuitems.js @@ -1,7 +1,7 @@ define([ - "cocosModule/core", - "cocosModule/actions", - "cocosModule/Menu", + "cocos/core", + "cocos/actions", + "cocos/Menu", "cocos2dPath/menus/CCMenuItem" ], function() { return cc; diff --git a/require.js b/require.js index a6af5400fe..68bf30b8b9 100644 --- a/require.js +++ b/require.js @@ -2106,73 +2106,73 @@ if (requirejsSystemInfo.isNative) require_config = { baseUrl: '', paths: { - cocosModule:'../../frameworks/cocos2d-html5/modules', - root: '../../frameworks/cocos2d-html5', - cocos2dPath: '../../frameworks/cocos2d-html5/cocos2d', + cocos:'frameworks/cocos2d-html5/modules', + root: 'frameworks/cocos2d-html5', + cocos2dPath: 'frameworks/cocos2d-html5/cocos2d', game: 'src' }, shim: { - "cocosModule/actions":{ + "cocos/actions":{ init: function () { return cc; } }, - "cocosModule/audio":{ + "cocos/audio":{ init: function () { return cc.audioEngine; } }, - "cocosModule/core":{ + "cocos/core":{ init: function () { return cc; } }, - "cocosModule/LabelBMFont":{ + "cocos/LabelBMFont":{ init: function () { return cc.LabelBMFont; } }, - "cocosModule/LabelTTF":{ + "cocos/LabelTTF":{ init: function () { return cc.LabelTTF; } }, - "cocosModule/layers":{ + "cocos/layers":{ init: function () { return cc; } }, - "cocosModule/LoaderScene":{ + "cocos/LoaderScene":{ init: function () { return cc.LoaderScene; } }, - "cocosModule/Menu":{ + "cocos/Menu":{ init: function () { return cc.Menu } }, - "cocosModule/menuitems":{ + "cocos/menuitems":{ init: function () { return cc; } }, - "cocosModule/Node":{ + "cocos/Node":{ init: function () { return cc.Node; } }, - "cocosModule/Scene":{ + "cocos/Scene":{ init: function () { return cc.Scene; } }, - "cocosModule/Sprite":{ + "cocos/Sprite":{ init: function () { return cc.Sprite; } }, - "cocosModule/SpriteBatchNode":{ + "cocos/SpriteBatchNode":{ init: function () { return cc.SpriteBatchNode; } @@ -2257,9 +2257,9 @@ else baseUrl: '', paths: { - cocosModule:'../../frameworks/cocos2d-html5/modules', - root: '../../frameworks/cocos2d-html5', - cocos2dPath: '../../frameworks/cocos2d-html5/cocos2d', + cocos:'frameworks/cocos2d-html5/modules', + root: 'frameworks/cocos2d-html5', + cocos2dPath: 'frameworks/cocos2d-html5/cocos2d', game: 'src' }, @@ -2293,7 +2293,7 @@ else ], "cocos2dPath/core/CCGLProgram": [ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/platform/CCClass" ], @@ -2310,6 +2310,9 @@ else "cocos2dPath/core/platform/CCInputManager": [ "cocos2dPath/core/cocoa/CCGeometry" ], + "cocos2dPath/core/textures/TexturesWebGL" : [ + "cocos2dPath/core/event-manager/CCEventManager" + ], "cocos2dPath/core/textures/CCTexture2D": [ "cocos2dPath/core/textures/TexturesWebGL", "cocos2dPath/core/textures/TexturesPropertyDefine" @@ -2318,6 +2321,11 @@ else "cocos2dPath/core/textures/TexturesWebGL", "cocos2dPath/core/textures/TexturesPropertyDefine" ], + "cocos2dPath/core/textures/CCTextureCache": [ + "cocos2dPath/core/textures/CCTexture2D", + "cocos2dPath/core/textures/TexturesWebGL", + "cocos2dPath/core/textures/TexturesPropertyDefine" + ], "cocos2dPath/core/CCDirectorWebGL": [ //"cocos2dPath/core/labelttf/CCLabelTTF" // 循环调用 @@ -2328,18 +2336,6 @@ else "cocos2dPath/core/platform/CCInputExtension": [ "cocos2dPath/core/platform/CCInputManager" ], - "cocos2dPath/core/textures/CCTexture2D": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/textures/CCTextureAtlas": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], - "cocos2dPath/core/textures/CCTextureCache": [ - "cocos2dPath/core/textures/TexturesWebGL", - "cocos2dPath/core/textures/TexturesPropertyDefine" - ], "cocos2dPath/core/event-manager/CCEventExtension": [ "cocos2dPath/core/event-manager/CCEvent", "cocos2dPath/core/event-manager/CCEventListener" @@ -2363,31 +2359,33 @@ else ], "cocos2dPath/core/base-nodes/CCNode": [ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/base-nodes/BaseNodesWebGL", "cocos2dPath/core/base-nodes/BaseNodesPropertyDefine" ], "cocos2dPath/core/scenes/CCScene": [ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/base-nodes/CCNode" ], + "cocos2dPath/core/sprites/CCSprite": [ + "cocos2dPath/core/renderer/RendererCanvas" + ], "cocos2dPath/core/sprites/CCBakeSprite": [ - "cocosModule/Sprite" + "cocos/Sprite" + ], + "cocos2dPath/core/sprites/SpritesWebGL": [ + "cocos2dPath/core/renderer/RendererWebGL" ], "cocos2dPath/core/layers/CCLayer": [ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/sprites/CCBakeSprite", "cocos2dPath/core/layers/CCLayerWebGL", "cocos2dPath/core/layers/CCLayerPropertyDefine" ], - - - - "cocos2dPath/menus/CCMenu" : [ "cocos2dPath/core/layers/CCLayer" ], @@ -2401,7 +2399,7 @@ else ], "cocos2dPath/actions/CCAction" : [ - "cocosModule/core" + "cocos/core" ], "cocos2dPath/actions/CCActionInterval" : [ "cocos2dPath/actions/CCAction" @@ -2414,7 +2412,7 @@ else "cocos2dPath/core/sprites/CCSpriteBatchNode" ], - "cocosModule/core" : { + "cocos/core" : { deps: [ "root/CCDebugger", "cocos2dPath/core/utils/BinaryLoader", @@ -2434,7 +2432,6 @@ else "cocos2dPath/core/platform/CCScreen", "cocos2dPath/core/platform/CCVisibleRect", - "cocos2dPath/core/platform/CCInputManager", "cocos2dPath/core/platform/CCInputExtension", @@ -2449,6 +2446,9 @@ else "cocos2dPath/core/event-manager/CCEventManager", "cocos2dPath/core/event-manager/CCEventExtension", + "cocos2dPath/core/renderer/RendererCanvas", + "cocos2dPath/core/renderer/RendererWebGL", + "cocos2dPath/core/CCConfiguration", "cocos2dPath/core/CCDirector", @@ -2514,7 +2514,7 @@ else "cocos2dPath/core/scenes/CCLoaderScene": { deps: [ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/layers/CCLayer", "cocos2dPath/core/labelttf/CCLabelTTF", "cocos2dPath/core/scenes/CCScene" @@ -2527,8 +2527,8 @@ else "cocos2dPath/core/sprites/CCSprite" : { deps: [ - "cocosModule/core", - "cocosModule/Node", + "cocos/core", + "cocos/Node", "cocos2dPath/core/sprites/SpritesPropertyDefine", "cocos2dPath/core/sprites/SpritesWebGL" ], @@ -2539,7 +2539,7 @@ else "cocos2dPath/core/base-nodes/CCAtlasNode" : { deps: [ - "cocosModule/Node" + "cocos/Node" ], init: function() { return cc.NodeAtlas; @@ -2548,7 +2548,7 @@ else "cocos2dPath/core/sprites/CCAnimation" : { deps: [ - "cocosModule/Sprite" + "cocos/Sprite" ], init: function() { return cc.Animation; @@ -2557,7 +2557,7 @@ else "cocos2dPath/core/sprites/CCAnimationCache" : { deps: [ - "cocosModule/Sprite", + "cocos/Sprite", "cocos2dPath/core/sprites/CCAnimation" ], init: function() { @@ -2567,7 +2567,7 @@ else "cocos2dPath/core/sprites/CCSpriteFrame" : { deps: [ - "cocosModule/Sprite" + "cocos/Sprite" ], init: function() { return cc.SpriteFrame; @@ -2585,7 +2585,7 @@ else "cocos2dPath/actions/CCActionCamera" : { deps: [ - "cocosModule/core", + "cocos/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2593,7 +2593,7 @@ else }, "cocos2dPath/actions/CCActionEase" : { deps: [ - "cocosModule/core", + "cocos/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2601,7 +2601,7 @@ else }, "cocos2dPath/actions/CCActionCatmullRom" : { deps: [ - "cocosModule/core", + "cocos/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2609,7 +2609,7 @@ else }, "cocos2dPath/actions/CCActionTween" : { deps: [ - "cocosModule/core", + "cocos/core", "cocos2dPath/actions/CCAction", "cocos2dPath/actions/CCActionInterval" ], @@ -2618,7 +2618,7 @@ else "cocos2dPath/audio/CCAudio" : { deps: [ - "cocosModule/core", + "cocos/core", "cocos2dPath/core/event-manager/CCEventManager" ], exports: "cc" From eb083054391c84c3dd428efd72e662dd8c8c49c0 Mon Sep 17 00:00:00 2001 From: Wu-Hao Date: Wed, 3 Dec 2014 16:39:16 +0800 Subject: [PATCH 23/32] initial version of serialization/unserialization --- cocos2d/clipping-nodes/CCClippingNode.js | 34 +- cocos2d/core/CCDirector.js | 2 +- .../base-nodes/BaseNodesPropertyDefine.js | 73 ++-- cocos2d/core/base-nodes/BaseNodesWebGL.js | 40 +- cocos2d/core/base-nodes/CCAtlasNode.js | 44 +-- cocos2d/core/base-nodes/CCNode.js | 365 ++++++++++-------- cocos2d/core/labelttf/CCLabelTTF.js | 21 +- .../core/labelttf/LabelTTFPropertyDefine.js | 33 +- cocos2d/core/labelttf/LabelTTFWebGL.js | 10 +- cocos2d/core/layers/CCLayer.js | 63 +-- cocos2d/core/layers/CCLayerPropertyDefine.js | 15 +- cocos2d/core/layers/CCLayerWebGL.js | 12 +- cocos2d/core/platform/CCClass.js | 121 ++++++ cocos2d/core/platform/CCMacro.js | 2 +- .../core/platform/CCTypesPropertyDefine.js | 1 + cocos2d/core/renderer/RendererCanvas.js | 56 +-- cocos2d/core/renderer/RendererWebGL.js | 100 ++--- cocos2d/core/scenes/CCLoaderScene.js | 2 +- cocos2d/core/scenes/CCScene.js | 3 +- cocos2d/core/sprites/CCSprite.js | 177 ++++----- cocos2d/core/sprites/CCSpriteBatchNode.js | 156 ++++---- cocos2d/core/sprites/CCSpriteFrame.js | 12 +- cocos2d/core/sprites/SpritesPropertyDefine.js | 25 +- cocos2d/core/sprites/SpritesWebGL.js | 118 +++--- cocos2d/core/textures/CCTextureAtlas.js | 52 +-- cocos2d/core/textures/TexturesWebGL.js | 6 +- cocos2d/labels/CCLabelAtlas.js | 20 +- cocos2d/labels/CCLabelBMFont.js | 80 ++-- cocos2d/menus/CCMenu.js | 2 +- cocos2d/menus/CCMenuItem.js | 2 +- cocos2d/motion-streak/CCMotionStreak.js | 6 +- cocos2d/node-grid/CCNodeGrid.js | 16 +- cocos2d/parallax/CCParallaxNode.js | 2 +- cocos2d/particle/CCParticleBatchNode.js | 72 ++-- cocos2d/particle/CCParticleSystem.js | 72 ++-- cocos2d/physics/CCPhysicsDebugNode.js | 6 +- cocos2d/physics/CCPhysicsSprite.js | 28 +- cocos2d/progress-timer/CCProgressTimer.js | 12 +- cocos2d/render-texture/CCRenderTexture.js | 8 +- cocos2d/shaders/CCGLProgram.js | 6 +- cocos2d/shape-nodes/CCDrawNode.js | 10 +- cocos2d/text-input/CCTextFieldTTF.js | 2 +- cocos2d/tilemap/CCTMXLayer.js | 62 +-- cocos2d/tilemap/CCTMXTiledMap.js | 2 +- cocos2d/tilemap/CCTileMapAtlas.js | 10 +- cocos2d/transitions/CCTransition.js | 2 +- cocos2d/transitions/CCTransitionPageTurn.js | 2 +- cocos2d/transitions/CCTransitionProgress.js | 2 +- extensions/ccpool/CCPool.js | 2 +- .../ccui/base-classes/CCProtectedNode.js | 46 +-- .../ccui/base-classes/UIScale9Sprite.js | 14 +- extensions/ccui/base-classes/UIWidget.js | 54 +-- extensions/ccui/layouts/UILayout.js | 20 +- extensions/ccui/uiwidgets/UIButton.js | 2 +- extensions/ccui/uiwidgets/UICheckBox.js | 2 +- extensions/ccui/uiwidgets/UIImageView.js | 2 +- extensions/ccui/uiwidgets/UILoadingBar.js | 2 +- extensions/ccui/uiwidgets/UISlider.js | 2 +- extensions/ccui/uiwidgets/UIText.js | 2 +- extensions/ccui/uiwidgets/UITextAtlas.js | 2 +- extensions/ccui/uiwidgets/UITextBMFont.js | 4 +- extensions/ccui/uiwidgets/UITextField.js | 2 +- .../uiwidgets/scroll-widget/UIPageView.js | 2 +- .../uiwidgets/scroll-widget/UIScrollView.js | 4 +- .../cocostudio/action/CCActionObject.js | 10 +- extensions/cocostudio/armature/CCArmature.js | 16 +- extensions/cocostudio/armature/CCBone.js | 12 +- .../armature/display/CCBatchNode.js | 4 +- .../armature/display/CCDecorativeDisplay.js | 6 +- .../cocostudio/armature/display/CCSkin.js | 12 +- extensions/cocostudio/reader/GUIReader.js | 56 +-- .../cocostudio/trigger/ObjectFactory.js | 8 +- extensions/editbox/CCEditBox.js | 2 +- extensions/editbox/CCdomNode.js | 6 +- extensions/gui/control-extension/CCControl.js | 2 +- .../gui/control-extension/CCControlButton.js | 6 +- .../CCControlColourPicker.js | 2 +- .../control-extension/CCControlHuePicker.js | 2 +- .../CCControlPotentiometer.js | 2 +- .../CCControlSaturationBrightnessPicker.js | 2 +- .../gui/control-extension/CCControlSlider.js | 2 +- .../gui/control-extension/CCControlStepper.js | 2 +- .../gui/control-extension/CCControlSwitch.js | 2 +- .../gui/control-extension/CCMenuPassive.js | 2 +- .../gui/control-extension/CCScale9Sprite.js | 14 +- extensions/gui/scrollview/CCScrollView.js | 22 +- extensions/gui/scrollview/CCTableView.js | 4 +- extensions/spine/CCSkeleton.js | 4 +- template/main.js | 44 ++- template/src/myApp.js | 30 +- 90 files changed, 1283 insertions(+), 1120 deletions(-) diff --git a/cocos2d/clipping-nodes/CCClippingNode.js b/cocos2d/clipping-nodes/CCClippingNode.js index 79c4a6f432..093e24f563 100644 --- a/cocos2d/clipping-nodes/CCClippingNode.js +++ b/cocos2d/clipping-nodes/CCClippingNode.js @@ -106,7 +106,7 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ */ init: null, - _className: "ClippingNode", + __className: "ClippingNode", _initForWebGL: function (stencil) { this._stencil = stencil; @@ -223,11 +223,11 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ //optimize performance for javascript var currentStack = cc.current_stack; currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(this._stackMatrix, currentStack.top); - currentStack.top = this._stackMatrix; + cc.kmMat4Assign(this.__stackMatrix, currentStack.top); + currentStack.top = this.__stackMatrix; this.transform(); - //this._stencil._stackMatrix = this._stackMatrix; + //this._stencil.__stackMatrix = this.__stackMatrix; this._stencil.visit(); cc.renderer.pushRenderCommand(this._afterDrawStencilCmd); @@ -244,8 +244,8 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ else break; } - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); // draw children zOrder >= 0 for (; i < childLen; i++) { if (locChildren[i]) { @@ -253,8 +253,8 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ } } } else{ - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); } cc.renderer.pushRenderCommand(this._afterVisitCmd); @@ -447,14 +447,14 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ else break; } - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); for (; i < len; i++) { children[i].visit(context); } } else - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); this._cangodhelpme(false); } @@ -483,10 +483,10 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ if(this._stencil == stencil) return; if(this._stencil) - this._stencil._parent = null; + this._stencil.__parent = null; this._stencil = stencil; if(this._stencil) - this._stencil._parent = this; + this._stencil.__parent = this; }, _setStencilForCanvas: function (stencil) { @@ -505,11 +505,11 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ // For shape stencil, rewrite the draw of stencil ,only init the clip path and draw nothing. //else if (stencil instanceof cc.DrawNode) { - stencil._rendererCmd.rendering = function (ctx, scaleX, scaleY) { + stencil.__rendererCmd.rendering = function (ctx, scaleX, scaleY) { scaleX = scaleX || cc.view.getScaleX(); scaleY = scaleY ||cc.view.getScaleY(); var context = ctx || cc._renderContext; - var t = this._node._transformWorld; + var t = this._node.__transformWorld; context.save(); context.beginPath(); for (var i = 0; i < stencil._buffer.length; i++) { @@ -580,7 +580,7 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{ _transformForRenderer: function(parentMatrix){ cc.Node.prototype._transformForRenderer.call(this, parentMatrix); if(this._stencil) - this._stencil._transformForRenderer(this._stackMatrix); + this._stencil._transformForRenderer(this.__stackMatrix); } }); diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 290b735c02..3ca4e3d688 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -237,7 +237,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ if (this._runningScene) { if (renderer.childrenOrderDirty === true) { cc.renderer.clearRenderCommands(); - this._runningScene._curLevel = 0; //level start from 0; + this._runningScene.__curLevel = 0; //level start from 0; this._runningScene.visit(); renderer.resetFlag(); } else if (renderer.transformDirty() === true) diff --git a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js index 74dc981d36..4bf8e9d429 100644 --- a/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js +++ b/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js @@ -28,44 +28,44 @@ cc._tmp.PrototypeCCNode = function () { var _p = cc.Node.prototype; - cc.addProperty(_p, "x", 0, _p.getPositionX, _p.setPositionX); - cc.addProperty(_p, "y", 0, _p.getPositionY, _p.setPositionY); + cc.defineGetterSetter(_p, "x", _p.getPositionX, _p.setPositionX); + cc.defineGetterSetter(_p, "y", _p.getPositionY, _p.setPositionY); /** @expose */ //_p.pos; - //cc.addProperty(_p, "pos", _p.getPosition, _p.setPosition); + //cc.defineGetterSetter(_p, "pos", _p.getPosition, _p.setPosition); /** @expose */ _p.width; - cc.addProperty(_p, "width", 0, _p._getWidth, _p._setWidth); + cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth); /** @expose */ _p.height; - cc.addProperty(_p, "height", 0, _p._getHeight, _p._setHeight); + cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight); /** @expose */ //_p.size; - //cc.addProperty(_p, "size", _p.getContentSize, _p.setContentSize); + //cc.defineGetterSetter(_p, "size", _p.getContentSize, _p.setContentSize); /** @expose */ //_p.anchor; - //cc.addProperty(_p, "anchor", _p._getAnchor, _p._setAnchor); + //cc.defineGetterSetter(_p, "anchor", _p._getAnchor, _p._setAnchor); /** @expose */ _p.anchorX; - cc.addProperty(_p, "anchorX", 0, _p._getAnchorX, _p._setAnchorX); + cc.defineGetterSetter(_p, "anchorX", _p._getAnchorX, _p._setAnchorX); /** @expose */ _p.anchorY; - cc.addProperty(_p, "anchorY", 0, _p._getAnchorY, _p._setAnchorY); + cc.defineGetterSetter(_p, "anchorY", _p._getAnchorY, _p._setAnchorY); /** @expose */ _p.skewX; - cc.addProperty(_p, "skewX", 0, _p.getSkewX, _p.setSkewX); + cc.defineGetterSetter(_p, "skewX", _p.getSkewX, _p.setSkewX); /** @expose */ _p.skewY; - cc.addProperty(_p, "skewY", 0, _p.getSkewY, _p.setSkewY); + cc.defineGetterSetter(_p, "skewY", _p.getSkewY, _p.setSkewY); /** @expose */ _p.zIndex; - cc.addProperty(_p, "zIndex", 0, _p.getLocalZOrder, _p.setLocalZOrder); + cc.defineGetterSetter(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder); /** @expose */ _p.vertexZ; cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ); /** @expose */ _p.rotation; - cc.addProperty(_p, "rotation", 0, _p.getRotation, _p.setRotation); + cc.defineGetterSetter(_p, "rotation", _p.getRotation, _p.setRotation); /** @expose */ _p.rotationX; cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX); @@ -77,13 +77,13 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale); /** @expose */ _p.scaleX; - cc.addProperty(_p, "scaleX", 1, _p.getScaleX, _p.setScaleX); + cc.defineGetterSetter(_p, "scaleX", _p.getScaleX, _p.setScaleX); /** @expose */ _p.scaleY; - cc.addProperty(_p, "scaleY", 1, _p.getScaleY, _p.setScaleY); + cc.defineGetterSetter(_p, "scaleY", _p.getScaleY, _p.setScaleY); /** @expose */ _p.children; - cc.addProperty(_p, "children", _p.getChildren, _p.setChildren); + cc.defineGetterSetter(_p, "children", _p.getChildren); /** @expose */ _p.childrenCount; cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount); @@ -92,13 +92,13 @@ cc._tmp.PrototypeCCNode = function () { cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent); /** @expose */ _p.visible; - cc.addProperty(_p, "visible", true, _p.isVisible, _p.setVisible); + cc.defineGetterSetter(_p, "visible", _p.isVisible, _p.setVisible); /** @expose */ _p.running; cc.defineGetterSetter(_p, "running", _p.isRunning); /** @expose */ _p.ignoreAnchor; - cc.addProperty(_p, "ignoreAnchor", false, _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); + cc.defineGetterSetter(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition); /** @expose */ _p.tag; /** @expose */ @@ -113,47 +113,24 @@ cc._tmp.PrototypeCCNode = function () { /** @expose */ _p.scheduler; cc.defineGetterSetter(_p, "scheduler", _p.getScheduler, _p.setScheduler); + //cc.defineGetterSetter(_p, "boundingBox", _p.getBoundingBox); /** @expose */ _p.shaderProgram; cc.defineGetterSetter(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram); /** @expose */ _p.opacity; - cc.addProperty(_p, "opacity", 255, _p.getOpacity, _p.setOpacity); + cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity); /** @expose */ _p.opacityModifyRGB; - cc.addProperty(_p, "opacityModifyRGB", false, _p.isOpacityModifyRGB, _p.setOpacityModifyRGB); + cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB); /** @expose */ _p.cascadeOpacity; - cc.addProperty(_p, "cascadeOpacity", false, _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); + cc.defineGetterSetter(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled); /** @expose */ _p.color; - cc.addProperty(_p, "color", null, _p.getColor, _p.setColor); + cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); /** @expose */ _p.cascadeColor; - cc.addProperty(_p, "cascadeColor", false, _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); - - _p.__delegators = { - color : cc.__delegators.color, - children : { - parser : function(json) { - var children = []; - for (var i in json) { - // Generate one child - children.push( cc.deserialize(json[i]) ); - } - return children; - }, - stringifier : function(children) { - var json = []; - for (var i in children) { - // Generate one child - json.push( cc.serialize(children[i]) ); - } - return JSON.stringify(json); - } - } - } - -}; - + cc.defineGetterSetter(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled); +}; \ No newline at end of file diff --git a/cocos2d/core/base-nodes/BaseNodesWebGL.js b/cocos2d/core/base-nodes/BaseNodesWebGL.js index cfc292eeeb..a9712ad112 100644 --- a/cocos2d/core/base-nodes/BaseNodesWebGL.js +++ b/cocos2d/core/base-nodes/BaseNodesWebGL.js @@ -33,9 +33,9 @@ cc._tmp.WebGLCCNode = function () { */ var _p = cc.Node.prototype; - _p._transform4x4 = null; - _p._stackMatrix = null; - _p._glServerState = null; + _p.__transform4x4 = null; + _p.__stackMatrix = null; + _p.__glServerState = null; _p._camera = null; _p.ctor = function () { @@ -46,17 +46,17 @@ cc._tmp.WebGLCCNode = function () { var mat4 = new cc.kmMat4(); mat4.mat[2] = mat4.mat[3] = mat4.mat[6] = mat4.mat[7] = mat4.mat[8] = mat4.mat[9] = mat4.mat[11] = mat4.mat[14] = 0.0; mat4.mat[10] = mat4.mat[15] = 1.0; - _t._transform4x4 = mat4; - _t._glServerState = 0; - _t._stackMatrix = new cc.kmMat4(); + _t.__transform4x4 = mat4; + _t.__glServerState = 0; + _t.__stackMatrix = new cc.kmMat4(); this._initRendererCmd(); }; _p.setNodeDirty = function () { var _t = this; - if(_t._transformDirty === false){ + if(_t.__transformDirty === false){ _t._setNodeDirtyForCache(); - _t._renderCmdDiry = _t._transformDirty = _t._inverseDirty = true; + _t.__renderCmdDirty = _t.__transformDirty = _t.__inverseDirty = true; cc.renderer.pushDirtyNode(this); } }; @@ -67,15 +67,15 @@ cc._tmp.WebGLCCNode = function () { if (!_t._visible) return; - if( _t._parent) - _t._curLevel = _t._parent._curLevel + 1; + if( _t.__parent) + _t.__curLevel = _t.__parent.__curLevel + 1; var context = cc._renderContext, i, currentStack = cc.current_stack; //optimize performance for javascript currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(_t._stackMatrix, currentStack.top); - currentStack.top = _t._stackMatrix; + cc.kmMat4Assign(_t.__stackMatrix, currentStack.top); + currentStack.top = _t.__stackMatrix; //_t.toRenderer(); _t.transform(); @@ -91,8 +91,8 @@ cc._tmp.WebGLCCNode = function () { else break; } - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); // draw children zOrder >= 0 for (; i < childLen; i++) { if (locChildren[i]) { @@ -100,8 +100,8 @@ cc._tmp.WebGLCCNode = function () { } } } else{ - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); } //optimize performance for javascript @@ -109,8 +109,8 @@ cc._tmp.WebGLCCNode = function () { }; _p._transformForRenderer = function (pMatrix) { - var t4x4 = this._transform4x4, stackMatrix = this._stackMatrix, - parentMatrix = pMatrix || (this._parent ? this._parent._stackMatrix : cc.current_stack.top); + var t4x4 = this.__transform4x4, stackMatrix = this.__stackMatrix, + parentMatrix = pMatrix || (this.__parent ? this.__parent.__stackMatrix : cc.current_stack.top); // Convert 3x3 into 4x4 matrix var trans = this.nodeToParentTransform(); @@ -152,7 +152,7 @@ cc._tmp.WebGLCCNode = function () { } } - this._renderCmdDiry = false; + this.__renderCmdDirty = false; if(!this._children || this._children.length === 0) return; var i, len, locChildren = this._children; @@ -165,7 +165,7 @@ cc._tmp.WebGLCCNode = function () { _p.transform = function () { var _t = this; //optimize performance for javascript - var t4x4 = _t._transform4x4, topMat4 = cc.current_stack.top; + var t4x4 = _t.__transform4x4, topMat4 = cc.current_stack.top; // Convert 3x3 into 4x4 matrix var trans = _t.nodeToParentTransform(); diff --git a/cocos2d/core/base-nodes/CCAtlasNode.js b/cocos2d/core/base-nodes/CCAtlasNode.js index e293697d21..14f78c7f78 100644 --- a/cocos2d/core/base-nodes/CCAtlasNode.js +++ b/cocos2d/core/base-nodes/CCAtlasNode.js @@ -44,11 +44,11 @@ * var node = new cc.AtlasNode("pathOfTile", 16, 16, 1); * * @property {cc.Texture2D} texture - Current used texture - * @property {cc.TextureAtlas} textureAtlas - Texture atlas for cc.AtlasNode + * @property {cc.TextureAtlas} __textureAtlas - Texture atlas for cc.AtlasNode * @property {Number} quadsToDraw - Number of quads to draw */ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ - textureAtlas: null, + __textureAtlas: null, quadsToDraw: 0, //! chars per row @@ -68,7 +68,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ // This variable is only used for CCLabelAtlas FPS display. So plz don't modify its value. _ignoreContentScaleFactor: false, - _className: "AtlasNode", + __className: "AtlasNode", /** *

Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.

@@ -88,7 +88,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ _initRendererCmd: function () { if(cc._renderType === cc._RENDER_TYPE_WEBGL) - this._rendererCmd = new cc.AtlasNodeRenderCmdWebGL(this); + this.__rendererCmd = new cc.AtlasNodeRenderCmdWebGL(this); }, /** @@ -161,7 +161,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ * @param {cc.TextureAtlas} value The texture */ setTextureAtlas: function (value) { - this.textureAtlas = value; + this.__textureAtlas = value; }, /** @@ -170,7 +170,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ * @return {cc.TextureAtlas} */ getTextureAtlas: function () { - return this.textureAtlas; + return this.__textureAtlas; }, /** @@ -252,10 +252,10 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ var locRealColor = this._realColor; this._colorF32Array = new Float32Array([locRealColor.r / 255.0, locRealColor.g / 255.0, locRealColor.b / 255.0, this._realOpacity / 255.0]); - this.textureAtlas = new cc.TextureAtlas(); - this.textureAtlas.initWithTexture(texture, itemsToRender); + this.__textureAtlas = new cc.TextureAtlas(); + this.__textureAtlas.initWithTexture(texture, itemsToRender); - if (!this.textureAtlas) { + if (!this.__textureAtlas) { cc.log(cc._LogInfos.AtlasNode__initWithTexture); return false; } @@ -284,7 +284,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst); if(this._uniformColor && this._colorF32Array){ context.uniform4fv(this._uniformColor, this._colorF32Array); - this.textureAtlas.drawNumberOfQuads(this.quadsToDraw, 0); + this.__textureAtlas.drawNumberOfQuads(this.quadsToDraw, 0); } }, @@ -303,7 +303,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ this._colorUnmodified = color3; if (this._opacityModifyRGB) { - var locDisplayedOpacity = this._displayedOpacity; + var locDisplayedOpacity = this.__displayedOpacity; temp.r = temp.r * locDisplayedOpacity / 255; temp.g = temp.g * locDisplayedOpacity / 255; temp.b = temp.b * locDisplayedOpacity / 255; @@ -335,14 +335,14 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ _setColorForWebGL: function (color3) { var temp = cc.color(color3.r, color3.g, color3.b); this._colorUnmodified = color3; - var locDisplayedOpacity = this._displayedOpacity; + var locDisplayedOpacity = this.__displayedOpacity; if (this._opacityModifyRGB) { temp.r = temp.r * locDisplayedOpacity / 255; temp.g = temp.g * locDisplayedOpacity / 255; temp.b = temp.b * locDisplayedOpacity / 255; } cc.Node.prototype.setColor.call(this, color3); - var locDisplayedColor = this._displayedColor; + var locDisplayedColor = this.__displayedColor; this._colorF32Array = new Float32Array([locDisplayedColor.r / 255.0, locDisplayedColor.g / 255.0, locDisplayedColor.b / 255.0, locDisplayedOpacity / 255.0]); }, @@ -369,9 +369,9 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ if (this._opacityModifyRGB) { this.color = this._colorUnmodified; } else { - var locDisplayedColor = this._displayedColor; + var locDisplayedColor = this.__displayedColor; this._colorF32Array = new Float32Array([locDisplayedColor.r / 255.0, locDisplayedColor.g / 255.0, - locDisplayedColor.b / 255.0, this._displayedOpacity / 255.0]); + locDisplayedColor.b / 255.0, this.__displayedOpacity / 255.0]); } }, @@ -387,7 +387,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ }, _getTextureForWebGL: function () { - return this.textureAtlas.texture; + return this.__textureAtlas.texture; }, /** @@ -402,7 +402,7 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ }, _setTextureForWebGL: function (texture) { - this.textureAtlas.texture = texture; + this.__textureAtlas.texture = texture; this._updateBlendFunc(); this._updateOpacityModifyRGB(); }, @@ -428,14 +428,14 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{ }, _updateBlendFunc: function () { - if (!this.textureAtlas.texture.hasPremultipliedAlpha()) { + if (!this.__textureAtlas.texture.hasPremultipliedAlpha()) { this._blendFunc.src = cc.SRC_ALPHA; this._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; } }, _updateOpacityModifyRGB: function () { - this._opacityModifyRGB = this.textureAtlas.texture.hasPremultipliedAlpha(); + this._opacityModifyRGB = this.__textureAtlas.texture.hasPremultipliedAlpha(); }, _setIgnoreContentScaleFactor: function (ignoreContentScaleFactor) { @@ -472,9 +472,9 @@ if (cc._renderType === cc._RENDER_TYPE_WEBGL) { if (cacheTextureForColor) { var textureRect = cc.rect(0, 0, element.width, element.height); if (locElement instanceof HTMLCanvasElement) - cc.generateTintImage(locElement, cacheTextureForColor, this._displayedColor, textureRect, locElement); + cc.generateTintImage(locElement, cacheTextureForColor, this.__displayedColor, textureRect, locElement); else { - locElement = cc.generateTintImage(locElement, cacheTextureForColor, this._displayedColor, textureRect); + locElement = cc.generateTintImage(locElement, cacheTextureForColor, this.__displayedColor, textureRect); locTexture = new cc.Texture2D(); locTexture.initWithElement(locElement); locTexture.handleLoadedTexture(); @@ -494,7 +494,7 @@ cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor); _p.texture; cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture); /** @expose */ -_p.textureAtlas; +_p.__textureAtlas; /** @expose */ _p.quadsToDraw; diff --git a/cocos2d/core/base-nodes/CCNode.js b/cocos2d/core/base-nodes/CCNode.js index c22e4843dd..fb2290d899 100644 --- a/cocos2d/core/base-nodes/CCNode.js +++ b/cocos2d/core/base-nodes/CCNode.js @@ -129,6 +129,7 @@ cc.s_globalOrderOfArrival = 1; * @property {Number} glServerState - The state of OpenGL server side */ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ + _type_: "cc.Node", _localZOrder: 0, ///< Local order (relative to its siblings) used to sort the node _globalZOrder: 0, ///< Global order used to sort the node _vertexZ: 0.0, @@ -141,7 +142,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ _normalizedPosition:null, _usingNormalizedPosition: false, - _normalizedPositionDirty: false, + __normalizedPositionDirty: false, _skewX: 0.0, _skewY: 0.0, @@ -152,56 +153,56 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ _anchorPoint: null, _anchorPointInPoints: null, _contentSize: null, - _running: false, - _parent: null, + __running: false, + __parent: null, // "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true _ignoreAnchorPointForPosition: false, tag: cc.NODE_TAG_INVALID, // userData is always initialized as nil userData: null, userObject: null, - _transformDirty: true, - _inverseDirty: true, - _cacheDirty: false, + __transformDirty: true, + __inverseDirty: true, + __cacheDirty: false, // Cached parent serves to construct the cached parent chain - _cachedParent: null, - _transformGLDirty: null, - _transform: null, //local transform - _transformWorld: null, //world transform - _inverse: null, + __cachedParent: null, + __transformGLDirty: null, + __transform: null, //local transform + __transformWorld: null, //world transform + __inverse: null, //since 2.0 api - _reorderChildDirty: false, + __reorderChildDirty: false, _shaderProgram: null, arrivalOrder: 0, - _actionManager: null, - _scheduler: null, - _eventDispatcher: null, + __actionManager: null, + __scheduler: null, + __eventDispatcher: null, - _initializedNode: false, - _additionalTransformDirty: false, - _additionalTransform: null, - _componentContainer: null, - _isTransitionFinished: false, + __initializedNode: false, + __additionalTransformDirty: false, + __additionalTransform: null, + __componentContainer: null, + __isTransitionFinished: false, - _rotationRadiansX: 0, - _rotationRadiansY: 0, - _className: "Node", + __rotationRadiansX: 0, + __rotationRadiansY: 0, + __className: "Node", _showNode: false, _name: "", ///Constructor of cc.Layer, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.

@@ -106,18 +107,18 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if (!this._isBaked) { cc.renderer.childrenOrderDirty = true; //limit: 1. its children's blendfunc are invalid. - this._isBaked = this._cacheDirty = true; + this._isBaked = this.__cacheDirty = true; if(!this._bakeRenderCmd && this._bakeRendering) this._bakeRenderCmd = new cc.CustomRenderCmdCanvas(this, this._bakeRendering); - this._cachedParent = this; + this.__cachedParent = this; var children = this._children; for(var i = 0, len = children.length; i < len; i++) children[i]._setCachedParent(this); if (!this._bakeSprite){ this._bakeSprite = new cc.BakeSprite(); - this._bakeSprite._parent = this; + this._bakeSprite.__parent = this; } } }; @@ -126,9 +127,9 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if (this._isBaked) { cc.renderer.childrenOrderDirty = true; this._isBaked = false; - this._cacheDirty = true; + this.__cacheDirty = true; - this._cachedParent = null; + this.__cachedParent = null; var children = this._children; for(var i = 0, len = children.length; i < len; i++) children[i]._setCachedParent(null); @@ -137,12 +138,12 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { p.addChild = function(child, localZOrder, tag){ cc.Node.prototype.addChild.call(this, child, localZOrder, tag); - if(child._parent == this && this._isBaked) + if(child.__parent == this && this._isBaked) child._setCachedParent(this); }; p._bakeRendering = function(){ - if(this._cacheDirty){ + if(this.__cacheDirty){ var _t = this; var children = _t._children, locBakeSprite = this._bakeSprite; //compute the bounding box of the bake layer. @@ -154,7 +155,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height); bakeContext.translate(0 - boundingBox.x, boundingBox.height + boundingBox.y); // invert - var t = cc.affineTransformInvert(this._transformWorld); + var t = cc.affineTransformInvert(this.__transformWorld); bakeContext.transform(t.a, t.c, t.b, t.d, t.tx , -t.ty ); //reset the bake sprite's position @@ -169,7 +170,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { } cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId); locBakeSprite.transform(); //because bake sprite's position was changed at rendering. - this._cacheDirty = false; + this.__cacheDirty = false; } }; @@ -249,7 +250,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { */ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ _blendFunc: null, - _className: "LayerColor", + __className: "LayerColor", /** * Returns the blend function @@ -335,7 +336,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ width = width === undefined ? winSize.width : width; height = height === undefined ? winSize.height : height; - var locDisplayedColor = this._displayedColor; + var locDisplayedColor = this.__displayedColor; locDisplayedColor.r = color.r; locDisplayedColor.g = color.g; locDisplayedColor.b = color.b; @@ -345,7 +346,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ locRealColor.g = color.g; locRealColor.b = color.b; - this._displayedOpacity = color.a; + this.__displayedOpacity = color.a; this._realOpacity = color.a; var proto = cc.LayerColor.prototype; @@ -413,7 +414,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.LayerColor.prototype.init.call(this, color, width, height); }; _p._initRendererCmd = function(){ - this._rendererCmd = new cc.RectRenderCmdCanvas(this); + this.__rendererCmd = new cc.RectRenderCmdCanvas(this); }; _p._setWidth = function(width){ cc.Node.prototype._setWidth.call(this, width); @@ -422,28 +423,28 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.Node.prototype._setHeight.call(this, height); }; _p._updateColor = function () { - var locCmd = this._rendererCmd; + var locCmd = this.__rendererCmd; if(!locCmd || !locCmd._color) return; - var locColor = this._displayedColor; + var locColor = this.__displayedColor; locCmd._color.r = locColor.r; locCmd._color.g = locColor.g; locCmd._color.b = locColor.b; - locCmd._color.a = this._displayedOpacity / 255; + locCmd._color.a = this.__displayedOpacity / 255; }; _p.draw = function (ctx) { var context = ctx || cc._renderContext, _t = this; - var locEGLViewer = cc.view, locDisplayedColor = _t._displayedColor; + var locEGLViewer = cc.view, locDisplayedColor = _t.__displayedColor; context.fillStyle = "rgba(" + (0 | locDisplayedColor.r) + "," + (0 | locDisplayedColor.g) + "," - + (0 | locDisplayedColor.b) + "," + _t._displayedOpacity / 255 + ")"; + + (0 | locDisplayedColor.b) + "," + _t.__displayedOpacity / 255 + ")"; context.fillRect(0, 0, _t.width * locEGLViewer.getScaleX(), -_t.height * locEGLViewer.getScaleY()); cc.g_NumberOfDraws++; }; _p._bakeRendering = function(){ - if(this._cacheDirty){ + if(this.__cacheDirty){ var _t = this; var locBakeSprite = _t._bakeSprite, children = this._children; var len = children.length, i; @@ -466,7 +467,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { locBakeSprite.setPosition(anchor.x + boundingBox.x - selfPos.x, anchor.y + boundingBox.y - selfPos.y); } // invert - var t = cc.affineTransformInvert(this._transformWorld); + var t = cc.affineTransformInvert(this.__transformWorld); bakeContext.transform(t.a, t.c, t.b, t.d, t.tx, -t.ty); var child; @@ -482,17 +483,17 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { else break; } - if(_t._rendererCmd) - cc.renderer.pushRenderCommand(_t._rendererCmd); + if(_t.__rendererCmd) + cc.renderer.pushRenderCommand(_t.__rendererCmd); for (; i < len; i++) { children[i].visit(bakeContext); } } else - if(_t._rendererCmd) - cc.renderer.pushRenderCommand(_t._rendererCmd); + if(_t.__rendererCmd) + cc.renderer.pushRenderCommand(_t.__rendererCmd); cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId); locBakeSprite.transform(); - this._cacheDirty = false; + this.__cacheDirty = false; } }; @@ -590,7 +591,7 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{ _endOpacity: 255, _alongVector: null, _compressedInterpolation: false, - _className: "LayerGradient", + __className: "LayerGradient", /** * Constructor of cc.LayerGradient @@ -610,7 +611,7 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{ }, _initRendererCmd: function(){ - this._rendererCmd = new cc.GradientRectRenderCmdCanvas(this); + this.__rendererCmd = new cc.GradientRectRenderCmdCanvas(this); }, /** @@ -797,13 +798,13 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var _t = this; var locAlongVector = _t._alongVector, tWidth = _t.width * 0.5, tHeight = _t.height * 0.5; - var locCmd = this._rendererCmd; + var locCmd = this.__rendererCmd; locCmd._startPoint.x = tWidth * (-locAlongVector.x) + tWidth; locCmd._startPoint.y = tHeight * locAlongVector.y - tHeight; locCmd._endPoint.x = tWidth * locAlongVector.x + tWidth; locCmd._endPoint.y = tHeight * (-locAlongVector.y) - tHeight; - var locStartColor = this._displayedColor, locEndColor = this._endColor, opacity = this._displayedOpacity / 255; + var locStartColor = this.__displayedColor, locEndColor = this._endColor, opacity = this.__displayedOpacity / 255; var startOpacity = this._startOpacity, endOpacity = this._endOpacity; locCmd._startStopStr = "rgba(" + Math.round(locStartColor.r) + "," + Math.round(locStartColor.g) + "," + Math.round(locStartColor.b) + "," + startOpacity.toFixed(4) + ")"; @@ -837,7 +838,7 @@ delete cc._tmp.PrototypeLayerGradient; cc.LayerMultiplex = cc.Layer.extend(/** @lends cc.LayerMultiplex# */{ _enabledLayer: 0, _layers: null, - _className: "LayerMultiplex", + __className: "LayerMultiplex", /** * Constructor of cc.LayerMultiplex diff --git a/cocos2d/core/layers/CCLayerPropertyDefine.js b/cocos2d/core/layers/CCLayerPropertyDefine.js index 7ce333d430..0600fa1dd6 100644 --- a/cocos2d/core/layers/CCLayerPropertyDefine.js +++ b/cocos2d/core/layers/CCLayerPropertyDefine.js @@ -36,22 +36,17 @@ cc._tmp.PrototypeLayerGradient = function () { // Extended properties /** @expose */ _p.startColor; - cc.addProperty(_p, "startColor", _p.getStartColor, _p.setStartColor); + cc.defineGetterSetter(_p, "startColor", _p.getStartColor, _p.setStartColor); /** @expose */ _p.endColor; - cc.addProperty(_p, "endColor", _p.getEndColor, _p.setEndColor); + cc.defineGetterSetter(_p, "endColor", _p.getEndColor, _p.setEndColor); /** @expose */ _p.startOpacity; - cc.addProperty(_p, "startOpacity", 255, _p.getStartOpacity, _p.setStartOpacity); + cc.defineGetterSetter(_p, "startOpacity", _p.getStartOpacity, _p.setStartOpacity); /** @expose */ _p.endOpacity; - cc.addProperty(_p, "endOpacity", 255, _p.getEndOpacity, _p.setEndOpacity); + cc.defineGetterSetter(_p, "endOpacity", _p.getEndOpacity, _p.setEndOpacity); /** @expose */ _p.vector; - cc.addProperty(_p, "vector", _p.getVector, _p.setVector); - - _p.__delegators = { - startColor : cc.__delegators.color, - endColor : cc.__delegators.color - } + cc.defineGetterSetter(_p, "vector", _p.getVector, _p.setVector); }; \ No newline at end of file diff --git a/cocos2d/core/layers/CCLayerWebGL.js b/cocos2d/core/layers/CCLayerWebGL.js index 4000438c2c..4ed67015df 100644 --- a/cocos2d/core/layers/CCLayerWebGL.js +++ b/cocos2d/core/layers/CCLayerWebGL.js @@ -65,7 +65,7 @@ cc._tmp.WebGLLayerColor = function () { cc.LayerColor.prototype.init.call(_t, color, width, height); }; _p._initRendererCmd = function(){ - this._rendererCmd = new cc.RectRenderCmdWebGL(this); + this.__rendererCmd = new cc.RectRenderCmdWebGL(this); }; _p.setContentSize = function (size, height) { var locSquareVertices = this._squareVertices; @@ -98,8 +98,8 @@ cc._tmp.WebGLLayerColor = function () { cc.Layer.prototype._setHeight.call(this, height); }; _p._updateColor = function () { - var locDisplayedColor = this._displayedColor; - var locDisplayedOpacity = this._displayedOpacity, locSquareColors = this._squareColors; + var locDisplayedColor = this.__displayedColor; + var locDisplayedOpacity = this.__displayedOpacity, locSquareColors = this._squareColors; for (var i = 0; i < 4; i++) { locSquareColors[i].r = locDisplayedColor.r; locSquareColors[i].g = locDisplayedColor.g; @@ -144,7 +144,7 @@ cc._tmp.WebGLLayerGradient = function () { //cc.LayerGradient define start var _p = cc.LayerGradient.prototype; _p._initRendererCmd = function(){ - this._rendererCmd = new cc.RectRenderCmdWebGL(this); + this.__rendererCmd = new cc.RectRenderCmdWebGL(this); }; _p.draw = cc.LayerColor.prototype.draw; _p._updateColor = function () { @@ -162,8 +162,8 @@ cc._tmp.WebGLLayerGradient = function () { u = cc.pMult(u, h2 * c); } - var opacityf = _t._displayedOpacity / 255.0; - var locDisplayedColor = _t._displayedColor, locEndColor = _t._endColor; + var opacityf = _t.__displayedOpacity / 255.0; + var locDisplayedColor = _t.__displayedColor, locEndColor = _t._endColor; var S = { r: locDisplayedColor.r, g: locDisplayedColor.g, b: locDisplayedColor.b, a: _t._startOpacity * opacityf}; var E = {r: locEndColor.r, g: locEndColor.g, b: locEndColor.b, a: _t._endOpacity * opacityf}; diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index fbfb92ea00..8dfd00fc3f 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -24,6 +24,9 @@ THE SOFTWARE. ****************************************************************************/ + + + var cc = cc || {}; /** @@ -322,3 +325,121 @@ cc.clone = function (obj) { } return newObj; }; +cc.Serializer = { + specialCases:[], + specialCasesMethods:[], + compact:false, + getMethods:function(key){ + var idx = cc.Serializer.specialCases.indexOf(key); + if(idx !== -1) + { + return cc.Serializer.specialCasesMethods[idx]; + } + }, + /** + * add special case methods for serialization, + * @function + * @param {String} key + * @param {Function} getFunc This function will be called during serialization of an object that matches the key, + * This function will be called from the actual key owner, + * for example, the key is "_position", and the object is a cc.Node instance, then function "this" refers to that cc.Node instance + * parameter : the value of the key will be passed to the function as the only parameter + * return : function should return a formatted object ready to be serialized + * + * example : format color to "stringify friendly" object + * function(val){return {r:val.r, g:val.g, b:val.b, a:val.a}} + * + * example : return the children array, or do nothing if its empty + * function(){ return this._children.length? this._children : undefined; } + * + * @param {Function} setFunc This function will be called during re-creation of an object that matches the key, + * This function will be called from the actual key owner, + * This function is to process serialized object that require more than a value copy, such as children needs to be passed through .addChild() + * for example, the key is "_position", and the object is a cc.Node instance, then function "this" refers to that cc.Node instance + * parameter : the value of the key will be passed to the function as the only parameter + * return : void, this function + * + * example : add Children through Node.addChild() + * function(val){ + * for(var i = 0; i < val.length; i++){ + * this.addChild(val[i]); + * } + * } + */ + addMethods: function(key, getFunc, setFunc){ + cc.Serializer.specialCases.push(key); + cc.Serializer.specialCasesMethods.push({g:getFunc,s:setFunc}); + }, + serialize:function(node){ + + + + + return JSON.stringify(node, function(key, val){ + if(val === null || key[1] == '_') + return undefined; + + //debug - remove these when finished + if(val instanceof HTMLElement) + { + console.log("html",this, key, val); + return undefined; + } + //end debug + + var special = cc.Serializer.getMethods(key); + if(special && special.g) + { + return special.g.call(this,val); + } + else if(typeof val === "object" && val._type_) + { + //copy the object type to local, so it gets serialized + val._type_ = val._type_; + } + return val; + },this.compact?0:4); + }, + unSerialize:function(json) + { + var specialList = []; + var ret = JSON.parse(json, function(key, val){ + var special = cc.Serializer.getMethods(key); + if(special && special.s) + { + specialList.push({func:special.s, that:this, val:val}); + return undefined; + } + //if we defined a type for this object then + if(typeof val === "object" && val._type_) + { + var cls = cc.Serializer._getClass(val._type_); + var ret = new cls; + var keys = Object.keys(val); + for(var i = 0; i < keys.length; i++) + { + ret[keys[i]] = val[keys[i]]; + } + return ret; + } + return val; + }); + for(var i = 0; i < specialList.length; i++) + { + var o = specialList[i]; + o.func.call(o.that, o.val, this); + } + return ret; + }, + _getClass:function(str){ + //not using eval to prevent code injection + var scopes = str.split("."); + var ret = window[scopes[0]]; + for(var i = 1; i < scopes.length; i++) + { + if(!ret[scopes[i]]) throw "Error recreating " + str +" object, maybe it doesn't exists?"; + ret = ret[scopes[i]]; + } + return ret; + } +}; \ No newline at end of file diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index adb7e453f4..3354d125e8 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -186,7 +186,7 @@ cc.BLEND_DST = 0x0303; * @function */ cc.nodeDrawSetup = function (node) { - //cc.glEnable(node._glServerState); + //cc.glEnable(node.__glServerState); if (node._shaderProgram) { //cc._renderContext.useProgram(node._shaderProgram._programObj); node._shaderProgram.use(); diff --git a/cocos2d/core/platform/CCTypesPropertyDefine.js b/cocos2d/core/platform/CCTypesPropertyDefine.js index f0be5ac1de..4d850ea36a 100644 --- a/cocos2d/core/platform/CCTypesPropertyDefine.js +++ b/cocos2d/core/platform/CCTypesPropertyDefine.js @@ -160,6 +160,7 @@ cc._tmp.PrototypeColor = function () { /** @expose */ cc.BlendFunc.ADDITIVE; cc.defineGetterSetter(cc.BlendFunc, "ADDITIVE", cc.BlendFunc._additive); + }; diff --git a/cocos2d/core/renderer/RendererCanvas.js b/cocos2d/core/renderer/RendererCanvas.js index 793f3f4afc..f2f5a94d8b 100644 --- a/cocos2d/core/renderer/RendererCanvas.js +++ b/cocos2d/core/renderer/RendererCanvas.js @@ -99,7 +99,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { //transform node for (var i = 0, len = locPool.length; i < len; i++) { - if (locPool[i]._renderCmdDiry) //TODO need modify name for LabelTTF + if (locPool[i].__renderCmdDirty) //TODO need modify name for LabelTTF locPool[i]._transformForRenderer(); } locPool.length = 0; @@ -110,7 +110,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { }, _sortNodeByLevelAsc: function (n1, n2) { - return n1._curLevel - n2._curLevel; + return n1.__curLevel - n2.__curLevel; }, pushDirtyNode: function (node) { @@ -158,20 +158,20 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if(node._texture && (locTextureCoord.width === 0 || locTextureCoord.height === 0)) return; - if (!locTextureCoord.validRect && node._displayedOpacity === 0) + if (!locTextureCoord.validRect && node.__displayedOpacity === 0) return; //draw nothing if(node._texture && !node._texture._isLoaded) //set texture but the texture isn't loaded. return; - var t = node._transformWorld, + var t = node.__transformWorld, locX = node._offsetPosition.x, locY = -node._offsetPosition.y - node._rect.height, locWidth = node._rect.width, locHeight = node._rect.height, image, curColor, contentSize; - var blendChange = (node._blendFuncStr !== "source"), alpha = (node._displayedOpacity / 255); + var blendChange = (node._blendFuncStr !== "source"), alpha = (node.__displayedOpacity / 255); /*if(cc.renderer.contextSession.globalAlpha !== alpha){ cc.renderer.contextSession.globalAlpha = context.globalAlpha = alpha; //TODO }*/ @@ -224,8 +224,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { } else { contentSize = node._contentSize; if(contentSize.width !== 0 && contentSize.height !== 0) { - curColor = node._displayedColor; - context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + (node._displayedOpacity/255).toFixed(4) + ")"; + curColor = node.__displayedColor; + context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + (node.__displayedOpacity/255).toFixed(4) + ")"; context.fillRect(locX * scaleX, locY * scaleY, contentSize.width * scaleX, contentSize.height * scaleY); } } @@ -264,8 +264,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { } else { contentSize = node._contentSize; if(contentSize.width !== 0 && contentSize.height !== 0) { - curColor = node._displayedColor; - context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + (node._displayedOpacity/255).toFixed(4) + ")"; + curColor = node.__displayedColor; + context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + (node.__displayedOpacity/255).toFixed(4) + ")"; context.fillRect((t.tx + locX) * scaleX, (-t.ty + locY) * scaleY, contentSize.width * scaleX, contentSize.height * scaleY); } } @@ -282,9 +282,9 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.RectRenderCmdCanvas.prototype.rendering = function (ctx, scaleX, scaleY) { var context = ctx || cc._renderContext, node = this._node, - t = node._transformWorld, - curColor = node._displayedColor, - opacity = node._displayedOpacity / 255, + t = node.__transformWorld, + curColor = node.__displayedColor, + opacity = node.__displayedOpacity / 255, locWidth = node._contentSize.width, locHeight = node._contentSize.height; @@ -324,8 +324,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var context = ctx || cc._renderContext, self = this, node = self._node, - opacity = node._displayedOpacity / 255, - t = node._transformWorld; + opacity = node.__displayedOpacity / 255, + t = node.__transformWorld; if(opacity === 0) return; @@ -362,7 +362,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.ParticleRenderCmdCanvas.prototype.rendering = function (ctx, scaleX, scaleY) { var context = ctx || cc._renderContext, node = this._node, - t = node._transformWorld, + t = node.__transformWorld, pointRect = node._pointRect; context.save(); @@ -467,14 +467,14 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.ProgressRenderCmdCanvas.prototype.rendering = function (ctx, scaleX, scaleY) { var context = ctx || cc._renderContext, node = this._node, locSprite = this._sprite; - var locTextureCoord = locSprite._rendererCmd._textureCoord, alpha = locSprite._displayedOpacity / 255; + var locTextureCoord = locSprite.__rendererCmd._textureCoord, alpha = locSprite.__displayedOpacity / 255; if(locTextureCoord.width === 0 || locTextureCoord.height === 0) return; if (!locSprite._texture || !locTextureCoord.validRect || alpha === 0) return; - var t = node._transformWorld; + var t = node.__transformWorld; context.save(); context.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); @@ -541,12 +541,12 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.DrawNodeRenderCmdCanvas.prototype.rendering = function (ctx, scaleX, scaleY) { var context = ctx || cc._renderContext, _t = this, node = _t._node; - var alpha = node._displayedOpacity/255; + var alpha = node.__displayedOpacity/255; if(alpha === 0) return; context.globalAlpha = alpha; - var t = node._transformWorld; + var t = node.__transformWorld; context.save(); ctx.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); if ((_t._blendFunc && (_t._blendFunc.src == cc.SRC_ALPHA) && (_t._blendFunc.dst == cc.ONE))) @@ -643,7 +643,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { context.save(); } else { node.transform(); - var t = node._transformWorld; + var t = node.__transformWorld; context.save(); context.save(); context.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); @@ -660,7 +660,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if (node._clipElemType) { context.globalCompositeOperation = node.inverted ? "destination-out" : "destination-in"; - var t = node._transformWorld; + var t = node.__transformWorld; context.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); } else { context.restore(); @@ -745,28 +745,28 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.TMXLayerRenderCmdCanvas.prototype._renderingChildToCache = function (scaleX, scaleY) { var locNode = this._node; - if (locNode._cacheDirty) { + if (locNode.__cacheDirty) { var locCacheCmds = this._childrenRenderCmds, locCacheContext = locNode._cacheContext, locCanvas = locNode._cacheCanvas; locCacheContext.save(); locCacheContext.clearRect(0, 0, locCanvas.width, -locCanvas.height); //reset the cache context - var t = cc.affineTransformInvert(locNode._transformWorld); + var t = cc.affineTransformInvert(locNode.__transformWorld); locCacheContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); for (var i = 0, len = locCacheCmds.length; i < len; i++) { locCacheCmds[i].rendering(locCacheContext, scaleX, scaleY); if (locCacheCmds[i]._node) - locCacheCmds[i]._node._cacheDirty = false; + locCacheCmds[i]._node.__cacheDirty = false; } locCacheContext.restore(); - locNode._cacheDirty = false; + locNode.__cacheDirty = false; } }; cc.TMXLayerRenderCmdCanvas.prototype.rendering = function (ctx, scaleX, scaleY) { var node = this._node; - var alpha = node._displayedOpacity/255; + var alpha = node.__displayedOpacity/255; if(alpha <= 0) return; @@ -774,7 +774,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var context = ctx || cc._renderContext; context.globalAlpha = alpha; var posX = 0 | ( -node._anchorPointInPoints.x), posY = 0 | ( -node._anchorPointInPoints.y); - var locCacheCanvas = node._cacheCanvas, t = node._transformWorld; + var locCacheCanvas = node._cacheCanvas, t = node.__transformWorld; //direct draw image by canvas drawImage if (locCacheCanvas && locCacheCanvas.width !== 0 && locCacheCanvas.height !== 0) { context.save(); @@ -818,7 +818,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if(!node._debugSlots && !node._debugBones){ return; } - var t = node._transformWorld; + var t = node.__transformWorld; ctx.save(); ctx.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); var locSkeleton = node._skeleton; diff --git a/cocos2d/core/renderer/RendererWebGL.js b/cocos2d/core/renderer/RendererWebGL.js index 49499c5ce8..a5c42a9b50 100644 --- a/cocos2d/core/renderer/RendererWebGL.js +++ b/cocos2d/core/renderer/RendererWebGL.js @@ -93,7 +93,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ locPool.sort(this._sortNodeByLevelAsc); //transform node for (var i = 0, len = locPool.length; i < len; i++) { - if (locPool[i]._renderCmdDiry) + if (locPool[i].__renderCmdDirty) locPool[i]._transformForRenderer(); } locPool.length = 0; @@ -104,7 +104,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ }, _sortNodeByLevelAsc: function (n1, n2) { - return n1._curLevel - n2._curLevel; + return n1.__curLevel - n2.__curLevel; }, pushDirtyNode: function (node) { @@ -136,8 +136,14 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ }; cc.TextureRenderCmdWebGL.prototype.rendering = function(ctx){ + + var _t = this._node; - if (!_t._textureLoaded || _t._displayedOpacity === 0) + if(_t._id == true) + { + console.log(1); + } + if (!_t.__textureLoaded || _t.__displayedOpacity === 0) return; var gl = ctx || cc._renderContext, locTexture = _t._texture; @@ -146,17 +152,17 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ if (locTexture) { if (locTexture._isLoaded) { _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix); cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst); //optimize performance for javascript cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture); cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); - gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadWebBuffer); - if (_t._quadDirty) { - gl.bufferData(gl.ARRAY_BUFFER, _t._quad.arrayBuffer, gl.DYNAMIC_DRAW); - _t._quadDirty = false; + gl.bindBuffer(gl.ARRAY_BUFFER, _t.__quadWebBuffer); + if (_t.__quadDirty) { + gl.bufferData(gl.ARRAY_BUFFER, _t.__quad.arrayBuffer, gl.DYNAMIC_DRAW); + _t.__quadDirty = false; } gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.VERTEX_ATTRIB_POSITION gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.VERTEX_ATTRIB_COLOR @@ -166,17 +172,17 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ } } else { _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix); cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst); cc.glBindTexture2D(null); cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); - gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadWebBuffer); - if (_t._quadDirty) { - gl.bufferData(gl.ARRAY_BUFFER, _t._quad.arrayBuffer, gl.STATIC_DRAW); - _t._quadDirty = false; + gl.bindBuffer(gl.ARRAY_BUFFER, _t.__quadWebBuffer); + if (_t.__quadDirty) { + gl.bufferData(gl.ARRAY_BUFFER, _t.__quad.arrayBuffer, gl.STATIC_DRAW); + _t.__quadDirty = false; } gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); @@ -195,7 +201,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ var node = this._node; node._shaderProgram.use(); - node._shaderProgram._setUniformForMVPMatrixWithMat4(node._stackMatrix); + node._shaderProgram._setUniformForMVPMatrixWithMat4(node.__stackMatrix); cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); // @@ -219,7 +225,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ var _t = this._node; cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst); _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix); _t._render(); }; @@ -235,7 +241,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ if(_t.texture && _t.texture.isLoaded()){ ctx = ctx || cc._renderContext; _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix); cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst); @@ -272,7 +278,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ return; _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix); var blendFunc = _t._sprite.getBlendFunc(); cc.glBlendFunc(blendFunc.src, blendFunc.dst); @@ -317,7 +323,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ var gl = ctx || cc._renderContext; _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix);//setUniformForModelViewAndProjectionMatrixWithMat4(); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix);//setUniformForModelViewAndProjectionMatrixWithMat4(); cc.glBindTexture2D(_t._texture); cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst); @@ -344,13 +350,13 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ cc.ParticleBatchNodeRenderCmdWebGL.prototype.rendering = function(ctx){ var _t = this._node; - if (_t.textureAtlas.totalQuads == 0) + if (_t.__textureAtlas.totalQuads == 0) return; _t._shaderProgram.use(); - _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix); + _t._shaderProgram._setUniformForMVPMatrixWithMat4(_t.__stackMatrix); cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst); - _t.textureAtlas.drawQuads(); + _t.__textureAtlas.drawQuads(); }; //RenderTexture render command @@ -418,16 +424,16 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ cc.SpriteBatchNodeRenderCmdWebGL.prototype.rendering = function(ctx){ var node = this._node; - if (node.textureAtlas.totalQuads === 0) + if (node.__textureAtlas.totalQuads === 0) return; //cc.nodeDrawSetup(this); node._shaderProgram.use(); - node._shaderProgram._setUniformForMVPMatrixWithMat4(node._stackMatrix); + node._shaderProgram._setUniformForMVPMatrixWithMat4(node.__stackMatrix); node._arrayMakeObjectsPerformSelector(node._children, cc.Node._StateCallbackType.updateTransform); cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); - node.textureAtlas.drawQuads(); + node.__textureAtlas.drawQuads(); }; cc.AtlasNodeRenderCmdWebGL = function(node){ @@ -438,12 +444,12 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ var context = ctx || cc._renderContext, node = this._node; node._shaderProgram.use(); - node._shaderProgram._setUniformForMVPMatrixWithMat4(node._stackMatrix); + node._shaderProgram._setUniformForMVPMatrixWithMat4(node.__stackMatrix); cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); if(node._uniformColor && node._colorF32Array){ context.uniform4fv(node._uniformColor, node._colorF32Array); - node.textureAtlas.drawNumberOfQuads(node.quadsToDraw, 0); + node.__textureAtlas.drawNumberOfQuads(node.quadsToDraw, 0); } }; @@ -486,7 +492,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ cc.SkeletonRenderCmdWebGL.prototype.rendering = function(ctx){ var node = this._node; node._shaderProgram.use(); - node._shaderProgram._setUniformForMVPMatrixWithMat4(node._stackMatrix); + node._shaderProgram._setUniformForMVPMatrixWithMat4(node.__stackMatrix); // cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst); var color = node.getColor(), locSkeleton = node._skeleton; locSkeleton.r = color.r / 255; @@ -499,7 +505,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ locSkeleton.b *= locSkeleton.a; } - var additive,textureAtlas,attachment,slot, i, n, + var additive,__textureAtlas,attachment,slot, i, n, quad = new cc.V3F_C4B_T2F_Quad(); var locBlendFunc = node._blendFunc; @@ -511,41 +517,41 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ var regionTextureAtlas = node.getTextureAtlas(attachment); if (slot.data.additiveBlending != additive) { - if (textureAtlas) { - textureAtlas.drawQuads(); - textureAtlas.removeAllQuads(); + if (__textureAtlas) { + __textureAtlas.drawQuads(); + __textureAtlas.removeAllQuads(); } additive = !additive; cc.glBlendFunc(locBlendFunc.src, additive ? cc.ONE : locBlendFunc.dst); - } else if (regionTextureAtlas != textureAtlas && textureAtlas) { - textureAtlas.drawQuads(); - textureAtlas.removeAllQuads(); + } else if (regionTextureAtlas != __textureAtlas && __textureAtlas) { + __textureAtlas.drawQuads(); + __textureAtlas.removeAllQuads(); } - textureAtlas = regionTextureAtlas; + __textureAtlas = regionTextureAtlas; - var quadCount = textureAtlas.getTotalQuads(); - if (textureAtlas.getCapacity() == quadCount) { - textureAtlas.drawQuads(); - textureAtlas.removeAllQuads(); - if (!textureAtlas.resizeCapacity(textureAtlas.getCapacity() * 2)) + var quadCount = __textureAtlas.getTotalQuads(); + if (__textureAtlas.getCapacity() == quadCount) { + __textureAtlas.drawQuads(); + __textureAtlas.removeAllQuads(); + if (!__textureAtlas.resizeCapacity(__textureAtlas.getCapacity() * 2)) return; } sp._regionAttachment_updateQuad(attachment, slot, quad, node._premultipliedAlpha); - textureAtlas.updateQuad(quad, quadCount); + __textureAtlas.updateQuad(quad, quadCount); } - if (textureAtlas) { - textureAtlas.drawQuads(); - textureAtlas.removeAllQuads(); + if (__textureAtlas) { + __textureAtlas.drawQuads(); + __textureAtlas.removeAllQuads(); } if(node._debugBones || node._debugSlots){ cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW); - //cc.kmGLPushMatrixWitMat4(node._stackMatrix); + //cc.kmGLPushMatrixWitMat4(node.__stackMatrix); cc.current_stack.stack.push(cc.current_stack.top); - cc.current_stack.top = node._stackMatrix; + cc.current_stack.top = node.__stackMatrix; var drawingUtil = cc._drawingUtil; @@ -611,7 +617,7 @@ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW); cc.kmGLPushMatrix(); - cc.kmGLLoadMatrix(_t._stackMatrix); + cc.kmGLLoadMatrix(_t.__stackMatrix); //TODO REMOVE THIS FUNCTION if (_t._parentBone == null && _t._batchNode == null) { diff --git a/cocos2d/core/scenes/CCLoaderScene.js b/cocos2d/core/scenes/CCLoaderScene.js index 2781c7c4d1..a4bdcb0f1d 100644 --- a/cocos2d/core/scenes/CCLoaderScene.js +++ b/cocos2d/core/scenes/CCLoaderScene.js @@ -33,7 +33,7 @@ cc.LoaderScene = cc.Scene.extend({ _interval : null, _label : null, - _className:"LoaderScene", + __className:"LoaderScene", /** * Contructor of cc.LoaderScene * @returns {boolean} diff --git a/cocos2d/core/scenes/CCScene.js b/cocos2d/core/scenes/CCScene.js index a54a179dcd..01417ad05d 100644 --- a/cocos2d/core/scenes/CCScene.js +++ b/cocos2d/core/scenes/CCScene.js @@ -43,7 +43,8 @@ cc.Scene = cc.Node.extend(/** @lends cc.Scene# */{ /** * Constructor of cc.Scene */ - _className:"Scene", + __className:"Scene", + _type_:"cc.Scene", ctor:function () { cc.Node.prototype.ctor.call(this); this._ignoreAnchorPointForPosition = true; diff --git a/cocos2d/core/sprites/CCSprite.js b/cocos2d/core/sprites/CCSprite.js index 5e205daa5c..fc7333667f 100644 --- a/cocos2d/core/sprites/CCSprite.js +++ b/cocos2d/core/sprites/CCSprite.js @@ -288,26 +288,27 @@ cc._getCompositeOperationByBlendFunc = function(blendFunc){ * var sprite1 = new cc.Sprite(texture); * var sprite2 = new cc.Sprite(texture, cc.rect(0,0,480,320)); * - * @property {Boolean} dirty - Indicates whether the sprite needs to be updated. + * @property {Boolean} __dirty - Indicates whether the sprite needs to be updated. * @property {Boolean} flippedX - Indicates whether or not the spirte is flipped on x axis. * @property {Boolean} flippedY - Indicates whether or not the spirte is flipped on y axis. * @property {Number} offsetX - <@readonly> The offset position on x axis of the sprite in texture. Calculated automatically by editors like Zwoptex. * @property {Number} offsetY - <@readonly> The offset position on x axis of the sprite in texture. Calculated automatically by editors like Zwoptex. - * @property {Number} atlasIndex - The index used on the TextureAtlas. + * @property {Number} __atlasIndex - The index used on the TextureAtlas. * @property {cc.Texture2D} texture - Texture used to render the sprite. * @property {Boolean} textureRectRotated - <@readonly> Indicate whether the texture rectangle is rotated. - * @property {cc.TextureAtlas} textureAtlas - The weak reference of the cc.TextureAtlas when the sprite is rendered using via cc.SpriteBatchNode. + * @property {cc.TextureAtlas} __textureAtlas - The weak reference of the cc.TextureAtlas when the sprite is rendered using via cc.SpriteBatchNode. * @property {cc.SpriteBatchNode} batchNode - The batch node object if this sprite is rendered by cc.SpriteBatchNode. * @property {cc.V3F_C4B_T2F_Quad} quad - <@readonly> The quad (tex coords, vertex coords and color) information. */ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ - dirty:false, - atlasIndex:0, - textureAtlas:null, + _type_:"cc.Sprite", + __dirty:false, + __atlasIndex:0, + __textureAtlas:null, _batchNode:null, - _recursiveDirty:null, //Whether all of the sprite's children needs to be updated - _hasChildren:null, //Whether the sprite contains children + __recursiveDirty:null, //Whether all of the sprite's children needs to be updated + __hasChildren:null, //Whether the sprite contains children _shouldBeHidden:false, //should not be drawn because one of the ancestors is not visible _transformToBatch:null, @@ -334,9 +335,9 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _flippedX:false, //Whether the sprite is flipped horizontally or not. _flippedY:false, //Whether the sprite is flipped vertically or not. - _textureLoaded:false, + __textureLoaded:false, _newTextureWhenChangeColor: null, //hack property for LabelBMFont - _className:"Sprite", + __className:"Sprite", //Only for texture update judgment _oldDisplayColor: cc.color.WHITE, @@ -346,7 +347,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @returns {boolean} */ textureLoaded:function(){ - return this._textureLoaded; + return this.__textureLoaded; }, /** @@ -364,7 +365,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @return {Boolean} True if the sprite needs to be updated in the Atlas, false otherwise. */ isDirty:function () { - return this.dirty; + return this.__dirty; }, /** @@ -372,7 +373,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Boolean} bDirty */ setDirty:function (bDirty) { - this.dirty = bDirty; + this.__dirty = bDirty; }, /** @@ -388,16 +389,16 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @return {Number} */ getAtlasIndex:function () { - return this.atlasIndex; + return this.__atlasIndex; }, /** * Sets the index used on the TextureAtlas. * @warning Don't modify this value unless you know what you are doing - * @param {Number} atlasIndex + * @param {Number} __atlasIndex */ - setAtlasIndex:function (atlasIndex) { - this.atlasIndex = atlasIndex; + setAtlasIndex:function (__atlasIndex) { + this.__atlasIndex = __atlasIndex; }, /** @@ -413,15 +414,15 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @return {cc.TextureAtlas} */ getTextureAtlas:function () { - return this.textureAtlas; + return this.__textureAtlas; }, /** * Sets the weak reference of the cc.TextureAtlas when the sprite is rendered using via cc.SpriteBatchNode - * @param {cc.TextureAtlas} textureAtlas + * @param {cc.TextureAtlas} __textureAtlas */ - setTextureAtlas:function (textureAtlas) { - this.textureAtlas = textureAtlas; + setTextureAtlas:function (__textureAtlas) { + this.__textureAtlas = __textureAtlas; }, /** @@ -459,7 +460,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ if(!spriteFrame.textureLoaded()){ //add event listener - this._textureLoaded = false; + this.__textureLoaded = false; spriteFrame.addEventListener("load", this._spriteFrameLoadedCallback, this); } @@ -495,7 +496,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {cc.SpriteBatchNode} batchNode */ useBatchNode:function (batchNode) { - this.textureAtlas = batchNode.textureAtlas; // weak ref + this.__textureAtlas = batchNode.__textureAtlas; // weak ref this._batchNode = batchNode; }, @@ -522,7 +523,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @override */ sortAllChildren:function () { - if (this._reorderChildDirty) { + if (this.__reorderChildDirty) { var _children = this._children; // insertion sort @@ -550,7 +551,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ } //don't need to check children recursively, that's done in visit of each child - this._reorderChildDirty = false; + this.__reorderChildDirty = false; } }, @@ -571,7 +572,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ if (zOrder === child.zIndex) return; - if (this._batchNode && !this._reorderChildDirty) { + if (this._batchNode && !this.__reorderChildDirty) { this._setReorderChildDirtyRecursively(); this._batchNode.reorderBatch(true); } @@ -613,7 +614,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ } cc.Node.prototype.removeAllChildren.call(this, cleanup); - this._hasChildren = false; + this.__hasChildren = false; }, // @@ -626,8 +627,8 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @param {Boolean} value */ setDirtyRecursively:function (value) { - this._recursiveDirty = value; - this.dirty = value; + this.__recursiveDirty = value; + this.__dirty = value; // recursively set dirty var locChildren = this._children, child, l = locChildren ? locChildren.length : 0; for (var i = 0; i < l; i++) { @@ -638,18 +639,18 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ /** * Make the node dirty - * @param {Boolean} norecursive When true children will not be set dirty recursively, by default, they will be. + * @param {Boolean} norecursive When true children will not be set __dirty recursively, by default, they will be. * @override */ setNodeDirty: function(norecursive) { cc.Node.prototype.setNodeDirty.call(this); // Lazy set dirty - if (!norecursive && this._batchNode && !this._recursiveDirty) { - if (this._hasChildren) + if (!norecursive && this._batchNode && !this.__recursiveDirty) { + if (this.__hasChildren) this.setDirtyRecursively(true); else { - this._recursiveDirty = true; - this.dirty = true; + this.__recursiveDirty = true; + this.__dirty = true; } } }, @@ -777,9 +778,9 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _setReorderChildDirtyRecursively:function () { //only set parents flag the first time - if (!this._reorderChildDirty) { - this._reorderChildDirty = true; - var pNode = this._parent; + if (!this.__reorderChildDirty) { + this.__reorderChildDirty = true; + var pNode = this.__parent; while (pNode && pNode != this._batchNode) { pNode._setReorderChildDirtyRecursively(); pNode = pNode.parent; @@ -796,9 +797,9 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ return this._texture; }, - _quad: null, // vertex coords, texture coords and color info - _quadWebBuffer: null, - _quadDirty: false, + __quad: null, // vertex coords, texture coords and color info + __quadWebBuffer: null, + __quadDirty: false, _colorized: false, _blendFuncStr: "source-over", _originalTexture: null, @@ -841,7 +842,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * @return {cc.V3F_C4B_T2F_Quad} */ getQuad:function () { - return this._quad; + return this.__quad; }, /** @@ -933,7 +934,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ * Update sprite's color */ updateColor:function () { - var locDisplayedColor = this._displayedColor, locDisplayedOpacity = this._displayedOpacity; + var locDisplayedColor = this.__displayedColor, locDisplayedOpacity = this.__displayedOpacity; var color4 = {r: locDisplayedColor.r, g: locDisplayedColor.g, b: locDisplayedColor.b, a: locDisplayedOpacity}; // special opacity for premultiplied textures if (this._opacityModifyRGB) { @@ -941,7 +942,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ color4.g *= locDisplayedOpacity / 255.0; color4.b *= locDisplayedOpacity / 255.0; } - var locQuad = this._quad; + var locQuad = this.__quad; locQuad.bl.colors = color4; locQuad.br.colors = color4; locQuad.tl.colors = color4; @@ -949,17 +950,17 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ // renders using Sprite Manager if (this._batchNode) { - if (this.atlasIndex != cc.Sprite.INDEX_NOT_INITIALIZED) { - this.textureAtlas.updateQuad(locQuad, this.atlasIndex) + if (this.__atlasIndex != cc.Sprite.INDEX_NOT_INITIALIZED) { + this.__textureAtlas.updateQuad(locQuad, this.__atlasIndex) } else { // no need to set it recursively // update dirty_, don't update recursiveDirty_ - this.dirty = true; + this.__dirty = true; } } // self render // do nothing - this._quadDirty = true; + this.__quadDirty = true; }, /** @@ -1060,7 +1061,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ }, _changeTextureColor: function () { - var locElement, locTexture = this._texture, locRect = this._rendererCmd._textureCoord; //this.getTextureRect(); + var locElement, locTexture = this._texture, locRect = this.__rendererCmd._textureCoord; //this.getTextureRect(); if (locTexture && locRect.validRect && this._originalTexture) { locElement = locTexture.getHtmlElementObj(); if (!locElement) @@ -1069,9 +1070,9 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ this._colorized = true; if (locElement instanceof HTMLCanvasElement && !this._rectRotated && !this._newTextureWhenChangeColor && this._originalTexture._htmlElementObj != locElement) - cc.generateTintImageWithMultiply(this._originalTexture._htmlElementObj, this._displayedColor, locRect, locElement); + cc.generateTintImageWithMultiply(this._originalTexture._htmlElementObj, this.__displayedColor, locRect, locElement); else { - locElement = cc.generateTintImageWithMultiply(this._originalTexture._htmlElementObj, this._displayedColor, locRect); + locElement = cc.generateTintImageWithMultiply(this._originalTexture._htmlElementObj, this.__displayedColor, locRect); locTexture = new cc.Texture2D(); locTexture.initWithElement(locElement); locTexture.handleLoadedTexture(); @@ -1083,14 +1084,14 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _setTextureCoords:function (rect) { rect = cc.rectPointsToPixels(rect); - var tex = this._batchNode ? this.textureAtlas.texture : this._texture; + var tex = this._batchNode ? this.__textureAtlas.texture : this._texture; if (!tex) return; var atlasWidth = tex.pixelsWidth; var atlasHeight = tex.pixelsHeight; - var left, right, top, bottom, tempSwap, locQuad = this._quad; + var left, right, top, bottom, tempSwap, locQuad = this.__quad; if (this._rectRotated) { if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { left = (2 * rect.x + 1) / (2 * atlasWidth); @@ -1158,7 +1159,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ locQuad.tr.texCoords.u = right; locQuad.tr.texCoords.v = top; } - this._quadDirty = true; + this.__quadDirty = true; } }); @@ -1239,14 +1240,14 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { self._rect = cc.rect(0, 0, 0, 0); self._newTextureWhenChangeColor = false; - self._textureLoaded = true; + self.__textureLoaded = true; self._drawSize_Canvas = cc.size(0, 0); self._softInit(fileName, rect, rotated); }; _p._initRendererCmd = function(){ - this._rendererCmd = new cc.TextureRenderCmdCanvas(this); + this.__rendererCmd = new cc.TextureRenderCmdCanvas(this); }; _p.setBlendFunc = function (src, dst) { @@ -1268,14 +1269,14 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { return _t.initWithFile(arguments[0], arguments[1]); cc.Node.prototype.init.call(_t); - _t.dirty = _t._recursiveDirty = false; + _t.__dirty = _t.__recursiveDirty = false; _t._blendFunc.src = cc.BLEND_SRC; _t._blendFunc.dst = cc.BLEND_DST; // update texture (calls _updateBlendFunc) _t.texture = null; - _t._textureLoaded = true; + _t.__textureLoaded = true; _t._flippedX = _t._flippedY = false; // default transform anchor: center @@ -1285,7 +1286,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { // zwoptex default values _t._offsetPosition.x = 0; _t._offsetPosition.y = 0; - _t._hasChildren = false; + _t.__hasChildren = false; // updated in "useSelfRender" // Atlas: TexCoords @@ -1314,8 +1315,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { return false; _t._batchNode = null; - _t._recursiveDirty = false; - _t.dirty = false; + _t.__recursiveDirty = false; + _t.__dirty = false; _t._opacityModifyRGB = true; _t._blendFunc.src = cc.BLEND_SRC; @@ -1330,10 +1331,10 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { // zwoptex default values _t._offsetPosition.x = 0; _t._offsetPosition.y = 0; - _t._hasChildren = false; + _t.__hasChildren = false; var locTextureLoaded = texture.isLoaded(); - _t._textureLoaded = locTextureLoaded; + _t.__textureLoaded = locTextureLoaded; if (!locTextureLoaded) { _t._rectRotated = rotated; @@ -1375,10 +1376,10 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { _p._textureLoadedCallback = function (sender) { var _t = this; - if(_t._textureLoaded) + if(_t.__textureLoaded) return; - _t._textureLoaded = true; + _t.__textureLoaded = true; var locRect = _t._rect; if (!locRect) { locRect = cc.rect(0, 0, sender.width, sender.height); @@ -1392,7 +1393,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { _t.setTextureRect(locRect, _t._rectRotated); //set the texture's color after the it loaded - var locColor = this._displayedColor; + var locColor = this.__displayedColor; if(locColor.r != 255 || locColor.g != 255 || locColor.b != 255) _t._changeTextureColor(); @@ -1409,7 +1410,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { _t.setVertexRect(rect); - var locTextureRect = _t._rendererCmd._textureCoord, + var locTextureRect = _t.__rendererCmd._textureCoord, scaleFactor = cc.contentScaleFactor(); locTextureRect.renderX = locTextureRect.x = 0 | (rect.x * scaleFactor); locTextureRect.renderY = locTextureRect.y = 0 | (rect.y * scaleFactor); @@ -1427,8 +1428,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { // rendering using batch node if (_t._batchNode) { - // update dirty, don't update _recursiveDirty - _t.dirty = true; + // update dirty, don't update __recursiveDirty + _t.__dirty = true; } }; @@ -1437,9 +1438,9 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { //cc.assert(_t._batchNode, "updateTransform is only valid when cc.Sprite is being rendered using an cc.SpriteBatchNode"); // re-calculate matrix only if it is dirty - if (_t.dirty) { + if (_t.__dirty) { // If it is not visible, or one of its ancestors is not visible, then do nothing: - var locParent = _t._parent; + var locParent = _t.__parent; if (!_t._visible || ( locParent && locParent != _t._batchNode && locParent._shouldBeHidden)) { _t._shouldBeHidden = true; } else { @@ -1448,16 +1449,16 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if (!locParent || locParent == _t._batchNode) { _t._transformToBatch = _t.getNodeToParentTransform(); } else { - //cc.assert(_t._parent instanceof cc.Sprite, "Logic error in CCSprite. Parent must be a CCSprite"); + //cc.assert(_t.__parent instanceof cc.Sprite, "Logic error in CCSprite. Parent must be a CCSprite"); _t._transformToBatch = cc.affineTransformConcat(_t.getNodeToParentTransform(), locParent._transformToBatch); } } - _t._recursiveDirty = false; - _t.dirty = false; + _t.__recursiveDirty = false; + _t.__dirty = false; } // recursively iterate over children - if (_t._hasChildren) + if (_t.__hasChildren) _t._arrayMakeObjectsPerformSelector(_t._children, cc.Node._stateCallbackType.updateTransform); }; @@ -1471,7 +1472,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { //cc.Node already sets isReorderChildDirty_ so this needs to be after batchNode check cc.Node.prototype.addChild.call(this, child, localZOrder, tag); - this._hasChildren = true; + this.__hasChildren = true; }; _p.setOpacity = function (opacity) { @@ -1492,7 +1493,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var _t = this; cc.Node.prototype.updateDisplayedColor.call(_t, parentColor); var oColor = _t._oldDisplayColor; - var nColor = _t._displayedColor; + var nColor = _t.__displayedColor; if (oColor.r === nColor.r && oColor.g === nColor.g && oColor.b === nColor.b) return; @@ -1519,9 +1520,9 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var pNewTexture = newFrame.getTexture(); var locTextureLoaded = newFrame.textureLoaded(); if (!locTextureLoaded) { - _t._textureLoaded = false; + _t.__textureLoaded = false; newFrame.addEventListener("load", function (sender) { - _t._textureLoaded = true; + _t.__textureLoaded = true; var locNewTexture = sender.getTexture(); if (locNewTexture != _t._texture) _t.texture = locNewTexture; @@ -1538,8 +1539,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { _t.setTextureRect(newFrame.getRect(), _t._rectRotated, newFrame.getOriginalSize()); _t._colorized = false; - _t._rendererCmd._textureCoord.renderX = _t._rendererCmd._textureCoord.x; - _t._rendererCmd._textureCoord.renderY = _t._rendererCmd._textureCoord.y; + _t.__rendererCmd._textureCoord.renderX = _t.__rendererCmd._textureCoord.x; + _t.__rendererCmd._textureCoord.renderY = _t.__rendererCmd._textureCoord.y; if (locTextureLoaded) { var curColor = _t.color; if (curColor.r !== 255 || curColor.g !== 255 || curColor.b !== 255) @@ -1559,14 +1560,14 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { // self render if (!_t._batchNode) { - _t.atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED; - _t.textureAtlas = null; - _t._recursiveDirty = false; - _t.dirty = false; + _t.__atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED; + _t.__textureAtlas = null; + _t.__recursiveDirty = false; + _t.__dirty = false; } else { // using batch _t._transformToBatch = cc.affineTransformIdentity(); - _t.textureAtlas = _t._batchNode.textureAtlas; // weak ref + _t.__textureAtlas = _t._batchNode.__textureAtlas; // weak ref } }; @@ -1601,7 +1602,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { if(!cc.sys._supportCanvasNewBlendModes) _p._changeTextureColor = function () { - var locElement, locTexture = this._texture, locRect = this._rendererCmd._textureCoord; //this.getTextureRect(); + var locElement, locTexture = this._texture, locRect = this.__rendererCmd._textureCoord; //this.getTextureRect(); if (locTexture && locRect.validRect && this._originalTexture) { locElement = locTexture.getHtmlElementObj(); if (!locElement) @@ -1612,9 +1613,9 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { this._colorized = true; //generate color texture cache if (locElement instanceof HTMLCanvasElement && !this._rectRotated && !this._newTextureWhenChangeColor) - cc.generateTintImage(locElement, cacheTextureForColor, this._displayedColor, locRect, locElement); + cc.generateTintImage(locElement, cacheTextureForColor, this.__displayedColor, locRect, locElement); else { - locElement = cc.generateTintImage(locElement, cacheTextureForColor, this._displayedColor, locRect); + locElement = cc.generateTintImage(locElement, cacheTextureForColor, this.__displayedColor, locRect); locTexture = new cc.Texture2D(); locTexture.initWithElement(locElement); locTexture.handleLoadedTexture(); diff --git a/cocos2d/core/sprites/CCSpriteBatchNode.js b/cocos2d/core/sprites/CCSpriteBatchNode.js index 75cb18cb9d..90daeb770d 100644 --- a/cocos2d/core/sprites/CCSpriteBatchNode.js +++ b/cocos2d/core/sprites/CCSpriteBatchNode.js @@ -61,16 +61,16 @@ cc.DEFAULT_SPRITE_BATCH_CAPACITY = 29; * var texture = cc.textureCache.addImage("res/animations/grossini.png"); * var spriteBatchNode = new cc.SpriteBatchNode(texture,50); * - * @property {cc.TextureAtlas} textureAtlas - The texture atlas + * @property {cc.TextureAtlas} __textureAtlas - The texture atlas * @property {Array} descendants - <@readonly> Descendants of sprite batch node */ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ - textureAtlas: null, + __textureAtlas: null, _blendFunc: null, // all descendants: chlidren, gran children, etc... _descendants: null, - _className: "SpriteBatchNode", + __className: "SpriteBatchNode", /** *

@@ -92,14 +92,14 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ } // quad index is Z - child.atlasIndex = z; + child.__atlasIndex = z; // XXX: optimize with a binary search var i = 0, locDescendants = this._descendants; if (locDescendants && locDescendants.length > 0) { for (var index = 0; index < locDescendants.length; index++) { var obj = locDescendants[index]; - if (obj && (obj.atlasIndex >= z)) + if (obj && (obj.__atlasIndex >= z)) ++i; } } @@ -119,16 +119,16 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ * @return {cc.TextureAtlas} */ getTextureAtlas: function () { - return this.textureAtlas; + return this.__textureAtlas; }, /** * TextureAtlas of cc.SpriteBatchNode setter - * @param {cc.TextureAtlas} textureAtlas + * @param {cc.TextureAtlas} __textureAtlas */ - setTextureAtlas: function (textureAtlas) { - if (textureAtlas != this.textureAtlas) { - this.textureAtlas = textureAtlas; + setTextureAtlas: function (__textureAtlas) { + if (__textureAtlas != this.__textureAtlas) { + this.__textureAtlas = __textureAtlas; } }, @@ -159,7 +159,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ }, _setNodeDirtyForCache: function () { - this._cacheDirty = true; + this.__cacheDirty = true; }, /** @@ -187,12 +187,12 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ // if we're going beyond the current TextureAtlas's capacity, // all the previously initialized sprites will need to redo their texture coords // this is likely computationally expensive - var locCapacity = this.textureAtlas.capacity; + var locCapacity = this.__textureAtlas.capacity; var quantity = Math.floor((locCapacity + 1) * 4 / 3); cc.log(cc._LogInfos.SpriteBatchNode_increaseAtlasCapacity, locCapacity, quantity); - if (!this.textureAtlas.resizeCapacity(quantity)) { + if (!this.__textureAtlas.resizeCapacity(quantity)) { // serious problems cc.log(cc._LogInfos.SpriteBatchNode_increaseAtlasCapacity_2); } @@ -225,7 +225,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ } // ignore self (batch node) if (!pobParent == this) { - pobParent.atlasIndex = index; + pobParent.__atlasIndex = index; index++; } if (children && children.length > 0) { @@ -247,7 +247,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var children = sprite.children; if (!children || children.length == 0) - return sprite.atlasIndex; + return sprite.__atlasIndex; else return this.highestAtlasIndexInChild(children[children.length - 1]); }, @@ -261,7 +261,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var children = sprite.children; if (!children || children.length == 0) - return sprite.atlasIndex; + return sprite.__atlasIndex; else return this.lowestAtlasIndexInChild(children[children.length - 1]); }, @@ -295,16 +295,16 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ if (childIndex == 0) { // less than parent and brothers if (nZ < 0) - return selParent.atlasIndex; + return selParent.__atlasIndex; else - return selParent.atlasIndex + 1; + return selParent.__atlasIndex + 1; } else { // previous & sprite belong to the same branch if ((previous.zIndex < 0 && nZ < 0) || (previous.zIndex >= 0 && nZ >= 0)) return this.highestAtlasIndexInChild(previous) + 1; // else (previous < 0 and sprite >= 0 ) - return selParent.atlasIndex + 1; + return selParent.__atlasIndex + 1; } }, @@ -313,7 +313,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ * @param {Boolean} reorder */ reorderBatch: function (reorder) { - this._reorderChildDirty = reorder; + this.__reorderChildDirty = reorder; }, /** @@ -416,7 +416,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ _initRendererCmd: function(){ if(cc._renderType === cc._RENDER_TYPE_WEBGL) - this._rendererCmd = new cc.SpriteBatchNodeRenderCmdWebGL(this); + this.__rendererCmd = new cc.SpriteBatchNodeRenderCmdWebGL(this); }, /** @@ -444,10 +444,10 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ // update the quad directly. Don't add the sprite to the scene graph // sprite.batchNode = this; - sprite.atlasIndex = index; + sprite.__atlasIndex = index; - sprite.dirty = true; - // UpdateTransform updates the textureAtlas quad + sprite.__dirty = true; + // UpdateTransform updates the __textureAtlas quad sprite.updateTransform(); }, @@ -461,8 +461,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ } // make needed room - var locCapacity = this.textureAtlas.capacity; - while (index >= locCapacity || locCapacity == this.textureAtlas.totalQuads) { + var locCapacity = this.__textureAtlas.capacity; + while (index >= locCapacity || locCapacity == this.__textureAtlas.totalQuads) { this.increaseAtlasCapacity(); } @@ -470,22 +470,22 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ // update the quad directly. Don't add the sprite to the scene graph // sprite.batchNode = this; - sprite.atlasIndex = index; + sprite.__atlasIndex = index; - sprite.dirty = true; - // UpdateTransform updates the textureAtlas quad + sprite.__dirty = true; + // UpdateTransform updates the __textureAtlas quad sprite.updateTransform(); }, _swap: function (oldIndex, newIndex) { var locDescendants = this._descendants; - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; var quads = locTextureAtlas.quads; var tempItem = locDescendants[oldIndex]; var tempIteQuad = cc.V3F_C4B_T2F_QuadCopy(quads[oldIndex]); //update the index of other swapped item - locDescendants[newIndex].atlasIndex = oldIndex; + locDescendants[newIndex].__atlasIndex = oldIndex; locDescendants[oldIndex] = locDescendants[newIndex]; locTextureAtlas.updateQuad(quads[newIndex], oldIndex); @@ -518,11 +518,11 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ // update the quad directly. Don't add the sprite to the scene graph // sprite.batchNode = this; - sprite.atlasIndex = index; + sprite.__atlasIndex = index; - // XXX: updateTransform will update the textureAtlas too, using updateQuad. + // XXX: updateTransform will update the __textureAtlas too, using updateQuad. // XXX: so, it should be AFTER the insertQuad - sprite.dirty = true; + sprite.__dirty = true; sprite.updateTransform(); sprite._setCachedParent(this); this._children.splice(index, 0, sprite); @@ -538,7 +538,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ } // make needed room - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; while (index >= locTextureAtlas.capacity || locTextureAtlas.capacity === locTextureAtlas.totalQuads) this.increaseAtlasCapacity(); @@ -546,12 +546,12 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ // update the quad directly. Don't add the sprite to the scene graph // sprite.batchNode = this; - sprite.atlasIndex = index; + sprite.__atlasIndex = index; locTextureAtlas.insertQuad(sprite.quad, index); - // XXX: updateTransform will update the textureAtlas too, using updateQuad. + // XXX: updateTransform will update the __textureAtlas too, using updateQuad. // XXX: so, it should be AFTER the insertQuad - sprite.dirty = true; + sprite.__dirty = true; sprite.updateTransform(); }, @@ -563,8 +563,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var oldIndex = 0; if (count === 0) { - oldIndex = sprite.atlasIndex; - sprite.atlasIndex = curIndex; + oldIndex = sprite.__atlasIndex; + sprite.__atlasIndex = curIndex; sprite.arrivalOrder = 0; if (oldIndex != curIndex) this._swap(oldIndex, curIndex); @@ -573,8 +573,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var needNewIndex = true; if (pArray[0].zIndex >= 0) { //all children are in front of the parent - oldIndex = sprite.atlasIndex; - sprite.atlasIndex = curIndex; + oldIndex = sprite.__atlasIndex; + sprite.__atlasIndex = curIndex; sprite.arrivalOrder = 0; if (oldIndex != curIndex) this._swap(oldIndex, curIndex); @@ -584,8 +584,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ for (var i = 0; i < pArray.length; i++) { var child = pArray[i]; if (needNewIndex && child.zIndex >= 0) { - oldIndex = sprite.atlasIndex; - sprite.atlasIndex = curIndex; + oldIndex = sprite.__atlasIndex; + sprite.__atlasIndex = curIndex; sprite.arrivalOrder = 0; if (oldIndex != curIndex) { this._swap(oldIndex, curIndex); @@ -598,8 +598,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ if (needNewIndex) { //all children have a zOrder < 0) - oldIndex = sprite.atlasIndex; - sprite.atlasIndex = curIndex; + oldIndex = sprite.__atlasIndex; + sprite.__atlasIndex = curIndex; sprite.arrivalOrder = 0; if (oldIndex != curIndex) { this._swap(oldIndex, curIndex); @@ -612,7 +612,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ }, _updateBlendFunc: function () { - if (!this.textureAtlas.texture.hasPremultipliedAlpha()) { + if (!this.__textureAtlas.texture.hasPremultipliedAlpha()) { this._blendFunc.src = cc.SRC_ALPHA; this._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; } @@ -648,8 +648,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); capacity = capacity || cc.DEFAULT_SPRITE_BATCH_CAPACITY; - this.textureAtlas = new cc.TextureAtlas(); - this.textureAtlas.initWithTexture(tex, capacity); + this.__textureAtlas = new cc.TextureAtlas(); + this.__textureAtlas.initWithTexture(tex, capacity); this._updateBlendFunc(); this.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); return true; @@ -662,10 +662,10 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ */ insertChild: function (sprite, index) { sprite.batchNode = this; - sprite.atlasIndex = index; - sprite.dirty = true; + sprite.__atlasIndex = index; + sprite.__dirty = true; - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; if (locTextureAtlas.totalQuads >= locTextureAtlas.capacity) this.increaseAtlasCapacity(); @@ -676,7 +676,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var i = index + 1, locDescendant = this._descendants; if (locDescendant && locDescendant.length > 0) { for (; i < locDescendant.length; i++) - locDescendant[i].atlasIndex++; + locDescendant[i].__atlasIndex++; } // add children recursively @@ -700,12 +700,12 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ appendChild: null, _appendChildForCanvas: function (sprite) { - this._reorderChildDirty = true; + this.__reorderChildDirty = true; sprite.batchNode = this; - sprite.dirty = true; + sprite.__dirty = true; this._descendants.push(sprite); - sprite.atlasIndex = this._descendants.length - 1; + sprite.__atlasIndex = this._descendants.length - 1; // add children recursively var children = sprite.children; @@ -714,15 +714,15 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ }, _appendChildForWebGL: function (sprite) { - this._reorderChildDirty = true; + this.__reorderChildDirty = true; sprite.batchNode = this; - sprite.dirty = true; + sprite.__dirty = true; this._descendants.push(sprite); var index = this._descendants.length - 1; - sprite.atlasIndex = index; + sprite.__atlasIndex = index; - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; if (locTextureAtlas.totalQuads == locTextureAtlas.capacity) this.increaseAtlasCapacity(); locTextureAtlas.insertQuad(sprite.quad, index); @@ -752,7 +752,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var len = locDescendants.length; for (; index < len; ++index) { var s = locDescendants[index]; - s.atlasIndex--; + s.__atlasIndex--; } } @@ -765,7 +765,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ }, _removeSpriteFromAtlasForWebGL: function (sprite) { - this.textureAtlas.removeQuadAtIndex(sprite.atlasIndex); // remove from TextureAtlas + this.__textureAtlas.removeQuadAtIndex(sprite.__atlasIndex); // remove from TextureAtlas // Cleanup sprite. It might be reused (issue #569) sprite.batchNode = null; @@ -780,7 +780,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var len = locDescendants.length; for (; index < len; ++index) { var s = locDescendants[index]; - s.atlasIndex--; + s.__atlasIndex--; } } @@ -804,7 +804,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ }, _getTextureForWebGL: function () { - return this.textureAtlas.texture; + return this.__textureAtlas.texture; }, /** @@ -822,7 +822,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ }, _setTextureForWebGL: function (texture) { - this.textureAtlas.texture = texture; + this.__textureAtlas.texture = texture; this._updateBlendFunc(); }, @@ -868,8 +868,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ var currentStack = cc.current_stack; currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(this._stackMatrix, currentStack.top); - currentStack.top = this._stackMatrix; + cc.kmMat4Assign(this.__stackMatrix, currentStack.top); + currentStack.top = this.__stackMatrix; /* var locGrid = this.grid; if (locGrid && locGrid.isActive()) { @@ -880,8 +880,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ this.sortAllChildren(); this.transform(gl); //this.draw(gl); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); /* if (locGrid && locGrid.isActive()) locGrid.afterDraw(this);*/ @@ -925,7 +925,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ cc.log(cc._LogInfos.Sprite_addChild_4); return; } - if (child.texture != this.textureAtlas.texture) { // check cc.Sprite is using the same texture id + if (child.texture != this.__textureAtlas.texture) { // check cc.Sprite is using the same texture id cc.log(cc._LogInfos.Sprite_addChild_5); return; } @@ -973,7 +973,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ } cc.Node.prototype.removeAllChildren.call(this, cleanup); this._descendants.length = 0; - this.textureAtlas.removeAllQuads(); + this.__textureAtlas.removeAllQuads(); }, /** @@ -982,7 +982,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ sortAllChildren: null, _sortAllChildrenForCanvas: function () { - if (this._reorderChildDirty) { + if (this.__reorderChildDirty) { var i, j = 0, locChildren = this._children; var length = locChildren.length, tempChild; //insertion sort @@ -1006,12 +1006,12 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ //first sort all children recursively based on zOrder this._arrayMakeObjectsPerformSelector(locChildren, cc.Node._StateCallbackType.sortAllChildren); } - this._reorderChildDirty = false; + this.__reorderChildDirty = false; } }, _sortAllChildrenForWebGL: function () { - if (this._reorderChildDirty) { + if (this.__reorderChildDirty) { var childrenArr = this._children; var i, j = 0, length = childrenArr.length, tempChild; //insertion sort @@ -1036,12 +1036,12 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ this._arrayMakeObjectsPerformSelector(childrenArr, cc.Node._StateCallbackType.sortAllChildren); var index = 0; - //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact) + //fast dispatch, give every child a new __atlasIndex based on their relative zOrder (keep parent -> child relations intact) // and at the same time reorder descedants and the quads to the right index for (i = 0; i < childrenArr.length; i++) index = this._updateAtlasIndex(childrenArr[i], index); } - this._reorderChildDirty = false; + this.__reorderChildDirty = false; } }, @@ -1053,7 +1053,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ _drawForWebGL: function () { // Optimization: Fast Dispatch - if (this.textureAtlas.totalQuads === 0) + if (this.__textureAtlas.totalQuads === 0) return; //cc.nodeDrawSetup(this); @@ -1062,7 +1062,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{ this._arrayMakeObjectsPerformSelector(this._children, cc.Node._StateCallbackType.updateTransform); cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst); - this.textureAtlas.drawQuads(); + this.__textureAtlas.drawQuads(); } }); diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index f485cfba57..f152a710c5 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -61,7 +61,7 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{ _originalSizeInPixels:null, _texture:null, _textureFilename:"", - _textureLoaded:false, + __textureLoaded:false, ctor:function (filename, rect, rotated, offset, originalSize) { this._offset = cc.p(0, 0); @@ -71,7 +71,7 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{ this._originalSizeInPixels = cc.size(0, 0); this._textureFilename = ""; this._texture = null; - this._textureLoaded = false; + this.__textureLoaded = false; if(filename !== undefined && rect !== undefined ){ if(rotated === undefined || offset === undefined || originalSize === undefined) @@ -86,7 +86,7 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{ * @returns {boolean} */ textureLoaded:function(){ - return this._textureLoaded; + return this.__textureLoaded; }, /** @@ -225,7 +225,7 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{ if (this._textureFilename !== "") { var locTexture = cc.textureCache.addImage(this._textureFilename); if (locTexture) - this._textureLoaded = locTexture.isLoaded(); + this.__textureLoaded = locTexture.isLoaded(); return locTexture; } return null; @@ -238,11 +238,11 @@ cc.SpriteFrame = cc.Class.extend(/** @lends cc.SpriteFrame# */{ setTexture:function (texture) { if (this._texture != texture) { var locLoaded = texture.isLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; this._texture = texture; if(!locLoaded){ texture.addEventListener("load", function(sender){ - this._textureLoaded = true; + this.__textureLoaded = true; if(this._rotated && cc._renderType === cc._RENDER_TYPE_CANVAS){ var tempElement = sender.getHtmlElementObj(); tempElement = cc.cutRotateImageToCanvas(tempElement, this.getRect()); diff --git a/cocos2d/core/sprites/SpritesPropertyDefine.js b/cocos2d/core/sprites/SpritesPropertyDefine.js index b576ca9a72..a98de94d43 100644 --- a/cocos2d/core/sprites/SpritesPropertyDefine.js +++ b/cocos2d/core/sprites/SpritesPropertyDefine.js @@ -34,13 +34,13 @@ cc._tmp.PrototypeSprite = function () { // Extended properties /** @expose */ - _p.dirty; + _p.__dirty; /** @expose */ _p.flippedX; - cc.addProperty(_p, "flippedX", false, _p.isFlippedX, _p.setFlippedX); + cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX); /** @expose */ _p.flippedY; - cc.addProperty(_p, "flippedY", false, _p.isFlippedY, _p.setFlippedY); + cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY); /** @expose */ _p.offsetX; cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX); @@ -48,15 +48,15 @@ cc._tmp.PrototypeSprite = function () { _p.offsetY; cc.defineGetterSetter(_p, "offsetY", _p._getOffsetY); /** @expose */ - _p.atlasIndex; + _p.__atlasIndex; /** @expose */ _p.texture; - cc.addProperty(_p, "texture", null, _p.getTexture, _p.setTexture); + cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture); /** @expose */ _p.textureRectRotated; cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated); /** @expose */ - _p.textureAtlas; + _p.__textureAtlas; /** @expose */ _p.batchNode; cc.defineGetterSetter(_p, "batchNode", _p.getBatchNode, _p.setBatchNode); @@ -64,17 +64,4 @@ cc._tmp.PrototypeSprite = function () { _p.quad; cc.defineGetterSetter(_p, "quad", _p.getQuad); - _p.__type = "cc.Sprite"; - - _p.__delegators = { - "texture" : { - parser : function(json) { - return cc.textureCache.addImage(json); - }, - stringifier : function(texture) { - return cc.textureCache.getKeyByTexture(texture); - } - } - } - }; diff --git a/cocos2d/core/sprites/SpritesWebGL.js b/cocos2d/core/sprites/SpritesWebGL.js index 4eff01f610..f7dd325893 100644 --- a/cocos2d/core/sprites/SpritesWebGL.js +++ b/cocos2d/core/sprites/SpritesWebGL.js @@ -54,17 +54,17 @@ cc._tmp.WebGLSprite = function () { self._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST}; self._rect = cc.rect(0,0,0,0); - self._quad = new cc.V3F_C4B_T2F_Quad(); - self._quadWebBuffer = cc._renderContext.createBuffer(); - self._quadDirty = true; + self.__quad = new cc.V3F_C4B_T2F_Quad(); + self.__quadWebBuffer = cc._renderContext.createBuffer(); + self.__quadDirty = true; - self._textureLoaded = true; + self.__textureLoaded = true; self._softInit(fileName, rect, rotated); }; _p._initRendererCmd = function(){ - this._rendererCmd = new cc.TextureRenderCmdWebGL(this); + this.__rendererCmd = new cc.TextureRenderCmdWebGL(this); }; _p.setBlendFunc = function (src, dst) { @@ -84,7 +84,7 @@ cc._tmp.WebGLSprite = function () { return _t.initWithFile(arguments[0], arguments[1]); cc.Node.prototype.init.call(_t); - _t.dirty = _t._recursiveDirty = false; + _t.__dirty = _t.__recursiveDirty = false; _t._opacityModifyRGB = true; _t._blendFunc.src = cc.BLEND_SRC; @@ -92,7 +92,7 @@ cc._tmp.WebGLSprite = function () { // update texture (calls _updateBlendFunc) _t.texture = null; - _t._textureLoaded = true; + _t.__textureLoaded = true; _t._flippedX = _t._flippedY = false; // default transform anchor: center @@ -103,15 +103,15 @@ cc._tmp.WebGLSprite = function () { _t._offsetPosition.x = 0; _t._offsetPosition.y = 0; - _t._hasChildren = false; + _t.__hasChildren = false; // Atlas: Color var tempColor = {r: 255, g: 255, b: 255, a: 255}; - _t._quad.bl.colors = tempColor; - _t._quad.br.colors = tempColor; - _t._quad.tl.colors = tempColor; - _t._quad.tr.colors = tempColor; - _t._quadDirty = true; + _t.__quad.bl.colors = tempColor; + _t.__quad.br.colors = tempColor; + _t.__quad.tl.colors = tempColor; + _t.__quad.tr.colors = tempColor; + _t.__quadDirty = true; // updated in "useSelfRender" // Atlas: TexCoords @@ -131,8 +131,8 @@ cc._tmp.WebGLSprite = function () { return false; _t._batchNode = null; - _t._recursiveDirty = false; - _t.dirty = false; + _t.__recursiveDirty = false; + _t.__dirty = false; _t._opacityModifyRGB = true; _t._blendFunc.src = cc.BLEND_SRC; @@ -147,18 +147,18 @@ cc._tmp.WebGLSprite = function () { // zwoptex default values _t._offsetPosition.x = 0; _t._offsetPosition.y = 0; - _t._hasChildren = false; + _t.__hasChildren = false; // Atlas: Color var tmpColor = cc.color(255, 255, 255, 255); - var locQuad = _t._quad; + var locQuad = _t.__quad; locQuad.bl.colors = tmpColor; locQuad.br.colors = tmpColor; locQuad.tl.colors = tmpColor; locQuad.tr.colors = tmpColor; var locTextureLoaded = texture.isLoaded(); - _t._textureLoaded = locTextureLoaded; + _t.__textureLoaded = locTextureLoaded; if (!locTextureLoaded) { _t._rectRotated = rotated || false; @@ -200,16 +200,16 @@ cc._tmp.WebGLSprite = function () { // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" _t.batchNode = null; - _t._quadDirty = true; + _t.__quadDirty = true; return true; }; _p._textureLoadedCallback = function (sender) { var _t = this; - if(_t._textureLoaded) + if(_t.__textureLoaded) return; - _t._textureLoaded = true; + _t.__textureLoaded = true; var locRect = _t._rect; if (!locRect) { locRect = cc.rect(0, 0, sender.width, sender.height); @@ -224,7 +224,7 @@ cc._tmp.WebGLSprite = function () { // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" _t.batchNode = _t._batchNode; - _t._quadDirty = true; + _t.__quadDirty = true; _t.dispatchEvent("load"); }; @@ -248,8 +248,8 @@ cc._tmp.WebGLSprite = function () { // rendering using batch node if (_t._batchNode) { - // update dirty, don't update _recursiveDirty - _t.dirty = true; + // update dirty, don't update __recursiveDirty + _t.__dirty = true; } else { // self rendering // Atlas: Vertex @@ -259,13 +259,13 @@ cc._tmp.WebGLSprite = function () { var y2 = y1 + locRect.height; // Don't update Z. - var locQuad = _t._quad; + var locQuad = _t.__quad; locQuad.bl.vertices = {x:x1, y:y1, z:0}; locQuad.br.vertices = {x:x2, y:y1, z:0}; locQuad.tl.vertices = {x:x1, y:y2, z:0}; locQuad.tr.vertices = {x:x2, y:y2, z:0}; - _t._quadDirty = true; + _t.__quadDirty = true; } }; @@ -274,8 +274,8 @@ cc._tmp.WebGLSprite = function () { //cc.assert(_t._batchNode, "updateTransform is only valid when cc.Sprite is being rendered using an cc.SpriteBatchNode"); // recaculate matrix only if it is dirty - if (_t.dirty) { - var locQuad = _t._quad, locParent = _t._parent; + if (_t.__dirty) { + var locQuad = _t.__quad, locParent = _t.__parent; // If it is not visible, or one of its ancestors is not visible, then do nothing: if (!_t._visible || ( locParent && locParent != _t._batchNode && locParent._shouldBeHidden)) { locQuad.br.vertices = locQuad.tl.vertices = locQuad.tr.vertices = locQuad.bl.vertices = {x: 0, y: 0, z: 0}; @@ -286,7 +286,7 @@ cc._tmp.WebGLSprite = function () { if (!locParent || locParent == _t._batchNode) { _t._transformToBatch = _t.nodeToParentTransform(); } else { - //cc.assert(_t._parent instanceof cc.Sprite, "Logic error in CCSprite. Parent must be a CCSprite"); + //cc.assert(_t.__parent instanceof cc.Sprite, "Logic error in CCSprite. Parent must be a CCSprite"); _t._transformToBatch = cc.affineTransformConcat(_t.nodeToParentTransform(), locParent._transformToBatch); } @@ -335,22 +335,22 @@ cc._tmp.WebGLSprite = function () { locQuad.tl.vertices = {x: dx, y: dy, z: locVertexZ}; locQuad.tr.vertices = {x: cx, y: cy, z: locVertexZ}; } - _t.textureAtlas.updateQuad(locQuad, _t.atlasIndex); - _t._recursiveDirty = false; - _t.dirty = false; + _t.__textureAtlas.updateQuad(locQuad, _t.__atlasIndex); + _t.__recursiveDirty = false; + _t.__dirty = false; } // recursively iterate over children - if (_t._hasChildren) + if (_t.__hasChildren) _t._arrayMakeObjectsPerformSelector(_t._children, cc.Node._StateCallbackType.updateTransform); if (cc.SPRITE_DEBUG_DRAW) { // draw bounding box var vertices = [ - cc.p(_t._quad.bl.vertices.x, _t._quad.bl.vertices.y), - cc.p(_t._quad.br.vertices.x, _t._quad.br.vertices.y), - cc.p(_t._quad.tr.vertices.x, _t._quad.tr.vertices.y), - cc.p(_t._quad.tl.vertices.x, _t._quad.tl.vertices.y) + cc.p(_t.__quad.bl.vertices.x, _t.__quad.bl.vertices.y), + cc.p(_t.__quad.br.vertices.x, _t.__quad.br.vertices.y), + cc.p(_t.__quad.tr.vertices.x, _t.__quad.tr.vertices.y), + cc.p(_t.__quad.tl.vertices.x, _t.__quad.tl.vertices.y) ]; cc._drawingUtil.drawPoly(vertices, 4, true); } @@ -371,18 +371,18 @@ cc._tmp.WebGLSprite = function () { cc.log(cc._LogInfos.Sprite_addChild); return; } - if(child.texture._webTextureObj !== _t.textureAtlas.texture._webTextureObj) + if(child.texture._webTextureObj !== _t.__textureAtlas.texture._webTextureObj) cc.log(cc._LogInfos.Sprite_addChild_2); //put it in descendants array of batch node _t._batchNode.appendChild(child); - if (!_t._reorderChildDirty) + if (!_t.__reorderChildDirty) _t._setReorderChildDirtyRecursively(); } //cc.Node already sets isReorderChildDirty_ so _t needs to be after batchNode check cc.Node.prototype.addChild.call(_t, child, localZOrder, tag); - _t._hasChildren = true; + _t.__hasChildren = true; }; _p.setOpacity = function (opacity) { @@ -415,9 +415,9 @@ cc._tmp.WebGLSprite = function () { var pNewTexture = newFrame.getTexture(); var locTextureLoaded = newFrame.textureLoaded(); if (!locTextureLoaded) { - _t._textureLoaded = false; + _t.__textureLoaded = false; newFrame.addEventListener("load", function (sender) { - _t._textureLoaded = true; + _t.__textureLoaded = true; var locNewTexture = sender.getTexture(); if (locNewTexture != _t._texture) _t.texture = locNewTexture; @@ -446,26 +446,26 @@ cc._tmp.WebGLSprite = function () { // self render if (!_t._batchNode) { - _t.atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED; - _t.textureAtlas = null; - _t._recursiveDirty = false; - _t.dirty = false; + _t.__atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED; + _t.__textureAtlas = null; + _t.__recursiveDirty = false; + _t.__dirty = false; var x1 = _t._offsetPosition.x; var y1 = _t._offsetPosition.y; var x2 = x1 + _t._rect.width; var y2 = y1 + _t._rect.height; - var locQuad = _t._quad; + var locQuad = _t.__quad; locQuad.bl.vertices = {x:x1, y:y1, z:0}; locQuad.br.vertices = {x:x2, y:y1, z:0}; locQuad.tl.vertices = {x:x1, y:y2, z:0}; locQuad.tr.vertices = {x:x2, y:y2, z:0}; - _t._quadDirty = true; + _t.__quadDirty = true; } else { // using batch _t._transformToBatch = cc.affineTransformIdentity(); - _t.textureAtlas = _t._batchNode.textureAtlas; // weak ref + _t.__textureAtlas = _t._batchNode.__textureAtlas; // weak ref } }; @@ -510,7 +510,7 @@ cc._tmp.WebGLSprite = function () { _p.draw = function () { var _t = this; - if (!_t._textureLoaded) + if (!_t.__textureLoaded) return; var gl = cc._renderContext, locTexture = _t._texture; @@ -526,10 +526,10 @@ cc._tmp.WebGLSprite = function () { cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture); cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); - gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadWebBuffer); - if (_t._quadDirty) { - gl.bufferData(gl.ARRAY_BUFFER, _t._quad.arrayBuffer, gl.DYNAMIC_DRAW); - _t._quadDirty = false; + gl.bindBuffer(gl.ARRAY_BUFFER, _t.__quadWebBuffer); + if (_t.__quadDirty) { + gl.bufferData(gl.ARRAY_BUFFER, _t.__quad.arrayBuffer, gl.DYNAMIC_DRAW); + _t.__quadDirty = false; } gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.VERTEX_ATTRIB_POSITION gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.VERTEX_ATTRIB_COLOR @@ -546,10 +546,10 @@ cc._tmp.WebGLSprite = function () { cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); - gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadWebBuffer); - if (_t._quadDirty) { - cc._renderContext.bufferData(cc._renderContext.ARRAY_BUFFER, _t._quad.arrayBuffer, cc._renderContext.STATIC_DRAW); - _t._quadDirty = false; + gl.bindBuffer(gl.ARRAY_BUFFER, _t.__quadWebBuffer); + if (_t.__quadDirty) { + cc._renderContext.bufferData(cc._renderContext.ARRAY_BUFFER, _t.__quad.arrayBuffer, cc._renderContext.STATIC_DRAW); + _t.__quadDirty = false; } gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); @@ -561,7 +561,7 @@ cc._tmp.WebGLSprite = function () { if (cc.SPRITE_DEBUG_DRAW === 1 || _t._showNode) { // draw bounding box - var locQuad = _t._quad; + var locQuad = _t.__quad; var verticesG1 = [ cc.p(locQuad.tl.vertices.x, locQuad.tl.vertices.y), cc.p(locQuad.bl.vertices.x, locQuad.bl.vertices.y), diff --git a/cocos2d/core/textures/CCTextureAtlas.js b/cocos2d/core/textures/CCTextureAtlas.js index f1b753abfb..32ebeb1531 100644 --- a/cocos2d/core/textures/CCTextureAtlas.js +++ b/cocos2d/core/textures/CCTextureAtlas.js @@ -36,14 +36,14 @@ * @class * @extends cc.Class * - * @property {Boolean} dirty - Indicates whether or not the array buffer of the VBO needs to be updated. + * @property {Boolean} __dirty - Indicates whether or not the array buffer of the VBO needs to be updated. * @property {Image} texture - Image texture for cc.TextureAtlas. * @property {Number} capacity - <@readonly> Quantity of quads that can be stored with the current texture atlas size. * @property {Number} totalQuads - <@readonly> Quantity of quads that are going to be drawn. * @property {Array} quads - <@readonly> Quads that are going to be rendered */ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ - dirty: false, + __dirty: false, texture: null, _indices: null, @@ -65,11 +65,11 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ * @example * 1. * //creates a TextureAtlas with filename - * var textureAtlas = new cc.TextureAtlas("res/hello.png", 3); + * var __textureAtlas = new cc.TextureAtlas("res/hello.png", 3); * 2. * //creates a TextureAtlas with texture * var texture = cc.textureCache.addImage("hello.png"); - * var textureAtlas = new cc.TextureAtlas(texture, 3); + * var __textureAtlas = new cc.TextureAtlas(texture, 3); */ ctor: function (fileName, capacity) { this._buffersVBO = []; @@ -115,10 +115,10 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ /** * specify if the array buffer of the VBO needs to be updated - * @param {Boolean} dirty + * @param {Boolean} __dirty */ - setDirty: function (dirty) { - this.dirty = dirty; + setDirty: function (__dirty) { + this.__dirty = __dirty; }, /** @@ -126,7 +126,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ * @returns {boolean} */ isDirty: function () { - return this.dirty; + return this.__dirty; }, /** @@ -227,8 +227,8 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ * @return {Boolean} * @example * //example - * var textureAtlas = new cc.TextureAtlas(); - * textureAtlas.initWithTexture("hello.png", 3); + * var __textureAtlas = new cc.TextureAtlas(); + * __textureAtlas.initWithTexture("hello.png", 3); */ initWithFile: function (file, capacity) { // retained in property @@ -252,8 +252,8 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ * @example * //example * var texture = cc.textureCache.addImage("hello.png"); - * var textureAtlas = new cc.TextureAtlas(); - * textureAtlas.initWithTexture(texture, 3); + * var __textureAtlas = new cc.TextureAtlas(); + * __textureAtlas.initWithTexture(texture, 3); */ initWithTexture: function (texture, capacity) { cc.assert(texture, cc._LogInfos.TextureAtlas_initWithTexture); @@ -281,7 +281,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ this._setupIndices(); this._setupVBO(); - this.dirty = true; + this.__dirty = true; return true; }, @@ -297,7 +297,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ this._totalQuads = Math.max(index + 1, this._totalQuads); this._setQuadToArray(quad, index); - this.dirty = true; + this.__dirty = true; }, /** @@ -323,7 +323,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ this._quadsReader.set(this._quadsReader.subarray(startOffset, startOffset + moveLength), startOffset + quadSize); this._setQuadToArray(quad, index); - this.dirty = true; + this.__dirty = true; }, /** @@ -361,7 +361,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ for (i = 0; i < amount; i++) this._setQuadToArray(quads[i], index + i); - this.dirty = true; + this.__dirty = true; }, /** @@ -393,7 +393,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ locQuadsReader.set(locQuadsReader.subarray(startOffset, startOffset + moveLength), startOffset - quadSize); locQuadsReader.set(sourceArr, newIndex * quadSize); } - this.dirty = true; + this.__dirty = true; }, /** @@ -413,7 +413,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ var moveLength = (this._totalQuads - index) * quadSize; this._quadsReader.set(this._quadsReader.subarray(startOffset, startOffset + moveLength), startOffset - quadSize); } - this.dirty = true; + this.__dirty = true; }, /** @@ -434,7 +434,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ var dstOffset = index * quadSize; this._quadsReader.set(this._quadsReader.subarray(srcOffset, srcOffset + moveLength), dstOffset); } - this.dirty = true; + this.__dirty = true; }, /** @@ -447,8 +447,8 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ this._totalQuads = 0; }, - _setDirty: function (dirty) { - this.dirty = dirty; + _setDirty: function (__dirty) { + this.__dirty = __dirty; }, /** @@ -520,7 +520,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ this._setupIndices(); this._mapBuffers(); - this.dirty = true; + this.__dirty = true; return true; }, @@ -573,7 +573,7 @@ cc.TextureAtlas = cc.Class.extend(/** @lends cc.TextureAtlas# */{ locQuadsReader.set(locQuadsReader.subarray(moveStart, moveStart + moveLength), srcOffset); } locQuadsReader.set(sourceArr, dstOffset); - this.dirty = true; + this.__dirty = true; }, /** @@ -616,13 +616,13 @@ var _p = cc.TextureAtlas.prototype; // Extended properties /** @expose */ _p.totalQuads; -cc.addProperty(_p, "totalQuads", _p.getTotalQuads); +cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads); /** @expose */ _p.capacity; -cc.addProperty(_p, "capacity", _p.getCapacity); +cc.defineGetterSetter(_p, "capacity", _p.getCapacity); /** @expose */ _p.quads; -cc.addProperty(_p, "quads", _p.getQuads, _p.setQuads); +cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads); /** *

Creates a TextureAtlas with an filename and with an initial capacity for Quads.
diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index abd6b53ee7..954adfd12e 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -815,15 +815,15 @@ cc._tmp.WebGLTextureAtlas = function () { cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadsWebBuffer); - if (_t.dirty) + if (_t.__dirty) gl.bufferData(gl.ARRAY_BUFFER, _t._quadsArrayBuffer, gl.DYNAMIC_DRAW); gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords - if (_t.dirty) - _t.dirty = false; + if (_t.__dirty) + _t.__dirty = false; gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _t._buffersVBO[1]); diff --git a/cocos2d/labels/CCLabelAtlas.js b/cocos2d/labels/CCLabelAtlas.js index 8ee45fac95..44d6552e20 100644 --- a/cocos2d/labels/CCLabelAtlas.js +++ b/cocos2d/labels/CCLabelAtlas.js @@ -52,8 +52,8 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ // the first char in the charmap _mapStartChar: null, - _textureLoaded: false, - _className: "LabelAtlas", + __textureLoaded: false, + __className: "LabelAtlas", /** *

@@ -83,7 +83,7 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ * @returns {boolean} */ textureLoaded: function () { - return this._textureLoaded; + return this.__textureLoaded; }, /** @@ -138,7 +138,7 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ else texture = cc.textureCache.addImage(textureFilename); var locLoaded = texture.isLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if (!locLoaded) { texture.addEventListener("load", function (sender) { this.initWithTexture(texture, width, height, label.length); @@ -236,7 +236,7 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ _updateAtlasValuesForWebGL: function () { var locString = this._string; var n = locString.length; - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; var texture = locTextureAtlas.texture; var textureWide = texture.pixelsWidth; @@ -250,8 +250,8 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ if (n > locTextureAtlas.getCapacity()) cc.log("cc.LabelAtlas._updateAtlasValues(): Invalid String length"); var quads = locTextureAtlas.quads; - var locDisplayedColor = this._displayedColor; - var curColor = {r: locDisplayedColor.r, g: locDisplayedColor.g, b: locDisplayedColor.b, a: this._displayedOpacity}; + var locDisplayedColor = this.__displayedColor; + var curColor = {r: locDisplayedColor.r, g: locDisplayedColor.g, b: locDisplayedColor.b, a: this.__displayedOpacity}; var locItemWidth = this._itemWidth; for (var i = 0; i < n; i++) { var a = locString.charCodeAt(i) - this._mapStartChar.charCodeAt(0); @@ -300,7 +300,7 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ locQuadBR.colors = curColor; } if (n > 0) { - locTextureAtlas.dirty = true; + locTextureAtlas.__dirty = true; var totalQuads = locTextureAtlas.totalQuads; if (n > totalQuads) locTextureAtlas.increaseTotalQuadsWith(n - totalQuads); @@ -337,8 +337,8 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ _setStringForWebGL: function (label) { label = String(label); var len = label.length; - if (len > this.textureAtlas.totalQuads) - this.textureAtlas.resizeCapacity(len); + if (len > this.__textureAtlas.totalQuads) + this.__textureAtlas.resizeCapacity(len); this._string = label; this.width = len * this._itemWidth; diff --git a/cocos2d/labels/CCLabelBMFont.js b/cocos2d/labels/CCLabelBMFont.js index a3b7617502..34ce156ae0 100644 --- a/cocos2d/labels/CCLabelBMFont.js +++ b/cocos2d/labels/CCLabelBMFont.js @@ -113,15 +113,15 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ _reusedChar: null, //texture RGBA - _displayedOpacity: 255, + __displayedOpacity: 255, _realOpacity: 255, - _displayedColor: null, + __displayedColor: null, _realColor: null, _cascadeColorEnabled: true, _cascadeOpacityEnabled: true, - _textureLoaded: false, - _className: "LabelBMFont", + __textureLoaded: false, + __className: "LabelBMFont", _setString: function (newString, needUpdateLabel) { if (!needUpdateLabel) { @@ -137,7 +137,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ selNode.setVisible(false); } } - if (this._textureLoaded) { + if (this.__textureLoaded) { this.createFontChars(); if (needUpdateLabel) @@ -158,7 +158,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ var self = this; cc.SpriteBatchNode.prototype.ctor.call(self); self._imageOffset = cc.p(0, 0); - self._displayedColor = cc.color(255, 255, 255, 255); + self.__displayedColor = cc.color(255, 255, 255, 255); self._realColor = cc.color(255, 255, 255, 255); self._reusedChar = []; @@ -170,7 +170,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @returns {boolean} */ textureLoaded: function () { - return this._textureLoaded; + return this.__textureLoaded; }, /** @@ -206,17 +206,17 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @param {cc.Color} color */ setColor: function (color) { - var locDisplayed = this._displayedColor, locRealColor = this._realColor; + var locDisplayed = this.__displayedColor, locRealColor = this._realColor; if ((locRealColor.r == color.r) && (locRealColor.g == color.g) && (locRealColor.b == color.b) && (locRealColor.a == color.a)) return; locDisplayed.r = locRealColor.r = color.r; locDisplayed.g = locRealColor.g = color.g; locDisplayed.b = locRealColor.b = color.b; - if (this._textureLoaded) { + if (this.__textureLoaded) { if (this._cascadeColorEnabled) { var parentColor = cc.color.WHITE; - var locParent = this._parent; + var locParent = this.__parent; if (locParent && locParent.cascadeColor) parentColor = locParent.getDisplayedColor(); this.updateDisplayedColor(parentColor); @@ -261,7 +261,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @returns {number} */ getDisplayedOpacity: function () { - return this._displayedOpacity; + return this.__displayedOpacity; }, /** @@ -269,16 +269,16 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @param {Number} opacity */ setOpacity: function (opacity) { - this._displayedOpacity = this._realOpacity = opacity; + this.__displayedOpacity = this._realOpacity = opacity; if (this._cascadeOpacityEnabled) { var parentOpacity = 255; - var locParent = this._parent; + var locParent = this.__parent; if (locParent && locParent.cascadeOpacity) parentOpacity = locParent.getDisplayedOpacity(); this.updateDisplayedOpacity(parentOpacity); } - this._displayedColor.a = this._realColor.a = opacity; + this.__displayedColor.a = this._realColor.a = opacity; }, /** @@ -286,14 +286,14 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @param parentOpacity */ updateDisplayedOpacity: function (parentOpacity) { - this._displayedOpacity = this._realOpacity * parentOpacity / 255.0; + this.__displayedOpacity = this._realOpacity * parentOpacity / 255.0; var locChildren = this._children; for (var i = 0; i < locChildren.length; i++) { var locChild = locChildren[i]; if (cc._renderType == cc._RENDER_TYPE_WEBGL) { - locChild.updateDisplayedOpacity(this._displayedOpacity); + locChild.updateDisplayedOpacity(this.__displayedOpacity); } else { - cc.Node.prototype.updateDisplayedOpacity.call(locChild, this._displayedOpacity); + cc.Node.prototype.updateDisplayedOpacity.call(locChild, this.__displayedOpacity); locChild.setNodeDirty(); } } @@ -332,7 +332,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @returns {cc.Color} */ getDisplayedColor: function () { - var dc = this._displayedColor; + var dc = this.__displayedColor; return cc.color(dc.r, dc.g, dc.b, dc.a); }, @@ -342,7 +342,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ * @returns {cc.Color} */ updateDisplayedColor: function (parentColor) { - var locDispColor = this._displayedColor; + var locDispColor = this.__displayedColor; var locRealColor = this._realColor; locDispColor.r = locRealColor.r * parentColor.r / 255.0; locDispColor.g = locRealColor.g * parentColor.g / 255.0; @@ -352,9 +352,9 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ for (var i = 0; i < locChildren.length; i++) { var locChild = locChildren[i]; if (cc._renderType == cc._RENDER_TYPE_WEBGL) { - locChild.updateDisplayedColor(this._displayedColor); + locChild.updateDisplayedColor(this.__displayedColor); } else { - cc.Node.prototype.updateDisplayedColor.call(locChild, this._displayedColor); + cc.Node.prototype.updateDisplayedColor.call(locChild, this.__displayedColor); locChild.setNodeDirty(); } } @@ -373,10 +373,10 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ var locElement = locTexture.getHtmlElementObj(); var textureRect = cc.rect(0, 0, element.width, element.height); if (locElement instanceof HTMLCanvasElement && !this._rectRotated){ - cc.generateTintImageWithMultiply(element, this._displayedColor, textureRect, locElement); + cc.generateTintImageWithMultiply(element, this.__displayedColor, textureRect, locElement); this.setTexture(locTexture); } else { - locElement = cc.generateTintImageWithMultiply(element, this._displayedColor, textureRect); + locElement = cc.generateTintImageWithMultiply(element, this.__displayedColor, textureRect); locTexture = new cc.Texture2D(); locTexture.initWithElement(locElement); locTexture.handleLoadedTexture(); @@ -436,11 +436,11 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ self._fntFile = fntFile; texture = cc.textureCache.addImage(newConf.atlasName); var locIsLoaded = texture.isLoaded(); - self._textureLoaded = locIsLoaded; + self.__textureLoaded = locIsLoaded; if (!locIsLoaded) { texture.addEventListener("load", function (sender) { var self1 = this; - self1._textureLoaded = true; + self1.__textureLoaded = true; //reset the LabelBMFont self1.initWithTexture(sender, self1._initialString.length); self1.setString(self1._initialString, true); @@ -451,7 +451,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ texture = new cc.Texture2D(); var image = new Image(); texture.initWithElement(image); - self._textureLoaded = false; + self.__textureLoaded = false; } if (self.initWithTexture(texture, theString.length)) { @@ -459,8 +459,8 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ self._imageOffset = imageOffset || cc.p(0, 0); self._width = (width == null) ? -1 : width; - self._displayedOpacity = self._realOpacity = 255; - self._displayedColor = cc.color(255, 255, 255, 255); + self.__displayedOpacity = self._realOpacity = 255; + self.__displayedColor = cc.color(255, 255, 255, 255); self._realColor = cc.color(255, 255, 255, 255); self._cascadeOpacityEnabled = true; self._cascadeColorEnabled = true; @@ -471,7 +471,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ self.setAnchorPoint(0.5, 0.5); if (cc._renderType === cc._RENDER_TYPE_WEBGL) { - var locTexture = self.textureAtlas.texture; + var locTexture = self.__textureAtlas.texture; self._opacityModifyRGB = locTexture.hasPremultipliedAlpha(); var reusedChar = self._reusedChar = new cc.Sprite(); @@ -490,7 +490,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ createFontChars: function () { var self = this; var locContextType = cc._renderType; - var locTexture = (locContextType === cc._RENDER_TYPE_CANVAS) ? self.texture : self.textureAtlas.texture; + var locTexture = (locContextType === cc._RENDER_TYPE_CANVAS) ? self.texture : self.__textureAtlas.texture; var nextFontPositionX = 0; @@ -562,11 +562,11 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ fontChar.opacityModifyRGB = self._opacityModifyRGB; // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on if (cc._renderType == cc._RENDER_TYPE_WEBGL) { - fontChar.updateDisplayedColor(self._displayedColor); - fontChar.updateDisplayedOpacity(self._displayedOpacity); + fontChar.updateDisplayedColor(self.__displayedColor); + fontChar.updateDisplayedOpacity(self.__displayedOpacity); } else { - cc.Node.prototype.updateDisplayedColor.call(fontChar, self._displayedColor); - cc.Node.prototype.updateDisplayedOpacity.call(fontChar, self._displayedOpacity); + cc.Node.prototype.updateDisplayedColor.call(fontChar, self.__displayedColor); + cc.Node.prototype.updateDisplayedOpacity.call(fontChar, self.__displayedOpacity); fontChar.setNodeDirty(); } @@ -940,14 +940,14 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ var texture = cc.textureCache.addImage(newConf.atlasName); var locIsLoaded = texture.isLoaded(); - self._textureLoaded = locIsLoaded; + self.__textureLoaded = locIsLoaded; self.texture = texture; if (cc._renderType === cc._RENDER_TYPE_CANVAS) self._originalTexture = self.texture; if (!locIsLoaded) { texture.addEventListener("load", function (sender) { var self1 = this; - self1._textureLoaded = true; + self1.__textureLoaded = true; self1.texture = sender; self1.createFontChars(); self1._changeTextureColor(); @@ -1073,10 +1073,10 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { var cacheTextureForColor = cc.textureCache.getTextureColors(this._originalTexture.getHtmlElementObj()); if (cacheTextureForColor) { if (locElement instanceof HTMLCanvasElement && !this._rectRotated) { - cc.generateTintImage(locElement, cacheTextureForColor, this._displayedColor, null, locElement); + cc.generateTintImage(locElement, cacheTextureForColor, this.__displayedColor, null, locElement); this.setTexture(locTexture); } else { - locElement = cc.generateTintImage(locElement, cacheTextureForColor, this._displayedColor); + locElement = cc.generateTintImage(locElement, cacheTextureForColor, this.__displayedColor); locTexture = new cc.Texture2D(); locTexture.initWithElement(locElement); locTexture.handleLoadedTexture(); @@ -1088,10 +1088,10 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { } _p.setTexture = function (texture) { var locChildren = this._children; - var locDisplayedColor = this._displayedColor; + var locDisplayedColor = this.__displayedColor; for (var i = 0; i < locChildren.length; i++) { var selChild = locChildren[i]; - var childDColor = selChild._displayedColor; + var childDColor = selChild.__displayedColor; if (this._textureForCanvas != selChild._texture && (childDColor.r !== locDisplayedColor.r || childDColor.g !== locDisplayedColor.g || childDColor.b !== locDisplayedColor.b)) continue; diff --git a/cocos2d/menus/CCMenu.js b/cocos2d/menus/CCMenu.js index 40923e3043..80966a5872 100644 --- a/cocos2d/menus/CCMenu.js +++ b/cocos2d/menus/CCMenu.js @@ -61,7 +61,7 @@ cc.Menu = cc.Layer.extend(/** @lends cc.Menu# */{ _selectedItem: null, _state: -1, _touchListener: null, - _className: "Menu", + __className: "Menu", /** * Constructor of cc.Menu override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. diff --git a/cocos2d/menus/CCMenuItem.js b/cocos2d/menus/CCMenuItem.js index d810ad4745..c848749cf8 100644 --- a/cocos2d/menus/CCMenuItem.js +++ b/cocos2d/menus/CCMenuItem.js @@ -40,7 +40,7 @@ cc.MenuItem = cc.Node.extend(/** @lends cc.MenuItem# */{ _target: null, _callback: null, _isSelected: false, - _className: "MenuItem", + __className: "MenuItem", /** * Constructor of cc.MenuItem diff --git a/cocos2d/motion-streak/CCMotionStreak.js b/cocos2d/motion-streak/CCMotionStreak.js index a0df3d6392..07f9ae5b67 100644 --- a/cocos2d/motion-streak/CCMotionStreak.js +++ b/cocos2d/motion-streak/CCMotionStreak.js @@ -70,7 +70,7 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{ _verticesBuffer:null, _colorPointerBuffer:null, _texCoordsBuffer:null, - _className:"MotionStreak", + __className:"MotionStreak", /** * creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture filename or texture
@@ -118,7 +118,7 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{ }, _initRendererCmd:function(){ - this._rendererCmd = new cc.MotionStreakCmdWebGL(this); + this.__rendererCmd = new cc.MotionStreakCmdWebGL(this); }, /** @@ -509,7 +509,7 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{ // Color assignment var offset = locNuPoints * 8; - var locDisplayedColor = this._displayedColor; + var locDisplayedColor = this.__displayedColor; locColorPointer[offset] = locDisplayedColor.r; locColorPointer[offset + 1] = locDisplayedColor.g; locColorPointer[offset + 2] = locDisplayedColor.b; diff --git a/cocos2d/node-grid/CCNodeGrid.js b/cocos2d/node-grid/CCNodeGrid.js index 1d9b39dd37..6506e28565 100644 --- a/cocos2d/node-grid/CCNodeGrid.js +++ b/cocos2d/node-grid/CCNodeGrid.js @@ -95,8 +95,8 @@ cc.NodeGrid = cc.Node.extend({ if(isWebGL){ var currentStack = cc.current_stack; currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(this._stackMatrix, currentStack.top); - currentStack.top = this._stackMatrix; + cc.kmMat4Assign(this.__stackMatrix, currentStack.top); + currentStack.top = this.__stackMatrix; } self.transform(); @@ -106,12 +106,12 @@ cc.NodeGrid = cc.Node.extend({ var beforeProjectionType = cc.director.PROJECTION_DEFAULT; if (locGrid && locGrid._active){ //var backMatrix = new cc.kmMat4(); - //cc.kmMat4Assign(backMatrix, this._stackMatrix); + //cc.kmMat4Assign(backMatrix, this.__stackMatrix); beforeProjectionType = cc.director.getProjection(); //locGrid.set2DProjection(); - //reset this._stackMatrix to current_stack.top + //reset this.__stackMatrix to current_stack.top //cc.kmMat4Assign(currentStack.top, backMatrix); } if(this._gridBeginCommand) @@ -144,10 +144,10 @@ cc.NodeGrid = cc.Node.extend({ _transformForWebGL: function () { //optimize performance for javascript - var t4x4 = this._transform4x4, topMat4 = cc.current_stack.top; + var t4x4 = this.__transform4x4, topMat4 = cc.current_stack.top; // Convert 3x3 into 4x4 matrix - //cc.CGAffineToGL(this.nodeToParentTransform(), this._transform4x4.mat); + //cc.CGAffineToGL(this.nodeToParentTransform(), this.__transform4x4.mat); var trans = this.nodeToParentTransform(); var t4x4Mat = t4x4.mat; t4x4Mat[0] = trans.a; @@ -158,11 +158,11 @@ cc.NodeGrid = cc.Node.extend({ t4x4Mat[13] = trans.ty; // Update Z vertex manually - //this._transform4x4.mat[14] = this._vertexZ; + //this.__transform4x4.mat[14] = this._vertexZ; t4x4Mat[14] = this._vertexZ; //optimize performance for Javascript - cc.kmMat4Multiply(topMat4, topMat4, t4x4); // = cc.kmGLMultMatrix(this._transform4x4); + cc.kmMat4Multiply(topMat4, topMat4, t4x4); // = cc.kmGLMultMatrix(this.__transform4x4); // XXX: Expensive calls. Camera should be integrated into the cached affine matrix if (this._camera != null && !(this.grid && this.grid.isActive())) { diff --git a/cocos2d/parallax/CCParallaxNode.js b/cocos2d/parallax/CCParallaxNode.js index 48fbb51616..31235d0c95 100644 --- a/cocos2d/parallax/CCParallaxNode.js +++ b/cocos2d/parallax/CCParallaxNode.js @@ -124,7 +124,7 @@ cc.ParallaxNode = cc.Node.extend(/** @lends cc.ParallaxNode# */{ parallaxArray:null, _lastPosition:null, - _className:"ParallaxNode", + __className:"ParallaxNode", /** * Gets the parallax array. diff --git a/cocos2d/particle/CCParticleBatchNode.js b/cocos2d/particle/CCParticleBatchNode.js index 4009bdb491..5410a84f1c 100644 --- a/cocos2d/particle/CCParticleBatchNode.js +++ b/cocos2d/particle/CCParticleBatchNode.js @@ -58,7 +58,7 @@ cc.PARTICLE_DEFAULT_CAPACITY = 500; * @param {Number} capacity * * @property {cc.Texture2D|HTMLImageElement|HTMLCanvasElement} texture - The used texture - * @property {cc.TextureAtlas} textureAtlas - The texture atlas used for drawing the quads + * @property {cc.TextureAtlas} __textureAtlas - The texture atlas used for drawing the quads * * @example * 1. @@ -71,12 +71,12 @@ cc.PARTICLE_DEFAULT_CAPACITY = 500; * var particleBatchNode = new cc.ParticleBatchNode(texture, 30); */ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ - textureAtlas:null, + __textureAtlas:null, TextureProtocol:true, //the blend function used for drawing the quads _blendFunc:null, - _className:"ParticleBatchNode", + __className:"ParticleBatchNode", /** * initializes the particle system with the name of a file on disk (for a list of supported formats look at the cc.Texture2D class), a capacity of particles @@ -110,8 +110,8 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ * @return {Boolean} */ initWithTexture:function (texture, capacity) { - this.textureAtlas = new cc.TextureAtlas(); - this.textureAtlas.initWithTexture(texture, capacity); + this.__textureAtlas = new cc.TextureAtlas(); + this.__textureAtlas.initWithTexture(texture, capacity); // no lazy alloc in this node this._children.length = 0; @@ -157,7 +157,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ zOrder = (zOrder == null) ? child.zIndex : zOrder; tag = (tag == null) ? child.tag : tag; - if(child.getTexture() != this.textureAtlas.texture) + if(child.getTexture() != this.__textureAtlas.texture) throw "cc.ParticleSystem.addChild() : the child is not using the same texture id"; // If this is the 1st children, then copy blending function @@ -174,16 +174,16 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ //no lazy sorting, so don't call super addChild, call helper instead var pos = this._addChildHelper(child, zOrder, tag); - //get new atlasIndex - var atlasIndex = 0; + //get new __atlasIndex + var __atlasIndex = 0; if (pos != 0) { var p = this._children[pos - 1]; - atlasIndex = p.getAtlasIndex() + p.getTotalParticles(); + __atlasIndex = p.getAtlasIndex() + p.getTotalParticles(); } else - atlasIndex = 0; + __atlasIndex = 0; - this.insertChild(child, atlasIndex); + this.insertChild(child, __atlasIndex); // update quad info child.setBatchNode(this); @@ -196,12 +196,12 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ */ insertChild:function (pSystem, index) { var totalParticles = pSystem.getTotalParticles(); - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; var totalQuads = locTextureAtlas.totalQuads; pSystem.setAtlasIndex(index); if (totalQuads + totalParticles > locTextureAtlas.getCapacity()) { this._increaseAtlasCapacityTo(totalQuads + totalParticles); - // after a realloc empty quads of textureAtlas can be filled with gibberish (realloc doesn't perform calloc), insert empty quads to prevent it + // after a realloc empty quads of __textureAtlas can be filled with gibberish (realloc doesn't perform calloc), insert empty quads to prevent it locTextureAtlas.fillWithEmptyQuadsFromIndex(locTextureAtlas.getCapacity() - totalParticles, totalParticles); } @@ -232,7 +232,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ cc.Node.prototype.removeChild.call(this, child, cleanup); - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; // remove child helper locTextureAtlas.removeQuadsAtIndex(child.getAtlasIndex(), child.getTotalParticles()); @@ -289,8 +289,8 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ } } - // reorder textureAtlas quads - this.textureAtlas.moveQuadsFromIndex(oldAtlasIndex, child.getTotalParticles(), newAtlasIndex); + // reorder __textureAtlas quads + this.__textureAtlas.moveQuadsFromIndex(oldAtlasIndex, child.getTotalParticles(), newAtlasIndex); child.updateWithNoTime(); } @@ -315,7 +315,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ locChildren[i].setBatchNode(null); } cc.Node.prototype.removeAllChildren.call(this, doCleanup); - this.textureAtlas.removeAllQuads(); + this.__textureAtlas.removeAllQuads(); }, /** @@ -323,10 +323,10 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ * @param {Number} particleIndex */ disableParticle:function (particleIndex) { - var quad = this.textureAtlas.quads[particleIndex]; + var quad = this.__textureAtlas.quads[particleIndex]; quad.br.vertices.x = quad.br.vertices.y = quad.tr.vertices.x = quad.tr.vertices.y = quad.tl.vertices.x = quad.tl.vertices.y = quad.bl.vertices.x = quad.bl.vertices.y = 0.0; - this.textureAtlas._setDirty(true); + this.__textureAtlas._setDirty(true); }, /** @@ -339,12 +339,12 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ if (cc._renderType === cc._RENDER_TYPE_CANVAS) return; - if (this.textureAtlas.totalQuads == 0) + if (this.__textureAtlas.totalQuads == 0) return; cc.nodeDrawSetup(this); cc.glBlendFuncForParticle(this._blendFunc.src, this._blendFunc.dst); - this.textureAtlas.drawQuads(); + this.__textureAtlas.drawQuads(); //cc.PROFILER_STOP("CCParticleBatchNode - draw"); }, @@ -354,7 +354,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ * @return {cc.Texture2D|HTMLImageElement|HTMLCanvasElement} */ getTexture:function () { - return this.textureAtlas.texture; + return this.__textureAtlas.texture; }, /** @@ -362,7 +362,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ * @param {cc.Texture2D|HTMLImageElement|HTMLCanvasElement} texture */ setTexture:function (texture) { - this.textureAtlas.texture = texture; + this.__textureAtlas.texture = texture; // If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it var locBlendFunc = this._blendFunc; @@ -419,13 +419,13 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ var currentStack = cc.current_stack; currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(this._stackMatrix, currentStack.top); - currentStack.top = this._stackMatrix; + cc.kmMat4Assign(this.__stackMatrix, currentStack.top); + currentStack.top = this.__stackMatrix; this.transform(ctx); //this.draw(ctx); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); cc.kmGLPopMatrix(); }, @@ -441,10 +441,10 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ }, _increaseAtlasCapacityTo:function (quantity) { - cc.log("cocos2d: cc.ParticleBatchNode: resizing TextureAtlas capacity from [" + this.textureAtlas.getCapacity() + cc.log("cocos2d: cc.ParticleBatchNode: resizing TextureAtlas capacity from [" + this.__textureAtlas.getCapacity() + "] to [" + quantity + "]."); - if (!this.textureAtlas.resizeCapacity(quantity)) { + if (!this.__textureAtlas.resizeCapacity(quantity)) { // serious problems cc.log("cc.ParticleBatchNode._increaseAtlasCapacityTo() : WARNING: Not enough memory to resize the atlas"); } @@ -527,7 +527,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ child.tag = aTag; child._setLocalZOrder(z); child.parent = this; - if (this._running) { + if (this.__running) { child.onEnter(); child.onEnterTransitionDidFinish(); } @@ -535,7 +535,7 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ }, _updateBlendFunc:function () { - if (!this.textureAtlas.texture.hasPremultipliedAlpha()) { + if (!this.__textureAtlas.texture.hasPremultipliedAlpha()) { this._blendFunc.src = cc.SRC_ALPHA; this._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; } @@ -546,20 +546,20 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{ * @return {cc.TextureAtlas} */ getTextureAtlas:function () { - return this.textureAtlas; + return this.__textureAtlas; }, /** * set the texture atlas used for drawing the quads - * @param {cc.TextureAtlas} textureAtlas + * @param {cc.TextureAtlas} __textureAtlas */ - setTextureAtlas:function (textureAtlas) { - this.textureAtlas = textureAtlas; + setTextureAtlas:function (__textureAtlas) { + this.__textureAtlas = __textureAtlas; }, _initRendererCmd:function(){ if(cc._renderType === cc._RENDER_TYPE_WEBGL) - this._rendererCmd = new cc.ParticleBatchNodeRenderCmdWebGL(this); + this.__rendererCmd = new cc.ParticleBatchNodeRenderCmdWebGL(this); } }); diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index 6ce1edf970..9d03922c84 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -59,11 +59,11 @@ * @param {Number} [rotation=0] * @param {Number} [deltaRotation=0] * @param {Number} [timeToLive=0] - * @param {Number} [atlasIndex=0] + * @param {Number} [__atlasIndex=0] * @param {cc.Particle.ModeA} [modeA=] * @param {cc.Particle.ModeA} [modeB=] */ -cc.Particle = function (pos, startPos, color, deltaColor, size, deltaSize, rotation, deltaRotation, timeToLive, atlasIndex, modeA, modeB) { +cc.Particle = function (pos, startPos, color, deltaColor, size, deltaSize, rotation, deltaRotation, timeToLive, __atlasIndex, modeA, modeB) { this.pos = pos ? pos : cc.p(0,0); this.startPos = startPos ? startPos : cc.p(0,0); this.color = color ? color : {r:0, g: 0, b:0, a:255}; @@ -73,7 +73,7 @@ cc.Particle = function (pos, startPos, color, deltaColor, size, deltaSize, rotat this.rotation = rotation || 0; this.deltaRotation = deltaRotation || 0; this.timeToLive = timeToLive || 0; - this.atlasIndex = atlasIndex || 0; + this.__atlasIndex = __atlasIndex || 0; this.modeA = modeA ? modeA : new cc.Particle.ModeA(); this.modeB = modeB ? modeB : new cc.Particle.ModeB(); this.isChangeColor = false; @@ -164,7 +164,7 @@ cc.Particle.TemporaryPoints = [ * @property {cc.SpriteBatchNode} batchNode - Weak reference to the sprite batch node. * @property {Boolean} active - <@readonly> Indicate whether the particle system is activated. * @property {Number} shapeType - ShapeType of ParticleSystem : cc.ParticleSystem.BALL_SHAPE | cc.ParticleSystem.STAR_SHAPE. - * @property {Number} atlasIndex - Index of system in batch node array. + * @property {Number} __atlasIndex - Index of system in batch node array. * @property {Number} particleCount - Current quantity of particles that are being simulated. * @property {Number} duration - How many seconds the emitter wil run. -1 means 'forever' * @property {cc.Point} sourcePos - Source position of the emitter. @@ -223,7 +223,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ modeA: null, //! Mode B: circular movement (gravity, radial accel and tangential accel don't are not used in this mode) modeB: null, - _className:"ParticleSystem", + __className:"ParticleSystem", //private POINTZERO for ParticleSystem _pointZeroForParticle: cc.p(0, 0), @@ -240,7 +240,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ _particleIdx: 0, _batchNode: null, - atlasIndex: 0, + __atlasIndex: 0, //true if scaled or rotated _transformSystemDirty: false, @@ -291,7 +291,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ _buffersVBO:null, _pointRect:null, - _textureLoaded: null, + __textureLoaded: null, _quadsArrayBuffer:null, /** @@ -325,7 +325,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ this._emitCounter = 0; this._particleIdx = 0; this._batchNode = null; - this.atlasIndex = 0; + this.__atlasIndex = 0; this._transformSystemDirty = false; this._allocatedParticles = 0; @@ -358,7 +358,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ this._quads = []; this._indices = []; this._pointRect = cc.rect(0, 0, 0, 0); - this._textureLoaded = true; + this.__textureLoaded = true; if (cc._renderType === cc._RENDER_TYPE_WEBGL) { this._quadsArrayBuffer = null; @@ -375,9 +375,9 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ _initRendererCmd: function(){ if(cc._renderType === cc._RENDER_TYPE_CANVAS) - this._rendererCmd = new cc.ParticleRenderCmdCanvas(this); + this.__rendererCmd = new cc.ParticleRenderCmdCanvas(this); else - this._rendererCmd = new cc.ParticleRenderCmdWebGL(this); + this.__rendererCmd = new cc.ParticleRenderCmdWebGL(this); }, /** @@ -445,9 +445,9 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ var quads; var start = 0, end = 0; if (this._batchNode) { - quads = this._batchNode.textureAtlas.quads; - start = this.atlasIndex; - end = this.atlasIndex + this._totalParticles; + quads = this._batchNode.__textureAtlas.quads; + start = this.__atlasIndex; + end = this.__atlasIndex + this._totalParticles; } else { quads = this._quads; start = 0; @@ -495,7 +495,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ if (batchNode) { var locParticles = this._particles; for (var i = 0; i < this._totalParticles; i++) - locParticles[i].atlasIndex = i; + locParticles[i].__atlasIndex = i; } // NEW: is self render ? @@ -510,7 +510,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ } else if (!oldBatch) { // OLD: was it self render cleanup ? // copy current state to batch - this._batchNode.textureAtlas._copyQuadsToTextureAtlas(this._quads, this.atlasIndex); + this._batchNode.__textureAtlas._copyQuadsToTextureAtlas(this._quads, this.__atlasIndex); //delete buffer cc._renderContext.deleteBuffer(this._buffersVBO[1]); //where is re-bindBuffer code? @@ -526,15 +526,15 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ * @return {Number} */ getAtlasIndex:function () { - return this.atlasIndex; + return this.__atlasIndex; }, /** * set index of system in batch node array - * @param {Number} atlasIndex + * @param {Number} __atlasIndex */ - setAtlasIndex:function (atlasIndex) { - this.atlasIndex = atlasIndex; + setAtlasIndex:function (__atlasIndex) { + this.__atlasIndex = __atlasIndex; }, /** @@ -551,8 +551,8 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ */ setDrawMode:function (drawMode) { this.drawMode = drawMode; - if(this._rendererCmd) - this._rendererCmd._drawMode = drawMode; + if(this.__rendererCmd) + this.__rendererCmd._drawMode = drawMode; }, /** @@ -569,8 +569,8 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ */ setShapeType:function (shapeType) { this.shapeType = shapeType; - if(this._rendererCmd) - this._rendererCmd._shapeType = shapeType; + if(this.__rendererCmd) + this.__rendererCmd._shapeType = shapeType; }, /** @@ -1264,7 +1264,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ // Init particles if (this._batchNode) { for (var i = 0; i < tp; i++) - locParticles[i].atlasIndex = i; + locParticles[i].__atlasIndex = i; } this._quadsArrayBuffer = locQuadsArrayBuffer; @@ -1300,9 +1300,9 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ if(texture.isLoaded()){ this.setTextureWithRect(texture, cc.rect(0, 0, texture.width, texture.height)); } else { - this._textureLoaded = false; + this.__textureLoaded = false; texture.addEventListener("load", function(sender){ - this._textureLoaded = true; + this.__textureLoaded = true; this.setTextureWithRect(sender, cc.rect(0, 0, sender.width, sender.height)); }, this); } @@ -1683,7 +1683,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ if (this._batchNode) for (i = 0; i < this._totalParticles; i++) - locParticles[i].atlasIndex = i; + locParticles[i].__atlasIndex = i; // default, active this._isActive = true; @@ -1913,9 +1913,9 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ updateQuadWithParticle:function (particle, newPosition) { var quad = null; if (this._batchNode) { - var batchQuads = this._batchNode.textureAtlas.quads; - quad = batchQuads[this.atlasIndex + particle.atlasIndex]; - this._batchNode.textureAtlas.dirty = true; + var batchQuads = this._batchNode.__textureAtlas.quads; + quad = batchQuads[this.__atlasIndex + particle.__atlasIndex]; + this._batchNode.__textureAtlas.__dirty = true; } else quad = this._quads[this._particleIdx]; @@ -2186,7 +2186,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ ++this._particleIdx; } else { // life < 0 - var currentIndex = selParticle.atlasIndex; + var currentIndex = selParticle.__atlasIndex; if(this._particleIdx !== this.particleCount -1){ var deadParticle = locParticles[this._particleIdx]; locParticles[this._particleIdx] = locParticles[this.particleCount -1]; @@ -2194,16 +2194,16 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ } if (this._batchNode) { //disable the switched particle - this._batchNode.disableParticle(this.atlasIndex + currentIndex); + this._batchNode.disableParticle(this.__atlasIndex + currentIndex); //switch indexes - locParticles[this.particleCount - 1].atlasIndex = currentIndex; + locParticles[this.particleCount - 1].__atlasIndex = currentIndex; } --this.particleCount; if (this.particleCount == 0 && this.autoRemoveOnFinish) { this.unscheduleUpdate(); - this._parent.removeChild(this, true); + this.__parent.removeChild(this, true); return; } } @@ -2405,7 +2405,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{ * @override */ draw:function (ctx) { - if(!this._textureLoaded || this._batchNode) // draw should not be called when added to a particleBatchNode + if(!this.__textureLoaded || this._batchNode) // draw should not be called when added to a particleBatchNode return; if (cc._renderType === cc._RENDER_TYPE_CANVAS) diff --git a/cocos2d/physics/CCPhysicsDebugNode.js b/cocos2d/physics/CCPhysicsDebugNode.js index 0ce8fd171f..57f1db7ad9 100644 --- a/cocos2d/physics/CCPhysicsDebugNode.js +++ b/cocos2d/physics/CCPhysicsDebugNode.js @@ -152,7 +152,7 @@ cc.CONSTRAINT_COLOR = cc.color(0, 255, 0, 128); */ cc.PhysicsDebugNode = cc.DrawNode.extend({ _space:null, - _className:"PhysicsDebugNode", + __className:"PhysicsDebugNode", /** * constructor of cc.PhysicsDebugNode @@ -165,9 +165,9 @@ cc.PhysicsDebugNode = cc.DrawNode.extend({ _initRendererCmd:function(){ if(cc._renderType === cc._RENDER_TYPE_CANVAS) - this._rendererCmd = new cc.PhysicsDebugNodeRenderCmdCanvas(this); + this.__rendererCmd = new cc.PhysicsDebugNodeRenderCmdCanvas(this); else - this._rendererCmd = new cc.PhysicsDebugNodeRenderCmdWebGL(this); + this.__rendererCmd = new cc.PhysicsDebugNodeRenderCmdWebGL(this); }, /** * get space diff --git a/cocos2d/physics/CCPhysicsSprite.js b/cocos2d/physics/CCPhysicsSprite.js index 34051a4496..9501bd8d34 100644 --- a/cocos2d/physics/CCPhysicsSprite.js +++ b/cocos2d/physics/CCPhysicsSprite.js @@ -369,7 +369,7 @@ * @return {Number} */ getRotation:function () { - return this._ignoreBodyRotation ? cc.radiansToDegrees(this._rotationRadiansX) : -cc.radiansToDegrees(this._body.a); + return this._ignoreBodyRotation ? cc.radiansToDegrees(this.__rotationRadiansX) : -cc.radiansToDegrees(this._body.a); }, /** @@ -385,7 +385,7 @@ } }, _syncRotation:function () { - if (this._rotationRadiansX != -this._body.a) { + if (this.__rotationRadiansX != -this._body.a) { cc.Sprite.prototype.setRotation.call(this, -cc.radiansToDegrees(this._body.a)); } }, @@ -402,11 +402,11 @@ */ getNodeToParentTransform:function () { var _t = this; - if(_t._usingNormalizedPosition && _t._parent){ //TODO need refactor - var conSize = _t._parent._contentSize; + if(_t._usingNormalizedPosition && _t.__parent){ //TODO need refactor + var conSize = _t.__parent._contentSize; _t._position.x = _t._normalizedPosition.x * conSize.width; _t._position.y = _t._normalizedPosition.y * conSize.height; - _t._normalizedPositionDirty = false; + _t.__normalizedPositionDirty = false; } if(cc._renderType === cc._RENDER_TYPE_CANVAS) @@ -435,16 +435,16 @@ } // Rot, Translate Matrix - this._transform = cc.affineTransformMake(c * locScaleX, s * locScaleX, + this.__transform = cc.affineTransformMake(c * locScaleX, s * locScaleX, -s * locScaleY, c * locScaleY, x, y); - return this._transform; + return this.__transform; }, _nodeToParentTransformForCanvas: function () { - if (this.dirty) { - var t = this._transform;// quick reference + if (this.__dirty) { + var t = this.__transform;// quick reference // base position var locBody = this._body, locScaleX = this._scaleX, locScaleY = this._scaleY, locAnchorPIP = this._anchorPointInPoints; t.tx = locBody.p.x; @@ -480,9 +480,9 @@ t.tx += locAnchorPIP.x; t.ty += locAnchorPIP.y; } - this._transformDirty = false; + this.__transformDirty = false; } - return this._transform; + return this.__transform; }, /** @@ -503,15 +503,15 @@ } }; cc.PhysicsSprite = cc.Sprite.extend(chipmunkAPI); - cc.PhysicsSprite._className = "PhysicsSprite"; + cc.PhysicsSprite.__className = "PhysicsSprite"; var _p = cc.PhysicsSprite.prototype; // Extended properties /** @expose */ _p.body; cc.defineGetterSetter(_p, "body", _p.getBody, _p.setBody); /** @expose */ - _p.dirty; - cc.defineGetterSetter(_p, "dirty", _p.isDirty, _p.setDirty); + _p.__dirty; + cc.defineGetterSetter(_p, "__dirty", _p.isDirty, _p.setDirty); /** diff --git a/cocos2d/progress-timer/CCProgressTimer.js b/cocos2d/progress-timer/CCProgressTimer.js index f980defc22..1a52de9623 100644 --- a/cocos2d/progress-timer/CCProgressTimer.js +++ b/cocos2d/progress-timer/CCProgressTimer.js @@ -55,7 +55,7 @@ cc.ProgressTimer = cc.Node.extend(/** @lends cc.ProgressTimer# */{ _midPoint:null, _barChangeRate:null, _reverseDirection:false, - _className:"ProgressTimer", + __className:"ProgressTimer", /** * Midpoint is used to modify the progress start position. @@ -187,7 +187,7 @@ cc.ProgressTimer = cc.Node.extend(/** @lends cc.ProgressTimer# */{ this._reverseDirection = false; this._sprite = null; - this._rendererCmd = new cc.ProgressRenderCmdCanvas(this); + this.__rendererCmd = new cc.ProgressRenderCmdCanvas(this); sprite && this._initWithSpriteForCanvas(sprite); }, @@ -206,7 +206,7 @@ cc.ProgressTimer = cc.Node.extend(/** @lends cc.ProgressTimer# */{ this._vertexData = null; this._vertexArrayBuffer = null; this._vertexDataDirty = false; - this._rendererCmd = new cc.ProgressRenderCmdWebGL(this); + this.__rendererCmd = new cc.ProgressRenderCmdWebGL(this); sprite && this._initWithSpriteForWebGL(sprite); }, @@ -278,7 +278,7 @@ cc.ProgressTimer = cc.Node.extend(/** @lends cc.ProgressTimer# */{ _setSpriteForCanvas:function (sprite) { if (this._sprite != sprite) { this._sprite = sprite; - this._rendererCmd._sprite = sprite; + this.__rendererCmd._sprite = sprite; this.width = this._sprite.width; this.height = this._sprite.height; } @@ -309,7 +309,7 @@ cc.ProgressTimer = cc.Node.extend(/** @lends cc.ProgressTimer# */{ _setTypeForCanvas:function (type) { if (type !== this._type){ this._type = type; - this._rendererCmd._type = type; + this.__rendererCmd._type = type; } }, @@ -733,7 +733,7 @@ cc.ProgressTimer = cc.Node.extend(/** @lends cc.ProgressTimer# */{ var locSprite = this._sprite; var sw = locSprite.width, sh = locSprite.height; var locMidPoint = this._midPoint; - var locCmd = this._rendererCmd; + var locCmd = this.__rendererCmd; if (this._type == cc.ProgressTimer.TYPE_RADIAL) { locCmd._radius = Math.round(Math.sqrt(sw * sw + sh * sh)); diff --git a/cocos2d/render-texture/CCRenderTexture.js b/cocos2d/render-texture/CCRenderTexture.js index 4697a56e6e..fc740901c7 100644 --- a/cocos2d/render-texture/CCRenderTexture.js +++ b/cocos2d/render-texture/CCRenderTexture.js @@ -114,7 +114,7 @@ cc.RenderTexture = cc.Node.extend(/** @lends cc.RenderTexture# */{ clearStencilVal:0, _clearColorStr:null, - _className:"RenderTexture", + __className:"RenderTexture", //for WebGL _beginWithClearCommand: null, @@ -159,7 +159,7 @@ cc.RenderTexture = cc.Node.extend(/** @lends cc.RenderTexture# */{ _initRendererCmd: function(){ //TODO need merge in some code if(cc._renderType === cc._RENDER_TYPE_WEBGL) - this._rendererCmd = new cc.RenderTextureRenderCmdWebGL(this); + this.__rendererCmd = new cc.RenderTextureRenderCmdWebGL(this); }, @@ -649,8 +649,8 @@ cc.RenderTexture = cc.Node.extend(/** @lends cc.RenderTexture# */{ this.sprite.visit(); //this.draw(ctx); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); //TODO GridNode /* if (locGrid && locGrid.isActive()) diff --git a/cocos2d/shaders/CCGLProgram.js b/cocos2d/shaders/CCGLProgram.js index 9a035b94cc..8995f64c63 100644 --- a/cocos2d/shaders/CCGLProgram.js +++ b/cocos2d/shaders/CCGLProgram.js @@ -578,12 +578,12 @@ cc.GLProgram = cc.Class.extend(/** @lends cc.GLProgram# */{ var matrixMVP = new cc.kmMat4(); cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, matrixP); - //cc.kmGLGetMatrix(cc.KM_GL_MODELVIEW, node._stackMatrix); + //cc.kmGLGetMatrix(cc.KM_GL_MODELVIEW, node.__stackMatrix); - cc.kmMat4Multiply(matrixMVP, matrixP, node._stackMatrix); + cc.kmMat4Multiply(matrixMVP, matrixP, node.__stackMatrix); this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX], matrixP.mat, 1); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVMATRIX], node._stackMatrix.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVMATRIX], node.__stackMatrix.mat, 1); this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVPMATRIX], matrixMVP.mat, 1); if (this._usesTime) { diff --git a/cocos2d/shape-nodes/CCDrawNode.js b/cocos2d/shape-nodes/CCDrawNode.js index 17d2f22ef3..971c07b801 100644 --- a/cocos2d/shape-nodes/CCDrawNode.js +++ b/cocos2d/shape-nodes/CCDrawNode.js @@ -93,7 +93,7 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNode# */{ _blendFunc: null, _lineWidth: 1, _drawColor: null, - _className:"DrawNodeCanvas", + __className:"DrawNodeCanvas", /** *

The cc.DrawNodeCanvas's constructor.
@@ -102,7 +102,7 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNode# */{ */ ctor: function () { cc.Node.prototype.ctor.call(this); - var locCmd = this._rendererCmd; + var locCmd = this.__rendererCmd; locCmd._buffer = this._buffer = []; locCmd._drawColor = this._drawColor = cc.color(255, 255, 255, 255); locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); @@ -111,7 +111,7 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNode# */{ }, _initRendererCmd: function(){ - this._rendererCmd = new cc.DrawNodeRenderCmdCanvas(this); + this.__rendererCmd = new cc.DrawNodeRenderCmdCanvas(this); }, // ----common function start ---- @@ -591,7 +591,7 @@ cc.DrawNodeWebGL = cc.Node.extend({ _blendFunc:null, _dirty:false, - _className:"DrawNodeWebGL", + __className:"DrawNodeWebGL", // ----common function start ---- getBlendFunc:function () { @@ -619,7 +619,7 @@ cc.DrawNodeWebGL = cc.Node.extend({ }, _initRendererCmd: function(){ - this._rendererCmd = new cc.DrawNodeRenderCmdWebGL(this); + this.__rendererCmd = new cc.DrawNodeRenderCmdWebGL(this); }, init:function () { diff --git a/cocos2d/text-input/CCTextFieldTTF.js b/cocos2d/text-input/CCTextFieldTTF.js index e9649f5ad7..49e51c86fb 100644 --- a/cocos2d/text-input/CCTextFieldTTF.js +++ b/cocos2d/text-input/CCTextFieldTTF.js @@ -112,7 +112,7 @@ cc.TextFieldTTF = cc.LabelTTF.extend(/** @lends cc.TextFieldTTF# */{ _inputText:"", _placeHolder:"", _charCount:0, - _className:"TextFieldTTF", + __className:"TextFieldTTF", /** * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
diff --git a/cocos2d/tilemap/CCTMXLayer.js b/cocos2d/tilemap/CCTMXLayer.js index 75bcb27712..ddb4a35cc7 100644 --- a/cocos2d/tilemap/CCTMXLayer.js +++ b/cocos2d/tilemap/CCTMXLayer.js @@ -81,7 +81,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ _cacheCanvas:null, _cacheContext:null, _cacheTexture:null, - _className:"TMXLayer", + __className:"TMXLayer", /** * Creates a cc.TMXLayer with an tile set info, a layer info and a map info
@@ -111,7 +111,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ this.width = locCanvas.width; this.height = locCanvas.height; // This class uses cache, so its default cachedParent should be himself - this._cachedParent = this; + this.__cachedParent = this; } if(mapInfo !== undefined) this.initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo); @@ -119,9 +119,9 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ _initRendererCmd: function(){ if(cc._renderType === cc._RENDER_TYPE_CANVAS) - this._rendererCmd = new cc.TMXLayerRenderCmdCanvas(this); + this.__rendererCmd = new cc.TMXLayerRenderCmdCanvas(this); else - this._rendererCmd = new cc.TMXLayerRenderCmdWebGL(this); + this.__rendererCmd = new cc.TMXLayerRenderCmdWebGL(this); }, /** @@ -202,12 +202,12 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ if (!this._visible || !locChildren || locChildren.length === 0) return; - if( this._parent) - this._curLevel = this._parent._curLevel + 1; + if( this.__parent) + this.__curLevel = this.__parent.__curLevel + 1; this.transform(); - if (this._cacheDirty) { + if (this.__cacheDirty) { var locCacheContext = this._cacheContext, locCanvas = this._cacheCanvas, locView = cc.view, instanceID = this.__instanceId, renderer = cc.renderer; //begin cache @@ -217,32 +217,32 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ for (i = 0, len = locChildren.length; i < len; i++) { if (locChildren[i]){ locChildren[i].visit(); - locChildren[i]._cacheDirty = false; + locChildren[i].__cacheDirty = false; } } //copy cached render cmd array to TMXLayer renderer - this._rendererCmd._copyRendererCmds(renderer._cacheToCanvasCmds[instanceID]); + this.__rendererCmd._copyRendererCmds(renderer._cacheToCanvasCmds[instanceID]); locCacheContext.save(); locCacheContext.clearRect(0, 0, locCanvas.width, -locCanvas.height); - var t = cc.affineTransformInvert(this._transformWorld); + var t = cc.affineTransformInvert(this.__transformWorld); locCacheContext.transform(t.a, t.c, t.b, t.d, t.tx * locView.getScaleX(), -t.ty * locView.getScaleY()); //draw to cache canvas renderer._renderingToCacheCanvas(locCacheContext, instanceID); locCacheContext.restore(); - this._cacheDirty = false; + this.__cacheDirty = false; } - cc.renderer.pushRenderCommand(this._rendererCmd); + cc.renderer.pushRenderCommand(this.__rendererCmd); }, - //set the cache dirty flag for canvas + //set the cache __dirty flag for canvas _setNodeDirtyForCache: function () { - this._cacheDirty = true; + this.__cacheDirty = true; if(cc.renderer._transformNodePool.indexOf(this) === -1) cc.renderer.pushDirtyNode(this); - this._renderCmdDiry = true; + this.__renderCmdDirty = true; }, /** @@ -658,12 +658,12 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ if (cc._renderType === cc._RENDER_TYPE_CANVAS) this._setNodeDirtyForCache(); var z = 0 | (pos.x + pos.y * this._layerSize.width); - var atlasIndex = this._atlasIndexForExistantZ(z); + var __atlasIndex = this._atlasIndexForExistantZ(z); // remove tile from GID map this.tiles[z] = 0; // remove tile from atlas position array - this._atlasIndexArray.splice(atlasIndex, 1); + this._atlasIndexArray.splice(__atlasIndex, 1); // remove it from sprites and/or texture atlas var sprite = this.getChildByTag(z); @@ -672,7 +672,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ cc.SpriteBatchNode.prototype.removeChild.call(this, sprite, true); //this.removeChild(sprite, true); else { if(cc._renderType === cc._RENDER_TYPE_WEBGL) - this.textureAtlas.removeQuadAtIndex(atlasIndex); + this.__textureAtlas.removeQuadAtIndex(__atlasIndex); // update possible children if (this._children) { @@ -680,9 +680,9 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ for (var i = 0, len = locChildren.length; i < len; i++) { var child = locChildren[i]; if (child) { - var ai = child.atlasIndex; - if (ai >= atlasIndex) - child.atlasIndex = ai - 1; + var ai = child.__atlasIndex; + if (ai >= __atlasIndex) + child.__atlasIndex = ai - 1; } } } @@ -733,14 +733,14 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { this.tileset.imageSize = this._originalTexture.getContentSizeInPixels(); } else { - this.tileset.imageSize = this.textureAtlas.texture.getContentSizeInPixels(); + this.tileset.imageSize = this.__textureAtlas.texture.getContentSizeInPixels(); // By default all the tiles are aliased // pros: // - easier to render // cons: // - difficult to scale / rotate / etc. - this.textureAtlas.texture.setAliasTexParameters(); + this.__textureAtlas.texture.setAliasTexParameters(); } // Parse cocos2d properties @@ -797,10 +797,10 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ if (cc._renderType === cc._RENDER_TYPE_CANVAS) this._setNodeDirtyForCache(); - var atlasIndex = sprite.atlasIndex; - var zz = this._atlasIndexArray[atlasIndex]; + var __atlasIndex = sprite.__atlasIndex; + var zz = this._atlasIndexArray[__atlasIndex]; this.tiles[zz] = 0; - this._atlasIndexArray.splice(atlasIndex, 1); + this._atlasIndexArray.splice(__atlasIndex, 1); cc.SpriteBatchNode.prototype.removeChild.call(this, sprite, cleanup); cc.renderer.childrenOrderDirty = true; }, @@ -898,9 +898,9 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ for (var i = 0, len = locChildren.length; i < len; i++) { var child = locChildren[i]; if (child) { - var ai = child.atlasIndex; + var ai = child.__atlasIndex; if (ai >= indexForZ) - child.atlasIndex = ai + 1; + child.__atlasIndex = ai + 1; } } } @@ -919,8 +919,8 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ this._setupTileSprite(tile, pos, gid); // get atlas index - tile.atlasIndex = this._atlasIndexForExistantZ(z); - tile.dirty = true; + tile.__atlasIndex = this._atlasIndexForExistantZ(z); + tile.__dirty = true; tile.updateTransform(); this.tiles[z] = gid; @@ -1023,7 +1023,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ this._reusedTile.initWithTexture(this._textureForCanvas, rect, false); this._reusedTile.batchNode = this; this._reusedTile.parent = this; - this._reusedTile._cachedParent = this; + this._reusedTile.__cachedParent = this; } return this._reusedTile; }, diff --git a/cocos2d/tilemap/CCTMXTiledMap.js b/cocos2d/tilemap/CCTMXTiledMap.js index 2344cdb9fc..e3057817dd 100644 --- a/cocos2d/tilemap/CCTMXTiledMap.js +++ b/cocos2d/tilemap/CCTMXTiledMap.js @@ -131,7 +131,7 @@ cc.TMXTiledMap = cc.Node.extend(/** @lends cc.TMXTiledMap# */{ _tileSize: null, //tile properties _tileProperties: null, - _className: "TMXTiledMap", + __className: "TMXTiledMap", /** * Creates a TMX Tiled Map with a TMX file or content string.
diff --git a/cocos2d/tilemap/CCTileMapAtlas.js b/cocos2d/tilemap/CCTileMapAtlas.js index 40d4f562e1..9631b43939 100644 --- a/cocos2d/tilemap/CCTileMapAtlas.js +++ b/cocos2d/tilemap/CCTileMapAtlas.js @@ -52,7 +52,7 @@ cc.TileMapAtlas = cc.AtlasNode.extend(/** @lends cc.TileMapAtlas# */{ _itemsToRender:0, //x,y to altas dictionary _posToAtlasIndex:null, - _className:"TileMapAtlas", + __className:"TileMapAtlas", /** *

Creates a cc.TileMap with a tile file (atlas) with a map file and the width and height of each tile in points.
@@ -199,7 +199,7 @@ cc.TileMapAtlas = cc.AtlasNode.extend(/** @lends cc.TileMapAtlas# */{ * @private */ _updateAtlasValueAt:function (pos, value, index) { - var locTextureAtlas = this.textureAtlas; + var locTextureAtlas = this.__textureAtlas; if(index < 0 && index >= locTextureAtlas.getCapacity()) throw "cc.TileMapAtlas._updateAtlasValueAt(): Invalid index"; var quad = locTextureAtlas.quads[index]; @@ -251,14 +251,14 @@ cc.TileMapAtlas = cc.AtlasNode.extend(/** @lends cc.TileMapAtlas# */{ quad.tr.vertices.y = (y * locItemHeight + locItemHeight); quad.tr.vertices.z = 0.0; - var locColor = this._displayedColor; - var color = {r: locColor.r, g: locColor.g, b: locColor.b, a: this._displayedOpacity}; + var locColor = this.__displayedColor; + var color = {r: locColor.r, g: locColor.g, b: locColor.b, a: this.__displayedOpacity}; quad.tr.colors = color; quad.tl.colors = color; quad.br.colors = color; quad.bl.colors = color; - locTextureAtlas.dirty = true; + locTextureAtlas.__dirty = true; var totalQuads = locTextureAtlas.totalQuads; if (index + 1 > totalQuads) locTextureAtlas.increaseTotalQuadsWith(index + 1 - totalQuads); diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js index 07a5bd7e8e..0af7e60930 100644 --- a/cocos2d/transitions/CCTransition.js +++ b/cocos2d/transitions/CCTransition.js @@ -69,7 +69,7 @@ cc.TransitionScene = cc.Scene.extend(/** @lends cc.TransitionScene# */{ _duration:null, _isInSceneOnTop:false, _isSendCleanupToScene:false, - _className:"TransitionScene", + __className:"TransitionScene", /** * creates a base transition with duration and incoming scene diff --git a/cocos2d/transitions/CCTransitionPageTurn.js b/cocos2d/transitions/CCTransitionPageTurn.js index 6b71fd848b..c92c390ebf 100644 --- a/cocos2d/transitions/CCTransitionPageTurn.js +++ b/cocos2d/transitions/CCTransitionPageTurn.js @@ -58,7 +58,7 @@ cc.TransitionPageTurn = cc.TransitionScene.extend(/** @lends cc.TransitionPageTu */ _back:true, _gridProxy: null, - _className:"TransitionPageTurn", + __className:"TransitionPageTurn", /** * Creates a base transition with duration and incoming scene.
diff --git a/cocos2d/transitions/CCTransitionProgress.js b/cocos2d/transitions/CCTransitionProgress.js index ab128091c8..0b53c4997b 100644 --- a/cocos2d/transitions/CCTransitionProgress.js +++ b/cocos2d/transitions/CCTransitionProgress.js @@ -44,7 +44,7 @@ cc.TransitionProgress = cc.TransitionScene.extend(/** @lends cc.TransitionProgre _to:0, _from:0, _sceneToBeModified:null, - _className:"TransitionProgress", + __className:"TransitionProgress", /** * @param {Number} t time diff --git a/extensions/ccpool/CCPool.js b/extensions/ccpool/CCPool.js index 4121439db4..d44bc48ea4 100644 --- a/extensions/ccpool/CCPool.js +++ b/extensions/ccpool/CCPool.js @@ -51,7 +51,7 @@ cc.pool = /** @lends cc.pool# */{ }, _autoRelease: function (obj) { - var running = obj._running === undefined ? false : !obj._running; + var running = obj.__running === undefined ? false : !obj.__running; cc.director.getScheduler().scheduleCallbackForTarget(obj, this._releaseCB, 0, 0, 0, running) }, diff --git a/extensions/ccui/base-classes/CCProtectedNode.js b/extensions/ccui/base-classes/CCProtectedNode.js index a342ebc0ef..e178885d44 100644 --- a/extensions/ccui/base-classes/CCProtectedNode.js +++ b/extensions/ccui/base-classes/CCProtectedNode.js @@ -68,10 +68,10 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ child.setOrderOfArrival(cc.s_globalOrderOfArrival); //TODO USE PHYSICS - if(this._running){ + if(this.__running){ child.onEnter(); // prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter - if(this._isTransitionFinished) + if(this.__isTransitionFinished) child.onEnterTransitionDidFinish(); } if(this._cascadeColorEnabled) @@ -107,7 +107,7 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ return; var idx = locChildren.indexOf(child); if(idx > -1){ - if(this._running){ + if(this.__running){ child.onExitTransitionDidStart(); child.onExit(); } @@ -166,7 +166,7 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ // IMPORTANT: // -1st do onExit // -2nd cleanup - if(this._running){ + if(this.__running){ child.onExitTransitionDidStart(); child.onExit(); } @@ -269,15 +269,15 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ } // _t.draw(context); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); for (; i < childLen; i++) children[i] && children[i].visit(context); for (; j < pLen; j++) locProtectedChildren[j] && locProtectedChildren[j].visit(context); - this._cacheDirty = false; + this.__cacheDirty = false; // context.restore(); }, @@ -290,8 +290,8 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ //optimize performance for javascript currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(_t._stackMatrix, currentStack.top); - currentStack.top = _t._stackMatrix; + cc.kmMat4Assign(_t.__stackMatrix, currentStack.top); + currentStack.top = _t.__stackMatrix; var locGrid = _t.grid; if (locGrid && locGrid._active) @@ -318,8 +318,8 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ break; } // _t.draw(context); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); // draw children zOrder >= 0 for (; i < childLen; i++) { @@ -403,10 +403,10 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ * @override */ updateDisplayedOpacity: function(parentOpacity){ - this._displayedOpacity = this._realOpacity * parentOpacity/255.0; + this.__displayedOpacity = this._realOpacity * parentOpacity/255.0; this._updateColor(); - var i,len, locChildren, _opacity = this._displayedOpacity; + var i,len, locChildren, _opacity = this.__displayedOpacity; if (this._cascadeOpacityEnabled){ locChildren = this._children; for(i = 0, len = locChildren.length;i < len; i++){ @@ -427,7 +427,7 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ * @override */ updateDisplayedColor: function(parentColor){ - var displayedColor = this._displayedColor, realColor = this._realColor; + var displayedColor = this.__displayedColor, realColor = this._realColor; displayedColor.r = realColor.r * parentColor.r/255.0; displayedColor.g = realColor.g * parentColor.g/255.0; displayedColor.b = realColor.b * parentColor.b/255.0; @@ -450,7 +450,7 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ }, _disableCascadeOpacity: function () { - this._displayedOpacity = this._realOpacity; + this.__displayedOpacity = this._realOpacity; var selChildren = this._children, i, item; for (i = 0; i < selChildren.length; i++) { @@ -482,16 +482,16 @@ cc.ProtectedNode = cc.Node.extend(/** @lends cc.ProtectedNode# */{ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { cc.ProtectedNode.prototype.visit = cc.ProtectedNode.prototype._visitForCanvas; cc.ProtectedNode.prototype._transformForRenderer = function () { - var t = this.nodeToParentTransform(), worldT = this._transformWorld; - if(this._parent){ - var pt = this._parent._transformWorld; + var t = this.nodeToParentTransform(), worldT = this.__transformWorld; + if(this.__parent){ + var pt = this.__parent.__transformWorld; //worldT = cc.AffineTransformConcat(t, pt); worldT.a = t.a * pt.a + t.b * pt.c; //a worldT.b = t.a * pt.b + t.b * pt.d; //b worldT.c = t.c * pt.a + t.d * pt.c; //c worldT.d = t.c * pt.b + t.d * pt.d; //d if(this._skewX || this._skewY){ - var plt = this._parent._transform; + var plt = this.__parent.__transform; var xOffset = -(plt.b + plt.c) * t.ty ; var yOffset = -(plt.b + plt.c) * t.tx; worldT.tx = (t.tx * pt.a + t.ty * pt.c + pt.tx + xOffset); //tx @@ -508,7 +508,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { worldT.tx = t.tx; worldT.ty = t.ty; } - this._renderCmdDiry = false; + this.__renderCmdDirty = false; var i, len, locChildren = this._children; for(i = 0, len = locChildren.length; i< len; i++){ locChildren[i]._transformForRenderer(); @@ -520,8 +520,8 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { }else{ cc.ProtectedNode.prototype.visit = cc.ProtectedNode.prototype._visitForWebGL; cc.ProtectedNode.prototype._transformForRenderer = function () { - var t4x4 = this._transform4x4, stackMatrix = this._stackMatrix, - parentMatrix = this._parent ? this._parent._stackMatrix : cc.current_stack.top; + var t4x4 = this._transform4x4, stackMatrix = this.__stackMatrix, + parentMatrix = this.__parent ? this.__parent.__stackMatrix : cc.current_stack.top; // Convert 3x3 into 4x4 matrix var trans = this.nodeToParentTransform(); @@ -539,7 +539,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { //optimize performance for Javascript cc.kmMat4Multiply(stackMatrix, parentMatrix, t4x4); - this._renderCmdDiry = false; + this.__renderCmdDirty = false; var i, len, locChildren = this._children; for(i = 0, len = locChildren.length; i< len; i++){ locChildren[i]._transformForRenderer(); diff --git a/extensions/ccui/base-classes/UIScale9Sprite.js b/extensions/ccui/base-classes/UIScale9Sprite.js index 32aede1ac6..1d0a0619a1 100644 --- a/extensions/ccui/base-classes/UIScale9Sprite.js +++ b/extensions/ccui/base-classes/UIScale9Sprite.js @@ -88,15 +88,15 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{ _spritesGenerated: false, _spriteFrameRotated: false, - _textureLoaded:false, - _className:"Scale9Sprite", + __textureLoaded:false, + __className:"Scale9Sprite", /** * return texture is loaded * @returns {boolean} */ textureLoaded:function(){ - return this._textureLoaded; + return this.__textureLoaded; }, /** @@ -571,7 +571,7 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{ } var locLoaded = texture.isLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ texture.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. @@ -604,7 +604,7 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{ capInsets = capInsets || cc.rect(0, 0, 0, 0); var locLoaded = spriteFrame.textureLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ spriteFrame.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. @@ -708,7 +708,7 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{ var tmpTexture = batchNode.getTexture(); var locLoaded = tmpTexture.isLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ tmpTexture.addEventListener("load", function(sender){ this._positionsAreDirty = true; @@ -1004,7 +1004,7 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{ var batchNode = new cc.SpriteBatchNode(spriteFrame.getTexture(), 9); // the texture is rotated on Canvas render mode, so isRotated always is false. var locLoaded = spriteFrame.textureLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ spriteFrame.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. diff --git a/extensions/ccui/base-classes/UIWidget.js b/extensions/ccui/base-classes/UIWidget.js index 4edac18fbe..b1b71f30b4 100644 --- a/extensions/ccui/base-classes/UIWidget.js +++ b/extensions/ccui/base-classes/UIWidget.js @@ -82,7 +82,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ _hit: false, _nodes: null, _touchListener: null, - _className: "Widget", + __className: "Widget", _flippedX: false, _flippedY: false, _opacity: 255, @@ -252,7 +252,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ _cleanupWidget: function(){ //clean up _touchListener - this._eventDispatcher.removeEventListener(this._touchListener); + this.__eventDispatcher.removeEventListener(this._touchListener); //cleanup focused widget and focus navigation controller if (ccui.Widget._focusedWidget == this) @@ -294,9 +294,9 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ if (this._ignoreSize){ this._contentSize = this.getVirtualRendererSize(); } - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); - var pSize = widgetParent ? widgetParent.getContentSize() : this._parent.getContentSize(); + var pSize = widgetParent ? widgetParent.getContentSize() : this.__parent.getContentSize(); this._sizePercent.x = (pSize.width > 0.0) ? locWidth / pSize.width : 0.0; this._sizePercent.y = (pSize.height > 0.0) ? locHeight / pSize.height : 0.0; } @@ -309,9 +309,9 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ if(this._ignoreSize) this._contentSize = this.getVirtualRendererSize(); - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); - var locWidth = widgetParent ? widgetParent.width : this._parent.width; + var locWidth = widgetParent ? widgetParent.width : this.__parent.width; this._sizePercent.x = locWidth > 0 ? this._customSize.width / locWidth : 0; } this._onSizeChanged(); @@ -322,9 +322,9 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ if(this._ignoreSize) this._contentSize = this.getVirtualRendererSize(); - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); - var locH = widgetParent ? widgetParent.height : this._parent.height; + var locH = widgetParent ? widgetParent.height : this.__parent.height; this._sizePercent.y = locH > 0 ? this._customSize.height / locH : 0; } this._onSizeChanged(); @@ -339,14 +339,14 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ this._sizePercent.x = percent.x; this._sizePercent.y = percent.y; var width = this._customSize.width, height = this._customSize.height; - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) { width = widgetParent.width * percent.x; height = widgetParent.height * percent.y; } else { - width = this._parent.width * percent.x; - height = this._parent.height * percent.y; + width = this.__parent.width * percent.x; + height = this.__parent.height * percent.y; } } if (this._ignoreSize) @@ -361,9 +361,9 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ _setWidthPercent: function (percent) { this._sizePercent.x = percent; var width = this._customSize.width; - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); - width = (widgetParent ? widgetParent.width : this._parent.width) * percent; + width = (widgetParent ? widgetParent.width : this.__parent.width) * percent; } if (this._ignoreSize) this._setWidth(this.getVirtualRendererSize().width); @@ -374,9 +374,9 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ _setHeightPercent: function (percent) { this._sizePercent.y = percent; var height = this._customSize.height; - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); - height = (widgetParent ? widgetParent.height : this._parent.height) * percent; + height = (widgetParent ? widgetParent.height : this.__parent.height) * percent; } if (this._ignoreSize) this._setHeight(this.getVirtualRendererSize().height); @@ -395,7 +395,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ if(widgetParent) parentSize = widgetParent.getLayoutSize(); else - parentSize = this._parent.getContentSize(); + parentSize = this.__parent.getContentSize(); } switch (this._sizeType) { @@ -436,9 +436,9 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ default: break; } - if(this._parent instanceof ccui.ImageView){ - var renderer = this._parent._imageRenderer; - if(renderer && !renderer._textureLoaded) + if(this.__parent instanceof ccui.ImageView){ + var renderer = this.__parent._imageRenderer; + if(renderer && !renderer.__textureLoaded) return; } this.setPosition(absPos); @@ -1033,7 +1033,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ * @param {Number} [posY] */ setPosition: function (pos, posY) { - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) { var pSize = widgetParent.getContentSize(); @@ -1057,7 +1057,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ }, setPositionX: function (x) { - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) { var pw = widgetParent.width; @@ -1071,7 +1071,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ cc.Node.prototype.setPositionX.call(this, x); }, setPositionY: function (y) { - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) { var ph = widgetParent.height; @@ -1091,7 +1091,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ */ setPositionPercent: function (percent) { this._positionPercent = percent; - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) { var parentSize = widgetParent.getSize(); @@ -1101,7 +1101,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ }, _setXPercent: function (percent) { this._positionPercent.x = percent; - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) this.setPositionX(widgetParent.width * percent); @@ -1109,7 +1109,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ }, _setYPercent: function (percent) { this._positionPercent.y = percent; - if (this._running) { + if (this.__running) { var widgetParent = this.getWidgetParent(); if (widgetParent) this.setPositionY(widgetParent.height * percent); @@ -1581,13 +1581,13 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ _findLayout: function(){ cc.renderer.childrenOrderDirty = true; - var layout = this._parent; + var layout = this.__parent; while(layout){ if(layout._doLayout){ layout._doLayoutDirty = true; break; }else - layout = layout._parent; + layout = layout.__parent; } }, diff --git a/extensions/ccui/layouts/UILayout.js b/extensions/ccui/layouts/UILayout.js index c94a181473..0bc47e72f9 100644 --- a/extensions/ccui/layouts/UILayout.js +++ b/extensions/ccui/layouts/UILayout.js @@ -58,7 +58,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ _scissorRectDirty: false, _clippingRect: null, _clippingParent: null, - _className: "Layout", + __className: "Layout", _backGroundImageColor: null, _finalPositionX: 0, _finalPositionY: 0, @@ -416,8 +416,8 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ //optimize performance for javascript var currentStack = cc.current_stack; currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(this._stackMatrix, currentStack.top); - currentStack.top = this._stackMatrix; + cc.kmMat4Assign(this.__stackMatrix, currentStack.top); + currentStack.top = this.__stackMatrix; this.transform(); this._clippingStencil.visit(); @@ -447,8 +447,8 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ break; } //this.draw(); //draw self - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); for (; i < iLen; i++) locChildren[i].visit(); for (; j < jLen; j++) @@ -544,7 +544,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ context.save(); }else{ this.transform(); - var t = this._transformWorld; + var t = this.__transformWorld; context.save(); context.save(); context.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY); @@ -610,12 +610,12 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ if (able){ this._clippingStencil = new cc.DrawNode(); if(cc._renderType === cc._RENDER_TYPE_CANVAS) - this._clippingStencil._rendererCmd.rendering = this.__stencilDraw.bind(this); - if (this._running) + this._clippingStencil.__rendererCmd.rendering = this.__stencilDraw.bind(this); + if (this.__running) this._clippingStencil.onEnter(); this._setStencilClippingSize(this._contentSize); } else { - if (this._running && this._clippingStencil) + if (this.__running && this._clippingStencil) this._clippingStencil.onExit(); this._clippingStencil = null; } @@ -1813,7 +1813,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ if(cc._renderType === cc._RENDER_TYPE_WEBGL){ ccui.Widget.prototype._transformForRenderer.call(this, parentMatrix); if(this._clippingStencil) - this._clippingStencil._transformForRenderer(this._stackMatrix); + this._clippingStencil._transformForRenderer(this.__stackMatrix); }else{ ccui.ProtectedNode.prototype._transformForRenderer.call(this); } diff --git a/extensions/ccui/uiwidgets/UIButton.js b/extensions/ccui/uiwidgets/UIButton.js index b001f0d173..6dbb5627d9 100644 --- a/extensions/ccui/uiwidgets/UIButton.js +++ b/extensions/ccui/uiwidgets/UIButton.js @@ -73,7 +73,7 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{ _pressedTextureLoaded: false, _disabledTextureLoaded: false, - _className: "Button", + __className: "Button", _normalTextureAdaptDirty: true, _pressedTextureAdaptDirty: true, _disabledTextureAdaptDirty: true, diff --git a/extensions/ccui/uiwidgets/UICheckBox.js b/extensions/ccui/uiwidgets/UICheckBox.js index 441a5e66f1..3ec000c842 100644 --- a/extensions/ccui/uiwidgets/UICheckBox.js +++ b/extensions/ccui/uiwidgets/UICheckBox.js @@ -53,7 +53,7 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{ _frontCrossFileName: "", _backGroundDisabledFileName: "", _frontCrossDisabledFileName: "", - _className: "CheckBox", + __className: "CheckBox", _backGroundBoxRendererAdaptDirty:true, _backGroundSelectedBoxRendererAdaptDirty:true, diff --git a/extensions/ccui/uiwidgets/UIImageView.js b/extensions/ccui/uiwidgets/UIImageView.js index d1f3c005e5..2194e4700e 100644 --- a/extensions/ccui/uiwidgets/UIImageView.js +++ b/extensions/ccui/uiwidgets/UIImageView.js @@ -36,7 +36,7 @@ ccui.ImageView = ccui.Widget.extend(/** @lends ccui.ImageView# */{ _textureFile: "", _imageTexType: ccui.Widget.LOCAL_TEXTURE, _imageTextureSize: null, - _className:"ImageView", + __className:"ImageView", _imageRendererAdaptDirty: true, /** diff --git a/extensions/ccui/uiwidgets/UILoadingBar.js b/extensions/ccui/uiwidgets/UILoadingBar.js index bf7bc314f7..26562a28b8 100644 --- a/extensions/ccui/uiwidgets/UILoadingBar.js +++ b/extensions/ccui/uiwidgets/UILoadingBar.js @@ -43,7 +43,7 @@ ccui.LoadingBar = ccui.Widget.extend(/** @lends ccui.LoadingBar# */{ _capInsets: null, _textureFile: "", _isTextureLoaded: false, - _className: "LoadingBar", + __className: "LoadingBar", _barRendererAdaptDirty: true, /** diff --git a/extensions/ccui/uiwidgets/UISlider.js b/extensions/ccui/uiwidgets/UISlider.js index 0b7756a1a6..8be771543d 100644 --- a/extensions/ccui/uiwidgets/UISlider.js +++ b/extensions/ccui/uiwidgets/UISlider.js @@ -57,7 +57,7 @@ ccui.Slider = ccui.Widget.extend(/** @lends ccui.Slider# */{ _ballPTexType: ccui.Widget.LOCAL_TEXTURE, _ballDTexType: ccui.Widget.LOCAL_TEXTURE, _isTextureLoaded: false, - _className: "Slider", + __className: "Slider", _barRendererAdaptDirty: true, _progressBarRendererDirty: true, diff --git a/extensions/ccui/uiwidgets/UIText.js b/extensions/ccui/uiwidgets/UIText.js index 8e8f1c13bb..790fb894e9 100644 --- a/extensions/ccui/uiwidgets/UIText.js +++ b/extensions/ccui/uiwidgets/UIText.js @@ -51,7 +51,7 @@ ccui.Text = ccui.Widget.extend(/** @lends ccui.Text# */{ _textAreaSize: null, _textVerticalAlignment: 0, _textHorizontalAlignment: 0, - _className: "Text", + __className: "Text", _type: null, _labelRendererAdaptDirty: true, diff --git a/extensions/ccui/uiwidgets/UITextAtlas.js b/extensions/ccui/uiwidgets/UITextAtlas.js index f60254614b..ac8383ecdb 100644 --- a/extensions/ccui/uiwidgets/UITextAtlas.js +++ b/extensions/ccui/uiwidgets/UITextAtlas.js @@ -37,7 +37,7 @@ ccui.TextAtlas = ccui.Widget.extend(/** @lends ccui.TextAtlas# */{ _itemWidth: 0, _itemHeight: 0, _startCharMap: "", - _className: "TextAtlas", + __className: "TextAtlas", _labelAtlasRendererAdaptDirty: null, /** diff --git a/extensions/ccui/uiwidgets/UITextBMFont.js b/extensions/ccui/uiwidgets/UITextBMFont.js index 2354261b46..716063ed76 100644 --- a/extensions/ccui/uiwidgets/UITextBMFont.js +++ b/extensions/ccui/uiwidgets/UITextBMFont.js @@ -35,7 +35,7 @@ ccui.LabelBMFont = ccui.TextBMFont = ccui.Widget.extend(/** @lends ccui.TextBMFo _fntFileHasInit: false, _fntFileName: "", _stringValue: "", - _className: "TextBMFont", + __className: "TextBMFont", _labelBMFontRendererAdaptDirty: true, /** @@ -76,7 +76,7 @@ ccui.LabelBMFont = ccui.TextBMFont = ccui.Widget.extend(/** @lends ccui.TextBMFo _self._labelBMFontRenderer.initWithString(this._stringValue, fileName); var locRenderer = _self._labelBMFontRenderer; - if(!locRenderer._textureLoaded){ + if(!locRenderer.__textureLoaded){ locRenderer.addEventListener("load", function(){ _self.updateSizeAndPosition(); }); diff --git a/extensions/ccui/uiwidgets/UITextField.js b/extensions/ccui/uiwidgets/UITextField.js index 3dd3f96eb4..0e6014cd0e 100644 --- a/extensions/ccui/uiwidgets/UITextField.js +++ b/extensions/ccui/uiwidgets/UITextField.js @@ -36,7 +36,7 @@ ccui._TextFieldRenderer = cc.TextFieldTTF.extend({ _detachWithIME: false, _insertText: false, _deleteBackward: false, - _className: "_TextFieldRenderer", + __className: "_TextFieldRenderer", _textFieldRendererAdaptDirty: true, ctor: function () { diff --git a/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js b/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js index a10e68f337..e6897c2f82 100644 --- a/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js +++ b/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js @@ -53,7 +53,7 @@ ccui.PageView = ccui.Layout.extend(/** @lends ccui.PageView# */{ _childFocusCancelOffset: 0, _pageViewEventListener: null, _pageViewEventSelector: null, - _className:"PageView", + __className:"PageView", _customScrollThreshold: 0, _usingCustomScrollThreshold: false, diff --git a/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js b/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js index 2b3f6b221e..3696432a12 100644 --- a/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js +++ b/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js @@ -76,7 +76,7 @@ ccui.ScrollView = ccui.Layout.extend(/** @lends ccui.ScrollView# */{ _scrollViewEventListener: null, _scrollViewEventSelector: null, - _className: "ScrollView", + __className: "ScrollView", /** * Allocates and initializes a UIScrollView. @@ -1744,7 +1744,7 @@ ccui.ScrollView = ccui.Layout.extend(/** @lends ccui.ScrollView# */{ _transformForRenderer: function(parentMatrix){ ccui.Layout.prototype._transformForRenderer.call(this, parentMatrix); if(this._innerContainer && cc._renderType === cc._RENDER_TYPE_WEBGL) - this._innerContainer._transformForRenderer(this._stackMatrix); + this._innerContainer._transformForRenderer(this.__stackMatrix); } }); diff --git a/extensions/cocostudio/action/CCActionObject.js b/extensions/cocostudio/action/CCActionObject.js index 15e0c200d4..056202cf57 100644 --- a/extensions/cocostudio/action/CCActionObject.js +++ b/extensions/cocostudio/action/CCActionObject.js @@ -36,7 +36,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{ _playing: false, _unitTime: 0, _currentTime: 0, - _scheduler:null, + __scheduler:null, _callback: null, _fTotalTime: 0, @@ -52,7 +52,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{ this._unitTime = 0.1; this._currentTime = 0; this._fTotalTime = 0; - this._scheduler = cc.director.getScheduler(); + this.__scheduler = cc.director.getScheduler(); }, /** @@ -200,7 +200,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{ locActionNodeList[i].playAction(fun); } if (this._loop) - this._scheduler.scheduleCallbackForTarget(this, this.simulationActionUpdate, 0, cc.REPEAT_FOREVER, 0, false); + this.__scheduler.scheduleCallbackForTarget(this, this.simulationActionUpdate, 0, cc.REPEAT_FOREVER, 0, false); if(fun !== undefined) this._callback = fun; }, @@ -220,7 +220,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{ var locActionNodeList = this._actionNodeList; for (var i = 0; i < locActionNodeList.length; i++) locActionNodeList[i].stopAction(); - this._scheduler.unscheduleCallbackForTarget(this, this.simulationActionUpdate); + this.__scheduler.unscheduleCallbackForTarget(this, this.simulationActionUpdate); this._pause = false; this._playing = false; }, @@ -256,7 +256,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{ this.play(); else{ this._playing = false; - this._scheduler.unschedule(this.simulationActionUpdate, this); + this.__scheduler.unschedule(this.simulationActionUpdate, this); } } } diff --git a/extensions/cocostudio/armature/CCArmature.js b/extensions/cocostudio/armature/CCArmature.js index 0dfadb77da..cb350078a1 100644 --- a/extensions/cocostudio/armature/CCArmature.js +++ b/extensions/cocostudio/armature/CCArmature.js @@ -51,7 +51,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ _armatureTransformDirty: true, _body: null, _blendFunc: null, - _className: "Armature", + __className: "Armature", _realAnchorPointInPoints: null, /** @@ -78,7 +78,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ this._rendererStartCmd = new cc.CustomRenderCmdCanvas(this, this._startRendererCmdForCanvas); this._rendererEndCmd = new cc.CustomRenderCmdCanvas(this, this._endRendererCmdForCanvas); }else{ - this._rendererCmd = new cc.ArmatureRenderCmdWebGL(this); + this.__rendererCmd = new cc.ArmatureRenderCmdWebGL(this); } }, @@ -479,7 +479,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ if(this._rendererEndCmd) cc.renderer.pushRenderCommand(this._rendererEndCmd); - this._cacheDirty = false; + this.__cacheDirty = false; context.restore(); }, @@ -488,7 +488,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ var context = ctx || cc._renderContext; context.save(); this.transform(context); - var t = this._transformWorld; + var t = this.__transformWorld; ctx.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY); var locChildren = this._children; @@ -508,7 +508,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ _endRendererCmdForCanvas: function(ctx){ var context = ctx || cc._renderContext; - this._cacheDirty = false; + this.__cacheDirty = false; context.restore(); }, @@ -521,14 +521,14 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ var context = cc._renderContext, currentStack = cc.current_stack; currentStack.stack.push(currentStack.top); - cc.kmMat4Assign(this._stackMatrix, currentStack.top); - currentStack.top = this._stackMatrix; + cc.kmMat4Assign(this.__stackMatrix, currentStack.top); + currentStack.top = this.__stackMatrix; this.transform(); this.sortAllChildren(); //this.draw(context); - cc.renderer.pushRenderCommand(this._rendererCmd); + cc.renderer.pushRenderCommand(this.__rendererCmd); currentStack.top = currentStack.stack.pop(); }, diff --git a/extensions/cocostudio/armature/CCBone.js b/extensions/cocostudio/armature/CCBone.js index 6a476a3b62..21a10dccdc 100644 --- a/extensions/cocostudio/armature/CCBone.js +++ b/extensions/cocostudio/armature/CCBone.js @@ -63,7 +63,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ _worldInfo: null, _armatureParentBone: null, _dataVersion: 0, - _className: "Bone", + __className: "Bone", ctor: function (name) { cc.Node.prototype.ctor.call(this); @@ -266,10 +266,10 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ if (display != null) { display.setColor( cc.color( - this._displayedColor.r * this._tweenData.r / 255, - this._displayedColor.g * this._tweenData.g / 255, - this._displayedColor.b * this._tweenData.b / 255)); - display.setOpacity(this._displayedOpacity * this._tweenData.a / 255); + this.__displayedColor.r * this._tweenData.r / 255, + this.__displayedColor.g * this._tweenData.g / 255, + this.__displayedColor.b * this._tweenData.b / 255)); + display.setOpacity(this.__displayedOpacity * this._tweenData.a / 255); } }, @@ -331,7 +331,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ /** * Sets parent bone to ccs.Bone. - * If _parent is NUll, then also remove this bone from armature. + * If __parent is NUll, then also remove this bone from armature. * It will not set the ccs.Armature, if you want to add the bone to a ccs.Armature, you should use ccs.Armature.addBone(bone, parentName). * @param {ccs.Bone} parent the parent bone. */ diff --git a/extensions/cocostudio/armature/display/CCBatchNode.js b/extensions/cocostudio/armature/display/CCBatchNode.js index f20c238850..39df2aa049 100644 --- a/extensions/cocostudio/armature/display/CCBatchNode.js +++ b/extensions/cocostudio/armature/display/CCBatchNode.js @@ -30,7 +30,7 @@ */ ccs.BatchNode = cc.Node.extend(/** @lends ccs.BatchNode# */{ _atlas:null, - _className:"BatchNode", + __className:"BatchNode", ctor:function () { this._atlas = null; @@ -70,7 +70,7 @@ ccs.BatchNode = cc.Node.extend(/** @lends ccs.BatchNode# */{ // IMPORTANT: // To ease the migration to v3.0, we still support the kmGL stack, // but it is deprecated and your code should not rely on it - cc.kmGLPushMatrixWitMat4(this._stackMatrix); + cc.kmGLPushMatrixWitMat4(this.__stackMatrix); if (this.grid && this.grid.isActive()) this.grid.beforeDraw(); diff --git a/extensions/cocostudio/armature/display/CCDecorativeDisplay.js b/extensions/cocostudio/armature/display/CCDecorativeDisplay.js index f7a7c3d4bf..fe922f0cc2 100644 --- a/extensions/cocostudio/armature/display/CCDecorativeDisplay.js +++ b/extensions/cocostudio/armature/display/CCDecorativeDisplay.js @@ -54,9 +54,9 @@ ccs.DecorativeDisplay = ccs.Class.extend(/** @lends ccs.DecorativeDisplay# */{ * @param {cc.Node} display */ setDisplay:function (display) { - if(display._parent){ - display._parent.removeChild(display); - delete display._parent; + if(display.__parent){ + display.__parent.removeChild(display); + delete display.__parent; } this._display = display; }, diff --git a/extensions/cocostudio/armature/display/CCSkin.js b/extensions/cocostudio/armature/display/CCSkin.js index eee89ac400..14f1498470 100644 --- a/extensions/cocostudio/armature/display/CCSkin.js +++ b/extensions/cocostudio/armature/display/CCSkin.js @@ -42,7 +42,7 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ _skinTransform: null, _displayName: "", _armature: null, - _className: "Skin", + __className: "Skin", ctor: function (fileName, rect) { cc.Sprite.prototype.ctor.call(this); @@ -131,14 +131,14 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ * Updates armature skin's transform with skin transform and bone's transform. */ updateArmatureTransform: function () { - this._transform = cc.affineTransformConcat( + this.__transform = cc.affineTransformConcat( this._skinTransform, this.bone.getNodeToArmatureTransform() ); }, _updateTransformForWebGL: function(){ - var locQuad = this._quad; + var locQuad = this.__quad; // If it is not visible, or one of its ancestors is not visible, then do nothing: if( !this._visible) locQuad.br.vertices = locQuad.tl.vertices = locQuad.tr.vertices = locQuad.bl.vertices = {x: 0, y:0, z:0}; @@ -188,7 +188,7 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ // MARMALADE CHANGE: ADDED CHECK FOR nullptr, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS if (this._textureAtlas) this._textureAtlas.updateQuad(locQuad, this._textureAtlas.getTotalQuads()); - this._quadDirty = true; + this.__quadDirty = true; }, SET_VERTEX3F: function(_v_, _x_, _y_, _z_){ @@ -209,11 +209,11 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ * @returns {cc.AffineTransform} */ getNodeToWorldTransform: function(){ - return cc.affineTransformConcat(this._transform,this.bone.getArmature().getNodeToWorldTransform()); + return cc.affineTransformConcat(this.__transform,this.bone.getArmature().getNodeToWorldTransform()); }, getNodeToWorldTransformAR: function(){ - var displayTransform = this._transform; + var displayTransform = this.__transform; this._anchorPointInPoints = cc.pointApplyAffineTransform(this._anchorPointInPoints, displayTransform); displayTransform.tx = this._anchorPointInPoints.x; displayTransform.ty = this._anchorPointInPoints.y; diff --git a/extensions/cocostudio/reader/GUIReader.js b/extensions/cocostudio/reader/GUIReader.js index ae816c8628..0d91a234ab 100644 --- a/extensions/cocostudio/reader/GUIReader.js +++ b/extensions/cocostudio/reader/GUIReader.js @@ -32,34 +32,34 @@ if(CSParseBinary && window["dcodeIO"] && window["dcodeIO"]["ProtoBuf"]){ (function(){ var factoryCreate = ccs.objectFactory; - factoryCreate.registerType({_className:"ButtonReader", _fun: ccs.buttonReader}); - factoryCreate.registerType({_className: "CheckBoxReader", _fun: ccs.checkBoxReader}); - factoryCreate.registerType({_className: "SliderReader", _fun: ccs.sliderReader}); - factoryCreate.registerType({_className: "ImageViewReader", _fun: ccs.imageViewReader}); - factoryCreate.registerType({_className: "LoadingBarReader", _fun: ccs.loadingBarReader}); - factoryCreate.registerType({_className: "TextAtlasReader", _fun: ccs.labelAtlasReader}); - factoryCreate.registerType({_className: "TextReader", _fun: ccs.labelReader}); - factoryCreate.registerType({_className: "TextBMFontReader", _fun: ccs.labelBMFontReader}); - factoryCreate.registerType({_className: "TextFieldReader", _fun: ccs.textFieldReader}); - factoryCreate.registerType({_className: "LayoutReader", _fun: ccs.layoutReader}); - factoryCreate.registerType({_className: "PageViewReader", _fun: ccs.pageViewReader}); - factoryCreate.registerType({_className: "ScrollViewReader", _fun: ccs.scrollViewReader}); - factoryCreate.registerType({_className: "ListViewReader", _fun: ccs.listViewReader}); - factoryCreate.registerType({_className: "WidgetReader", _fun: ccs.widgetReader}); - - factoryCreate.registerType({_className: "Button", _fun: ccui.Button}); - factoryCreate.registerType({_className: "CheckBox", _fun: ccui.CheckBox}); - factoryCreate.registerType({_className: "ImageView", _fun: ccui.ImageView}); - factoryCreate.registerType({_className: "Text", _fun: ccui.Text}); - factoryCreate.registerType({_className: "TextAtlas", _fun: ccui.TextAtlas}); - factoryCreate.registerType({_className: "TextBMFont", _fun: ccui.TextBMFont}); - factoryCreate.registerType({_className: "LoadingBar", _fun: ccui.LoadingBar}); - factoryCreate.registerType({_className: "Slider", _fun: ccui.Slider}); - factoryCreate.registerType({_className: "TextField", _fun: ccui.TextField}); - factoryCreate.registerType({_className: "Layout", _fun: ccui.Layout}); - factoryCreate.registerType({_className: "ListView", _fun: ccui.ListView}); - factoryCreate.registerType({_className: "PageView", _fun: ccui.PageView}); - factoryCreate.registerType({_className: "ScrollView", _fun: ccui.ScrollView}); + factoryCreate.registerType({__className:"ButtonReader", _fun: ccs.buttonReader}); + factoryCreate.registerType({__className: "CheckBoxReader", _fun: ccs.checkBoxReader}); + factoryCreate.registerType({__className: "SliderReader", _fun: ccs.sliderReader}); + factoryCreate.registerType({__className: "ImageViewReader", _fun: ccs.imageViewReader}); + factoryCreate.registerType({__className: "LoadingBarReader", _fun: ccs.loadingBarReader}); + factoryCreate.registerType({__className: "TextAtlasReader", _fun: ccs.labelAtlasReader}); + factoryCreate.registerType({__className: "TextReader", _fun: ccs.labelReader}); + factoryCreate.registerType({__className: "TextBMFontReader", _fun: ccs.labelBMFontReader}); + factoryCreate.registerType({__className: "TextFieldReader", _fun: ccs.textFieldReader}); + factoryCreate.registerType({__className: "LayoutReader", _fun: ccs.layoutReader}); + factoryCreate.registerType({__className: "PageViewReader", _fun: ccs.pageViewReader}); + factoryCreate.registerType({__className: "ScrollViewReader", _fun: ccs.scrollViewReader}); + factoryCreate.registerType({__className: "ListViewReader", _fun: ccs.listViewReader}); + factoryCreate.registerType({__className: "WidgetReader", _fun: ccs.widgetReader}); + + factoryCreate.registerType({__className: "Button", _fun: ccui.Button}); + factoryCreate.registerType({__className: "CheckBox", _fun: ccui.CheckBox}); + factoryCreate.registerType({__className: "ImageView", _fun: ccui.ImageView}); + factoryCreate.registerType({__className: "Text", _fun: ccui.Text}); + factoryCreate.registerType({__className: "TextAtlas", _fun: ccui.TextAtlas}); + factoryCreate.registerType({__className: "TextBMFont", _fun: ccui.TextBMFont}); + factoryCreate.registerType({__className: "LoadingBar", _fun: ccui.LoadingBar}); + factoryCreate.registerType({__className: "Slider", _fun: ccui.Slider}); + factoryCreate.registerType({__className: "TextField", _fun: ccui.TextField}); + factoryCreate.registerType({__className: "Layout", _fun: ccui.Layout}); + factoryCreate.registerType({__className: "ListView", _fun: ccui.ListView}); + factoryCreate.registerType({__className: "PageView", _fun: ccui.PageView}); + factoryCreate.registerType({__className: "ScrollView", _fun: ccui.ScrollView}); })(); diff --git a/extensions/cocostudio/trigger/ObjectFactory.js b/extensions/cocostudio/trigger/ObjectFactory.js index c2bc197c82..c55eafa817 100644 --- a/extensions/cocostudio/trigger/ObjectFactory.js +++ b/extensions/cocostudio/trigger/ObjectFactory.js @@ -53,7 +53,7 @@ ccs.objectFactory = /** @lends ccs.objectFactory# */{ * @param {ccs.TInfo} t */ registerType: function (t) { - this._typeMap[t._className] = t; + this._typeMap[t.__className] = t; }, /** @@ -83,15 +83,15 @@ ccs.objectFactory = /** @lends ccs.objectFactory# */{ }; ccs.TInfo = ccs.Class.extend({ - _className: "", + __className: "", _fun: null, ctor: function (c, f) { if (f) { - this._className = c; + this.__className = c; this._fun = f; } else { - this._className = c._className; + this.__className = c.__className; this._fun = c._fun; } ccs.objectFactory.registerType(this); diff --git a/extensions/editbox/CCEditBox.js b/extensions/editbox/CCEditBox.js index eae0db612b..0d18f249fd 100644 --- a/extensions/editbox/CCEditBox.js +++ b/extensions/editbox/CCEditBox.js @@ -227,7 +227,7 @@ cc.EditBox = cc.ControlButton.extend({ _placeholderFontSize: 14, _tooltip: false, - _className: "EditBox", + __className: "EditBox", /** * constructor of cc.EditBox diff --git a/extensions/editbox/CCdomNode.js b/extensions/editbox/CCdomNode.js index 2fb5bd47af..6ad94083e8 100644 --- a/extensions/editbox/CCdomNode.js +++ b/extensions/editbox/CCdomNode.js @@ -289,8 +289,8 @@ cc.DOM.methods = /** @lends cc.DOM# */{ //this._addDirtyRegionToDirector(this.getBoundingBoxToWorld()); this._rotationX = this._rotationY = newRotation; - this._rotationRadiansX = this._rotationX * (Math.PI / 180); - this._rotationRadiansY = this._rotationY * (Math.PI / 180); + this.__rotationRadiansX = this._rotationX * (Math.PI / 180); + this.__rotationRadiansY = this._rotationY * (Math.PI / 180); this.setNodeDirty(); this.dom.rotate(newRotation); @@ -338,7 +338,7 @@ cc.DOM.methods = /** @lends cc.DOM# */{ * @param {cc.Node} p */ setParent:function (p) { - this._parent = p; + this.__parent = p; if (p !== null) { p.setAnchorPoint(p.getAnchorPoint()); diff --git a/extensions/gui/control-extension/CCControl.js b/extensions/gui/control-extension/CCControl.js index 392a2c3af1..3c2bf77cdc 100644 --- a/extensions/gui/control-extension/CCControl.js +++ b/extensions/gui/control-extension/CCControl.js @@ -66,7 +66,7 @@ cc.Control = cc.Layer.extend(/** @lends cc.Control# */{ _isOpacityModifyRGB: false, _hasVisibleParents: false, _touchListener: null, - _className: "Control", + __className: "Control", isOpacityModifyRGB: function () { return this._isOpacityModifyRGB; diff --git a/extensions/gui/control-extension/CCControlButton.js b/extensions/gui/control-extension/CCControlButton.js index 448f3ea1f7..58b031a0f9 100644 --- a/extensions/gui/control-extension/CCControlButton.js +++ b/extensions/gui/control-extension/CCControlButton.js @@ -60,7 +60,7 @@ cc.ControlButton = cc.Control.extend(/** @lends cc.ControlButton# */{ _marginV: 0, _marginH: 0, - _className: "ControlButton", + __className: "ControlButton", ctor: function (label, backgroundSprite, fontSize) { cc.Control.prototype.ctor.call(this); @@ -88,7 +88,7 @@ cc.ControlButton = cc.Control.extend(/** @lends cc.ControlButton# */{ }, needsLayout: function () { - if (!this._parentInited) { + if (!this.__parentInited) { return; } // Hide the background and the label @@ -172,7 +172,7 @@ cc.ControlButton = cc.Control.extend(/** @lends cc.ControlButton# */{ if (!backgroundSprite) throw "cc.ControlButton.initWithLabelAndBackgroundSprite(): backgroundSprite should be non-null"; if (cc.Control.prototype.init.call(this, true)) { - this._parentInited = true; + this.__parentInited = true; // Initialize the button state tables this._titleDispatchTable = {}; diff --git a/extensions/gui/control-extension/CCControlColourPicker.js b/extensions/gui/control-extension/CCControlColourPicker.js index 4e7a49f039..5be53c65f6 100644 --- a/extensions/gui/control-extension/CCControlColourPicker.js +++ b/extensions/gui/control-extension/CCControlColourPicker.js @@ -43,7 +43,7 @@ cc.ControlColourPicker = cc.Control.extend(/** @lends cc.ControlColourPicker# */ _huePicker:null, _background:null, - _className:"ControlColourPicker", + __className:"ControlColourPicker", ctor:function () { cc.Control.prototype.ctor.call(this); this.init(); diff --git a/extensions/gui/control-extension/CCControlHuePicker.js b/extensions/gui/control-extension/CCControlHuePicker.js index 9c002740f4..32dfe88c70 100644 --- a/extensions/gui/control-extension/CCControlHuePicker.js +++ b/extensions/gui/control-extension/CCControlHuePicker.js @@ -49,7 +49,7 @@ cc.ControlHuePicker = cc.Control.extend(/** @lends cc.ControlHuePicker# */{ _background:null, _slider:null, _startPos:null, - _className:"ControlHuePicker", + __className:"ControlHuePicker", /** * The constructor of cc.ControlHuePicker diff --git a/extensions/gui/control-extension/CCControlPotentiometer.js b/extensions/gui/control-extension/CCControlPotentiometer.js index 3fb2d8bba1..a4a36e131f 100644 --- a/extensions/gui/control-extension/CCControlPotentiometer.js +++ b/extensions/gui/control-extension/CCControlPotentiometer.js @@ -52,7 +52,7 @@ cc.ControlPotentiometer = cc.Control.extend(/** @lends cc.ControlPotentiometer# /** Contains the maximum value of the receiver. * The default value of this property is 1.0. */ _maximumValue:1, - _className:"ControlPotentiometer", + __className:"ControlPotentiometer", ctor:function (backgroundFile, progressFile, thumbFile) { cc.Control.prototype.ctor.call(this); diff --git a/extensions/gui/control-extension/CCControlSaturationBrightnessPicker.js b/extensions/gui/control-extension/CCControlSaturationBrightnessPicker.js index a9045c43d0..f63e2770bd 100644 --- a/extensions/gui/control-extension/CCControlSaturationBrightnessPicker.js +++ b/extensions/gui/control-extension/CCControlSaturationBrightnessPicker.js @@ -57,7 +57,7 @@ cc.ControlSaturationBrightnessPicker = cc.Control.extend(/** @lends cc.ControlSa _boxPos:0, _boxSize:0, - _className:"ControlSaturationBrightnessPicker", + __className:"ControlSaturationBrightnessPicker", /** * The constructor of cc.ControlSaturationBrightnessPicker diff --git a/extensions/gui/control-extension/CCControlSlider.js b/extensions/gui/control-extension/CCControlSlider.js index f2221a7ebe..c6645e86cc 100644 --- a/extensions/gui/control-extension/CCControlSlider.js +++ b/extensions/gui/control-extension/CCControlSlider.js @@ -59,7 +59,7 @@ cc.ControlSlider = cc.Control.extend(/** @lends cc.ControlSlider# */{ _thumbSprite:null, _progressSprite:null, _backgroundSprite:null, - _className:"ControlSlider", + __className:"ControlSlider", ctor:function (bgFile, progressFile, thumbFile) { cc.Control.prototype.ctor.call(this); diff --git a/extensions/gui/control-extension/CCControlStepper.js b/extensions/gui/control-extension/CCControlStepper.js index f9757cc3b2..b440759749 100644 --- a/extensions/gui/control-extension/CCControlStepper.js +++ b/extensions/gui/control-extension/CCControlStepper.js @@ -71,7 +71,7 @@ cc.ControlStepper = cc.Control.extend(/** @lends cc.ControlStepper# */{ _touchInsideFlag:false, _touchedPart:cc.CONTROL_STEPPER_PARTNONE, _autorepeatCount:0, - _className:"ControlStepper", + __className:"ControlStepper", ctor:function (minusSprite, plusSprite) { cc.Control.prototype.ctor.call(this); this._minusSprite = null; diff --git a/extensions/gui/control-extension/CCControlSwitch.js b/extensions/gui/control-extension/CCControlSwitch.js index 240af15017..fc799c7bdd 100644 --- a/extensions/gui/control-extension/CCControlSwitch.js +++ b/extensions/gui/control-extension/CCControlSwitch.js @@ -39,7 +39,7 @@ cc.ControlSwitch = cc.Control.extend(/** @lends cc.ControlSwitch# */{ _moved:false, /** A Boolean value that determines the off/on state of the switch. */ _on:false, - _className:"ControlSwitch", + __className:"ControlSwitch", ctor:function (maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel) { cc.Control.prototype.ctor.call(this); diff --git a/extensions/gui/control-extension/CCMenuPassive.js b/extensions/gui/control-extension/CCMenuPassive.js index f6600c1c5a..cf9ff0c611 100644 --- a/extensions/gui/control-extension/CCMenuPassive.js +++ b/extensions/gui/control-extension/CCMenuPassive.js @@ -54,7 +54,7 @@ cc.MenuPassive = cc.Layer.extend(/** @lends cc.MenuPassive# */{ _color:null, _opacity:0, - _className:"MenuPassive", + __className:"MenuPassive", ctor:function () { }, diff --git a/extensions/gui/control-extension/CCScale9Sprite.js b/extensions/gui/control-extension/CCScale9Sprite.js index ea8a307cb2..c4003a87fb 100644 --- a/extensions/gui/control-extension/CCScale9Sprite.js +++ b/extensions/gui/control-extension/CCScale9Sprite.js @@ -83,15 +83,15 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ _spritesGenerated: false, _spriteFrameRotated: false, - _textureLoaded:false, - _className:"Scale9Sprite", + __textureLoaded:false, + __className:"Scale9Sprite", /** * return texture is loaded * @returns {boolean} */ textureLoaded:function(){ - return this._textureLoaded; + return this.__textureLoaded; }, /** @@ -571,7 +571,7 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ } var locLoaded = texture.isLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ texture.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. @@ -604,7 +604,7 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ capInsets = capInsets || cc.rect(0, 0, 0, 0); var locLoaded = spriteFrame.textureLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ spriteFrame.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. @@ -708,7 +708,7 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ var tmpTexture = batchNode.getTexture(); var locLoaded = tmpTexture.isLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ tmpTexture.addEventListener("load", function(sender){ this._positionsAreDirty = true; @@ -1004,7 +1004,7 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ var batchNode = new cc.SpriteBatchNode(spriteFrame.getTexture(), 9); // the texture is rotated on Canvas render mode, so isRotated always is false. var locLoaded = spriteFrame.textureLoaded(); - this._textureLoaded = locLoaded; + this.__textureLoaded = locLoaded; if(!locLoaded){ spriteFrame.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. diff --git a/extensions/gui/scrollview/CCScrollView.js b/extensions/gui/scrollview/CCScrollView.js index 28c396c7f9..474e9dbf70 100644 --- a/extensions/gui/scrollview/CCScrollView.js +++ b/extensions/gui/scrollview/CCScrollView.js @@ -100,7 +100,7 @@ cc.ScrollView = cc.Layer.extend(/** @lends cc.ScrollView# */{ // cache object _tmpViewRect:null, _touchListener: null, - _className:"ScrollView", + __className:"ScrollView", _beforeDrawCmd:null, _afterDrawCmd:null, @@ -129,7 +129,7 @@ cc.ScrollView = cc.Layer.extend(/** @lends cc.ScrollView# */{ ctx.save(); ctx.save(); this.transform(); - var t = this._transformWorld; + var t = this.__transformWorld; ctx.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY); cc.ScrollView.prototype._beforeDraw.call(this); }); @@ -636,16 +636,16 @@ cc.ScrollView = cc.Layer.extend(/** @lends cc.ScrollView# */{ } // this.draw(context); // self draw - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); // draw children zOrder >= 0 for (; i < childrenLen; i++) locChildren[i].visit(context); } else{ // this.draw(context); // self draw - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); } // this._afterDraw(); @@ -676,16 +676,16 @@ cc.ScrollView = cc.Layer.extend(/** @lends cc.ScrollView# */{ // this draw //this.draw(context); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); // draw children zOrder >= 0 for (; i < childrenLen; i++) locChildren[i].visit(); } else{ //this.draw(context); - if(this._rendererCmd) - cc.renderer.pushRenderCommand(this._rendererCmd); + if(this.__rendererCmd) + cc.renderer.pushRenderCommand(this.__rendererCmd); } this._afterDraw(context); @@ -926,7 +926,7 @@ cc.ScrollView = cc.Layer.extend(/** @lends cc.ScrollView# */{ var scaleX = this.getScaleX(); var scaleY = this.getScaleY(); - for (var p = this._parent; p != null; p = p.getParent()) { + for (var p = this.__parent; p != null; p = p.getParent()) { scaleX *= p.getScaleX(); scaleY *= p.getScaleY(); } diff --git a/extensions/gui/scrollview/CCTableView.js b/extensions/gui/scrollview/CCTableView.js index f3347aa498..692b599f13 100644 --- a/extensions/gui/scrollview/CCTableView.js +++ b/extensions/gui/scrollview/CCTableView.js @@ -49,7 +49,7 @@ cc.TABLEVIEW_FILL_BOTTOMUP = 1; */ cc.TableViewCell = cc.Node.extend(/** @lends cc.TableViewCell# */{ _idx:0, - _className:"TableViewCell", + __className:"TableViewCell", /** * The index used internally by SWTableView and its subclasses @@ -627,7 +627,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ if (this._touchedCell){ var bb = this.getBoundingBox(); var tmpOrigin = cc.p(bb.x, bb.y); - tmpOrigin = this._parent.convertToWorldSpace(tmpOrigin); + tmpOrigin = this.__parent.convertToWorldSpace(tmpOrigin); bb.x = tmpOrigin.x; bb.y = tmpOrigin.y; var locTableViewDelegate = this._tableViewDelegate; diff --git a/extensions/spine/CCSkeleton.js b/extensions/spine/CCSkeleton.js index fd2ee9a37d..3d5647b16b 100644 --- a/extensions/spine/CCSkeleton.js +++ b/extensions/spine/CCSkeleton.js @@ -94,9 +94,9 @@ sp.Skeleton = cc.Node.extend(/** @lends sp.Skeleton# */{ _initRendererCmd:function () { if(cc._renderType === cc._RENDER_TYPE_WEBGL) - this._rendererCmd = new cc.SkeletonRenderCmdWebGL(this); + this.__rendererCmd = new cc.SkeletonRenderCmdWebGL(this); else - this._rendererCmd = new cc.SkeletonRenderCmdCanvas(this); + this.__rendererCmd = new cc.SkeletonRenderCmdCanvas(this); }, /** diff --git a/template/main.js b/template/main.js index 8d14ccf6a2..a0e766bf4d 100644 --- a/template/main.js +++ b/template/main.js @@ -15,4 +15,46 @@ cc.game.onStart = function(){ cc.director.runScene(new MyScene()); }, this); }; -cc.game.run(); \ No newline at end of file +cc.game.run(); + +var node = new cc.Node; +node.setColor({r:100,g:200,b:255}); +var test = cc.Serializer.serialize(node); +var node2 = cc.Serializer.unSerialize(test); + +var root = new cc.Node; +var child1 = new cc.Node; +child1.name = "child1"; +var child2 = new cc.Node; +child2.name = "child2"; + +root.addChild(child1); +root.addChild(child2); + +var test2 = cc.Serializer.serialize(root); + +var revivedRoot = cc.Serializer.unSerialize(test2); + + + +var obj = { + a:"a", + b:"b", + children:[{ + a:"a", + b:"b", + children:[] + }, + { + a:"a", + b:"b", + children:[] + }] + + +}; + + + + + diff --git a/template/src/myApp.js b/template/src/myApp.js index a1cd0c1e63..5829d587ae 100644 --- a/template/src/myApp.js +++ b/template/src/myApp.js @@ -15,28 +15,28 @@ var MyLayer = cc.Layer.extend({ var size = cc.director.getWinSize(); // add a "close" icon to exit the progress. it's an autorelease object - var closeItem = cc.MenuItemImage.create( - s_CloseNormal, - s_CloseSelected, - function () { - cc.log("close"); - },this); - closeItem.setAnchorPoint(0.5, 0.5); - - var menu = new cc.Menu(closeItem); - menu.setPosition(0, 0); - this.addChild(menu, 1); - closeItem.setPosition(size.width - 20, 20); +// var closeItem = cc.MenuItemImage.create( +// s_CloseNormal, +// s_CloseSelected, +// function () { +// cc.log("close"); +// },this); +// closeItem.setAnchorPoint(0.5, 0.5); +// +// var menu = new cc.Menu(closeItem); +// menu.setPosition(0, 0); +// this.addChild(menu, 1); +// closeItem.setPosition(size.width - 20, 20); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label - this.helloLabel = new cc.LabelTTF("Hello World", "Impact", 38); +// this.helloLabel = new cc.LabelTTF("Hello World", "Impact", 38); // position the label on the center of the screen - this.helloLabel.setPosition(size.width / 2, size.height - 40); +// this.helloLabel.setPosition(size.width / 2, size.height - 40); // add the label as a child to this layer - this.addChild(this.helloLabel, 5); +// this.addChild(this.helloLabel, 5); // add "Helloworld" splash screen" this.sprite = cc.Sprite.create(s_HelloWorld); From 93531d6c033c63959455f60b991b2e7782e0b969 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 9 Dec 2014 14:35:30 +0800 Subject: [PATCH 24/32] Improve restart game feature --- CCBoot.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CCBoot.js b/CCBoot.js index 3d3a177b63..ab001427e8 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2078,6 +2078,10 @@ cc.game = /** @lends cc.game# */{ restart: function () { cc.director.popToSceneStackLevel(0); + // Clean up audio + cc.audioEngine && cc.audioEngine.end(); + + cc.game.onStart(); }, _initConfig: function () { From 95ce54b7010188464e6d61396b08d18bd3ecc939 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 10 Dec 2014 18:04:09 +0800 Subject: [PATCH 25/32] Fix LabelTTF dependency issue --- cocos2d/core/CCDirector.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 290b735c02..bc264e1d1c 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -983,14 +983,16 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { else fontSize = 0 | (_t._winSizeInPoints.width / 320 * 24); - _t._FPSLabel = new cc.LabelTTF("000.0", "Arial", fontSize); - _t._SPFLabel = new cc.LabelTTF("0.000", "Arial", fontSize); - _t._drawsLabel = new cc.LabelTTF("0000", "Arial", fontSize); - - var locStatsPosition = cc.DIRECTOR_STATS_POSITION; - _t._drawsLabel.setPosition(_t._drawsLabel.width / 2 + locStatsPosition.x, _t._drawsLabel.height * 5 / 2 + locStatsPosition.y); - _t._SPFLabel.setPosition(_t._SPFLabel.width / 2 + locStatsPosition.x, _t._SPFLabel.height * 3 / 2 + locStatsPosition.y); - _t._FPSLabel.setPosition(_t._FPSLabel.width / 2 + locStatsPosition.x, _t._FPSLabel.height / 2 + locStatsPosition.y); + if (cc.LabelTTF) { + _t._FPSLabel = new cc.LabelTTF("000.0", "Arial", fontSize); + _t._SPFLabel = new cc.LabelTTF("0.000", "Arial", fontSize); + _t._drawsLabel = new cc.LabelTTF("0000", "Arial", fontSize); + + var locStatsPosition = cc.DIRECTOR_STATS_POSITION; + _t._drawsLabel.setPosition(_t._drawsLabel.width / 2 + locStatsPosition.x, _t._drawsLabel.height * 5 / 2 + locStatsPosition.y); + _t._SPFLabel.setPosition(_t._SPFLabel.width / 2 + locStatsPosition.x, _t._SPFLabel.height * 3 / 2 + locStatsPosition.y); + _t._FPSLabel.setPosition(_t._FPSLabel.width / 2 + locStatsPosition.x, _t._FPSLabel.height / 2 + locStatsPosition.y); + } }; _p.getVisibleSize = function () { From 20adf5e4d1ba21ac68d4db8c2f94fba96c61dec5 Mon Sep 17 00:00:00 2001 From: Wu-Hao Date: Wed, 10 Dec 2014 18:05:24 +0800 Subject: [PATCH 26/32] serializer for nodes --- CCBoot.js | 2 +- cocos2d/core/base-nodes/CCNode.js | 26 ++-- cocos2d/core/platform/CCClass.js | 238 ++++++++++++++++++++++++----- cocos2d/core/platform/CCLoaders.js | 2 +- template/main.js | 43 ------ template/src/resource.js | 4 +- 6 files changed, 212 insertions(+), 103 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 3d3a177b63..7bf1ee9aa9 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2236,7 +2236,7 @@ Function.prototype.bind = Function.prototype.bind || function (oThis) { cc.game.loadScene = function (resource, scene, callback) { if (resource && scene) { cc.LoaderScene.preload(resource, function() { - cc.director.runScene(scene); + cc.director.runScene(cc.Serializer.unSerialize(cc.loader.getRes(scene))); cc.director.drawScene(scene); cc.game.pause(); callback && callback(); diff --git a/cocos2d/core/base-nodes/CCNode.js b/cocos2d/core/base-nodes/CCNode.js index fb2290d899..15491d29f6 100644 --- a/cocos2d/core/base-nodes/CCNode.js +++ b/cocos2d/core/base-nodes/CCNode.js @@ -150,6 +150,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ _children: null, // lazy alloc, _visible: true, + uid:null, _anchorPoint: null, _anchorPointInPoints: null, _contentSize: null, @@ -206,6 +207,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{ _initNode: function () { var _t = this; + _t.uid = Date.now()+Math.random(); _t._anchorPoint = cc.p(0, 0); _t._anchorPointInPoints = cc.p(0, 0); _t._contentSize = cc.size(0, 0); @@ -2815,28 +2817,24 @@ cc._tmp.PrototypeCCNode(); delete cc._tmp.PrototypeCCNode; cc.Serializer.addMethods("_realColor", function(val){return {r:val.r, g:val.g, b:val.b, a:val.a}}, cc.Node.prototype.setColor); -//cc.Serializer.addMethods("_children", cc.Node.prototype.getChildren, function(val){ -// for(var i = 0; i < val.length; i++) -// { -// this.addChild(val[i]); -// } -//}); +cc.Serializer.addMethods("_children", cc.Node.prototype.getChildren, function(val, nodesList){ + for(var i = 0; i < val.length; i++) + { + //this.addChild(nodesList[val[i].ref]); + this.addChild(val[i]); + } +}); cc.Serializer.addMethods("_texture", function(val){ return {url:val.url, pixelFormat:val.pixelFormat}; }, -function(val, that){ - console.log(this, that); +function(val, nodesList, unSerializedMirror){ var tex = cc.textureCache.getTextureForKey(val.url); if(!tex){ tex = cc.textureCache.addImage(val.url); } - - var tempTexture = new cc.Texture2D(); - tempTexture.initWithElement(tex.getHtmlElementObj()); - tempTexture.handleLoadedTexture(); - that.setTexture(tempTexture); - that.setTextureRect(that._rect); + this.setTexture(tex); + this.setTextureRect(unSerializedMirror._rect); }); //ignore some that are not supported diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 8dfd00fc3f..0087ad55b2 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -370,66 +370,220 @@ cc.Serializer = { cc.Serializer.specialCases.push(key); cc.Serializer.specialCasesMethods.push({g:getFunc,s:setFunc}); }, - serialize:function(node){ - - - - - return JSON.stringify(node, function(key, val){ - if(val === null || key[1] == '_') - return undefined; - - //debug - remove these when finished - if(val instanceof HTMLElement) + _addToStructure:function(struct, node){ + if(typeof node === "object" && node !== null){ + if(node.uid)//object is a node { - console.log("html",this, key, val); - return undefined; + if(struct.nodes[node.uid])//if already exists in struct + { + if(struct.nodes[node.uid] !== node) + throw "duplicate node uid encountered"; + } + else if(!struct.nodes[node.uid])//else if doesnt exists in struct, add to it + { + struct.nodes[node.uid] = node; + var keys = Object.keys(node); + for(var i = 0; i < keys.length; i++) + { + var o = node[keys[i]]; + this._addToStructure(struct, o); + } + } + } + else if(node.length)//object is an non-empty array, then go into it + { + for(var i = 0; i < node.length; i++) + { + var o = node[i]; + this._addToStructure(struct, o); + } + } + } + }, + serialize:function(node){ + var structure = { + SerializerVersion:"1.0", + root:node.uid, + nodes:{} + }; + // find all nodes and add them to structure.nodes + this._addToStructure(structure, node); + //node is the base, build the tree based on it + +// for(var k in structure.nodes) +// { +// var n = structure.nodes[k]; +// structure.tree[n.uid] = []; +//// for(var j = 0; j< n._children.length; j++) +//// { +//// structure.tree[n.uid].push(n._children[j].uid); +//// } +// } + + + return JSON.stringify(structure, function(key, val){ + if(val === null || key[1] === "_"){ + return; } - //end debug - var special = cc.Serializer.getMethods(key); if(special && special.g) { return special.g.call(this,val); } - else if(typeof val === "object" && val._type_) + if(typeof val === "object") { - //copy the object type to local, so it gets serialized - val._type_ = val._type_; + //if its object + if(val.uid) + { + //this is a node + if(this === structure.nodes) + { + // we are in the nodes, proceed to stringify + //copy type to local + val._type_ = val._type_; + return val; + } + else{ + // we should not stringify this, but leave uid + return {ref:val.uid}; + } + } + else if(val instanceof HTMLElement) + { + //we don't want anything to do with htmlelement + return; + } + else if(val.toJSON) + { + //this object has tojson method, so we should let it pass + return val; + } + else{ + return val; + } + } + else{ + //not an object is always a good value + return val; } - return val; },this.compact?0:4); + +// return JSON.stringify(node, function(key, val){ +// if(val === null || key[1] == '_') +// return undefined; +// +// //debug - remove these when finished +// if(val instanceof HTMLElement) +// { +// console.log("html",this, key, val); +// return undefined; +// } +// //end debug +// +// var special = cc.Serializer.getMethods(key); +// if(special && special.g) +// { +// return special.g.call(this,val); +// } +// else if(typeof val === "object" && val._type_) +// { +// //copy the object type to local, so it gets serialized +// val._type_ = val._type_; +// } +// return val; +// },this.compact?0:4); }, - unSerialize:function(json) - { - var specialList = []; - var ret = JSON.parse(json, function(key, val){ - var special = cc.Serializer.getMethods(key); - if(special && special.s) + _fixlinks:function(unserializedMirror, revivedNodes){ + for(var key in unserializedMirror) + { + var uns = unserializedMirror[key]; + if(typeof uns === "object") { - specialList.push({func:special.s, that:this, val:val}); - return undefined; + if(uns.ref) + { + //this is a node, make this a link to the revived Nodes + unserializedMirror[key] = revivedNodes[uns.ref]; + } + else{ + this._fixlinks(uns, revivedNodes); + } } - //if we defined a type for this object then - if(typeof val === "object" && val._type_) + } + }, + unSerialize:function(json) + { + var unSerializedObj = JSON.parse(json); + //start reviving nodes + var revivedNodes = {}; + //first revive all nodes and add them to the nodes list + for(var uid in unSerializedObj.nodes) + { + var unSerializedNode = unSerializedObj.nodes[uid]; + var cls = cc.Serializer._getClass(unSerializedNode._type_); + var revivedObj = new cls; + revivedNodes[uid] = revivedObj; + } + //fix all linking issue by scanning everything recursively + for(var uid in unSerializedObj.nodes) + { + this._fixlinks(unSerializedObj.nodes[uid], revivedNodes); + } + + //try to revive the values for each node + for(uid in revivedNodes) + { + var revivedObj = revivedNodes[uid]; + var keys = Object.keys(unSerializedObj.nodes[uid]); + for(var i = 0; i < keys.length; i ++) { - var cls = cc.Serializer._getClass(val._type_); - var ret = new cls; - var keys = Object.keys(val); - for(var i = 0; i < keys.length; i++) + + var key = keys[i]; + var value = unSerializedObj.nodes[uid][key]; + if(value.ref) { - ret[keys[i]] = val[keys[i]]; + value = revivedNodes[value.ref]; + } + var reviver = this.getMethods(key); + if(reviver){ + reviver.s.call(revivedObj, value, revivedNodes,unSerializedObj.nodes[uid]); + } + else{ + revivedObj[key] = unSerializedObj.nodes[uid][key]; } - return ret; } - return val; - }); - for(var i = 0; i < specialList.length; i++) - { - var o = specialList[i]; - o.func.call(o.that, o.val, this); } - return ret; + + return revivedNodes[unSerializedObj.root]; + + +// var specialList = []; +// var ret = JSON.parse(json, function(key, val){ +// var special = cc.Serializer.getMethods(key); +// if(special && special.s) +// { +// specialList.push({func:special.s, that:this, val:val}); +// return undefined; +// } +// //if we defined a type for this object then +// if(typeof val === "object" && val._type_) +// { +// var cls = cc.Serializer._getClass(val._type_); +// var ret = new cls; +// var keys = Object.keys(val); +// for(var i = 0; i < keys.length; i++) +// { +// ret[keys[i]] = val[keys[i]]; +// } +// return ret; +// } +// return val; +// }); +// for(var i = 0; i < specialList.length; i++) +// { +// var o = specialList[i]; +// o.func.call(o.that, o.val, this); +// } +// return ret; }, _getClass:function(str){ //not using eval to prevent code injection diff --git a/cocos2d/core/platform/CCLoaders.js b/cocos2d/core/platform/CCLoaders.js index d051a80b42..77c025d67b 100644 --- a/cocos2d/core/platform/CCLoaders.js +++ b/cocos2d/core/platform/CCLoaders.js @@ -28,7 +28,7 @@ cc._txtLoader = { cc.loader.loadTxt(realUrl, cb); } }; -cc.loader.register(["txt", "xml", "vsh", "fsh", "atlas"], cc._txtLoader); +cc.loader.register(["txt", "xml", "vsh", "fsh", "atlas", "ccd"], cc._txtLoader); cc._jsonLoader = { load : function(realUrl, url, res, cb){ diff --git a/template/main.js b/template/main.js index a0e766bf4d..2a61aaabae 100644 --- a/template/main.js +++ b/template/main.js @@ -2,12 +2,6 @@ cc.game.onStart = function(){ var designSize = cc.size(480, 800); var screenSize = cc.view.getFrameSize(); - if(!cc.sys.isNative && screenSize.height < 800){ - designSize = cc.size(320, 480); - cc.loader.resPath = "res/Normal"; - }else{ - cc.loader.resPath = "res/HD"; - } cc.view.setDesignResolutionSize(designSize.width, designSize.height, cc.ResolutionPolicy.SHOW_ALL); //load resources @@ -17,43 +11,6 @@ cc.game.onStart = function(){ }; cc.game.run(); -var node = new cc.Node; -node.setColor({r:100,g:200,b:255}); -var test = cc.Serializer.serialize(node); -var node2 = cc.Serializer.unSerialize(test); - -var root = new cc.Node; -var child1 = new cc.Node; -child1.name = "child1"; -var child2 = new cc.Node; -child2.name = "child2"; - -root.addChild(child1); -root.addChild(child2); - -var test2 = cc.Serializer.serialize(root); - -var revivedRoot = cc.Serializer.unSerialize(test2); - - - -var obj = { - a:"a", - b:"b", - children:[{ - a:"a", - b:"b", - children:[] - }, - { - a:"a", - b:"b", - children:[] - }] - - -}; - diff --git a/template/src/resource.js b/template/src/resource.js index 94284083d1..1868ed3463 100644 --- a/template/src/resource.js +++ b/template/src/resource.js @@ -1,5 +1,5 @@ -var s_HelloWorld = "HelloWorld.jpg"; -var s_CloseNormal = "CloseNormal.png"; +var s_HelloWorld = "res/HelloWorld.jpg"; +var s_CloseNormal = "res/CloseNormal.png"; var s_CloseSelected = "CloseSelected.png"; var g_resources = [ From 88964b720d5908939eb189f081de7d1f98d5ff98 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 16 Dec 2014 12:04:48 +0800 Subject: [PATCH 27/32] Improve the engine to support GameEngine --- CCBoot.js | 25 ++++++++++++++++++++----- require.js | 2 ++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index fddbde8aca..94880cb7d8 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -727,10 +727,18 @@ cc.loader = /** @lends cc.loader# */{ */ loadJson: function (url, cb) { this.loadTxt(url, function (err, txt) { - try { - err ? cb(err) : cb(null, JSON.parse(txt)); - } catch (e) { - throw "load json [" + url + "] failed : " + e; + if (err) { + cb(err); + } + else { + try { + var result = JSON.parse(txt); + } + catch (e) { + throw "parse json [" + url + "] failed : " + e; + return; + } + cb(null, result); } }); }, @@ -2213,7 +2221,7 @@ cc.game._initConfig(); Function.prototype.bind = Function.prototype.bind || function (oThis) { if (!cc.isFunction(this)) { - // closest thing possible to the ECMAScript 5 + // closest thing possible to =the ECMAScript 5 // internal IsCallable function throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); } @@ -2253,3 +2261,10 @@ cc.game.loadScene = function (resource, scene, callback) { callback && callback(); } }; + +cc.game.createNode = function (ccd_file, callback) { + cc.loader.loadTxt(ccd_file, function(err, jsonStr) { + var node = cc.Serializer.unSerialize(jsonStr); + callback.call(cc.game, node); + }); +}; \ No newline at end of file diff --git a/require.js b/require.js index 68bf30b8b9..f8d7119f1a 100644 --- a/require.js +++ b/require.js @@ -2626,3 +2626,5 @@ else } }; } + +require.config(require_config); \ No newline at end of file From 25fa7a7cc54c7d5cdbc7655917a6b2c02b62fe12 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 16 Dec 2014 12:56:15 +0800 Subject: [PATCH 28/32] Fix typo --- CCBoot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CCBoot.js b/CCBoot.js index 94880cb7d8..1994b4e1af 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2221,7 +2221,7 @@ cc.game._initConfig(); Function.prototype.bind = Function.prototype.bind || function (oThis) { if (!cc.isFunction(this)) { - // closest thing possible to =the ECMAScript 5 + // closest thing possible to the ECMAScript 5 // internal IsCallable function throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); } From 94ef0c1d391141a61f3980395e106a592b67462b Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 18 Dec 2014 15:17:59 +0800 Subject: [PATCH 29/32] Automatically setup design resolution, policy, adjust viewport, auto resize from project.json --- CCBoot.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CCBoot.js b/CCBoot.js index 1994b4e1af..1194a1f608 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -1787,7 +1787,13 @@ cc._setup = function (el, width, height) { else cc._setupCalled = true; var win = window; var lastTime = new Date(); - var frameTime = 1000 / cc.game.config[cc.game.CONFIG_KEY.frameRate]; + var cfg = cc.game.config, + cfgKey = cc.game.CONFIG_KEY, + frameTime = 1000 / cfg[cfgKey.frameRate], + resolution = cfg[cfgKey.designResolution], + policy = cfg[cfgKey.resolutionPolicy], + adjustVP = cfg[cfgKey.adjustViewport], + autoResize = cfg[cfgKey.resizeWithBrowser]; var stTime = function(callback){ var currTime = new Date().getTime(); @@ -1930,6 +1936,14 @@ cc._setup = function (el, width, height) { * A Plist Parser */ cc.plistParser = new cc.PlistParser(); + + // Set design resolution policy + if (adjustVP !== undefined) + cc.view.adjustViewPort(adjustVP); + if (autoResize !== undefined) + cc.view.resizeWithBrowserSize(autoResize); + if (policy !== undefined && resolution) + cc.view.setDesignResolutionSize(resolution[0], resolution[1], policy); }; cc._checkWebGLRenderMode = function () { @@ -1984,6 +1998,10 @@ cc.game = /** @lends cc.game# */{ renderMode: "renderMode", jsList: "jsList", classReleaseMode: "classReleaseMode", + designResolution: "designResolution", + resolutionPolicy: "resolutionPolicy", + adjustViewport: "adjustViewport", + resizeWithBrowser: "resizeWithBrowser", useRequireJS:"useRequireJS" }, From 96c5069e569919f6363a1d0fad335bc2c1aec162 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 18 Dec 2014 18:25:01 +0800 Subject: [PATCH 30/32] Fix container margin issue of EqualToFrame policy --- cocos2d/core/platform/CCEGLView.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 6de11ebccd..33ec34b94f 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -856,7 +856,13 @@ cc.ContentStrategy = cc.Class.extend(/** @lends cc.ContentStrategy# */{ */ var EqualToFrame = cc.ContainerStrategy.extend({ apply: function (view) { + var containerStyle = cc.container.style; this._setupContainer(view, view._frameSize.width, view._frameSize.height); + // Setup container's margin + containerStyle.marginLeft = "0px"; + containerStyle.marginRight = "0px"; + containerStyle.marginTop = "0px"; + containerStyle.marginBottom = "0px"; } }); From a7ecf5b9607faf751d17805e8df38b415c7e8912 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 23 Dec 2014 00:26:21 +0800 Subject: [PATCH 31/32] Improve createNode callback paramters --- CCBoot.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 1194a1f608..bb610e9e6a 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2282,7 +2282,12 @@ cc.game.loadScene = function (resource, scene, callback) { cc.game.createNode = function (ccd_file, callback) { cc.loader.loadTxt(ccd_file, function(err, jsonStr) { - var node = cc.Serializer.unSerialize(jsonStr); - callback.call(cc.game, node); + if (!err) { + var node = cc.Serializer.unSerialize(jsonStr); + callback.call(cc.game, err, node); + } + else { + callback.call(cc.game, err); + } }); }; \ No newline at end of file From 48dbc76311bc2dbb3b50580ae7676f445337b59f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 26 Dec 2014 14:26:07 +0800 Subject: [PATCH 32/32] Fix issue of resize event --- cocos2d/core/platform/CCEGLView.js | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 33ec34b94f..09431c084f 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -132,14 +132,20 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ // Resize helper functions _resizeEvent: function () { - var width = this._originalDesignResolutionSize.width; - var height = this._originalDesignResolutionSize.height; - if (this._resizeCallback) { - this._initFrameSize(); - this._resizeCallback.call(); + var view; + if(this.setDesignResolutionSize){ + view = this; + }else{ + view = cc.view; } + if (view._resizeCallback) { + view._initFrameSize(); + view._resizeCallback.call(); + } + var width = view._originalDesignResolutionSize.width; + var height = view._originalDesignResolutionSize.height; if (width > 0) - this.setDesignResolutionSize(width, height, this._resolutionPolicy); + view.setDesignResolutionSize(width, height, view._resolutionPolicy); }, /** @@ -172,20 +178,17 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ * @param {Boolean} enabled Whether enable automatic resize with browser's resize event */ resizeWithBrowserSize: function (enabled) { - var adjustSize, _t = this; if (enabled) { //enable - if (!_t.__resizeWithBrowserSize) { - _t.__resizeWithBrowserSize = true; - adjustSize = _t._resizeEvent.bind(_t); - cc._addEventListener(window, 'resize', adjustSize, false); + if (!this.__resizeWithBrowserSize) { + this.__resizeWithBrowserSize = true; + cc._addEventListener(window, 'resize', this._resizeEvent, false); } } else { //disable - if (_t.__resizeWithBrowserSize) { - _t.__resizeWithBrowserSize = true; - adjustSize = _t._resizeEvent.bind(_t); - window.removeEventListener('resize', adjustSize, false); + if (this.__resizeWithBrowserSize) { + this.__resizeWithBrowserSize = false; + window.removeEventListener('resize', this._resizeEvent, false); } } },