2022-08-31 01:48:48 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
node version_generator.js -v 1.0.0 -u https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/ -s build/jsb-default/remote-assets -d remote-assets
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-08-30 03:37:02 +00:00
|
|
|
import { CoroutineV2 } from "./Engine/CatanEngine/CoroutineV2/CoroutineV2";
|
2022-08-29 07:25:13 +00:00
|
|
|
import { System_Eevent } from "./Engine/CatanEngine/CSharp/System/System_Eevent";
|
2022-08-31 01:48:48 +00:00
|
|
|
import { Enum_HUDM } from "./HUD/Enum_HUDM";
|
|
|
|
import HUDM from "./HUD/HUDM";
|
2022-08-25 06:25:48 +00:00
|
|
|
import NativeClass from "./NativeClass";
|
2022-08-31 01:48:48 +00:00
|
|
|
import UpdatePanel from "./UpdatePanel";
|
2022-01-21 03:01:58 +00:00
|
|
|
|
2021-12-28 15:37:22 +00:00
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
@ccclass
|
|
|
|
export default class Manager extends cc.Component {
|
2022-08-25 06:25:48 +00:00
|
|
|
//#region 外調參數
|
|
|
|
|
|
|
|
@property({ type: cc.WebView })
|
|
|
|
public webview: cc.WebView = null;
|
|
|
|
|
|
|
|
@property({ type: cc.Node })
|
|
|
|
public BG: cc.Node = null;
|
|
|
|
|
2022-08-31 01:48:48 +00:00
|
|
|
@property({ type: cc.Node })
|
|
|
|
public UpdatePanel: cc.Node = null;
|
2022-08-25 06:25:48 +00:00
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region Lifecycle
|
|
|
|
|
|
|
|
protected onLoad(): void {
|
2022-08-31 01:48:48 +00:00
|
|
|
CoroutineV2.Single(this._init()).Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private *_init(): IterableIterator<any> {
|
|
|
|
console.log(`2022/08/30 16:26`);
|
2022-08-29 03:23:54 +00:00
|
|
|
cc.debug.setDisplayStats(false);
|
2022-08-25 06:25:48 +00:00
|
|
|
if (CC_DEBUG) {
|
|
|
|
console.log("Debug");
|
|
|
|
}
|
|
|
|
|
2022-08-29 07:25:13 +00:00
|
|
|
new NativeClass(this.webview);
|
2022-08-31 01:48:48 +00:00
|
|
|
if (cc.sys.isNative) {
|
|
|
|
new HUDM(this.UpdatePanel.getComponentInChildren(UpdatePanel));
|
|
|
|
let needUpdateData: Enum_HUDM.NeedUpdateDataObj = yield* HUDM.Instance.CheckUpdate();
|
|
|
|
if (needUpdateData.IsNeedUpdate) {
|
|
|
|
this.UpdatePanel.active = true;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
this.UpdatePanel.active = false;
|
|
|
|
}
|
|
|
|
}
|
2022-08-25 06:25:48 +00:00
|
|
|
|
|
|
|
let self: this = this;
|
|
|
|
// this._text_to_Speech = new Text_to_Speech();
|
2022-08-29 01:54:55 +00:00
|
|
|
let href: string = window.location.href;
|
|
|
|
|
|
|
|
// let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/Test/?host=${href}&v=${Date.now()}`;
|
|
|
|
// let url: string = `https://karolchang.github.io/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`;
|
|
|
|
// let url: string = `http://karol.jianmiau.cf/jm-expense-vue-ts/?v=${Date.now()}`;
|
|
|
|
let url: string = `https://jm-expense-2022.firebaseapp.com/login?host=${href}&v=${Date.now()}`;
|
|
|
|
this.webview.url = url;
|
|
|
|
this.webview.node.active = true;
|
|
|
|
|
|
|
|
cc.view.setResizeCallback(this._resize.bind(this));
|
|
|
|
this._resize();
|
|
|
|
|
|
|
|
// Set EventListener
|
2022-08-25 06:25:48 +00:00
|
|
|
window.addEventListener("message", function (e: MessageEvent<any>): void {
|
|
|
|
let data: any = e.data;
|
|
|
|
let method: string = data.method;
|
|
|
|
let value: any = data.value;
|
2022-08-25 09:49:29 +00:00
|
|
|
if (method) {
|
|
|
|
self.Birdge(method, ...value);
|
|
|
|
}
|
2022-08-25 06:25:48 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
if (!window["Bridge"]) {
|
|
|
|
window["Bridge"] = function (method: string = "", value: string = ""): void {
|
|
|
|
self.Birdge(method, value);
|
|
|
|
};
|
|
|
|
}
|
2022-08-29 05:59:46 +00:00
|
|
|
let scheme: string = "jmka";
|
2022-08-25 09:49:29 +00:00
|
|
|
this.webview.setJavascriptInterfaceScheme(scheme);
|
2022-08-29 01:54:55 +00:00
|
|
|
this.webview.setOnJSCallback((sender: any, url: any) => {
|
2022-08-29 05:56:24 +00:00
|
|
|
let content: string = decodeURI(url.split(`${scheme}://?data=`)[1]);
|
2022-08-29 04:25:51 +00:00
|
|
|
try {
|
|
|
|
let data: JSON = JSON.parse(content);
|
|
|
|
let method: any = data["method"];
|
|
|
|
let value: any = data["value"];
|
|
|
|
if (method) {
|
|
|
|
self.Birdge(method, ...value);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2022-08-25 09:49:29 +00:00
|
|
|
}
|
|
|
|
});
|
2022-08-25 06:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 跨版本溝通
|
|
|
|
* @example
|
|
|
|
* CallParent('Speak', '我愛豬涵')
|
|
|
|
*/
|
|
|
|
public Birdge(method: string, value: string = ""): void {
|
|
|
|
let self: this = this;
|
|
|
|
if (method && self[method]) {
|
|
|
|
if (value) {
|
|
|
|
self[method](value);
|
|
|
|
return;
|
|
|
|
} else if (self[method]) {
|
|
|
|
self[method]();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(`not function: ${method}, value: ${value}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CloseBG(): void {
|
|
|
|
this.BG.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Log(msg: string): void {
|
|
|
|
console.log(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Speak(msg: string): void {
|
|
|
|
// this._text_to_Speech.speak(msg);
|
|
|
|
NativeClass.Instance.TTS_Play(msg);
|
|
|
|
}
|
|
|
|
|
2022-08-29 07:58:44 +00:00
|
|
|
public onLoadOK(): void {
|
2022-08-30 03:37:02 +00:00
|
|
|
CoroutineV2.Single(this.GetFCMToken()).Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public *GetFCMToken(): IterableIterator<any> {
|
2022-08-29 07:58:44 +00:00
|
|
|
const FCMToken: string = NativeClass.Instance.GetFCMToken();
|
2022-08-31 01:48:48 +00:00
|
|
|
if (cc.sys.os === cc.sys.OS_IOS && !FCMToken) {
|
2022-08-30 03:37:02 +00:00
|
|
|
yield CoroutineV2.WaitTime(1);
|
|
|
|
yield this.GetFCMToken();
|
|
|
|
return;
|
|
|
|
}
|
2022-08-29 07:58:44 +00:00
|
|
|
console.log(`FCMToken ${FCMToken}`);
|
2022-08-29 08:04:26 +00:00
|
|
|
NativeClass.Instance.CocosBridge(System_Eevent.SetFCMToken, `"${FCMToken}"`);
|
2022-08-29 07:58:44 +00:00
|
|
|
}
|
|
|
|
|
2022-08-25 06:25:48 +00:00
|
|
|
public Alert(msg: string): void {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _resize(): void {
|
|
|
|
let Canvas: cc.Canvas = cc.Canvas.instance;
|
|
|
|
let rect: DOMRect = cc.game.canvas.getBoundingClientRect();
|
|
|
|
/** 判断是否是横屏 */
|
|
|
|
let landscape: boolean = false;
|
|
|
|
if (rect.width > rect.height) {
|
|
|
|
landscape = true;
|
|
|
|
}
|
|
|
|
// 根据横竖屏调整节点的位置适配等
|
|
|
|
let frameSize: cc.Size = cc.view.getFrameSize();
|
|
|
|
if (landscape) {
|
|
|
|
// 横屏
|
|
|
|
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
|
|
|
|
if (frameSize.height > frameSize.width) {
|
|
|
|
cc.view.setFrameSize(frameSize.height, frameSize.width);
|
|
|
|
}
|
|
|
|
Canvas.designResolution = cc.size(1920, 1080);
|
|
|
|
} else {
|
|
|
|
// 竖屏
|
|
|
|
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
|
|
|
|
if (frameSize.width > frameSize.height) {
|
|
|
|
cc.view.setFrameSize(frameSize.height, frameSize.width);
|
|
|
|
}
|
|
|
|
Canvas.designResolution = cc.size(1080, 1920);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//#endregion
|
2021-12-28 15:37:22 +00:00
|
|
|
}
|