Extract Seed and AppSettings to utils
This commit is contained in:
parent
9be7b102d7
commit
b7780b8862
5 changed files with 43 additions and 35 deletions
22
src/utils/seed.rs
Normal file
22
src/utils/seed.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Clone, Resource)]
|
||||
pub struct Seed(u64);
|
||||
|
||||
impl From<String> for Seed {
|
||||
fn from(value: String) -> Self {
|
||||
Self(value.parse::<u64>().unwrap_or_else(|_| {
|
||||
let mut state = DefaultHasher::new();
|
||||
value.hash(&mut state);
|
||||
state.finish()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Seed> for [u8; 8] {
|
||||
fn from(value: Seed) -> Self {
|
||||
value.0.to_le_bytes()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue