Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ pub struct CustomSection {
pub entrypoint: String,
}

#[derive(Debug, Deserialize)]
pub struct JsDosSection {
pub version: String,
pub entrypoint: String,
}

#[derive(Debug, Deserialize)]
pub struct RuffleSection {
pub version: String,
pub entrypoint: String,
}

#[derive(Debug, Deserialize)]
pub struct WavedashConfig {
pub game_id: String,
Expand All @@ -116,13 +128,21 @@ pub struct WavedashConfig {

#[serde(rename = "custom")]
pub custom: Option<CustomSection>,

#[serde(rename = "jsdos")]
pub jsdos: Option<JsDosSection>,

#[serde(rename = "ruffle")]
pub ruffle: Option<RuffleSection>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EngineKind {
Godot,
Unity,
Custom,
JsDos,
Ruffle,
}

impl EngineKind {
Expand All @@ -131,6 +151,8 @@ impl EngineKind {
EngineKind::Godot => "godot",
EngineKind::Unity => "unity",
EngineKind::Custom => "custom",
EngineKind::JsDos => "jsdos",
EngineKind::Ruffle => "ruffle",
}
}

Expand All @@ -139,6 +161,8 @@ impl EngineKind {
EngineKind::Godot => "GODOT",
EngineKind::Unity => "UNITY",
EngineKind::Custom => "CUSTOM",
EngineKind::JsDos => "JSDOS",
EngineKind::Ruffle => "RUFFLE",
}
}
}
Expand All @@ -160,16 +184,24 @@ impl WavedashConfig {
}

pub fn engine_type(&self) -> Result<EngineKind> {
match (
self.godot.is_some(),
self.unity.is_some(),
self.custom.is_some(),
) {
(true, false, false) => Ok(EngineKind::Godot),
(false, true, false) => Ok(EngineKind::Unity),
(false, false, true) => Ok(EngineKind::Custom),
let engines: Vec<EngineKind> = [
self.godot.is_some().then_some(EngineKind::Godot),
self.unity.is_some().then_some(EngineKind::Unity),
self.custom.is_some().then_some(EngineKind::Custom),
self.jsdos.is_some().then_some(EngineKind::JsDos),
self.ruffle.is_some().then_some(EngineKind::Ruffle),
]
.into_iter()
.flatten()
.collect();

match engines.len() {
1 => Ok(engines[0]),
0 => anyhow::bail!(
"Config must have exactly one engine section: [godot], [unity], [custom], [jsdos], or [ruffle]"
),
_ => anyhow::bail!(
"Config must have exactly one of [godot], [unity], or [custom] sections"
"Config must have exactly one engine section: [godot], [unity], [custom], [jsdos], or [ruffle]"
),
}
}
Expand All @@ -181,12 +213,20 @@ impl WavedashConfig {
Ok(&unity.version)
} else if let Some(ref custom) = self.custom {
Ok(&custom.version)
} else if let Some(ref jsdos) = self.jsdos {
Ok(&jsdos.version)
} else if let Some(ref ruffle) = self.ruffle {
Ok(&ruffle.version)
} else {
anyhow::bail!("No engine section found")
}
}

pub fn entrypoint(&self) -> Option<&str> {
self.custom.as_ref().map(|c| c.entrypoint.as_str())
self.custom
.as_ref()
.map(|c| c.entrypoint.as_str())
.or_else(|| self.jsdos.as_ref().map(|j| j.entrypoint.as_str()))
.or_else(|| self.ruffle.as_ref().map(|r| r.entrypoint.as_str()))
}
}
6 changes: 3 additions & 3 deletions src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ pub async fn handle_dev(config_path: Option<PathBuf>, verbose: bool, no_open: bo
let engine_kind = wavedash_config.engine_type()?;
let engine_label = engine_kind.as_label();

let entrypoint = if matches!(engine_kind, EngineKind::Custom) {
let entrypoint = if matches!(engine_kind, EngineKind::Custom | EngineKind::JsDos | EngineKind::Ruffle) {
Some(
wavedash_config
.entrypoint()
.ok_or_else(|| anyhow::anyhow!("Custom engine configs require an entrypoint"))?
.ok_or_else(|| anyhow::anyhow!("Engine config requires an entrypoint"))?
.to_string(),
)
} else {
Expand All @@ -88,7 +88,7 @@ pub async fn handle_dev(config_path: Option<PathBuf>, verbose: bool, no_open: bo
})?;
Some(fetch_entrypoint_params(engine_label, html_path).await?)
}
EngineKind::Custom => None,
EngineKind::Custom | EngineKind::JsDos | EngineKind::Ruffle => None,
};

let (rustls_config, cert_path, _key_path) = load_or_create_certificates().await?;
Expand Down