@oasiz/sdk 1.5.2 → 1.5.4
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/README.md +14 -11
- package/dist/index.cjs +203 -63
- package/dist/index.d.cts +145 -1
- package/dist/index.d.ts +145 -1
- package/dist/index.js +199 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,9 @@ Typed SDK for integrating browser games with the Oasiz platform: score, haptics,
|
|
|
21
21
|
npm install @oasiz/sdk
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
The published package includes ESM, CommonJS, and TypeScript declarations.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
25
27
|
|
|
26
28
|
```ts
|
|
27
29
|
import { oasiz } from "@oasiz/sdk";
|
|
@@ -36,10 +38,10 @@ oasiz.saveGameState({ level, coins: 42 });
|
|
|
36
38
|
// 3. Trigger haptics on key events
|
|
37
39
|
oasiz.triggerHaptic("medium");
|
|
38
40
|
|
|
39
|
-
// 4. Respect the host's top safe area
|
|
41
|
+
// 4. Respect the host's top safe area (percent of viewport height → CSS vh)
|
|
40
42
|
document.documentElement.style.setProperty(
|
|
41
43
|
"--safe-top",
|
|
42
|
-
`${oasiz.safeAreaTop}
|
|
44
|
+
`${oasiz.safeAreaTop}vh`,
|
|
43
45
|
);
|
|
44
46
|
|
|
45
47
|
// 5. Submit score when the game ends
|
|
@@ -194,15 +196,15 @@ private onGameOver(): void {
|
|
|
194
196
|
|
|
195
197
|
### Layout
|
|
196
198
|
|
|
197
|
-
Use the runtime safe-area value instead of hardcoded top offsets. The
|
|
199
|
+
Use the runtime safe-area value instead of hardcoded top offsets. The SDK returns the top inset as **a percentage of the viewport height (0–100)**. If the host exposes CSS pixels via `window.getSafeAreaTop()` or `window.__OASIZ_SAFE_AREA_TOP__`, the SDK converts using `window.innerHeight`. The host may instead set **`window.getSafeAreaTopPercent()`** or **`window.__OASIZ_SAFE_AREA_TOP_PERCENT__`** (0–100) and that value is used directly.
|
|
198
200
|
|
|
199
201
|
#### `oasiz.getSafeAreaTop(): number`
|
|
200
202
|
|
|
201
|
-
Returns the
|
|
203
|
+
Returns the top inset as a percentage of viewport height (0–100). To get pixels in JavaScript, use `(getSafeAreaTop() / 100) * window.innerHeight`. In CSS, the same value matches **`vh`** units (for example `12.5vh` for 12.5% of the viewport height). Unsupported hosts return `0`.
|
|
202
204
|
|
|
203
205
|
```ts
|
|
204
|
-
const
|
|
205
|
-
document.documentElement.style.setProperty("--safe-top", `${
|
|
206
|
+
const safeTopPct = oasiz.getSafeAreaTop();
|
|
207
|
+
document.documentElement.style.setProperty("--safe-top", `${safeTopPct}vh`);
|
|
206
208
|
```
|
|
207
209
|
|
|
208
210
|
#### `oasiz.safeAreaTop`
|
|
@@ -453,9 +455,10 @@ public class GameManager : MonoBehaviour
|
|
|
453
455
|
OasizSDK.OnPause += OnPause;
|
|
454
456
|
OasizSDK.OnResume += OnResume;
|
|
455
457
|
|
|
456
|
-
// Offset UI for the host's top safe area
|
|
457
|
-
float
|
|
458
|
-
|
|
458
|
+
// Offset UI for the host's top safe area (0–100 percent of Screen.height)
|
|
459
|
+
float safeTopPct = OasizSDK.SafeAreaTop;
|
|
460
|
+
float safeTopPx = safeTopPct / 100f * Screen.height;
|
|
461
|
+
Debug.Log($"Safe area top: {safeTopPx}px ({safeTopPct}% of height)");
|
|
459
462
|
|
|
460
463
|
// Emit score normalization anchors
|
|
461
464
|
OasizSDK.EmitScoreConfig(new ScoreConfig(
|
|
@@ -498,7 +501,7 @@ public class GameManager : MonoBehaviour
|
|
|
498
501
|
| `oasiz.loadGameState()` | `OasizSDK.LoadGameState()` → `Dictionary<string, object>` |
|
|
499
502
|
| `oasiz.saveGameState(obj)` | `OasizSDK.SaveGameState(Dictionary<string, object>)` |
|
|
500
503
|
| `oasiz.flushGameState()` | `OasizSDK.FlushGameState()` |
|
|
501
|
-
| `oasiz.getSafeAreaTop()` / `safeAreaTop` | `OasizSDK.GetSafeAreaTop()` / `OasizSDK.SafeAreaTop` (`float`,
|
|
504
|
+
| `oasiz.getSafeAreaTop()` / `safeAreaTop` | `OasizSDK.GetSafeAreaTop()` / `OasizSDK.SafeAreaTop` (`float`, 0–100, % of viewport height) |
|
|
502
505
|
| `oasiz.setLeaderboardVisible(v)` | `OasizSDK.SetLeaderboardVisible(bool)` |
|
|
503
506
|
| `oasiz.onPause` / `onResume` | `OasizSDK.OnPause` / `OnResume` static events |
|
|
504
507
|
| `oasiz.onBackButton` | `OasizSDK.OnBackButton` or `SubscribeBackButton(Action)` (reference-counts `__oasizSetBackOverride`) |
|
package/dist/index.cjs
CHANGED
|
@@ -20,10 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
addScore: () => addScore,
|
|
23
24
|
enableLogOverlay: () => enableLogOverlay,
|
|
24
25
|
flushGameState: () => flushGameState,
|
|
25
26
|
getGameId: () => getGameId,
|
|
26
27
|
getPlayerAvatar: () => getPlayerAvatar,
|
|
28
|
+
getPlayerCharacter: () => getPlayerCharacter,
|
|
29
|
+
getPlayerId: () => getPlayerId,
|
|
27
30
|
getPlayerName: () => getPlayerName,
|
|
28
31
|
getRoomCode: () => getRoomCode,
|
|
29
32
|
getSafeAreaTop: () => getSafeAreaTop,
|
|
@@ -37,6 +40,7 @@ __export(index_exports, {
|
|
|
37
40
|
openInviteModal: () => openInviteModal,
|
|
38
41
|
saveGameState: () => saveGameState,
|
|
39
42
|
setLeaderboardVisible: () => setLeaderboardVisible,
|
|
43
|
+
setScore: () => setScore,
|
|
40
44
|
share: () => share,
|
|
41
45
|
shareRoomCode: () => shareRoomCode,
|
|
42
46
|
submitScore: () => submitScore,
|
|
@@ -44,7 +48,7 @@ __export(index_exports, {
|
|
|
44
48
|
});
|
|
45
49
|
module.exports = __toCommonJS(index_exports);
|
|
46
50
|
|
|
47
|
-
// src/
|
|
51
|
+
// src/character.ts
|
|
48
52
|
function isDevelopment() {
|
|
49
53
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
50
54
|
return nodeEnv !== "production";
|
|
@@ -55,13 +59,48 @@ function getBridgeWindow() {
|
|
|
55
59
|
}
|
|
56
60
|
return window;
|
|
57
61
|
}
|
|
58
|
-
function
|
|
62
|
+
function warnMissingBridge(methodName) {
|
|
63
|
+
if (isDevelopment()) {
|
|
64
|
+
console.warn(
|
|
65
|
+
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function getPlayerCharacter() {
|
|
59
70
|
const bridge = getBridgeWindow();
|
|
71
|
+
if (typeof bridge?.__oasizGetPlayerCharacter !== "function") {
|
|
72
|
+
warnMissingBridge("getPlayerCharacter");
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const result = await bridge.__oasizGetPlayerCharacter();
|
|
77
|
+
return result ?? null;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (isDevelopment()) {
|
|
80
|
+
console.error("[oasiz/sdk] getPlayerCharacter failed:", error);
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/haptics.ts
|
|
87
|
+
function isDevelopment2() {
|
|
88
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
89
|
+
return nodeEnv !== "production";
|
|
90
|
+
}
|
|
91
|
+
function getBridgeWindow2() {
|
|
92
|
+
if (typeof window === "undefined") {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
return window;
|
|
96
|
+
}
|
|
97
|
+
function triggerHaptic(type) {
|
|
98
|
+
const bridge = getBridgeWindow2();
|
|
60
99
|
if (typeof bridge?.triggerHaptic === "function") {
|
|
61
100
|
bridge.triggerHaptic(type);
|
|
62
101
|
return;
|
|
63
102
|
}
|
|
64
|
-
if (
|
|
103
|
+
if (isDevelopment2()) {
|
|
65
104
|
console.warn(
|
|
66
105
|
"[oasiz/sdk] triggerHaptic bridge is unavailable. This is expected in local development."
|
|
67
106
|
);
|
|
@@ -960,70 +999,74 @@ function enableLogOverlay(options = {}) {
|
|
|
960
999
|
}
|
|
961
1000
|
|
|
962
1001
|
// src/multiplayer.ts
|
|
963
|
-
function
|
|
1002
|
+
function isDevelopment3() {
|
|
964
1003
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
965
1004
|
return nodeEnv !== "production";
|
|
966
1005
|
}
|
|
967
|
-
function
|
|
1006
|
+
function getBridgeWindow3() {
|
|
968
1007
|
if (typeof window === "undefined") {
|
|
969
1008
|
return void 0;
|
|
970
1009
|
}
|
|
971
1010
|
return window;
|
|
972
1011
|
}
|
|
973
1012
|
function shareRoomCode(roomCode, options) {
|
|
974
|
-
const bridge =
|
|
1013
|
+
const bridge = getBridgeWindow3();
|
|
975
1014
|
if (typeof bridge?.shareRoomCode === "function") {
|
|
976
1015
|
bridge.shareRoomCode(roomCode, options);
|
|
977
1016
|
return;
|
|
978
1017
|
}
|
|
979
|
-
if (
|
|
1018
|
+
if (isDevelopment3()) {
|
|
980
1019
|
console.warn(
|
|
981
1020
|
"[oasiz/sdk] shareRoomCode bridge is unavailable. This is expected in local development."
|
|
982
1021
|
);
|
|
983
1022
|
}
|
|
984
1023
|
}
|
|
985
1024
|
function openInviteModal() {
|
|
986
|
-
const bridge =
|
|
1025
|
+
const bridge = getBridgeWindow3();
|
|
987
1026
|
if (typeof bridge?.openInviteModal === "function") {
|
|
988
1027
|
bridge.openInviteModal();
|
|
989
1028
|
return;
|
|
990
1029
|
}
|
|
991
|
-
if (
|
|
1030
|
+
if (isDevelopment3()) {
|
|
992
1031
|
console.warn(
|
|
993
1032
|
"[oasiz/sdk] openInviteModal bridge is unavailable. This is expected in local development."
|
|
994
1033
|
);
|
|
995
1034
|
}
|
|
996
1035
|
}
|
|
997
1036
|
function getGameId() {
|
|
998
|
-
const bridge =
|
|
1037
|
+
const bridge = getBridgeWindow3();
|
|
999
1038
|
return bridge?.__GAME_ID__;
|
|
1000
1039
|
}
|
|
1001
1040
|
function getRoomCode() {
|
|
1002
|
-
const bridge =
|
|
1041
|
+
const bridge = getBridgeWindow3();
|
|
1003
1042
|
return bridge?.__ROOM_CODE__;
|
|
1004
1043
|
}
|
|
1044
|
+
function getPlayerId() {
|
|
1045
|
+
const bridge = getBridgeWindow3();
|
|
1046
|
+
return bridge?.__PLAYER_ID__;
|
|
1047
|
+
}
|
|
1005
1048
|
function getPlayerName() {
|
|
1006
|
-
const bridge =
|
|
1049
|
+
const bridge = getBridgeWindow3();
|
|
1007
1050
|
return bridge?.__PLAYER_NAME__;
|
|
1008
1051
|
}
|
|
1009
1052
|
function getPlayerAvatar() {
|
|
1010
|
-
const bridge =
|
|
1053
|
+
const bridge = getBridgeWindow3();
|
|
1011
1054
|
return bridge?.__PLAYER_AVATAR__;
|
|
1012
1055
|
}
|
|
1013
1056
|
|
|
1014
1057
|
// src/score.ts
|
|
1015
|
-
function
|
|
1058
|
+
function isDevelopment4() {
|
|
1016
1059
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1017
1060
|
return nodeEnv !== "production";
|
|
1018
1061
|
}
|
|
1019
|
-
function
|
|
1020
|
-
if (
|
|
1062
|
+
function warnMissingBridge2(methodName) {
|
|
1063
|
+
if (isDevelopment4()) {
|
|
1021
1064
|
console.warn(
|
|
1022
1065
|
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
1023
1066
|
);
|
|
1024
1067
|
}
|
|
1025
1068
|
}
|
|
1026
|
-
function
|
|
1069
|
+
function getBridgeWindow4() {
|
|
1027
1070
|
if (typeof window === "undefined") {
|
|
1028
1071
|
return void 0;
|
|
1029
1072
|
}
|
|
@@ -1031,33 +1074,92 @@ function getBridgeWindow3() {
|
|
|
1031
1074
|
}
|
|
1032
1075
|
function submitScore(score) {
|
|
1033
1076
|
if (!Number.isFinite(score)) {
|
|
1034
|
-
if (
|
|
1077
|
+
if (isDevelopment4()) {
|
|
1035
1078
|
console.warn("[oasiz/sdk] submitScore expected a finite number:", score);
|
|
1036
1079
|
}
|
|
1037
1080
|
return;
|
|
1038
1081
|
}
|
|
1039
|
-
const bridge =
|
|
1082
|
+
const bridge = getBridgeWindow4();
|
|
1040
1083
|
const normalizedScore = Math.max(0, Math.floor(score));
|
|
1041
1084
|
if (typeof bridge?.submitScore === "function") {
|
|
1042
1085
|
bridge.submitScore(normalizedScore);
|
|
1043
1086
|
return;
|
|
1044
1087
|
}
|
|
1045
|
-
|
|
1088
|
+
warnMissingBridge2("submitScore");
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/score-edit.ts
|
|
1092
|
+
function isDevelopment5() {
|
|
1093
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1094
|
+
return nodeEnv !== "production";
|
|
1095
|
+
}
|
|
1096
|
+
function getBridgeWindow5() {
|
|
1097
|
+
if (typeof window === "undefined") {
|
|
1098
|
+
return void 0;
|
|
1099
|
+
}
|
|
1100
|
+
return window;
|
|
1101
|
+
}
|
|
1102
|
+
function warnMissingBridge3(methodName) {
|
|
1103
|
+
if (isDevelopment5()) {
|
|
1104
|
+
console.warn(
|
|
1105
|
+
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
async function editScore(payload, methodName) {
|
|
1110
|
+
const bridge = getBridgeWindow5();
|
|
1111
|
+
if (typeof bridge?.__oasizEditScore !== "function") {
|
|
1112
|
+
warnMissingBridge3(methodName);
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
try {
|
|
1116
|
+
const result = await bridge.__oasizEditScore(payload);
|
|
1117
|
+
return result ?? null;
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
if (isDevelopment5()) {
|
|
1120
|
+
console.error("[oasiz/sdk] " + methodName + " failed:", error);
|
|
1121
|
+
}
|
|
1122
|
+
return null;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
async function addScore(delta) {
|
|
1126
|
+
if (!Number.isInteger(delta)) {
|
|
1127
|
+
if (isDevelopment5()) {
|
|
1128
|
+
console.warn("[oasiz/sdk] addScore expected an integer:", delta);
|
|
1129
|
+
}
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
if (delta === 0) {
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
return editScore({ delta }, "addScore");
|
|
1136
|
+
}
|
|
1137
|
+
async function setScore(score) {
|
|
1138
|
+
if (!Number.isInteger(score) || score < 0) {
|
|
1139
|
+
if (isDevelopment5()) {
|
|
1140
|
+
console.warn(
|
|
1141
|
+
"[oasiz/sdk] setScore expected a non-negative integer:",
|
|
1142
|
+
score
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
return null;
|
|
1146
|
+
}
|
|
1147
|
+
return editScore({ score }, "setScore");
|
|
1046
1148
|
}
|
|
1047
1149
|
|
|
1048
1150
|
// src/share.ts
|
|
1049
|
-
function
|
|
1151
|
+
function isDevelopment6() {
|
|
1050
1152
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1051
1153
|
return nodeEnv !== "production";
|
|
1052
1154
|
}
|
|
1053
|
-
function
|
|
1155
|
+
function getBridgeWindow6() {
|
|
1054
1156
|
if (typeof window === "undefined") {
|
|
1055
1157
|
return void 0;
|
|
1056
1158
|
}
|
|
1057
1159
|
return window;
|
|
1058
1160
|
}
|
|
1059
|
-
function
|
|
1060
|
-
if (
|
|
1161
|
+
function warnMissingBridge4(methodName) {
|
|
1162
|
+
if (isDevelopment6()) {
|
|
1061
1163
|
console.warn(
|
|
1062
1164
|
"[oasiz/sdk] " + methodName + " share bridge is unavailable. This is expected in local development."
|
|
1063
1165
|
);
|
|
@@ -1100,20 +1202,20 @@ function validateRequest(options) {
|
|
|
1100
1202
|
}
|
|
1101
1203
|
async function share(options) {
|
|
1102
1204
|
const request = validateRequest(options);
|
|
1103
|
-
const bridge =
|
|
1205
|
+
const bridge = getBridgeWindow6();
|
|
1104
1206
|
if (typeof bridge?.__oasizShareRequest !== "function") {
|
|
1105
|
-
|
|
1207
|
+
warnMissingBridge4("__oasizShareRequest");
|
|
1106
1208
|
throw new Error("Share bridge unavailable");
|
|
1107
1209
|
}
|
|
1108
1210
|
await bridge.__oasizShareRequest(request);
|
|
1109
1211
|
}
|
|
1110
1212
|
|
|
1111
1213
|
// src/state.ts
|
|
1112
|
-
function
|
|
1214
|
+
function isDevelopment7() {
|
|
1113
1215
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1114
1216
|
return nodeEnv !== "production";
|
|
1115
1217
|
}
|
|
1116
|
-
function
|
|
1218
|
+
function getBridgeWindow7() {
|
|
1117
1219
|
if (typeof window === "undefined") {
|
|
1118
1220
|
return void 0;
|
|
1119
1221
|
}
|
|
@@ -1126,22 +1228,22 @@ function isPlainObject(value) {
|
|
|
1126
1228
|
const proto = Object.getPrototypeOf(value);
|
|
1127
1229
|
return proto === Object.prototype || proto === null;
|
|
1128
1230
|
}
|
|
1129
|
-
function
|
|
1130
|
-
if (
|
|
1231
|
+
function warnMissingBridge5(methodName) {
|
|
1232
|
+
if (isDevelopment7()) {
|
|
1131
1233
|
console.warn(
|
|
1132
1234
|
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
1133
1235
|
);
|
|
1134
1236
|
}
|
|
1135
1237
|
}
|
|
1136
1238
|
function loadGameState() {
|
|
1137
|
-
const bridge =
|
|
1239
|
+
const bridge = getBridgeWindow7();
|
|
1138
1240
|
if (typeof bridge?.loadGameState !== "function") {
|
|
1139
|
-
|
|
1241
|
+
warnMissingBridge5("loadGameState");
|
|
1140
1242
|
return {};
|
|
1141
1243
|
}
|
|
1142
1244
|
const state = bridge.loadGameState();
|
|
1143
1245
|
if (!isPlainObject(state)) {
|
|
1144
|
-
if (
|
|
1246
|
+
if (isDevelopment7()) {
|
|
1145
1247
|
console.warn(
|
|
1146
1248
|
"[oasiz/sdk] loadGameState returned invalid data. Falling back to empty object."
|
|
1147
1249
|
);
|
|
@@ -1152,35 +1254,35 @@ function loadGameState() {
|
|
|
1152
1254
|
}
|
|
1153
1255
|
function saveGameState(state) {
|
|
1154
1256
|
if (!isPlainObject(state)) {
|
|
1155
|
-
if (
|
|
1257
|
+
if (isDevelopment7()) {
|
|
1156
1258
|
console.warn("[oasiz/sdk] saveGameState expected a plain object:", state);
|
|
1157
1259
|
}
|
|
1158
1260
|
return;
|
|
1159
1261
|
}
|
|
1160
|
-
const bridge =
|
|
1262
|
+
const bridge = getBridgeWindow7();
|
|
1161
1263
|
if (typeof bridge?.saveGameState === "function") {
|
|
1162
1264
|
bridge.saveGameState(state);
|
|
1163
1265
|
return;
|
|
1164
1266
|
}
|
|
1165
|
-
|
|
1267
|
+
warnMissingBridge5("saveGameState");
|
|
1166
1268
|
}
|
|
1167
1269
|
function flushGameState() {
|
|
1168
|
-
const bridge =
|
|
1270
|
+
const bridge = getBridgeWindow7();
|
|
1169
1271
|
if (typeof bridge?.flushGameState === "function") {
|
|
1170
1272
|
bridge.flushGameState();
|
|
1171
1273
|
return;
|
|
1172
1274
|
}
|
|
1173
|
-
|
|
1275
|
+
warnMissingBridge5("flushGameState");
|
|
1174
1276
|
}
|
|
1175
1277
|
|
|
1176
1278
|
// src/lifecycle.ts
|
|
1177
|
-
function
|
|
1279
|
+
function isDevelopment8() {
|
|
1178
1280
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1179
1281
|
return nodeEnv !== "production";
|
|
1180
1282
|
}
|
|
1181
1283
|
function addLifecycleListener(eventName, callback) {
|
|
1182
1284
|
if (typeof window === "undefined") {
|
|
1183
|
-
if (
|
|
1285
|
+
if (isDevelopment8()) {
|
|
1184
1286
|
console.warn(
|
|
1185
1287
|
"[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
|
|
1186
1288
|
);
|
|
@@ -1200,46 +1302,74 @@ function onResume(callback) {
|
|
|
1200
1302
|
}
|
|
1201
1303
|
|
|
1202
1304
|
// src/layout.ts
|
|
1203
|
-
function
|
|
1305
|
+
function isDevelopment9() {
|
|
1204
1306
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1205
1307
|
return nodeEnv !== "production";
|
|
1206
1308
|
}
|
|
1207
|
-
function
|
|
1309
|
+
function getBridgeWindow8() {
|
|
1208
1310
|
if (typeof window === "undefined") {
|
|
1209
1311
|
return void 0;
|
|
1210
1312
|
}
|
|
1211
1313
|
return window;
|
|
1212
1314
|
}
|
|
1213
|
-
function
|
|
1214
|
-
if (
|
|
1315
|
+
function warnMissingBridge6(methodName) {
|
|
1316
|
+
if (isDevelopment9()) {
|
|
1215
1317
|
console.warn(
|
|
1216
1318
|
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
1217
1319
|
);
|
|
1218
1320
|
}
|
|
1219
1321
|
}
|
|
1220
|
-
function
|
|
1322
|
+
function normalizeSafeAreaTopPixels(value) {
|
|
1221
1323
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1222
1324
|
return 0;
|
|
1223
1325
|
}
|
|
1224
1326
|
return Math.max(0, value);
|
|
1225
1327
|
}
|
|
1328
|
+
function normalizeSafeAreaTopPercent(value) {
|
|
1329
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1330
|
+
return 0;
|
|
1331
|
+
}
|
|
1332
|
+
return Math.min(100, Math.max(0, value));
|
|
1333
|
+
}
|
|
1334
|
+
function viewportInnerHeight(bridge) {
|
|
1335
|
+
const h = bridge.innerHeight;
|
|
1336
|
+
if (typeof h !== "number" || !Number.isFinite(h) || h <= 0) {
|
|
1337
|
+
return 0;
|
|
1338
|
+
}
|
|
1339
|
+
return h;
|
|
1340
|
+
}
|
|
1341
|
+
function pixelsTopToPercentOfViewport(pixels, bridge) {
|
|
1342
|
+
const h = viewportInnerHeight(bridge);
|
|
1343
|
+
if (h <= 0) {
|
|
1344
|
+
return 0;
|
|
1345
|
+
}
|
|
1346
|
+
return normalizeSafeAreaTopPercent(pixels / h * 100);
|
|
1347
|
+
}
|
|
1226
1348
|
function getSafeAreaTop() {
|
|
1227
|
-
const bridge =
|
|
1349
|
+
const bridge = getBridgeWindow8();
|
|
1228
1350
|
if (!bridge) {
|
|
1229
1351
|
return 0;
|
|
1230
1352
|
}
|
|
1353
|
+
if (typeof bridge.getSafeAreaTopPercent === "function") {
|
|
1354
|
+
return normalizeSafeAreaTopPercent(bridge.getSafeAreaTopPercent());
|
|
1355
|
+
}
|
|
1356
|
+
if (typeof bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__ !== "undefined") {
|
|
1357
|
+
return normalizeSafeAreaTopPercent(bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__);
|
|
1358
|
+
}
|
|
1231
1359
|
if (typeof bridge.getSafeAreaTop === "function") {
|
|
1232
|
-
|
|
1360
|
+
const px = normalizeSafeAreaTopPixels(bridge.getSafeAreaTop());
|
|
1361
|
+
return pixelsTopToPercentOfViewport(px, bridge);
|
|
1233
1362
|
}
|
|
1234
1363
|
if (typeof bridge.__OASIZ_SAFE_AREA_TOP__ !== "undefined") {
|
|
1235
|
-
|
|
1364
|
+
const px = normalizeSafeAreaTopPixels(bridge.__OASIZ_SAFE_AREA_TOP__);
|
|
1365
|
+
return pixelsTopToPercentOfViewport(px, bridge);
|
|
1236
1366
|
}
|
|
1237
|
-
|
|
1367
|
+
warnMissingBridge6("getSafeAreaTop");
|
|
1238
1368
|
return 0;
|
|
1239
1369
|
}
|
|
1240
1370
|
function setLeaderboardVisible(visible) {
|
|
1241
1371
|
if (typeof visible !== "boolean") {
|
|
1242
|
-
if (
|
|
1372
|
+
if (isDevelopment9()) {
|
|
1243
1373
|
console.warn(
|
|
1244
1374
|
"[oasiz/sdk] setLeaderboardVisible expected a boolean:",
|
|
1245
1375
|
visible
|
|
@@ -1247,28 +1377,28 @@ function setLeaderboardVisible(visible) {
|
|
|
1247
1377
|
}
|
|
1248
1378
|
return;
|
|
1249
1379
|
}
|
|
1250
|
-
const bridge =
|
|
1380
|
+
const bridge = getBridgeWindow8();
|
|
1251
1381
|
if (typeof bridge?.__oasizSetLeaderboardVisible === "function") {
|
|
1252
1382
|
bridge.__oasizSetLeaderboardVisible(visible);
|
|
1253
1383
|
return;
|
|
1254
1384
|
}
|
|
1255
|
-
|
|
1385
|
+
warnMissingBridge6("__oasizSetLeaderboardVisible");
|
|
1256
1386
|
}
|
|
1257
1387
|
|
|
1258
1388
|
// src/navigation.ts
|
|
1259
1389
|
var activeBackListeners = 0;
|
|
1260
|
-
function
|
|
1390
|
+
function isDevelopment10() {
|
|
1261
1391
|
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1262
1392
|
return nodeEnv !== "production";
|
|
1263
1393
|
}
|
|
1264
|
-
function
|
|
1394
|
+
function getBridgeWindow9() {
|
|
1265
1395
|
if (typeof window === "undefined") {
|
|
1266
1396
|
return void 0;
|
|
1267
1397
|
}
|
|
1268
1398
|
return window;
|
|
1269
1399
|
}
|
|
1270
|
-
function
|
|
1271
|
-
if (
|
|
1400
|
+
function warnMissingBridge7(methodName) {
|
|
1401
|
+
if (isDevelopment10()) {
|
|
1272
1402
|
console.warn(
|
|
1273
1403
|
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
1274
1404
|
);
|
|
@@ -1284,7 +1414,7 @@ function normalizeNavigationError(error) {
|
|
|
1284
1414
|
}
|
|
1285
1415
|
function addNavigationListener(eventName, callback) {
|
|
1286
1416
|
if (typeof window === "undefined") {
|
|
1287
|
-
if (
|
|
1417
|
+
if (isDevelopment10()) {
|
|
1288
1418
|
console.warn(
|
|
1289
1419
|
"[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
|
|
1290
1420
|
);
|
|
@@ -1305,24 +1435,24 @@ function onBackButton(callback) {
|
|
|
1305
1435
|
throw normalizeNavigationError(error);
|
|
1306
1436
|
}
|
|
1307
1437
|
});
|
|
1308
|
-
const bridge =
|
|
1438
|
+
const bridge = getBridgeWindow9();
|
|
1309
1439
|
activeBackListeners += 1;
|
|
1310
1440
|
if (activeBackListeners === 1) {
|
|
1311
1441
|
if (typeof bridge?.__oasizSetBackOverride === "function") {
|
|
1312
1442
|
bridge.__oasizSetBackOverride(true);
|
|
1313
1443
|
} else {
|
|
1314
|
-
|
|
1444
|
+
warnMissingBridge7("__oasizSetBackOverride");
|
|
1315
1445
|
}
|
|
1316
1446
|
}
|
|
1317
1447
|
return () => {
|
|
1318
1448
|
off();
|
|
1319
1449
|
activeBackListeners = Math.max(0, activeBackListeners - 1);
|
|
1320
1450
|
if (activeBackListeners === 0) {
|
|
1321
|
-
const currentBridge =
|
|
1451
|
+
const currentBridge = getBridgeWindow9();
|
|
1322
1452
|
if (typeof currentBridge?.__oasizSetBackOverride === "function") {
|
|
1323
1453
|
currentBridge.__oasizSetBackOverride(false);
|
|
1324
1454
|
} else {
|
|
1325
|
-
|
|
1455
|
+
warnMissingBridge7("__oasizSetBackOverride");
|
|
1326
1456
|
}
|
|
1327
1457
|
}
|
|
1328
1458
|
};
|
|
@@ -1331,17 +1461,20 @@ function onLeaveGame(callback) {
|
|
|
1331
1461
|
return addNavigationListener("oasiz:leave", callback);
|
|
1332
1462
|
}
|
|
1333
1463
|
function leaveGame() {
|
|
1334
|
-
const bridge =
|
|
1464
|
+
const bridge = getBridgeWindow9();
|
|
1335
1465
|
if (typeof bridge?.__oasizLeaveGame === "function") {
|
|
1336
1466
|
bridge.__oasizLeaveGame();
|
|
1337
1467
|
return;
|
|
1338
1468
|
}
|
|
1339
|
-
|
|
1469
|
+
warnMissingBridge7("__oasizLeaveGame");
|
|
1340
1470
|
}
|
|
1341
1471
|
|
|
1342
1472
|
// src/index.ts
|
|
1343
1473
|
var oasiz = {
|
|
1344
1474
|
submitScore,
|
|
1475
|
+
addScore,
|
|
1476
|
+
setScore,
|
|
1477
|
+
getPlayerCharacter,
|
|
1345
1478
|
share,
|
|
1346
1479
|
triggerHaptic,
|
|
1347
1480
|
enableLogOverlay,
|
|
@@ -1363,6 +1496,9 @@ var oasiz = {
|
|
|
1363
1496
|
get roomCode() {
|
|
1364
1497
|
return getRoomCode();
|
|
1365
1498
|
},
|
|
1499
|
+
get playerId() {
|
|
1500
|
+
return getPlayerId();
|
|
1501
|
+
},
|
|
1366
1502
|
get playerName() {
|
|
1367
1503
|
return getPlayerName();
|
|
1368
1504
|
},
|
|
@@ -1375,10 +1511,13 @@ var oasiz = {
|
|
|
1375
1511
|
};
|
|
1376
1512
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1377
1513
|
0 && (module.exports = {
|
|
1514
|
+
addScore,
|
|
1378
1515
|
enableLogOverlay,
|
|
1379
1516
|
flushGameState,
|
|
1380
1517
|
getGameId,
|
|
1381
1518
|
getPlayerAvatar,
|
|
1519
|
+
getPlayerCharacter,
|
|
1520
|
+
getPlayerId,
|
|
1382
1521
|
getPlayerName,
|
|
1383
1522
|
getRoomCode,
|
|
1384
1523
|
getSafeAreaTop,
|
|
@@ -1392,6 +1531,7 @@ var oasiz = {
|
|
|
1392
1531
|
openInviteModal,
|
|
1393
1532
|
saveGameState,
|
|
1394
1533
|
setLeaderboardVisible,
|
|
1534
|
+
setScore,
|
|
1395
1535
|
share,
|
|
1396
1536
|
shareRoomCode,
|
|
1397
1537
|
submitScore,
|