refactor: switch to key-based i18n for choices, revert inline textEn approach

This commit is contained in:
2026-06-09 15:54:55 +08:00
parent 8e7f77bc38
commit f044ed0b60
3 changed files with 3 additions and 25 deletions

View File

@@ -24,7 +24,6 @@ export interface SceneNode {
export interface Choice { export interface Choice {
text: string text: string
textKey?: string textKey?: string
textEn?: string
targetScene: string targetScene: string
conditions?: Condition[] conditions?: Condition[]
effects?: Effect[] effects?: Effect[]

View File

@@ -44,7 +44,6 @@
"choices": [ "choices": [
{ {
"text": "走向左边那扇发光的门", "text": "走向左边那扇发光的门",
"textEn": "Walk towards the glowing door on the left",
"textKey": "scene.intro.choice.left_door", "textKey": "scene.intro.choice.left_door",
"targetScene": "left_door", "targetScene": "left_door",
"effects": [ "effects": [
@@ -53,7 +52,6 @@
}, },
{ {
"text": "走向右边那扇普通的门", "text": "走向右边那扇普通的门",
"textEn": "Walk towards the plain door on the right",
"textKey": "scene.intro.choice.right_door", "textKey": "scene.intro.choice.right_door",
"targetScene": "right_door", "targetScene": "right_door",
"effects": [ "effects": [
@@ -62,13 +60,11 @@
}, },
{ {
"text": "仔细搜索房间", "text": "仔细搜索房间",
"textEn": "Search the room carefully",
"textKey": "scene.intro.choice.search", "textKey": "scene.intro.choice.search",
"targetScene": "investigation_site" "targetScene": "investigation_site"
}, },
{ {
"text": "留在原地,什么也不做", "text": "留在原地,什么也不做",
"textEn": "Stay where you are, do nothing",
"textKey": "scene.intro.choice.stay", "textKey": "scene.intro.choice.stay",
"targetScene": "stay" "targetScene": "stay"
} }
@@ -111,7 +107,6 @@
} }
], ],
"choices": [ "choices": [
{ "text": "离开房间", "textEn": "Leave the room", "targetScene": "corridor" }
] ]
}, },
"corridor": { "corridor": {
@@ -151,7 +146,6 @@
"choices": [ "choices": [
{ {
"text": "与陌生人握手", "text": "与陌生人握手",
"textEn": "Shake hands with the stranger",
"targetScene": "trust_ending", "targetScene": "trust_ending",
"effects": [ "effects": [
{ "type": "add", "target": "trust", "value": 30 } { "type": "add", "target": "trust", "value": 30 }
@@ -159,7 +153,6 @@
}, },
{ {
"text": "拒绝握手,保持警惕", "text": "拒绝握手,保持警惕",
"textEn": "Refuse to shake hands, stay alert",
"targetScene": "alone_ending" "targetScene": "alone_ending"
} }
] ]
@@ -191,12 +184,10 @@
"choices": [ "choices": [
{ {
"text": "继续前进", "text": "继续前进",
"textEn": "Continue forward",
"targetScene": "continue_ending" "targetScene": "continue_ending"
}, },
{ {
"text": "回头", "text": "回头",
"textEn": "Turn back",
"targetScene": "intro" "targetScene": "intro"
} }
] ]
@@ -207,12 +198,10 @@
"choices": [ "choices": [
{ {
"text": "继续前进", "text": "继续前进",
"textEn": "Continue forward",
"targetScene": "continue_ending" "targetScene": "continue_ending"
}, },
{ {
"text": "回头", "text": "回头",
"textEn": "Turn back",
"targetScene": "intro" "targetScene": "intro"
} }
] ]
@@ -223,12 +212,10 @@
"choices": [ "choices": [
{ {
"text": "返回调查现场", "text": "返回调查现场",
"textEn": "Return to the investigation scene",
"targetScene": "investigation_site" "targetScene": "investigation_site"
}, },
{ {
"text": "离开", "text": "离开",
"textEn": "Leave",
"targetScene": "corridor" "targetScene": "corridor"
} }
] ]
@@ -243,7 +230,6 @@
"loopStart": 3.0, "loopStart": 3.0,
"loopEnd": 6.0, "loopEnd": 6.0,
"choices": [ "choices": [
{ "text": "站起来离开", "textEn": "Stand up and leave", "targetScene": "alone_ending" }
] ]
}, },
"trust_ending": { "trust_ending": {
@@ -252,7 +238,6 @@
"choices": [ "choices": [
{ {
"text": "开启信任的旅程(需要 trust >= 80", "text": "开启信任的旅程(需要 trust >= 80",
"textEn": "Embark on a journey of trust (requires trust >= 80)",
"targetScene": "secret_ending", "targetScene": "secret_ending",
"conditions": [ "conditions": [
{ "variable": "trust", "op": ">=", "value": 80 } { "variable": "trust", "op": ">=", "value": 80 }
@@ -260,7 +245,6 @@
}, },
{ {
"text": "离开这里", "text": "离开这里",
"textEn": "Leave this place",
"targetScene": "alone_ending" "targetScene": "alone_ending"
} }
] ]

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, nextTick, computed } from 'vue' import { ref, watch, nextTick } from 'vue'
import type { Choice } from '@engine/types' import type { Choice } from '@engine/types'
import { useI18n } from '@/composables/useI18n' import { useI18n } from '@/composables/useI18n'
@@ -13,12 +13,7 @@ const emit = defineEmits<{
choose: [index: number] choose: [index: number]
}>() }>()
const { t, currentLang } = useI18n() const { t } = useI18n()
function choiceLabel(c: Choice): string {
if (currentLang.value === 'en' && (c as any).textEn) return (c as any).textEn
return c.text
}
const focusIndex = ref(0) const focusIndex = ref(0)
const btnRefs = ref<(HTMLButtonElement | null)[]>([]) const btnRefs = ref<(HTMLButtonElement | null)[]>([])
@@ -80,7 +75,7 @@ function onKeydown(e: KeyboardEvent, index: number) {
@click="emit('choose', index)" @click="emit('choose', index)"
@keydown="onKeydown($event, index)" @keydown="onKeydown($event, index)"
> >
{{ choiceLabel(choice) }} {{ t(choice.textKey || choice.text) }}
</button> </button>
</div> </div>
</div> </div>