hey the dialog system kinda works!
* .mono dialog files * clicking trees loads the dialog in to the dialog box * dialog box only visible when dialog is active/idle (not none i.e., hidden) Next up: Debug info about tree's dialogs and the active dialogmain
parent
e7557c67f2
commit
0d0b814b56
@ -0,0 +1,27 @@
|
|||||||
|
a
|
||||||
|
|
||||||
|
b
|
||||||
|
|
||||||
|
c
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
d
|
||||||
|
|
||||||
|
e
|
||||||
|
|
||||||
|
f
|
||||||
|
|
||||||
|
---
|
||||||
|
g
|
||||||
|
|
||||||
|
h
|
||||||
|
---
|
||||||
|
|
||||||
|
i
|
||||||
|
|
||||||
|
j
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
k
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
# This empty dialog should be ignored
|
||||||
|
---
|
||||||
|
|
||||||
|
# This is a comment
|
||||||
|
this is one line of dialog
|
||||||
|
|
||||||
|
this is another options
|
||||||
|
|
||||||
|
# This is another comment
|
||||||
|
---
|
||||||
|
|
||||||
|
# this is
|
||||||
|
# a lot
|
||||||
|
# of comments
|
||||||
|
# back to back
|
||||||
|
together they can make poetry
|
||||||
|
|
||||||
|
together they can tell a story
|
||||||
|
# and a few more for good measure
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# This should be ignored
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# This too
|
||||||
|
|
||||||
|
---
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
###
|
||||||
|
# Industry
|
||||||
|
# Written by Elijah Voigt
|
||||||
|
# No copyright, it's bad on purpose
|
||||||
|
###
|
||||||
|
|
||||||
|
industry
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
cars drone in the distance with no sign of stopping...
|
||||||
|
|
||||||
|
the roar of a jet echos in the sky somewhere between takeoff and landing...
|
||||||
|
|
||||||
|
a train in the distance warns of it's imminent arrival...
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
industry
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
use bevy::{
|
||||||
|
asset::{AssetLoader, LoadContext, io::Reader},
|
||||||
|
prelude::*,
|
||||||
|
reflect::TypePath,
|
||||||
|
};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Asset, TypePath, Debug, Deserialize, Default, Clone)]
|
||||||
|
pub(crate) struct Monologue {
|
||||||
|
value: Vec<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Monologue {
|
||||||
|
pub fn get(&self, idx: usize) -> Option<&Vec<String>> {
|
||||||
|
self.value.get(idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct MonologueLoader;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
enum MonologueLoaderError {
|
||||||
|
#[error("Could not load asset: {0}")]
|
||||||
|
Io(#[from] std::io::Error),
|
||||||
|
#[error("Could not parse utf8")]
|
||||||
|
Utf8(#[from] std::string::FromUtf8Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetLoader for MonologueLoader {
|
||||||
|
type Asset = Monologue;
|
||||||
|
type Settings = ();
|
||||||
|
type Error = MonologueLoaderError;
|
||||||
|
async fn load(
|
||||||
|
&self,
|
||||||
|
reader: &mut dyn Reader,
|
||||||
|
_settings: &(),
|
||||||
|
_load_context: &mut LoadContext<'_>,
|
||||||
|
) -> Result<Self::Asset, Self::Error> {
|
||||||
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
|
reader.read_to_end(&mut bytes).await?;
|
||||||
|
|
||||||
|
let raw_string = String::from_utf8(bytes)?;
|
||||||
|
|
||||||
|
let value: Vec<Vec<String>> = raw_string
|
||||||
|
// First split on the '---' separators between batches
|
||||||
|
.split_terminator("---")
|
||||||
|
.map(|batch| {
|
||||||
|
batch
|
||||||
|
// Then split batches into newline-separated groups of text
|
||||||
|
.split_terminator("\n\n")
|
||||||
|
.filter_map(|line| {
|
||||||
|
// Filter out comments, empty lines, and extraneous newlines
|
||||||
|
(!line.starts_with("#") && !line.is_empty() && line != "\n")
|
||||||
|
// Trim the resulting dialog option
|
||||||
|
.then_some(line.trim().into())
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.filter(|sub: &Vec<String>| !sub.is_empty())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
info!("Monologue: {:#?}", value);
|
||||||
|
|
||||||
|
let thing = Monologue { value };
|
||||||
|
Ok(thing)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extensions(&self) -> &[&str] {
|
||||||
|
&["mono"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MonologueAssetsPlugin;
|
||||||
|
|
||||||
|
impl Plugin for MonologueAssetsPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.init_asset::<Monologue>()
|
||||||
|
.init_asset_loader::<MonologueLoader>();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue