cargo fix && cargo clippy fix

This commit is contained in:
emilis 2025-10-05 10:54:47 +01:00
parent 88665302f6
commit c0838c276c
No known key found for this signature in database
27 changed files with 156 additions and 206 deletions

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use convert_case::{Case, Casing};
use quote::{ToTokens, quote, quote_spanned};
use syn::{parenthesized, parse::Parse, spanned::Spanned};
use syn::{parse::Parse, spanned::Spanned};
use crate::hashlist::HashList;
@ -14,22 +14,6 @@ pub struct ChecksAs {
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)]
enum ChecksAsArg {
AsSelf(proc_macro2::Span),
@ -76,6 +60,7 @@ impl ChecksAsArg {
}
}
#[allow(unused)]
fn with_span(&self, span: proc_macro2::Span) -> Self {
match self {
ChecksAsArg::AsSelf(_) => ChecksAsArg::AsSelf(span),

View File

@ -162,11 +162,10 @@ where
}
continue;
}
if let Some(file_name) = item.file_name().to_str() {
if include_in_rerun(file_name) {
if let Some(file_name) = item.file_name().to_str()
&& include_in_rerun(file_name) {
out.push(FileWithPath::from_path(item.path(), origin_path)?);
}
}
}
Ok(())

View File

@ -1,5 +1,3 @@
use std::collections::HashMap;
use convert_case::{Case, Casing};
use proc_macro2::TokenStream;
use quote::{ToTokens, quote, quote_spanned};
@ -16,15 +14,6 @@ enum VariantFieldIndex {
None,
}
impl VariantFieldIndex {
const fn is_numeric(&self) -> bool {
match self {
Self::Numeric(_) => true,
_ => false,
}
}
}
impl syn::parse::Parse for VariantFieldIndex {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
if input.is_empty() {
@ -116,7 +105,7 @@ impl Targets {
let matching = field
.ident
.as_ref()
.map(|i| i.to_string() == ident.to_string())
.map(|i| i == ident)
.unwrap_or_default();
if matching_val.is_some() && matching {
panic!("duplicate?")

View File

@ -47,7 +47,7 @@ impl KillOutcome {
.ok_or(GameError::InvalidTarget)?
.kill(DiedTo::GuardianProtecting {
night,
source: guardian.clone(),
source: guardian,
protecting: original_target,
protecting_from: original_killer,
protecting_from_cause: Box::new(original_kill.clone()),
@ -75,8 +75,8 @@ fn resolve_protection(
guarding: true,
} => Some(KillOutcome::Guarding {
original_killer: killer,
guardian: source.clone(),
original_target: target.clone(),
guardian: *source,
original_target: *target,
original_kill: killed_with.clone(),
night,
}),
@ -103,8 +103,8 @@ pub fn resolve_kill(
&& let Some(protection) = changes.protected_take(target)
{
return Ok(Some(
resolve_protection(source.clone(), died_to, target, &protection, *night).unwrap_or(
KillOutcome::Single(source.clone(), DiedTo::MapleWolfStarved { night: *night }),
resolve_protection(*source, died_to, target, &protection, *night).unwrap_or(
KillOutcome::Single(*source, DiedTo::MapleWolfStarved { night: *night }),
),
));
}
@ -121,7 +121,7 @@ pub fn resolve_kill(
match changes.protected_take(target) {
Some(protection) => {
return Ok(resolve_protection(
killing_wolf.character_id().clone(),
killing_wolf.character_id(),
died_to,
target,
&protection,
@ -131,9 +131,9 @@ pub fn resolve_kill(
None => {
// Wolf kill went through -- can kill shifter
return Ok(Some(KillOutcome::Single(
ss_source.clone(),
*ss_source,
DiedTo::Shapeshift {
into: target.clone(),
into: *target,
night: *night,
},
)));
@ -143,7 +143,7 @@ pub fn resolve_kill(
let protection = match changes.protected_take(target) {
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 {
@ -151,13 +151,12 @@ pub fn resolve_kill(
source,
guarding: true,
} => Ok(Some(KillOutcome::Guarding {
original_killer: died_to
original_killer: *died_to
.killer()
.ok_or(GameError::GuardianInvalidOriginalKill)?
.clone(),
original_target: target.clone(),
.ok_or(GameError::GuardianInvalidOriginalKill)?,
original_target: *target,
original_kill: died_to.clone(),
guardian: source.clone(),
guardian: source,
night: NonZeroU8::new(night).unwrap(),
})),
Protection::Guardian {

View File

@ -96,7 +96,7 @@ impl Game {
.characters()
.into_iter()
.map(|c| CharacterState {
player_id: c.player_id().clone(),
player_id: c.player_id(),
identity: c.identity(),
role: c.role().title(),
died_to: c.died_to().cloned(),

View File

@ -1,4 +1,4 @@
use core::{num::NonZeroU8, ops::Not};
use core::num::NonZeroU8;
use std::collections::VecDeque;
use serde::{Deserialize, Serialize};
@ -178,7 +178,7 @@ impl Night {
.into_iter()
.filter_map(|c| c.died_to().map(|d| (c, d)))
.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,
})
.filter_map(|(c, t, d)| match d.date_time() {
@ -189,7 +189,7 @@ impl Night {
target,
died_to: DiedTo::Hunter {
night,
killer: c.character_id().clone(),
killer: c.character_id(),
},
})
.for_each(|c| changes.push(c));
@ -258,7 +258,7 @@ impl Night {
if let Role::Hunter { target: t } =
new_village.character_by_id_mut(*source).unwrap().role_mut()
{
t.replace(target.clone());
t.replace(*target);
}
if changes.killed(source).is_some()
&& changes.protected(source).is_none()
@ -268,7 +268,7 @@ impl Night {
.character_by_id_mut(*target)
.unwrap()
.kill(DiedTo::Hunter {
killer: source.clone(),
killer: *source,
night: NonZeroU8::new(self.night).unwrap(),
})
}
@ -291,12 +291,12 @@ impl Night {
let ss = new_village.character_by_id_mut(*source).unwrap();
match ss.role_mut() {
Role::Shapeshifter { shifted_into } => {
*shifted_into = Some(target.clone())
*shifted_into = Some(*target)
}
_ => unreachable!(),
}
ss.kill(DiedTo::Shapeshift {
into: target.clone(),
into: *target,
night: NonZeroU8::new(self.night).unwrap(),
});
// role change pushed in [apply_shapeshift]
@ -328,7 +328,7 @@ impl Night {
night: _,
killing_wolf: _,
},
} => Some(target.clone()),
} => Some(*target),
_ => None,
}) {
if self.changes.iter().any(|c| match c {
@ -355,15 +355,15 @@ impl Night {
)
}) {
self.changes.push(NightChange::Kill {
target: source.clone(),
target: *source,
died_to: DiedTo::Shapeshift {
into: kill_target.clone(),
into: kill_target,
night: NonZeroU8::new(self.night).unwrap(),
},
});
}
self.changes.push(NightChange::Shapeshift {
source: source.clone(),
source: *source,
});
self.action_queue.push_front(ActionPrompt::RoleChange {
new_role: RoleTitle::Werewolf,
@ -584,7 +584,7 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Shapeshift {
source: source.character_id.clone(),
source: source.character_id,
}),
unless: None,
})),
@ -600,7 +600,7 @@ impl Night {
return Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::RoleChange(
character_id.character_id.clone(),
character_id.character_id,
*new_role,
)),
unless: None,
@ -623,7 +623,7 @@ impl Night {
Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::ElderReveal {
elder: character_id.character_id.clone(),
elder: character_id.character_id,
}),
unless: None,
}))
@ -640,7 +640,7 @@ impl Night {
Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::Seer(alignment),
change: None,
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
}))
}
ActionPrompt::Protector {
@ -650,12 +650,12 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Protection {
target: marked.clone(),
target: *marked,
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 {
marked: (Some(marked1), Some(marked2)),
@ -675,7 +675,7 @@ impl Night {
Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::Arcanist { same },
change: None,
unless: Some(Unless::TargetsBlocked(marked1.clone(), marked2.clone())),
unless: Some(Unless::TargetsBlocked(*marked1, *marked2)),
}))
}
ActionPrompt::Gravedigger {
@ -690,7 +690,7 @@ impl Night {
Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GraveDigger(dig_role),
change: None,
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
}))
}
ActionPrompt::Hunter {
@ -700,10 +700,10 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::HunterTarget {
source: character_id.character_id.clone(),
target: marked.clone(),
source: character_id.character_id,
target: *marked,
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::Militia {
character_id,
@ -712,14 +712,14 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Kill {
target: marked.clone(),
target: *marked,
died_to: DiedTo::Militia {
killer: character_id.character_id.clone(),
killer: character_id.character_id,
night: NonZeroU8::new(self.night)
.ok_or(GameError::InvalidMessageForGameState)?,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::Militia { marked: None, .. } => {
Ok(ResponseOutcome::ActionComplete(Default::default()))
@ -732,15 +732,15 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Kill {
target: marked.clone(),
target: *marked,
died_to: DiedTo::MapleWolf {
source: character_id.character_id.clone(),
source: character_id.character_id,
night: NonZeroU8::new(self.night)
.ok_or(GameError::InvalidMessageForGameState)?,
starves_if_fails: *kill_or_die,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::MapleWolf { marked: None, .. } => {
Ok(ResponseOutcome::ActionComplete(Default::default()))
@ -753,13 +753,13 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Protection {
target: marked.clone(),
target: *marked,
protection: Protection::Guardian {
source: character_id.character_id.clone(),
source: character_id.character_id,
guarding: false,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::Guardian {
character_id,
@ -773,13 +773,13 @@ impl Night {
Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Protection {
target: marked.clone(),
target: *marked,
protection: Protection::Guardian {
source: character_id.character_id.clone(),
source: character_id.character_id,
guarding: false,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
}))
}
ActionPrompt::Guardian {
@ -790,13 +790,13 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Protection {
target: marked.clone(),
target: *marked,
protection: Protection::Guardian {
source: character_id.character_id.clone(),
source: character_id.character_id,
guarding: prev_protect.character_id == *marked,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::WolfPackKill {
marked: Some(marked),
@ -804,25 +804,24 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Kill {
target: marked.clone(),
target: *marked,
died_to: DiedTo::Wolfpack {
killing_wolf: self
.village
.killing_wolf()
.ok_or(GameError::NoWolves)?
.character_id()
.clone(),
.character_id(),
night: NonZeroU8::new(self.night)
.ok_or(GameError::InvalidMessageForGameState)?,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::Shapeshifter { character_id } => {
Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Shapeshift {
source: character_id.character_id.clone(),
source: character_id.character_id,
}),
unless: None,
}))
@ -834,14 +833,14 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::Kill {
target: marked.clone(),
target: *marked,
died_to: DiedTo::AlphaWolf {
killer: character_id.character_id.clone(),
killer: character_id.character_id,
night: NonZeroU8::new(self.night)
.ok_or(GameError::InvalidMessageForGameState)?,
},
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::AlphaWolf { marked: None, .. } => {
Ok(ResponseOutcome::ActionComplete(Default::default()))
@ -853,11 +852,11 @@ impl Night {
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
result: ActionResult::GoBackToSleep,
change: Some(NightChange::RoleBlock {
source: character_id.character_id.clone(),
target: marked.clone(),
source: character_id.character_id,
target: *marked,
block_type: RoleBlock::Direwolf,
}),
unless: Some(Unless::TargetBlocked(marked.clone())),
unless: Some(Unless::TargetBlocked(*marked)),
})),
ActionPrompt::Protector { marked: None, .. }

View File

@ -123,7 +123,7 @@ impl GameSettings {
players
.iter()
.find(|pid| pid.player_id == *assign_to)
.ok_or(GameError::AssignedPlayerMissing(assign_to.clone()))
.ok_or(GameError::AssignedPlayerMissing(*assign_to))
.map(|id| (id, s))
})
})
@ -170,7 +170,7 @@ impl GameSettings {
if let Some(assigned) = role.assign_to.as_ref()
&& !players.iter().any(|p| p.player_id == *assigned)
{
return Err(GameError::AssignedPlayerMissing(assigned.clone()));
return Err(GameError::AssignedPlayerMissing(*assigned));
}
}

View File

@ -145,13 +145,13 @@ impl Village {
pub fn killing_wolf_id(&self) -> CharacterId {
let wolves = self.living_wolf_pack_players();
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| {
w.role().wolf() && !matches!(w.role(), Role::Shapeshifter { shifted_into: _ })
}) {
non_ss_wolf.character_id().clone()
non_ss_wolf.character_id()
} else {
wolves.into_iter().next().unwrap().character_id().clone()
wolves.into_iter().next().unwrap().character_id()
}
}

View File

@ -2,9 +2,8 @@ mod night_order;
mod role;
use crate::{
diedto::DiedTo,
error::GameError,
game::{Game, GameSettings, OrRandom, SetupRole, SetupSlot, night::NightChange},
game::{Game, GameSettings, SetupRole, SetupSlot},
message::{
CharacterState, Identification, PublicIdentity,
host::{HostDayMessage, HostGameMessage, HostNightMessage, ServerToHostMessage},
@ -15,8 +14,7 @@ use crate::{
};
use colored::Colorize;
use core::{
char,
num::{NonZero, NonZeroU8},
num::NonZeroU8,
ops::Range,
};
#[allow(unused)]
@ -205,7 +203,7 @@ impl GameExt for Game {
self.village()
.characters()
.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()
}
@ -226,7 +224,7 @@ impl GameExt for Game {
fn mark(&mut self, mark: CharacterId) -> ActionPrompt {
self.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
ActionResponse::MarkTarget(mark.clone()),
ActionResponse::MarkTarget(mark),
)))
.unwrap()
.prompt()
@ -500,11 +498,10 @@ fn yes_wolf_kill_n2() {
.into_iter()
.find(|v| v.is_village())
.unwrap()
.character_id()
.clone();
.character_id();
match game
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
execution_target.clone(),
execution_target,
)))
.unwrap()
{
@ -568,11 +565,10 @@ fn wolfpack_kill_all_targets_valid() {
.into_iter()
.find(|v| v.is_village() && !matches!(v.role().title(), RoleTitle::Protector))
.unwrap()
.character_id()
.clone();
.character_id();
match game
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
execution_target.clone(),
execution_target,
)))
.unwrap()
{
@ -603,7 +599,7 @@ fn wolfpack_kill_all_targets_valid() {
let mut attempt = game.clone();
if let ServerToHostMessage::Error(GameError::InvalidTarget) = attempt
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
ActionResponse::MarkTarget(target.character_id.clone()),
ActionResponse::MarkTarget(target.character_id),
)))
.unwrap()
{

View File

@ -13,19 +13,19 @@ use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
#[test]
fn elder_doesnt_die_first_try_night_doesnt_know() {
let players = gen_players(1..10);
let elder_player_id = players[0].player_id.clone();
let wolf_player_id = players[2].player_id.clone();
let elder_player_id = players[0].player_id;
let wolf_player_id = players[2].player_id;
let mut settings = GameSettings::empty();
settings.add_role(
SetupRole::Elder {
knows_on_night: NonZeroU8::new(3).unwrap(),
},
|slot| {
slot.assign_to = Some(elder_player_id.clone());
slot.assign_to = Some(elder_player_id);
},
);
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());
let mut game = Game::new(&players, settings).unwrap();
@ -62,8 +62,7 @@ fn elder_doesnt_die_first_try_night_doesnt_know() {
Some(DiedTo::Wolfpack {
killing_wolf: game
.character_by_player_id(wolf_player_id)
.character_id()
.clone(),
.character_id(),
night: NonZeroU8::new(2).unwrap(),
})
);
@ -72,19 +71,19 @@ fn elder_doesnt_die_first_try_night_doesnt_know() {
#[test]
fn elder_doesnt_die_first_try_night_knows() {
let players = gen_players(1..10);
let elder_player_id = players[0].player_id.clone();
let wolf_player_id = players[2].player_id.clone();
let elder_player_id = players[0].player_id;
let wolf_player_id = players[2].player_id;
let mut settings = GameSettings::empty();
settings.add_role(
SetupRole::Elder {
knows_on_night: NonZeroU8::new(1).unwrap(),
},
|slot| {
slot.assign_to = Some(elder_player_id.clone());
slot.assign_to = Some(elder_player_id);
},
);
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());
let mut game = Game::new(&players, settings).unwrap();
@ -145,12 +144,12 @@ fn elder_executed_doesnt_know() {
knows_on_night: NonZeroU8::new(3).unwrap(),
},
|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| {
slot.assign_to = Some(wolf_player_id.clone())
slot.assign_to = Some(wolf_player_id)
});
settings.fill_remaining_slots_with_villagers(players.len());
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(),
},
|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| {
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.fill_remaining_slots_with_villagers(players.len());

View File

@ -13,10 +13,10 @@ use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
#[test]
fn redeemed_scapegoat_role_changes() {
let players = gen_players(1..10);
let scapegoat_player_id = players[0].player_id.clone();
let seer_player_id = players[1].player_id.clone();
let wolf_player_id = players[2].player_id.clone();
let wolf_target_2_player_id = players[3].player_id.clone();
let scapegoat_player_id = players[0].player_id;
let seer_player_id = players[1].player_id;
let wolf_player_id = players[2].player_id;
let wolf_target_2_player_id = players[3].player_id;
let mut settings = GameSettings::default();
{
let scapegoat_slot = settings.new_slot(RoleTitle::Scapegoat);
@ -29,7 +29,7 @@ fn redeemed_scapegoat_role_changes() {
scapegoat_slot.role = SetupRole::Scapegoat {
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);
}
{
@ -39,7 +39,7 @@ fn redeemed_scapegoat_role_changes() {
.find(|s| matches!(s.role, SetupRole::Werewolf))
.unwrap()
.clone();
slot.assign_to = Some(wolf_player_id.clone());
slot.assign_to = Some(wolf_player_id);
settings.update_slot(slot);
}
{
@ -50,7 +50,7 @@ fn redeemed_scapegoat_role_changes() {
.find(|s| s.slot_id == slot)
.unwrap()
.clone();
slot.assign_to = Some(seer_player_id.clone());
slot.assign_to = Some(seer_player_id);
settings.update_slot(slot);
}
for _ in 0..6 {
@ -67,8 +67,7 @@ fn redeemed_scapegoat_role_changes() {
.into_iter()
.find(|c| c.player_id() == wolf_player_id)
.unwrap()
.character_id()
.clone();
.character_id();
game.mark_and_check(wolf_char_id);
assert_eq!(game.r#continue().seer(), Alignment::Wolves);
game.next_expect_day();
@ -82,8 +81,7 @@ fn redeemed_scapegoat_role_changes() {
.into_iter()
.find(|c| c.player_id() == seer_player_id)
.unwrap()
.character_id()
.clone();
.character_id();
game.mark_and_check(seer);
game.r#continue().sleep();
@ -101,7 +99,7 @@ fn redeemed_scapegoat_role_changes() {
.died_to()
.unwrap(),
DiedTo::Wolfpack {
killing_wolf: wolf_char_id.clone(),
killing_wolf: wolf_char_id,
night: NonZero::new(1).unwrap()
}
);
@ -115,8 +113,7 @@ fn redeemed_scapegoat_role_changes() {
.iter()
.find(|c| c.player_id() == wolf_target_2_player_id)
.unwrap()
.character_id()
.clone();
.character_id();
game.mark_and_check(wolf_target_2);
game.r#continue().sleep();
let scapegoat = game

View File

@ -65,11 +65,10 @@ fn protect_stops_shapeshift() {
.into_iter()
.find(|v| v.is_village() && !matches!(v.role().title(), RoleTitle::Protector))
.unwrap()
.character_id()
.clone();
.character_id();
match game
.process(HostGameMessage::Day(HostDayMessage::MarkForExecution(
execution_target.clone(),
execution_target,
)))
.unwrap()
{
@ -104,8 +103,7 @@ fn protect_stops_shapeshift() {
.map(|c| game.village().character_by_id(c.character_id).unwrap())
.find(|c| c.is_village())
.unwrap()
.character_id()
.clone(),
.character_id(),
prot_char_id,
),
_ => panic!("first n2 prompt isn't protector"),
@ -119,7 +117,7 @@ fn protect_stops_shapeshift() {
match game
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
ActionResponse::MarkTarget(prot_and_wolf_target.clone()),
ActionResponse::MarkTarget(prot_and_wolf_target),
)))
.unwrap()
{
@ -183,9 +181,9 @@ fn only_1_shapeshift_prompt_if_first_shifts() {
.village()
.characters()
.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();
let (_, marked, _) = game.mark_for_execution(target.clone());
let (_, marked, _) = game.mark_for_execution(target);
let (marked, target_list): (&[CharacterId], &[CharacterId]) = (&marked, &[target]);
assert_eq!(target_list, marked);
assert_eq!(game.execute().title(), ActionPromptTitle::CoverOfDarkness);
@ -195,7 +193,7 @@ fn only_1_shapeshift_prompt_if_first_shifts() {
.village()
.characters()
.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();
game.mark_and_check(target);

View File

@ -177,17 +177,17 @@ impl ActionPrompt {
if *m == mark {
*marked = (None, None);
} else {
*marked = (Some(m.clone()), Some(mark));
*marked = (Some(*m), Some(mark));
}
}
(None, None) => *marked = (Some(mark), None),
(Some(m1), Some(m2)) => {
if *m1 == mark {
*marked = (Some(m2.clone()), None);
*marked = (Some(*m2), None);
} else if *m2 == mark {
*marked = (Some(m1.clone()), None);
*marked = (Some(*m1), None);
} else {
*marked = (Some(m2.clone()), Some(mark));
*marked = (Some(*m2), Some(mark));
}
}
}

View File

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use crate::{
diedto::DiedTo,
error::GameError,
game::{DateTime, SetupSlot, Village},
game::{DateTime, Village},
message::{CharacterIdentity, Identification, PublicIdentity, night::ActionPrompt},
modifier::Modifier,
role::{Alignment, MAPLE_WOLF_ABSTAIN_LIMIT, PreviousGuardianAction, Role, RoleTitle},

View File

@ -47,12 +47,12 @@ pub async fn handler(
}
};
// 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 (send, recv) = tokio::sync::broadcast::channel(100);
player_list
.insert_or_replace(
ident.player_id.clone(),
ident.player_id,
JoinedPlayer::new(
send,
recv,

View File

@ -1,5 +1,4 @@
use tokio::sync::broadcast::Receiver;
use werewolves_proto::{error::GameError, player::PlayerId};
use werewolves_proto::error::GameError;
use crate::{
communication::{Comms, connect::ConnectUpdate},

View File

@ -82,7 +82,7 @@ impl JoinedPlayers {
self.players.lock().await;
let senders = players
.iter()
.map(|(pid, p)| (pid.clone(), p.sender.clone()))
.map(|(pid, p)| (*pid, p.sender.clone()))
.collect::<Box<[_]>>();
core::mem::drop(players);
for (pid, send) in senders {
@ -126,7 +126,7 @@ impl JoinedPlayers {
pub async fn disconnect(&self, connection: &ConnectionId) -> Option<JoinedPlayer> {
let mut map = self.players.lock().await;
self.connect_state.disconnect(connection.0.clone()).await;
self.connect_state.disconnect(connection.0).await;
if map
.get(connection.player_id())
@ -154,13 +154,13 @@ impl JoinedPlayers {
) -> Receiver<ServerMessage> {
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() };
old_map_entry.receiver = old.resubscribe_reciever();
old.receiver
} else {
self.connect_state.connect(player_id.clone()).await;
self.connect_state.connect(player_id).await;
unsafe { map.get(&player_id).unwrap_unchecked() }
.receiver

View File

@ -59,7 +59,7 @@ impl Lobby {
&self
.players_in_lobby
.iter()
.map(|(id, _)| id.player_id.clone())
.map(|(id, _)| id.player_id)
.collect::<Box<[_]>>(),
)
.await;

View File

@ -55,7 +55,7 @@ impl Connection2 {
}
fn identification(&self) -> Identification {
Identification {
player_id: self.ident.0.clone(),
player_id: self.ident.0,
public: self.ident.1.clone(),
}
}

View File

@ -1,5 +1,5 @@
use core::{num::NonZeroU8, ops::Not, time::Duration};
use std::{rc::Rc, sync::Arc};
use std::rc::Rc;
use futures::{
SinkExt, StreamExt,
@ -12,7 +12,7 @@ use werewolves_proto::{
error::GameError,
game::{GameOver, GameSettings},
message::{
CharacterIdentity, CharacterState, PlayerState, PublicIdentity,
CharacterIdentity, CharacterState, PlayerState,
host::{
HostDayMessage, HostGameMessage, HostLobbyMessage, HostMessage, HostNightMessage,
ServerToHostMessage,
@ -412,7 +412,7 @@ impl Component for Host {
yew::platform::spawn_local(async move {
if let Err(err) = send
.clone()
.send(HostMessage::ForceRoleAckFor(target.character_id.clone()))
.send(HostMessage::ForceRoleAckFor(target.character_id))
.await
{
log::error!("force role ack for [{target}]: {err}");

View File

@ -61,10 +61,10 @@ pub fn TargetCard(
mark_callback,
}: &TargetCardProps,
) -> Html {
let click_target = target.character_id.clone();
let click_target = target.character_id;
let on_click = mark_callback
.clone()
.map(|cb| Callback::from(move |_| cb.emit(click_target.clone())))
.map(|cb| Callback::from(move |_| cb.emit(click_target)))
.unwrap_or_default();
let marked = marked.then_some("marked");
let ident: PublicIdentity = target.into();

View File

@ -174,10 +174,7 @@ pub fn Prompt(props: &ActionPromptProps) -> Html {
} => (
Some(character_id),
living_players,
[&marked.0, &marked.1]
.iter()
.filter_map(|c| (*c).clone())
.collect(),
[&marked.0, &marked.1].iter().filter_map(|c| **c).collect(),
html! {{"arcanist"}},
),
ActionPrompt::Gravedigger {

View File

@ -1,7 +1,5 @@
use core::{fmt::Debug, ops::Not};
use std::sync::Arc;
use werewolves_macros::ChecksAs;
use werewolves_proto::{
message::{CharacterIdentity, PublicIdentity},
player::CharacterId,
@ -82,12 +80,12 @@ impl Component for TwoTarget {
let submit = target_selection.as_ref().map(|target_selection| {
let selected = match &self.0 {
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 disabled = selected.is_none();
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! {
<div class="button-container sp-ace">
<button
@ -118,16 +116,16 @@ impl Component for TwoTarget {
if character_id == &msg {
self.0 = TwoTargetSelection::None
} else {
self.0 = TwoTargetSelection::Two(character_id.clone(), msg)
self.0 = TwoTargetSelection::Two(*character_id, msg)
}
}
TwoTargetSelection::Two(t1, t2) => {
if &msg == t1 {
self.0 = TwoTargetSelection::One(t2.clone());
self.0 = TwoTargetSelection::One(*t2);
} else if &msg == t2 {
self.0 = TwoTargetSelection::One(t1.clone());
self.0 = TwoTargetSelection::One(*t1);
} 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 target_selection = target_selection.clone();
let sel = self.0.clone();
let on_click = move |_| target_selection.emit(sel.clone());
let sel = self.0;
let on_click = move |_| target_selection.emit(sel);
html! {
<div class="button-container sp-ace">
<button
@ -294,8 +292,7 @@ impl Component for SingleTarget {
let target_selection = target_selection.clone();
let on_click = self
.selected
.clone()
.map(|t| Callback::from(move |_| target_selection.emit(t.clone())))
.map(|t| Callback::from(move |_| target_selection.emit(t)))
.unwrap_or_default();
html! {
<div class="button-container sp-ace">
@ -342,9 +339,9 @@ pub struct TargetCardProps {
#[function_component]
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_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 ident: PublicIdentity = props.target.clone().into();

View File

@ -6,7 +6,7 @@ use werewolves_proto::{
};
use yew::prelude::*;
use crate::components::{Button, ClickableField, Identity};
use crate::components::{Button, Identity};
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct DaytimePlayerListProps {
@ -90,14 +90,14 @@ pub fn DaytimePlayer(
) -> Html {
let dead = died_to.is_some().then_some("dead");
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
.is_none()
.then_some(())
.and(
on_select
.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();
let identity: PublicIdentity = identity.into();

View File

@ -1,4 +1,3 @@
use core::ops::Deref;
use werewolves_proto::message::PublicIdentity;
use yew::prelude::*;

View File

@ -1,6 +1,5 @@
use core::num::NonZeroU8;
use web_sys::{HtmlDivElement, HtmlElement};
use werewolves_proto::{message::PlayerState, player::PlayerId};
use yew::prelude::*;
@ -23,16 +22,15 @@ pub enum LobbyPlayerAction {
pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) -> Html {
let open = use_state(|| false);
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 = |action: LobbyPlayerAction| {
let pid = pid.clone();
on_action
.as_ref()
.cloned()
.map(|on_action| {
Callback::from(move |_| {
on_action.emit((pid.clone(), action));
on_action.emit((pid, action));
action_open.set(false);
})
})
@ -42,7 +40,7 @@ pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) ->
let number_open = use_state(|| false);
let submenu_open = open.clone();
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 open = submenu_open.clone();
let on_number_submit = Callback::from(move |_| {
@ -50,7 +48,7 @@ pub fn LobbyPlayer(LobbyPlayerProps { player, on_action }: &LobbyPlayerProps) ->
Ok(num) => num,
Err(_) => return,
};
on_action.emit((pid.clone(), LobbyPlayerAction::SetNumber(number)));
on_action.emit((pid, LobbyPlayerAction::SetNumber(number)));
open.set(false);
});
html! {

View File

@ -1,8 +1,7 @@
use core::{num::NonZeroU8, ops::Not};
use std::{collections::HashMap, rc::Rc};
use std::rc::Rc;
use convert_case::{Case, Casing};
use web_sys::HtmlInputElement;
use werewolves_proto::{
error::GameError,
game::{GameSettings, OrRandom, SetupRole, SetupSlot, SlotId},
@ -53,7 +52,7 @@ pub fn Settings(
let already_assigned_pids = settings
.slots()
.iter()
.filter_map(|r| r.assign_to.clone())
.filter_map(|r| r.assign_to)
.collect::<Box<[_]>>();
let players_for_assign = players
.iter()
@ -321,11 +320,11 @@ fn assign_to_submenu(
.map(|p| {
let slot = slot.clone();
let update = update.clone();
let pid = p.player_id.clone();
let pid = p.player_id;
let setter = assign_setter.clone();
let on_click = Callback::from(move |_| {
let mut slot = slot.clone();
slot.assign_to.replace(pid.clone());
slot.assign_to.replace(pid);
update.emit(SettingSlotAction::Update(slot));
setter.set(false);
});