Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
add show_plan option
Browse files Browse the repository at this point in the history
  • Loading branch information
MinusKelvin committed Oct 26, 2021
1 parent 24ef169 commit 295a167
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 40 deletions.
20 changes: 17 additions & 3 deletions cc-client/src/battle_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@ pub struct BattleUi {
}

impl BattleUi {
pub fn new(battle: &Battle, p1_name: String, p2_name: String) -> Self {
pub fn new(
battle: &Battle,
p1_name: String,
p1_show_plan: bool,
p2_name: String,
p2_show_plan: bool,
) -> Self {
BattleUi {
player_1_graphics: PlayerDrawState::new(battle.player_1.board.next_queue(), p1_name),
player_2_graphics: PlayerDrawState::new(battle.player_2.board.next_queue(), p2_name),
player_1_graphics: PlayerDrawState::new(
battle.player_1.board.next_queue(),
p1_name,
p1_show_plan,
),
player_2_graphics: PlayerDrawState::new(
battle.player_2.board.next_queue(),
p2_name,
p2_show_plan,
),
time: 0,
}
}
Expand Down
21 changes: 19 additions & 2 deletions cc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ pub fn main() {
el_proxy,
executor,
state: match replay_file {
Some(f) => Box::new(ReplayGame::new(f)),
Some(f) => Box::new(ReplayGame::new(
f,
options.p1.show_plan,
options.p2.show_plan,
)),
None => Box::new(RealtimeGame::new(options, 0, 0).await),
},
p1: p1_gamepad,
Expand Down Expand Up @@ -237,13 +241,26 @@ impl Default for Options {
}
}

#[derive(Serialize, Deserialize, Clone, Default)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(default)]
struct PlayerConfig<E: Default> {
controls: input::UserInput,
game: GameConfig,
bot_config: BotConfig<E>,
is_bot: bool,
show_plan: bool,
}

impl<E: Default> Default for PlayerConfig<E> {
fn default() -> Self {
Self {
controls: Default::default(),
game: Default::default(),
bot_config: Default::default(),
is_bot: false,
show_plan: true,
}
}
}

impl<E> PlayerConfig<E>
Expand Down
66 changes: 35 additions & 31 deletions cc-client/src/player_draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct PlayerDrawState {
statistics: Statistics,
garbage_queue: u32,
dead: bool,
show_plan: bool,
hold_piece: Option<Piece>,
next_queue: VecDeque<Piece>,
game_time: u32,
Expand All @@ -31,7 +32,7 @@ enum State {
}

impl PlayerDrawState {
pub fn new(queue: impl IntoIterator<Item = Piece>, name: String) -> Self {
pub fn new(queue: impl IntoIterator<Item = Piece>, name: String, show_plan: bool) -> Self {
PlayerDrawState {
board: ArrayVec::from([*ColoredRow::EMPTY; 40]),
state: State::Delay,
Expand All @@ -46,6 +47,7 @@ impl PlayerDrawState {
clear_splash: None,
name,
info: None,
show_plan,
}
}

Expand Down Expand Up @@ -331,41 +333,43 @@ impl PlayerDrawState {
0,
);

if let Some(ref info) = self.info {
let mut has_pc = false;
for (_, l) in info.plan() {
if l.perfect_clear {
has_pc = true;
if self.show_plan {
if let Some(ref info) = self.info {
let mut has_pc = false;
for (_, l) in info.plan() {
if l.perfect_clear {
has_pc = true;
}
}
}

// Draw bot plan
let mut y_map = [0; 40];
for i in 0..40 {
y_map[i] = i as i32;
}
for (placement, lock) in info.plan() {
for &(x, y, d) in &placement.cells_with_connections() {
res.sprite_batch.draw(
&res.sprites.plan[d.as_usize()],
point2(offset_x + x as f32 + 4.0, y_map[y as usize] as f32 + 3.25),
cell_color_to_color(placement.kind.0.color()),
);
}
let mut new_map = [0; 40];
let mut j = 0;
// Draw bot plan
let mut y_map = [0; 40];
for i in 0..40 {
if !lock.cleared_lines.contains(&i) {
new_map[j] = y_map[i as usize];
j += 1;
}
y_map[i] = i as i32;
}
y_map = new_map;
for (placement, lock) in info.plan() {
for &(x, y, d) in &placement.cells_with_connections() {
res.sprite_batch.draw(
&res.sprites.plan[d.as_usize()],
point2(offset_x + x as f32 + 4.0, y_map[y as usize] as f32 + 3.25),
cell_color_to_color(placement.kind.0.color()),
);
}
let mut new_map = [0; 40];
let mut j = 0;
for i in 0..40 {
if !lock.cleared_lines.contains(&i) {
new_map[j] = y_map[i as usize];
j += 1;
}
}
y_map = new_map;

if !has_pc && lock.placement_kind.is_hard() && lock.placement_kind.is_clear()
|| lock.perfect_clear
{
break;
if !has_pc && lock.placement_kind.is_hard() && lock.placement_kind.is_clear()
|| lock.perfect_clear
{
break;
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion cc-client/src/realtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ impl RealtimeGame {
battle.replay.p1_name = p1_name.clone();
battle.replay.p2_name = p2_name.clone();
RealtimeGame {
ui: BattleUi::new(&battle, p1_name, p2_name),
ui: BattleUi::new(
&battle,
p1_name,
options.p1.show_plan,
p2_name,
options.p2.show_plan,
),
battle,
options: Some(options),
p1_input,
Expand Down
22 changes: 19 additions & 3 deletions cc-client/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ pub struct ReplayGame {
p1_info_updates: VecDeque<Option<cold_clear::Info>>,
p2_info_updates: VecDeque<Option<cold_clear::Info>>,
start_delay: u32,
p1_show_plan: bool,
p2_show_plan: bool,
}

impl ReplayGame {
pub fn new(file: impl Into<PathBuf>) -> Self {
pub fn new(file: impl Into<PathBuf>, p1_show_plan: bool, p2_show_plan: bool) -> Self {
let file = file.into();
let InfoReplay {
replay,
Expand All @@ -41,13 +43,21 @@ impl ReplayGame {
replay.garbage_seed,
);
ReplayGame {
ui: BattleUi::new(&battle, replay.p1_name, replay.p2_name),
ui: BattleUi::new(
&battle,
replay.p1_name,
p1_show_plan,
replay.p2_name,
p2_show_plan,
),
battle,
updates: replay.updates,
p1_info_updates,
p2_info_updates,
start_delay: 500,
file,
p1_show_plan,
p2_show_plan,
}
}
}
Expand Down Expand Up @@ -100,7 +110,13 @@ impl crate::State for ReplayGame {
replay.p2_seed,
replay.garbage_seed,
);
self.ui = BattleUi::new(&battle, replay.p1_name, replay.p2_name);
self.ui = BattleUi::new(
&battle,
replay.p1_name,
self.p1_show_plan,
replay.p2_name,
self.p2_show_plan,
);
self.battle = battle;
self.updates = replay.updates;
self.p1_info_updates = p1_info_updates;
Expand Down

0 comments on commit 295a167

Please sign in to comment.