Format Rust code using rustfmt
This commit is contained in:
committed by
GitHub
parent
9a5c4df2b1
commit
cba6c16414
56
src/game.rs
56
src/game.rs
@@ -1,4 +1,7 @@
|
||||
use crate::{Avatar, Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection, Tile, Variable, optional_data_line, ToBase36};
|
||||
use crate::{
|
||||
optional_data_line, Avatar, Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection,
|
||||
Tile, ToBase36, Variable,
|
||||
};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Version {
|
||||
@@ -10,7 +13,10 @@ impl Version {
|
||||
fn from(str: &str) -> Version {
|
||||
let parts: Vec<&str> = str.split(".").collect();
|
||||
assert_eq!(parts.len(), 2);
|
||||
Version { major: parts[0].parse().unwrap(), minor: parts[1].parse().unwrap() }
|
||||
Version {
|
||||
major: parts[0].parse().unwrap(),
|
||||
minor: parts[1].parse().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +82,8 @@ impl From<String> for Game {
|
||||
}
|
||||
}
|
||||
|
||||
let dialogue_segments = format!(
|
||||
"\n\nDLG{}",
|
||||
dialogues_endings_variables.trim_matches('\n')
|
||||
);
|
||||
let dialogue_segments =
|
||||
format!("\n\nDLG{}", dialogues_endings_variables.trim_matches('\n'));
|
||||
|
||||
let dialogue_segments: Vec<&str> = dialogue_segments.split("\n\nDLG").collect();
|
||||
for segment in dialogue_segments[1..].to_owned() {
|
||||
@@ -181,7 +185,7 @@ impl ToString for Game {
|
||||
// then SPR A (avatar), then all the non-numeric IDs
|
||||
fn is_string_numeric(str: String) -> bool {
|
||||
for c in str.chars() {
|
||||
if ! c.is_numeric() {
|
||||
if !c.is_numeric() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +202,7 @@ impl ToString for Game {
|
||||
segments.push(self.avatar.to_string());
|
||||
|
||||
for sprite in &self.sprites {
|
||||
if ! is_string_numeric(sprite.id.to_base36()) {
|
||||
if !is_string_numeric(sprite.id.to_base36()) {
|
||||
segments.push(sprite.to_string());
|
||||
}
|
||||
}
|
||||
@@ -233,7 +237,7 @@ impl ToString for Game {
|
||||
|
||||
impl Game {
|
||||
pub fn tile_ids(&self) -> Vec<u64> {
|
||||
self.tiles.iter().map(|tile| {tile.id}).collect()
|
||||
self.tiles.iter().map(|tile| tile.id).collect()
|
||||
}
|
||||
|
||||
/// first available tile ID.
|
||||
@@ -264,7 +268,10 @@ impl Game {
|
||||
}
|
||||
|
||||
fn version_line(&self) -> String {
|
||||
format!("\n# BITSY VERSION {}.{}", self.version.major, self.version.minor)
|
||||
format!(
|
||||
"\n# BITSY VERSION {}.{}",
|
||||
self.version.major, self.version.minor
|
||||
)
|
||||
}
|
||||
|
||||
fn room_format_line(&self) -> String {
|
||||
@@ -284,15 +291,17 @@ impl Game {
|
||||
}
|
||||
|
||||
fn text_direction_line(&self) -> &str {
|
||||
if self.text_direction == TextDirection::RightToLeft {"\n\nTEXT_DIRECTION RTL"} else {""}
|
||||
if self.text_direction == TextDirection::RightToLeft {
|
||||
"\n\nTEXT_DIRECTION RTL"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_from_string() {
|
||||
let output = Game::from(
|
||||
include_str!["test-resources/default.bitsy"].to_string()
|
||||
);
|
||||
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string());
|
||||
|
||||
let expected = crate::mock::game_default();
|
||||
|
||||
@@ -317,7 +326,7 @@ fn test_new_tile_id() {
|
||||
assert_eq!(crate::mock::game_default().new_tile_id(), 0);
|
||||
|
||||
let mut game = crate::mock::game_default();
|
||||
let mut tiles : Vec<Tile> = Vec::new();
|
||||
let mut tiles: Vec<Tile> = Vec::new();
|
||||
|
||||
for n in 0..9 {
|
||||
if n != 4 {
|
||||
@@ -356,34 +365,26 @@ fn test_bitsy_omnibus() {
|
||||
let acceptable_failures: Vec<String> = vec![
|
||||
// fails because of sprite colours but also because a tile contains "NaN"
|
||||
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
|
||||
|
||||
// SET instead of ROOM? todo investigate
|
||||
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/046871F8.bitsy.txt".to_string(),
|
||||
|
||||
// not sure about this one but it uses room wall array
|
||||
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
|
||||
|
||||
// bad game data
|
||||
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image
|
||||
|
||||
// this one has font data appended to the end of the game data - is this valid?
|
||||
"src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(),
|
||||
|
||||
// has an ending position of -1
|
||||
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
|
||||
|
||||
// extra line between dialogues
|
||||
"src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(),
|
||||
|
||||
// something going on with dialogues? todo investigate
|
||||
"src/test-resources/omnibus/807805CC.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(),
|
||||
|
||||
// this avatar has `ITM 0 1` - can the player start with an item? todo investigate
|
||||
"src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(),
|
||||
"src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(),
|
||||
@@ -394,7 +395,7 @@ fn test_bitsy_omnibus() {
|
||||
|
||||
let files = std::fs::read_dir("src/test-resources/omnibus");
|
||||
|
||||
if ! files.is_ok() {
|
||||
if !files.is_ok() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -402,7 +403,7 @@ fn test_bitsy_omnibus() {
|
||||
let path = file.unwrap().path();
|
||||
let nice_name = format!("{}", path.display());
|
||||
|
||||
if ! nice_name.contains("bitsy") || acceptable_failures.contains(&nice_name) {
|
||||
if !nice_name.contains("bitsy") || acceptable_failures.contains(&nice_name) {
|
||||
skips += 1;
|
||||
// println!("Skipping: {}", nice_name);
|
||||
println!("Skipped. {} passes, {} skips.", passes, skips);
|
||||
@@ -412,7 +413,10 @@ fn test_bitsy_omnibus() {
|
||||
println!("Testing: {}...", path.display());
|
||||
let game_data = std::fs::read_to_string(path).unwrap();
|
||||
let game = Game::from(game_data.clone());
|
||||
assert_eq!(game.to_string().trim_matches('\n'), game_data.trim_matches('\n'));
|
||||
assert_eq!(
|
||||
game.to_string().trim_matches('\n'),
|
||||
game_data.trim_matches('\n')
|
||||
);
|
||||
passes += 1;
|
||||
println!("Success! {} passes, {} skips.", passes, skips);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user