@maoyugames/phaser-framework 1.0.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/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/BasePlatform-BCOkvvDW.d.ts +47 -0
- package/dist/chunk-H5CUVYCN.js +229 -0
- package/dist/chunk-II3JM4R3.js +9 -0
- package/dist/chunk-PKBMQBKP.js +5 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +1219 -0
- package/dist/index.d.ts +1778 -0
- package/dist/index.js +3790 -0
- package/dist/platform/capacitor.d.ts +34 -0
- package/dist/platform/capacitor.js +145 -0
- package/dist/platform/facebook.d.ts +33 -0
- package/dist/platform/facebook.js +256 -0
- package/dist/platform/tiktok.d.ts +30 -0
- package/dist/platform/tiktok.js +170 -0
- package/dist/platform/web.d.ts +22 -0
- package/dist/platform/web.js +67 -0
- package/dist/platform/wechat.d.ts +37 -0
- package/dist/platform/wechat.js +436 -0
- package/dist/types-DtcRFbM0.d.ts +239 -0
- package/global.d.ts +8 -0
- package/package.json +83 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 框架通用基础类型。底层与业务共用,业务层只读取不修改。
|
|
3
|
+
*/
|
|
4
|
+
/** 可释放资源 */
|
|
5
|
+
interface IDisposable {
|
|
6
|
+
dispose(): void;
|
|
7
|
+
}
|
|
8
|
+
/** 通用事件回调 */
|
|
9
|
+
type Handler<T = void> = (payload: T) => void;
|
|
10
|
+
/** 取消订阅句柄 */
|
|
11
|
+
type Unsubscribe = () => void;
|
|
12
|
+
/** 二维坐标 */
|
|
13
|
+
interface Vec2 {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}
|
|
17
|
+
/** 安全区(刘海屏 / 小游戏胶囊按钮规避用) */
|
|
18
|
+
interface SafeArea {
|
|
19
|
+
top: number;
|
|
20
|
+
bottom: number;
|
|
21
|
+
left: number;
|
|
22
|
+
right: number;
|
|
23
|
+
}
|
|
24
|
+
/** 设备 / 运行环境信息 */
|
|
25
|
+
interface SystemInfo {
|
|
26
|
+
/** 屏幕逻辑宽度(px) */
|
|
27
|
+
screenWidth: number;
|
|
28
|
+
/** 屏幕逻辑高度(px) */
|
|
29
|
+
screenHeight: number;
|
|
30
|
+
/** 设备像素比 */
|
|
31
|
+
pixelRatio: number;
|
|
32
|
+
/** 操作系统:ios / android / windows / mac / devtools / unknown */
|
|
33
|
+
os: string;
|
|
34
|
+
/** 宿主语言,如 zh-CN / en */
|
|
35
|
+
language: string;
|
|
36
|
+
/** 宿主 App 版本(小游戏宿主版本 / 浏览器 UA 摘要) */
|
|
37
|
+
hostVersion?: string;
|
|
38
|
+
}
|
|
39
|
+
/** 通用结果包装,避免到处抛异常 */
|
|
40
|
+
type Result<T> = {
|
|
41
|
+
ok: true;
|
|
42
|
+
value: T;
|
|
43
|
+
} | {
|
|
44
|
+
ok: false;
|
|
45
|
+
error: Error;
|
|
46
|
+
};
|
|
47
|
+
declare function ok<T>(value: T): Result<T>;
|
|
48
|
+
declare function err<T = never>(error: Error | string): Result<T>;
|
|
49
|
+
/** 日志级别 */
|
|
50
|
+
declare enum LogLevel {
|
|
51
|
+
Debug = 0,
|
|
52
|
+
Info = 1,
|
|
53
|
+
Warn = 2,
|
|
54
|
+
Error = 3,
|
|
55
|
+
Silent = 4
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 平台抽象契约。这是整个框架"业务无关、平台可替换"的核心。
|
|
60
|
+
*
|
|
61
|
+
* 设计原则:
|
|
62
|
+
* 1. 业务代码与底层服务一律只依赖这些接口,绝不直接调用 wx / TTMinis / FBInstant 等平台全局对象。
|
|
63
|
+
* 2. 每个平台一个独立实现(src/core/platform/impl/<platform>),并由独立入口
|
|
64
|
+
* (src/platform-entries/main.<platform>.ts)静态导入 —— 保证打包时 tree-shaking,
|
|
65
|
+
* TikTok 包不会混入微信 / Facebook 的 SDK 适配代码。
|
|
66
|
+
* 3. 不支持的能力返回 undefined(可选 capability)或抛出 PlatformUnsupportedError,
|
|
67
|
+
* 由上层服务统一降级处理。
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/** 受支持的平台名 */
|
|
71
|
+
type PlatformName = 'web' | 'tiktok' | 'wechat' | 'facebook' | 'capacitor';
|
|
72
|
+
/** 平台静态信息 */
|
|
73
|
+
interface PlatformInfo {
|
|
74
|
+
/** 平台名 */
|
|
75
|
+
readonly name: PlatformName;
|
|
76
|
+
/** 是否为"小游戏"类宿主(TikTok / 微信 / Facebook Instant) */
|
|
77
|
+
readonly isMiniGame: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 运行环境是否具备完整 DOM/BOM(window/document)。
|
|
80
|
+
* - web / tiktok(HTML 运行时,真 webview)/ capacitor(WebView):true
|
|
81
|
+
* - wechat 小游戏(JSCore/V8,无 DOM):false —— 资源加载等需走适配器
|
|
82
|
+
*/
|
|
83
|
+
readonly hasDOM: boolean;
|
|
84
|
+
/** 安全区 */
|
|
85
|
+
readonly safeArea: SafeArea;
|
|
86
|
+
/** 系统信息 */
|
|
87
|
+
readonly system: SystemInfo;
|
|
88
|
+
}
|
|
89
|
+
/** 启动参数(深链 / 分享回流 / 场景值等) */
|
|
90
|
+
interface LaunchOptions {
|
|
91
|
+
/** 小游戏场景值 / 来源标识 */
|
|
92
|
+
scene?: number | string;
|
|
93
|
+
/** 透传查询参数 */
|
|
94
|
+
query: Record<string, string>;
|
|
95
|
+
/** 平台原始启动对象,逃生舱 */
|
|
96
|
+
raw?: unknown;
|
|
97
|
+
}
|
|
98
|
+
/** 平台不支持该能力时抛出 */
|
|
99
|
+
declare class PlatformUnsupportedError extends Error {
|
|
100
|
+
constructor(platform: PlatformName, capability: string);
|
|
101
|
+
}
|
|
102
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';
|
|
103
|
+
interface HttpRequestOptions {
|
|
104
|
+
url: string;
|
|
105
|
+
method?: HttpMethod;
|
|
106
|
+
headers?: Record<string, string>;
|
|
107
|
+
/** 请求体:对象会按 JSON 序列化;ArrayBuffer 原样发送 */
|
|
108
|
+
body?: unknown;
|
|
109
|
+
/** 期望响应类型 */
|
|
110
|
+
responseType?: 'json' | 'text' | 'arraybuffer';
|
|
111
|
+
/** 超时毫秒 */
|
|
112
|
+
timeout?: number;
|
|
113
|
+
/** 中断信号(web/capacitor 支持;小游戏侧尽力而为) */
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
}
|
|
116
|
+
interface HttpResponse<T = unknown> {
|
|
117
|
+
status: number;
|
|
118
|
+
ok: boolean;
|
|
119
|
+
headers: Record<string, string>;
|
|
120
|
+
data: T;
|
|
121
|
+
}
|
|
122
|
+
interface SocketOptions {
|
|
123
|
+
url: string;
|
|
124
|
+
/** 子协议 */
|
|
125
|
+
protocols?: string[];
|
|
126
|
+
/** 期望接收二进制类型(默认 arraybuffer) */
|
|
127
|
+
binaryType?: 'arraybuffer' | 'blob';
|
|
128
|
+
/** 附加请求头(仅部分平台支持,如微信) */
|
|
129
|
+
headers?: Record<string, string>;
|
|
130
|
+
}
|
|
131
|
+
/** 与具体平台无关的 Socket 抽象(包裹 WebSocket / wx.SocketTask) */
|
|
132
|
+
interface IPlatformSocket {
|
|
133
|
+
readonly readyState: number;
|
|
134
|
+
send(data: string | ArrayBuffer): void;
|
|
135
|
+
close(code?: number, reason?: string): void;
|
|
136
|
+
onOpen(cb: () => void): Unsubscribe;
|
|
137
|
+
onMessage(cb: (data: string | ArrayBuffer) => void): Unsubscribe;
|
|
138
|
+
onError(cb: (err: Error) => void): Unsubscribe;
|
|
139
|
+
onClose(cb: (info: {
|
|
140
|
+
code: number;
|
|
141
|
+
reason: string;
|
|
142
|
+
}) => void): Unsubscribe;
|
|
143
|
+
}
|
|
144
|
+
interface IPlatformNet {
|
|
145
|
+
/** HTTP 请求底层实现(fetch / wx.request) */
|
|
146
|
+
request(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
147
|
+
/** 建立 Socket(WebSocket / wx.connectSocket),供 WebSocket / KCP 协议层使用 */
|
|
148
|
+
createSocket(options: SocketOptions): IPlatformSocket;
|
|
149
|
+
}
|
|
150
|
+
/** 本地存储(localStorage / wx.setStorageSync / Capacitor Preferences) */
|
|
151
|
+
interface IPlatformStorage {
|
|
152
|
+
getItem(key: string): string | null;
|
|
153
|
+
setItem(key: string, value: string): void;
|
|
154
|
+
removeItem(key: string): void;
|
|
155
|
+
clear(): void;
|
|
156
|
+
}
|
|
157
|
+
/** 登录态 */
|
|
158
|
+
interface LoginResult {
|
|
159
|
+
/** 平台下发的临时凭证(微信 code / TikTok auth code / FB signature 等) */
|
|
160
|
+
code: string;
|
|
161
|
+
/** 平台用户唯一标识(若可直接获取) */
|
|
162
|
+
openId?: string;
|
|
163
|
+
raw?: unknown;
|
|
164
|
+
}
|
|
165
|
+
interface IPlatformAuth {
|
|
166
|
+
login(): Promise<LoginResult>;
|
|
167
|
+
/** 获取用户公开信息(昵称头像),需平台授权 */
|
|
168
|
+
getProfile(): Promise<{
|
|
169
|
+
nickname: string;
|
|
170
|
+
avatarUrl: string;
|
|
171
|
+
} | null>;
|
|
172
|
+
}
|
|
173
|
+
/** 广告 */
|
|
174
|
+
type AdResult = 'completed' | 'skipped' | 'failed' | 'closed';
|
|
175
|
+
interface IPlatformAds {
|
|
176
|
+
/** 预加载激励视频 */
|
|
177
|
+
preloadRewarded(adUnitId?: string): Promise<void>;
|
|
178
|
+
/** 展示激励视频,返回是否看完 */
|
|
179
|
+
showRewarded(adUnitId?: string): Promise<AdResult>;
|
|
180
|
+
/** 展示插屏 */
|
|
181
|
+
showInterstitial(adUnitId?: string): Promise<AdResult>;
|
|
182
|
+
}
|
|
183
|
+
/** 内购 */
|
|
184
|
+
interface PurchaseResult {
|
|
185
|
+
productId: string;
|
|
186
|
+
transactionId: string;
|
|
187
|
+
/** 平台回执,交由业务后端校验 */
|
|
188
|
+
receipt: string;
|
|
189
|
+
raw?: unknown;
|
|
190
|
+
}
|
|
191
|
+
interface IPlatformPayment {
|
|
192
|
+
/** 拉起内购 */
|
|
193
|
+
purchase(productId: string, extra?: Record<string, unknown>): Promise<PurchaseResult>;
|
|
194
|
+
/** 查询历史未发货订单(掉单恢复) */
|
|
195
|
+
restore?(): Promise<PurchaseResult[]>;
|
|
196
|
+
}
|
|
197
|
+
/** 设备能力(震动 / 剪贴板 / 分享等;注意 TikTok 禁用部分 Web API,须走桥接) */
|
|
198
|
+
interface IPlatformDevice {
|
|
199
|
+
vibrateShort?(): void;
|
|
200
|
+
vibrateLong?(): void;
|
|
201
|
+
setClipboard?(text: string): Promise<void>;
|
|
202
|
+
getClipboard?(): Promise<string>;
|
|
203
|
+
/** 触发平台分享 */
|
|
204
|
+
share?(payload: {
|
|
205
|
+
title?: string;
|
|
206
|
+
imageUrl?: string;
|
|
207
|
+
query?: string;
|
|
208
|
+
}): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
/** 平台原生埋点(可选;通常业务用 AnalyticsManager 统一上报) */
|
|
211
|
+
interface IPlatformAnalytics {
|
|
212
|
+
reportEvent(name: string, params?: Record<string, unknown>): void;
|
|
213
|
+
}
|
|
214
|
+
/** 生命周期 */
|
|
215
|
+
interface IPlatformLifecycle {
|
|
216
|
+
onShow(cb: Handler<LaunchOptions>): Unsubscribe;
|
|
217
|
+
onHide(cb: Handler<void>): Unsubscribe;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* 平台总接口。每个平台一个实现类。
|
|
221
|
+
* 可选 capability 为 undefined 表示该平台不提供,服务层自行降级。
|
|
222
|
+
*/
|
|
223
|
+
interface IPlatform {
|
|
224
|
+
readonly info: PlatformInfo;
|
|
225
|
+
/** 平台初始化(读取系统信息、注入 SDK、初始化适配器) */
|
|
226
|
+
init(): Promise<void>;
|
|
227
|
+
/** 获取启动参数 */
|
|
228
|
+
getLaunchOptions(): LaunchOptions;
|
|
229
|
+
readonly net: IPlatformNet;
|
|
230
|
+
readonly storage: IPlatformStorage;
|
|
231
|
+
readonly lifecycle: IPlatformLifecycle;
|
|
232
|
+
readonly auth?: IPlatformAuth;
|
|
233
|
+
readonly ads?: IPlatformAds;
|
|
234
|
+
readonly payment?: IPlatformPayment;
|
|
235
|
+
readonly device?: IPlatformDevice;
|
|
236
|
+
readonly analytics?: IPlatformAnalytics;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export { type AdResult as A, type Handler as H, type IDisposable as I, type LaunchOptions as L, type PlatformInfo as P, type Result as R, type SafeArea as S, type Unsubscribe as U, type Vec2 as V, type HttpMethod as a, type HttpRequestOptions as b, type HttpResponse as c, type IPlatform as d, type IPlatformAds as e, type IPlatformAnalytics as f, type IPlatformAuth as g, type IPlatformDevice as h, type IPlatformLifecycle as i, type IPlatformNet as j, type IPlatformPayment as k, type IPlatformSocket as l, type IPlatformStorage as m, LogLevel as n, type LoginResult as o, type PlatformName as p, PlatformUnsupportedError as q, type PurchaseResult as r, type SocketOptions as s, type SystemInfo as t, err as u, ok as v };
|
package/global.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构建期注入的全局常量(由 Vite define 提供)。
|
|
3
|
+
* 业务/底层可据此做平台分支,但平台相关实现应优先走平台抽象层而非裸判断。
|
|
4
|
+
*/
|
|
5
|
+
declare const __PLATFORM__: 'web' | 'tiktok' | 'wechat' | 'facebook' | 'capacitor';
|
|
6
|
+
declare const __DEV__: boolean;
|
|
7
|
+
/** 框架版本,构建期注入 */
|
|
8
|
+
declare const __FRAMEWORK_VERSION__: string;
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maoyugames/phaser-framework",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "多平台 Phaser 游戏框架:业务/底层分离,HTTP/WebSocket/KCP,Web/TikTok/微信/Facebook/App 隔离打包",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"bin": {
|
|
12
|
+
"pf": "dist/cli/index.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./platform/web": {
|
|
20
|
+
"types": "./dist/platform/web.d.ts",
|
|
21
|
+
"import": "./dist/platform/web.js"
|
|
22
|
+
},
|
|
23
|
+
"./platform/tiktok": {
|
|
24
|
+
"types": "./dist/platform/tiktok.d.ts",
|
|
25
|
+
"import": "./dist/platform/tiktok.js"
|
|
26
|
+
},
|
|
27
|
+
"./platform/wechat": {
|
|
28
|
+
"types": "./dist/platform/wechat.d.ts",
|
|
29
|
+
"import": "./dist/platform/wechat.js"
|
|
30
|
+
},
|
|
31
|
+
"./platform/facebook": {
|
|
32
|
+
"types": "./dist/platform/facebook.d.ts",
|
|
33
|
+
"import": "./dist/platform/facebook.js"
|
|
34
|
+
},
|
|
35
|
+
"./platform/capacitor": {
|
|
36
|
+
"types": "./dist/platform/capacitor.d.ts",
|
|
37
|
+
"import": "./dist/platform/capacitor.js"
|
|
38
|
+
},
|
|
39
|
+
"./cli": "./dist/cli/index.js",
|
|
40
|
+
"./global": {
|
|
41
|
+
"types": "./global.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"global.d.ts",
|
|
49
|
+
"README.md",
|
|
50
|
+
"LICENSE"
|
|
51
|
+
],
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"phaser": "^3.60.0 || ^3.80.0 || ^3.90.0",
|
|
54
|
+
"vite": "^5.0.0",
|
|
55
|
+
"typescript": "^5.0.0",
|
|
56
|
+
"terser": "^5.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"terser": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"picocolors": "^1.0.0",
|
|
65
|
+
"fs-extra": "^11.2.0"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"tsup": "^8.0.0",
|
|
69
|
+
"typescript": "^5.4.5",
|
|
70
|
+
"@types/node": "^20.12.7",
|
|
71
|
+
"@types/fs-extra": "^11.0.4",
|
|
72
|
+
"phaser": "^3.90.0",
|
|
73
|
+
"vite": "^5.2.11"
|
|
74
|
+
},
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsup",
|
|
80
|
+
"typecheck": "tsc --noEmit",
|
|
81
|
+
"prepublishOnly": "npm run build"
|
|
82
|
+
}
|
|
83
|
+
}
|