Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#11 dialogue player #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
68 changes: 64 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ opt-level = 3
[dependencies]
bevy = { version = "0.7.0", features = ["mp3"] }
bevy-inspector-egui = "0.11.0"
bevy_egui = "0.14.0"
bevy_ecs_ldtk = "0.3.0"
paste = "1.0.7"
strum = "0.24.1"
Expand All @@ -25,5 +26,8 @@ heron = { version = "3.1.0", features = ["2d"] }
once_cell = "1.10.0"
rust-i18n = "0.6.1"

ron = "0.7.1"
ron = "0.8.0"
serde = "1.0.139"

dlg = "0.1"
anyhow = "1.0.62"
37 changes: 37 additions & 0 deletions assets/dialogues/ru/verres-home/test.dlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@ Alice came into the room and waved her hand

@alice Hi, Bob!

@bob Hi!

@alice What are you going to do?

// :menu What should I say to her? {
// #walk I'm going to go for a walk
// I want to sleep {
// @alice Oh, okay. Then I'll come back later. Sweet dreams

// @bob Are made of this...
// }
// }

:menu What should I say to her?
:opt(#walk) I'm going to go for a walk
:opt(#sleep) I want to sleep

#walk

@alice

Great! May I come with you?

@bob Sure!

@ You went for a walk and had a good time


#sleep

@alice Oh, okay. Then I'll come back later. Sweet dreams

@bob Are made of this...
36 changes: 36 additions & 0 deletions src/bevy_dlg/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// TODO: Move to separate crate

use anyhow::*;
use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
reflect::TypeUuid,
utils::BoxedFuture,
};
use dlg::prelude::Dialog;
use std::str::FromStr;

#[derive(TypeUuid, Default)]
#[uuid = "a914688f-8e8e-4584-8eca-8e6322e1de3b"]
pub struct DialogAsset(pub Dialog);

impl AssetLoader for DialogAsset {
fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, anyhow::Result<()>> {
Box::pin(async move {
let raw = String::from_utf8(Vec::from(bytes))?;

let dialog = Dialog::from_str(&raw).map_err(|_| anyhow!("can't parse dialog"))?;
let res = DialogAsset(dialog);

load_context.set_default_asset(LoadedAsset::new(res));
Ok(())
})
}

fn extensions(&self) -> &[&str] {
&["dlg"]
}
}
Loading