Skip to content

Commit

Permalink
Merge pull request #63 from Berrysoft/dev/overlay
Browse files Browse the repository at this point in the history
Enable multiple FRFS files overlay.
  • Loading branch information
Berrysoft committed Dec 17, 2022
2 parents 2b1b1b4 + c06771b commit 9b1abed
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 34 deletions.
3 changes: 2 additions & 1 deletion bins/ayaka-check/src/main.rs
Expand Up @@ -9,7 +9,8 @@ use std::{
#[derive(Debug, Parser)]
#[clap(about, version, author)]
pub struct Options {
input: OsString,
#[clap(required = true)]
input: Vec<OsString>,
#[clap(long)]
auto: bool,
#[clap(short, long)]
Expand Down
51 changes: 35 additions & 16 deletions bins/ayaka-gui/src-tauri/src/main.rs
Expand Up @@ -58,7 +58,7 @@ fn ayaka_version() -> &'static str {
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "t", content = "data")]
enum OpenGameStatus {
LoadProfile(String),
LoadProfile,
CreateRuntime,
LoadPlugin(String, usize, usize),
GamePlugin,
Expand All @@ -78,7 +78,7 @@ impl OpenGameStatus {

#[derive(Default)]
struct Storage {
config: String,
config: Vec<String>,
dist_port: u16,
manager: FileSettingsManager,
records: Mutex<Vec<ActionRecord>>,
Expand All @@ -89,9 +89,9 @@ struct Storage {
}

impl Storage {
pub fn new(resolver: &PathResolver, config: impl Into<String>, dist_port: u16) -> Self {
pub fn new(resolver: &PathResolver, config: Vec<String>, dist_port: u16) -> Self {
Self {
config: config.into(),
config,
dist_port,
manager: FileSettingsManager::new(resolver),
..Default::default()
Expand Down Expand Up @@ -129,7 +129,7 @@ async fn open_game(handle: AppHandle, storage: State<'_, Storage>) -> CommandRes
while let Some(status) = context.next().await {
match status {
OpenStatus::LoadProfile => {
OpenGameStatus::LoadProfile(config.clone()).emit(&handle)?;
OpenGameStatus::LoadProfile.emit(&handle)?;
}
OpenStatus::CreateRuntime => OpenGameStatus::CreateRuntime.emit(&handle)?,
OpenStatus::LoadPlugin(name, i, len) => {
Expand Down Expand Up @@ -465,22 +465,41 @@ fn main() -> Result<()> {
let window = app.get_window("main").unwrap();
window.open_devtools();
}

use serde_json::Value;

let matches = app.get_cli_matches()?;
let config = matches.args["config"]
.value
.as_str()
.map(|s| s.to_string())
.unwrap_or_else(|| {
let config = match &matches.args["config"].value {
Value::String(s) => vec![s.to_string()],
Value::Array(arr) => arr
.iter()
.filter_map(|v| v.as_str())
.map(|s| s.to_string())
.collect::<Vec<_>>(),
_ => {
let current = std::env::current_exe().unwrap();
let current = current.parent().unwrap();
let mut paths = vec![];

let data = current.join("data.frfs");
let data = if data.exists() {
data
if data.exists() {
paths.push(data);
paths.extend(
('a'..'z')
.into_iter()
.map(|c| current.join(format!("data.{}.frfs", c)))
.filter(|p| p.exists()),
);
} else {
current.join("config.yaml")
};
data.to_string_lossy().into_owned()
});
paths.push(current.join("config.yaml"));
}

paths
.into_iter()
.map(|p| p.to_string_lossy().into_owned())
.collect()
}
};
app.manage(Storage::new(&resolver, config, port));
Ok(())
})
Expand Down
3 changes: 2 additions & 1 deletion bins/ayaka-gui/src-tauri/tauri.conf.json
Expand Up @@ -78,7 +78,8 @@
{
"name": "config",
"index": 1,
"takesValue": true
"takesValue": true,
"multiple": true
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion bins/ayaka-gui/src/views/StartView.vue
Expand Up @@ -65,7 +65,7 @@ export default {
const t = OpenGameStatusType[s.t]
switch (t) {
case OpenGameStatusType.LoadProfile:
return [`Loading profile "${s.data as unknown as string}"...`, step * (t + 1)]
return [`Loading profile...`, step * (t + 1)]
case OpenGameStatusType.CreateRuntime:
return ["Creating runtime...", step * (t + 1)]
case OpenGameStatusType.LoadPlugin:
Expand Down
3 changes: 2 additions & 1 deletion bins/ayaka-latex/src/main.rs
Expand Up @@ -9,7 +9,8 @@ use writer::LaTeXWriter;
#[derive(Debug, Parser)]
#[clap(about, version, author)]
pub struct Options {
input: OsString,
#[clap(required = true)]
input: Vec<OsString>,
#[clap(short, long)]
output: OsString,
#[clap(short, long)]
Expand Down
46 changes: 32 additions & 14 deletions utils/ayaka-runtime/src/context.rs
Expand Up @@ -10,6 +10,7 @@ use frfs::FRFS;
use log::error;
use std::{collections::HashMap, path::Path, sync::Arc};
use stream_future::stream;
use tryiterator::TryIteratorExt;
use trylog::macros::*;
use vfs::*;

Expand Down Expand Up @@ -48,23 +49,40 @@ pub enum OpenStatus {

impl Context {
/// Open a config file with frontend type.
///
/// If the input `paths` contains only one element, it may be a YAML or an FRFS file.
/// If the input `paths` contains many element, they should all be FRFS files,
/// and the latter one will override the former one.
#[stream(OpenStatus, lifetime = "'a")]
pub async fn open<'a>(path: impl AsRef<Path> + 'a, frontend: FrontendType) -> Result<Self> {
let path = path.as_ref();
pub async fn open<'a>(paths: &'a [impl AsRef<Path>], frontend: FrontendType) -> Result<Self> {
if paths.is_empty() {
bail!("At least one path should be input.");
}
yield OpenStatus::LoadProfile;
let ext = path.extension().unwrap_or_default();
let (root_path, filename) = if ext == "yaml" {
let root_path = path
.parent()
.ok_or_else(|| anyhow!("Cannot get parent from input path."))?;
(
VfsPath::from(PhysicalFS::new(root_path)),
path.file_name().unwrap_or_default().to_string_lossy(),
)
} else if ext == "frfs" {
(FRFS::new(path)?.into(), "config.yaml".into())
let (root_path, filename) = if paths.len() == 1 {
let path = paths[0].as_ref();
let ext = path.extension().unwrap_or_default();
if ext == "yaml" {
let root_path = path
.parent()
.ok_or_else(|| anyhow!("Cannot get parent from input path."))?;
(
VfsPath::from(PhysicalFS::new(root_path)),
path.file_name().unwrap_or_default().to_string_lossy(),
)
} else if ext == "frfs" {
(FRFS::new(path)?.into(), "config.yaml".into())
} else {
bail!("Cannot determine filesystem.")
}
} else {
bail!("Cannot determine filesystem.")
let files = paths
.iter()
.rev()
.map(|path| FRFS::new(path.as_ref()))
.try_filter_map(|fs| Ok(Some(VfsPath::from(fs))))
.try_collect::<Vec<_>>()?;
(OverlayFS::new(&files).into(), "config.yaml".into())
};
let file = root_path.join(&filename)?.read_to_string()?;
let mut config: GameConfig = serde_yaml::from_str(&file)?;
Expand Down

0 comments on commit 9b1abed

Please sign in to comment.