@playcraft/build 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzers/scene-asset-collector.js +99 -9
- package/dist/base-builder.d.ts +15 -78
- package/dist/base-builder.js +34 -741
- package/dist/engines/engine-detector.d.ts +38 -0
- package/dist/engines/engine-detector.js +201 -0
- package/dist/engines/generic-adapter.d.ts +71 -0
- package/dist/engines/generic-adapter.js +378 -0
- package/dist/engines/index.d.ts +7 -0
- package/dist/engines/index.js +7 -0
- package/dist/engines/playcanvas-adapter.d.ts +85 -0
- package/dist/engines/playcanvas-adapter.js +813 -0
- package/dist/generators/config-generator.js +59 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/loaders/playcraft-loader.js +240 -5
- package/dist/platforms/adikteev.d.ts +1 -1
- package/dist/platforms/adikteev.js +30 -36
- package/dist/platforms/applovin.d.ts +1 -1
- package/dist/platforms/applovin.js +31 -36
- package/dist/platforms/base.d.ts +27 -5
- package/dist/platforms/base.js +79 -181
- package/dist/platforms/bigo.d.ts +1 -1
- package/dist/platforms/bigo.js +28 -28
- package/dist/platforms/facebook.d.ts +1 -1
- package/dist/platforms/facebook.js +21 -10
- package/dist/platforms/google.d.ts +1 -1
- package/dist/platforms/google.js +28 -21
- package/dist/platforms/index.d.ts +1 -0
- package/dist/platforms/index.js +4 -0
- package/dist/platforms/inmobi.d.ts +1 -1
- package/dist/platforms/inmobi.js +27 -34
- package/dist/platforms/ironsource.d.ts +1 -1
- package/dist/platforms/ironsource.js +37 -40
- package/dist/platforms/liftoff.d.ts +1 -1
- package/dist/platforms/liftoff.js +22 -30
- package/dist/platforms/mintegral.d.ts +10 -0
- package/dist/platforms/mintegral.js +65 -0
- package/dist/platforms/moloco.d.ts +1 -1
- package/dist/platforms/moloco.js +18 -20
- package/dist/platforms/playcraft.d.ts +1 -1
- package/dist/platforms/playcraft.js +2 -2
- package/dist/platforms/remerge.d.ts +1 -1
- package/dist/platforms/remerge.js +19 -20
- package/dist/platforms/snapchat.d.ts +1 -1
- package/dist/platforms/snapchat.js +32 -26
- package/dist/platforms/tiktok.d.ts +1 -1
- package/dist/platforms/tiktok.js +28 -24
- package/dist/platforms/unity.d.ts +1 -1
- package/dist/platforms/unity.js +30 -36
- package/dist/playable-builder.d.ts +1 -0
- package/dist/playable-builder.js +16 -2
- package/dist/types.d.ts +113 -1
- package/dist/types.js +77 -1
- package/dist/utils/ammo-detector.d.ts +9 -0
- package/dist/utils/ammo-detector.js +76 -0
- package/dist/utils/build-mode-detector.js +2 -0
- package/dist/utils/minify.d.ts +32 -0
- package/dist/utils/minify.js +82 -0
- package/dist/utils/obfuscate.d.ts +42 -0
- package/dist/utils/obfuscate.js +216 -0
- package/dist/vite/config-builder-generic.d.ts +70 -0
- package/dist/vite/config-builder-generic.js +251 -0
- package/dist/vite/config-builder.d.ts +8 -0
- package/dist/vite/config-builder.js +53 -16
- package/dist/vite/platform-configs.js +29 -1
- package/dist/vite/plugin-compress-js.d.ts +21 -0
- package/dist/vite/plugin-compress-js.js +213 -0
- package/dist/vite/plugin-esm-html-generator.js +5 -1
- package/dist/vite/plugin-obfuscate.d.ts +22 -0
- package/dist/vite/plugin-obfuscate.js +52 -0
- package/dist/vite/plugin-platform.d.ts +5 -0
- package/dist/vite/plugin-platform.js +499 -35
- package/dist/vite/plugin-playcanvas.js +21 -68
- package/dist/vite/plugin-source-builder.js +102 -21
- package/dist/vite-builder.d.ts +25 -7
- package/dist/vite-builder.js +141 -52
- package/package.json +4 -2
- package/physics/cannon-rigidbody-adapter.js +243 -22
- package/templates/__loading__.js +0 -12
- package/templates/index.esm.mjs +0 -11
- package/templates/patches/playcraft-cta-adapter.js +129 -31
- package/templates/patches/scene-physics-defaults.js +49 -0
|
@@ -3,10 +3,44 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 提供统一的 API 接口,自动适配不同渠道的 CTA 调用方式
|
|
5
5
|
* 游戏开发者只需调用 window.PlayCraftCTA.jump() 即可
|
|
6
|
+
*
|
|
7
|
+
* 支持的广告渠道:
|
|
8
|
+
* MRAID - mraid.open(url)
|
|
9
|
+
* DAPI - dapi.openStoreUrl()
|
|
10
|
+
* Nucleo - NUC.trigger.convert(url)
|
|
11
|
+
* BigoAds - BGY_MRAID.open()
|
|
12
|
+
* Facebook - FbPlayableAd.onCTAClick()
|
|
13
|
+
* Snapchat - snapchatCta()
|
|
14
|
+
* Smadex - smxTracking.redirect()
|
|
15
|
+
* Vungle - parent.postMessage('download','*')
|
|
16
|
+
* Google - ExitApi.exit()
|
|
17
|
+
* Mintegral - window.install()
|
|
18
|
+
* Tapjoy - TJ_API.click()
|
|
19
|
+
* TikTok - window.openAppStore()
|
|
20
|
+
* 其他/兜底 - window.open(url)
|
|
6
21
|
*/
|
|
7
22
|
(function() {
|
|
8
23
|
'use strict';
|
|
9
24
|
|
|
25
|
+
// 商店跳转地址:优先读取构建时注入的全局变量,无则留空(由平台 SDK 接管)
|
|
26
|
+
var _storeUrls = (typeof window !== 'undefined' && window.__PLAYCRAFT_STORE_URLS__) || {};
|
|
27
|
+
var IOS_STORE_URL = _storeUrls.ios || '';
|
|
28
|
+
var ANDROID_STORE_URL = _storeUrls.android || '';
|
|
29
|
+
|
|
30
|
+
function getOS() {
|
|
31
|
+
var ua = navigator.userAgent || '';
|
|
32
|
+
if (/iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) {
|
|
33
|
+
return 'ios';
|
|
34
|
+
} else if (/Android/i.test(ua)) {
|
|
35
|
+
return 'android';
|
|
36
|
+
}
|
|
37
|
+
return 'unknown';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getStoreUrl() {
|
|
41
|
+
return getOS() === 'ios' ? IOS_STORE_URL : ANDROID_STORE_URL;
|
|
42
|
+
}
|
|
43
|
+
|
|
10
44
|
// CTA 适配器类
|
|
11
45
|
function CTAAdapter() {
|
|
12
46
|
this.platform = null;
|
|
@@ -20,12 +54,13 @@
|
|
|
20
54
|
|
|
21
55
|
/**
|
|
22
56
|
* 检测当前运行的平台
|
|
57
|
+
* 通过检测全局对象来判断广告渠道
|
|
23
58
|
*/
|
|
24
59
|
CTAAdapter.prototype.detectPlatform = function() {
|
|
25
60
|
if (typeof FbPlayableAd !== 'undefined') {
|
|
26
|
-
this.platform = 'facebook'; // Facebook / Moloco
|
|
61
|
+
this.platform = 'facebook'; // Facebook / Moloco / Remerge
|
|
27
62
|
} else if (typeof mraid !== 'undefined') {
|
|
28
|
-
this.platform = 'mraid'; // MRAID 系列(AppLovin, ironSource, Unity Ads
|
|
63
|
+
this.platform = 'mraid'; // MRAID 系列(AppLovin, ironSource, Unity Ads, Snapchat, Liftoff, InMobi, Adikteev)
|
|
29
64
|
} else if (typeof dapi !== 'undefined') {
|
|
30
65
|
this.platform = 'dapi'; // ironSource DAPI
|
|
31
66
|
} else if (typeof ExitApi !== 'undefined') {
|
|
@@ -34,6 +69,16 @@
|
|
|
34
69
|
this.platform = 'bigo'; // BIGO Ads
|
|
35
70
|
} else if (typeof snapchatCta === 'function') {
|
|
36
71
|
this.platform = 'snapchat'; // Snapchat
|
|
72
|
+
} else if (typeof window.openAppStore === 'function') {
|
|
73
|
+
this.platform = 'tiktok'; // TikTok / Pangle
|
|
74
|
+
} else if (typeof window.install === 'function') {
|
|
75
|
+
this.platform = 'mintegral'; // Mintegral
|
|
76
|
+
} else if (typeof window.TJ_API !== 'undefined' && typeof window.TJ_API.click === 'function') {
|
|
77
|
+
this.platform = 'tapjoy'; // Tapjoy
|
|
78
|
+
} else if (typeof window.NUC !== 'undefined' && window.NUC.trigger && typeof window.NUC.trigger.convert === 'function') {
|
|
79
|
+
this.platform = 'nucleo'; // Nucleo
|
|
80
|
+
} else if (typeof window.smxTracking !== 'undefined' && typeof window.smxTracking.redirect === 'function') {
|
|
81
|
+
this.platform = 'smadex'; // Smadex
|
|
37
82
|
} else {
|
|
38
83
|
this.platform = 'unknown';
|
|
39
84
|
console.warn('[PlayCraft CTA] 未检测到已知的广告平台 API');
|
|
@@ -50,7 +95,15 @@
|
|
|
50
95
|
|
|
51
96
|
switch (this.platform) {
|
|
52
97
|
case 'facebook':
|
|
53
|
-
|
|
98
|
+
case 'google':
|
|
99
|
+
case 'bigo':
|
|
100
|
+
case 'snapchat':
|
|
101
|
+
case 'tiktok':
|
|
102
|
+
case 'mintegral':
|
|
103
|
+
case 'tapjoy':
|
|
104
|
+
case 'nucleo':
|
|
105
|
+
case 'smadex':
|
|
106
|
+
// 以上平台通常直接就绪
|
|
54
107
|
this.isReady = true;
|
|
55
108
|
this.notifyReady();
|
|
56
109
|
break;
|
|
@@ -83,24 +136,6 @@
|
|
|
83
136
|
}
|
|
84
137
|
break;
|
|
85
138
|
|
|
86
|
-
case 'google':
|
|
87
|
-
// Google Ads 通常直接就绪
|
|
88
|
-
this.isReady = true;
|
|
89
|
-
this.notifyReady();
|
|
90
|
-
break;
|
|
91
|
-
|
|
92
|
-
case 'bigo':
|
|
93
|
-
// BIGO 通常直接就绪
|
|
94
|
-
this.isReady = true;
|
|
95
|
-
this.notifyReady();
|
|
96
|
-
break;
|
|
97
|
-
|
|
98
|
-
case 'snapchat':
|
|
99
|
-
// Snapchat 通常直接就绪
|
|
100
|
-
this.isReady = true;
|
|
101
|
-
this.notifyReady();
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
139
|
default:
|
|
105
140
|
// 未知平台,标记为就绪(使用降级方案)
|
|
106
141
|
this.isReady = true;
|
|
@@ -147,22 +182,31 @@
|
|
|
147
182
|
if (!this.isReady) {
|
|
148
183
|
console.warn('[PlayCraft CTA] API 尚未就绪,跳转可能失败');
|
|
149
184
|
}
|
|
185
|
+
|
|
186
|
+
// Store URL 空值预警
|
|
187
|
+
var _jumpUrl = options.url || getStoreUrl();
|
|
188
|
+
if (!_jumpUrl) {
|
|
189
|
+
console.error('[PlayCraft CTA] Store URL is not configured. Platform:', this.platform,
|
|
190
|
+
'| OS:', getOS(),
|
|
191
|
+
'| iOS URL:', IOS_STORE_URL,
|
|
192
|
+
'| Android URL:', ANDROID_STORE_URL);
|
|
193
|
+
}
|
|
150
194
|
|
|
151
195
|
console.log('[PlayCraft CTA] 跳转应用商店 - 平台:', this.platform);
|
|
152
196
|
|
|
153
197
|
try {
|
|
154
198
|
switch (this.platform) {
|
|
155
199
|
case 'facebook':
|
|
156
|
-
// Facebook / Moloco
|
|
200
|
+
// Facebook / Moloco / Remerge
|
|
157
201
|
if (typeof FbPlayableAd !== 'undefined' && FbPlayableAd.onCTAClick) {
|
|
158
202
|
FbPlayableAd.onCTAClick();
|
|
159
203
|
}
|
|
160
204
|
break;
|
|
161
205
|
|
|
162
206
|
case 'mraid':
|
|
163
|
-
// MRAID 系列(AppLovin, ironSource, Unity Ads
|
|
207
|
+
// MRAID 系列(AppLovin, ironSource, Unity Ads, Snapchat, Liftoff, InMobi, Adikteev)
|
|
164
208
|
if (typeof mraid !== 'undefined' && mraid.open) {
|
|
165
|
-
mraid.open(options.url ||
|
|
209
|
+
mraid.open(options.url || getStoreUrl());
|
|
166
210
|
}
|
|
167
211
|
break;
|
|
168
212
|
|
|
@@ -193,6 +237,41 @@
|
|
|
193
237
|
snapchatCta();
|
|
194
238
|
}
|
|
195
239
|
break;
|
|
240
|
+
|
|
241
|
+
case 'tiktok':
|
|
242
|
+
// TikTok / Pangle
|
|
243
|
+
if (typeof window.openAppStore === 'function') {
|
|
244
|
+
window.openAppStore();
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
|
|
248
|
+
case 'mintegral':
|
|
249
|
+
// Mintegral
|
|
250
|
+
if (typeof window.install === 'function') {
|
|
251
|
+
window.install();
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
|
|
255
|
+
case 'tapjoy':
|
|
256
|
+
// Tapjoy
|
|
257
|
+
if (typeof window.TJ_API !== 'undefined' && window.TJ_API.click) {
|
|
258
|
+
window.TJ_API.click();
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
|
|
262
|
+
case 'nucleo':
|
|
263
|
+
// Nucleo
|
|
264
|
+
if (typeof window.NUC !== 'undefined' && window.NUC.trigger && window.NUC.trigger.convert) {
|
|
265
|
+
window.NUC.trigger.convert(options.url || getStoreUrl());
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case 'smadex':
|
|
270
|
+
// Smadex
|
|
271
|
+
if (typeof window.smxTracking !== 'undefined' && window.smxTracking.redirect) {
|
|
272
|
+
window.smxTracking.redirect();
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
196
275
|
|
|
197
276
|
default:
|
|
198
277
|
// 降级方案:尝试所有可能的 API
|
|
@@ -208,14 +287,16 @@
|
|
|
208
287
|
};
|
|
209
288
|
|
|
210
289
|
/**
|
|
211
|
-
* 降级跳转方案
|
|
290
|
+
* 降级跳转方案 - 按优先级尝试各种 API,最终兜底到 window.open
|
|
212
291
|
*/
|
|
213
292
|
CTAAdapter.prototype.fallbackJump = function(url) {
|
|
293
|
+
var storeUrl = url || getStoreUrl();
|
|
294
|
+
|
|
214
295
|
// 按优先级尝试各种 API
|
|
215
296
|
if (typeof FbPlayableAd !== 'undefined' && FbPlayableAd.onCTAClick) {
|
|
216
297
|
FbPlayableAd.onCTAClick();
|
|
217
298
|
} else if (typeof mraid !== 'undefined' && mraid.open) {
|
|
218
|
-
mraid.open(
|
|
299
|
+
mraid.open(storeUrl);
|
|
219
300
|
} else if (typeof dapi !== 'undefined' && dapi.openStoreUrl) {
|
|
220
301
|
dapi.openStoreUrl();
|
|
221
302
|
} else if (typeof ExitApi !== 'undefined' && ExitApi.exit) {
|
|
@@ -224,12 +305,29 @@
|
|
|
224
305
|
window.BGY_MRAID.open();
|
|
225
306
|
} else if (typeof snapchatCta === 'function') {
|
|
226
307
|
snapchatCta();
|
|
227
|
-
} else if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
window.
|
|
308
|
+
} else if (typeof window.openAppStore === 'function') {
|
|
309
|
+
window.openAppStore();
|
|
310
|
+
} else if (typeof window.install === 'function') {
|
|
311
|
+
window.install();
|
|
312
|
+
} else if (typeof window.TJ_API !== 'undefined' && window.TJ_API.click) {
|
|
313
|
+
window.TJ_API.click();
|
|
314
|
+
} else if (typeof window.NUC !== 'undefined' && window.NUC.trigger && window.NUC.trigger.convert) {
|
|
315
|
+
window.NUC.trigger.convert(storeUrl);
|
|
316
|
+
} else if (typeof window.smxTracking !== 'undefined' && window.smxTracking.redirect) {
|
|
317
|
+
window.smxTracking.redirect();
|
|
231
318
|
} else {
|
|
232
|
-
|
|
319
|
+
// 最后的降级方案:直接打开应用商店链接
|
|
320
|
+
console.warn('[PlayCraft CTA] 使用降级方案: window.open');
|
|
321
|
+
try {
|
|
322
|
+
parent.postMessage('download', '*');
|
|
323
|
+
} catch (e) {
|
|
324
|
+
// Vungle 兜底
|
|
325
|
+
}
|
|
326
|
+
if (!storeUrl) {
|
|
327
|
+
console.error('[PlayCraft CTA] Store URL is not configured for this platform. Aborting redirect.');
|
|
328
|
+
} else {
|
|
329
|
+
window.open(storeUrl, '_blank');
|
|
330
|
+
}
|
|
233
331
|
}
|
|
234
332
|
};
|
|
235
333
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scene applySettings 补丁:当使用 ammoReplacement (Cannon/p2) 时,
|
|
3
|
+
* 确保 settings.physics 存在,避免 PlayCanvas 引擎在 applySettings 中
|
|
4
|
+
* 访问 undefined.gravity 导致 "Cannot read properties of undefined (reading 'gravity')" 错误。
|
|
5
|
+
*
|
|
6
|
+
* 使用场景:项目使用 Ammo.js 但构建时被替换为 Cannon/p2,部分场景 JSON 可能缺少 physics 配置。
|
|
7
|
+
*/
|
|
8
|
+
(function () {
|
|
9
|
+
'use strict';
|
|
10
|
+
function patchSceneApplySettings() {
|
|
11
|
+
if (typeof pc === 'undefined' || !pc.Scene || !pc.Scene.prototype.applySettings) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var original = pc.Scene.prototype.applySettings;
|
|
15
|
+
pc.Scene.prototype.applySettings = function (settings) {
|
|
16
|
+
if (!settings) return;
|
|
17
|
+
if (!settings.physics) {
|
|
18
|
+
settings.physics = { gravity: [0, -9.8, 0] };
|
|
19
|
+
} else if (!settings.physics.gravity) {
|
|
20
|
+
settings.physics.gravity = [0, -9.8, 0];
|
|
21
|
+
}
|
|
22
|
+
if (!settings.render) {
|
|
23
|
+
settings.render = {
|
|
24
|
+
global_ambient: [0.2, 0.2, 0.2],
|
|
25
|
+
ambientLuminance: 0,
|
|
26
|
+
fog: 'none',
|
|
27
|
+
fog_color: [0.5, 0.5, 0.5],
|
|
28
|
+
fog_start: 1,
|
|
29
|
+
fog_end: 1000,
|
|
30
|
+
fog_density: 0.01,
|
|
31
|
+
lightmapSizeMultiplier: 16,
|
|
32
|
+
lightmapMaxResolution: 2048,
|
|
33
|
+
lightmapMode: 1,
|
|
34
|
+
exposure: 1
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return original.call(this, settings);
|
|
38
|
+
};
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (patchSceneApplySettings()) {
|
|
42
|
+
console.log('[PlayCraft] Scene applySettings patched for physics defaults');
|
|
43
|
+
} else {
|
|
44
|
+
var attempts = 0;
|
|
45
|
+
var id = setInterval(function () {
|
|
46
|
+
if (patchSceneApplySettings() || ++attempts > 50) clearInterval(id);
|
|
47
|
+
}, 20);
|
|
48
|
+
}
|
|
49
|
+
})();
|