Skip to content

Commit 0397c4b

Browse files
authored
refactor, bug fixes (#172)
1 parent 230ad13 commit 0397c4b

File tree

273 files changed

+7379
-7007
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+7379
-7007
lines changed

client/src/action_buttons.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn base_or_custom_available(
164164
custom: &CustomActionType,
165165
) -> bool {
166166
rc.can_play_action(action)
167-
|| (rc.game.state == GameState::Playing
167+
|| (rc.game.state() == &GameState::Playing
168168
&& rc
169169
.game
170170
.is_custom_action_available(rc.shown_player.index, custom))

client/src/advance_ui.rs

+3-24
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use server::content::advances;
1515
use server::game::GameState;
1616
use server::player::Player;
1717
use server::playing_actions::PlayingAction;
18-
use server::status_phase::StatusPhaseAction;
1918
use std::ops::Rem;
2019

2120
const COLUMNS: usize = 6;
@@ -39,7 +38,9 @@ pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
3938
|a, p| {
4039
if p.has_advance(&a.name) {
4140
AdvanceState::Owned
42-
} else if game.state == GameState::Playing && game.actions_left > 0 && p.can_advance(a)
41+
} else if game.state() == &GameState::Playing
42+
&& game.actions_left > 0
43+
&& p.can_advance(a)
4344
{
4445
AdvanceState::Available
4546
} else {
@@ -50,28 +51,6 @@ pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
5051
)
5152
}
5253

53-
pub fn show_free_advance_menu(rc: &RenderContext) -> StateUpdate {
54-
show_advance_menu(
55-
rc,
56-
"Select a free advance",
57-
|a, p| {
58-
if p.can_advance_free(a) {
59-
AdvanceState::Available
60-
} else if p.has_advance(&a.name) {
61-
AdvanceState::Owned
62-
} else {
63-
AdvanceState::Unavailable
64-
}
65-
},
66-
|a| {
67-
StateUpdate::execute_with_confirm(
68-
vec![format!("Select {} as a free advance?", a.name)],
69-
Action::StatusPhase(StatusPhaseAction::FreeAdvance(a.name.clone())),
70-
)
71-
},
72-
)
73-
}
74-
7554
pub fn show_advance_menu(
7655
rc: &RenderContext,
7756
title: &str,

client/src/city_ui.rs

+9-23
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use server::city::{City, MoodState};
2020
use server::city_pieces::Building;
2121
use server::collect::possible_resource_collections;
2222
use server::content::custom_actions::CustomActionType;
23-
use server::content::custom_phase_actions::Structure;
23+
use server::content::custom_phase_actions::{SelectedStructure, Structure};
2424
use server::game::Game;
2525
use server::playing_actions::PlayingActionType;
2626
use server::position::Position;
@@ -257,26 +257,12 @@ fn structure_selected(
257257
let ActiveDialog::StructuresRequest(r) = &rc.state.active_dialog else {
258258
panic!("invalid state");
259259
};
260-
if let Some(i) = r
261-
.structures
262-
.iter()
263-
.position(|(pos, s)| s == &h.structure && pos == &position)
264-
{
265-
let mut new = r.clone();
266-
new.structures.remove(i);
267-
return Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
268-
new,
269-
)));
270-
}
271-
if r.request.choices.contains(&(position, h.structure.clone())) {
272-
let mut new = r.clone();
273-
new.structures.push((position, h.structure.clone()));
274-
return Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
275-
new,
276-
)));
277-
};
260+
Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
261+
r.clone().toggle((position, h.structure.clone())),
262+
)))
263+
} else {
264+
None
278265
}
279-
None
280266
}
281267

282268
pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {
@@ -285,13 +271,13 @@ pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {
285271

286272
let highlighted = match rc.state.active_dialog {
287273
ActiveDialog::StructuresRequest(ref s) => highlight_structures(
288-
&position_structures(city, &s.structures),
274+
&position_structures(city, &s.selected),
289275
HighlightType::Primary,
290276
)
291277
.into_iter()
292278
.chain(highlight_structures(
293279
&position_structures(city, &s.request.choices),
294-
HighlightType::Secondary,
280+
HighlightType::Choices,
295281
))
296282
.collect_vec(),
297283
_ => vec![],
@@ -415,7 +401,7 @@ fn draw_wonders(
415401
Ok(i)
416402
}
417403

418-
fn position_structures(city: &City, list: &[(Position, Structure)]) -> Vec<Structure> {
404+
fn position_structures(city: &City, list: &[SelectedStructure]) -> Vec<Structure> {
419405
list.iter()
420406
.filter_map(|(pos, st)| {
421407
if pos == &city.position {

client/src/client.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use macroquad::prelude::clear_background;
33
use macroquad::prelude::*;
44

55
use server::action::Action;
6-
use server::content::custom_phase_actions::CurrentEventResponse;
76
use server::game::Game;
87
use server::position::Position;
98

10-
use crate::advance_ui::{pay_advance_dialog, show_free_advance_menu, show_paid_advance_menu};
9+
use crate::advance_ui::{pay_advance_dialog, show_paid_advance_menu};
1110
use crate::client_state::{
1211
ActiveDialog, CameraMode, DialogChooser, State, StateUpdate, StateUpdates,
1312
};
@@ -22,7 +21,6 @@ use crate::log_ui::show_log;
2221
use crate::map_ui::{draw_map, explore_dialog, show_tile_menu};
2322
use crate::player_ui::{player_select, show_global_controls, show_top_center, show_top_left};
2423
use crate::render_context::RenderContext;
25-
use crate::status_phase_ui::raze_city_confirm_dialog;
2624
use crate::unit_ui::unit_selection_click;
2725
use crate::{
2826
custom_actions_ui, custom_phase_ui, dialog_ui, influence_ui, map_ui, move_ui, recruit_unit_ui,
@@ -97,7 +95,7 @@ fn render(rc: &RenderContext, features: &Features) -> StateUpdate {
9795
updates.add(show_tile_menu(rc, pos));
9896
}
9997
}
100-
updates.add(try_click(rc));
98+
updates.add(rc.with_camera(CameraMode::World, try_click));
10199
updates.result()
102100
}
103101

@@ -130,8 +128,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
130128
match &state.active_dialog {
131129
ActiveDialog::None
132130
| ActiveDialog::WaitingForUpdate
133-
| ActiveDialog::CulturalInfluence(_)
134-
| ActiveDialog::PositionRequest(_) => StateUpdate::None,
131+
| ActiveDialog::CulturalInfluence(_) => StateUpdate::None,
135132
ActiveDialog::DialogChooser(d) => dialog_chooser(rc, d),
136133
ActiveDialog::Log => show_log(rc),
137134

@@ -143,23 +140,17 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
143140
ActiveDialog::CollectResources(c) => collect_dialog(rc, c),
144141
ActiveDialog::RecruitUnitSelection(s) => recruit_unit_ui::select_dialog(rc, s),
145142
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::replace_dialog(rc, r),
146-
ActiveDialog::CulturalInfluenceResolution(r) => {
147-
influence_ui::cultural_influence_resolution_dialog(rc, r)
148-
}
149143
ActiveDialog::ExploreResolution(r) => explore_dialog(rc, r),
150144
ActiveDialog::MoveUnits(_) => move_ui::move_units_dialog(rc),
151145
ActiveDialog::MovePayment(p) => move_ui::move_payment_dialog(rc, p),
152146

153147
//status phase
154-
ActiveDialog::FreeAdvance => show_free_advance_menu(rc),
155-
ActiveDialog::RazeSize1City => status_phase_ui::raze_city_dialog(rc),
156-
ActiveDialog::CompleteObjectives => status_phase_ui::complete_objectives_dialog(rc),
157-
ActiveDialog::ChangeGovernmentType => status_phase_ui::change_government_type_dialog(rc),
148+
ActiveDialog::ChangeGovernmentType(r) => {
149+
status_phase_ui::change_government_type_dialog(rc, r)
150+
}
158151
ActiveDialog::ChooseAdditionalAdvances(a) => {
159152
status_phase_ui::choose_additional_advances_dialog(rc, a)
160153
}
161-
ActiveDialog::DetermineFirstPlayer => status_phase_ui::determine_first_player_dialog(rc),
162-
163154
ActiveDialog::Sports((p, pos)) => custom_actions_ui::sports(rc, p, *pos),
164155
ActiveDialog::Taxes(p) => custom_actions_ui::taxes(rc, p),
165156
ActiveDialog::Theaters(p) => custom_actions_ui::theaters(rc, p),
@@ -174,6 +165,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
174165
ActiveDialog::UnitsRequest(r) => custom_phase_ui::select_units_dialog(rc, r),
175166
ActiveDialog::StructuresRequest(r) => custom_phase_ui::select_structures_dialog(rc, r),
176167
ActiveDialog::BoolRequest => custom_phase_ui::bool_request_dialog(rc),
168+
ActiveDialog::PositionRequest(r) => custom_phase_ui::position_request_dialog(rc, r),
177169
}
178170
}
179171

@@ -223,15 +215,8 @@ fn controlling_player_click(rc: &RenderContext, mouse_pos: Vec2, pos: Position)
223215
ActiveDialog::ReplaceUnits(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
224216
StateUpdate::OpenDialog(ActiveDialog::ReplaceUnits(new.clone()))
225217
}),
226-
ActiveDialog::RazeSize1City => raze_city_confirm_dialog(rc, pos),
227218
ActiveDialog::PositionRequest(r) => {
228-
if r.choices.contains(&pos) {
229-
StateUpdate::Execute(Action::CustomPhaseEvent(
230-
CurrentEventResponse::SelectPosition(pos),
231-
))
232-
} else {
233-
StateUpdate::None
234-
}
219+
StateUpdate::OpenDialog(ActiveDialog::PositionRequest(r.clone().toggle(pos)))
235220
}
236221
ActiveDialog::UnitsRequest(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
237222
StateUpdate::OpenDialog(ActiveDialog::UnitsRequest(new.clone()))

0 commit comments

Comments
 (0)