大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

120 lines
3.8 KiB

function __initApp () { // init app
globalThis.__wxRequire = require; // FIX: require cannot work in separate engine
require('./web-adapter');
const firstScreen = require('./first-screen');
// IAA插件标记
const openIAA = false;
const defaultIAA = false;
if(window["ks"]){
const TDAnalytics = require('./tdanalytics.mg.ks.min.js');
globalThis.TDAnalytics = TDAnalytics;
}else{
const TDAnalytics = require('./tdanalytics.mg.wx.min.js');
globalThis.TDAnalytics = TDAnalytics;
if(openIAA){
const IAASDK = require('./iaa.js');
window.IAASDK = IAASDK;
window.ChannelUpload = require("./channel_upload.js");
}else if(defaultIAA){
try {
if (typeof requirePlugin !== 'undefined') {
console.log("开始加载iaa插件");
const createMiniGameCommon = requirePlugin('MiniGameCommon', {
enableRequireHostModule: true,
customEnv: {
wx,
},
}).default;
const miniGameCommon = createMiniGameCommon();
if (typeof miniGameCommon === 'undefined' || typeof miniGameCommon.canIUse === 'undefined') {
// 插件初始化失败
console.error('miniGameCommon create error');
} else {
// 插件初始化成功
window.miniGameCommon = miniGameCommon;
}
}
} catch (e) {
// 基础库版本过低
console.error("iaa插件错误",e);
}
}
}
<%- include(cocosTemplate, {}) %>
// Adapt for IOS, swap if opposite
const info = wx.getSystemInfoSync();
if (canvas){
var _w = canvas.width;
var _h = canvas.height;
if (info.screenWidth < info.screenHeight) {
if (canvas.width > canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
} else {
if (canvas.width < canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
}
canvas.width = _w;
canvas.height = _h;
}
// Adjust initial canvas size
if (canvas && window.devicePixelRatio >= 2) {canvas.width *= info.devicePixelRatio; canvas.height *= info.devicePixelRatio;}
const importMap = require("<%= importMapFile%>").default;
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require('.' + urlNoSchema);
},
handlers: {
'plugin:': (urlNoSchema) => {
requirePlugin(urlNoSchema);
},
'project:': (urlNoSchema) => {
require(urlNoSchema);
},
},
});
firstScreen.start('<%= alpha %>', '<%= antialias %>', '<%= useWebgl2 %>').then(() => {
return System.import('<%= applicationJs %>');
}).then((module) => {
return firstScreen.setProgress(0.2).then(() => Promise.resolve(module));
}).then(({ Application }) => {
return new Application();
}).then((application) => {
return firstScreen.setProgress(0.4).then(() => Promise.resolve(application));
}).then((application) => {
return onApplicationCreated(application);
}).catch((err) => {
console.error(err);
});
function onApplicationCreated(application) {
return System.import('cc').then((module) => {
return firstScreen.setProgress(0.6).then(() => Promise.resolve(module));
}).then((cc) => {
require('./engine-adapter');
return application.init(cc);
}).then(() => {
return firstScreen.end().then(() => application.start());
});
}
} // init app
// NOTE: on WeChat Android end, we can only get the correct screen size at the second tick of game.
var sysInfo = wx.getSystemInfoSync();
if (sysInfo.platform.toLocaleLowerCase() === 'android') {
GameGlobal.requestAnimationFrame (__initApp);
} else {
__initApp();
}