From dd00686de0a5918e9306400cf05be206b2c600c6 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Tue, 28 Apr 2020 08:34:35 +0100 Subject: [PATCH] add transition and dialogue for exits (7.0) --- README.md | 1 - src/lib.rs | 2 ++ src/mock.rs | 2 ++ src/room.rs | 21 ++++++++++++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8758f99..6a45862 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ some more practical uses would be things like: ## todo * test for bitsy 7.0 and implement new features - * add dialogues to exits * titles can have multiple lines of dialog * dialogue names * implement Result return types on ::from functions so we can handle errors diff --git a/src/lib.rs b/src/lib.rs index d7baffd..533f421 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,8 @@ pub struct Instance { pub struct ExitInstance { position: Position, exit: Exit, + transition: Option, + dialogue_id: Option, } pub trait AnimationFrames { diff --git a/src/mock.rs b/src/mock.rs index 005bac1..ae0b5a5 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -396,6 +396,8 @@ pub fn room() -> Room { position: Position { x: 10, y: 6 }, effect: Transition::None, }, + transition: None, + dialogue_id: None }], endings: vec![Instance { position: Position { x: 8, y: 7 }, diff --git a/src/room.rs b/src/room.rs index 539e18d..892e947 100644 --- a/src/room.rs +++ b/src/room.rs @@ -1,5 +1,6 @@ use crate::{from_base36, optional_data_line, Exit, ExitInstance, Instance, Position, ToBase36}; use crate::game::{RoomType, RoomFormat}; +use crate::exit::Transition; #[derive(Debug, Eq, PartialEq)] pub struct Room { @@ -76,8 +77,17 @@ impl From for Room { let parts: Vec<&str> = last_line.split(' ').collect(); let position = Position::from(parts[0].to_string()).unwrap(); let exit = Exit::from(format!("{} {}", parts[1], parts[2])); - - exits.push(ExitInstance { position, exit }); + let mut transition = None; + let mut dialogue_id = None; + let chunks = parts[3..].chunks(2); + for chunk in chunks { + if chunk[0] == "FX" { + transition = Some(Transition::from(chunk[1])); + } else if chunk[0] == "DLG" { + dialogue_id = Some(chunk[1].to_string()); + } + } + exits.push(ExitInstance { position, exit, transition, dialogue_id }); } else if last_line.starts_with("END") { let last_line = last_line.replace("END ", ""); let ending_position: Vec<&str> = last_line.split(' ').collect(); @@ -163,9 +173,14 @@ impl Room { for instance in &self.exits { exits.push_str(&format!( - "\nEXT {} {}", + "\nEXT {} {}{}{}{}", instance.position.to_string(), instance.exit.to_string(), + if instance.transition.is_some() { + instance.transition.as_ref().unwrap().to_string() + } else {"".to_string()}, + if instance.dialogue_id.is_some() {" DLG "} else {""}, + instance.dialogue_id.as_ref().unwrap_or(&"".to_string()), )); }