mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 12:25:23 +00:00
[adapters] 增加小游戏适配部分源码
This commit is contained in:
11
adapters/platforms/bytedance/res/ccRequire.js
Normal file
11
adapters/platforms/bytedance/res/ccRequire.js
Normal file
@@ -0,0 +1,11 @@
|
||||
let moduleMap = {
|
||||
// tail
|
||||
};
|
||||
|
||||
window.__cocos_require__ = function (moduleName) {
|
||||
let func = moduleMap[moduleName];
|
||||
if (!func) {
|
||||
throw new Error(`cannot find module ${moduleName}`);
|
||||
}
|
||||
return func();
|
||||
};
|
3
adapters/platforms/bytedance/res/cocos/plugin.json
Normal file
3
adapters/platforms/bytedance/res/cocos/plugin.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"main": "cocos2d-js-min.js"
|
||||
}
|
9
adapters/platforms/bytedance/res/cocos/signature.json
Normal file
9
adapters/platforms/bytedance/res/cocos/signature.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"provider": "tt9186e73b0ebd04c2",
|
||||
"signature": [
|
||||
{
|
||||
"path": "cocos2d-js-min.js",
|
||||
"md5": ""
|
||||
}
|
||||
]
|
||||
}
|
20
adapters/platforms/bytedance/res/game.js
Normal file
20
adapters/platforms/bytedance/res/game.js
Normal file
@@ -0,0 +1,20 @@
|
||||
require('adapter-js-path');
|
||||
__globalAdapter.init();
|
||||
require('cocos2d-js-path');
|
||||
require('physics-js-path');
|
||||
__globalAdapter.adaptEngine();
|
||||
require('./ccRequire');
|
||||
|
||||
require('./src/settings');
|
||||
// Introduce Cocos Service here
|
||||
require('./main'); // TODO: move to common
|
||||
|
||||
// Adjust devicePixelRatio
|
||||
cc.view._maxPixelRatio = 4;
|
||||
|
||||
if (cc.sys.platform !== cc.sys.BYTEDANCE_GAME_SUB) {
|
||||
// Release Image objects after uploaded gl texture
|
||||
cc.macro.CLEANUP_IMAGE_CACHE = true;
|
||||
}
|
||||
|
||||
window.boot();
|
18
adapters/platforms/bytedance/res/game.json
Normal file
18
adapters/platforms/bytedance/res/game.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"deviceOrientation": "portrait",
|
||||
"showStatusBar": false,
|
||||
"openDataContext": "",
|
||||
"networkTimeout": {
|
||||
"request": 5000,
|
||||
"connectSocket": 20000,
|
||||
"uploadFile": 5000,
|
||||
"downloadFile": 5000
|
||||
},
|
||||
"plugins": {
|
||||
"cocos": {
|
||||
"provider": "tt9186e73b0ebd04c2",
|
||||
"version": "",
|
||||
"path": "cocos"
|
||||
}
|
||||
}
|
||||
}
|
67
adapters/platforms/bytedance/res/main.js
Normal file
67
adapters/platforms/bytedance/res/main.js
Normal file
@@ -0,0 +1,67 @@
|
||||
window.boot = function () {
|
||||
var settings = window._CCSettings;
|
||||
window._CCSettings = undefined;
|
||||
|
||||
var onStart = function () {
|
||||
cc.view.enableRetina(true);
|
||||
cc.view.resizeWithBrowserSize(true);
|
||||
|
||||
var launchScene = settings.launchScene;
|
||||
|
||||
// load scene
|
||||
cc.director.loadScene(launchScene, null,
|
||||
function () {
|
||||
console.log('Success to load scene: ' + launchScene);
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
var isSubContext = __globalAdapter.isSubContext;
|
||||
|
||||
var option = {
|
||||
id: 'GameCanvas',
|
||||
debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
|
||||
showFPS: !isSubContext && settings.debug,
|
||||
frameRate: 60,
|
||||
groupList: settings.groupList,
|
||||
collisionMatrix: settings.collisionMatrix,
|
||||
}
|
||||
|
||||
cc.assetManager.init({
|
||||
bundleVers: settings.bundleVers,
|
||||
subpackages: settings.subpackages,
|
||||
remoteBundles: settings.remoteBundles,
|
||||
server: settings.server,
|
||||
subContextRoot: settings.subContextRoot
|
||||
});
|
||||
|
||||
var RESOURCES = cc.AssetManager.BuiltinBundleName.RESOURCES;
|
||||
var INTERNAL = cc.AssetManager.BuiltinBundleName.INTERNAL;
|
||||
var MAIN = cc.AssetManager.BuiltinBundleName.MAIN;
|
||||
var START_SCENE = cc.AssetManager.BuiltinBundleName.START_SCENE;
|
||||
var bundleRoot = [INTERNAL];
|
||||
settings.hasResourcesBundle && bundleRoot.push(RESOURCES);
|
||||
settings.hasStartSceneBundle && bundleRoot.push(MAIN);
|
||||
|
||||
var count = 0;
|
||||
function cb (err) {
|
||||
if (err) return console.error(err.message, err.stack);
|
||||
count++;
|
||||
if (count === bundleRoot.length + 1) {
|
||||
// if there is start-scene bundle. should load start-scene bundle in the last stage
|
||||
// Otherwise the main bundle should be the last
|
||||
cc.assetManager.loadBundle(settings.hasStartSceneBundle ? START_SCENE : MAIN, function (err) {
|
||||
if (!err) cc.game.run(option, onStart);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// load plugins
|
||||
cc.assetManager.loadScript(settings.jsList.map(function (x) { return 'src/' + x;}), cb);
|
||||
|
||||
// load bundles
|
||||
for (var i = 0; i < bundleRoot.length; i++) {
|
||||
cc.assetManager.loadBundle(bundleRoot[i], cb);
|
||||
}
|
||||
};
|
11
adapters/platforms/bytedance/res/project.config.json
Normal file
11
adapters/platforms/bytedance/res/project.config.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"setting": {
|
||||
"urlCheck": true,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"newFeature": true
|
||||
},
|
||||
"appid": "testappId",
|
||||
"projectname": ""
|
||||
}
|
Reference in New Issue
Block a user