drgame-cc 1.0.52 → 1.0.55
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/drscript/Define.ts +91 -5
- package/drscript/KeyAdapter.ts +11 -0
- package/drscript/PlatformAdapter.ts +6 -6
- package/drscript/README.md +1 -7
- package/drscript/component/ExitWin.ts +0 -4
- package/drscript/virtualgamepad/VirtualGamepad.ts +638 -0
- package/drscript/virtualgamepad/VirtualGamepadView.ts +311 -280
- package/package.json +1 -1
- package/drscript/virtualgamepad/VirtualGamepadClient.ts +0 -214
- package/drscript/virtualgamepad/VirtualGamepadConfig.ts +0 -70
- package/drscript/virtualgamepad/VirtualGamepadManager.ts +0 -809
package/drscript/Define.ts
CHANGED
|
@@ -56,16 +56,102 @@ export enum AwardModel {
|
|
|
56
56
|
Video = "video",
|
|
57
57
|
/** 免费 */
|
|
58
58
|
Free = "free",
|
|
59
|
-
/**
|
|
59
|
+
/** 时间限制 */
|
|
60
60
|
TimeLimit = "time_limit",
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** 渠道类型 */
|
|
64
64
|
export enum EAppItem {
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
/**
|
|
65
|
+
/** 测试环境 */
|
|
66
|
+
Test = "00",
|
|
67
|
+
/** 道然(原乐窝) */
|
|
68
68
|
LeWo = "29",
|
|
69
69
|
/** 咪咕 */
|
|
70
|
-
Migu = "
|
|
70
|
+
Migu = "my",
|
|
71
|
+
/** 海信 */
|
|
72
|
+
Hisense = "h",
|
|
73
|
+
/** 乐视 */
|
|
74
|
+
LeTV = "le",
|
|
75
|
+
/** 陕西移动 */
|
|
76
|
+
ShanxiMobile = "sy",
|
|
77
|
+
/** 洛神 */
|
|
78
|
+
LuoShen = "lu",
|
|
79
|
+
/** 百视通 */
|
|
80
|
+
BesTV = "33",
|
|
81
|
+
/** 联通中屏 */
|
|
82
|
+
UnicomMedium = "10",
|
|
83
|
+
/** 联通 */
|
|
84
|
+
Unicom = "bt",
|
|
85
|
+
/** 小米TV */
|
|
86
|
+
XiaomiTV = "25",
|
|
87
|
+
/** 雷鸟 */
|
|
88
|
+
Leinao = "47",
|
|
89
|
+
/** 长虹 */
|
|
90
|
+
Changhong = "90",
|
|
91
|
+
/** 极米 */
|
|
92
|
+
Jimi = "37",
|
|
93
|
+
/** 百视通酒店(小帅) */
|
|
94
|
+
BesTVHotelXiaoshuai = "bi",
|
|
95
|
+
/** 华为移动端 */
|
|
96
|
+
HuaweiMobile = "h5",
|
|
97
|
+
/** OPPO移动端 */
|
|
98
|
+
OPPOMobile = "03",
|
|
99
|
+
/** VIVO移动端 */
|
|
100
|
+
VIVOMobile = "v5",
|
|
101
|
+
/** 小米移动端 */
|
|
102
|
+
XiaomiMobile = "x5",
|
|
103
|
+
/** KTC闺蜜机 */
|
|
104
|
+
KTCFriendsMachine = "mc",
|
|
105
|
+
/** 沙发 */
|
|
106
|
+
Sofa = "27",
|
|
107
|
+
/** 长城车载 */
|
|
108
|
+
GreatWallCar = "cc",
|
|
109
|
+
/** 海尔闺蜜机 */
|
|
110
|
+
HaierFriendsMachine = "hg",
|
|
111
|
+
/** 百视通酒店(携旅) */
|
|
112
|
+
BesTVHotelXielv = "bl",
|
|
113
|
+
/** 野草助手 */
|
|
114
|
+
WildGrass = "yc",
|
|
115
|
+
/** 当贝 */
|
|
116
|
+
Dangbei = "07",
|
|
117
|
+
/** 抖音 */
|
|
118
|
+
Douyin = "t",
|
|
119
|
+
/** 应用宝 */
|
|
120
|
+
YingyongBao = "y9",
|
|
121
|
+
/** 欢网 */
|
|
122
|
+
Huanwang = "hw",
|
|
123
|
+
/** 蜂鸟 */
|
|
124
|
+
Fengniao = "fn",
|
|
125
|
+
/** 酷开TV */
|
|
126
|
+
CoocaaTV = "31",
|
|
127
|
+
/** mumu模拟器 */
|
|
128
|
+
MuMu = "mm",
|
|
129
|
+
/** 坚果 */
|
|
130
|
+
Jianguo = "jg",
|
|
131
|
+
/** 欢喜 */
|
|
132
|
+
Huanxi = "hx",
|
|
133
|
+
/** KTC电视 */
|
|
134
|
+
KTCTV = "kc",
|
|
135
|
+
/** 阿里TV */
|
|
136
|
+
AliTV = "26",
|
|
137
|
+
/** 乐家 */
|
|
138
|
+
Lejia = "al",
|
|
139
|
+
/** 视推 */
|
|
140
|
+
Shitui = "st",
|
|
141
|
+
/** 讯码 */
|
|
142
|
+
Xunma = "",
|
|
143
|
+
/** 华数音箱 */
|
|
144
|
+
HuashuSoundBox = "hu",
|
|
145
|
+
/** kook */
|
|
146
|
+
Kook = "bk",
|
|
147
|
+
/** 欢网长虹 */
|
|
148
|
+
HuanwangChanghong = "hh",
|
|
149
|
+
/** 欢网TCL */
|
|
150
|
+
HuanwangTCL = "ht",
|
|
151
|
+
/** 赛的美 */
|
|
152
|
+
Saidemei = "sd",
|
|
153
|
+
/** 华为TV */
|
|
154
|
+
HuaweiTV = "70",
|
|
155
|
+
/** 雷鸟多屏互动 */
|
|
156
|
+
LeinaoMultiScreen = "dp",
|
|
71
157
|
}
|
package/drscript/KeyAdapter.ts
CHANGED
|
@@ -6,6 +6,14 @@ export class KeyAdapter {
|
|
|
6
6
|
private static keyHandler: ((event: { key: KeyCode, action: KeyAction }) => void) | null = null;
|
|
7
7
|
private static keyboardBound: boolean = false;
|
|
8
8
|
|
|
9
|
+
/** 虚拟手柄模式:激活时忽略键盘/遥控器/AdSdk 输入 */
|
|
10
|
+
private static _virtualGamepadActive: boolean = false;
|
|
11
|
+
|
|
12
|
+
/** 设置虚拟手柄模式,连接时自动禁用键盘/遥控器输入 */
|
|
13
|
+
public static setVirtualGamepadMode(active: boolean) {
|
|
14
|
+
KeyAdapter._virtualGamepadActive = active;
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
/** 防重复:记录上次处理的按键,同一按键在 150ms 内忽略重复 */
|
|
10
18
|
private static lastKey: string = "";
|
|
11
19
|
private static lastAction: string = "";
|
|
@@ -70,16 +78,19 @@ export class KeyAdapter {
|
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
private static onKeyboardDown(event: cc.Event.EventKeyboard) {
|
|
81
|
+
if (KeyAdapter._virtualGamepadActive) return;
|
|
73
82
|
const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
|
|
74
83
|
if (key) KeyAdapter.dispatchKey(key, KeyAction.Down);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
private static onKeyboardUp(event: cc.Event.EventKeyboard) {
|
|
87
|
+
if (KeyAdapter._virtualGamepadActive) return;
|
|
78
88
|
const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
|
|
79
89
|
if (key) KeyAdapter.dispatchKey(key, KeyAction.Up);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
private static dispatchKey(key: KeyCode, action: KeyAction) {
|
|
93
|
+
if (KeyAdapter._virtualGamepadActive) return;
|
|
83
94
|
// console.log(`[KeyAdapter] dispatchKey: ${key}, action: ${action}`);
|
|
84
95
|
// 防重复:同一按键+动作在 150ms 内重复触发则不处理
|
|
85
96
|
let now = Date.now();
|
|
@@ -15,7 +15,7 @@ export class PlatformAdapter {
|
|
|
15
15
|
/** WebBridge */
|
|
16
16
|
public static get webBridge() { return UIAdapter.webBridge; }
|
|
17
17
|
/** 渠道类型 */
|
|
18
|
-
private static appItem: EAppItem = EAppItem.
|
|
18
|
+
private static appItem: EAppItem = EAppItem.Test;
|
|
19
19
|
/** 是否是会员 */
|
|
20
20
|
private static isVIP: boolean = false;
|
|
21
21
|
|
|
@@ -32,7 +32,7 @@ export class PlatformAdapter {
|
|
|
32
32
|
*/
|
|
33
33
|
public static async init(cnName: string, minigameID: number, focusIcon: FingerStyle) {
|
|
34
34
|
// ── 初始化渠道类型 ──
|
|
35
|
-
this.appItem = PlatformUtil.getUrlParam('appItem') as EAppItem || EAppItem.
|
|
35
|
+
this.appItem = PlatformUtil.getUrlParam('appItem') as EAppItem || EAppItem.LeWo;
|
|
36
36
|
this.isVIP = PlatformUtil.getUrlParam('isVIP') === '1';
|
|
37
37
|
|
|
38
38
|
// ── UI 初始化 ──
|
|
@@ -47,8 +47,8 @@ export class PlatformAdapter {
|
|
|
47
47
|
platform: AdPlatform.Xiaomi,
|
|
48
48
|
adapters: { [AdPlatform.Xiaomi]: { cpId: this.contentId } },
|
|
49
49
|
reporter: {
|
|
50
|
-
app_item:
|
|
51
|
-
content_type: "游戏",
|
|
50
|
+
app_item: this.appItem,
|
|
51
|
+
content_type: this.appItem === EAppItem.LeWo ? "乐窝" : "游戏",
|
|
52
52
|
content_id: this.contentId,
|
|
53
53
|
content_title: cnName,
|
|
54
54
|
},
|
|
@@ -74,11 +74,11 @@ export class PlatformAdapter {
|
|
|
74
74
|
/** 是否 Cocos 环境 */
|
|
75
75
|
private static get isCocos() { return window['cc'] != undefined; }
|
|
76
76
|
/** 是否基座环境 */
|
|
77
|
-
|
|
77
|
+
public static get isWebBridge() { return this.webBridge.isAvailable(); }
|
|
78
78
|
/** 是否可以观看视频 */
|
|
79
79
|
private static get canWatchVideo() { return this.isXiaomi; }
|
|
80
80
|
/** 是否小米平台 */
|
|
81
|
-
|
|
81
|
+
public static get isXiaomi() {
|
|
82
82
|
if (typeof window === 'undefined') return null;
|
|
83
83
|
return window['AppBridge'] || null;
|
|
84
84
|
}
|
package/drscript/README.md
CHANGED
|
@@ -58,13 +58,7 @@ PlatformAdapter.showHelperWin('skeleton', () => {
|
|
|
58
58
|
PlatformAdapter.report(AnalyticsEvent.StartGame, AnalyticsAction.Click);
|
|
59
59
|
// 批量上报
|
|
60
60
|
PlatformAdapter.reportBatch([AnalyticsEvent.StartGame, AnalyticsEvent.LevelComplete]);
|
|
61
|
-
|
|
62
|
-
### 1.8 属性
|
|
63
|
-
```typescript
|
|
64
|
-
PlatformAdapter.isCocos // 是否 Cocos 环境
|
|
65
|
-
PlatformAdapter.isWebBridge // 是否基座环境
|
|
66
|
-
PlatformAdapter.canWatchVideo // 是否可以观看视频(小米 TV)
|
|
67
|
-
PlatformAdapter.isVIP // 是否 VIP 用户
|
|
61
|
+
|
|
68
62
|
```
|
|
69
63
|
## 二、KeyAdapter 按键适配
|
|
70
64
|
### 2.1 外部回调
|
|
@@ -21,15 +21,11 @@ export default class ExitWin extends cc.Component {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
private async onClickExit() {
|
|
24
|
-
console.log("onClickExit", PlatformAdapter.isXiaomi, PlatformAdapter.isWebBridge);
|
|
25
24
|
if (PlatformAdapter.isXiaomi) {
|
|
26
|
-
console.log("onClickExit Xiaomi");
|
|
27
25
|
await AdSdk.exitGame();
|
|
28
26
|
} else if (PlatformAdapter.isWebBridge) {
|
|
29
|
-
console.log("onClickExit WebBridge");
|
|
30
27
|
PlatformAdapter.webBridge.callHandler("router/navigateBack", {}, (a) => { cc.log(a); });
|
|
31
28
|
} else {
|
|
32
|
-
console.log("onClickExit Other");
|
|
33
29
|
cc.game.end();
|
|
34
30
|
}
|
|
35
31
|
}
|