chore: sync latest changes

This commit is contained in:
2026-06-09 17:21:54 +08:00
parent bca137535b
commit 451c6ea025
12 changed files with 503 additions and 28 deletions

View File

@@ -9,6 +9,8 @@ import SaveLoadMenu from '@/components/SaveLoadMenu.vue'
import ChapterSelect from '@/components/ChapterSelect.vue'
import PlaybackBar from '@/components/PlaybackBar.vue'
import LangSwitch from '@/components/LangSwitch.vue'
import AchievementToast from '@/components/AchievementToast.vue'
import AchievementPanel from '@/components/AchievementPanel.vue'
import { useGameEngine } from '@/composables/useGameEngine'
import { useGameStore } from '@/stores/gameStore'
import { useFullscreen } from '@/composables/useFullscreen'
@@ -23,6 +25,7 @@ const loading = ref(true)
const started = ref(false)
const showMenu = ref(false)
const showChapterSelect = ref(false)
const showAchievements = ref(false)
const hasAutoSave = ref(false)
const currentSpeed = ref(1)
const canSkip = ref(false)
@@ -199,6 +202,7 @@ init()
<button class="start-btn" @click="handleStart">{{ t('ui.start') }}</button>
<button v-if="hasAutoSave" class="start-btn resume-btn" @click="handleResume">{{ t('ui.resume') }}</button>
<button v-if="store.chapters.length > 0" class="start-btn chapters-btn" @click="openChapterSelect">{{ t('ui.chapters') }}</button>
<button v-if="store.achievementDefs.length > 0" class="start-btn achievement-btn" @click="showAchievements = true">成就</button>
</div>
<div v-if="store.gameEnded" class="game-end-overlay">
<div class="game-end-text">{{ t('ui.gameEnd') }}</div>
@@ -220,6 +224,17 @@ init()
@select="onStartChapter"
@back="showChapterSelect = false"
/>
<AchievementPanel
v-if="showAchievements"
:definitions="store.achievementDefs"
:unlocked-ids="store.unlockedAchievementIds"
@close="showAchievements = false"
/>
<AchievementToast
:achievement-id="store.toastAchievementId"
:definitions="store.achievementDefs"
@done="store.clearToastAchievement()"
/>
</template>
</div>
</template>
@@ -346,6 +361,11 @@ html, body {
color: #fc8;
}
.achievement-btn {
border-color: rgba(255, 193, 7, 0.3);
color: #ffc107;
}
.game-end-actions {
margin-top: 24px;
display: flex;

View File

@@ -0,0 +1,156 @@
<script setup lang="ts">
import type { AchievementDef } from '@engine/types'
defineProps<{
definitions: AchievementDef[]
unlockedIds: Set<string>
}>()
const emit = defineEmits<{
close: []
}>()
</script>
<template>
<div class="ach-overlay" @click.self="emit('close')" @keydown.escape="emit('close')">
<div class="ach-panel">
<h2 class="ach-title">成就</h2>
<div class="ach-list">
<div
v-for="ach in definitions"
:key="ach.id"
class="ach-card"
:class="{ locked: !unlockedIds.has(ach.id), hidden: ach.hidden && !unlockedIds.has(ach.id) }"
>
<div class="ach-icon">
<img v-if="ach.icon" :src="ach.icon" class="ach-img" />
<span v-else class="ach-star">{{ unlockedIds.has(ach.id) ? '⭐' : '🔒' }}</span>
</div>
<div class="ach-body">
<div class="ach-title-text">
{{ !unlockedIds.has(ach.id) && ach.hidden ? '???' : ach.title }}
</div>
<div class="ach-desc-text">
{{ !unlockedIds.has(ach.id) && ach.hidden ? '' : ach.description }}
</div>
</div>
</div>
</div>
<button class="ach-close" @click="emit('close')">关闭</button>
</div>
</div>
</template>
<style scoped>
.ach-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.88);
display: flex;
align-items: center;
justify-content: center;
z-index: 200;
}
.ach-panel {
background: #1a1a2e;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
padding: 36px 40px;
min-width: 420px;
max-width: 520px;
max-height: 80vh;
display: flex;
flex-direction: column;
}
.ach-title {
text-align: center;
font-size: 22px;
font-weight: 400;
color: #ddd;
letter-spacing: 3px;
margin-bottom: 24px;
}
.ach-list {
display: flex;
flex-direction: column;
gap: 8px;
overflow-y: auto;
padding-right: 8px;
}
.ach-card {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 6px;
}
.ach-card.locked {
opacity: 0.4;
}
.ach-card.hidden {
opacity: 0.2;
}
.ach-icon {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.ach-star {
font-size: 20px;
}
.ach-img {
width: 100%;
height: 100%;
object-fit: contain;
}
.ach-body {
display: flex;
flex-direction: column;
gap: 2px;
}
.ach-title-text {
font-size: 14px;
color: #eee;
}
.ach-desc-text {
font-size: 12px;
color: #888;
}
.ach-close {
margin-top: 20px;
padding: 10px 36px;
font-size: 14px;
color: #888;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 4px;
cursor: pointer;
transition: background 0.15s, color 0.15s;
align-self: center;
}
.ach-close:hover {
background: rgba(255, 255, 255, 0.1);
color: #ccc;
}
</style>

View File

@@ -0,0 +1,108 @@
<script setup lang="ts">
import { computed, watch, ref } from 'vue'
import type { AchievementDef } from '@engine/types'
const props = defineProps<{
achievementId: string
definitions: AchievementDef[]
}>()
const emit = defineEmits<{
done: []
}>()
const visible = ref(false)
const def = computed(() => props.definitions.find((d) => d.id === props.achievementId))
watch(() => props.achievementId, (id) => {
if (!id) return
visible.value = true
setTimeout(() => {
visible.value = false
setTimeout(() => emit('done'), 400)
}, 3000)
}, { immediate: true })
</script>
<template>
<div class="achievement-toast" v-if="visible && def" :class="{ show: visible }">
<div class="toast-icon">
<img v-if="def.icon" :src="def.icon" class="toast-img" />
<span v-else class="toast-star"></span>
</div>
<div class="toast-body">
<div class="toast-label">成就解锁</div>
<div class="toast-title">{{ def.title }}</div>
<div class="toast-desc">{{ def.description }}</div>
</div>
</div>
</template>
<style scoped>
.achievement-toast {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: rgba(20, 20, 40, 0.95);
border: 1px solid rgba(255, 193, 7, 0.4);
border-radius: 8px;
padding: 14px 20px;
display: flex;
align-items: center;
gap: 14px;
z-index: 300;
min-width: 320px;
opacity: 0;
transition: transform 0.4s ease, opacity 0.4s ease;
}
.achievement-toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
.toast-icon {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.toast-star {
font-size: 24px;
}
.toast-img {
width: 100%;
height: 100%;
object-fit: contain;
}
.toast-body {
display: flex;
flex-direction: column;
gap: 2px;
}
.toast-label {
font-size: 11px;
color: #ffc107;
text-transform: uppercase;
letter-spacing: 1px;
}
.toast-title {
font-size: 15px;
color: #fff;
font-weight: 600;
}
.toast-desc {
font-size: 12px;
color: #aaa;
}
</style>

View File

@@ -26,6 +26,11 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
await saveSystem.markWatched(sceneId)
})
engine.achievementSystem.setUnlockCallback(async (ach) => {
await saveSystem.unlockAchievement(ach.id)
store.addUnlockedAchievement(ach.id)
})
engine.on('sceneChange', (scene) => {
store.setScene(scene)
store.clearChoices()
@@ -106,8 +111,14 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
engine.sceneManager.load(data)
engine.stateManager.init(data.variables)
store.setChapters(data.chapters || [])
store.setAchievementDefs(data.achievements || [])
const unlocked = await saveSystem.getUnlockedChapters()
store.setUnlockedChapters(unlocked)
const achieved = await saveSystem.getUnlockedAchievements()
store.setUnlockedAchievementIds(achieved)
engine.achievementSystem.init(data.achievements || [], achieved)
}
function ensureVideo() {

View File

@@ -1,6 +1,6 @@
import { defineStore } from 'pinia'
import { ref, shallowRef } from 'vue'
import type { SceneNode, Choice, QTEDefinition, Hotspot, ChapterInfo } from '@engine/types'
import type { SceneNode, Choice, QTEDefinition, Hotspot, ChapterInfo, AchievementDef } from '@engine/types'
export interface SlotInfo {
slot: number
@@ -29,6 +29,10 @@ export const useGameStore = defineStore('game', () => {
const showChapterSelect = ref(false)
const chapters = ref<ChapterInfo[]>([])
const unlockedChapterIds = ref<Set<string>>(new Set())
const showAchievements = ref(false)
const achievementDefs = ref<AchievementDef[]>([])
const unlockedAchievementIds = ref<Set<string>>(new Set())
const toastAchievementId = ref('')
function setScene(scene: SceneNode) {
currentScene.value = scene
@@ -126,6 +130,28 @@ export const useGameStore = defineStore('game', () => {
showChapterSelect.value = val
}
function setShowAchievements(val: boolean) {
showAchievements.value = val
}
function setAchievementDefs(list: AchievementDef[]) {
achievementDefs.value = list
}
function setUnlockedAchievementIds(ids: string[]) {
unlockedAchievementIds.value = new Set(ids)
}
function addUnlockedAchievement(id: string) {
unlockedAchievementIds.value.add(id)
unlockedAchievementIds.value = new Set(unlockedAchievementIds.value)
toastAchievementId.value = id
}
function clearToastAchievement() {
toastAchievementId.value = ''
}
function dump() {
console.group('GameStore')
console.log('currentScene:', currentScene.value?.id)
@@ -142,13 +168,16 @@ export const useGameStore = defineStore('game', () => {
currentScene, choices, gameEnded, timerTotal, timerRemaining, saves,
qteActive, qteDef, qteTotal, qteRemaining, qteResult, videoTime,
hotspots, isImageScene, showChapterSelect, chapters, unlockedChapterIds,
inputMode,
inputMode, showAchievements, achievementDefs, unlockedAchievementIds,
toastAchievementId,
setScene, setChoices, clearChoices, setGameEnded,
setTimer, clearTimer, setSaves,
showQTE, updateQTE, resolveQTE, clearQTE, setVideoTime,
setHotspots, clearHotspots, setIsImageScene,
setInputMode,
setChapters, setUnlockedChapters, addUnlockedChapter, setShowChapterSelect,
setShowAchievements, setAchievementDefs, setUnlockedAchievementIds,
addUnlockedAchievement, clearToastAchievement,
dump,
}
})