diff options
| author | troido <troido@protonmail.com> | 2020-04-16 10:54:23 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-16 10:54:23 +0200 |
| commit | 905c6b649521296bba609db5b5c9a39008d34325 (patch) | |
| tree | 8d253de507b3663399e23819bf8b4a222e7b64a5 /src/componentwrapper.rs | |
| parent | 43bde225ebbadd0b917ca87f3164a50455a2b588 (diff) | |
add visit whitelist to homeportal, save and dedup its data even though it is loaded from template
Diffstat (limited to 'src/componentwrapper.rs')
| -rw-r--r-- | src/componentwrapper.rs | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 5fe8f1d..d677cb2 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -132,10 +132,10 @@ macro_rules! components { (pre: ($($done: tt)*)) => { components!(post: $($done)*); }; - ($($all: tt)*) => {components!(pre: () $($all)*);}; + (all: $($all: tt)*) => {components!(pre: () $($all)*);}; } -components!( +components!(all: Visible (name: String, sprite: String, height: Float) { Visible { sprite: Sprite{name: sprite}, @@ -238,6 +238,52 @@ components!( }; Ear () {Ear::default()}; Build (obj: Template); + Whitelist ( + allowed: List ({ + Whitelist.allowed.iter().map(|(item, players)|{ + Parameter::List(vec![ + Parameter::String(item.clone()), + Parameter::List( + players + .iter() + .map(|playerid| Parameter::String(playerid.name.clone())) + .collect() + ) + ]) + }).collect() + }) + ) { + Whitelist { + allowed: allowed + .iter() + .map(|p| { + if let Parameter::List(e) = p { + if e.len() != 2 { + Err(aerr!("whitelist must be a list of pairs"))? + } + if let (Parameter::String(s), Parameter::List(l)) = (e[0].clone(), e[1].clone()) { + let names = l + .iter() + .map(|n| { + if let Parameter::String(name) = n { + Ok(PlayerId{name: name.clone()}) + } else { + Err(aerr!("whitelisted players must be strings"))? + } + }) + .collect::<Result<HashSet<PlayerId>>>()?; + Ok((s, names)) + } else { + Err(aerr!("whitelist entries must be a string and a list"))? + } + } else { + Err(aerr!("whitelist must be a list of pairs"))? + } + }) + .collect::<Result<HashMap<String, HashSet<PlayerId>>>>()? + } + }; + Dedup (id: String, priority: Int); ); |
