@stringke/game-framework-web
基于 SolidJS(solid-js + solid-js/web)的通用游戏 WebUI 与外壳框架,提供 <PixiStage /> 渲染桥接、统一游戏外壳、DOM 浮层管理与高频 HUD 组件。零具体游戏玩法耦合,采用外链 CSS(styles.css),兼容 kxed static_files.spa 默认严格 CSP(无内联 <style>)。
安装#
配置 GitHub Packages scope(.npmrc):
@stringke:registry=https://npm.pkg.github.com安装依赖:
npm install @stringke/game-framework-web @stringke/game-framework-core solid-js按需引入外链默认样式:
import '@stringke/game-framework-web/styles.css'核心模块#
| 模块 | 主要导出 | 说明 |
|---|---|---|
| 画布桥接 | PixiStage, createPixiStageAdapter, computeStageSize | SolidJS 与 PixiJS/Spine 画布生命周期桥接,自动绑定 ResizeObserver 并在卸载时销毁 GPU 上下文,支持 fullscreen 与 embedded 两种模式 |
| 游戏外壳 | GameShell, detectViewportOrientation, normalizeProgress | 响应 GameConnection 与 PlatformAdapter 信号,提供安全区适配、Loading 进度罩、弱网重连遮罩与横竖屏方向提示 |
| DOM 浮层 | OverlayModal, createOverlayManager | 挂在画布之上的轻量浮层栈,支持规则/历史记录/设置/提示弹窗、Esc 关闭与焦点闭环管理 |
| 校准倒计时 | CountdownBar, computeRemainingMs, formatCountdown | 基于 GameConnection.serverNow() 校准的高频倒计时进度条,零内联 style |
| 虚拟列表 | VirtualList, calculateVirtualWindow | 面向历史记录、榜单与走势列表的轻量虚拟滚动列表,仅渲染可视切片 |
方案 A 示例(SolidJS 主体界面 + 局部舞台)#
import { GameShell, PixiStage, CountdownBar, createOverlayManager, OverlayModal } from '@stringke/game-framework-web'
import '@stringke/game-framework-web/styles.css'
const overlays = createOverlayManager()
export function App(props: { adapter: any; connection: any; platform: any }) {
return (
<GameShell connection={props.connection} platform={props.platform} requiredOrientation="landscape">
<PixiStage mode="embedded" adapter={props.adapter} ariaLabel="主舞台" />
<CountdownBar targetTimeMs={Date.now() + 15000} connection={props.connection} label="剩余时间" />
<OverlayModal manager={overlays} renderContent={(entry) => <div>{entry.title}</div>} />
</GameShell>
)
}开发命令#
npm install
npm run typecheck
npm run test
npm run build