handle room formats
This commit is contained in:
@@ -242,7 +242,7 @@ impl ToString for Game {
|
||||
}
|
||||
|
||||
for room in &self.rooms {
|
||||
segments.push(room.to_string());
|
||||
segments.push(room.to_string(self.room_format(), self.room_type));
|
||||
}
|
||||
|
||||
for tile in &self.tiles {
|
||||
|
||||
19
src/room.rs
19
src/room.rs
@@ -100,10 +100,14 @@ impl From<String> for Room {
|
||||
let mut tiles: Vec<String> = Vec::new();
|
||||
|
||||
for line in lines.into_iter() {
|
||||
let line: Vec<&str> = line
|
||||
.split(if line.contains(",") {","} else {""}) // old room format?
|
||||
let comma_separated = line.contains(","); // old room format?
|
||||
let mut line: Vec<&str> = line
|
||||
.split(if comma_separated {","} else {""})
|
||||
.collect();
|
||||
|
||||
if ! comma_separated { line = line[1..].to_owned(); }
|
||||
let line = line[..16].to_owned();
|
||||
|
||||
for tile_id in line {
|
||||
tiles.push(tile_id.to_string());
|
||||
}
|
||||
@@ -136,9 +140,16 @@ impl Room {
|
||||
let sqrt = (self.tiles.len() as f64).sqrt() as usize; // 8 for SD, 16 for HD
|
||||
for line in self.tiles.chunks(sqrt) {
|
||||
for tile in line {
|
||||
tiles.push_str(&format!("{},", tile));
|
||||
tiles.push_str(tile);
|
||||
if room_format == RoomFormat::CommaSeparated {
|
||||
tiles.push(',');
|
||||
}
|
||||
}
|
||||
tiles.pop(); // remove trailing comma
|
||||
|
||||
if room_format == RoomFormat::CommaSeparated {
|
||||
tiles.pop(); // remove trailing comma
|
||||
}
|
||||
|
||||
tiles.push_str("\n");
|
||||
}
|
||||
tiles.pop(); // remove trailing newline
|
||||
|
||||
Reference in New Issue
Block a user