From d35517043de53a1583e2f196e10bb31ab4081103 Mon Sep 17 00:00:00 2001 From: p11 Date: Wed, 9 Apr 2025 22:01:58 +0200 Subject: [PATCH] Use vn-settings and don't display empty boxes --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 1 + src/dialog.rs | 49 ++++++++++++++----------------------------------- src/main.rs | 30 +++++++++++++++++------------- 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95e65d4..38222b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,6 +149,7 @@ dependencies = [ "percent-encoding", "pukram2html", "rayon", + "vn-settings", ] [[package]] @@ -189,6 +190,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "simple-color" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0869e0c3d2f70dff69e4797b5af38d18bbf74374b0253843d79b31d63334f33" +dependencies = [ + "thiserror", +] + [[package]] name = "syn" version = "2.0.96" @@ -231,3 +241,13 @@ name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "vn-settings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f799fd65b2bf363a1c70c8dce20b9ea2e2e594173dd9bcd5475dd257b0e0b44a" +dependencies = [ + "dialogi", + "simple-color", +] diff --git a/Cargo.toml b/Cargo.toml index 8f27a51..4945317 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ pukram2html = "0.3.0" data-stream = "0.3.0" rayon = "1.10.0" dialogi = "0.3.1" +vn-settings = "0.1.0" diff --git a/src/dialog.rs b/src/dialog.rs index 648cf98..0fb45f8 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -1,40 +1,19 @@ -use std::path::Path; +use std::{collections::HashMap, path::Path}; -use dialogi::{DialogChange, DialogParameter, DialogSequence}; - -pub struct EmptyDialogContext; - -#[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct EmptyDialogParameter; - -impl DialogParameter for EmptyDialogParameter { - type Context = EmptyDialogContext; - - fn create(_: &str, _: &mut Self::Context) -> Option { - None - } -} - -pub struct EmptyDialogChange; - -impl DialogChange for EmptyDialogChange { - type Parameter = EmptyDialogParameter; - - fn default_change(_: Self::Parameter) -> Self { - Self - } - - fn value_change( - _: Self::Parameter, - _: &str, - _: &mut <::Parameter as DialogParameter>::Context, - ) -> Self { - Self - } -} +use dialogi::DialogSequence; +use vn_settings::{Change, Parameter, SettingsContext}; pub fn parse_map( story_path: &Path, -) -> Result>, dialogi::ParsingError> { - DialogSequence::map_from_path(story_path, &mut EmptyDialogContext) +) -> Result>, dialogi::ParsingError> { + let mut layers = HashMap::new(); + layers.insert("Background".into(), 0); + layers.insert("Character".into(), 1); + + let mut settings_context = SettingsContext { + object_cache: HashMap::new(), + layers, + }; + + DialogSequence::map_from_path(story_path, &mut settings_context) } diff --git a/src/main.rs b/src/main.rs index bf35af8..2da3f3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -588,20 +588,24 @@ fn handle_relative_connection( for block in &dialog_sequence.blocks { let mut block_content = Vec::new(); - convert_subheader( - block.lines.iter().map(|l| l.text.as_ref()), - &mut block_content, - start_level, - ); + let section_html = if block.lines.is_empty() { + html! {} + } else { + convert_subheader( + block.lines.iter().map(|l| l.text.as_ref()), + &mut block_content, + start_level, + ); - let section_html = html! { - fieldset class="visual-novel-box" { - @if !block.name.is_empty() { - legend class="character-name" { (block.name) } - } - div class="dialog-content" { - @if let Ok(content) = String::from_utf8(block_content) { - (maud::PreEscaped(content)) + html! { + fieldset class="visual-novel-box" { + @if !block.name.is_empty() { + legend class="character-name" { (block.name) } + } + div class="dialog-content" { + @if let Ok(content) = String::from_utf8(block_content) { + (maud::PreEscaped(content)) + } } } }