|
@@ -58,8 +58,9 @@
|
|
|
<script src="src/import-map.json" type="systemjs-importmap" charset="utf-8"> </script>
|
|
|
|
|
|
<script>
|
|
|
+ // adInstance = null
|
|
|
// 动态加载外部脚本的方法
|
|
|
- function loadScript(url) {
|
|
|
+ loadScript = function (url) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const script = document.createElement('script');
|
|
|
script.src = url;
|
|
@@ -78,28 +79,81 @@
|
|
|
var adSdkConfig = {
|
|
|
el: document.querySelector("GameDiv"),
|
|
|
client: 'cpsense-cd',
|
|
|
- is_test: false
|
|
|
+ is_test: true
|
|
|
};
|
|
|
var adInstance = new adSdk(adSdkConfig);
|
|
|
window.adInstance = adInstance;
|
|
|
+ window.CPSenseShowAd = {
|
|
|
+ showAd: function (type) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (type === 'interstitial') {
|
|
|
+ adInstance.interstitialAd({
|
|
|
+ beforeAd: function () {
|
|
|
+ console.log("The ad starts playing")
|
|
|
+ },
|
|
|
+ afterAd: function () {
|
|
|
+ console.log("The ad ends playing")
|
|
|
+ resolve({
|
|
|
+ result: 'success',
|
|
|
+ message: 'Interstitial ad closed'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ error: function (n) {
|
|
|
+ console.log("error", n);
|
|
|
+ reject(new Error('Interstitial ad error'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (type === 'rewarded') {
|
|
|
+ adInstance.rewardAd({
|
|
|
+ beforeAd: function () {
|
|
|
+ console.log("The ad starts playing, and the game should pause."),
|
|
|
+ window.youxi.SoundManager.pauseAll();
|
|
|
+ },
|
|
|
+ adDismissed: function () {
|
|
|
+ console.log("Player dismissed the ad before completion."),
|
|
|
+ window.youxi.SoundManager.resumeAll();
|
|
|
+ reject(new Error('Interstitial ad error'));
|
|
|
+ },
|
|
|
+ adViewed: function () {
|
|
|
+ console.log("Ad was viewed and closed."),
|
|
|
+ window.youxi.SoundManager.resumeAll();
|
|
|
+ resolve({
|
|
|
+ result: 'success',
|
|
|
+ message: 'Interstitial ad closed'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ error: function (n) {
|
|
|
+ console.log("error", n);
|
|
|
+ window.youxi.SoundManager.resumeAll();
|
|
|
+ reject(new Error('Interstitial ad error'));
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ reject(new Error('Invalid ad type'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log('AD initialized successfully');
|
|
|
+
|
|
|
|
|
|
- // 加载项目主入口
|
|
|
- return System.import('./index.js');
|
|
|
})
|
|
|
.then(() => {
|
|
|
- console.log('Game initialized successfully');
|
|
|
+ // 加载项目主入口
|
|
|
+ return System.import('./index.js');
|
|
|
})
|
|
|
.catch(err => {
|
|
|
console.error('Error during initialization:', err);
|
|
|
});
|
|
|
- </script>
|
|
|
|
|
|
- <script src=""></script>
|
|
|
- <script>
|
|
|
+
|
|
|
// 外部广告调用
|
|
|
window.showAd = function (type) {
|
|
|
+ type = type.toLowerCase();
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- window.__woso.showAd(type)
|
|
|
+
|
|
|
+ window.CPSenseShowAd.showAd(type)
|
|
|
.then((res) => {
|
|
|
// 为游戏返回广告结果
|
|
|
console.log(res);
|
|
@@ -110,16 +164,19 @@
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
};
|
|
|
|
|
|
// 回调测试
|
|
|
function TopCallback() {
|
|
|
+
|
|
|
//sound
|
|
|
if (window.__woso.SoundManager.isSound) {
|
|
|
window.youxi.SoundManager.resumeAll();
|
|
|
} else {
|
|
|
window.youxi.SoundManager.pauseAll();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
</script>
|
|
|
|