feat: battle system, state manager enhancements, engine and demo updates
This commit is contained in:
147
src/components/BattleHUD.vue
Normal file
147
src/components/BattleHUD.vue
Normal 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>
|
||||
114
src/components/BattleResult.vue
Normal file
114
src/components/BattleResult.vue
Normal 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>
|
||||
Reference in New Issue
Block a user