use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Seed {
pub value: i32,
}
impl Seed {
pub fn new(value: i32) -> Self {
Self { value }
}
pub fn apply(&self) {
plottery_lib::seed(self.value);
}
}
impl fmt::Display for Seed {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.value)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProjectParamSeed {
pub current: i32,
pub history: Vec<i32>,
}
impl ProjectParamSeed {
pub const HISTORY_CAP: usize = 10;
pub fn new(current: i32) -> Self {
Self {
current,
history: Vec::new(),
}
}
pub fn set(&mut self, new: i32) {
if new == self.current {
return;
}
let previous = std::mem::replace(&mut self.current, new);
self.history.retain(|s| *s != previous && *s != new);
self.history.insert(0, previous);
self.history.truncate(Self::HISTORY_CAP);
}
pub fn clear_history(&mut self) {
self.history.clear();
}
}