cargo fix && cargo clippy fix
This commit is contained in:
parent
88665302f6
commit
c0838c276c
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use quote::{ToTokens, quote, quote_spanned};
|
use quote::{ToTokens, quote, quote_spanned};
|
||||||
use syn::{parenthesized, parse::Parse, spanned::Spanned};
|
use syn::{parse::Parse, spanned::Spanned};
|
||||||
|
|
||||||
use crate::hashlist::HashList;
|
use crate::hashlist::HashList;
|
||||||
|
|
||||||
|
|
@ -14,22 +14,6 @@ pub struct ChecksAs {
|
||||||
total_fields: usize,
|
total_fields: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<V> HashList<ChecksAsArg, V> {
|
|
||||||
// pub fn add_spanned(&mut self, key: ChecksAsArg, value: V) {
|
|
||||||
// if let Some(orig_key) = self.0.keys().find(|k| **k == key).cloned() {
|
|
||||||
// let new_span = key
|
|
||||||
// .span()
|
|
||||||
// .join(orig_key.span())
|
|
||||||
// .unwrap_or(key.span().located_at(orig_key.span()));
|
|
||||||
// let mut vals = self.0.remove(&key).unwrap();
|
|
||||||
// vals.push(value);
|
|
||||||
// self.0.insert(key.with_span(new_span), vals);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// self.0.insert(key, vec![value]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum ChecksAsArg {
|
enum ChecksAsArg {
|
||||||
AsSelf(proc_macro2::Span),
|
AsSelf(proc_macro2::Span),
|
||||||
|
|
@ -76,6 +60,7 @@ impl ChecksAsArg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
fn with_span(&self, span: proc_macro2::Span) -> Self {
|
fn with_span(&self, span: proc_macro2::Span) -> Self {
|
||||||
match self {
|
match self {
|
||||||
ChecksAsArg::AsSelf(_) => ChecksAsArg::AsSelf(span),
|
ChecksAsArg::AsSelf(_) => ChecksAsArg::AsSelf(span),
|
||||||
|
|
|
||||||
|
|
@ -162,12 +162,11 @@ where
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(file_name) = item.file_name().to_str() {
|
if let Some(file_name) = item.file_name().to_str()
|
||||||
if include_in_rerun(file_name) {
|
&& include_in_rerun(file_name) {
|
||||||
out.push(FileWithPath::from_path(item.path(), origin_path)?);
|
out.push(FileWithPath::from_path(item.path(), origin_path)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{ToTokens, quote, quote_spanned};
|
use quote::{ToTokens, quote, quote_spanned};
|
||||||
|
|
@ -16,15 +14,6 @@ enum VariantFieldIndex {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VariantFieldIndex {
|
|
||||||
const fn is_numeric(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
Self::Numeric(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl syn::parse::Parse for VariantFieldIndex {
|
impl syn::parse::Parse for VariantFieldIndex {
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
if input.is_empty() {
|
if input.is_empty() {
|
||||||
|
|
@ -116,7 +105,7 @@ impl Targets {
|
||||||
let matching = field
|
let matching = field
|
||||||
.ident
|
.ident
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|i| i.to_string() == ident.to_string())
|
.map(|i| i == ident)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if matching_val.is_some() && matching {
|
if matching_val.is_some() && matching {
|
||||||
panic!("duplicate?")
|
panic!("duplicate?")
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl KillOutcome {
|
||||||
.ok_or(GameError::InvalidTarget)?
|
.ok_or(GameError::InvalidTarget)?
|
||||||
.kill(DiedTo::GuardianProtecting {
|
.kill(DiedTo::GuardianProtecting {
|
||||||
night,
|
night,
|
||||||
source: guardian.clone(),
|
source: guardian,
|
||||||
protecting: original_target,
|
protecting: original_target,
|
||||||
protecting_from: original_killer,
|
protecting_from: original_killer,
|
||||||
protecting_from_cause: Box::new(original_kill.clone()),
|
protecting_from_cause: Box::new(original_kill.clone()),
|
||||||
|
|
@ -75,8 +75,8 @@ fn resolve_protection(
|
||||||
guarding: true,
|
guarding: true,
|
||||||
} => Some(KillOutcome::Guarding {
|
} => Some(KillOutcome::Guarding {
|
||||||
original_killer: killer,
|
original_killer: killer,
|
||||||
guardian: source.clone(),
|
guardian: *source,
|
||||||
original_target: target.clone(),
|
original_target: *target,
|
||||||
original_kill: killed_with.clone(),
|
original_kill: killed_with.clone(),
|
||||||
night,
|
night,
|
||||||
}),
|
}),
|
||||||
|
|
@ -103,8 +103,8 @@ pub fn resolve_kill(
|
||||||
&& let Some(protection) = changes.protected_take(target)
|
&& let Some(protection) = changes.protected_take(target)
|
||||||
{
|
{
|
||||||
return Ok(Some(
|
return Ok(Some(
|
||||||
resolve_protection(source.clone(), died_to, target, &protection, *night).unwrap_or(
|
resolve_protection(*source, died_to, target, &protection, *night).unwrap_or(
|
||||||
KillOutcome::Single(source.clone(), DiedTo::MapleWolfStarved { night: *night }),
|
KillOutcome::Single(*source, DiedTo::MapleWolfStarved { night: *night }),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +121,7 @@ pub fn resolve_kill(
|
||||||
match changes.protected_take(target) {
|
match changes.protected_take(target) {
|
||||||
Some(protection) => {
|
Some(protection) => {
|
||||||
return Ok(resolve_protection(
|
return Ok(resolve_protection(
|
||||||
killing_wolf.character_id().clone(),
|
killing_wolf.character_id(),
|
||||||
died_to,
|
died_to,
|
||||||
target,
|
target,
|
||||||
&protection,
|
&protection,
|
||||||
|
|
@ -131,9 +131,9 @@ pub fn resolve_kill(
|
||||||
None => {
|
None => {
|
||||||
// Wolf kill went through -- can kill shifter
|
// Wolf kill went through -- can kill shifter
|
||||||
return Ok(Some(KillOutcome::Single(
|
return Ok(Some(KillOutcome::Single(
|
||||||
ss_source.clone(),
|
*ss_source,
|
||||||
DiedTo::Shapeshift {
|
DiedTo::Shapeshift {
|
||||||
into: target.clone(),
|
into: *target,
|
||||||
night: *night,
|
night: *night,
|
||||||
},
|
},
|
||||||
)));
|
)));
|
||||||
|
|
@ -143,7 +143,7 @@ pub fn resolve_kill(
|
||||||
|
|
||||||
let protection = match changes.protected_take(target) {
|
let protection = match changes.protected_take(target) {
|
||||||
Some(prot) => prot,
|
Some(prot) => prot,
|
||||||
None => return Ok(Some(KillOutcome::Single(target.clone(), died_to.clone()))),
|
None => return Ok(Some(KillOutcome::Single(*target, died_to.clone()))),
|
||||||
};
|
};
|
||||||
|
|
||||||
match protection {
|
match protection {
|
||||||
|
|
@ -151,13 +151,12 @@ pub fn resolve_kill(
|
||||||
source,
|
source,
|
||||||
guarding: true,
|
guarding: true,
|
||||||
} => Ok(Some(KillOutcome::Guarding {
|
} => Ok(Some(KillOutcome::Guarding {
|
||||||
original_killer: died_to
|
original_killer: *died_to
|
||||||
.killer()
|
.killer()
|
||||||
.ok_or(GameError::GuardianInvalidOriginalKill)?
|
.ok_or(GameError::GuardianInvalidOriginalKill)?,
|
||||||
.clone(),
|
original_target: *target,
|
||||||
original_target: target.clone(),
|
|
||||||
original_kill: died_to.clone(),
|
original_kill: died_to.clone(),
|
||||||
guardian: source.clone(),
|
guardian: source,
|
||||||
night: NonZeroU8::new(night).unwrap(),
|
night: NonZeroU8::new(night).unwrap(),
|
||||||
})),
|
})),
|
||||||
Protection::Guardian {
|
Protection::Guardian {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ impl Game {
|
||||||
.characters()
|
.characters()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|c| CharacterState {
|
.map(|c| CharacterState {
|
||||||
player_id: c.player_id().clone(),
|
player_id: c.player_id(),
|
||||||
identity: c.identity(),
|
identity: c.identity(),
|
||||||
role: c.role().title(),
|
role: c.role().title(),
|
||||||
died_to: c.died_to().cloned(),
|
died_to: c.died_to().cloned(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use core::{num::NonZeroU8, ops::Not};
|
use core::num::NonZeroU8;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -178,7 +178,7 @@ impl Night {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|c| c.died_to().map(|d| (c, d)))
|
.filter_map(|c| c.died_to().map(|d| (c, d)))
|
||||||
.filter_map(|(c, d)| match c.role() {
|
.filter_map(|(c, d)| match c.role() {
|
||||||
Role::Hunter { target } => target.clone().map(|t| (c, t, d)),
|
Role::Hunter { target } => (*target).map(|t| (c, t, d)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.filter_map(|(c, t, d)| match d.date_time() {
|
.filter_map(|(c, t, d)| match d.date_time() {
|
||||||
|
|
@ -189,7 +189,7 @@ impl Night {
|
||||||
target,
|
target,
|
||||||
died_to: DiedTo::Hunter {
|
died_to: DiedTo::Hunter {
|
||||||
night,
|
night,
|
||||||
killer: c.character_id().clone(),
|
killer: c.character_id(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.for_each(|c| changes.push(c));
|
.for_each(|c| changes.push(c));
|
||||||
|
|
@ -258,7 +258,7 @@ impl Night {
|
||||||
if let Role::Hunter { target: t } =
|
if let Role::Hunter { target: t } =
|
||||||
new_village.character_by_id_mut(*source).unwrap().role_mut()
|
new_village.character_by_id_mut(*source).unwrap().role_mut()
|
||||||
{
|
{
|
||||||
t.replace(target.clone());
|
t.replace(*target);
|
||||||
}
|
}
|
||||||
if changes.killed(source).is_some()
|
if changes.killed(source).is_some()
|
||||||
&& changes.protected(source).is_none()
|
&& changes.protected(source).is_none()
|
||||||
|
|
@ -268,7 +268,7 @@ impl Night {
|
||||||
.character_by_id_mut(*target)
|
.character_by_id_mut(*target)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.kill(DiedTo::Hunter {
|
.kill(DiedTo::Hunter {
|
||||||
killer: source.clone(),
|
killer: *source,
|
||||||
night: NonZeroU8::new(self.night).unwrap(),
|
night: NonZeroU8::new(self.night).unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -291,12 +291,12 @@ impl Night {
|
||||||
let ss = new_village.character_by_id_mut(*source).unwrap();
|
let ss = new_village.character_by_id_mut(*source).unwrap();
|
||||||
match ss.role_mut() {
|
match ss.role_mut() {
|
||||||
Role::Shapeshifter { shifted_into } => {
|
Role::Shapeshifter { shifted_into } => {
|
||||||
*shifted_into = Some(target.clone())
|
*shifted_into = Some(*target)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
ss.kill(DiedTo::Shapeshift {
|
ss.kill(DiedTo::Shapeshift {
|
||||||
into: target.clone(),
|
into: *target,
|
||||||
night: NonZeroU8::new(self.night).unwrap(),
|
night: NonZeroU8::new(self.night).unwrap(),
|
||||||
});
|
});
|
||||||
// role change pushed in [apply_shapeshift]
|
// role change pushed in [apply_shapeshift]
|
||||||
|
|
@ -328,7 +328,7 @@ impl Night {
|
||||||
night: _,
|
night: _,
|
||||||
killing_wolf: _,
|
killing_wolf: _,
|
||||||
},
|
},
|
||||||
} => Some(target.clone()),
|
} => Some(*target),
|
||||||
_ => None,
|
_ => None,
|
||||||
}) {
|
}) {
|
||||||
if self.changes.iter().any(|c| match c {
|
if self.changes.iter().any(|c| match c {
|
||||||
|
|
@ -355,15 +355,15 @@ impl Night {
|
||||||
)
|
)
|
||||||
}) {
|
}) {
|
||||||
self.changes.push(NightChange::Kill {
|
self.changes.push(NightChange::Kill {
|
||||||
target: source.clone(),
|
target: *source,
|
||||||
died_to: DiedTo::Shapeshift {
|
died_to: DiedTo::Shapeshift {
|
||||||
into: kill_target.clone(),
|
into: kill_target,
|
||||||
night: NonZeroU8::new(self.night).unwrap(),
|
night: NonZeroU8::new(self.night).unwrap(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.changes.push(NightChange::Shapeshift {
|
self.changes.push(NightChange::Shapeshift {
|
||||||
source: source.clone(),
|
source: *source,
|
||||||
});
|
});
|
||||||
self.action_queue.push_front(ActionPrompt::RoleChange {
|
self.action_queue.push_front(ActionPrompt::RoleChange {
|
||||||
new_role: RoleTitle::Werewolf,
|
new_role: RoleTitle::Werewolf,
|
||||||
|
|
@ -584,7 +584,7 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Shapeshift {
|
change: Some(NightChange::Shapeshift {
|
||||||
source: source.character_id.clone(),
|
source: source.character_id,
|
||||||
}),
|
}),
|
||||||
unless: None,
|
unless: None,
|
||||||
})),
|
})),
|
||||||
|
|
@ -600,7 +600,7 @@ impl Night {
|
||||||
return Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
return Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::RoleChange(
|
change: Some(NightChange::RoleChange(
|
||||||
character_id.character_id.clone(),
|
character_id.character_id,
|
||||||
*new_role,
|
*new_role,
|
||||||
)),
|
)),
|
||||||
unless: None,
|
unless: None,
|
||||||
|
|
@ -623,7 +623,7 @@ impl Night {
|
||||||
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::ElderReveal {
|
change: Some(NightChange::ElderReveal {
|
||||||
elder: character_id.character_id.clone(),
|
elder: character_id.character_id,
|
||||||
}),
|
}),
|
||||||
unless: None,
|
unless: None,
|
||||||
}))
|
}))
|
||||||
|
|
@ -640,7 +640,7 @@ impl Night {
|
||||||
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::Seer(alignment),
|
result: ActionResult::Seer(alignment),
|
||||||
change: None,
|
change: None,
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
ActionPrompt::Protector {
|
ActionPrompt::Protector {
|
||||||
|
|
@ -650,12 +650,12 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Protection {
|
change: Some(NightChange::Protection {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
protection: Protection::Protector {
|
protection: Protection::Protector {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::Arcanist {
|
ActionPrompt::Arcanist {
|
||||||
marked: (Some(marked1), Some(marked2)),
|
marked: (Some(marked1), Some(marked2)),
|
||||||
|
|
@ -675,7 +675,7 @@ impl Night {
|
||||||
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::Arcanist { same },
|
result: ActionResult::Arcanist { same },
|
||||||
change: None,
|
change: None,
|
||||||
unless: Some(Unless::TargetsBlocked(marked1.clone(), marked2.clone())),
|
unless: Some(Unless::TargetsBlocked(*marked1, *marked2)),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
ActionPrompt::Gravedigger {
|
ActionPrompt::Gravedigger {
|
||||||
|
|
@ -690,7 +690,7 @@ impl Night {
|
||||||
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GraveDigger(dig_role),
|
result: ActionResult::GraveDigger(dig_role),
|
||||||
change: None,
|
change: None,
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
ActionPrompt::Hunter {
|
ActionPrompt::Hunter {
|
||||||
|
|
@ -700,10 +700,10 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::HunterTarget {
|
change: Some(NightChange::HunterTarget {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::Militia {
|
ActionPrompt::Militia {
|
||||||
character_id,
|
character_id,
|
||||||
|
|
@ -712,14 +712,14 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Kill {
|
change: Some(NightChange::Kill {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
died_to: DiedTo::Militia {
|
died_to: DiedTo::Militia {
|
||||||
killer: character_id.character_id.clone(),
|
killer: character_id.character_id,
|
||||||
night: NonZeroU8::new(self.night)
|
night: NonZeroU8::new(self.night)
|
||||||
.ok_or(GameError::InvalidMessageForGameState)?,
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::Militia { marked: None, .. } => {
|
ActionPrompt::Militia { marked: None, .. } => {
|
||||||
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
||||||
|
|
@ -732,15 +732,15 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Kill {
|
change: Some(NightChange::Kill {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
died_to: DiedTo::MapleWolf {
|
died_to: DiedTo::MapleWolf {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
night: NonZeroU8::new(self.night)
|
night: NonZeroU8::new(self.night)
|
||||||
.ok_or(GameError::InvalidMessageForGameState)?,
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
||||||
starves_if_fails: *kill_or_die,
|
starves_if_fails: *kill_or_die,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::MapleWolf { marked: None, .. } => {
|
ActionPrompt::MapleWolf { marked: None, .. } => {
|
||||||
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
||||||
|
|
@ -753,13 +753,13 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Protection {
|
change: Some(NightChange::Protection {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
protection: Protection::Guardian {
|
protection: Protection::Guardian {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
guarding: false,
|
guarding: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::Guardian {
|
ActionPrompt::Guardian {
|
||||||
character_id,
|
character_id,
|
||||||
|
|
@ -773,13 +773,13 @@ impl Night {
|
||||||
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Protection {
|
change: Some(NightChange::Protection {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
protection: Protection::Guardian {
|
protection: Protection::Guardian {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
guarding: false,
|
guarding: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
ActionPrompt::Guardian {
|
ActionPrompt::Guardian {
|
||||||
|
|
@ -790,13 +790,13 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Protection {
|
change: Some(NightChange::Protection {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
protection: Protection::Guardian {
|
protection: Protection::Guardian {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
guarding: prev_protect.character_id == *marked,
|
guarding: prev_protect.character_id == *marked,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::WolfPackKill {
|
ActionPrompt::WolfPackKill {
|
||||||
marked: Some(marked),
|
marked: Some(marked),
|
||||||
|
|
@ -804,25 +804,24 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Kill {
|
change: Some(NightChange::Kill {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
died_to: DiedTo::Wolfpack {
|
died_to: DiedTo::Wolfpack {
|
||||||
killing_wolf: self
|
killing_wolf: self
|
||||||
.village
|
.village
|
||||||
.killing_wolf()
|
.killing_wolf()
|
||||||
.ok_or(GameError::NoWolves)?
|
.ok_or(GameError::NoWolves)?
|
||||||
.character_id()
|
.character_id(),
|
||||||
.clone(),
|
|
||||||
night: NonZeroU8::new(self.night)
|
night: NonZeroU8::new(self.night)
|
||||||
.ok_or(GameError::InvalidMessageForGameState)?,
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::Shapeshifter { character_id } => {
|
ActionPrompt::Shapeshifter { character_id } => {
|
||||||
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Shapeshift {
|
change: Some(NightChange::Shapeshift {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
}),
|
}),
|
||||||
unless: None,
|
unless: None,
|
||||||
}))
|
}))
|
||||||
|
|
@ -834,14 +833,14 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::Kill {
|
change: Some(NightChange::Kill {
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
died_to: DiedTo::AlphaWolf {
|
died_to: DiedTo::AlphaWolf {
|
||||||
killer: character_id.character_id.clone(),
|
killer: character_id.character_id,
|
||||||
night: NonZeroU8::new(self.night)
|
night: NonZeroU8::new(self.night)
|
||||||
.ok_or(GameError::InvalidMessageForGameState)?,
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
ActionPrompt::AlphaWolf { marked: None, .. } => {
|
ActionPrompt::AlphaWolf { marked: None, .. } => {
|
||||||
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
||||||
|
|
@ -853,11 +852,11 @@ impl Night {
|
||||||
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
||||||
result: ActionResult::GoBackToSleep,
|
result: ActionResult::GoBackToSleep,
|
||||||
change: Some(NightChange::RoleBlock {
|
change: Some(NightChange::RoleBlock {
|
||||||
source: character_id.character_id.clone(),
|
source: character_id.character_id,
|
||||||
target: marked.clone(),
|
target: *marked,
|
||||||
block_type: RoleBlock::Direwolf,
|
block_type: RoleBlock::Direwolf,
|
||||||
}),
|
}),
|
||||||
unless: Some(Unless::TargetBlocked(marked.clone())),
|
unless: Some(Unless::TargetBlocked(*marked)),
|
||||||
})),
|
})),
|
||||||
|
|
||||||
ActionPrompt::Protector { marked: None, .. }
|
ActionPrompt::Protector { marked: None, .. }
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ impl GameSettings {
|
||||||
players
|
players
|
||||||
.iter()
|
.iter()
|
||||||
.find(|pid| pid.player_id == *assign_to)
|
.find(|pid| pid.player_id == *assign_to)
|
||||||
.ok_or(GameError::AssignedPlayerMissing(assign_to.clone()))
|
.ok_or(GameError::AssignedPlayerMissing(*assign_to))
|
||||||
.map(|id| (id, s))
|
.map(|id| (id, s))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -170,7 +170,7 @@ impl GameSettings {
|
||||||
if let Some(assigned) = role.assign_to.as_ref()
|
if let Some(assigned) = role.assign_to.as_ref()
|
||||||
&& !players.iter().any(|p| p.player_id == *assigned)
|
&& !players.iter().any(|p| p.player_id == *assigned)
|
||||||
{
|
{
|
||||||
return Err(GameError::AssignedPlayerMissing(assigned.clone()));
|
return Err(GameError::AssignedPlayerMissing(*assigned));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,13 +145,13 @@ impl Village {
|
||||||
pub fn killing_wolf_id(&self) -> CharacterId {
|
pub fn killing_wolf_id(&self) -> CharacterId {
|
||||||
let wolves = self.living_wolf_pack_players();
|
let wolves = self.living_wolf_pack_players();
|
||||||
if let Some(ww) = wolves.iter().find(|w| matches!(w.role(), Role::Werewolf)) {
|
if let Some(ww) = wolves.iter().find(|w| matches!(w.role(), Role::Werewolf)) {
|
||||||
ww.character_id().clone()
|
ww.character_id()
|
||||||
} else if let Some(non_ss_wolf) = wolves.iter().find(|w| {
|
} else if let Some(non_ss_wolf) = wolves.iter().find(|w| {
|
||||||
w.role().wolf() && !matches!(w.role(), Role::Shapeshifter { shifted_into: _ })
|
w.role().wolf() && !matches!(w.role(), Role::Shapeshifter { shifted_into: _ })
|
||||||
}) {
|
}) {
|
||||||
non_ss_wolf.character_id().clone()
|
non_ss_wolf.character_id()
|
||||||
} else {
|
} else {
|
||||||
wolves.into_iter().next().unwrap().character_id().clone()
|
wolves.into_iter().next().unwrap().character_id()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@ mod night_order;
|
||||||
mod role;
|
mod role;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
diedto::DiedTo,
|
|
||||||
error::GameError,
|
error::GameError,
|
||||||
game::{Game, GameSettings, OrRandom, SetupRole, SetupSlot, night::NightChange},
|
game::{Game, GameSettings, SetupRole, SetupSlot},
|
||||||
message::{
|
message::{
|
||||||
CharacterState, Identification, PublicIdentity,
|
CharacterState, Identification, PublicIdentity,
|
||||||
host::{HostDayMessage, HostGameMessage, HostNightMessage, ServerToHostMessage},
|
host::{HostDayMessage, HostGameMessage, HostNightMessage, ServerToHostMessage},
|
||||||
|
|
@ -15,8 +14,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use core::{
|
use core::{
|
||||||
char,
|
num::NonZeroU8,
|
||||||
num::{NonZero, NonZeroU8},
|
|
||||||
ops::Range,
|
ops::Range,
|
||||||
};
|
};
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
|
@ -205,7 +203,7 @@ impl GameExt for Game {
|
||||||
self.village()
|
self.village()
|
||||||
.characters()
|
.characters()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|c| matches!(c.role(), Role::Villager).then_some(c.character_id().clone()))
|
.filter_map(|c| matches!(c.role(), Role::Villager).then_some(c.character_id()))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +224,7 @@ impl GameExt for Game {
|
||||||
|
|
||||||
fn mark(&mut self, mark: CharacterId) -> ActionPrompt {
|
fn mark(&mut self, mark: CharacterId) -> ActionPrompt {
|
||||||
self.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
|
self.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
|
||||||
ActionResponse::MarkTarget(mark.clone()),
|
ActionResponse::MarkTarget(mark),
|
||||||
)))
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.prompt()
|
.prompt()
|
||||||
|
|
@ -500,11 +498,10 @@ fn yes_wolf_kill_n2() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|v| v.is_village())
|
.find(|v| v.is_village())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id();
|
||||||
.clone();
|
|
||||||
match game
|
match game
|
||||||
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
|
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
|
||||||
execution_target.clone(),
|
execution_target,
|
||||||
)))
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
|
@ -568,11 +565,10 @@ fn wolfpack_kill_all_targets_valid() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|v| v.is_village() && !matches!(v.role().title(), RoleTitle::Protector))
|
.find(|v| v.is_village() && !matches!(v.role().title(), RoleTitle::Protector))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id();
|
||||||
.clone();
|
|
||||||
match game
|
match game
|
||||||
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
|
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
|
||||||
execution_target.clone(),
|
execution_target,
|
||||||
)))
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
|
@ -603,7 +599,7 @@ fn wolfpack_kill_all_targets_valid() {
|
||||||
let mut attempt = game.clone();
|
let mut attempt = game.clone();
|
||||||
if let ServerToHostMessage::Error(GameError::InvalidTarget) = attempt
|
if let ServerToHostMessage::Error(GameError::InvalidTarget) = attempt
|
||||||
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
|
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
|
||||||
ActionResponse::MarkTarget(target.character_id.clone()),
|
ActionResponse::MarkTarget(target.character_id),
|
||||||
)))
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,19 +13,19 @@ use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
|
||||||
#[test]
|
#[test]
|
||||||
fn elder_doesnt_die_first_try_night_doesnt_know() {
|
fn elder_doesnt_die_first_try_night_doesnt_know() {
|
||||||
let players = gen_players(1..10);
|
let players = gen_players(1..10);
|
||||||
let elder_player_id = players[0].player_id.clone();
|
let elder_player_id = players[0].player_id;
|
||||||
let wolf_player_id = players[2].player_id.clone();
|
let wolf_player_id = players[2].player_id;
|
||||||
let mut settings = GameSettings::empty();
|
let mut settings = GameSettings::empty();
|
||||||
settings.add_role(
|
settings.add_role(
|
||||||
SetupRole::Elder {
|
SetupRole::Elder {
|
||||||
knows_on_night: NonZeroU8::new(3).unwrap(),
|
knows_on_night: NonZeroU8::new(3).unwrap(),
|
||||||
},
|
},
|
||||||
|slot| {
|
|slot| {
|
||||||
slot.assign_to = Some(elder_player_id.clone());
|
slot.assign_to = Some(elder_player_id);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
settings.add_role(SetupRole::Werewolf, |slot| {
|
settings.add_role(SetupRole::Werewolf, |slot| {
|
||||||
slot.assign_to = Some(wolf_player_id.clone())
|
slot.assign_to = Some(wolf_player_id)
|
||||||
});
|
});
|
||||||
settings.fill_remaining_slots_with_villagers(players.len());
|
settings.fill_remaining_slots_with_villagers(players.len());
|
||||||
let mut game = Game::new(&players, settings).unwrap();
|
let mut game = Game::new(&players, settings).unwrap();
|
||||||
|
|
@ -62,8 +62,7 @@ fn elder_doesnt_die_first_try_night_doesnt_know() {
|
||||||
Some(DiedTo::Wolfpack {
|
Some(DiedTo::Wolfpack {
|
||||||
killing_wolf: game
|
killing_wolf: game
|
||||||
.character_by_player_id(wolf_player_id)
|
.character_by_player_id(wolf_player_id)
|
||||||
.character_id()
|
.character_id(),
|
||||||
.clone(),
|
|
||||||
night: NonZeroU8::new(2).unwrap(),
|
night: NonZeroU8::new(2).unwrap(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
@ -72,19 +71,19 @@ fn elder_doesnt_die_first_try_night_doesnt_know() {
|
||||||
#[test]
|
#[test]
|
||||||
fn elder_doesnt_die_first_try_night_knows() {
|
fn elder_doesnt_die_first_try_night_knows() {
|
||||||
let players = gen_players(1..10);
|
let players = gen_players(1..10);
|
||||||
let elder_player_id = players[0].player_id.clone();
|
let elder_player_id = players[0].player_id;
|
||||||
let wolf_player_id = players[2].player_id.clone();
|
let wolf_player_id = players[2].player_id;
|
||||||
let mut settings = GameSettings::empty();
|
let mut settings = GameSettings::empty();
|
||||||
settings.add_role(
|
settings.add_role(
|
||||||
SetupRole::Elder {
|
SetupRole::Elder {
|
||||||
knows_on_night: NonZeroU8::new(1).unwrap(),
|
knows_on_night: NonZeroU8::new(1).unwrap(),
|
||||||
},
|
},
|
||||||
|slot| {
|
|slot| {
|
||||||
slot.assign_to = Some(elder_player_id.clone());
|
slot.assign_to = Some(elder_player_id);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
settings.add_role(SetupRole::Werewolf, |slot| {
|
settings.add_role(SetupRole::Werewolf, |slot| {
|
||||||
slot.assign_to = Some(wolf_player_id.clone())
|
slot.assign_to = Some(wolf_player_id)
|
||||||
});
|
});
|
||||||
settings.fill_remaining_slots_with_villagers(players.len());
|
settings.fill_remaining_slots_with_villagers(players.len());
|
||||||
let mut game = Game::new(&players, settings).unwrap();
|
let mut game = Game::new(&players, settings).unwrap();
|
||||||
|
|
@ -145,12 +144,12 @@ fn elder_executed_doesnt_know() {
|
||||||
knows_on_night: NonZeroU8::new(3).unwrap(),
|
knows_on_night: NonZeroU8::new(3).unwrap(),
|
||||||
},
|
},
|
||||||
|slot| {
|
|slot| {
|
||||||
slot.assign_to = Some(elder_player_id.clone());
|
slot.assign_to = Some(elder_player_id);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
settings.add_and_assign(SetupRole::Seer, seer_player_id.clone());
|
settings.add_and_assign(SetupRole::Seer, seer_player_id);
|
||||||
settings.add_role(SetupRole::Werewolf, |slot| {
|
settings.add_role(SetupRole::Werewolf, |slot| {
|
||||||
slot.assign_to = Some(wolf_player_id.clone())
|
slot.assign_to = Some(wolf_player_id)
|
||||||
});
|
});
|
||||||
settings.fill_remaining_slots_with_villagers(players.len());
|
settings.fill_remaining_slots_with_villagers(players.len());
|
||||||
let mut game = Game::new(&players, settings).unwrap();
|
let mut game = Game::new(&players, settings).unwrap();
|
||||||
|
|
@ -214,12 +213,12 @@ fn elder_executed_knows_no_powers_incl_hunter_activation() {
|
||||||
knows_on_night: NonZeroU8::new(1).unwrap(),
|
knows_on_night: NonZeroU8::new(1).unwrap(),
|
||||||
},
|
},
|
||||||
|slot| {
|
|slot| {
|
||||||
slot.assign_to = Some(elder_player_id.clone());
|
slot.assign_to = Some(elder_player_id);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
settings.add_and_assign(SetupRole::Seer, seer_player_id.clone());
|
settings.add_and_assign(SetupRole::Seer, seer_player_id);
|
||||||
settings.add_role(SetupRole::Werewolf, |slot| {
|
settings.add_role(SetupRole::Werewolf, |slot| {
|
||||||
slot.assign_to = Some(wolf_player_id.clone())
|
slot.assign_to = Some(wolf_player_id)
|
||||||
});
|
});
|
||||||
settings.add_and_assign(SetupRole::Hunter, hunter_player_id);
|
settings.add_and_assign(SetupRole::Hunter, hunter_player_id);
|
||||||
settings.fill_remaining_slots_with_villagers(players.len());
|
settings.fill_remaining_slots_with_villagers(players.len());
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
|
||||||
#[test]
|
#[test]
|
||||||
fn redeemed_scapegoat_role_changes() {
|
fn redeemed_scapegoat_role_changes() {
|
||||||
let players = gen_players(1..10);
|
let players = gen_players(1..10);
|
||||||
let scapegoat_player_id = players[0].player_id.clone();
|
let scapegoat_player_id = players[0].player_id;
|
||||||
let seer_player_id = players[1].player_id.clone();
|
let seer_player_id = players[1].player_id;
|
||||||
let wolf_player_id = players[2].player_id.clone();
|
let wolf_player_id = players[2].player_id;
|
||||||
let wolf_target_2_player_id = players[3].player_id.clone();
|
let wolf_target_2_player_id = players[3].player_id;
|
||||||
let mut settings = GameSettings::default();
|
let mut settings = GameSettings::default();
|
||||||
{
|
{
|
||||||
let scapegoat_slot = settings.new_slot(RoleTitle::Scapegoat);
|
let scapegoat_slot = settings.new_slot(RoleTitle::Scapegoat);
|
||||||
|
|
@ -29,7 +29,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
scapegoat_slot.role = SetupRole::Scapegoat {
|
scapegoat_slot.role = SetupRole::Scapegoat {
|
||||||
redeemed: OrRandom::Determined(true),
|
redeemed: OrRandom::Determined(true),
|
||||||
};
|
};
|
||||||
scapegoat_slot.assign_to = Some(scapegoat_player_id.clone());
|
scapegoat_slot.assign_to = Some(scapegoat_player_id);
|
||||||
settings.update_slot(scapegoat_slot);
|
settings.update_slot(scapegoat_slot);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +39,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
.find(|s| matches!(s.role, SetupRole::Werewolf))
|
.find(|s| matches!(s.role, SetupRole::Werewolf))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.clone();
|
.clone();
|
||||||
slot.assign_to = Some(wolf_player_id.clone());
|
slot.assign_to = Some(wolf_player_id);
|
||||||
settings.update_slot(slot);
|
settings.update_slot(slot);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
@ -50,7 +50,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
.find(|s| s.slot_id == slot)
|
.find(|s| s.slot_id == slot)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.clone();
|
.clone();
|
||||||
slot.assign_to = Some(seer_player_id.clone());
|
slot.assign_to = Some(seer_player_id);
|
||||||
settings.update_slot(slot);
|
settings.update_slot(slot);
|
||||||
}
|
}
|
||||||
for _ in 0..6 {
|
for _ in 0..6 {
|
||||||
|
|
@ -67,8 +67,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|c| c.player_id() == wolf_player_id)
|
.find(|c| c.player_id() == wolf_player_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id();
|
||||||
.clone();
|
|
||||||
game.mark_and_check(wolf_char_id);
|
game.mark_and_check(wolf_char_id);
|
||||||
assert_eq!(game.r#continue().seer(), Alignment::Wolves);
|
assert_eq!(game.r#continue().seer(), Alignment::Wolves);
|
||||||
game.next_expect_day();
|
game.next_expect_day();
|
||||||
|
|
@ -82,8 +81,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|c| c.player_id() == seer_player_id)
|
.find(|c| c.player_id() == seer_player_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id();
|
||||||
.clone();
|
|
||||||
|
|
||||||
game.mark_and_check(seer);
|
game.mark_and_check(seer);
|
||||||
game.r#continue().sleep();
|
game.r#continue().sleep();
|
||||||
|
|
@ -101,7 +99,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
.died_to()
|
.died_to()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
DiedTo::Wolfpack {
|
DiedTo::Wolfpack {
|
||||||
killing_wolf: wolf_char_id.clone(),
|
killing_wolf: wolf_char_id,
|
||||||
night: NonZero::new(1).unwrap()
|
night: NonZero::new(1).unwrap()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -115,8 +113,7 @@ fn redeemed_scapegoat_role_changes() {
|
||||||
.iter()
|
.iter()
|
||||||
.find(|c| c.player_id() == wolf_target_2_player_id)
|
.find(|c| c.player_id() == wolf_target_2_player_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id();
|
||||||
.clone();
|
|
||||||
game.mark_and_check(wolf_target_2);
|
game.mark_and_check(wolf_target_2);
|
||||||
game.r#continue().sleep();
|
game.r#continue().sleep();
|
||||||
let scapegoat = game
|
let scapegoat = game
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,10 @@ fn protect_stops_shapeshift() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|v| v.is_village() && !matches!(v.role().title(), RoleTitle::Protector))
|
.find(|v| v.is_village() && !matches!(v.role().title(), RoleTitle::Protector))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id();
|
||||||
.clone();
|
|
||||||
match game
|
match game
|
||||||
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
|
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
|
||||||
execution_target.clone(),
|
execution_target,
|
||||||
)))
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
|
@ -104,8 +103,7 @@ fn protect_stops_shapeshift() {
|
||||||
.map(|c| game.village().character_by_id(c.character_id).unwrap())
|
.map(|c| game.village().character_by_id(c.character_id).unwrap())
|
||||||
.find(|c| c.is_village())
|
.find(|c| c.is_village())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.character_id()
|
.character_id(),
|
||||||
.clone(),
|
|
||||||
prot_char_id,
|
prot_char_id,
|
||||||
),
|
),
|
||||||
_ => panic!("first n2 prompt isn't protector"),
|
_ => panic!("first n2 prompt isn't protector"),
|
||||||
|
|
@ -119,7 +117,7 @@ fn protect_stops_shapeshift() {
|
||||||
|
|
||||||
match game
|
match game
|
||||||
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
|
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
|
||||||
ActionResponse::MarkTarget(prot_and_wolf_target.clone()),
|
ActionResponse::MarkTarget(prot_and_wolf_target),
|
||||||
)))
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
|
@ -183,9 +181,9 @@ fn only_1_shapeshift_prompt_if_first_shifts() {
|
||||||
.village()
|
.village()
|
||||||
.characters()
|
.characters()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|c| c.is_village().then_some(c.character_id().clone()))
|
.find_map(|c| c.is_village().then_some(c.character_id()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (_, marked, _) = game.mark_for_execution(target.clone());
|
let (_, marked, _) = game.mark_for_execution(target);
|
||||||
let (marked, target_list): (&[CharacterId], &[CharacterId]) = (&marked, &[target]);
|
let (marked, target_list): (&[CharacterId], &[CharacterId]) = (&marked, &[target]);
|
||||||
assert_eq!(target_list, marked);
|
assert_eq!(target_list, marked);
|
||||||
assert_eq!(game.execute().title(), ActionPromptTitle::CoverOfDarkness);
|
assert_eq!(game.execute().title(), ActionPromptTitle::CoverOfDarkness);
|
||||||
|
|
@ -195,7 +193,7 @@ fn only_1_shapeshift_prompt_if_first_shifts() {
|
||||||
.village()
|
.village()
|
||||||
.characters()
|
.characters()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|c| (c.is_village() && c.alive()).then_some(c.character_id().clone()))
|
.find_map(|c| (c.is_village() && c.alive()).then_some(c.character_id()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
game.mark_and_check(target);
|
game.mark_and_check(target);
|
||||||
|
|
|
||||||
|
|
@ -177,17 +177,17 @@ impl ActionPrompt {
|
||||||
if *m == mark {
|
if *m == mark {
|
||||||
*marked = (None, None);
|
*marked = (None, None);
|
||||||
} else {
|
} else {
|
||||||
*marked = (Some(m.clone()), Some(mark));
|
*marked = (Some(*m), Some(mark));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, None) => *marked = (Some(mark), None),
|
(None, None) => *marked = (Some(mark), None),
|
||||||
(Some(m1), Some(m2)) => {
|
(Some(m1), Some(m2)) => {
|
||||||
if *m1 == mark {
|
if *m1 == mark {
|
||||||
*marked = (Some(m2.clone()), None);
|
*marked = (Some(*m2), None);
|
||||||
} else if *m2 == mark {
|
} else if *m2 == mark {
|
||||||
*marked = (Some(m1.clone()), None);
|
*marked = (Some(*m1), None);
|
||||||
} else {
|
} else {
|
||||||
*marked = (Some(m2.clone()), Some(mark));
|
*marked = (Some(*m2), Some(mark));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use crate::{
|
use crate::{
|
||||||
diedto::DiedTo,
|
diedto::DiedTo,
|
||||||
error::GameError,
|
error::GameError,
|
||||||
game::{DateTime, SetupSlot, Village},
|
game::{DateTime, Village},
|
||||||
message::{CharacterIdentity, Identification, PublicIdentity, night::ActionPrompt},
|
message::{CharacterIdentity, Identification, PublicIdentity, night::ActionPrompt},
|
||||||
modifier::Modifier,
|
modifier::Modifier,
|
||||||
role::{Alignment, MAPLE_WOLF_ABSTAIN_LIMIT, PreviousGuardianAction, Role, RoleTitle},
|
role::{Alignment, MAPLE_WOLF_ABSTAIN_LIMIT, PreviousGuardianAction, Role, RoleTitle},
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,12 @@ pub async fn handler(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// log::debug!("connected {who} as {ident}");
|
// log::debug!("connected {who} as {ident}");
|
||||||
let connection_id = ConnectionId::new(ident.player_id.clone());
|
let connection_id = ConnectionId::new(ident.player_id);
|
||||||
let recv = {
|
let recv = {
|
||||||
let (send, recv) = tokio::sync::broadcast::channel(100);
|
let (send, recv) = tokio::sync::broadcast::channel(100);
|
||||||
player_list
|
player_list
|
||||||
.insert_or_replace(
|
.insert_or_replace(
|
||||||
ident.player_id.clone(),
|
ident.player_id,
|
||||||
JoinedPlayer::new(
|
JoinedPlayer::new(
|
||||||
send,
|
send,
|
||||||
recv,
|
recv,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use tokio::sync::broadcast::Receiver;
|
use werewolves_proto::error::GameError;
|
||||||
use werewolves_proto::{error::GameError, player::PlayerId};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
communication::{Comms, connect::ConnectUpdate},
|
communication::{Comms, connect::ConnectUpdate},
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ impl JoinedPlayers {
|
||||||
self.players.lock().await;
|
self.players.lock().await;
|
||||||
let senders = players
|
let senders = players
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(pid, p)| (pid.clone(), p.sender.clone()))
|
.map(|(pid, p)| (*pid, p.sender.clone()))
|
||||||
.collect::<Box<[_]>>();
|
.collect::<Box<[_]>>();
|
||||||
core::mem::drop(players);
|
core::mem::drop(players);
|
||||||
for (pid, send) in senders {
|
for (pid, send) in senders {
|
||||||
|
|
@ -126,7 +126,7 @@ impl JoinedPlayers {
|
||||||
pub async fn disconnect(&self, connection: &ConnectionId) -> Option<JoinedPlayer> {
|
pub async fn disconnect(&self, connection: &ConnectionId) -> Option<JoinedPlayer> {
|
||||||
let mut map = self.players.lock().await;
|
let mut map = self.players.lock().await;
|
||||||
|
|
||||||
self.connect_state.disconnect(connection.0.clone()).await;
|
self.connect_state.disconnect(connection.0).await;
|
||||||
|
|
||||||
if map
|
if map
|
||||||
.get(connection.player_id())
|
.get(connection.player_id())
|
||||||
|
|
@ -154,13 +154,13 @@ impl JoinedPlayers {
|
||||||
) -> Receiver<ServerMessage> {
|
) -> Receiver<ServerMessage> {
|
||||||
let mut map = self.players.lock().await;
|
let mut map = self.players.lock().await;
|
||||||
|
|
||||||
if let Some(old) = map.insert(player_id.clone(), player) {
|
if let Some(old) = map.insert(player_id, player) {
|
||||||
let old_map_entry = unsafe { map.get_mut(&player_id).unwrap_unchecked() };
|
let old_map_entry = unsafe { map.get_mut(&player_id).unwrap_unchecked() };
|
||||||
old_map_entry.receiver = old.resubscribe_reciever();
|
old_map_entry.receiver = old.resubscribe_reciever();
|
||||||
|
|
||||||
old.receiver
|
old.receiver
|
||||||
} else {
|
} else {
|
||||||
self.connect_state.connect(player_id.clone()).await;
|
self.connect_state.connect(player_id).await;
|
||||||
|
|
||||||
unsafe { map.get(&player_id).unwrap_unchecked() }
|
unsafe { map.get(&player_id).unwrap_unchecked() }
|
||||||
.receiver
|
.receiver
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ impl Lobby {
|
||||||
&self
|
&self
|
||||||
.players_in_lobby
|
.players_in_lobby
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, _)| id.player_id.clone())
|
.map(|(id, _)| id.player_id)
|
||||||
.collect::<Box<[_]>>(),
|
.collect::<Box<[_]>>(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl Connection2 {
|
||||||
}
|
}
|
||||||
fn identification(&self) -> Identification {
|
fn identification(&self) -> Identification {
|
||||||
Identification {
|
Identification {
|
||||||
player_id: self.ident.0.clone(),
|
player_id: self.ident.0,
|
||||||
public: self.ident.1.clone(),
|
public: self.ident.1.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use core::{num::NonZeroU8, ops::Not, time::Duration};
|
use core::{num::NonZeroU8, ops::Not, time::Duration};
|
||||||
use std::{rc::Rc, sync::Arc};
|
use std::rc::Rc;
|
||||||
|
|
||||||
use futures::{
|
use futures::{
|
||||||
SinkExt, StreamExt,
|
SinkExt, StreamExt,
|
||||||
|
|
@ -12,7 +12,7 @@ use werewolves_proto::{
|
||||||
error::GameError,
|
error::GameError,
|
||||||
game::{GameOver, GameSettings},
|
game::{GameOver, GameSettings},
|
||||||
message::{
|
message::{
|
||||||
CharacterIdentity, CharacterState, PlayerState, PublicIdentity,
|
CharacterIdentity, CharacterState, PlayerState,
|
||||||
host::{
|
host::{
|
||||||
HostDayMessage, HostGameMessage, HostLobbyMessage, HostMessage, HostNightMessage,
|
HostDayMessage, HostGameMessage, HostLobbyMessage, HostMessage, HostNightMessage,
|
||||||
ServerToHostMessage,
|
ServerToHostMessage,
|
||||||
|
|
@ -412,7 +412,7 @@ impl Component for Host {
|
||||||
yew::platform::spawn_local(async move {
|
yew::platform::spawn_local(async move {
|
||||||
if let Err(err) = send
|
if let Err(err) = send
|
||||||
.clone()
|
.clone()
|
||||||
.send(HostMessage::ForceRoleAckFor(target.character_id.clone()))
|
.send(HostMessage::ForceRoleAckFor(target.character_id))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
log::error!("force role ack for [{target}]: {err}");
|
log::error!("force role ack for [{target}]: {err}");
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,10 @@ pub fn TargetCard(
|
||||||
mark_callback,
|
mark_callback,
|
||||||
}: &TargetCardProps,
|
}: &TargetCardProps,
|
||||||
) -> Html {
|
) -> Html {
|
||||||
let click_target = target.character_id.clone();
|
let click_target = target.character_id;
|
||||||
let on_click = mark_callback
|
let on_click = mark_callback
|
||||||
.clone()
|
.clone()
|
||||||
.map(|cb| Callback::from(move |_| cb.emit(click_target.clone())))
|
.map(|cb| Callback::from(move |_| cb.emit(click_target)))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let marked = marked.then_some("marked");
|
let marked = marked.then_some("marked");
|
||||||
let ident: PublicIdentity = target.into();
|
let ident: PublicIdentity = target.into();
|
||||||
|
|
|
||||||
|
|
@ -174,10 +174,7 @@ pub fn Prompt(props: &ActionPromptProps) -> Html {
|
||||||
} => (
|
} => (
|
||||||
Some(character_id),
|
Some(character_id),
|
||||||
living_players,
|
living_players,
|
||||||
[&marked.0, &marked.1]
|
[&marked.0, &marked.1].iter().filter_map(|c| **c).collect(),
|
||||||
.iter()
|
|
||||||
.filter_map(|c| (*c).clone())
|
|
||||||
.collect(),
|
|
||||||
html! {{"arcanist"}},
|
html! {{"arcanist"}},
|
||||||
),
|
),
|
||||||
ActionPrompt::Gravedigger {
|
ActionPrompt::Gravedigger {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use core::{fmt::Debug, ops::Not};
|
use core::{fmt::Debug, ops::Not};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use werewolves_macros::ChecksAs;
|
|
||||||
use werewolves_proto::{
|
use werewolves_proto::{
|
||||||
message::{CharacterIdentity, PublicIdentity},
|
message::{CharacterIdentity, PublicIdentity},
|
||||||
player::CharacterId,
|
player::CharacterId,
|
||||||
|
|
@ -82,12 +80,12 @@ impl Component for TwoTarget {
|
||||||
let submit = target_selection.as_ref().map(|target_selection| {
|
let submit = target_selection.as_ref().map(|target_selection| {
|
||||||
let selected = match &self.0 {
|
let selected = match &self.0 {
|
||||||
TwoTargetSelection::None | TwoTargetSelection::One(_) => None,
|
TwoTargetSelection::None | TwoTargetSelection::One(_) => None,
|
||||||
TwoTargetSelection::Two(t1, t2) => Some((t1.clone(), t2.clone())),
|
TwoTargetSelection::Two(t1, t2) => Some((*t1, *t2)),
|
||||||
};
|
};
|
||||||
let target_selection = target_selection.clone();
|
let target_selection = target_selection.clone();
|
||||||
let disabled = selected.is_none();
|
let disabled = selected.is_none();
|
||||||
let on_click =
|
let on_click =
|
||||||
selected.map(|(t1, t2)| move |_| target_selection.emit((t1.clone(), t2.clone())));
|
selected.map(|(t1, t2)| move |_| target_selection.emit((t1, t2)));
|
||||||
html! {
|
html! {
|
||||||
<div class="button-container sp-ace">
|
<div class="button-container sp-ace">
|
||||||
<button
|
<button
|
||||||
|
|
@ -118,16 +116,16 @@ impl Component for TwoTarget {
|
||||||
if character_id == &msg {
|
if character_id == &msg {
|
||||||
self.0 = TwoTargetSelection::None
|
self.0 = TwoTargetSelection::None
|
||||||
} else {
|
} else {
|
||||||
self.0 = TwoTargetSelection::Two(character_id.clone(), msg)
|
self.0 = TwoTargetSelection::Two(*character_id, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TwoTargetSelection::Two(t1, t2) => {
|
TwoTargetSelection::Two(t1, t2) => {
|
||||||
if &msg == t1 {
|
if &msg == t1 {
|
||||||
self.0 = TwoTargetSelection::One(t2.clone());
|
self.0 = TwoTargetSelection::One(*t2);
|
||||||
} else if &msg == t2 {
|
} else if &msg == t2 {
|
||||||
self.0 = TwoTargetSelection::One(t1.clone());
|
self.0 = TwoTargetSelection::One(*t1);
|
||||||
} else {
|
} else {
|
||||||
self.0 = TwoTargetSelection::Two(t1.clone(), msg);
|
self.0 = TwoTargetSelection::Two(*t1, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -193,8 +191,8 @@ impl Component for OptionalSingleTarget {
|
||||||
|
|
||||||
let submit = target_selection.as_ref().map(|target_selection| {
|
let submit = target_selection.as_ref().map(|target_selection| {
|
||||||
let target_selection = target_selection.clone();
|
let target_selection = target_selection.clone();
|
||||||
let sel = self.0.clone();
|
let sel = self.0;
|
||||||
let on_click = move |_| target_selection.emit(sel.clone());
|
let on_click = move |_| target_selection.emit(sel);
|
||||||
html! {
|
html! {
|
||||||
<div class="button-container sp-ace">
|
<div class="button-container sp-ace">
|
||||||
<button
|
<button
|
||||||
|
|
@ -294,8 +292,7 @@ impl Component for SingleTarget {
|
||||||
let target_selection = target_selection.clone();
|
let target_selection = target_selection.clone();
|
||||||
let on_click = self
|
let on_click = self
|
||||||
.selected
|
.selected
|
||||||
.clone()
|
.map(|t| Callback::from(move |_| target_selection.emit(t)))
|
||||||
.map(|t| Callback::from(move |_| target_selection.emit(t.clone())))
|
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
html! {
|
html! {
|
||||||
<div class="button-container sp-ace">
|
<div class="button-container sp-ace">
|
||||||
|
|
@ -342,9 +339,9 @@ pub struct TargetCardProps {
|
||||||
|
|
||||||
#[function_component]
|
#[function_component]
|
||||||
fn TargetCard(props: &TargetCardProps) -> Html {
|
fn TargetCard(props: &TargetCardProps) -> Html {
|
||||||
let character_id = props.target.character_id.clone();
|
let character_id = props.target.character_id;
|
||||||
let on_select = props.on_select.clone();
|
let on_select = props.on_select.clone();
|
||||||
let on_click = Callback::from(move |_| on_select.emit(character_id.clone()));
|
let on_click = Callback::from(move |_| on_select.emit(character_id));
|
||||||
|
|
||||||
let marked = props.selected.then_some("marked");
|
let marked = props.selected.then_some("marked");
|
||||||
let ident: PublicIdentity = props.target.clone().into();
|
let ident: PublicIdentity = props.target.clone().into();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use werewolves_proto::{
|
||||||
};
|
};
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
use crate::components::{Button, ClickableField, Identity};
|
use crate::components::{Button, Identity};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Properties)]
|
#[derive(Debug, Clone, PartialEq, Properties)]
|
||||||
pub struct DaytimePlayerListProps {
|
pub struct DaytimePlayerListProps {
|
||||||
|
|
@ -90,14 +90,14 @@ pub fn DaytimePlayer(
|
||||||
) -> Html {
|
) -> Html {
|
||||||
let dead = died_to.is_some().then_some("dead");
|
let dead = died_to.is_some().then_some("dead");
|
||||||
let marked = on_the_block.then_some("marked");
|
let marked = on_the_block.then_some("marked");
|
||||||
let character_id = identity.character_id.clone();
|
let character_id = identity.character_id;
|
||||||
let on_click: Callback<_> = died_to
|
let on_click: Callback<_> = died_to
|
||||||
.is_none()
|
.is_none()
|
||||||
.then_some(())
|
.then_some(())
|
||||||
.and(
|
.and(
|
||||||
on_select
|
on_select
|
||||||
.clone()
|
.clone()
|
||||||
.map(|on_select| Callback::from(move |_| on_select.emit(character_id.clone()))),
|
.map(|on_select| Callback::from(move |_| on_select.emit(character_id))),
|
||||||
)
|
)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let identity: PublicIdentity = identity.into();
|
let identity: PublicIdentity = identity.into();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
use core::ops::Deref;
|
|
||||||
use werewolves_proto::message::PublicIdentity;
|
use werewolves_proto::message::PublicIdentity;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use core::num::NonZeroU8;
|
use core::num::NonZeroU8;
|
||||||
|
|
||||||
use web_sys::{HtmlDivElement, HtmlElement};
|
|
||||||
use werewolves_proto::{message::PlayerState, player::PlayerId};
|
use werewolves_proto::{message::PlayerState, player::PlayerId};
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
|
|
@ -23,16 +22,15 @@ pub enum LobbyPlayerAction {
|
||||||
pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) -> Html {
|
pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) -> Html {
|
||||||
let open = use_state(|| false);
|
let open = use_state(|| false);
|
||||||
let class = player.connected.then_some("connected");
|
let class = player.connected.then_some("connected");
|
||||||
let pid = player.identification.player_id.clone();
|
let pid = player.identification.player_id;
|
||||||
let action_open = open.clone();
|
let action_open = open.clone();
|
||||||
let action = |action: LobbyPlayerAction| {
|
let action = |action: LobbyPlayerAction| {
|
||||||
let pid = pid.clone();
|
|
||||||
on_action
|
on_action
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|on_action| {
|
.map(|on_action| {
|
||||||
Callback::from(move |_| {
|
Callback::from(move |_| {
|
||||||
on_action.emit((pid.clone(), action));
|
on_action.emit((pid, action));
|
||||||
action_open.set(false);
|
action_open.set(false);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -42,7 +40,7 @@ pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) ->
|
||||||
let number_open = use_state(|| false);
|
let number_open = use_state(|| false);
|
||||||
let submenu_open = open.clone();
|
let submenu_open = open.clone();
|
||||||
let submenu = on_action.clone().map(|on_action| {
|
let submenu = on_action.clone().map(|on_action| {
|
||||||
let pid = player.identification.player_id.clone();
|
let pid = player.identification.player_id;
|
||||||
let number_submit = number.clone();
|
let number_submit = number.clone();
|
||||||
let open = submenu_open.clone();
|
let open = submenu_open.clone();
|
||||||
let on_number_submit = Callback::from(move |_| {
|
let on_number_submit = Callback::from(move |_| {
|
||||||
|
|
@ -50,7 +48,7 @@ pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) ->
|
||||||
Ok(num) => num,
|
Ok(num) => num,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
on_action.emit((pid.clone(), LobbyPlayerAction::SetNumber(number)));
|
on_action.emit((pid, LobbyPlayerAction::SetNumber(number)));
|
||||||
open.set(false);
|
open.set(false);
|
||||||
});
|
});
|
||||||
html! {
|
html! {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use core::{num::NonZeroU8, ops::Not};
|
use core::{num::NonZeroU8, ops::Not};
|
||||||
use std::{collections::HashMap, rc::Rc};
|
use std::rc::Rc;
|
||||||
|
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use web_sys::HtmlInputElement;
|
|
||||||
use werewolves_proto::{
|
use werewolves_proto::{
|
||||||
error::GameError,
|
error::GameError,
|
||||||
game::{GameSettings, OrRandom, SetupRole, SetupSlot, SlotId},
|
game::{GameSettings, OrRandom, SetupRole, SetupSlot, SlotId},
|
||||||
|
|
@ -53,7 +52,7 @@ pub fn Settings(
|
||||||
let already_assigned_pids = settings
|
let already_assigned_pids = settings
|
||||||
.slots()
|
.slots()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|r| r.assign_to.clone())
|
.filter_map(|r| r.assign_to)
|
||||||
.collect::<Box<[_]>>();
|
.collect::<Box<[_]>>();
|
||||||
let players_for_assign = players
|
let players_for_assign = players
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -321,11 +320,11 @@ fn assign_to_submenu(
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
let slot = slot.clone();
|
let slot = slot.clone();
|
||||||
let update = update.clone();
|
let update = update.clone();
|
||||||
let pid = p.player_id.clone();
|
let pid = p.player_id;
|
||||||
let setter = assign_setter.clone();
|
let setter = assign_setter.clone();
|
||||||
let on_click = Callback::from(move |_| {
|
let on_click = Callback::from(move |_| {
|
||||||
let mut slot = slot.clone();
|
let mut slot = slot.clone();
|
||||||
slot.assign_to.replace(pid.clone());
|
slot.assign_to.replace(pid);
|
||||||
update.emit(SettingSlotAction::Update(slot));
|
update.emit(SettingSlotAction::Update(slot));
|
||||||
setter.set(false);
|
setter.set(false);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue