feat: battle system, state manager enhancements, engine and demo updates

This commit is contained in:
2026-06-14 15:35:31 +08:00
parent 4d066b53bf
commit d0e901bd1f
12 changed files with 515 additions and 6 deletions

View File

@@ -13,6 +13,8 @@ import AchievementToast from '@/components/AchievementToast.vue'
import AchievementPanel from '@/components/AchievementPanel.vue'
import AccessibilitySettings from '@/components/AccessibilitySettings.vue'
import StoryGallery from '@/components/StoryGallery.vue'
import BattleHUD from '@/components/BattleHUD.vue'
import BattleResult from '@/components/BattleResult.vue'
import { useGameEngine } from '@/composables/useGameEngine'
import { useGameStore } from '@/stores/gameStore'
import { useFullscreen } from '@/composables/useFullscreen'
@@ -346,6 +348,10 @@ init()
<Transition name="prompt-toast">
<div v-if="showPromptToast" class="prompt-toast">{{ promptToast }}</div>
</Transition>
<BattleHUD
v-if="store.currentScene?.battleHUD"
:entries="store.currentScene!.battleHUD"
/>
<div v-if="started && !store.gameEnded && store.choices.length === 0" class="top-bar" :class="{ hidden: !showTopBar }">
<button class="top-btn" @click="toggleFullscreen" :title="t('ui.fullscreen')"></button>
<button class="top-btn" @click="showPauseMenu = true" :title="t('ui.menu')"></button>
@@ -361,6 +367,11 @@ init()
@skip="handleSkip"
@speed-change="handleSpeedChange"
/>
<BattleResult
v-if="store.showBattleResult"
:result="store.battleResultData"
@continue="store.setShowBattleResult(false)"
/>
<MainMenu
v-if="!started || store.gameEnded"
:show-resume="!store.gameEnded && hasAutoSave"

View File

@@ -0,0 +1,147 @@
<script setup lang="ts">
import { computed } from 'vue'
import type { BattleHUDEntry } from '@engine/types'
import { useGameStore } from '@/stores/gameStore'
import { useI18n } from '@/composables/useI18n'
const props = defineProps<{
entries: BattleHUDEntry[]
}>()
const store = useGameStore()
const { t } = useI18n()
function statValue(variable: string): number {
return store.variable(variable)
}
function barPercent(value: number, max: number): number {
if (!max || max <= 0) return 0
return Math.min(100, Math.max(0, (value / max) * 100))
}
function barClass(percent: number): string {
if (percent <= 25) return 'danger'
if (percent <= 50) return 'warning'
return ''
}
function statStyle(stat: { variable: string; max?: number; style?: string }): 'bar' | 'number' {
if (stat.style === 'bar' || stat.style === 'number') return stat.style
return stat.max !== undefined ? 'bar' : 'number'
}
</script>
<template>
<div class="battle-hud" v-if="entries.length > 0">
<div class="hud-entry" v-for="entry in entries" :key="entry.label">
<img v-if="entry.portrait" :src="entry.portrait" class="hud-portrait" />
<div class="hud-stats">
<div class="hud-name">{{ t(entry.labelKey || entry.label) }}</div>
<div class="hud-stat" v-for="s in entry.stats" :key="s.variable">
<span class="stat-label">{{ t(s.labelKey || s.label) }}</span>
<template v-if="statStyle(s) === 'number'">
<span class="stat-value">{{ statValue(s.variable) }}</span>
</template>
<template v-else>
<div class="stat-bar-bg">
<div
class="stat-bar-fill"
:class="barClass(barPercent(statValue(s.variable), s.max || 1))"
:style="{ width: barPercent(statValue(s.variable), s.max || 1) + '%' }"
></div>
</div>
<span class="stat-value">{{ statValue(s.variable) }}/{{ s.max }}</span>
</template>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.battle-hud {
position: absolute;
top: 20px;
left: 20px;
z-index: 25;
display: flex;
flex-direction: column;
gap: 12px;
}
.hud-entry {
display: flex;
align-items: center;
gap: 10px;
background: rgba(0, 0, 0, 0.65);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
padding: 10px 14px;
min-width: 180px;
}
.hud-portrait {
width: 48px;
height: 48px;
border-radius: 4px;
object-fit: cover;
border: 1px solid rgba(255, 255, 255, 0.15);
}
.hud-stats {
display: flex;
flex-direction: column;
gap: 4px;
flex: 1;
}
.hud-name {
font-size: 13px;
color: #ddd;
margin-bottom: 2px;
}
.hud-stat {
display: flex;
align-items: center;
gap: 6px;
}
.stat-label {
font-size: 11px;
color: #999;
min-width: 28px;
}
.stat-bar-bg {
flex: 1;
height: 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
overflow: hidden;
}
.stat-bar-fill {
height: 100%;
background: #4caf50;
border-radius: 4px;
transition: width 0.3s ease;
}
.stat-bar-fill.warning {
background: #ff9800;
}
.stat-bar-fill.danger {
background: #e74c3c;
}
.stat-value {
font-size: 11px;
color: #ddd;
white-space: nowrap;
min-width: 50px;
text-align: right;
}
</style>

View File

@@ -0,0 +1,114 @@
<script setup lang="ts">
import type { BattleResultDef } from '@engine/types'
import { useGameStore } from '@/stores/gameStore'
import { useI18n } from '@/composables/useI18n'
defineProps<{
result: BattleResultDef
}>()
const emit = defineEmits<{
continue: []
}>()
const store = useGameStore()
const { t } = useI18n()
function statValue(variable: string): number {
return store.variable(variable)
}
</script>
<template>
<div class="battle-result-overlay" @click.self="emit('continue')" @keydown.escape="emit('continue')">
<div class="battle-result-panel">
<h2 class="result-title">{{ t(result.titleKey || result.title) }}</h2>
<div class="result-stats">
<div class="result-stat" v-for="s in result.stats" :key="s.variable">
<span class="rstat-label">{{ t(s.labelKey || s.label) }}</span>
<span class="rstat-value">
{{ statValue(s.variable) }}
<span v-if="s.max !== undefined"> / {{ s.max }}</span>
</span>
</div>
</div>
<button class="result-continue" @click="emit('continue')">{{ t('ui.continue') }}</button>
</div>
</div>
</template>
<style scoped>
.battle-result-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.85);
display: flex;
align-items: center;
justify-content: center;
z-index: 200;
}
.battle-result-panel {
background: #1a1a2e;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
padding: 36px 40px;
min-width: 340px;
max-width: 440px;
display: flex;
flex-direction: column;
align-items: center;
}
.result-title {
font-size: 24px;
font-weight: 400;
color: #ffc107;
letter-spacing: 4px;
margin-bottom: 28px;
}
.result-stats {
display: flex;
flex-direction: column;
gap: 10px;
width: 100%;
}
.result-stat {
display: flex;
justify-content: space-between;
padding: 10px 16px;
background: rgba(255, 255, 255, 0.04);
border-radius: 4px;
}
.rstat-label {
font-size: 14px;
color: #aaa;
}
.rstat-value {
font-size: 14px;
color: #eee;
}
.result-continue {
margin-top: 24px;
padding: 12px 48px;
font-size: 16px;
color: #fff;
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 4px;
cursor: pointer;
letter-spacing: 2px;
transition: background 0.15s;
}
.result-continue:hover {
background: rgba(255, 255, 255, 0.15);
}
</style>

View File

@@ -12,6 +12,10 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
const { t } = useI18n()
let lastThumbnail: string | undefined
engine.stateManager.onAfterApply.add((vars) => {
store.syncVariables(vars)
})
if (import.meta.env.DEV) {
;(window as any).__sm = engine.stateManager
;(window as any).__store = store
@@ -42,6 +46,10 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
store.clearTimer()
store.clearHotspots()
store.setIsImageScene(scene.type === 'image')
if (scene.battleResult) {
store.setBattleResult(scene.battleResult)
}
store.syncVariables(engine.stateManager.variables)
saveGame(0)
})

View File

@@ -41,6 +41,8 @@
"qualityAuto": "Auto",
"quality1080p": "1080p 2.5Mbps",
"quality720p": "720p 2Mbps",
"quality480p": "480p 0.8Mbps"
"quality480p": "480p 0.8Mbps",
"continue": "Continue",
"toMenu": "Back to Menu"
}
}

View File

@@ -41,6 +41,8 @@
"qualityAuto": "自动",
"quality1080p": "超清 320KB/s",
"quality720p": "高清 256KB/s",
"quality480p": "标清 100KB/s"
"quality480p": "标清 100KB/s",
"continue": "继续",
"toMenu": "返回菜单"
}
}

View File

@@ -45,6 +45,9 @@ export const useGameStore = defineStore('game', () => {
const antiMistap = ref(localStorage.getItem('antiMistap') !== 'false')
const pauseEnabled = ref(localStorage.getItem('pauseEnabled') !== 'false')
const showSettings = ref(false)
const showBattleResult = ref(false)
const battleResultData = ref<any>(null)
const variables = ref<Record<string, number>>({})
const preferredQuality = ref(localStorage.getItem('preferredQuality') || '')
const introVideo = ref('')
const menuVideo = ref('')
@@ -200,6 +203,21 @@ export const useGameStore = defineStore('game', () => {
function setPauseEnabled(v: boolean) { pauseEnabled.value = v; localStorage.setItem('pauseEnabled', String(v)) }
function setShowSettings(v: boolean) { showSettings.value = v }
function variable(name: string): number {
return variables.value[name] ?? 0
}
function syncVariables(vars: Record<string, number>) {
variables.value = { ...vars }
}
function setBattleResult(data: any) {
battleResultData.value = data
showBattleResult.value = true
}
function setShowBattleResult(v: boolean) { showBattleResult.value = v }
function setPreferredQuality(q: string) { preferredQuality.value = q; localStorage.setItem('preferredQuality', q) }
function setIntroVideo(url: string) { introVideo.value = url }
@@ -226,6 +244,7 @@ export const useGameStore = defineStore('game', () => {
storyLocales,
subFontSize, subBgAlpha, qteTimeRelax, qteSingleKey, antiMistap, pauseEnabled,
showSettings, introVideo, menuVideo,
showBattleResult, battleResultData, variables,
preferredQuality,
setScene, setChoices, clearChoices, setGameEnded,
setTimer, clearTimer, setSaves,
@@ -239,6 +258,7 @@ export const useGameStore = defineStore('game', () => {
setStoryLocales,
setSubFontSize, setSubBgAlpha, setQteTimeRelax, setQteSingleKey, setAntiMistap, setPauseEnabled,
setShowSettings, setIntroVideo, setMenuVideo,
variable, setBattleResult, setShowBattleResult, syncVariables,
setPreferredQuality,
dump,
}