diff --git a/dashboards/gear_indicator/manifest.json b/dashboards/gear_indicator/manifest.json index 136b80b..6b2dbd4 100644 --- a/dashboards/gear_indicator/manifest.json +++ b/dashboards/gear_indicator/manifest.json @@ -5,6 +5,7 @@ "description": "醒目大圆档位显示,适合竖屏手机副屏", "author": "Yei.J. (AskaEth)", "version": "1.0.0", + "supported_games": "all", "config": { "icon": "⚙️", "aspect_ratio": "1:1", diff --git a/dashboards/lap_timer/manifest.json b/dashboards/lap_timer/manifest.json index 60feaea..ccba71b 100644 --- a/dashboards/lap_timer/manifest.json +++ b/dashboards/lap_timer/manifest.json @@ -2,9 +2,10 @@ "id": "lap_timer", "name": "圈速计时器", "category": "timing", - "description": "当前圈速、最佳圈和上圈时间对比显示", + "description": "当前圈速、最佳圈和上圈时间对比显示。仅支持 Forza 系列和 F1", "author": "Yei.J. (AskaEth)", "version": "1.0.0", + "supported_games": "forza_horizon_5,forza_horizon_4,forza_motorsport,f1_24", "config": { "icon": "⏱️", "aspect_ratio": "4:3", diff --git a/dashboards/speedometer/manifest.json b/dashboards/speedometer/manifest.json index 069450b..9c04cc7 100644 --- a/dashboards/speedometer/manifest.json +++ b/dashboards/speedometer/manifest.json @@ -5,10 +5,10 @@ "description": "大字号实时速度显示,支持km/h和mph,适合横屏全屏显示", "author": "Yei.J. (AskaEth)", "version": "1.0.0", + "supported_games": "all", "config": { "icon": "🏎️", "unit": "kmh", - "show_unit": true, "aspect_ratio": "auto", "render_mode": "contain" } diff --git a/dashboards/tachometer/manifest.json b/dashboards/tachometer/manifest.json index 68c5260..e019b99 100644 --- a/dashboards/tachometer/manifest.json +++ b/dashboards/tachometer/manifest.json @@ -5,6 +5,7 @@ "description": "赛车风格弧形转速表,支持红区换档提示,推荐横屏", "author": "Yei.J. (AskaEth)", "version": "1.0.0", + "supported_games": "all", "config": { "icon": "⏱️", "max_rpm": 8000, diff --git a/docs/DASHBOARD_DEV.md b/docs/DASHBOARD_DEV.md index 7e936ab..319b03c 100644 --- a/docs/DASHBOARD_DEV.md +++ b/docs/DASHBOARD_DEV.md @@ -21,6 +21,7 @@ dashboards/my_dashboard/ "description": "简短描述", "author": "你的名字", "version": "1.0.0", + "supported_games": "all", "config": { "icon": "🏎️", "aspect_ratio": "16:9", @@ -37,6 +38,7 @@ dashboards/my_dashboard/ | `description` | string | 否 | 描述文字 | | `author` | string | 否 | 作者 | | `version` | string | 否 | 版本号 | +| `supported_games` | string | 否 | 支持的游戏: `"all"` 或 ID 逗号分隔 (如 `"forza_horizon_5,f1_24"`) | | `config.icon` | string | 否 | 预览图标 emoji | | `config.aspect_ratio` | string | 否 | 渲染比例: `auto` / `16:9` / `4:3` / `1:1` / `21:9` | | `config.render_mode` | string | 否 | 渲染模式: `contain` / `cover` / `fill` / `center` | diff --git a/models/dashboard.py b/models/dashboard.py index 6a633b2..1e1f276 100644 --- a/models/dashboard.py +++ b/models/dashboard.py @@ -30,6 +30,7 @@ class DashboardTheme: icon: str = "📊" aspect_ratio: str = "auto" render_mode: str = "contain" + supported_games: str = "all" created_at: str = "" updated_at: str = "" is_builtin: bool = False @@ -46,6 +47,7 @@ class DashboardTheme: "icon": self.icon, "aspect_ratio": self.aspect_ratio, "render_mode": self.render_mode, + "supported_games": self.supported_games, "created_at": self.created_at, "updated_at": self.updated_at, "is_builtin": self.is_builtin, @@ -67,6 +69,7 @@ class DashboardTheme: icon=config.get("icon", "📊"), aspect_ratio=config.get("aspect_ratio", "auto"), render_mode=config.get("render_mode", "contain"), + supported_games=data.get("supported_games", "all"), created_at=data.get("created_at", ""), updated_at=data.get("updated_at", ""), is_builtin=is_builtin, @@ -137,6 +140,7 @@ class DashboardManager: "description": theme.description, "author": theme.author, "version": theme.version, + "supported_games": theme.supported_games, "config": { "icon": theme.icon, "aspect_ratio": theme.aspect_ratio, diff --git a/static/js/pages/dashboard.js b/static/js/pages/dashboard.js index 347bf6b..486a1e0 100644 --- a/static/js/pages/dashboard.js +++ b/static/js/pages/dashboard.js @@ -1,12 +1,15 @@ const PageDashboard = { _el: null, _currentCategory: 'all', + _selectedGameId: null, init() { this._el = document.getElementById('page-dashboard'); }, async render() { + const cfg = await API.getConfig(); + this._selectedGameId = cfg.selected_game_id; this._el.innerHTML = this._template(); await this._loadCategories(); await this._loadThemes(); @@ -44,14 +47,18 @@ const PageDashboard = { gridEl.innerHTML = '
加载中...
'; try { - const themes = await API.getDashboards(this._currentCategory); + let themes = await API.getDashboards(this._currentCategory); if (!themes || themes.length === 0) { - gridEl.innerHTML = ` -
- -

暂无仪表盘主题

-

创建或导入你的第一个仪表盘主题

-
`; + gridEl.innerHTML = this._emptyHtml(); + return; + } + + if (this._selectedGameId) { + themes = themes.filter(t => this._isGameSupported(t)); + } + + if (themes.length === 0) { + gridEl.innerHTML = this._emptyHtml('当前游戏没有兼容的仪表盘'); return; } @@ -62,6 +69,22 @@ const PageDashboard = { } }, + _isGameSupported(theme) { + const supported = theme.supported_games || 'all'; + if (supported === 'all') return true; + const ids = supported.split(',').map(s => s.trim()); + return ids.includes(this._selectedGameId); + }, + + _emptyHtml(msg) { + return ` +
+ +

${msg || '暂无仪表盘主题'}

+

创建或导入你的仪表盘主题

+
`; + }, + _bindEvents() { const categoryList = document.getElementById('dash-category-list'); if (categoryList) { @@ -133,6 +156,10 @@ const PageDashboard = { _themeCardHtml(theme) { const icon = theme.icon || '📊'; const aspect = theme.aspect_ratio || 'auto'; + const supported = theme.supported_games || 'all'; + const isAll = supported === 'all'; + const compatLabel = isAll ? '全' : '限'; + const compatClass = isAll ? 'badge-info' : 'badge-warning'; return `
${icon}
@@ -144,7 +171,7 @@ const PageDashboard = {
${theme.author || ''} - ${theme.is_builtin ? '内置' : '自定义'} + ${compatLabel}
`;