Initial version of image rendering
This commit is contained in:
parent
7a4b5b9908
commit
d35d4824a0
34
src/main.rs
34
src/main.rs
@ -605,6 +605,25 @@ fn handle_relative_connection(
|
|||||||
.map(|parent| parse_config(&parent.with_extension("vng")).ok())
|
.map(|parent| parse_config(&parent.with_extension("vng")).ok())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
fn render_scene(settings: &PlayerSettings, name: &str, output: &mut Vec<u8>) {
|
||||||
|
for object in &settings.objects.objects {
|
||||||
|
let Some(image_set) = object.image.get(name) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
for image in &settings.images.images[image_set] {
|
||||||
|
let Some(image) = image.get_ref(name) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = writeln!(
|
||||||
|
output,
|
||||||
|
"<img src={image:?} style='max-height: 100%; max-width: 100%; object-fit: cover'/>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_novel(
|
fn render_novel(
|
||||||
mut config_map: IndexMap<Box<str>, Box<str>>,
|
mut config_map: IndexMap<Box<str>, Box<str>>,
|
||||||
pk_path: &Path,
|
pk_path: &Path,
|
||||||
@ -654,6 +673,7 @@ fn handle_relative_connection(
|
|||||||
|
|
||||||
let dialogs = parse_map(pk_path, &mut settings_context)?;
|
let dialogs = parse_map(pk_path, &mut settings_context)?;
|
||||||
|
|
||||||
|
let mut scenes = Vec::new();
|
||||||
let mut sections = Vec::new();
|
let mut sections = Vec::new();
|
||||||
|
|
||||||
for dialog_sequence in dialogs {
|
for dialog_sequence in dialogs {
|
||||||
@ -679,6 +699,10 @@ fn handle_relative_connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut scene_data = Vec::new();
|
||||||
|
render_scene(&player_settings, &block.name, &mut scene_data);
|
||||||
|
scenes.push(unsafe { String::from_utf8_unchecked(scene_data) });
|
||||||
|
|
||||||
let section_html = if block.lines.is_empty() {
|
let section_html = if block.lines.is_empty() {
|
||||||
html! {}
|
html! {}
|
||||||
} else {
|
} else {
|
||||||
@ -711,6 +735,13 @@ fn handle_relative_connection(
|
|||||||
let html = html! {
|
let html = html! {
|
||||||
div id="story-container" {
|
div id="story-container" {
|
||||||
div class="textbox-container" {
|
div class="textbox-container" {
|
||||||
|
@for (index, scene) in scenes.iter().enumerate() {
|
||||||
|
div class="scene-section" data-section-index=(index)
|
||||||
|
style=(format!("display: {};", if index == 0 { "block" } else { "none" })) {
|
||||||
|
(maud::PreEscaped(scene))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
div class="textbox-content" {
|
div class="textbox-content" {
|
||||||
@for (index, section) in sections.iter().enumerate() {
|
@for (index, section) in sections.iter().enumerate() {
|
||||||
div class="story-section" data-section-index=(index)
|
div class="story-section" data-section-index=(index)
|
||||||
@ -854,6 +885,9 @@ fn handle_relative_connection(
|
|||||||
document.querySelectorAll('.story-section').forEach((el, index) => {
|
document.querySelectorAll('.story-section').forEach((el, index) => {
|
||||||
el.style.display = index === currentSection ? 'block' : 'none';
|
el.style.display = index === currentSection ? 'block' : 'none';
|
||||||
});
|
});
|
||||||
|
document.querySelectorAll('.scene-section').forEach((el, index) => {
|
||||||
|
el.style.display = index === currentSection ? 'block' : 'none';
|
||||||
|
});
|
||||||
document.getElementById('section-counter').textContent =
|
document.getElementById('section-counter').textContent =
|
||||||
`${currentSection + 1}/${totalSections}`;
|
`${currentSection + 1}/${totalSections}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user