mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge pull request #114 from jareguo/master
support mounted raw assets in build version
This commit is contained in:
@@ -14,7 +14,8 @@ var CallbacksInvoker = require('./callbacks-invoker');
|
||||
// configs
|
||||
|
||||
var _libraryBase = '';
|
||||
var _uuidToRawAssets = {};
|
||||
var _rawAssetsBase = ''; // The base dir for raw assets in runtime
|
||||
var _uuidToRawAssets;
|
||||
|
||||
// variables
|
||||
|
||||
@@ -137,7 +138,7 @@ var AssetLibrary = {
|
||||
var info = _uuidToRawAssets[uuid];
|
||||
if (info) {
|
||||
return {
|
||||
url: cc.url._rawAssets + info.url,
|
||||
url: _rawAssetsBase + info.url,
|
||||
raw: info.raw,
|
||||
};
|
||||
}
|
||||
@@ -510,11 +511,12 @@ var AssetLibrary = {
|
||||
* init the asset library
|
||||
*
|
||||
* @method init
|
||||
* @param {String} libraryPath - 能接收的任意类型的路径,通常在编辑器里使用绝对的,在网页里使用相对的。
|
||||
* @param {Object} mountPaths - mount point of actual urls for raw assets
|
||||
* @param {Object} [rawAssets] - uuid to raw asset's urls (only used in runtime)
|
||||
* @param {String} options.libraryPath - 能接收的任意类型的路径,通常在编辑器里使用绝对的,在网页里使用相对的。
|
||||
* @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)
|
||||
*/
|
||||
init: function (libraryPath, mountPaths, rawAssets) {
|
||||
init: function (options) {
|
||||
if (CC_EDITOR && _libraryBase) {
|
||||
cc.error('AssetLibrary has already been initialized!');
|
||||
return;
|
||||
@@ -522,11 +524,34 @@ var AssetLibrary = {
|
||||
|
||||
// 这里将路径转 url,不使用路径的原因是有的 runtime 不能解析 "\" 符号。
|
||||
// 不使用 url.format 的原因是 windows 不支持 file:// 和 /// 开头的协议,所以只能用 replace 操作直接把路径转成 URL。
|
||||
var libraryPath = options.libraryPath;
|
||||
libraryPath = libraryPath.replace(/\\/g, '/');
|
||||
|
||||
_libraryBase = cc.path._setEndWithSep(libraryPath, '/');
|
||||
_uuidToRawAssets = rawAssets || {};
|
||||
|
||||
_rawAssetsBase = options.rawAssetsBase;
|
||||
|
||||
_uuidToRawAssets = {};
|
||||
var rawAssets = options.rawAssets;
|
||||
if (rawAssets) {
|
||||
for (var mountPoint in rawAssets) {
|
||||
var assets = rawAssets[mountPoint];
|
||||
for (var uuid in assets) {
|
||||
var info = assets[uuid];
|
||||
_uuidToRawAssets[uuid] = {
|
||||
url: mountPoint + '/' + info.url,
|
||||
raw: !!info.raw,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mountPaths = options.mountPaths;
|
||||
if (!mountPaths) {
|
||||
mountPaths = {
|
||||
assets: _rawAssetsBase + 'assets',
|
||||
internal: _rawAssetsBase + 'internal',
|
||||
}
|
||||
}
|
||||
cc.url._init(mountPaths);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -443,7 +443,6 @@ JS.get(Vec2, 'RIGHT', function () {
|
||||
});
|
||||
|
||||
cc.Vec2 = Vec2;
|
||||
var proto = Vec2.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
+3
-1
@@ -28,7 +28,9 @@ Editor.require('app://builtin/fire-assets/init');
|
||||
Editor.require('app://engine');
|
||||
|
||||
// init asset library
|
||||
cc.AssetLibrary.init( Path.resolve(Path.join(__dirname, 'fixtures/library')) );
|
||||
cc.AssetLibrary.init({
|
||||
libraryPath: Path.resolve(Path.join(__dirname, 'fixtures/library'))
|
||||
});
|
||||
|
||||
describe('test wrappers', function () {
|
||||
// test wrappers
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
largeModule('AssetLibrary', {
|
||||
setup: function () {
|
||||
_resetGame();
|
||||
AssetLibrary.init(libPath);
|
||||
AssetLibrary.init({libraryPath: libPath});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
largeModule('Prefab', {
|
||||
setup: function () {
|
||||
_resetGame();
|
||||
AssetLibrary.init('../assets/library');
|
||||
AssetLibrary.init({libraryPath: '../assets/library'});
|
||||
},
|
||||
//teardownOnce: function () {
|
||||
// console.log('teardownOnce');
|
||||
|
||||
Reference in New Issue
Block a user