Compare commits
No commits in common. "1d7e3f070448ed2c2c48a40669077f98dee9d88b" and "ee0e6af143bffb5fb8004b6080d80ce1f81d6590" have entirely different histories.
1d7e3f0704
...
ee0e6af143
|
@ -11,7 +11,7 @@ impl From<String> for Dialogue {
|
|||
#[inline]
|
||||
fn from(string: String) -> Dialogue {
|
||||
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 ") {
|
||||
Some(lines.pop().unwrap().replace("NAME ", ""))
|
||||
|
|
|
@ -16,7 +16,7 @@ impl FromStr for Ending {
|
|||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
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");
|
||||
|
||||
Ok(Ending { id, dialogue })
|
||||
|
|
29
src/game.rs
29
src/game.rs
|
@ -6,7 +6,7 @@ use std::str::FromStr;
|
|||
use std::collections::HashMap;
|
||||
use std::borrow::BorrowMut;
|
||||
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 -
|
||||
/// so there was a maximum of 36 unique tiles. later versions are comma-separated.
|
||||
|
@ -25,14 +25,12 @@ impl RoomFormat {
|
|||
_ => Err(InvalidRoomFormat),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for RoomFormat {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", match &self {
|
||||
fn to_string(&self) -> String {
|
||||
match &self {
|
||||
RoomFormat::Contiguous => "0",
|
||||
RoomFormat::CommaSeparated => "1",
|
||||
})
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -828,17 +826,22 @@ impl Game {
|
|||
}
|
||||
|
||||
fn font_line(&self) -> String {
|
||||
match self.font {
|
||||
Font::AsciiSmall => "".to_string(),
|
||||
Font::Custom => format!("\n\nDEFAULT_FONT {}", self.custom_font.as_ref().unwrap()),
|
||||
_ => format!("\n\nDEFAULT_FONT {}", self.font.to_string().unwrap()),
|
||||
if self.font == Font::AsciiSmall {
|
||||
"".to_string()
|
||||
} else {
|
||||
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 {
|
||||
match self.text_direction {
|
||||
TextDirection::RightToLeft => "\n\nTEXT_DIRECTION RTL",
|
||||
_ => "",
|
||||
if self.text_direction == TextDirection::RightToLeft {
|
||||
"\n\nTEXT_DIRECTION RTL"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
extern crate loe;
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::io::Cursor;
|
||||
|
||||
|
@ -160,7 +162,7 @@ fn new_unique_id(ids: Vec<String>) -> String {
|
|||
new_id += 1;
|
||||
}
|
||||
|
||||
to_base36(new_id)
|
||||
return to_base36(new_id);
|
||||
}
|
||||
|
||||
pub trait Quote {
|
||||
|
@ -169,7 +171,7 @@ pub trait Quote {
|
|||
|
||||
impl Quote for String {
|
||||
fn quote(&self) -> String {
|
||||
format!("\"\"\"\n{}\n\"\"\"", self)
|
||||
format!("\"\"\"\n{}\n\"\"\"", self).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
21
src/room.rs
21
src/room.rs
|
@ -67,7 +67,7 @@ impl From<String> for Room {
|
|||
|
||||
if last_line.starts_with("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();
|
||||
} else if last_line.starts_with("NAME") {
|
||||
name = Some(last_line.replace("NAME ", "").to_string());
|
||||
|
@ -80,7 +80,8 @@ impl From<String> for Room {
|
|||
let position = item_position[1];
|
||||
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() });
|
||||
}
|
||||
} 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 position = Position::from_str(parts[0]);
|
||||
|
||||
if let Ok(position) = position {
|
||||
if position.is_ok() {
|
||||
let position = position.unwrap();
|
||||
let exit = Exit::from_str(
|
||||
&format!("{} {}", parts[1], parts[2])
|
||||
);
|
||||
|
||||
if let Ok(exit) = exit {
|
||||
if exit.is_ok() {
|
||||
let exit = exit.unwrap();
|
||||
let mut transition = None;
|
||||
let mut dialogue_id = None;
|
||||
let chunks = parts[3..].chunks(2);
|
||||
|
@ -114,7 +117,8 @@ impl From<String> for Room {
|
|||
let position = ending_position[1];
|
||||
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 });
|
||||
}
|
||||
} else {
|
||||
|
@ -127,8 +131,8 @@ impl From<String> for Room {
|
|||
let dimension = lines.len(); // x or y, e.g. `16` for 16x16
|
||||
let mut tiles: Vec<String> = Vec::new();
|
||||
|
||||
for line in lines.iter() {
|
||||
let comma_separated = line.contains(','); // old room format?
|
||||
for line in lines.into_iter() {
|
||||
let comma_separated = line.contains(","); // old room format?
|
||||
let mut line: Vec<&str> = line
|
||||
.split(if comma_separated {","} else {""})
|
||||
.collect();
|
||||
|
@ -177,9 +181,8 @@ impl Room {
|
|||
tiles.pop(); // remove trailing comma
|
||||
}
|
||||
|
||||
tiles.push('\n');
|
||||
tiles.push_str("\n");
|
||||
}
|
||||
|
||||
tiles.pop(); // remove trailing newline
|
||||
|
||||
for instance in &self.items {
|
||||
|
|
|
@ -40,13 +40,10 @@ impl Sprite {
|
|||
}
|
||||
|
||||
fn item_lines(&self) -> String {
|
||||
if self.items.is_empty() {
|
||||
if self.items.len() == 0 {
|
||||
"".to_string()
|
||||
} else {
|
||||
let lines: Vec<String> = self.items.iter().map(
|
||||
|item| format!("ITM {}", item)
|
||||
).collect();
|
||||
|
||||
let lines: Vec<String> = self.items.iter().map(|item| format!("ITM {}", item)).collect();
|
||||
format!("\n{}", lines.join("\n"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ pub struct Variable {
|
|||
impl From<String> for Variable {
|
||||
fn from(string: String) -> Variable {
|
||||
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 {
|
||||
"".to_string()
|
||||
|
|
Loading…
Reference in New Issue