mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
@@ -286,6 +286,24 @@ function initClipData (root, state) {
|
||||
}
|
||||
}
|
||||
|
||||
// property curves
|
||||
|
||||
var curveData = clip.curveData;
|
||||
var childrenCurveDatas = curveData.paths;
|
||||
|
||||
createTargetCurves(root, curveData);
|
||||
|
||||
for (var namePath in childrenCurveDatas) {
|
||||
var target = cc.find(namePath, root);
|
||||
|
||||
if (!target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var childCurveDatas = childrenCurveDatas[namePath];
|
||||
createTargetCurves(target, childCurveDatas);
|
||||
}
|
||||
|
||||
// events curve
|
||||
|
||||
var events = clip.events;
|
||||
@@ -317,24 +335,6 @@ function initClipData (root, state) {
|
||||
eventInfo.add(eventData.func, eventData.params);
|
||||
}
|
||||
}
|
||||
|
||||
// property curves
|
||||
|
||||
var curveData = clip.curveData;
|
||||
var childrenCurveDatas = curveData.paths;
|
||||
|
||||
createTargetCurves(root, curveData);
|
||||
|
||||
for (var namePath in childrenCurveDatas) {
|
||||
var target = cc.find(namePath, root);
|
||||
|
||||
if (!target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var childCurveDatas = childrenCurveDatas[namePath];
|
||||
createTargetCurves(target, childCurveDatas);
|
||||
}
|
||||
}
|
||||
|
||||
if (CC_TEST) {
|
||||
|
||||
@@ -85,8 +85,9 @@ var AnimationClip = cc.Class({
|
||||
/**
|
||||
* !#en Crate clip with a set of sprite frames
|
||||
* !#zh 使用一组序列帧图片来创建动画剪辑
|
||||
* @property {[cc.SpriteFrame]} spriteFrames
|
||||
* @property {Number} sample
|
||||
* @method createWithSpriteFrames
|
||||
* @param {[cc.SpriteFrame]} spriteFrames
|
||||
* @param {Number} sample
|
||||
* @return {AnimationClip}
|
||||
* @example
|
||||
*
|
||||
|
||||
@@ -800,6 +800,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
scene = sceneAsset;
|
||||
}
|
||||
if (scene instanceof cc.Scene) {
|
||||
scene._name = sceneAsset._name;
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1172,7 +1172,7 @@ var Node = cc.Class({
|
||||
* node.targetOff(target);
|
||||
*/
|
||||
targetOff: function (target) {
|
||||
this._EventTargetTargetOff(this, target);
|
||||
this._EventTargetTargetOff(target);
|
||||
|
||||
this._checkTouchListeners();
|
||||
this._checkMouseListeners();
|
||||
|
||||
@@ -111,6 +111,9 @@ var Button = cc.Class({
|
||||
this._toColor = null;
|
||||
this._time = 0;
|
||||
this._transitionFinished = true;
|
||||
if(CC_EDITOR) {
|
||||
this._previousNormalSprite = null;
|
||||
}
|
||||
},
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
@@ -133,7 +136,14 @@ var Button = cc.Class({
|
||||
interactable: {
|
||||
default: true,
|
||||
tooltip: 'i18n:COMPONENT.button.interactable',
|
||||
notify: function () {
|
||||
notify: function (oldValue) {
|
||||
if(CC_EDITOR) {
|
||||
if(oldValue) {
|
||||
this._previousNormalSprite = this.normalSprite;
|
||||
} else {
|
||||
this.normalSprite = this._previousNormalSprite;
|
||||
}
|
||||
}
|
||||
this._updateState();
|
||||
},
|
||||
animatable: false
|
||||
|
||||
@@ -125,6 +125,12 @@ var Label = cc.Class({
|
||||
name: 'cc.Label',
|
||||
extends: cc._RendererUnderSG,
|
||||
|
||||
ctor: function() {
|
||||
if(CC_EDITOR) {
|
||||
this._userDefinedFontSize = 40;
|
||||
}
|
||||
},
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
menu: 'i18n:MAIN_MENU.component.renderers/Label',
|
||||
help: 'i18n:COMPONENT.help_url.label',
|
||||
@@ -146,6 +152,9 @@ var Label = cc.Class({
|
||||
if (this._sgNode) {
|
||||
this._sgNode.setString(this.string);
|
||||
this._updateNodeSize();
|
||||
if(CC_EDITOR && this.overflow === cc.Label.Overflow.SHRINK) {
|
||||
this.fontSize = this._userDefinedFontSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -199,6 +208,9 @@ var Label = cc.Class({
|
||||
},
|
||||
set: function(value){
|
||||
this._fontSize = value;
|
||||
if(CC_EDITOR) {
|
||||
this._userDefinedFontSize = value;
|
||||
}
|
||||
if (this._sgNode) {
|
||||
this._sgNode.setFontSize(value);
|
||||
this._updateNodeSize();
|
||||
@@ -284,10 +296,15 @@ var Label = cc.Class({
|
||||
return this._N$file;
|
||||
},
|
||||
set: function (value) {
|
||||
//if delete the font, we should change isSystemFontUsed to true
|
||||
if(!value) {
|
||||
this._isSystemFontUsed = true;
|
||||
}
|
||||
|
||||
this._N$file = value;
|
||||
this._bmFontOriginalSize = -1;
|
||||
if (value && this._isSystemFontUsed)
|
||||
this.useSystemFont = false;
|
||||
this._isSystemFontUsed = false;
|
||||
|
||||
if (this._sgNode) {
|
||||
|
||||
@@ -323,6 +340,8 @@ var Label = cc.Class({
|
||||
return this._isSystemFontUsed;
|
||||
},
|
||||
set: function(value){
|
||||
if(!value && this._isSystemFontUsed) return;
|
||||
|
||||
this._isSystemFontUsed = !!value;
|
||||
if (value) {
|
||||
this.font = null;
|
||||
@@ -421,6 +440,9 @@ var Label = cc.Class({
|
||||
sgNode.enableWrapText( this._enableWrapText );
|
||||
sgNode.setLineHeight(this._lineHeight);
|
||||
sgNode.setString(this.string);
|
||||
if (CC_EDITOR) {
|
||||
this._userDefinedFontSize = this.fontSize;
|
||||
}
|
||||
if (CC_EDITOR && this._useOriginalSize) {
|
||||
this.node.setContentSize(sgNode.getContentSize());
|
||||
if (this.font instanceof cc.BitmapFont) {
|
||||
|
||||
@@ -448,8 +448,30 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
return new cc.BlendFunc(this._blendFunc.src, this._blendFunc.dst);
|
||||
},
|
||||
|
||||
_setupBMFontOverflowMetrics: function(newWidth, newHeight) {
|
||||
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
|
||||
newWidth = 0;
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
this._labelWidth = newWidth;
|
||||
this._labelHeight = newHeight;
|
||||
this._labelDimensions.width = newWidth;
|
||||
this._labelDimensions.height = newHeight;
|
||||
this._maxLineWidth = newWidth;
|
||||
},
|
||||
|
||||
_updateLabel: function () {
|
||||
if (this._labelType === _ccsg.Label.Type.BMFont) {
|
||||
var contentSize = this._contentSize;
|
||||
var newWidth = contentSize.width;
|
||||
var newHeight = contentSize.height;
|
||||
this._setupBMFontOverflowMetrics(newWidth, newHeight);
|
||||
|
||||
this._updateContent();
|
||||
this.setColor(this.color);
|
||||
} else if (this._labelType === _ccsg.Label.Type.TTF
|
||||
@@ -510,7 +532,7 @@ cc.BMFontHelper = {
|
||||
|
||||
this._textDesiredHeight = 0;
|
||||
this._linesWidth = [];
|
||||
if (this._maxLineWidth > 0 && !this._lineBreakWithoutSpaces) {
|
||||
if (!this._lineBreakWithoutSpaces) {
|
||||
this._multilineTextWrapByWord();
|
||||
} else {
|
||||
this._multilineTextWrapByChar();
|
||||
@@ -672,21 +694,7 @@ cc.BMFontHelper = {
|
||||
|
||||
if (newHeight !== oldSize.height || newWidth !== oldSize.width) {
|
||||
|
||||
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
|
||||
newWidth = 0;
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
this._labelWidth = newWidth;
|
||||
this._labelHeight = newHeight;
|
||||
this._labelDimensions.width = newWidth;
|
||||
this._labelDimensions.height = newHeight;
|
||||
|
||||
this._maxLineWidth = newWidth;
|
||||
this._setupBMFontOverflowMetrics(newWidth, newHeight);
|
||||
|
||||
if (this._drawFontsize > 0) {
|
||||
this._restoreFontSize();
|
||||
@@ -822,6 +830,7 @@ cc.BMFontHelper = {
|
||||
if (this._labelHeight <= 0) {
|
||||
contentSize.height = parseFloat(this._textDesiredHeight.toFixed(2));
|
||||
}
|
||||
|
||||
_ccsg.Node.prototype.setContentSize.call(this, contentSize);
|
||||
|
||||
this._tailoredTopY = contentSize.height;
|
||||
@@ -902,7 +911,7 @@ cc.BMFontHelper = {
|
||||
this._fontAtlas.assignLetterDefinitions(tempLetterDefinition);
|
||||
this._fontAtlas.scaleFontLetterDefinition(scale);
|
||||
this._lineHeight = originalLineHeight * scale;
|
||||
if (this._maxLineWidth > 0 && !this._lineBreakWithoutSpaces) {
|
||||
if (!this._lineBreakWithoutSpaces) {
|
||||
this._multilineTextWrapByWord();
|
||||
} else {
|
||||
this._multilineTextWrapByChar();
|
||||
@@ -1004,8 +1013,25 @@ cc.BMFontHelper = {
|
||||
}
|
||||
|
||||
var len = 1;
|
||||
var nextLetterX = 0;
|
||||
var letterDef;
|
||||
var letterX;
|
||||
for (var index = startIndex + 1; index < textLen; ++index) {
|
||||
character = text.charAt(index);
|
||||
//calculate the word boundary
|
||||
|
||||
letterDef = this._fontAtlas.getLetterDefinitionForChar(character);
|
||||
if (!letterDef) {
|
||||
break;
|
||||
}
|
||||
letterX = nextLetterX + letterDef._offsetX * this._bmfontScale;
|
||||
|
||||
if(letterX + letterDef._width * this._bmfontScale > this._maxLineWidth && !this._isspace_unicode(character) && this._maxLineWidth > 0) {
|
||||
if(len >= 2) {
|
||||
return len - 1;
|
||||
}
|
||||
}
|
||||
nextLetterX += letterDef._xAdvance * this._bmfontScale + this._additionalKerning;
|
||||
if (character === "\n" || this._isspace_unicode(character) || this._isCJK_unicode(character)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -241,7 +241,9 @@
|
||||
for (i = 0; i < paragraphedStrings.length; ++i) {
|
||||
totalLength += ((paragraphLength[i] / canvasWidthNoMargin + 1) | 0) * canvasWidthNoMargin;
|
||||
}
|
||||
var scale = canvasWidthNoMargin * ((this._canvasSize.height / this._getLineHeight()) | 0) / totalLength;
|
||||
var heightRatio = this._canvasSize.height / this._getLineHeight();
|
||||
heightRatio = heightRatio < 1 ? 1: heightRatio;
|
||||
var scale = canvasWidthNoMargin * (heightRatio | 0) / totalLength;
|
||||
node._fontSize = (drawFontize * Math.min(Math.sqrt(scale), 1)) | 0;
|
||||
fontDesc = node._fontSize.toString() + 'px ' + fontFamily;
|
||||
|
||||
|
||||
@@ -490,4 +490,10 @@ JS.mixin(cc.loader, {
|
||||
}
|
||||
});
|
||||
|
||||
if (CC_EDITOR) {
|
||||
cc.loader.refreshUrl = function (uuid, oldUrl, newUrl) {
|
||||
this._items.refreshItemUrl(uuid, oldUrl, newUrl);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = cc.loader;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
var JS = require('../platform/js');
|
||||
var Path = require('../utils/CCPath');
|
||||
var Pipeline = require('./pipeline');
|
||||
var PackDownloader = require('./pack-downloader');
|
||||
|
||||
var downloadAudio;
|
||||
if (!CC_EDITOR || !Editor.isMainProcess) {
|
||||
@@ -47,7 +48,7 @@ function isUrlCrossOrigin (url) {
|
||||
var endIndex = url.indexOf('/', startIndex + 3);
|
||||
var urlOrigin = (endIndex === -1) ? url : url.substring(0, endIndex);
|
||||
return urlOrigin !== location.origin;
|
||||
};
|
||||
}
|
||||
|
||||
var _noCacheRex = /\?/;
|
||||
function urlAppendTimestamp (url) {
|
||||
@@ -263,28 +264,30 @@ function downloadUuid (item, callback) {
|
||||
item.url = url;
|
||||
item.isRawAsset = isRawAsset;
|
||||
if (isRawAsset) {
|
||||
self.pipeline._items.map[url] = {
|
||||
id: url,
|
||||
url: url,
|
||||
type: Path.extname(url).toLowerCase().substr(1),
|
||||
error: null,
|
||||
alias: item.id,
|
||||
complete: true
|
||||
};
|
||||
|
||||
var ext = Path.extname(url).toLowerCase();
|
||||
if (!ext) {
|
||||
callback(new Error('Download Uuid: can not find type of raw asset[' + uuid + ']: ' + url));
|
||||
return;
|
||||
}
|
||||
ext = ext.substr(1);
|
||||
self.pipeline._items.map[url] = {
|
||||
id: url,
|
||||
url: url,
|
||||
type: ext,
|
||||
error: null,
|
||||
alias: item.id,
|
||||
complete: true
|
||||
};
|
||||
// Dispatch to other raw type downloader
|
||||
var downloadFunc = self.extMap[ext] || self.extMap['default'];
|
||||
item.type = ext;
|
||||
downloadFunc(item, callback);
|
||||
}
|
||||
else {
|
||||
self.extMap['json'](item, callback);
|
||||
var loadByPack = PackDownloader.load(item, callback);
|
||||
if (!loadByPack) {
|
||||
self.extMap['json'](item, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -339,9 +342,6 @@ var defaultMap = {
|
||||
|
||||
// Deserializer
|
||||
'uuid' : downloadUuid,
|
||||
'prefab' : downloadUuid,
|
||||
'fire' : downloadUuid,
|
||||
'scene' : downloadUuid,
|
||||
|
||||
'default' : downloadText
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
require('./downloader');
|
||||
require('./loader');
|
||||
require('./json-unpacker');
|
||||
|
||||
require('./loading-items');
|
||||
require('./pipeline');
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
function JsonUnpacker () {
|
||||
this.jsons = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String[]} indices
|
||||
* @param {String} data
|
||||
*/
|
||||
JsonUnpacker.prototype.read = function (indices, data) {
|
||||
var jsons = typeof data === 'string' ? JSON.parse(data) : data;
|
||||
if (jsons.length !== indices.length) {
|
||||
cc.error('Pack indices and data do not match in size');
|
||||
}
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var key = indices[i];
|
||||
var json = jsons[i];
|
||||
this.jsons[key] = json;
|
||||
}
|
||||
};
|
||||
|
||||
JsonUnpacker.prototype.retrieve = function (key) {
|
||||
return this.jsons[key] || null;
|
||||
};
|
||||
|
||||
if (CC_TEST) {
|
||||
cc._Test.JsonUnpacker = JsonUnpacker;
|
||||
}
|
||||
|
||||
module.exports = JsonUnpacker;
|
||||
@@ -267,4 +267,21 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, {
|
||||
}
|
||||
});
|
||||
|
||||
if (CC_EDITOR) {
|
||||
LoadingItems.prototype.refreshItemUrl = function (id, oldUrl, newUrl) {
|
||||
var item = this.map[id];
|
||||
if (item) {
|
||||
item.url = newUrl;
|
||||
}
|
||||
|
||||
item = this.map[oldUrl];
|
||||
if (item) {
|
||||
item.id = newUrl;
|
||||
item.url = newUrl;
|
||||
this.map[newUrl] = item;
|
||||
delete this.map[oldUrl];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = LoadingItems;
|
||||
@@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var JsonUnpacker = require('./json-unpacker');
|
||||
|
||||
// {assetUuid: packUuid}
|
||||
var uuidToPack = {};
|
||||
// {packUuid: assetIndices}
|
||||
var packIndices = {};
|
||||
|
||||
// {packUuid: JsonUnpacker}
|
||||
// We have to cache all packs in global because for now there's no operation context in loader.
|
||||
var globalUnpackers = {};
|
||||
|
||||
function error (callback, uuid, packUuid) {
|
||||
callback(new Error('Can not retrieve ' + uuid + ' from packer ' + packUuid));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initPacks: function (packs) {
|
||||
packIndices = packs;
|
||||
for (var packUuid in packs) {
|
||||
var uuids = packs[packUuid];
|
||||
for (var i = 0; i < uuids.length; i++) {
|
||||
var uuid = uuids[i];
|
||||
uuidToPack[uuid] = packUuid;
|
||||
}
|
||||
}
|
||||
},
|
||||
//getPackUuid: function (uuid) {
|
||||
// return uuidToPack[uuid];
|
||||
//},
|
||||
|
||||
_loadNewPack: function (uuid, packUuid, callback) {
|
||||
var packUrl = cc.AssetLibrary.getImportedDir(packUuid) + '/' + packUuid + '.json';
|
||||
cc.loader.load(packUrl, function (err, packJson) {
|
||||
if (err) {
|
||||
cc.error('Failed to download package for ' + uuid);
|
||||
return callback(err);
|
||||
}
|
||||
// double check cache after load
|
||||
var unpacker = globalUnpackers[packUuid];
|
||||
if (!unpacker) {
|
||||
console.log('Load pack %s for %s', packUuid, uuid);
|
||||
unpacker = globalUnpackers[packUuid] = new JsonUnpacker();
|
||||
}
|
||||
unpacker.read(packIndices[packUuid], packJson);
|
||||
var json = unpacker.retrieve(uuid);
|
||||
if (json) {
|
||||
callback(null, json);
|
||||
}
|
||||
else {
|
||||
error(callback, uuid, packUuid);
|
||||
}
|
||||
});
|
||||
//var packItem = {
|
||||
// id: packUrl,
|
||||
// type: 'json',
|
||||
// uuid: packUuid
|
||||
//};
|
||||
//pipeline.flowInDeps(depends, function (items) {
|
||||
//});
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Boolean} specify whether loaded by pack
|
||||
*/
|
||||
load: function (item, callback) {
|
||||
var uuid = item.id;
|
||||
var packUuid = uuidToPack[uuid];
|
||||
if (!packUuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var unpacker = globalUnpackers[packUuid];
|
||||
if (unpacker) {
|
||||
var json = unpacker.retrieve(uuid);
|
||||
if (json) {
|
||||
callback(null, json);
|
||||
}
|
||||
else {
|
||||
error(callback, uuid, packUuid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._loadNewPack(uuid, packUuid, callback);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -46,15 +46,18 @@ function loadDepends (pipeline, item, asset, tdInfo, callback) {
|
||||
var ownerList = JS.array.copy(tdInfo.uuidObjList);
|
||||
var propList = JS.array.copy(tdInfo.uuidPropList);
|
||||
|
||||
var depends = new Array(dependsSrcs.length);
|
||||
var depends = [];
|
||||
// load depends assets
|
||||
for (var i = 0; i < dependsSrcs.length; i++) {
|
||||
var dependSrc = dependsSrcs[i];
|
||||
depends[i] = {
|
||||
if (dependSrc === uuid) {
|
||||
continue;
|
||||
}
|
||||
depends.push({
|
||||
id: dependSrc,
|
||||
type: 'uuid',
|
||||
uuid: dependSrc
|
||||
};
|
||||
});
|
||||
}
|
||||
// load raw
|
||||
if (tdInfo.rawProp) {
|
||||
@@ -104,6 +107,9 @@ function loadDepends (pipeline, item, asset, tdInfo, callback) {
|
||||
}
|
||||
asset._uuid = uuid;
|
||||
callback(null, asset);
|
||||
if (CC_EDITOR) {
|
||||
cc.loader.removeItem(uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
var Asset = require('../assets/CCAsset');
|
||||
var callInNextTick = require('./utils').callInNextTick;
|
||||
var Loader = require('../load-pipeline/CCLoader');
|
||||
var PackDownloader = require('../load-pipeline/pack-downloader');
|
||||
|
||||
/**
|
||||
* The asset library which managing loading/unloading assets in project.
|
||||
@@ -38,7 +39,7 @@ var Loader = require('../load-pipeline/CCLoader');
|
||||
|
||||
var _libraryBase = '';
|
||||
var _rawAssetsBase = ''; // The base dir for raw assets in runtime
|
||||
var _uuidToRawAssets;
|
||||
var _uuidToRawAsset = {};
|
||||
|
||||
function isScene (asset) {
|
||||
return asset && (asset.constructor === cc.SceneAsset || asset instanceof cc.Scene);
|
||||
@@ -107,7 +108,7 @@ var AssetLibrary = {
|
||||
},
|
||||
|
||||
_getAssetInfoInRuntime: function (uuid) {
|
||||
var info = _uuidToRawAssets[uuid];
|
||||
var info = _uuidToRawAsset[uuid];
|
||||
if (info && !cc.isChildClassOf(info.type, cc.Asset)) {
|
||||
return {
|
||||
url: _rawAssetsBase + info.url,
|
||||
@@ -249,6 +250,7 @@ var AssetLibrary = {
|
||||
* @param {Object} options.mountPaths - mount point of actual urls for raw assets (only used in editor)
|
||||
* @param {Object} [options.rawAssets] - uuid to raw asset's urls (only used in runtime)
|
||||
* @param {String} [options.rawAssetsBase] - base of raw asset's urls (only used in runtime)
|
||||
* @param {String} [options.packedAssets] - packed assets (only used in runtime)
|
||||
*/
|
||||
init: function (options) {
|
||||
if (CC_EDITOR && _libraryBase) {
|
||||
@@ -264,7 +266,8 @@ var AssetLibrary = {
|
||||
|
||||
_rawAssetsBase = options.rawAssetsBase;
|
||||
|
||||
_uuidToRawAssets = {};
|
||||
// init raw assets
|
||||
|
||||
var resources = Loader._resources;
|
||||
resources.reset();
|
||||
var rawAssets = options.rawAssets;
|
||||
@@ -281,7 +284,7 @@ var AssetLibrary = {
|
||||
cc.error('Cannot get', typeId);
|
||||
continue;
|
||||
}
|
||||
_uuidToRawAssets[uuid] = {
|
||||
_uuidToRawAsset[uuid] = {
|
||||
url: mountPoint + '/' + url,
|
||||
type: type,
|
||||
};
|
||||
@@ -309,6 +312,12 @@ var AssetLibrary = {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.packedAssets) {
|
||||
PackDownloader.initPacks(options.packedAssets);
|
||||
}
|
||||
|
||||
// init mount paths
|
||||
|
||||
var mountPaths = options.mountPaths;
|
||||
if (!mountPaths) {
|
||||
mountPaths = {
|
||||
|
||||
@@ -109,6 +109,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
return this._name;
|
||||
},
|
||||
set: function (value) {
|
||||
if (CC_DEV && value.indexOf('/') !== -1) {
|
||||
cc.error('Node name can not include \'/\'.');
|
||||
return;
|
||||
}
|
||||
this._name = value;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -167,7 +167,7 @@ cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function () {
|
||||
}
|
||||
});
|
||||
|
||||
cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () {
|
||||
cc.game.on(cc.game.EVENT_SHOW, function () {
|
||||
var list = _ccsg.VideoPlayer.pauseElements;
|
||||
var node = list.pop();
|
||||
while(node){
|
||||
|
||||
@@ -9,7 +9,7 @@ const Fs = require('fire-fs');
|
||||
const Path = require('fire-path');
|
||||
const Spine = require('../lib/spine');
|
||||
|
||||
const ATLAS_EXTS = ['.atlas', '.txt', ''];
|
||||
const ATLAS_EXTS = ['.atlas', '.txt', '.atlas.txt', ''];
|
||||
const SPINE_ENCODING = { encoding: 'utf-8' };
|
||||
|
||||
const CustomAssetMeta = Editor.metas['custom-asset'];
|
||||
@@ -62,16 +62,18 @@ class TextureParser {
|
||||
var base = Path.dirname(this.atlasPath);
|
||||
var path = Path.resolve(base, name);
|
||||
var uuid = Editor.assetdb.fspathToUuid(path);
|
||||
if (!uuid) {
|
||||
return;
|
||||
if (uuid) {
|
||||
console.log('UUID is initialized for "%s".', path);
|
||||
var url = Editor.assetdb.uuidToUrl(uuid);
|
||||
this.textures.push(url);
|
||||
}
|
||||
else if (!Fs.existsSync(path)) {
|
||||
Editor.error('Can not find texture "%s" for atlas "%s"', line, this.atlasPath);
|
||||
}
|
||||
else {
|
||||
// AssetDB may call postImport more than once, we can get uuid in the next time.
|
||||
console.warn('WARN: UUID not yet initialized for "%s".', path);
|
||||
}
|
||||
//if (!uuid) {
|
||||
// cc.error('Can not find texture "%s" for atlas "%s"', line, this.atlasPath);
|
||||
// return;
|
||||
//}
|
||||
//var texture = Editor.serialize.asAsset(uuid);
|
||||
var url = Editor.assetdb.uuidToUrl(uuid);
|
||||
this.textures.push(url);
|
||||
}
|
||||
unload () {}
|
||||
}
|
||||
@@ -136,7 +138,7 @@ class SpineMeta extends CustomAssetMeta {
|
||||
return res;
|
||||
}
|
||||
|
||||
import (fspath, cb) {
|
||||
postImport (fspath, cb) {
|
||||
Fs.readFile(fspath, SPINE_ENCODING, (err, data) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
|
||||
+10
-2
@@ -144,7 +144,11 @@ function rebundle_html_dev_min(bundler) {
|
||||
.pipe(sourcemaps.init({loadMaps: true}))
|
||||
.pipe(mirror(pipe(devPipes), pipe(minPipes)))
|
||||
.pipe(printSizes(sizeGetter, minSizeGetter, zippedSizeGetter))
|
||||
.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true}))
|
||||
.pipe(sourcemaps.write('./', {
|
||||
sourceRoot: './',
|
||||
includeContent: true,
|
||||
addComment: true
|
||||
}))
|
||||
.pipe(gulp.dest(paths.outDir));
|
||||
}
|
||||
|
||||
@@ -167,7 +171,11 @@ function rebundle(bundler, name, options) {
|
||||
}
|
||||
bundle = bundle.pipe(uglify(getUglifyOptions(minify, macros)));
|
||||
if (sourceMaps) {
|
||||
bundle = bundle.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true}));
|
||||
bundle = bundle.pipe(sourcemaps.write('./', {
|
||||
sourceRoot: '../',
|
||||
includeContent: false,
|
||||
addComment: true
|
||||
}));
|
||||
}
|
||||
}
|
||||
bundle = bundle.pipe(gulp.dest(paths.outDir));
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
module('JSON packer/unpacker');
|
||||
|
||||
(function () {
|
||||
var KEY1 = 'amitabha';
|
||||
var JSON1 = {
|
||||
__born__: 1985,
|
||||
$$: 'Amoy'
|
||||
};
|
||||
var KEY2 = 'hallelujah';
|
||||
var JSON2 = [{
|
||||
text: 'hallelujah\nalujah\\alujah...\uD83D\uDE02'
|
||||
}];
|
||||
|
||||
test('pack nothing', function () {
|
||||
var packer = new Editor.JsonPacker();
|
||||
var res = packer.pack();
|
||||
ok(res.indices, 'should pack empty indices');
|
||||
ok(res.data && typeof res.data === 'string', 'should pack empty data');
|
||||
});
|
||||
|
||||
test('unpack nothing', function () {
|
||||
var unpacker = new cc._Test.JsonUnpacker();
|
||||
var res = unpacker.retrieve('non-exists key');
|
||||
ok(!res, 'chould not unpack if key is invalid');
|
||||
});
|
||||
|
||||
test('pack something', function () {
|
||||
var packer = new Editor.JsonPacker();
|
||||
packer.add(KEY2, JSON2);
|
||||
packer.add(KEY1, JSON1);
|
||||
var res = packer.pack();
|
||||
|
||||
ok(res.indices.indexOf(KEY1) !== -1 && res.indices.indexOf(KEY2) !== -1, 'should generate index data when packing');
|
||||
|
||||
var unpacker = new cc._Test.JsonUnpacker();
|
||||
unpacker.read(res.indices, res.data);
|
||||
deepEqual(unpacker.retrieve(KEY1), JSON1, 'should unpack JSON1');
|
||||
deepEqual(unpacker.retrieve(KEY2), JSON2, 'should unpack JSON2');
|
||||
});
|
||||
|
||||
//test('unpack speed', function () {
|
||||
// var bigJson = Editor.serialize(new cc.Node());
|
||||
// var packer = new Editor.JsonPacker();
|
||||
// for (var i = 0; i < 100; ++i) {
|
||||
// packer.add('' + i, bigJson);
|
||||
// }
|
||||
// var res = packer.pack();
|
||||
//
|
||||
// console.time('unpack time');
|
||||
//
|
||||
// var unpacker = new cc._Test.JsonUnpacker();
|
||||
// unpacker.read(res.indices, res.data);
|
||||
// for (var i = 0; i < 100; ++i) {
|
||||
// unpacker.retrieve('' + i);
|
||||
// }
|
||||
//
|
||||
// console.timeEnd('unpack time');
|
||||
// ok(true);
|
||||
//});
|
||||
})();
|
||||
Reference in New Issue
Block a user