store previous function data in local storage

This should maybe be done through website's hash instead? but idk
This commit is contained in:
Simon Gardling
2022-05-11 22:39:46 -04:00
parent 30475eb4f4
commit 3d7f313c18
4 changed files with 158 additions and 10 deletions

View File

@@ -5,6 +5,11 @@ use egui::{Button, Id, Key, Modifiers, TextEdit, WidgetText};
use emath::vec2;
use parsing::Hint;
use parsing::Movement;
use serde::ser::SerializeStruct;
use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;
use serde::Serializer;
use std::ops::BitXorAssign;
use uuid::Uuid;
@@ -23,6 +28,46 @@ impl Default for FunctionManager {
}
}
impl Serialize for FunctionManager {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut s = serializer.serialize_struct("FunctionManager", 1)?;
s.serialize_field(
"data",
&self
.functions
.iter()
.cloned()
.map(|(id, func)| (id.value(), func))
.collect::<Vec<(u64, FunctionEntry)>>(),
)?;
s.end()
}
}
impl<'de> Deserialize<'de> for FunctionManager {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Helper(Vec<(u64, FunctionEntry)>);
let helper = Helper::deserialize(deserializer)?;
Ok(FunctionManager {
functions: helper
.0
.iter()
.cloned()
.map(|(id, func)| (egui::Id::new_from_u64(id), func))
.collect::<Vec<(Id, FunctionEntry)>>(),
})
}
}
/// Function that creates button that's used with the `button_area`
const fn button_area_button(text: impl Into<WidgetText>) -> Button {
Button::new(text).frame(false)