allow game to have font data (not really parsed for now)

This commit is contained in:
Max Bradbury 2020-04-23 07:43:52 +01:00
parent f740496727
commit d1254988bc
2 changed files with 20 additions and 6 deletions

View File

@ -38,6 +38,7 @@ pub struct Game {
pub dialogues: Vec<Dialogue>, pub dialogues: Vec<Dialogue>,
pub endings: Vec<Ending>, pub endings: Vec<Ending>,
pub variables: Vec<Variable>, pub variables: Vec<Variable>,
pub font_data: Option<String>, // todo make this an actual struct for parsing
} }
impl Game { impl Game {
@ -55,14 +56,21 @@ impl Game {
let mut dialogues: Vec<Dialogue> = Vec::new(); let mut dialogues: Vec<Dialogue> = Vec::new();
let mut endings: Vec<Ending> = Vec::new(); let mut endings: Vec<Ending> = Vec::new();
let mut variables: Vec<Variable> = Vec::new(); let mut variables: Vec<Variable> = Vec::new();
let mut font_data: Option<String> = None;
let main_split: Vec<&str> = string.split("\n\nDLG").collect(); let main_split: Vec<&str> = string.split("\n\nDLG").collect();
let main = main_split[0].to_string(); 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(); let variable_segments: Vec<&str> = variable_segments.split("\n\nVAR").collect();
if variable_segments.len() > 0 { 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(); let variable_segments = variable_segments[1..].to_owned();
for segment in variable_segments { 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(); let ending_segments: Vec<&str> = ending_segments.split("\n\nEND").collect();
if ending_segments.len() > 0 { 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(); let ending_segments = ending_segments[1..].to_owned();
for segment in ending_segments { for segment in ending_segments {
@ -84,7 +92,7 @@ impl Game {
} }
let dialogue_segments = 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(); let dialogue_segments: Vec<&str> = dialogue_segments.split("\n\nDLG").collect();
for segment in dialogue_segments[1..].to_owned() { for segment in dialogue_segments[1..].to_owned() {
@ -159,6 +167,7 @@ impl Game {
dialogues, dialogues,
endings, endings,
variables, variables,
font_data,
}) })
} }
} }
@ -224,6 +233,10 @@ impl ToString for Game {
segments.push(variable.to_string()); segments.push(variable.to_string());
} }
if self.font_data.is_some() {
segments.push(self.font_data.to_owned().unwrap())
}
format!( format!(
"{}\n{}\n{}{}{}\n\n{}\n\n", "{}\n{}\n{}{}{}\n\n{}\n\n",
&self.name, &self.name,

View File

@ -753,5 +753,6 @@ pub fn game_default() -> Game {
id: "a".to_string(), id: "a".to_string(),
initial_value: "42".to_string(), initial_value: "42".to_string(),
}], }],
font_data: None
} }
} }