@hezzlgames/sdk 1.1.0
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 +415 -0
- package/bin/hezzl-sdk.mjs +150 -0
- package/demo/centre.html +481 -0
- package/demo/economy.json +8 -0
- package/demo/game.html +380 -0
- package/demo/hezzl.json +18 -0
- package/hezzl-sdk.js +767 -0
- package/index.cjs +7 -0
- package/index.d.ts +180 -0
- package/index.mjs +7 -0
- package/package.json +56 -0
package/index.cjs
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hezzl Games SDK — типы. Полные требования: docs/GAME-REQUIREMENTS.md
|
|
3
|
+
* в репозитории play.hezzl.com; ссылки на разделы ведут туда.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Команды центра, которые игра может обрабатывать (3.1). */
|
|
7
|
+
export type Command =
|
|
8
|
+
| 'mute' | 'haptics' | 'pause' | 'resume' | 'restart'
|
|
9
|
+
| 'setlang' | 'settheme' | 'setaccent';
|
|
10
|
+
|
|
11
|
+
/** Уведомления центра: приходят сами, не в ответ (3.1, 7.8, 7.9). */
|
|
12
|
+
export type Notice =
|
|
13
|
+
| 'signedin' | 'signedout' | 'signincancelled' | 'profile'
|
|
14
|
+
| 'balance' | 'walletclosed';
|
|
15
|
+
|
|
16
|
+
/** Умения центра из ack (3.8). */
|
|
17
|
+
export type CentreAbility =
|
|
18
|
+
| 'share' | 'support' | 'exit' | 'auth' | 'profile' | 'storage' | 'balance';
|
|
19
|
+
|
|
20
|
+
export type Mode = 'unknown' | 'centre' | 'standalone';
|
|
21
|
+
export type GameMode = 'quick' | 'levels' | 'pvp_bot' | 'arena' | 'hotseat';
|
|
22
|
+
export type Orientation = 'portrait' | 'landscape' | 'any';
|
|
23
|
+
export type Lang = 'ru' | 'en' | '';
|
|
24
|
+
export type Theme = 'light' | 'dark' | '';
|
|
25
|
+
|
|
26
|
+
/** Причины отказа. Ветвиться по ним, не по тексту (7.6, 7.9). */
|
|
27
|
+
export type Reason =
|
|
28
|
+
| 'unavailable' | 'quota' | 'invalid' | 'unknown'
|
|
29
|
+
| 'insufficient' | 'cancelled' | 'signin' | 'notfound' | 'disabled';
|
|
30
|
+
|
|
31
|
+
export interface Refusal extends Error {
|
|
32
|
+
reason: Reason;
|
|
33
|
+
/** Сколько на балансе — у денежных отказов. */
|
|
34
|
+
amount?: number;
|
|
35
|
+
/** Сколько не хватило — у insufficient. */
|
|
36
|
+
need?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface Settings {
|
|
40
|
+
lang: Lang;
|
|
41
|
+
theme: Theme;
|
|
42
|
+
/** Шесть шестнадцатеричных знаков без решётки или пустая строка. */
|
|
43
|
+
accent: string;
|
|
44
|
+
muted: boolean;
|
|
45
|
+
haptics: boolean;
|
|
46
|
+
/** Метка партнёра, уже проверенная маской (раздел 2). */
|
|
47
|
+
ref: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Profile {
|
|
51
|
+
userId: string;
|
|
52
|
+
name?: string;
|
|
53
|
+
avatar?: string;
|
|
54
|
+
age?: number;
|
|
55
|
+
gender?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface Currency {
|
|
59
|
+
key?: string;
|
|
60
|
+
title?: string;
|
|
61
|
+
icon?: string;
|
|
62
|
+
/** Последняя известная сумма; null, пока не приходила. */
|
|
63
|
+
amount: number | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface Good {
|
|
67
|
+
id: number | string;
|
|
68
|
+
title: string;
|
|
69
|
+
picture?: string;
|
|
70
|
+
price: number;
|
|
71
|
+
award: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Handlers {
|
|
75
|
+
mute?(muted: boolean, data: Record<string, unknown>): void;
|
|
76
|
+
haptics?(enabled: boolean, data: Record<string, unknown>): void;
|
|
77
|
+
pause?(): void;
|
|
78
|
+
resume?(): void;
|
|
79
|
+
restart?(): void;
|
|
80
|
+
setlang?(lang: 'ru' | 'en', data: Record<string, unknown>): void;
|
|
81
|
+
settheme?(theme: 'light' | 'dark', data: Record<string, unknown>): void;
|
|
82
|
+
setaccent?(hex: string, data: Record<string, unknown>): void;
|
|
83
|
+
signedin?(userId: string, data: Record<string, unknown>): void;
|
|
84
|
+
signedout?(): void;
|
|
85
|
+
signincancelled?(): void;
|
|
86
|
+
profile?(profile: Profile | null, data: Record<string, unknown>): void;
|
|
87
|
+
/** Баланс изменился — по любой причине (7.9). */
|
|
88
|
+
balance?(amount: number | null, data: { amount?: number; currency?: Currency; signedIn?: boolean }): void;
|
|
89
|
+
walletclosed?(amount: number | null, data: { amount?: number; bought?: boolean }): void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface InitOptions {
|
|
93
|
+
/** Ярлык из каталога, как в hezzl.json. */
|
|
94
|
+
id: string;
|
|
95
|
+
version: string;
|
|
96
|
+
modes?: GameMode[];
|
|
97
|
+
orientation?: Orientation;
|
|
98
|
+
on?: Handlers;
|
|
99
|
+
/** Отладочный вывод в консоль. В собранной игре — false (раздел 38). */
|
|
100
|
+
debug?: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface StorageOptions {
|
|
104
|
+
/** Уносить ли на сервер, когда человек войдёт (7.2). */
|
|
105
|
+
sync?: boolean;
|
|
106
|
+
/** Версия формата записи (7.7). */
|
|
107
|
+
schema?: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface HezzlStorage {
|
|
111
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
112
|
+
set(key: string, value: unknown, opts?: StorageOptions): Promise<void>;
|
|
113
|
+
remove(key: string): Promise<void>;
|
|
114
|
+
keys(): Promise<string[]>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface AuthAnswer { signedIn: boolean; code?: string; rid?: string }
|
|
118
|
+
export interface ProfileAnswer { signedIn: boolean; profile?: Profile; rid?: string }
|
|
119
|
+
export interface BalanceAnswer { signedIn: boolean; amount: number; currency?: Currency; rid?: string }
|
|
120
|
+
export interface GoodsAnswer { goods: Good[]; currency?: Currency; rid?: string }
|
|
121
|
+
export interface BuyAnswer {
|
|
122
|
+
ok: true;
|
|
123
|
+
goodId: number | string;
|
|
124
|
+
/** Сколько осталось. */
|
|
125
|
+
amount: number;
|
|
126
|
+
/** Что выдано — из ответа центра, не из своих ожиданий. */
|
|
127
|
+
award: Record<string, unknown>;
|
|
128
|
+
issued?: { id: number; rewardId: number; status: string };
|
|
129
|
+
}
|
|
130
|
+
export interface SpendAnswer { ok: true; amount: number; spent: number }
|
|
131
|
+
export interface WalletAnswer { closed: true; amount: number; bought: boolean }
|
|
132
|
+
|
|
133
|
+
export interface HezzlSDK {
|
|
134
|
+
/** Версия протокола (3.2). */
|
|
135
|
+
readonly sdk: number;
|
|
136
|
+
/** Версия пакета @hezzlgames/sdk. */
|
|
137
|
+
readonly version: string;
|
|
138
|
+
readonly settings: Settings;
|
|
139
|
+
|
|
140
|
+
init(about: InitOptions): HezzlSDK;
|
|
141
|
+
/** Игра приняла ввод. Обязателен: по нему центр гасит заставку (раздел 5). */
|
|
142
|
+
ready(extra?: Record<string, unknown>): HezzlSDK;
|
|
143
|
+
mode(): Mode;
|
|
144
|
+
can(what: CentreAbility): boolean;
|
|
145
|
+
on(name: Command | Notice, fn: (value: unknown, data: Record<string, unknown>) => void): HezzlSDK;
|
|
146
|
+
resolve<T>(name: keyof Settings, saved: T | '' | null | undefined, fallback: T | (() => T)): T;
|
|
147
|
+
|
|
148
|
+
gameStart(about?: Record<string, unknown>): void;
|
|
149
|
+
score(value: number, about?: Record<string, unknown>): void;
|
|
150
|
+
milestone(what: string, value?: unknown): void;
|
|
151
|
+
levelComplete(about?: Record<string, unknown>): void;
|
|
152
|
+
levelFailed(about?: Record<string, unknown>): void;
|
|
153
|
+
gameOver(about?: Record<string, unknown>): void;
|
|
154
|
+
|
|
155
|
+
share(about?: { text?: string; image?: string }): void;
|
|
156
|
+
support(about?: { message?: string; state?: Record<string, unknown> }): void;
|
|
157
|
+
exit(): void;
|
|
158
|
+
signin(): void;
|
|
159
|
+
auth(): Promise<AuthAnswer>;
|
|
160
|
+
profile(need?: Array<keyof Profile>): Promise<ProfileAnswer>;
|
|
161
|
+
error(code: 'asset_load' | 'storage_write' | 'webgl_lost' | 'runtime' | string, message?: string, fatal?: boolean): void;
|
|
162
|
+
|
|
163
|
+
/* валюта центра, 7.9 */
|
|
164
|
+
currency(): Currency | null;
|
|
165
|
+
balance(): Promise<BalanceAnswer>;
|
|
166
|
+
goods(): Promise<GoodsAnswer>;
|
|
167
|
+
buy(goodId: number | string, opts?: { wallet?: boolean }): Promise<BuyAnswer>;
|
|
168
|
+
spend(amount: number, opts?: { item?: string; wallet?: boolean }): Promise<SpendAnswer>;
|
|
169
|
+
wallet(opts?: { need?: number; reason?: string }): Promise<WalletAnswer>;
|
|
170
|
+
|
|
171
|
+
storage: HezzlStorage;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare const Hezzl: HezzlSDK;
|
|
175
|
+
export default Hezzl;
|
|
176
|
+
|
|
177
|
+
declare global {
|
|
178
|
+
interface Window { Hezzl: HezzlSDK }
|
|
179
|
+
var Hezzl: HezzlSDK;
|
|
180
|
+
}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* ESM-вход пакета. Сам SDK — IIFE, который объявляет window.Hezzl:
|
|
2
|
+
импорт ради побочного эффекта, потом отдаём объект. Один исходник
|
|
3
|
+
на все три способа подключения. */
|
|
4
|
+
import './hezzl-sdk.js';
|
|
5
|
+
const Hezzl = globalThis.Hezzl;
|
|
6
|
+
export { Hezzl };
|
|
7
|
+
export default Hezzl;
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hezzlgames/sdk",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Hezzl Games SDK: договор игры с игровым центром play.hezzl.ru — настройки, рукопожатие, хранилище, валюта центра",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"homepage": "https://play.hezzl.ru",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/hezzl/play.hezzl.com.git",
|
|
10
|
+
"directory": "sdk"
|
|
11
|
+
},
|
|
12
|
+
"main": "./index.cjs",
|
|
13
|
+
"module": "./index.mjs",
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"browser": "./hezzl-sdk.js",
|
|
16
|
+
"unpkg": "./hezzl-sdk.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"import": "./index.mjs",
|
|
21
|
+
"require": "./index.cjs",
|
|
22
|
+
"default": "./hezzl-sdk.js"
|
|
23
|
+
},
|
|
24
|
+
"./hezzl-sdk.js": "./hezzl-sdk.js",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"hezzl-sdk": "bin/hezzl-sdk.mjs"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"hezzl-sdk.js",
|
|
32
|
+
"index.mjs",
|
|
33
|
+
"index.cjs",
|
|
34
|
+
"index.d.ts",
|
|
35
|
+
"bin/",
|
|
36
|
+
"demo/",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"sideEffects": true,
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "node test/run.mjs",
|
|
45
|
+
"stand": "node bin/hezzl-sdk.mjs stand",
|
|
46
|
+
"check": "node bin/hezzl-sdk.mjs check demo",
|
|
47
|
+
"prepack": "npm test && npm run check"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"hezzl",
|
|
51
|
+
"games",
|
|
52
|
+
"sdk",
|
|
53
|
+
"postmessage",
|
|
54
|
+
"game-centre"
|
|
55
|
+
]
|
|
56
|
+
}
|