-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expressions simplified descriptions from hash
- Loading branch information
Showing
7 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(expressions: [(RandomUnit(AllEnemyUnits), "random enemy")]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::hash::{DefaultHasher, Hash, Hasher}; | ||
|
||
use once_cell::sync::OnceCell; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::*; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Descriptions { | ||
expressions: Vec<(Expression, String)>, | ||
} | ||
|
||
static DESCRIPTIONS: OnceCell<HashMap<u64, String>> = OnceCell::new(); | ||
|
||
impl Descriptions { | ||
pub fn set(self) { | ||
dbg!(&self); | ||
let mut map: HashMap<u64, String> = default(); | ||
for (x, text) in self.expressions { | ||
let mut state = DefaultHasher::new(); | ||
x.hash(&mut state); | ||
map.insert(state.finish(), text); | ||
} | ||
DESCRIPTIONS.set(map).unwrap(); | ||
} | ||
pub fn get(key: impl Hash) -> Option<&'static String> { | ||
let mut state = DefaultHasher::new(); | ||
key.hash(&mut state); | ||
DESCRIPTIONS.get().unwrap().get(&state.finish()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters