Compare commits
No commits in common. "fe690a6d9b5336ed2b97669009e052d1277e6b5a" and "0763d15b0ed0ea7807c1a3fac84934686eee0a61" have entirely different histories.
fe690a6d9b
...
0763d15b0e
19
src/game.rs
19
src/game.rs
|
@ -67,10 +67,8 @@ impl Version {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug)]
|
||||
pub enum NotFound {
|
||||
/// no game data whatsoever
|
||||
Anything,
|
||||
Avatar,
|
||||
Room,
|
||||
Sprite,
|
||||
|
@ -103,14 +101,7 @@ pub struct GameHasNoAvatar;
|
|||
// todo no tiles? no rooms? no palettes? turn this into an enum?
|
||||
|
||||
impl Game {
|
||||
// todo return (Result<Game, ?>, Vec<Box<dyn Error>>)?
|
||||
// would be nice to *try* to parse a game, and catalogue any and all errors without crashing,
|
||||
// for display purposes etc.
|
||||
pub fn from(string: String) -> Result<Game, NotFound> {
|
||||
if string.clone().trim() == "".to_string() {
|
||||
return Err(NotFound::Anything);
|
||||
}
|
||||
|
||||
let line_endings_crlf = string.contains("\r\n");
|
||||
let mut string = string;
|
||||
if line_endings_crlf {
|
||||
|
@ -843,7 +834,7 @@ impl Game {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::game::{Version, Game, NotFound};
|
||||
use crate::game::{Version, Game};
|
||||
use crate::text::{TextDirection, Font};
|
||||
use crate::tile::Tile;
|
||||
use crate::image::Image;
|
||||
|
@ -1068,10 +1059,4 @@ mod test {
|
|||
let expected = Some(&game.tiles[0]);
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_game_data_throws_error() {
|
||||
assert_eq!(Game::from("".to_string() ).err().unwrap(), NotFound::Anything);
|
||||
assert_eq!(Game::from(" \n \r\n".to_string()).err().unwrap(), NotFound::Anything);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue