From 970803cfa86e9e7303b6b413b6934bfd478e9cd8 Mon Sep 17 00:00:00 2001 From: BurnyLlama Date: Sun, 6 Nov 2022 16:58:38 +0100 Subject: [PATCH] Refactor --- src/database/map.rs | 27 +++++++++++++++++---------- src/database/mod.rs | 20 ++++++++++++++++++-- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/database/map.rs b/src/database/map.rs index 3d4acf7..cb1ba49 100644 --- a/src/database/map.rs +++ b/src/database/map.rs @@ -2,18 +2,11 @@ use mysql_common::{chrono::NaiveDateTime, frunk::HList}; use rocket::serde::{Serialize, Deserialize}; pub type MapRow = HList!(String, String, i8, i8, String, NaiveDateTime, String, i32, i32, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool); - + +// Different tile types and whether they appear in the map. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(crate = "rocket::serde")] -pub struct Map { - pub name: String, - pub server: String, - pub points: i8, - pub stars: i8, - pub mapper: String, - pub timestamp: NaiveDateTime, - pub width: i32, - pub height: i32, +pub struct MapTileData { pub death: bool, pub through: bool, pub jump: bool, @@ -56,6 +49,20 @@ pub struct Map { pub plasmau: bool } +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(crate = "rocket::serde")] +pub struct Map { + pub name: String, + pub server: String, + pub points: i8, + pub stars: i8, + pub mapper: String, + pub timestamp: NaiveDateTime, + pub width: i32, + pub height: i32, + pub tile_data: MapTileData +} + /* IMPORTANT: For this to work the following SQL query must be executed: ```SQL diff --git a/src/database/mod.rs b/src/database/mod.rs index 02fb261..062b91c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -16,7 +16,15 @@ pub fn get_maps(pool: &Pool) -> Result, Box> { "SELECT * FROM record_maps AS maps JOIN record_mapinfo AS mapinfo ON maps.Map = mapinfo.Map", |row: map::MapRow| { let hlist_pat![ name, server, points, stars, mapper, timestamp, _name_again, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau ] = row; - map::Map { name, server, points, stars, mapper, timestamp, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau } + map::Map { + name, + server, points, + stars, mapper, + timestamp, + width, + height, + tile_data: map::MapTileData { death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau } + } } )?; @@ -35,7 +43,15 @@ pub fn get_map_by_name(pool: &Pool, name: &str) -> Result, Box< Ok(match map { Some(row) => { let hlist_pat![ name, server, points, stars, mapper, timestamp, _name_again, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau ] = row; - Some(map::Map { name, server, points, stars, mapper, timestamp, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau }) + Some(map::Map { + name, + server, points, + stars, mapper, + timestamp, + width, + height, + tile_data: map::MapTileData { death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau } + }) }, None => None })