Skip to content

Commit

Permalink
Merge pull request #202 from TruncateGame/main
Browse files Browse the repository at this point in the history
Production release March 11 2024
  • Loading branch information
bglw authored Mar 11, 2024
2 parents 4e00ba1 + 6af39f7 commit 3dbeb7f
Show file tree
Hide file tree
Showing 11 changed files with 3,784 additions and 3,678 deletions.
7,076 changes: 3,538 additions & 3,538 deletions dict_builder/support_data/tranche_2_add.txt

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions truncate_client/src/app_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use epaint::{vec2, Color32};
use instant::Duration;
use truncate_core::{
board::Board,
game::{self, GAME_COLORS},
game::{self, GAME_COLORS, GAME_COLOR_BLUE, GAME_COLOR_RED},
generation::{self, generate_board, BoardSeed},
messages::{LobbyPlayerMessage, RoomCode, TruncateToken},
npc::scoring::{NPCParams, NPCPersonality},
Expand Down Expand Up @@ -273,14 +273,14 @@ pub fn handle_server_msg(outer: &mut OuterApplication, ui: &mut egui::Ui, curren
game.add_player("You".into());
game.add_player("Computer".into());

game.players[0].color = GAME_COLORS[0];
game.players[1].color = GAME_COLORS[1];
game.players[0].color = GAME_COLOR_BLUE;
game.players[1].color = GAME_COLOR_RED;
} else {
game.add_player("Computer".into());
game.add_player("You".into());

game.players[0].color = GAME_COLORS[1];
game.players[1].color = GAME_COLORS[0];
game.players[0].color = GAME_COLOR_RED;
game.players[1].color = GAME_COLOR_BLUE;
}

let mut board = generation::generate_board(seed.clone())
Expand Down
125 changes: 87 additions & 38 deletions truncate_client/src/lil_bits/result_modal/daily_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use epaint::{emath::Align, hex_color, vec2, Color32, TextureHandle, Vec2};
use instant::Duration;
use truncate_core::{
game::Game,
messages::{DailyStats, PlayerMessage},
messages::{DailyAttempt, DailyStats, PlayerMessage},
};

use crate::{
Expand All @@ -16,22 +16,68 @@ use super::{msg_mock::ShareMessageMock, ResultModalAction};
#[derive(Clone)]
pub struct DailyActions {
msg_mock: ShareMessageMock,
replay_link: Option<String>,
replay_link: String,
replay_copied_at: Option<Duration>,
share_copied_at: Option<Duration>,
won_today: bool,
won_yesterday: bool,
}

impl DailyActions {
pub fn new(game: &Game, depot: &TruncateDepot, stats: &DailyStats) -> Self {
let this_attempt = stats
.days
.last_key_value()
.map(|(_, v)| v.attempts.last().map(|a| a.id.clone()))
.flatten();
pub fn new(
game: &Game,
player_move_count: u32,
depot: &TruncateDepot,
stats: &DailyStats,
day: u32,
) -> Self {
let mut first_win = None;
let mut best_win = None;
let mut latest_attempt = None;

if let Some(today_result) = stats.days.get(&day) {
best_win = today_result
.attempts
.iter()
.filter(|a| a.won)
.min_by_key(|a| a.moves);

let msg_mock = ShareMessageMock::new_daily(game, &depot, &stats);
first_win = today_result
.attempts
.iter()
.enumerate()
.find(|(_, a)| a.won)
.map(|(i, a)| (i as u32, a));

latest_attempt = today_result
.attempts
.last()
.cloned()
.map(|a| (today_result.attempts.len() as u32 - 1, a));
};

let latest_attempt = latest_attempt.unwrap_or_else(|| {
(
0,
DailyAttempt {
id: "UNAVAILABLE".to_string(),
moves: player_move_count,
won: game.winner == Some(depot.gameplay.player_number as usize),
},
)
});

let shared_attempt = best_win.unwrap_or(&latest_attempt.1);

let msg_mock = ShareMessageMock::new_daily(
day,
game,
depot,
stats,
first_win,
best_win,
(latest_attempt.0, &latest_attempt.1),
);

let win_history = |rev_day: usize| {
stats
Expand All @@ -47,7 +93,10 @@ impl DailyActions {

Self {
msg_mock,
replay_link: this_attempt.map(|a| format!("https://truncate.town/#REPLAY:{a}")),
replay_link: format!(
"https://truncate.town/#REPLAY:{}",
shared_attempt.id.clone()
),
replay_copied_at: None,
share_copied_at: None,
won_today: win_history(0),
Expand Down Expand Up @@ -108,40 +157,40 @@ impl DailyActions {

ui.add_space(ui.available_height() * 0.05);

if let Some(replay_link) = &self.replay_link {
let button_text = if self.replay_copied_at.is_some() {
"COPIED LINK!"
} else {
"SHARE REPLAY"
};
let text = TextHelper::heavy(button_text, 12.0, None, ui);
let replay_button =
text.centered_button(theme.button_primary, theme.text, map_texture, ui);

if self.replay_copied_at.is_none()
&& (replay_button.clicked()
|| replay_button.drag_started()
|| replay_button.is_pointer_button_down_on())
{
if let Some(backchannel) = backchannel {
if backchannel.is_open() {
backchannel.send_msg(crate::app_outer::BackchannelMsg::Copy {
text: replay_link.clone(),
share: ShareType::Url,
});
} else {
ui.ctx().output_mut(|o| o.copied_text = replay_link.clone());
}
let button_text = if self.replay_copied_at.is_some() {
"COPIED LINK!"
} else {
"SHARE REPLAY"
};
let text = TextHelper::heavy(button_text, 12.0, None, ui);
let replay_button =
text.centered_button(theme.button_primary, theme.text, map_texture, ui);

if self.replay_copied_at.is_none()
&& (replay_button.clicked()
|| replay_button.drag_started()
|| replay_button.is_pointer_button_down_on())
{
if let Some(backchannel) = backchannel {
if backchannel.is_open() {
backchannel.send_msg(crate::app_outer::BackchannelMsg::Copy {
text: self.replay_link.clone(),
share: ShareType::Url,
});
} else {
ui.ctx().output_mut(|o| o.copied_text = replay_link.clone());
ui.ctx()
.output_mut(|o| o.copied_text = self.replay_link.clone());
}

self.replay_copied_at = Some(depot.timing.current_time);
} else {
ui.ctx()
.output_mut(|o| o.copied_text = self.replay_link.clone());
}

ui.add_space(ui.available_height() * 0.01);
self.replay_copied_at = Some(depot.timing.current_time);
}

ui.add_space(ui.available_height() * 0.01);

let button_text = if self.share_copied_at.is_some() {
"COPIED TEXT!"
} else {
Expand Down
13 changes: 12 additions & 1 deletion truncate_client/src/lil_bits/result_modal/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ impl DailySplashGraph {
let max_total_moves = stats
.days
.values()
.map(|day| day.attempts.iter().map(|a| a.moves as usize).sum())
.map(|day| {
if let Some(best_win) = day
.attempts
.iter()
.filter(|a| a.won)
.min_by_key(|a| a.moves)
{
return best_win.moves as usize;
};

day.attempts.iter().map(|a| a.moves as usize).sum()
})
.max()
.unwrap_or(30);

Expand Down
11 changes: 10 additions & 1 deletion truncate_client/src/lil_bits/result_modal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use interpolation::Ease;
use truncate_core::{
game::Game,
messages::{DailyStats, PlayerMessage},
moves::Move,
};

mod daily_actions;
Expand Down Expand Up @@ -64,9 +65,11 @@ impl ResultModalUI {
pub fn new_daily(
ui: &mut egui::Ui,
game: &Game,
player_move_count: u32,
depot: &mut TruncateDepot,
stats: DailyStats,
best_game: Option<&Game>,
day: u32,
) -> Self {
let streak_length = stats
.days
Expand Down Expand Up @@ -96,7 +99,13 @@ impl ResultModalUI {
ResultModalUI::seed_animations(ui);

let graph = DailySplashGraph::new(ui, &stats, depot.timing.current_time);
let daily_actions = DailyActions::new(best_game.unwrap_or(game), &depot, &stats);
let daily_actions = DailyActions::new(
best_game.unwrap_or(game),
player_move_count,
&depot,
&stats,
day,
);

Self {
contents: ResultModalVariant::Daily(ResultModalDaily {
Expand Down
Loading

0 comments on commit 3dbeb7f

Please sign in to comment.