diff --git a/bins/ayaka-check/src/main.rs b/bins/ayaka-check/src/main.rs index c2d53a4e..32274cc0 100644 --- a/bins/ayaka-check/src/main.rs +++ b/bins/ayaka-check/src/main.rs @@ -62,7 +62,9 @@ async fn main() -> Result<()> { bail!("Check failed."); } ctx.init_new(); - ctx.set_locale(opts.locale.unwrap_or_else(Locale::current)); + ctx.set_settings(Settings { + lang: opts.locale.unwrap_or_else(Locale::current), + }); while let Some(action) = ctx.next_run() { if let Some(name) = &action.character { print!("_{}_", name); diff --git a/bins/ayaka-gui/src-tauri/src/main.rs b/bins/ayaka-gui/src-tauri/src/main.rs index 23baf29a..3d20049e 100644 --- a/bins/ayaka-gui/src-tauri/src/main.rs +++ b/bins/ayaka-gui/src-tauri/src/main.rs @@ -10,7 +10,10 @@ use ayaka_runtime::{ }; use flexi_logger::{FileSpec, LogSpecification, Logger}; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, fmt::Display}; +use std::{ + collections::{HashMap, HashSet}, + fmt::Display, +}; use tauri::{async_runtime::Mutex, command, AppHandle, Manager, State}; type CommandResult = std::result::Result; @@ -174,7 +177,24 @@ async fn save_all(storage: State<'_, Storage>) -> CommandResult<()> { } #[command] -fn choose_locale(locales: Vec) -> CommandResult> { +async fn avaliable_locale( + storage: State<'_, Storage>, + locales: HashSet, +) -> CommandResult> { + if let Some(context) = storage.context.lock().await.as_ref() { + let avaliable = context.game.paras.keys().cloned().collect(); + Ok(locales.intersection(&avaliable).cloned().collect()) + } else { + Ok(locales) + } +} + +#[command] +async fn choose_locale( + storage: State<'_, Storage>, + locales: HashSet, +) -> CommandResult> { + let locales = avaliable_locale(storage, locales).await?; let current = Locale::current(); debug!("Choose {} from {:?}", current, locales); Ok(current.choose_from(&locales).cloned()) @@ -305,6 +325,16 @@ async fn current_run(storage: State<'_, Storage>) -> CommandResult) -> CommandResult> { + Ok(storage + .context + .lock() + .await + .as_ref() + .and_then(|context| context.current_paragraph_title().cloned())) +} + #[command] async fn switch(i: usize, storage: State<'_, Storage>) -> CommandResult { debug!("Switch {}", i); @@ -389,6 +419,7 @@ fn main() -> Result<()> { get_records, save_record_to, save_all, + avaliable_locale, choose_locale, info, start_new, @@ -396,6 +427,7 @@ fn main() -> Result<()> { next_run, next_back_run, current_run, + current_title, current_visited, switch, history, diff --git a/bins/ayaka-gui/src/interop/index.ts b/bins/ayaka-gui/src/interop/index.ts index 1f24e0dd..fa4ddfca 100644 --- a/bins/ayaka-gui/src/interop/index.ts +++ b/bins/ayaka-gui/src/interop/index.ts @@ -50,7 +50,6 @@ export interface Action { line: ActionLine[], ch_key?: string, character?: string, - para_title?: string, switches: Switch[], props: { bg?: string, @@ -58,7 +57,7 @@ export interface Action { efm?: string, voice?: string, video?: string, - ch_models_count?: string, + ch_models?: string, }, } @@ -111,12 +110,12 @@ export function save_all(): Promise { return invoke("save_all") } -export function choose_locale(locales: Locale[]): Promise { - return invoke("choose_locale", { locales: locales }) +export function avaliable_locale(locales: Locale[]): Promise { + return invoke("avaliable_locale", { locales: locales }) } -export function locale_native_name(loc: Locale): string { - return new Intl.DisplayNames(loc, { type: "language" }).of(loc) ?? "" +export function choose_locale(locales: Locale[]): Promise { + return invoke("choose_locale", { locales: locales }) } export async function info(): Promise { @@ -144,6 +143,10 @@ export function current_run(): Promise { return invoke("current_run") } +export function current_title(): Promise { + return invoke("current_title") +} + export async function current_visited(): Promise { return invoke("current_visited") } diff --git a/bins/ayaka-gui/src/views/GameView.vue b/bins/ayaka-gui/src/views/GameView.vue index 9c679d8a..5e041665 100644 --- a/bins/ayaka-gui/src/views/GameView.vue +++ b/bins/ayaka-gui/src/views/GameView.vue @@ -3,7 +3,7 @@ import { setTimeout } from 'timers-promises' import { Mutex, tryAcquire } from 'async-mutex' import ActionCard from '../components/ActionCard.vue' import IconButton from '../components/IconButton.vue' -import { conv_src, current_run, next_run, next_back_run, switch_, merge_lines, Action, ActionLineType, ActionLine, current_visited } from '../interop' +import { conv_src, current_run, current_title, next_run, next_back_run, switch_, merge_lines, Action, ActionLineType, ActionLine, current_visited } from '../interop' import { cloneDeep } from 'lodash' import Live2D from '../components/Live2D.vue' import { Modal } from 'bootstrap' @@ -30,8 +30,8 @@ function wait_play(e: HTMLAudioElement): Promise { }) } -function live2d_names(props: any): string[] { - return ((props.ch_models ?? "") as string).split(",").filter(s => s.length != 0) +function live2d_names(props: { ch_models?: string }): string[] { + return (props.ch_models ?? "").split(",").filter(s => s.length != 0) } export default { @@ -43,6 +43,7 @@ export default { switches: [], props: {}, } as Action, + title: "", type_text: "", type_text_buffer: [] as ActionLine[], state: ActionState.End, @@ -69,6 +70,7 @@ export default { // Should be called in mutex async fetch_current_run() { const res = await current_run() + this.title = await current_title() ?? "" console.info(res) if (res) { const load_new_bgm = (res.props.bgm != this.action.props.bgm); @@ -263,7 +265,7 @@ export default {
-

{{ action.para_title }}

+

{{ title }}