Skip to content

Commit 0bf8e78

Browse files
committed
feat: add Device::inputMode
1 parent 9a8dda8 commit 0bf8e78

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

docs/apis/GameAPI/Device.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Each device information object contains some fixed object properties. for a spec
2727
| dv.lastPing | Network latency for players (ms) | `Integer` |
2828
| dv.lastPacketLoss | Player's network packet loss rate (%) | `Float` |
2929
| dv.os | The OS type of the player's device | `String` |
30+
| dv.inputMode | Player's input mode | `Integer` |
3031
| dv.serverAddress | The player's connection address | `String` |
3132
| dv.clientId | ID of the player client | `String` |
3233

@@ -51,3 +52,10 @@ Among them, the operating system type attribute returns a string that records th
5152
| `WindowsPhone` | Windows Mobile |
5253
| `Dedicated` | Dedicated server (Device os spoofer) |
5354
| `Unknown` | Unknown System |
55+
56+
| Input mode ENUM |
57+
| ---------------------------- |
58+
| `InputMode.Mouse` |
59+
| `InputMode.Touch` |
60+
| `InputMode.GamePad` |
61+
| `InputMode.MotionController` |

docs/apis/GameAPI/Device.zh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| dv.lastPing | 玩家的网络延迟时间(ms) | `Integer` |
2828
| dv.lastPacketLoss | 玩家的网络丢包率(%) | `Float` |
2929
| dv.os | 玩家设备的操作系统类型 | `String` |
30+
| dv.inputMode | 玩家的操作模式 | `Integer` |
3031
| dv.serverAddress | 玩家连接的地址 | `String` |
3132
| dv.clientId | 玩家客户端的识别码ID | `String` |
3233

@@ -50,3 +51,10 @@
5051
| `Xbox` | 主机微软Xbox |
5152
| `WindowsPhone` | 手机微软Windows Mobile |
5253
| `Unknown` | 未知系统 |
54+
55+
| Input mode ENUM | 备注 |
56+
| ---------------------------- | ---------- |
57+
| `InputMode.Mouse` | 鼠标 |
58+
| `InputMode.Touch` | 触屏 |
59+
| `InputMode.GamePad` | 手柄 |
60+
| `InputMode.MotionController` | 运动控制器 |

src/legacy/api/DeviceAPI.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ll/api/service/Bedrock.h"
55
#include "magic_enum.hpp"
66
#include "mc/certificates/WebToken.h"
7+
#include "mc/enums/InputMode.h"
78
#include "mc/network/ConnectionRequest.h"
89
#include "mc/network/ServerNetworkHandler.h"
910
#include "mc/world/actor/player/Player.h"
@@ -13,6 +14,7 @@
1314
#include <string>
1415

1516
//////////////////// Class Definition ////////////////////
17+
ClassDefine<void> InputModeStaticBuilder = EnumDefineBuilder<InputMode>::build("InputMode");
1618

1719
ClassDefine<DeviceClass> DeviceClassBuilder = defineClass<DeviceClass>("LLSE_Device")
1820
.constructor(nullptr)
@@ -22,8 +24,8 @@ ClassDefine<DeviceClass> DeviceClassBuilder = defineClass<DeviceClass>("LLSE_Dev
2224
.instanceProperty("lastPing", &DeviceClass::getLastPing)
2325
.instanceProperty("lastPacketLoss", &DeviceClass::getLastPacketLoss)
2426
.instanceProperty("os", &DeviceClass::getOs)
25-
//.instanceProperty("inputMode", &DeviceClass::getInputMode)
26-
//.instanceProperty("playMode", &DeviceClass::getPlayMode)
27+
.instanceProperty("inputMode", &DeviceClass::getInputMode)
28+
// .instanceProperty("playMode", &DeviceClass::getPlayMode)
2729
.instanceProperty("serverAddress", &DeviceClass::getServerAddress)
2830
.instanceProperty("clientId", &DeviceClass::getClientId)
2931
.build();
@@ -121,9 +123,9 @@ Local<Value> DeviceClass::getServerAddress() {
121123
return Local<Value>();
122124
}
123125
if (player->isSimulatedPlayer()) String::newString("unknown");
124-
Json::Value requestJson = ll::service::getServerNetworkHandler()
125-
->fetchConnectionRequest(player->getNetworkIdentifier())
126-
.mRawToken->mDataInfo;
126+
Json::Value& requestJson = ll::service::getServerNetworkHandler()
127+
->fetchConnectionRequest(player->getNetworkIdentifier())
128+
.mRawToken->mDataInfo;
127129
return String::newString(requestJson.get("ServerAddress", "unknown").asString("unknown"));
128130
}
129131
CATCH("Fail in getServerAddress!")
@@ -136,29 +138,30 @@ Local<Value> DeviceClass::getClientId() {
136138

137139
return String::newString(
138140
ll::service::getServerNetworkHandler()->fetchConnectionRequest(player->getNetworkIdentifier()).getDeviceId()
139-
); //=============???
141+
);
140142
}
141143
CATCH("Fail in getClientId!")
142144
}
143145

144-
// Local<Value> DeviceClass::getInputMode() {
145-
// try {
146-
// Player* player = getPlayer();
147-
// if (!player)
148-
// return Local<Value>();
149-
//
150-
// return Number::newNumber((int)player->getInputMode());
151-
// }
152-
// CATCH("Fail in getInputMode!")
153-
// }
154-
//
146+
Local<Value> DeviceClass::getInputMode() {
147+
try {
148+
Player* player = getPlayer();
149+
if (!player) return Local<Value>();
150+
151+
Json::Value& requestJson = ll::service::getServerNetworkHandler()
152+
->fetchConnectionRequest(player->getNetworkIdentifier())
153+
.mRawToken->mDataInfo;
154+
return Number::newNumber(requestJson.get("CurrentInputMode", 0).asInt(0));
155+
}
156+
CATCH("Fail in getInputMode!")
157+
}
158+
155159
// Local<Value> DeviceClass::getPlayMode() {
156160
// try {
157161
// Player* player = getPlayer();
158-
// if (!player)
159-
// return Local<Value>();
160-
//
161-
// return Number::newNumber((int)player->getPlayMode());
162+
// if (!player) return Local<Value>();
163+
164+
// return Number::newNumber(0);
162165
// }
163166
// CATCH("Fail in getPlayMode!")
164167
// }

src/legacy/api/DeviceAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DeviceClass : public ScriptClass {
2323
Local<Value> getLastPing();
2424
Local<Value> getLastPacketLoss();
2525
Local<Value> getOs();
26-
// Local<Value> getInputMode();
26+
Local<Value> getInputMode();
2727
// Local<Value> getPlayMode();
2828
Local<Value> getServerAddress();
2929
Local<Value> getClientId();

0 commit comments

Comments
 (0)