@playcraft/build 0.0.4 → 0.0.8
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 +210 -1
- package/dist/base-builder.d.ts +15 -0
- package/dist/base-builder.js +192 -16
- package/dist/generators/config-generator.js +29 -3
- package/dist/loaders/playcanvas-loader.d.ts +7 -0
- package/dist/loaders/playcanvas-loader.js +53 -3
- package/dist/platforms/adikteev.d.ts +10 -0
- package/dist/platforms/adikteev.js +72 -0
- package/dist/platforms/base.d.ts +12 -0
- package/dist/platforms/base.js +208 -0
- package/dist/platforms/facebook.js +5 -2
- package/dist/platforms/index.d.ts +4 -0
- package/dist/platforms/index.js +16 -0
- package/dist/platforms/inmobi.d.ts +10 -0
- package/dist/platforms/inmobi.js +68 -0
- package/dist/platforms/ironsource.js +5 -2
- package/dist/platforms/moloco.js +5 -2
- package/dist/platforms/playcraft.d.ts +33 -0
- package/dist/platforms/playcraft.js +44 -0
- package/dist/platforms/remerge.d.ts +10 -0
- package/dist/platforms/remerge.js +56 -0
- package/dist/templates/__loading__.js +100 -0
- package/dist/templates/__modules__.js +47 -0
- package/dist/templates/__settings__.template.js +20 -0
- package/dist/templates/__start__.js +332 -0
- package/dist/templates/index.html +18 -0
- package/dist/templates/logo.png +0 -0
- package/dist/templates/manifest.json +1 -0
- package/dist/templates/patches/cannon.min.js +28 -0
- package/dist/templates/patches/lz4.js +10 -0
- package/dist/templates/patches/one-page-http-get.js +20 -0
- package/dist/templates/patches/one-page-inline-game-scripts.js +52 -0
- package/dist/templates/patches/one-page-mraid-resize-canvas.js +46 -0
- package/dist/templates/patches/p2.min.js +27 -0
- package/dist/templates/patches/playcraft-no-xhr.js +76 -0
- package/dist/templates/playcanvas-stable.min.js +16363 -0
- package/dist/templates/styles.css +43 -0
- package/dist/types.d.ts +14 -1
- package/dist/utils/build-mode-detector.d.ts +9 -0
- package/dist/utils/build-mode-detector.js +42 -0
- package/dist/vite/config-builder.d.ts +29 -1
- package/dist/vite/config-builder.js +169 -25
- package/dist/vite/platform-configs.d.ts +4 -0
- package/dist/vite/platform-configs.js +97 -13
- package/dist/vite/plugin-esm-html-generator.d.ts +22 -0
- package/dist/vite/plugin-esm-html-generator.js +1061 -0
- package/dist/vite/plugin-platform.js +56 -17
- package/dist/vite/plugin-playcanvas.d.ts +2 -0
- package/dist/vite/plugin-playcanvas.js +497 -40
- package/dist/vite/plugin-source-builder.d.ts +3 -0
- package/dist/vite/plugin-source-builder.js +886 -19
- package/dist/vite-builder.d.ts +19 -2
- package/dist/vite-builder.js +162 -12
- package/package.json +2 -1
- package/physics/cannon-es-bundle.js +13092 -0
- package/physics/cannon-rigidbody-adapter.js +375 -0
- package/physics/connon-integration.js +411 -0
- package/templates/__start__.js +8 -3
- package/templates/index.esm.html +20 -0
- package/templates/index.esm.mjs +502 -0
- package/templates/patches/one-page-inline-game-scripts.js +25 -1
- package/templates/patches/playcraft-cta-adapter.js +297 -0
- package/templates/patches/playcraft-no-xhr.js +25 -1
- package/templates/playcanvas-esm-wrapper.mjs +827 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlayCraft CTA Adapter - 统一的跳转应用商店适配器
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 API 接口,自动适配不同渠道的 CTA 调用方式
|
|
5
|
+
* 游戏开发者只需调用 window.PlayCraftCTA.jump() 即可
|
|
6
|
+
*/
|
|
7
|
+
(function() {
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
// CTA 适配器类
|
|
11
|
+
function CTAAdapter() {
|
|
12
|
+
this.platform = null;
|
|
13
|
+
this.isReady = false;
|
|
14
|
+
this.readyCallbacks = [];
|
|
15
|
+
|
|
16
|
+
// 自动检测并初始化
|
|
17
|
+
this.detectPlatform();
|
|
18
|
+
this.initialize();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 检测当前运行的平台
|
|
23
|
+
*/
|
|
24
|
+
CTAAdapter.prototype.detectPlatform = function() {
|
|
25
|
+
if (typeof FbPlayableAd !== 'undefined') {
|
|
26
|
+
this.platform = 'facebook'; // Facebook / Moloco
|
|
27
|
+
} else if (typeof mraid !== 'undefined') {
|
|
28
|
+
this.platform = 'mraid'; // MRAID 系列(AppLovin, ironSource, Unity Ads 等)
|
|
29
|
+
} else if (typeof dapi !== 'undefined') {
|
|
30
|
+
this.platform = 'dapi'; // ironSource DAPI
|
|
31
|
+
} else if (typeof ExitApi !== 'undefined') {
|
|
32
|
+
this.platform = 'google'; // Google Ads
|
|
33
|
+
} else if (typeof window.BGY_MRAID !== 'undefined') {
|
|
34
|
+
this.platform = 'bigo'; // BIGO Ads
|
|
35
|
+
} else if (typeof snapchatCta === 'function') {
|
|
36
|
+
this.platform = 'snapchat'; // Snapchat
|
|
37
|
+
} else {
|
|
38
|
+
this.platform = 'unknown';
|
|
39
|
+
console.warn('[PlayCraft CTA] 未检测到已知的广告平台 API');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('[PlayCraft CTA] 检测到平台:', this.platform);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 初始化平台 API
|
|
47
|
+
*/
|
|
48
|
+
CTAAdapter.prototype.initialize = function() {
|
|
49
|
+
var self = this;
|
|
50
|
+
|
|
51
|
+
switch (this.platform) {
|
|
52
|
+
case 'facebook':
|
|
53
|
+
// Facebook/Moloco 通常直接就绪
|
|
54
|
+
this.isReady = true;
|
|
55
|
+
this.notifyReady();
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'mraid':
|
|
59
|
+
// MRAID 需要等待 ready 事件
|
|
60
|
+
if (mraid.isReady && mraid.isReady()) {
|
|
61
|
+
this.isReady = true;
|
|
62
|
+
this.notifyReady();
|
|
63
|
+
} else if (mraid.addEventListener) {
|
|
64
|
+
mraid.addEventListener('ready', function() {
|
|
65
|
+
self.isReady = true;
|
|
66
|
+
self.notifyReady();
|
|
67
|
+
console.log('[PlayCraft CTA] MRAID ready');
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case 'dapi':
|
|
73
|
+
// DAPI 需要等待 ready 事件
|
|
74
|
+
if (dapi.isReady && dapi.isReady()) {
|
|
75
|
+
this.isReady = true;
|
|
76
|
+
this.notifyReady();
|
|
77
|
+
} else if (dapi.addEventListener) {
|
|
78
|
+
dapi.addEventListener('ready', function() {
|
|
79
|
+
self.isReady = true;
|
|
80
|
+
self.notifyReady();
|
|
81
|
+
console.log('[PlayCraft CTA] DAPI ready');
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
|
|
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
|
+
default:
|
|
105
|
+
// 未知平台,标记为就绪(使用降级方案)
|
|
106
|
+
this.isReady = true;
|
|
107
|
+
this.notifyReady();
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 通知所有等待的回调
|
|
114
|
+
*/
|
|
115
|
+
CTAAdapter.prototype.notifyReady = function() {
|
|
116
|
+
for (var i = 0; i < this.readyCallbacks.length; i++) {
|
|
117
|
+
try {
|
|
118
|
+
this.readyCallbacks[i]();
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error('[PlayCraft CTA] Ready callback error:', e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
this.readyCallbacks = [];
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 注册就绪回调
|
|
128
|
+
*/
|
|
129
|
+
CTAAdapter.prototype.onReady = function(callback) {
|
|
130
|
+
if (this.isReady) {
|
|
131
|
+
// 已经就绪,立即调用
|
|
132
|
+
setTimeout(callback, 0);
|
|
133
|
+
} else {
|
|
134
|
+
// 等待就绪
|
|
135
|
+
this.readyCallbacks.push(callback);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 跳转到应用商店(主方法)
|
|
141
|
+
* @param {Object} options - 可选配置
|
|
142
|
+
* @param {string} options.url - 自定义 URL(不推荐,仅用于测试)
|
|
143
|
+
*/
|
|
144
|
+
CTAAdapter.prototype.jump = function(options) {
|
|
145
|
+
options = options || {};
|
|
146
|
+
|
|
147
|
+
if (!this.isReady) {
|
|
148
|
+
console.warn('[PlayCraft CTA] API 尚未就绪,跳转可能失败');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log('[PlayCraft CTA] 跳转应用商店 - 平台:', this.platform);
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
switch (this.platform) {
|
|
155
|
+
case 'facebook':
|
|
156
|
+
// Facebook / Moloco
|
|
157
|
+
if (typeof FbPlayableAd !== 'undefined' && FbPlayableAd.onCTAClick) {
|
|
158
|
+
FbPlayableAd.onCTAClick();
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
|
|
162
|
+
case 'mraid':
|
|
163
|
+
// MRAID 系列(AppLovin, ironSource, Unity Ads 等)
|
|
164
|
+
if (typeof mraid !== 'undefined' && mraid.open) {
|
|
165
|
+
mraid.open(options.url || '');
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
|
|
169
|
+
case 'dapi':
|
|
170
|
+
// ironSource DAPI
|
|
171
|
+
if (typeof dapi !== 'undefined' && dapi.openStoreUrl) {
|
|
172
|
+
dapi.openStoreUrl();
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
|
|
176
|
+
case 'google':
|
|
177
|
+
// Google Ads
|
|
178
|
+
if (typeof ExitApi !== 'undefined' && ExitApi.exit) {
|
|
179
|
+
ExitApi.exit();
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
|
|
183
|
+
case 'bigo':
|
|
184
|
+
// BIGO Ads
|
|
185
|
+
if (typeof window.BGY_MRAID !== 'undefined' && window.BGY_MRAID.open) {
|
|
186
|
+
window.BGY_MRAID.open();
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
|
|
190
|
+
case 'snapchat':
|
|
191
|
+
// Snapchat
|
|
192
|
+
if (typeof snapchatCta === 'function') {
|
|
193
|
+
snapchatCta();
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
|
|
197
|
+
default:
|
|
198
|
+
// 降级方案:尝试所有可能的 API
|
|
199
|
+
console.warn('[PlayCraft CTA] 未知平台,尝试降级方案');
|
|
200
|
+
this.fallbackJump(options.url);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
} catch (e) {
|
|
204
|
+
console.error('[PlayCraft CTA] 跳转失败:', e);
|
|
205
|
+
// 尝试降级方案
|
|
206
|
+
this.fallbackJump(options.url);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 降级跳转方案
|
|
212
|
+
*/
|
|
213
|
+
CTAAdapter.prototype.fallbackJump = function(url) {
|
|
214
|
+
// 按优先级尝试各种 API
|
|
215
|
+
if (typeof FbPlayableAd !== 'undefined' && FbPlayableAd.onCTAClick) {
|
|
216
|
+
FbPlayableAd.onCTAClick();
|
|
217
|
+
} else if (typeof mraid !== 'undefined' && mraid.open) {
|
|
218
|
+
mraid.open(url || '');
|
|
219
|
+
} else if (typeof dapi !== 'undefined' && dapi.openStoreUrl) {
|
|
220
|
+
dapi.openStoreUrl();
|
|
221
|
+
} else if (typeof ExitApi !== 'undefined' && ExitApi.exit) {
|
|
222
|
+
ExitApi.exit();
|
|
223
|
+
} else if (typeof window.BGY_MRAID !== 'undefined' && window.BGY_MRAID.open) {
|
|
224
|
+
window.BGY_MRAID.open();
|
|
225
|
+
} else if (typeof snapchatCta === 'function') {
|
|
226
|
+
snapchatCta();
|
|
227
|
+
} else if (url) {
|
|
228
|
+
// 最后的降级方案:直接打开链接(仅在开发环境)
|
|
229
|
+
console.warn('[PlayCraft CTA] 使用降级方案: window.open');
|
|
230
|
+
window.open(url, '_blank');
|
|
231
|
+
} else {
|
|
232
|
+
console.error('[PlayCraft CTA] 无法跳转:未找到可用的 API');
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 获取当前平台信息
|
|
238
|
+
*/
|
|
239
|
+
CTAAdapter.prototype.getPlatform = function() {
|
|
240
|
+
return this.platform;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 检查是否就绪
|
|
245
|
+
*/
|
|
246
|
+
CTAAdapter.prototype.checkReady = function() {
|
|
247
|
+
return this.isReady;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// 创建全局实例
|
|
251
|
+
var ctaAdapter = new CTAAdapter();
|
|
252
|
+
|
|
253
|
+
// 暴露简洁的全局 API
|
|
254
|
+
window.PlayCraftCTA = {
|
|
255
|
+
/**
|
|
256
|
+
* 跳转到应用商店(推荐使用)
|
|
257
|
+
* @param {Object} options - 可选配置
|
|
258
|
+
*/
|
|
259
|
+
jump: function(options) {
|
|
260
|
+
ctaAdapter.jump(options);
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 跳转到应用商店(别名,简化调用)
|
|
265
|
+
*/
|
|
266
|
+
jump2AppStore: function(options) {
|
|
267
|
+
ctaAdapter.jump(options);
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 注册就绪回调
|
|
272
|
+
* @param {Function} callback - 回调函数
|
|
273
|
+
*/
|
|
274
|
+
onReady: function(callback) {
|
|
275
|
+
ctaAdapter.onReady(callback);
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 获取当前平台
|
|
280
|
+
*/
|
|
281
|
+
getPlatform: function() {
|
|
282
|
+
return ctaAdapter.getPlatform();
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 检查是否就绪
|
|
287
|
+
*/
|
|
288
|
+
isReady: function() {
|
|
289
|
+
return ctaAdapter.checkReady();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// 向后兼容的别名
|
|
294
|
+
window.jump2AppStore = window.PlayCraftCTA.jump2AppStore;
|
|
295
|
+
|
|
296
|
+
console.log('[PlayCraft CTA] 适配器已加载,平台:', ctaAdapter.getPlatform());
|
|
297
|
+
})();
|
|
@@ -27,7 +27,31 @@
|
|
|
27
27
|
|
|
28
28
|
var index = url.indexOf(',');
|
|
29
29
|
var base64 = url.slice(index + 1);
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
// 移除查询参数(如 ?t=hash 用于缓存破坏)
|
|
32
|
+
var queryIndex = base64.indexOf('?');
|
|
33
|
+
if (queryIndex !== -1) {
|
|
34
|
+
base64 = base64.substring(0, queryIndex);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 防御性检查:清理 base64 字符串,移除空白字符
|
|
38
|
+
base64 = base64.trim().replace(/\s/g, '');
|
|
39
|
+
|
|
40
|
+
// 如果 base64 为空,返回空数据
|
|
41
|
+
if (!base64) {
|
|
42
|
+
console.warn('警告: base64 数据为空,URL:', url.substring(0, 100));
|
|
43
|
+
callback(null, url.startsWith('data:image/') ? new Blob([]) : '');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var data;
|
|
48
|
+
try {
|
|
49
|
+
data = window.atob(base64);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error('atob 解码失败:', e.message, 'URL:', url.substring(0, 100));
|
|
52
|
+
callback('atob 解码失败: ' + e.message);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
31
55
|
|
|
32
56
|
if (url.startsWith('data:application/json') || options.responseType === pc.Http.ResponseType.JSON) {
|
|
33
57
|
data = JSON.parse(data);
|