|
| 1 | +<% if (isUsePhysX) { %> |
| 2 | +const systemInfo = tt.getSystemInfoSync(); |
| 3 | +// a hack way to load physics provide by bytedance |
| 4 | +if (tt.getPhysx) { |
| 5 | + tt.getPhysx({ |
| 6 | + success (physx) { |
| 7 | + if (!physx) { |
| 8 | + console.error('can not use native PhysX'); |
| 9 | + } else { |
| 10 | + console.info('physics plugin load success, version=' + physx.getVersion()); |
| 11 | + GameGlobal.nativePhysX = physx; |
| 12 | + } |
| 13 | + loadCC(); |
| 14 | + }, |
| 15 | + fail () { |
| 16 | + loadCC(); |
| 17 | + } |
| 18 | + }); |
| 19 | +} else if (systemInfo.platform === 'android' && tt.getLoader && tt.getLoader()) { |
| 20 | + const appid = "<%= appid %>"; |
| 21 | + const loader = tt.getLoader().loader; |
| 22 | + loader.load('physics', appid, "token", message => { |
| 23 | + if (message) { |
| 24 | + console.error('[tt.loader]:' + message); |
| 25 | + } else { |
| 26 | + console.info('[tt.loader]: physics plugin load success, version=' + tt.getPhy().getVersion()); |
| 27 | + GameGlobal.nativePhysX = tt.getPhy(); |
| 28 | + } |
| 29 | + loadCC(); |
| 30 | + }) |
| 31 | +} else { |
| 32 | + loadCC(); |
| 33 | +} |
| 34 | +<% } %> |
| 35 | + |
| 36 | +<% if (!isUsePhysX) { %> |
| 37 | +loadCC(); |
| 38 | +<% } %> |
| 39 | + |
| 40 | +function loadCC() { |
| 41 | + require('./web-adapter'); |
| 42 | + |
| 43 | +<% if(polyfillsBundleFile) { %> |
| 44 | + // Polyfills bundle. |
| 45 | + require("<%= polyfillsBundleFile %>"); |
| 46 | +<% } %> |
| 47 | + |
| 48 | + // SystemJS support. |
| 49 | + require("<%= systemJsBundleFile %>"); |
| 50 | + |
| 51 | + // Adapt for IOS, swap if opposite |
| 52 | + if (canvas){ |
| 53 | + var _w = canvas.width; |
| 54 | + var _h = canvas.height; |
| 55 | + if (screen.width < screen.height) { |
| 56 | + if (canvas.width > canvas.height) { |
| 57 | + _w = canvas.height; |
| 58 | + _h = canvas.width; |
| 59 | + } |
| 60 | + } else { |
| 61 | + if (canvas.width < canvas.height) { |
| 62 | + _w = canvas.height; |
| 63 | + _h = canvas.width; |
| 64 | + } |
| 65 | + } |
| 66 | + canvas.width = _w; |
| 67 | + canvas.height = _h; |
| 68 | + } |
| 69 | + |
| 70 | + // Adjust initial canvas size |
| 71 | + if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;} |
| 72 | + |
| 73 | + const importMap = require("<%= importMapFile%>").default; |
| 74 | + System.warmup({ |
| 75 | + importMap, |
| 76 | + importMapUrl: '<%= importMapFile%>', |
| 77 | + defaultHandler: (urlNoSchema) => { |
| 78 | + require('.' + urlNoSchema); |
| 79 | + }, |
| 80 | + handlers: { |
| 81 | + 'plugin:': (urlNoSchema) => { |
| 82 | + typeof requirePlugin === 'function' ? requirePlugin(urlNoSchema) : require(urlNoSchema); |
| 83 | + }, |
| 84 | + 'project:': (urlNoSchema) => { |
| 85 | + require(urlNoSchema); |
| 86 | + }, |
| 87 | + }, |
| 88 | + }); |
| 89 | + |
| 90 | + System.import('<%= applicationJs %>').then(({ Application }) => { |
| 91 | + return new Application(); |
| 92 | + }).then((application) => { |
| 93 | + return onApplicationCreated(application); |
| 94 | + }).catch((err) => { |
| 95 | + console.error(err); |
| 96 | + }); |
| 97 | + |
| 98 | + function onApplicationCreated(application) { |
| 99 | + return System.import('cc').then((cc) => { |
| 100 | + require('./engine-adapter'); |
| 101 | + return application.init(cc); |
| 102 | + }).then(() => { return application.start(); }); |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments