Compare commits
No commits in common. "a2597a1c5cd973da9b2390f48bd470cf82811091" and "e18f3acada7a0d2d89a2f3656511d600cdcd2774" have entirely different histories.
a2597a1c5c
...
e18f3acada
1 changed files with 84 additions and 128 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::{fs::File, io::Result as IOResult, path::PathBuf, str::FromStr};
|
use std::{path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use crate::agnostic_interface::CameraInterface;
|
use crate::agnostic_interface::CameraInterface;
|
||||||
use crate::faux_quicksilver::{Circle, Color, Rectangle, Transform, Vector, Window};
|
use crate::faux_quicksilver::{Circle, Color, Rectangle, Transform, Vector, Window};
|
||||||
|
@ -16,9 +16,8 @@ const JOINING_OPACITY_RATE: f32 = 0.13;
|
||||||
const JOINING_FAR_DIST: f32 = 700.0;
|
const JOINING_FAR_DIST: f32 = 700.0;
|
||||||
const JOINING_NEAR_DIST: f32 = 150.0;
|
const JOINING_NEAR_DIST: f32 = 150.0;
|
||||||
const DOUBLE_CLICK_TIME: f32 = 0.350;
|
const DOUBLE_CLICK_TIME: f32 = 0.350;
|
||||||
const SL_NOTIF_TIME: f32 = 7.0;
|
const SL_NOTIF_TIME: f32 = 5000.0;
|
||||||
const MAX_MOONS: usize = 5;
|
const MAX_MOONS: usize = 5;
|
||||||
const SAVE_FILENAME: &'static str = "LudumDare45_OneAndAll_SaveFile.bin";
|
|
||||||
|
|
||||||
fn interp_sq_inv(x: f32) -> f32 {
|
fn interp_sq_inv(x: f32) -> f32 {
|
||||||
if x < 0.0 {
|
if x < 0.0 {
|
||||||
|
@ -511,13 +510,13 @@ impl Menu {
|
||||||
true,
|
true,
|
||||||
"Single click to move, Double-click to create something",
|
"Single click to move, Double-click to create something",
|
||||||
),
|
),
|
||||||
Menu::instant_text(
|
//Menu::instant_text(
|
||||||
20.0,
|
// 20.0,
|
||||||
HEIGHT_F - 20.0,
|
// HEIGHT_F - 20.0,
|
||||||
20.0,
|
// 20.0,
|
||||||
true,
|
// true,
|
||||||
"S - save; L - load (can load from the start); R - reset",
|
// "S - save; L - load (can load from the start); R - reset",
|
||||||
),
|
//),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2225,25 +2224,53 @@ impl GameState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check pressed keys
|
// check pressed keys
|
||||||
if window.get_gi_mut().get_key_pressed('s')? {
|
//if window.get_gi_mut().get_key_pressed('s')? {
|
||||||
if self.state == 10 {
|
// TODO implement save
|
||||||
let save_result = self.save().map_err(|e| e.to_string());
|
//if self.state == 10 {
|
||||||
if let Err(s) = save_result {
|
// let save_data = SaveData {
|
||||||
self.save_load_notification = Some(SaveLoadNotification::Save {
|
// planets: self.planets.clone(),
|
||||||
text: Some(format!("Failed to save! {}", s)),
|
// stars: self.stars.clone(),
|
||||||
timer: SL_NOTIF_TIME,
|
// fishes: self.fishes.clone(),
|
||||||
});
|
// player: self.player,
|
||||||
}
|
// joining_particles: self.joining_particles.clone(),
|
||||||
}
|
// };
|
||||||
} else if window.get_gi_mut().get_key_pressed('l')? {
|
// save("OneAndAll_LD45", "slot0", &save_data)?;
|
||||||
let load_result = self.load().map_err(|e| e.to_string());
|
// self.save_load_notification = Some(SaveLoadNotification::Save {
|
||||||
if let Err(s) = load_result {
|
// text: None,
|
||||||
self.save_load_notification = Some(SaveLoadNotification::Load {
|
// timer: SL_NOTIF_TIME,
|
||||||
text: Some(format!("Failed to load! {}", s)),
|
// });
|
||||||
timer: SL_NOTIF_TIME,
|
//}
|
||||||
});
|
//} else if window.get_gi_mut().get_key_pressed('l')? {
|
||||||
}
|
// TODO
|
||||||
} else if window.get_gi_mut().get_key_pressed('r')? && self.state == 10 {
|
//let load_result = load::<SaveData>("OneAndAll_LD45", "slot0");
|
||||||
|
//if let Ok(save_data) = load_result {
|
||||||
|
// self.planets = save_data.planets;
|
||||||
|
// self.stars = save_data.stars;
|
||||||
|
// self.fishes = save_data.fishes;
|
||||||
|
// self.player = save_data.player;
|
||||||
|
// self.joining_particles = save_data.joining_particles;
|
||||||
|
// self.expl_conv_p_systems.clear();
|
||||||
|
// self.move_to = Vector {
|
||||||
|
// x: self.player.x,
|
||||||
|
// y: self.player.y,
|
||||||
|
// };
|
||||||
|
// self.camera.set_view_xy(
|
||||||
|
// self.player.x - WIDTH_F / 2.0,
|
||||||
|
// self.player.y - HEIGHT_F / 2.0,
|
||||||
|
// );
|
||||||
|
// self.dbl_click_timeout = None;
|
||||||
|
// self.click_time = None;
|
||||||
|
// self.click_release_time = DOUBLE_CLICK_TIME;
|
||||||
|
|
||||||
|
// self.state = 10;
|
||||||
|
// self.state_dirty = true;
|
||||||
|
// self.save_load_notification = Some(SaveLoadNotification::Load {
|
||||||
|
// text: None,
|
||||||
|
// timer: SL_NOTIF_TIME,
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
//} else if window.get_gi_mut().get_key_pressed('r')? && self.state == 10 {
|
||||||
|
if window.get_gi_mut().get_key_pressed('r')? && self.state == 10 {
|
||||||
self.state = 0;
|
self.state = 0;
|
||||||
self.state_dirty = true;
|
self.state_dirty = true;
|
||||||
window.get_music_mut(&self.music2)?.stop()?;
|
window.get_music_mut(&self.music2)?.stop()?;
|
||||||
|
@ -2498,11 +2525,15 @@ impl GameState {
|
||||||
match sl {
|
match sl {
|
||||||
SaveLoadNotification::Save { text, timer } => {
|
SaveLoadNotification::Save { text, timer } => {
|
||||||
*timer -= dt;
|
*timer -= dt;
|
||||||
println!("save, timer is {}", timer);
|
|
||||||
if *timer <= 0.0 {
|
if *timer <= 0.0 {
|
||||||
self.save_load_notification = None;
|
self.save_load_notification = None;
|
||||||
} else if text.is_none() {
|
} else if text.is_none() {
|
||||||
*text = Some(String::from("Saved the Game!"));
|
//self.font.execute(|f| {
|
||||||
|
// *text = Some(
|
||||||
|
// f.render("Saved the Game", &FontStyle::new(45.0, Color::WHITE))?,
|
||||||
|
// );
|
||||||
|
// Ok(())
|
||||||
|
//})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SaveLoadNotification::Load { text, timer } => {
|
SaveLoadNotification::Load { text, timer } => {
|
||||||
|
@ -2510,7 +2541,12 @@ impl GameState {
|
||||||
if *timer <= 0.0 {
|
if *timer <= 0.0 {
|
||||||
self.save_load_notification = None;
|
self.save_load_notification = None;
|
||||||
} else if text.is_none() {
|
} else if text.is_none() {
|
||||||
*text = Some(String::from("Loaded the Game!"));
|
//self.font.execute(|f| {
|
||||||
|
// *text = Some(
|
||||||
|
// f.render("Loaded the Game", &FontStyle::new(45.0, Color::WHITE))?,
|
||||||
|
// );
|
||||||
|
// Ok(())
|
||||||
|
//})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2610,106 +2646,26 @@ impl GameState {
|
||||||
fish.draw(&self.i_fish, window, Transform::IDENTITY);
|
fish.draw(&self.i_fish, window, Transform::IDENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(sl) = &mut self.save_load_notification {
|
// TODO
|
||||||
match sl {
|
//if let Some(sl) = &mut self.save_load_notification {
|
||||||
SaveLoadNotification::Save { text, timer }
|
// match sl {
|
||||||
| SaveLoadNotification::Load { text, timer } => {
|
// SaveLoadNotification::Save { text, timer }
|
||||||
if let Some(s) = text {
|
// | SaveLoadNotification::Load { text, timer } => {
|
||||||
window.get_font_mut(&self.font)?.draw(
|
// if let Some(i) = text {
|
||||||
s,
|
// let mut c = Color::WHITE;
|
||||||
20,
|
// c.a = ((*timer / SL_NOTIF_TIME) as f32 * 255.0) as u8;
|
||||||
20.0,
|
// let mut image_rect = i.area_rect();
|
||||||
20.0,
|
// image_rect.x = self.camera.x + 20.0;
|
||||||
Color::from_rgba(
|
// image_rect.y = self.camera.y + 20.0;
|
||||||
255,
|
// window.draw(&image_rect, Blended(i, c));
|
||||||
255,
|
// }
|
||||||
255,
|
// }
|
||||||
((*timer / SL_NOTIF_TIME) as f32 * 255.0) as u8,
|
// }
|
||||||
),
|
//}
|
||||||
)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.get_gi_mut().end_drawing()?;
|
window.get_gi_mut().end_drawing()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_family = "wasm"))]
|
|
||||||
pub fn save(&mut self) -> IOResult<()> {
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
let save_bytes = SaveData {
|
|
||||||
planets: self.planets.clone(),
|
|
||||||
stars: self.stars.clone(),
|
|
||||||
fishes: self.fishes.clone(),
|
|
||||||
player: self.player,
|
|
||||||
joining_particles: self.joining_particles.clone(),
|
|
||||||
}
|
|
||||||
.serialize();
|
|
||||||
let mut file = File::create(SAVE_FILENAME)?;
|
|
||||||
file.write_all(&save_bytes)?;
|
|
||||||
self.save_load_notification = Some(SaveLoadNotification::Save {
|
|
||||||
text: None,
|
|
||||||
timer: SL_NOTIF_TIME,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_family = "wasm"))]
|
|
||||||
pub fn load(&mut self) -> IOResult<()> {
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
let mut bytes = Vec::new();
|
|
||||||
{
|
|
||||||
let mut file = File::open(SAVE_FILENAME)?;
|
|
||||||
|
|
||||||
file.read_to_end(&mut bytes)?;
|
|
||||||
}
|
|
||||||
let (save_data, _) = SaveData::deserialize(&bytes).map_err(|_| {
|
|
||||||
std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidData,
|
|
||||||
"Failed to deserialize into SaveData!",
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
self.planets = save_data.planets;
|
|
||||||
self.stars = save_data.stars;
|
|
||||||
self.fishes = save_data.fishes;
|
|
||||||
self.player = save_data.player;
|
|
||||||
self.joining_particles = save_data.joining_particles;
|
|
||||||
self.expl_conv_p_systems.clear();
|
|
||||||
self.move_to = Vector::new(self.player.x, self.player.y);
|
|
||||||
self.camera
|
|
||||||
.set_view_xy(
|
|
||||||
self.player.x - WIDTH_F / 2.0,
|
|
||||||
self.player.y - HEIGHT_F / 2.0,
|
|
||||||
)
|
|
||||||
.ok();
|
|
||||||
self.dbl_click_timeout = None;
|
|
||||||
self.click_time = None;
|
|
||||||
self.click_release_time = DOUBLE_CLICK_TIME;
|
|
||||||
self.state = 10;
|
|
||||||
self.state_dirty = true;
|
|
||||||
self.save_load_notification = Some(SaveLoadNotification::Load {
|
|
||||||
text: None,
|
|
||||||
timer: SL_NOTIF_TIME,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_family = "wasm")]
|
|
||||||
pub fn save(&mut self) -> IOResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_family = "wasm")]
|
|
||||||
pub fn load(&mut self) -> IOResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue