drgame-cc 1.0.44 → 1.0.46
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/drres/focus/focus_1/gesture.atlas +34 -0
- package/drres/focus/focus_1/gesture.atlas.meta +6 -0
- package/drres/focus/focus_1/gesture.json +1 -0
- package/drres/focus/focus_1/gesture.json.meta +10 -0
- package/drres/focus/focus_1/gesture.png +0 -0
- package/drres/{icons/pointer-yellow-60.png.meta → focus/focus_1/gesture.png.meta} +14 -14
- package/drres/focus/focus_1.meta +13 -0
- package/drres/focus/focus_2/gesture.atlas +41 -0
- package/drres/focus/focus_2/gesture.atlas.meta +6 -0
- package/drres/focus/focus_2/gesture.json +1 -0
- package/drres/focus/focus_2/gesture.json.meta +10 -0
- package/drres/focus/focus_2/gesture.png +0 -0
- package/drres/{icons/pointer-blue-60.png.meta → focus/focus_2/gesture.png.meta} +13 -13
- package/drres/focus/focus_2.meta +13 -0
- package/drres/focus/focus_3/gesture.atlas +34 -0
- package/drres/focus/focus_3/gesture.atlas.meta +6 -0
- package/drres/focus/focus_3/gesture.json +1 -0
- package/drres/focus/focus_3/gesture.json.meta +10 -0
- package/drres/focus/focus_3/gesture.png +0 -0
- package/drres/{icons/pointer-pink-60.png.meta → focus/focus_3/gesture.png.meta} +12 -12
- package/drres/focus/focus_3.meta +13 -0
- package/drres/focus/focus_4/gesture.atlas +20 -0
- package/drres/focus/focus_4/gesture.atlas.meta +6 -0
- package/drres/focus/focus_4/gesture.json +1 -0
- package/drres/focus/focus_4/gesture.json.meta +10 -0
- package/drres/focus/focus_4/gesture.png +0 -0
- package/drres/focus/focus_4/gesture.png.meta +38 -0
- package/drres/focus/focus_4.meta +13 -0
- package/drres/focus.meta +13 -0
- package/drres/prefab/ExitWin.prefab +2 -2
- package/drres/prefab/Toast.prefab +378 -378
- package/drscript/{ad/AdManager.ts.meta → BtnExtra.ts.meta} +1 -1
- package/drscript/Define.ts +20 -0
- package/drscript/{ad/AdSlot.ts.meta → Define.ts.meta} +1 -1
- package/drscript/{ad/AggregateAdProvider.ts.meta → ExitWin.ts.meta} +1 -1
- package/drscript/GameAnalytics.ts +37 -118
- package/drscript/{ad/IAdProvider.ts.meta → GameAnalytics.ts.meta} +1 -1
- package/drscript/HelperWin.ts.meta +10 -0
- package/drscript/Info.ts.meta +10 -0
- package/drscript/InternalUitl.ts.meta +10 -0
- package/drscript/KeyAdapter.ts +133 -0
- package/drscript/KeyAdapter.ts.meta +10 -0
- package/drscript/Loader.ts.meta +10 -0
- package/drscript/PlatformAdapter.ts +179 -192
- package/drscript/PlatformAdapter.ts.meta +10 -0
- package/drscript/README.md +91 -805
- package/drscript/README.md.meta +6 -0
- package/drscript/UIAdapter.ts +324 -0
- package/drscript/UIAdapter.ts.meta +10 -0
- package/drscript/WebBridge.ts +1 -1
- package/drscript/WebBridge.ts.meta +10 -0
- package/drscript/ad-sdk/reporters/superset-lewo.js +6 -0
- package/drscript/ad-sdk/types/enums.d.ts +1 -0
- package/drscript/ad-sdk.meta +13 -0
- package/drscript/ad.meta +13 -0
- package/drscript/component/AlertTip.ts +25 -0
- package/drscript/component/AlertTip.ts.meta +10 -0
- package/drscript/component/BtnExtra.ts +17 -0
- package/drscript/component/BtnExtra.ts.meta +10 -0
- package/drscript/{ExitWin.ts → component/ExitWin.ts} +6 -8
- package/drscript/component/ExitWin.ts.meta +10 -0
- package/drscript/{HelperWin.ts → component/HelperWin.ts} +5 -19
- package/drscript/component/HelperWin.ts.meta +10 -0
- package/drscript/component.meta +13 -0
- package/drscript/config.meta +13 -0
- package/drscript/core.meta +13 -0
- package/drscript/focus/FocusItem.ts +1 -19
- package/drscript/focus/FocusManager.ts +132 -170
- package/drscript/focus/FocusVisualLayer.ts +74 -163
- package/drscript/focus.meta +13 -0
- package/drscript/input/KeyboardMove.ts +40 -11
- package/drscript/input/KeyboardMove.ts.meta +10 -0
- package/drscript/input.meta +13 -0
- package/drscript/interface.meta +13 -0
- package/drscript/pinyin.meta +13 -0
- package/drscript/toast.meta +13 -0
- package/drscript/virtualgamepad.meta +13 -0
- package/package.json +1 -1
- package/drres/config/default.json +0 -101
- package/drres/config/default.json.meta +0 -6
- package/drres/icons/pointer-blue-60.png +0 -0
- package/drres/icons/pointer-pink-60.png +0 -0
- package/drres/icons/pointer-yellow-60.png +0 -0
- package/drscript/Info.ts +0 -78
- package/drscript/InternalUitl.ts +0 -65
- package/drscript/ad/AdManager.ts +0 -174
- package/drscript/ad/AdSlot.ts +0 -44
- package/drscript/ad/AggregateAdProvider.ts +0 -149
- package/drscript/ad/IAdProvider.ts +0 -39
- package/drscript/ad/MockAdProvider.ts +0 -36
- package/drscript/ad/MockAdProvider.ts.meta +0 -10
- package/drscript/ad/SelfAdProvider.ts +0 -41
- package/drscript/ad/SelfAdProvider.ts.meta +0 -10
- package/drscript/config/TvUiConfig.ts +0 -155
- package/drscript/config/TvUiConfig.ts.meta +0 -10
- package/drscript/config/TvUiConfigManager.ts +0 -133
- package/drscript/config/TvUiConfigManager.ts.meta +0 -10
- package/drscript/core/BackManager.ts +0 -38
- package/drscript/core/BackManager.ts.meta +0 -10
- package/drscript/core/NativeBridge.ts +0 -137
- package/drscript/core/NativeBridge.ts.meta +0 -10
- package/drscript/core/TvUi.ts +0 -69
- package/drscript/core/TvUi.ts.meta +0 -10
- package/drscript/core/TvUiRoot.ts +0 -137
- package/drscript/core/TvUiRoot.ts.meta +0 -10
- package/drscript/icon/IconConfig.ts +0 -7
- package/drscript/icon/IconConfig.ts.meta +0 -10
- package/drscript/icon/IconManager.ts +0 -97
- package/drscript/icon/IconManager.ts.meta +0 -10
- package/drscript/input/KeyCodeAdapter.ts +0 -23
- package/drscript/input/RemoteInputManager.ts +0 -105
- package/drscript/interface/ILobbyBridge.ts +0 -5
- package/drscript/toast/ToastComponent.ts +0 -35
- package/drscript/toast/ToastComponent.ts.meta +0 -10
- package/drscript/toast/ToastManager.ts +0 -66
- package/drscript/toast/ToastManager.ts.meta +0 -10
- package/drscript/toast/TvExitConfirmDialog.ts +0 -334
- package/drscript/toast/TvExitConfirmDialog.ts.meta +0 -10
- package/drscript/toast/UIFunctions.ts +0 -150
- package/drscript/toast/UIFunctions.ts.meta +0 -10
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import TvUiConfigManager from "../config/TvUiConfigManager";
|
|
2
|
-
import NativeBridge from "../core/NativeBridge";
|
|
3
|
-
import { TvUiAdChannelConfig } from "../config/TvUiConfig";
|
|
4
|
-
import IAdProvider, { AdRuntimeData, AdShowResult } from "./IAdProvider";
|
|
5
|
-
import { AdErrorCode, AdPlatform, AdSdk, AdType } from "../ad-sdk/ad-sdk";
|
|
6
|
-
|
|
7
|
-
export default class AggregateAdProvider implements IAdProvider {
|
|
8
|
-
public type: string = "aggregate";
|
|
9
|
-
private GAME_VERSION: string = "1.0.0";
|
|
10
|
-
private static initialized: boolean = false;
|
|
11
|
-
private static initTask: Promise<void> | null = null;
|
|
12
|
-
private static gameReadyNotified: boolean = false;
|
|
13
|
-
|
|
14
|
-
public isAvailable(): boolean {
|
|
15
|
-
return NativeBridge.hasBridge();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public load(data: AdRuntimeData): Promise<AdRuntimeData> {
|
|
19
|
-
return this.ensureSdk().then(() => data);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public show(data: AdRuntimeData): Promise<AdShowResult> {
|
|
23
|
-
let options = data.options || {};
|
|
24
|
-
let mode = options.mode || data.slotConfig.mode || "popup";
|
|
25
|
-
if (mode == "reward") {
|
|
26
|
-
return this.showReward(data);
|
|
27
|
-
}
|
|
28
|
-
return this.showPopup(data);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public hide(slotId: string, channel?: TvUiAdChannelConfig): void {
|
|
32
|
-
if (!AggregateAdProvider.initialized || !this.isAvailable()) return;
|
|
33
|
-
let runtime = TvUiConfigManager.getConfig();
|
|
34
|
-
try {
|
|
35
|
-
// TODO: fix
|
|
36
|
-
// AdSdk.hidePopupAd({
|
|
37
|
-
// cpId: runtime.cpId || "ppl",
|
|
38
|
-
// triggerScene: slotId || "",
|
|
39
|
-
// placementId: (channel && channel.placementId) || ""
|
|
40
|
-
// });
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.warn("[AggregateAdProvider] hide popup failed", error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private showReward(data: AdRuntimeData): Promise<AdShowResult> {
|
|
47
|
-
let options = data.options || {};
|
|
48
|
-
let channel = data.channel || <any>{};
|
|
49
|
-
let runtime = TvUiConfigManager.getConfig();
|
|
50
|
-
return AdSdk.requestAd({
|
|
51
|
-
adType: AdType.RewardVideo,
|
|
52
|
-
cpId: options.cpId || runtime.cpId || "ppl",
|
|
53
|
-
rewardType: options.rewardType || "reward",
|
|
54
|
-
triggerScene: options.scene || data.slotId,
|
|
55
|
-
extra: options.extra || {}
|
|
56
|
-
}).then((result: any) => {
|
|
57
|
-
if (!result || result.isCompleted !== true) {
|
|
58
|
-
if (options.onClose) options.onClose(result);
|
|
59
|
-
return <AdShowResult>{ status: "closed", data: result };
|
|
60
|
-
}
|
|
61
|
-
if (options.onSuccess) options.onSuccess(result);
|
|
62
|
-
return <AdShowResult>{ status: "success", data: result };
|
|
63
|
-
}).catch((error: any) => {
|
|
64
|
-
if (this.isUserAbandoned(error)) {
|
|
65
|
-
if (options.onClose) options.onClose(error);
|
|
66
|
-
return <AdShowResult>{ status: "closed", data: error };
|
|
67
|
-
}
|
|
68
|
-
return <AdShowResult>{ status: "failed", error: error };
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private showPopup(data: AdRuntimeData): Promise<AdShowResult> {
|
|
73
|
-
let options = data.options || {};
|
|
74
|
-
let channel = data.channel || <any>{};
|
|
75
|
-
let runtime = TvUiConfigManager.getConfig();
|
|
76
|
-
return Promise.reject(new Error("Popup ad not implemented"));
|
|
77
|
-
// TODO: fix
|
|
78
|
-
// return AdSdk.requestPopupAd({
|
|
79
|
-
// adType: AdType.Interstitial,
|
|
80
|
-
// cpId: options.cpId || runtime.cpId || "ppl",
|
|
81
|
-
// rewardType: options.rewardType || channel.rewardType || "popup",
|
|
82
|
-
// triggerScene: options.scene || data.slotId,
|
|
83
|
-
// placementId: channel.placementId || "",
|
|
84
|
-
// extra: options.extra || {}
|
|
85
|
-
// }).then((result: any) => {
|
|
86
|
-
// if (result && result.isClosed) {
|
|
87
|
-
// if (options.onClose) options.onClose(result);
|
|
88
|
-
// return <AdShowResult>{ status: "closed", data: result };
|
|
89
|
-
// }
|
|
90
|
-
// if (options.onLoad) options.onLoad(result);
|
|
91
|
-
// return <AdShowResult>{ status: "loaded", data: result };
|
|
92
|
-
// }).catch((error: any) => {
|
|
93
|
-
// return <AdShowResult>{ status: "failed", error: error };
|
|
94
|
-
// });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private ensureSdk(): Promise<void> {
|
|
98
|
-
if (AggregateAdProvider.initialized) return Promise.resolve();
|
|
99
|
-
if (AggregateAdProvider.initTask) return AggregateAdProvider.initTask;
|
|
100
|
-
|
|
101
|
-
let runtime = TvUiConfigManager.getConfig();
|
|
102
|
-
let adSdkConfig = runtime.adSdk || {};
|
|
103
|
-
let platform = this.getPlatform(adSdkConfig.platform || "xiaomi");
|
|
104
|
-
let adapterConfig: any = {};
|
|
105
|
-
let customConfig = adSdkConfig.adapterConfig || {};
|
|
106
|
-
let key: string;
|
|
107
|
-
adapterConfig.cpId = runtime.cpId || "ppl";
|
|
108
|
-
for (key in customConfig) adapterConfig[key] = customConfig[key];
|
|
109
|
-
|
|
110
|
-
let adapters: any = {};
|
|
111
|
-
adapters[platform] = adapterConfig;
|
|
112
|
-
|
|
113
|
-
AggregateAdProvider.initTask = AdSdk.init({
|
|
114
|
-
platform: platform,
|
|
115
|
-
adapters: adapters
|
|
116
|
-
}).then(() => {
|
|
117
|
-
AggregateAdProvider.initialized = true;
|
|
118
|
-
this.notifyGameReady(runtime.version || this.GAME_VERSION);
|
|
119
|
-
}).catch((error: any) => {
|
|
120
|
-
AggregateAdProvider.initTask = null;
|
|
121
|
-
throw error;
|
|
122
|
-
});
|
|
123
|
-
return AggregateAdProvider.initTask;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private notifyGameReady(version: string) {
|
|
127
|
-
if (AggregateAdProvider.gameReadyNotified) return;
|
|
128
|
-
AggregateAdProvider.gameReadyNotified = true;
|
|
129
|
-
try {
|
|
130
|
-
AdSdk.onGameReady(version || this.GAME_VERSION);
|
|
131
|
-
} catch (error) {
|
|
132
|
-
console.warn("[AggregateAdProvider] onGameReady failed", error);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private getPlatform(platform: string): any {
|
|
137
|
-
if (platform == "xiaomi" || !platform) return AdPlatform.Xiaomi;
|
|
138
|
-
return platform;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private isUserAbandoned(error: any): boolean {
|
|
142
|
-
if (!error) return false;
|
|
143
|
-
return error.code == AdErrorCode.UserAbandoned
|
|
144
|
-
|| error.code == 1006
|
|
145
|
-
|| error.isCompleted === false
|
|
146
|
-
|| error.is_completed === false
|
|
147
|
-
|| error.message == "Ad closed by user before completion";
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { TvUiAdChannelConfig, TvUiAdSlotConfig } from "../config/TvUiConfig";
|
|
2
|
-
|
|
3
|
-
export interface AdShowOptions {
|
|
4
|
-
slotId?: string;
|
|
5
|
-
mode?: string;
|
|
6
|
-
cpId?: string;
|
|
7
|
-
scene?: string;
|
|
8
|
-
rewardType?: string;
|
|
9
|
-
extra?: any;
|
|
10
|
-
container?: cc.Node;
|
|
11
|
-
onLoad?: (data?: any) => void;
|
|
12
|
-
onSuccess?: (data?: any) => void;
|
|
13
|
-
onClose?: (data?: any) => void;
|
|
14
|
-
onFail?: (data?: any) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface AdRuntimeData {
|
|
18
|
-
slotId: string;
|
|
19
|
-
slotConfig: TvUiAdSlotConfig;
|
|
20
|
-
channel: TvUiAdChannelConfig;
|
|
21
|
-
options: AdShowOptions;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type AdShowResultStatus = "success" | "loaded" | "closed" | "failed";
|
|
25
|
-
|
|
26
|
-
export interface AdShowResult {
|
|
27
|
-
status: AdShowResultStatus;
|
|
28
|
-
data?: any;
|
|
29
|
-
error?: any;
|
|
30
|
-
action?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default interface IAdProvider {
|
|
34
|
-
type: string;
|
|
35
|
-
isAvailable(): boolean;
|
|
36
|
-
load(data: AdRuntimeData): Promise<AdRuntimeData>;
|
|
37
|
-
show(data: AdRuntimeData): Promise<AdShowResult>;
|
|
38
|
-
hide(slotId: string, channel?: TvUiAdChannelConfig): void;
|
|
39
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import IAdProvider, { AdRuntimeData, AdShowResult } from "./IAdProvider";
|
|
2
|
-
|
|
3
|
-
export default class MockAdProvider implements IAdProvider {
|
|
4
|
-
public type: string = "mock";
|
|
5
|
-
|
|
6
|
-
public isAvailable(): boolean {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public load(data: AdRuntimeData): Promise<AdRuntimeData> {
|
|
11
|
-
return Promise.resolve(data);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public show(data: AdRuntimeData): Promise<AdShowResult> {
|
|
15
|
-
let options = data.options || {};
|
|
16
|
-
let mode = options.mode || data.slotConfig.mode || "popup";
|
|
17
|
-
console.log("[MockAdProvider] show", data.slotId, mode);
|
|
18
|
-
return new Promise<AdShowResult>((resolve) => {
|
|
19
|
-
setTimeout(() => {
|
|
20
|
-
let result = { mock: true, slotId: data.slotId };
|
|
21
|
-
if (mode == "reward") {
|
|
22
|
-
let rewardResult = { isCompleted: true, mock: true, slotId: data.slotId };
|
|
23
|
-
if (options.onSuccess) options.onSuccess(rewardResult);
|
|
24
|
-
resolve({ status: "success", data: rewardResult });
|
|
25
|
-
} else {
|
|
26
|
-
if (options.onLoad) options.onLoad(result);
|
|
27
|
-
resolve({ status: "loaded", data: result });
|
|
28
|
-
}
|
|
29
|
-
}, 0);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public hide(slotId: string): void {
|
|
34
|
-
console.log("[MockAdProvider] hide", slotId);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import IAdProvider, { AdRuntimeData, AdShowResult } from "./IAdProvider";
|
|
2
|
-
|
|
3
|
-
export default class SelfAdProvider implements IAdProvider {
|
|
4
|
-
public type: string = "self";
|
|
5
|
-
|
|
6
|
-
public isAvailable(): boolean {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public load(data: AdRuntimeData): Promise<AdRuntimeData> {
|
|
11
|
-
return Promise.resolve(data);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public show(data: AdRuntimeData): Promise<AdShowResult> {
|
|
15
|
-
let channel = data.channel || <any>{};
|
|
16
|
-
let options = data.options || {};
|
|
17
|
-
let path = channel.imagePath || (data.slotConfig.fallback && data.slotConfig.fallback.imagePath);
|
|
18
|
-
if (!path || !options.container) {
|
|
19
|
-
if (options.onLoad) options.onLoad({ self: true, slotId: data.slotId });
|
|
20
|
-
return Promise.resolve({ status: "loaded", data: { self: true, slotId: data.slotId } });
|
|
21
|
-
}
|
|
22
|
-
let node = options.container;
|
|
23
|
-
let sprite = node.getComponent(cc.Sprite) || node.addComponent(cc.Sprite);
|
|
24
|
-
sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
|
25
|
-
return new Promise<AdShowResult>((resolve) => {
|
|
26
|
-
cc.loader.loadRes(path, cc.SpriteFrame, (error: Error, frame: cc.SpriteFrame) => {
|
|
27
|
-
if (error || !frame) {
|
|
28
|
-
resolve({ status: "failed", error: error || { message: "self ad frame missing" } });
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
sprite.spriteFrame = frame;
|
|
32
|
-
node.active = true;
|
|
33
|
-
if (options.onLoad) options.onLoad({ self: true, slotId: data.slotId });
|
|
34
|
-
resolve({ status: "loaded", data: { self: true, slotId: data.slotId } });
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public hide(_slotId: string): void {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
export type TvUiDirection = "up" | "down" | "left" | "right";
|
|
2
|
-
|
|
3
|
-
export interface TvUiIconItem {
|
|
4
|
-
path?: string;
|
|
5
|
-
url?: string;
|
|
6
|
-
width?: number;
|
|
7
|
-
height?: number;
|
|
8
|
-
offsetX?: number;
|
|
9
|
-
offsetY?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface TvUiFocusVisualConfig {
|
|
13
|
-
enabled?: boolean;
|
|
14
|
-
frameEnabled?: boolean;
|
|
15
|
-
framePadding?: number;
|
|
16
|
-
frameColor?: string;
|
|
17
|
-
frameOpacity?: number;
|
|
18
|
-
lineWidth?: number;
|
|
19
|
-
animationTime?: number;
|
|
20
|
-
defaultIconKey?: string;
|
|
21
|
-
iconPlacement?: "topRight" | "bottomRight";
|
|
22
|
-
iconOffsetX?: number;
|
|
23
|
-
iconOffsetY?: number;
|
|
24
|
-
zIndex?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TvUiAdChannelConfig {
|
|
28
|
-
type: string;
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
priority?: number;
|
|
31
|
-
placementId?: string;
|
|
32
|
-
reward_type?: string;
|
|
33
|
-
action?: string;
|
|
34
|
-
rewardAction?: string;
|
|
35
|
-
popupAction?: string;
|
|
36
|
-
hideAction?: string;
|
|
37
|
-
imagePath?: string;
|
|
38
|
-
imageUrl?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface TvUiAdSlotConfig {
|
|
42
|
-
enabled?: boolean;
|
|
43
|
-
mode?: "reward" | "popup" | "banner" | "self" | string;
|
|
44
|
-
channels?: TvUiAdChannelConfig[];
|
|
45
|
-
fallback?: TvUiAdChannelConfig;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface TvUiAdSdkConfig {
|
|
49
|
-
platform?: "xiaomi" | string;
|
|
50
|
-
adapterConfig?: any;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface TvUiConfig {
|
|
54
|
-
designWidth?: number;
|
|
55
|
-
designHeight?: number;
|
|
56
|
-
resolutionPolicy?: number;
|
|
57
|
-
cpId?: string;
|
|
58
|
-
version?: string;
|
|
59
|
-
configPath?: string;
|
|
60
|
-
defaultScopeId?: string;
|
|
61
|
-
enableRemoteInput?: boolean;
|
|
62
|
-
enableCursor?: boolean;
|
|
63
|
-
enableLifecycle?: boolean;
|
|
64
|
-
focus?: TvUiFocusVisualConfig;
|
|
65
|
-
icons?: { [key: string]: TvUiIconItem };
|
|
66
|
-
ads?: { [slotId: string]: TvUiAdSlotConfig };
|
|
67
|
-
adSdk?: TvUiAdSdkConfig;
|
|
68
|
-
nativeCallback?: (action: string, data?: any) => void;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function createDefaultTvUiConfig(): TvUiConfig {
|
|
72
|
-
return {
|
|
73
|
-
designWidth: 1920,
|
|
74
|
-
designHeight: 1080,
|
|
75
|
-
cpId: "ppl",
|
|
76
|
-
version: "1.0.0",
|
|
77
|
-
configPath: "drres/config/default",
|
|
78
|
-
defaultScopeId: "page",
|
|
79
|
-
enableRemoteInput: true,
|
|
80
|
-
enableLifecycle: true,
|
|
81
|
-
focus: {
|
|
82
|
-
enabled: true,
|
|
83
|
-
frameEnabled: false,
|
|
84
|
-
framePadding: 10,
|
|
85
|
-
frameColor: "#ffd451",
|
|
86
|
-
frameOpacity: 230,
|
|
87
|
-
lineWidth: 5,
|
|
88
|
-
animationTime: 0.1,
|
|
89
|
-
defaultIconKey: "default",
|
|
90
|
-
iconPlacement: "bottomRight",
|
|
91
|
-
iconOffsetX: -20,
|
|
92
|
-
iconOffsetY: 20,
|
|
93
|
-
zIndex: 800
|
|
94
|
-
},
|
|
95
|
-
icons: {
|
|
96
|
-
"default": {
|
|
97
|
-
path: "drres/icons/pointer-yellow-60",
|
|
98
|
-
width: 60,
|
|
99
|
-
height: 60,
|
|
100
|
-
offsetX: -20,
|
|
101
|
-
offsetY: 20
|
|
102
|
-
},
|
|
103
|
-
"yellow": {
|
|
104
|
-
path: "drres/icons/pointer-yellow-60",
|
|
105
|
-
width: 60,
|
|
106
|
-
height: 60,
|
|
107
|
-
offsetX: -20,
|
|
108
|
-
offsetY: 20
|
|
109
|
-
},
|
|
110
|
-
"blue": {
|
|
111
|
-
path: "drres/icons/pointer-blue-60",
|
|
112
|
-
width: 60,
|
|
113
|
-
height: 60,
|
|
114
|
-
offsetX: -20,
|
|
115
|
-
offsetY: 20
|
|
116
|
-
},
|
|
117
|
-
"pink": {
|
|
118
|
-
path: "drres/icons/pointer-pink-60",
|
|
119
|
-
width: 60,
|
|
120
|
-
height: 60,
|
|
121
|
-
offsetX: -20,
|
|
122
|
-
offsetY: 20
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
adSdk: {
|
|
126
|
-
platform: "xiaomi"
|
|
127
|
-
},
|
|
128
|
-
ads: {
|
|
129
|
-
"reward": {
|
|
130
|
-
enabled: true,
|
|
131
|
-
mode: "reward",
|
|
132
|
-
channels: [
|
|
133
|
-
{ type: "aggregate", priority: 1, reward_type: "reward" },
|
|
134
|
-
{ type: "mock", priority: 100 }
|
|
135
|
-
]
|
|
136
|
-
},
|
|
137
|
-
"popup": {
|
|
138
|
-
enabled: true,
|
|
139
|
-
mode: "popup",
|
|
140
|
-
channels: [
|
|
141
|
-
{ type: "aggregate", priority: 1 },
|
|
142
|
-
{ type: "mock", priority: 100 }
|
|
143
|
-
]
|
|
144
|
-
},
|
|
145
|
-
"game": {
|
|
146
|
-
enabled: true,
|
|
147
|
-
mode: "popup",
|
|
148
|
-
channels: [
|
|
149
|
-
{ type: "aggregate", priority: 1 },
|
|
150
|
-
{ type: "mock", priority: 100 }
|
|
151
|
-
]
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { createDefaultTvUiConfig, TvUiConfig } from "./TvUiConfig";
|
|
2
|
-
|
|
3
|
-
type ConfigListener = (config: TvUiConfig) => void;
|
|
4
|
-
|
|
5
|
-
export default class TvUiConfigManager {
|
|
6
|
-
private static readonly LOCAL_KEY = "tvui_local_config";
|
|
7
|
-
private static config: TvUiConfig = createDefaultTvUiConfig();
|
|
8
|
-
private static projectConfig: TvUiConfig | null = null;
|
|
9
|
-
private static resourceConfig: TvUiConfig | null = null;
|
|
10
|
-
private static listeners: ConfigListener[] = [];
|
|
11
|
-
|
|
12
|
-
public static init(config?: TvUiConfig, callback?: (config: TvUiConfig) => void) {
|
|
13
|
-
this.projectConfig = config || {};
|
|
14
|
-
this.rebuildConfig();
|
|
15
|
-
this.loadResourceConfig((loaded: boolean) => {
|
|
16
|
-
if (loaded) {
|
|
17
|
-
this.rebuildConfig();
|
|
18
|
-
this.emitChanged();
|
|
19
|
-
}
|
|
20
|
-
if (callback) callback(this.config);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static getConfig(): TvUiConfig {
|
|
25
|
-
return this.config;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public static updateConfig(config: TvUiConfig, saveLocal: boolean = false) {
|
|
29
|
-
if (saveLocal) {
|
|
30
|
-
this.saveLocalConfig(config);
|
|
31
|
-
} else {
|
|
32
|
-
this.projectConfig = this.merge(this.projectConfig || {}, config || {});
|
|
33
|
-
}
|
|
34
|
-
this.rebuildConfig();
|
|
35
|
-
this.emitChanged();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public static onChanged(listener: ConfigListener) {
|
|
39
|
-
if (!listener) return;
|
|
40
|
-
if (this.listeners.indexOf(listener) < 0) this.listeners.push(listener);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static offChanged(listener: ConfigListener) {
|
|
44
|
-
let index = this.listeners.indexOf(listener);
|
|
45
|
-
if (index >= 0) this.listeners.splice(index, 1);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private static rebuildConfig() {
|
|
49
|
-
let next = this.merge(createDefaultTvUiConfig(), this.resourceConfig || {});
|
|
50
|
-
next = this.merge(next, this.projectConfig || {});
|
|
51
|
-
next = this.merge(next, this.loadLocalConfig());
|
|
52
|
-
this.config = next;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private static loadResourceConfig(callback: (loaded: boolean) => void) {
|
|
56
|
-
let path = (this.projectConfig && this.projectConfig.configPath) || this.config.configPath;
|
|
57
|
-
if (!path || !cc || !cc.loader || !cc.loader.loadRes) {
|
|
58
|
-
callback(false);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
cc.loader.loadRes(path, (error: Error, asset: any) => {
|
|
63
|
-
if (error || !asset) {
|
|
64
|
-
callback(false);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
let json = asset.json || asset;
|
|
68
|
-
this.resourceConfig = json || null;
|
|
69
|
-
callback(!!this.resourceConfig);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private static loadLocalConfig(): TvUiConfig {
|
|
74
|
-
try {
|
|
75
|
-
let raw = cc.sys.localStorage.getItem(this.LOCAL_KEY);
|
|
76
|
-
if (!raw) return {};
|
|
77
|
-
return JSON.parse(raw) || {};
|
|
78
|
-
} catch (e) {
|
|
79
|
-
return {};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private static saveLocalConfig(config: TvUiConfig) {
|
|
84
|
-
let local = this.merge(this.loadLocalConfig(), config || {});
|
|
85
|
-
try {
|
|
86
|
-
cc.sys.localStorage.setItem(this.LOCAL_KEY, JSON.stringify(local));
|
|
87
|
-
} catch (e) {
|
|
88
|
-
console.warn("[TvUiConfigManager] save local config failed", e);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private static emitChanged() {
|
|
93
|
-
for (let i = 0; i < this.listeners.length; i++) {
|
|
94
|
-
this.listeners[i](this.config);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private static merge(base: any, extra: any): any {
|
|
99
|
-
let result: any = {};
|
|
100
|
-
let key: string;
|
|
101
|
-
base = base || {};
|
|
102
|
-
extra = extra || {};
|
|
103
|
-
for (key in base) {
|
|
104
|
-
if (!base.hasOwnProperty(key)) continue;
|
|
105
|
-
result[key] = this.clone(base[key]);
|
|
106
|
-
}
|
|
107
|
-
for (key in extra) {
|
|
108
|
-
if (!extra.hasOwnProperty(key)) continue;
|
|
109
|
-
if (this.isPlainObject(result[key]) && this.isPlainObject(extra[key])) {
|
|
110
|
-
result[key] = this.merge(result[key], extra[key]);
|
|
111
|
-
} else {
|
|
112
|
-
result[key] = this.clone(extra[key]);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private static clone(value: any): any {
|
|
119
|
-
if (value instanceof Array) {
|
|
120
|
-
let list = [];
|
|
121
|
-
for (let i = 0; i < value.length; i++) list.push(this.clone(value[i]));
|
|
122
|
-
return list;
|
|
123
|
-
}
|
|
124
|
-
if (this.isPlainObject(value)) {
|
|
125
|
-
return this.merge({}, value);
|
|
126
|
-
}
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private static isPlainObject(value: any): boolean {
|
|
131
|
-
return value && typeof value == "object" && !(value instanceof Array);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type BackHandler = () => boolean | void;
|
|
2
|
-
|
|
3
|
-
export default class BackManager {
|
|
4
|
-
private static handlers: BackHandler[] = [];
|
|
5
|
-
private static fallback: BackHandler | null = null;
|
|
6
|
-
|
|
7
|
-
public static reset() {
|
|
8
|
-
this.handlers = [];
|
|
9
|
-
this.fallback = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public static setFallback(handler: BackHandler | null) {
|
|
13
|
-
this.fallback = handler;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static push(handler: BackHandler) {
|
|
17
|
-
if (!handler) return;
|
|
18
|
-
this.remove(handler);
|
|
19
|
-
this.handlers.push(handler);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public static remove(handler: BackHandler) {
|
|
23
|
-
for (let i = this.handlers.length - 1; i >= 0; i--) {
|
|
24
|
-
if (this.handlers[i] == handler) this.handlers.splice(i, 1);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public static handle(): boolean {
|
|
29
|
-
for (let i = this.handlers.length - 1; i >= 0; i--) {
|
|
30
|
-
let handler = this.handlers[i];
|
|
31
|
-
if (!handler) continue;
|
|
32
|
-
let result = handler();
|
|
33
|
-
if (result !== false) return true;
|
|
34
|
-
}
|
|
35
|
-
if (this.fallback) return this.fallback() !== false;
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|