Refactorings/Fixes related to emoting

This commit is contained in:
Stephen Seo 2022-04-29 19:21:59 +09:00
parent d88e8ef9f3
commit b4eaba09c5
3 changed files with 48 additions and 10 deletions

View file

@ -49,7 +49,7 @@
display: grid;
}
div.emote_wrapper {
grid-row: 3;
grid-row: 4;
grid-column: 8;
display: grid;
}

View file

@ -123,6 +123,14 @@ impl GameState {
None
}
}
pub fn get_singleplayer_current_side(&self) -> Option<Turn> {
if let GameState::SinglePlayer(turn, _) = *self {
Some(turn)
} else {
None
}
}
}
impl Default for GameState {

View file

@ -256,13 +256,43 @@ impl Component for EmoteButton {
}
}
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
fn update(&mut self, ctx: &Context<Self>, _msg: Self::Message) -> bool {
let (shared, _) = ctx
.link()
.context::<SharedState>(Callback::noop())
.expect("state to be set");
let (_window, document) =
get_window_document().expect("Should be able to get Window and Document");
if shared.game_state.borrow().is_networked_multiplayer() {
ctx.link()
.get_parent()
.expect("Wrapper should be parent of EmoteButton")
.clone()
.downcast::<Wrapper>()
.send_message(WrapperMsg::SendEmote(ctx.props().emote));
} else if let Some(side) = shared.game_state.borrow().get_singleplayer_current_side() {
append_to_info_text(
&document,
"info_text0",
&format!(
"<b class=\"{}\">{} emoted with <b class=\"emote\">{}</b></b>",
side.get_color(),
side,
ctx.props().emote.get_unicode()
),
INFO_TEXT_MAX_ITEMS,
)
.ok();
} else {
append_to_info_text(
&document,
"info_text0",
"<b>Cannot use emotes at this time</b>",
INFO_TEXT_MAX_ITEMS,
)
.ok();
}
true
}
}
@ -1508,7 +1538,7 @@ impl Component for Wrapper {
&document,
"info_text0",
&format!(
"<b class=\"{}\">{} sent <b class=\"emote\">{}</p></b>",
"<b class=\"{}\">{} sent <b class=\"emote\">{}</b></b>",
current_side.get_opposite().get_color(),
current_side.get_opposite(),
emote_enum.get_unicode()
@ -1854,7 +1884,7 @@ impl Component for Wrapper {
&document,
"info_text0",
&format!(
"<b class=\"{}\">{} sent <b class=\"emote\">{}</p></b>",
"<b class=\"{}\">{} sent <b class=\"emote\">{}</b></b>",
current_side.get_color(),
current_side,
emote.get_unicode()