From d1254988bc1e117eaf6737f74e6213dc3e2a8f62 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Thu, 23 Apr 2020 07:43:52 +0100 Subject: [PATCH] allow game to have font data (not really parsed for now) --- src/game.rs | 25 +++++++++++++++++++------ src/mock.rs | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/game.rs b/src/game.rs index f590206..6b09048 100644 --- a/src/game.rs +++ b/src/game.rs @@ -38,6 +38,7 @@ pub struct Game { pub dialogues: Vec, pub endings: Vec, pub variables: Vec, + pub font_data: Option, // todo make this an actual struct for parsing } impl Game { @@ -55,14 +56,21 @@ impl Game { let mut dialogues: Vec = Vec::new(); let mut endings: Vec = Vec::new(); let mut variables: Vec = Vec::new(); + let mut font_data: Option = None; let main_split: Vec<&str> = string.split("\n\nDLG").collect(); let main = main_split[0].to_string(); - let mut dialogues_endings_variables: String = main_split[1..].join("\n\nDLG"); + let mut extra: String = main_split[1..].join("\n\nDLG"); - let variable_segments = dialogues_endings_variables.clone(); + if extra.contains("\n\nFONT") { + let parts = extra.clone(); + let parts: Vec<&str> = parts.split("\n\nFONT").collect(); + font_data = Some(format!("FONT{}", parts[1])); + } + + let variable_segments = extra.clone(); let variable_segments: Vec<&str> = variable_segments.split("\n\nVAR").collect(); if variable_segments.len() > 0 { - dialogues_endings_variables = variable_segments[0].to_string(); + extra = variable_segments[0].to_string(); let variable_segments = variable_segments[1..].to_owned(); for segment in variable_segments { @@ -71,10 +79,10 @@ impl Game { } } - let ending_segments = dialogues_endings_variables.clone(); + let ending_segments = extra.clone(); let ending_segments: Vec<&str> = ending_segments.split("\n\nEND").collect(); if ending_segments.len() > 0 { - dialogues_endings_variables = ending_segments[0].to_string(); + extra = ending_segments[0].to_string(); let ending_segments = ending_segments[1..].to_owned(); for segment in ending_segments { @@ -84,7 +92,7 @@ impl Game { } let dialogue_segments = - format!("\n\nDLG{}", dialogues_endings_variables.trim_matches('\n')); + format!("\n\nDLG{}", extra.trim_matches('\n')); let dialogue_segments: Vec<&str> = dialogue_segments.split("\n\nDLG").collect(); for segment in dialogue_segments[1..].to_owned() { @@ -159,6 +167,7 @@ impl Game { dialogues, endings, variables, + font_data, }) } } @@ -224,6 +233,10 @@ impl ToString for Game { segments.push(variable.to_string()); } + if self.font_data.is_some() { + segments.push(self.font_data.to_owned().unwrap()) + } + format!( "{}\n{}\n{}{}{}\n\n{}\n\n", &self.name, diff --git a/src/mock.rs b/src/mock.rs index bc29f09..7f97306 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -753,5 +753,6 @@ pub fn game_default() -> Game { id: "a".to_string(), initial_value: "42".to_string(), }], + font_data: None } }