From 33423cbf499e282b2cb42f648c59f87c6238cf62 Mon Sep 17 00:00:00 2001 From: aprzn Date: Sun, 29 Jan 2023 01:05:59 -0500 Subject: [PATCH] setting up the level builder for generating levels from the save file --- src/gd.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/gd.rs b/src/gd.rs index 5cea5de..65dd1e2 100644 --- a/src/gd.rs +++ b/src/gd.rs @@ -36,7 +36,36 @@ pub fn gd_path() -> PathBuf { path_buf } -fn load_levels() -> Vec { + +struct LevelBuilder { + name: Option, + song: Option, +} + +impl Default for LevelBuilder { + fn default() -> Self { + Self {name: None, song: None} + } +} + +impl LevelBuilder { + fn with_name(&mut self, name: String) { + self.name = Some(name); + } + fn with_song(&mut self, song: Song) { + self.song = Some(song); + } + fn make_level(self) -> Option { + if let Some(name) = self.name { + if let Some(song) = self.song { + return Some(Level {name, song}); + } + } + None + } +} + +fn get_levels() -> Vec { let raw_save_data = { let mut save_file = File::open(gd_path().join("CCLocalLevels.dat")).expect("No save file found!"); let mut sd = Vec::new();