Compare commits

...

3 Commits

14 changed files with 486 additions and 110 deletions

View File

@ -494,6 +494,32 @@ impl Night {
}
pub fn previous_state(&mut self) -> Result<()> {
#[cfg(test)]
{
use colored::Colorize;
log::info!(
"{}({}): {}: [{}]; {}: [{}]",
"previous_state".bold(),
"initial".bold().yellow(),
"queue state".dimmed(),
self.action_queue
.iter()
.map(|a| a.title().to_string())
.collect::<Vec<_>>()
.join(", ")
.bold()
.green(),
"used actions state".dimmed(),
self.used_actions
.iter()
.map(|(a, _, _)| a.title().to_string())
.collect::<Vec<_>>()
.join(", ")
.bold()
.yellow()
);
}
let all_current_changes = self.current_changes();
let (current_prompt, current_result, current_changes) = match &mut self.night_state {
NightState::Active {
current_prompt,
@ -534,6 +560,15 @@ impl Night {
_ => None,
});
#[cfg(test)]
{
use colored::Colorize;
log::info!(
"{} [{}]",
"setting current prompt to".dimmed(),
prompt.title().to_string().bold().red(),
);
}
core::mem::swap(&mut prompt, current_prompt);
let last_prompt = prompt;
let next_prompt_ss_related_role_change = match (&last_prompt, ss_target) {
@ -551,9 +586,60 @@ impl Night {
// role change associated with the shapeshift
self.action_queue.push_front(last_prompt);
}
// Check if the prompt is from someone shifted. in that case, it goes back in.
if let Some(source) = current_prompt.character_id()
&& !current_prompt.is_wolfy()
&& !matches!(
current_prompt,
ActionPrompt::RoleChange {
new_role: RoleTitle::Werewolf,
..
}
)
&& let Some(NightChange::Shapeshift { into, .. }) =
ChangesLookup::new(&all_current_changes).shapeshift_change()
&& source == into
{
#[cfg(test)]
{
use colored::Colorize;
log::info!(
"{source} is shifted, got prompt [{}] but calling previous_state again",
current_prompt.title().to_string().bold().red()
);
}
return self.previous_state();
}
*current_result = CurrentResult::None;
*current_changes = Vec::new();
#[cfg(test)]
{
use colored::Colorize;
log::info!(
"{}({}): {}: [{}]; {}: [{}]",
"previous_state".bold(),
"final".bold().green(),
"queue state".dimmed(),
self.action_queue
.iter()
.map(|a| a.title().to_string())
.collect::<Vec<_>>()
.join(", ")
.bold()
.green(),
"used actions state".dimmed(),
self.used_actions
.iter()
.map(|(a, _, _)| a.title().to_string())
.collect::<Vec<_>>()
.join(", ")
.bold()
.yellow()
);
}
Ok(())
} else {
Err(GameError::NoPreviousState)
@ -902,9 +988,21 @@ impl Night {
&self,
outcome: ResponseOutcome,
) -> ResponseOutcome {
let ss_change = ChangesLookup::new(&self.current_changes()).shapeshift_change();
let same_char = self
.current_character_id()
.and_then(|curr| {
let is_shifted = ss_change
.as_ref()
.and_then(|c| match c {
NightChange::Shapeshift { into, .. } => Some(*into == curr),
_ => None,
})
.unwrap_or_default();
if is_shifted {
return None;
}
self.action_queue
.iter()
.next()

View File

@ -19,7 +19,10 @@ use crate::{
character::CharacterId,
diedto::DiedTo,
error::GameError,
game::night::{CurrentResult, Night, NightState, changes::NightChange},
game::night::{
CurrentResult, Night, NightState,
changes::{ChangesLookup, NightChange},
},
message::night::{ActionPrompt, ActionResult, ActionType},
role::{RoleBlock, RoleTitle},
};
@ -82,22 +85,66 @@ impl Night {
} => return Err(GameError::AwaitingResponse),
NightState::Complete => return Err(GameError::NightOver),
}
if let Some(prompt) = self.pull_next_prompt_with_dead_ignore()? {
if let ActionPrompt::Insomniac { character_id } = &prompt
&& self.get_visits_for(character_id.character_id).is_empty()
{
// skip!
self.used_actions.pop(); // it will be re-added
return self.next();
loop {
if let Some(prompt) = self.pull_next_prompt_with_dead_ignore()? {
if let ActionPrompt::Insomniac { character_id } = &prompt
&& self.get_visits_for(character_id.character_id).is_empty()
{
// skip!
self.used_actions.pop(); // it will be re-added
return self.next();
}
let current_changes = self.current_changes();
if let Some(NightChange::Shapeshift { into, .. }) =
ChangesLookup::new(&current_changes).shapeshift_change()
&& !prompt.is_wolfy()
&& let Some(char) = prompt.character_id()
&& char == into
{
#[cfg(test)]
{
use colored::Colorize;
log::info!(
"{char} is shifted, ignoring prompt [{}]",
prompt.title().to_string().bold().red()
);
}
self.used_actions.push((
prompt.clone(),
ActionResult::GoBackToSleep,
Vec::new(),
));
continue;
}
#[cfg(test)]
{
use colored::Colorize;
log::info!(
"{}: {}: [{}]; {}: [{}]",
"next".bold(),
"setting prompt to".dimmed(),
prompt.title().to_string().bold().purple(),
"queue".dimmed(),
self.action_queue
.iter()
.map(|a| a.title().to_string())
.collect::<Vec<_>>()
.join(", ")
.bold()
.cyan()
);
}
self.night_state = NightState::Active {
current_prompt: prompt,
current_result: CurrentResult::None,
current_changes: Vec::new(),
current_page: 0,
};
break;
} else {
self.night_state = NightState::Complete;
break;
}
self.night_state = NightState::Active {
current_prompt: prompt,
current_result: CurrentResult::None,
current_changes: Vec::new(),
current_page: 0,
};
} else {
self.night_state = NightState::Complete;
}
Ok(())

View File

@ -30,7 +30,7 @@ use crate::{
night::{ActionPrompt, ActionPromptTitle, ActionResponse, ActionResult, Visits},
},
player::PlayerId,
role::{Alignment, Killer, Powerful, RoleTitle},
role::{Alignment, AlignmentEq, Killer, Powerful, RoleTitle},
};
use colored::Colorize;
use core::{num::NonZeroU8, ops::Range};
@ -182,7 +182,7 @@ pub trait ActionResultExt {
fn r#continue(&self);
fn seer(&self) -> Alignment;
fn insomniac(&self) -> Visits;
fn arcanist(&self) -> bool;
fn arcanist(&self) -> AlignmentEq;
fn role_blocked(&self);
fn gravedigger(&self) -> Option<RoleTitle>;
fn power_seer(&self) -> Powerful;
@ -248,9 +248,9 @@ impl ActionResultExt for ActionResult {
}
}
fn arcanist(&self) -> bool {
fn arcanist(&self) -> AlignmentEq {
match self {
ActionResult::Arcanist(same) => same.same(),
ActionResult::Arcanist(same) => same.clone(),
resp => panic!("expected an arcanist result, got {resp:?}"),
}
}
@ -949,6 +949,17 @@ fn big_game_test_based_on_story_test() {
.shapeshift_failed();
game.r#continue().sleep();
game.next().title().maple_wolf();
game.mark(
game.living_villager_excl(protect.player_id())
.character_id(),
);
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().seer();
game.mark(game.character_by_player_id(werewolf).character_id());
game.r#continue().seer();
@ -985,17 +996,6 @@ fn big_game_test_based_on_story_test() {
assert!(!game.r#continue().empath());
game.r#continue().sleep();
game.next().title().maple_wolf();
game.mark(
game.living_villager_excl(protect.player_id())
.character_id(),
);
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().insomniac();
game.r#continue().insomniac();
game.r#continue().sleep();
@ -1033,6 +1033,13 @@ fn big_game_test_based_on_story_test() {
game.next().title().shapeshifter();
game.r#continue().sleep();
game.next().title().maple_wolf();
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().seer();
game.mark(game.character_by_player_id(werewolf).character_id());
game.r#continue().seer();
@ -1069,13 +1076,6 @@ fn big_game_test_based_on_story_test() {
assert!(game.r#continue().empath());
game.r#continue().sleep();
game.next().title().maple_wolf();
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().insomniac();
game.r#continue().insomniac();
game.r#continue().sleep();
@ -1114,6 +1114,13 @@ fn big_game_test_based_on_story_test() {
);
game.r#continue().sleep();
game.next().title().maple_wolf();
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().seer();
game.mark(game.character_by_player_id(shapeshifter).character_id());
game.r#continue().seer();
@ -1145,13 +1152,6 @@ fn big_game_test_based_on_story_test() {
assert_eq!(game.r#continue().mortician(), DiedToTitle::Wolfpack);
game.r#continue().sleep();
game.next().title().maple_wolf();
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().insomniac();
game.r#continue().insomniac();
game.r#continue().sleep();
@ -1166,6 +1166,14 @@ fn big_game_test_based_on_story_test() {
game.mark(game.character_by_player_id(mortician).character_id());
game.r#continue().sleep();
game.next().title().maple_wolf();
game.mark(game.character_by_player_id(hunter).character_id());
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(empath).character_id());
game.r#continue().sleep();
game.next().title().seer();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().seer();
@ -1200,14 +1208,6 @@ fn big_game_test_based_on_story_test() {
);
game.r#continue().sleep();
game.next().title().maple_wolf();
game.mark(game.character_by_player_id(hunter).character_id());
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(empath).character_id());
game.r#continue().sleep();
game.next().title().insomniac();
game.r#continue().insomniac();
game.r#continue().sleep();

View File

@ -361,6 +361,17 @@ fn previous_prompt() {
.shapeshift_failed();
game.r#continue().sleep();
game.next().title().maple_wolf();
game.mark(
game.living_villager_excl(protect.player_id())
.character_id(),
);
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().seer();
game.mark(game.character_by_player_id(werewolf).character_id());
game.r#continue().seer();
@ -397,17 +408,6 @@ fn previous_prompt() {
assert!(!game.r#continue().empath());
game.r#continue().sleep();
game.next().title().maple_wolf();
game.mark(
game.living_villager_excl(protect.player_id())
.character_id(),
);
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(insomniac).character_id());
game.r#continue().sleep();
game.next().title().insomniac();
game.r#continue().insomniac();
game.r#continue().sleep();

View File

@ -238,15 +238,15 @@ fn elder_executed_knows_no_powers_incl_hunter_activation() {
game.mark(villagers.next().unwrap());
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(wolf_player_id).character_id());
game.r#continue().sleep();
game.next().title().seer();
game.mark(game.living_villager_excl(seer_player_id).character_id());
assert_eq!(game.r#continue().seer(), Alignment::Village);
game.r#continue().sleep();
game.next().title().hunter();
game.mark(game.character_by_player_id(wolf_player_id).character_id());
game.r#continue().sleep();
game.next_expect_day();
assert_eq!(

View File

@ -19,7 +19,7 @@ use crate::{
game::{Game, GameSettings, SetupRole},
game_test::{ActionPromptTitleExt, ActionResultExt, GameExt, SettingsExt, gen_players},
message::night::{ActionPromptTitle, Visits},
role::{Role, RoleTitle},
role::{AlignmentEq, Role, RoleTitle},
};
#[test]
@ -54,7 +54,7 @@ fn sees_visits() {
let mut villagers = game.villager_character_ids().into_iter();
game.mark(villagers.next().unwrap());
game.mark(villagers.next().unwrap());
assert_eq!(game.r#continue().arcanist(), true);
assert_eq!(game.r#continue().arcanist(), AlignmentEq::Same);
game.r#continue().sleep();
game.next_expect_day();
@ -77,7 +77,7 @@ fn sees_visits() {
game.character_by_player_id(insomniac_player_id)
.character_id(),
);
assert_eq!(game.r#continue().arcanist(), true);
assert_eq!(game.r#continue().arcanist(), AlignmentEq::Same);
game.r#continue().sleep();
game.next().title().insomniac();
@ -124,7 +124,7 @@ fn direwolf_block_prevents_visits_so_they_are_not_seen() {
let mut villagers = game.villager_character_ids().into_iter();
game.mark(villagers.next().unwrap());
game.mark(villagers.next().unwrap());
assert_eq!(game.r#continue().arcanist(), true);
assert_eq!(game.r#continue().arcanist(), AlignmentEq::Same);
game.r#continue().sleep();
game.next_expect_day();
@ -185,7 +185,7 @@ fn dead_people_still_get_prompts_to_trigger_visits() {
let mut villagers = game.villager_character_ids().into_iter();
game.mark(villagers.next().unwrap());
game.mark(villagers.next().unwrap());
assert_eq!(game.r#continue().arcanist(), true);
assert_eq!(game.r#continue().arcanist(), AlignmentEq::Same);
game.r#continue().sleep();
game.next_expect_day();
@ -202,7 +202,7 @@ fn dead_people_still_get_prompts_to_trigger_visits() {
game.next().title().arcanist();
game.mark(game.character_by_player_id(seer).character_id());
game.mark(game.character_by_player_id(insomniac).character_id());
assert!(game.r#continue().arcanist());
assert_eq!(game.r#continue().arcanist(), AlignmentEq::Same);
game.r#continue().sleep();
game.next().title().insomniac();

View File

@ -17,7 +17,7 @@ use pretty_assertions::{assert_eq, assert_ne, assert_str_eq};
use crate::{
character::CharacterId,
game::{Game, GameSettings, SetupRole},
game::{Game, GameSettings, GameState, SetupRole, night::changes::ChangesLookup},
game_test::{
ActionPromptTitleExt, ActionResultExt, GameExt, ServerToHostMessageExt, SettingsExt,
gen_players, init_log,
@ -223,6 +223,7 @@ fn i_would_simply_refuse() {
#[test]
fn shapeshift_fail_can_continue() {
init_log();
let players = gen_players(1..21);
let mut player_ids = players.iter().map(|p| p.player_id);
let shapeshifter = player_ids.next().unwrap();
@ -277,3 +278,161 @@ fn shapeshift_fail_can_continue() {
game.next_expect_day();
}
#[test]
fn shapeshift_removes_village_prompt() {
init_log();
let players = gen_players(1..21);
let mut player_ids = players.iter().map(|p| p.player_id);
let shapeshifter = player_ids.next().unwrap();
let wolf = player_ids.next().unwrap();
let gravedigger = player_ids.next().unwrap();
let mut settings = GameSettings::empty();
settings.add_and_assign(SetupRole::Shapeshifter, shapeshifter);
settings.add_and_assign(SetupRole::Werewolf, wolf);
settings.add_and_assign(SetupRole::Gravedigger, gravedigger);
settings.fill_remaining_slots_with_villagers(players.len());
let mut game = Game::new(&players, settings).unwrap();
game.r#continue().r#continue();
assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro);
game.r#continue().sleep();
game.next_expect_day();
game.mark_for_execution(game.living_villager().character_id());
game.execute().title().wolf_pack_kill();
game.mark(game.character_by_player_id(gravedigger).character_id());
game.r#continue().r#continue();
game.next().title().shapeshifter();
match game
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
ActionResponse::Shapeshift,
)))
.unwrap()
{
ServerToHostMessage::ActionResult(Some(ident), ActionResult::Continue) => {
assert_eq!(ident, game.character_by_player_id(shapeshifter).identity());
}
other => panic!("expected shift, got {other:?}"),
};
assert_eq!(
game.next(),
ActionPrompt::RoleChange {
character_id: game.character_by_player_id(gravedigger).identity(),
new_role: RoleTitle::Werewolf
}
);
game.r#continue().sleep();
game.next_expect_day();
}
#[test]
fn shapeshift_removes_village_prompt_but_previous_can_bring_it_back() {
init_log();
let players = gen_players(1..21);
let mut player_ids = players.iter().map(|p| p.player_id);
let shapeshifter = player_ids.next().unwrap();
let wolf = player_ids.next().unwrap();
let gravedigger = player_ids.next().unwrap();
let beholder = player_ids.next().unwrap();
let mut settings = GameSettings::empty();
settings.add_and_assign(SetupRole::Shapeshifter, shapeshifter);
settings.add_and_assign(SetupRole::Werewolf, wolf);
settings.add_and_assign(SetupRole::Gravedigger, gravedigger);
settings.add_and_assign(SetupRole::Beholder, beholder);
settings.fill_remaining_slots_with_villagers(players.len());
let mut game = Game::new(&players, settings).unwrap();
game.r#continue().r#continue();
assert_eq!(game.next().title(), ActionPromptTitle::WolvesIntro);
game.r#continue().sleep();
game.next_expect_day();
let executed = game.living_villager();
game.mark_for_execution(executed.character_id());
game.execute().title().wolf_pack_kill();
game.mark(game.character_by_player_id(gravedigger).character_id());
game.r#continue().r#continue();
game.next().title().shapeshifter();
match game
.process(HostGameMessage::Night(HostNightMessage::ActionResponse(
ActionResponse::Shapeshift,
)))
.unwrap()
{
ServerToHostMessage::ActionResult(Some(ident), ActionResult::Continue) => {
assert_eq!(ident, game.character_by_player_id(shapeshifter).identity());
}
other => panic!("expected shift, got {other:?}"),
};
assert_eq!(
game.next(),
ActionPrompt::RoleChange {
character_id: game.character_by_player_id(gravedigger).identity(),
new_role: RoleTitle::Werewolf
}
);
game.r#continue().sleep();
game.next().title().beholder();
assert_eq!(
game.prev(),
ServerToHostMessage::ActionPrompt(
ActionPrompt::RoleChange {
character_id: game.character_by_player_id(gravedigger).identity(),
new_role: RoleTitle::Werewolf
},
0
)
);
assert_eq!(
game.prev(),
ServerToHostMessage::ActionPrompt(
ActionPrompt::Shapeshifter {
character_id: game.character_by_player_id(shapeshifter).identity()
},
0
)
);
let current_changes = match game.game_state() {
GameState::Night { night } => night.current_changes(),
GameState::Day { .. } => unreachable!(),
};
assert_eq!(
ChangesLookup::new(&current_changes).shapeshift_change(),
None
);
game.r#continue().sleep();
game.next().title().gravedigger();
game.mark(executed.character_id());
assert_eq!(game.r#continue().gravedigger(), Some(RoleTitle::Villager));
game.r#continue().sleep();
game.next().title().beholder();
game.mark_villager();
game.r#continue().sleep();
game.next_expect_day();
assert_eq!(
game.character_by_player_id(gravedigger).role_title(),
RoleTitle::Gravedigger
);
assert_eq!(
game.character_by_player_id(shapeshifter)
.shapeshifter_ref()
.unwrap()
.shifted_into
.clone(),
None
);
}

View File

@ -95,7 +95,7 @@ pub enum ActionPrompt {
dead_players: Box<[CharacterIdentity]>,
marked: Option<CharacterId>,
},
#[checks(ActionType::Other)]
#[checks(ActionType::VillageKill)]
Hunter {
character_id: CharacterIdentity,
current_target: Option<CharacterIdentity>,
@ -108,7 +108,7 @@ pub enum ActionPrompt {
living_players: Box<[CharacterIdentity]>,
marked: Option<CharacterId>,
},
#[checks(ActionType::Other)]
#[checks(ActionType::VillageKill)]
MapleWolf {
character_id: CharacterIdentity,
nights_til_starvation: u8,

View File

@ -12,7 +12,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use core::ops::Not;
use core::{ops::Not, time::Duration};
use std::sync::Arc;
use crate::{
@ -132,23 +132,43 @@ impl GameRunner {
.log_err();
};
(update_host)(&acks, &mut self.comms);
let notify_of_role = |player_id: PlayerId, village: &Village, sender: &LobbyPlayers| {
if let Some(char) = village.character_by_player_id(player_id) {
sender
.send_if_present(
player_id,
ServerMessage::GameStart {
let notify_of_role =
async |player_id: PlayerId, village: &Village, sender: &JoinedPlayers| {
if let Some(char) = village.character_by_player_id(player_id)
&& let Some(sender) = sender.get_sender(player_id).await
{
sender
.send(ServerMessage::GameStart {
role: char.initial_shown_role(),
},
)
.log_debug();
}
};
})
.log_debug();
}
};
let notify_non_ackd =
async |acks: &[(Character, bool)], village: &Village, sender: &JoinedPlayers| {
for pid in acks
.iter()
.filter_map(|(c, ack)| ack.not().then_some(c.player_id()))
{
(notify_of_role)(pid, village, sender).await;
}
};
let mut last_err_log = tokio::time::Instant::now() - tokio::time::Duration::from_secs(60);
let mut connect_list: Arc<[PlayerId]> = Arc::new([]);
while acks.iter().any(|(_, ackd)| !*ackd) {
let msg = match self.comms.message().await {
const PING_TIME: Duration = Duration::from_secs(1);
let sleep_fut = tokio::time::sleep(PING_TIME);
let msg = tokio::select! {
_ = sleep_fut => {
(notify_non_ackd)(&acks, self.game.village(), &self.joined_players).await;
continue;
}
msg = self.comms.message() => {
msg
}
};
let msg = match msg {
Ok(msg) => msg,
Err(err) => {
if (tokio::time::Instant::now() - last_err_log).as_secs() >= 30 {
@ -164,7 +184,8 @@ impl GameRunner {
acks.iter_mut().find(|(c, _)| c.character_id() == char_id)
{
*ackd = true;
(notify_of_role)(c.player_id(), self.game.village(), &self.player_sender);
(notify_of_role)(c.player_id(), self.game.village(), &self.joined_players)
.await;
}
(update_host)(&acks, &mut self.comms);
}
@ -233,11 +254,12 @@ impl GameRunner {
public: _,
},
message: _,
}) => (notify_of_role)(player_id, self.game.village(), &self.player_sender),
}) => (notify_of_role)(player_id, self.game.village(), &self.joined_players).await,
Message::ConnectedList(c) => {
let newly_connected = c.iter().filter(|c| connect_list.contains(*c));
for connected in newly_connected {
(notify_of_role)(*connected, self.game.village(), &self.player_sender)
(notify_of_role)(*connected, self.game.village(), &self.joined_players)
.await
}
connect_list = c;
}

View File

@ -285,14 +285,12 @@ impl Lobby {
},
message: ClientMessage::Goodbye,
}) => {
log::error!("we are in there");
if let Some(remove_idx) = self
.players_in_lobby
.iter()
.enumerate()
.find_map(|(idx, p)| (p.0.player_id == player_id).then_some(idx))
{
log::error!("removing player {player_id} at idx {remove_idx}");
self.players_in_lobby.swap_remove(remove_idx);
self.send_lobby_info_to_host().await?;
self.send_lobby_info_to_clients().await;

View File

@ -94,10 +94,11 @@ body {
app {
max-width: 100vw;
width: 100vw;
min-height: 100vh;
display: flex;
flex-direction: column;
top: 0;
left: 0;
display: block;
position: absolute;
}
.big-screen {
@ -957,18 +958,45 @@ input {
}
.info-update {
border: 1px solid rgba(255, 255, 255, 0.5);
padding: 30px 0px 30px 0px;
font-size: 2rem;
align-content: stretch;
margin: 0;
position: absolute;
left: 0;
position: fixed;
left: 5vw;
z-index: 3;
background-color: #000;
min-width: 2cm;
width: 90vw;
& * {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-items: center;
gap: 10px;
&>input {
border: 1px solid rgba(255, 255, 255, 0.25);
background-color: black;
color: white;
padding: 0;
font-size: 1.5em;
&:focus {
background-color: white;
color: black;
outline: 1px solid rgba(255, 255, 255, 0.25);
}
}
&>button {
font-size: 1.1em;
}
&>* {
margin: 0;
width: 100%;
width: 80% !important;
text-align: center;
}
}
@ -980,6 +1008,12 @@ input {
text-align: center;
align-items: center;
width: 100%;
height: 80vh;
justify-content: center;
&>p {
font-size: 1.5em;
}
&>button {
font-size: 1.5rem;
@ -2301,7 +2335,7 @@ li.choice {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
overflow: hidden;
margin-top: auto;
max-height: 1cm;
justify-content: center;
background-color: #000;

View File

@ -48,10 +48,10 @@ pub fn ClientFooter() -> Html {
};
html! {
<nav class="footer">
<footer class="footer">
<button class="default-button solid" onclick={about_click}>{"about"}</button>
{about_dialog}
</nav>
</footer>
}
}

View File

@ -102,6 +102,7 @@ pub fn ClientNav(
on_submit={on_submit}
state={number_open.clone()}
on_open={close_others}
label={String::from("number")}
>
<div class="number">{current_num}</div>
</ClickableNumberEdit>
@ -137,10 +138,11 @@ pub fn ClientNav(
<ClickableTextEdit
value={name.clone()}
submit_ident={identity.clone()}
field_name="pronouns"
field_name="name"
on_submit={on_submit}
state={name_open.clone()}
on_open={close_others}
label={String::from("name")}
>
<div class="name">{identity.1.name.as_str()}</div>
</ClickableTextEdit>
@ -180,6 +182,7 @@ pub fn ClientNav(
on_submit={on_submit}
state={pronouns_open}
on_open={close_others}
label={String::from("pronouns")}
>
{pronouns}
</ClickableTextEdit>
@ -228,6 +231,8 @@ struct ClickableTextEditProps {
pub max_length: usize,
#[prop_or_default]
pub on_open: Option<Callback<()>>,
#[prop_or_default]
pub label: String,
}
#[function_component]
@ -241,6 +246,7 @@ fn ClickableTextEdit(
state,
max_length,
on_open,
label,
}: &ClickableTextEditProps,
) -> Html {
let on_input = crate::components::input_element_string_oninput(value.setter(), *max_length);
@ -260,9 +266,13 @@ fn ClickableTextEdit(
}
}
};
let label = label.is_empty().not().then_some(html! {
<label>{label}</label>
});
let options = html! {
<div class="row-list info-update">
<input type="text" oninput={on_input} name={*field_name}/>
<div class="info-update">
{label}
<input type="text" oninput={on_input} name={*field_name} autofocus=true/>
<Button on_click={submit}>{"ok"}</Button>
</div>
};

View File

@ -12,6 +12,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use core::ops::Not;
use yew::prelude::*;
use crate::components::Button;
@ -92,6 +93,8 @@ pub struct ClickableNumberEditProps {
pub state: UseStateHandle<bool>,
#[prop_or_default]
pub on_open: Option<Callback<()>>,
#[prop_or_default]
pub label: String,
}
#[function_component]
@ -103,14 +106,19 @@ pub fn ClickableNumberEdit(
on_submit,
state,
on_open,
label,
}: &ClickableNumberEditProps,
) -> Html {
let on_input = crate::components::input_element_string_oninput(value.setter(), 20);
let on_submit = on_submit.clone();
let label = label.is_empty().not().then_some(html! {
<label>{label}</label>
});
let options = html! {
<div class="row-list info-update">
<input type="text" oninput={on_input} name={*field_name}/>
<div class="info-update">
{label}
<input type="text" oninput={on_input} name={*field_name} autofocus=true/>
<Button on_click={on_submit.clone()}>{"ok"}</Button>
</div>
};