Compare commits

..

No commits in common. "1d7e3f070448ed2c2c48a40669077f98dee9d88b" and "ee0e6af143bffb5fb8004b6080d80ce1f81d6590" have entirely different histories.

7 changed files with 37 additions and 32 deletions

View File

@ -11,7 +11,7 @@ impl From<String> for Dialogue {
#[inline] #[inline]
fn from(string: String) -> Dialogue { fn from(string: String) -> Dialogue {
let mut lines: Vec<&str> = string.lines().collect(); let mut lines: Vec<&str> = string.lines().collect();
let id = lines[0].replace("DLG ", ""); let id = lines[0].replace("DLG ", "").to_string();
let name = if lines.last().unwrap().starts_with("NAME ") { let name = if lines.last().unwrap().starts_with("NAME ") {
Some(lines.pop().unwrap().replace("NAME ", "")) Some(lines.pop().unwrap().replace("NAME ", ""))

View File

@ -16,7 +16,7 @@ impl FromStr for Ending {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let lines: Vec<&str> = s.lines().collect(); let lines: Vec<&str> = s.lines().collect();
let id = lines[0].replace("END ", ""); let id = lines[0].replace("END ", "").to_string();
let dialogue = lines[1..].join("\n"); let dialogue = lines[1..].join("\n");
Ok(Ending { id, dialogue }) Ok(Ending { id, dialogue })

View File

@ -6,7 +6,7 @@ use std::str::FromStr;
use std::collections::HashMap; use std::collections::HashMap;
use std::borrow::BorrowMut; use std::borrow::BorrowMut;
use std::fmt; use std::fmt;
use std::fmt::{Display, Formatter}; use std::fmt::Display;
/// in very early versions of Bitsy, room tiles were defined as single alphanumeric characters - /// in very early versions of Bitsy, room tiles were defined as single alphanumeric characters -
/// so there was a maximum of 36 unique tiles. later versions are comma-separated. /// so there was a maximum of 36 unique tiles. later versions are comma-separated.
@ -25,14 +25,12 @@ impl RoomFormat {
_ => Err(InvalidRoomFormat), _ => Err(InvalidRoomFormat),
} }
} }
}
impl Display for RoomFormat { fn to_string(&self) -> String {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self {
write!(f, "{}", match &self {
RoomFormat::Contiguous => "0", RoomFormat::Contiguous => "0",
RoomFormat::CommaSeparated => "1", RoomFormat::CommaSeparated => "1",
}) }.to_string()
} }
} }
@ -828,17 +826,22 @@ impl Game {
} }
fn font_line(&self) -> String { fn font_line(&self) -> String {
match self.font { if self.font == Font::AsciiSmall {
Font::AsciiSmall => "".to_string(), "".to_string()
Font::Custom => format!("\n\nDEFAULT_FONT {}", self.custom_font.as_ref().unwrap()), } else {
_ => format!("\n\nDEFAULT_FONT {}", self.font.to_string().unwrap()), if self.font == Font::Custom {
format!("\n\nDEFAULT_FONT {}", self.custom_font.as_ref().unwrap())
} else {
format!("\n\nDEFAULT_FONT {}", self.font.to_string().unwrap())
}
} }
} }
fn text_direction_line(&self) -> &str { fn text_direction_line(&self) -> &str {
match self.text_direction { if self.text_direction == TextDirection::RightToLeft {
TextDirection::RightToLeft => "\n\nTEXT_DIRECTION RTL", "\n\nTEXT_DIRECTION RTL"
_ => "", } else {
""
} }
} }

View File

@ -1,3 +1,5 @@
extern crate loe;
use std::fmt::Display; use std::fmt::Display;
use std::io::Cursor; use std::io::Cursor;
@ -160,7 +162,7 @@ fn new_unique_id(ids: Vec<String>) -> String {
new_id += 1; new_id += 1;
} }
to_base36(new_id) return to_base36(new_id);
} }
pub trait Quote { pub trait Quote {
@ -169,7 +171,7 @@ pub trait Quote {
impl Quote for String { impl Quote for String {
fn quote(&self) -> String { fn quote(&self) -> String {
format!("\"\"\"\n{}\n\"\"\"", self) format!("\"\"\"\n{}\n\"\"\"", self).to_string()
} }
} }

View File

@ -67,7 +67,7 @@ impl From<String> for Room {
if last_line.starts_with("WAL") { if last_line.starts_with("WAL") {
let last_line = last_line.replace("WAL ", ""); let last_line = last_line.replace("WAL ", "");
let ids: Vec<&str> = last_line.split(',').collect(); let ids: Vec<&str> = last_line.split(",").collect();
walls = ids.iter().map(|&id| id.to_string()).collect(); walls = ids.iter().map(|&id| id.to_string()).collect();
} else if last_line.starts_with("NAME") { } else if last_line.starts_with("NAME") {
name = Some(last_line.replace("NAME ", "").to_string()); name = Some(last_line.replace("NAME ", "").to_string());
@ -80,7 +80,8 @@ impl From<String> for Room {
let position = item_position[1]; let position = item_position[1];
let position = Position::from_str(position); let position = Position::from_str(position);
if let Ok(position) = position { if position.is_ok() {
let position = position.unwrap();
items.push(Instance { position, id: item_id.to_string() }); items.push(Instance { position, id: item_id.to_string() });
} }
} else if last_line.starts_with("EXT") { } else if last_line.starts_with("EXT") {
@ -88,12 +89,14 @@ impl From<String> for Room {
let parts: Vec<&str> = last_line.split(' ').collect(); let parts: Vec<&str> = last_line.split(' ').collect();
let position = Position::from_str(parts[0]); let position = Position::from_str(parts[0]);
if let Ok(position) = position { if position.is_ok() {
let position = position.unwrap();
let exit = Exit::from_str( let exit = Exit::from_str(
&format!("{} {}", parts[1], parts[2]) &format!("{} {}", parts[1], parts[2])
); );
if let Ok(exit) = exit { if exit.is_ok() {
let exit = exit.unwrap();
let mut transition = None; let mut transition = None;
let mut dialogue_id = None; let mut dialogue_id = None;
let chunks = parts[3..].chunks(2); let chunks = parts[3..].chunks(2);
@ -114,7 +117,8 @@ impl From<String> for Room {
let position = ending_position[1]; let position = ending_position[1];
let position = Position::from_str(position); let position = Position::from_str(position);
if let Ok(position) = position { if position.is_ok() {
let position = position.unwrap();
endings.push(Instance { position, id: ending }); endings.push(Instance { position, id: ending });
} }
} else { } else {
@ -127,8 +131,8 @@ impl From<String> for Room {
let dimension = lines.len(); // x or y, e.g. `16` for 16x16 let dimension = lines.len(); // x or y, e.g. `16` for 16x16
let mut tiles: Vec<String> = Vec::new(); let mut tiles: Vec<String> = Vec::new();
for line in lines.iter() { for line in lines.into_iter() {
let comma_separated = line.contains(','); // old room format? let comma_separated = line.contains(","); // old room format?
let mut line: Vec<&str> = line let mut line: Vec<&str> = line
.split(if comma_separated {","} else {""}) .split(if comma_separated {","} else {""})
.collect(); .collect();
@ -177,9 +181,8 @@ impl Room {
tiles.pop(); // remove trailing comma tiles.pop(); // remove trailing comma
} }
tiles.push('\n'); tiles.push_str("\n");
} }
tiles.pop(); // remove trailing newline tiles.pop(); // remove trailing newline
for instance in &self.items { for instance in &self.items {

View File

@ -40,13 +40,10 @@ impl Sprite {
} }
fn item_lines(&self) -> String { fn item_lines(&self) -> String {
if self.items.is_empty() { if self.items.len() == 0 {
"".to_string() "".to_string()
} else { } else {
let lines: Vec<String> = self.items.iter().map( let lines: Vec<String> = self.items.iter().map(|item| format!("ITM {}", item)).collect();
|item| format!("ITM {}", item)
).collect();
format!("\n{}", lines.join("\n")) format!("\n{}", lines.join("\n"))
} }
} }

View File

@ -7,7 +7,7 @@ pub struct Variable {
impl From<String> for Variable { impl From<String> for Variable {
fn from(string: String) -> Variable { fn from(string: String) -> Variable {
let id_value: Vec<&str> = string.lines().collect(); let id_value: Vec<&str> = string.lines().collect();
let id = id_value[0].replace("VAR ", ""); let id = id_value[0].replace("VAR ", "").to_string();
let initial_value = if id_value.len() == 1 { let initial_value = if id_value.len() == 1 {
"".to_string() "".to_string()