Skip to content

Commit

Permalink
refactor: default options now in Default impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ActuallyHappening committed Jul 20, 2023
1 parent d6a25bd commit f940f17
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

## v0.1.13:
- Display window
- Various UI improvements, saving is now seperate window


## v0.1.12:
- Hotkeys for targets/disable
Expand Down
18 changes: 3 additions & 15 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,14 @@ pub struct CurrentOptions {

/// Sets up default resources + sends initial [NewOptions] event
fn setup(mut commands: Commands) {
// let mut board = BoardOptions::new(2, 3);
// board.rm((1, 2));
// board.rm((2, 2));
// board.rm((2, 1));
// board.rm((3, 1));
let board = BoardOptions::new(8, 8);
let mut default_options = CurrentOptions::from_options(Options::default());

let options = Options {
options: board,
selected_start: None,
selected_algorithm: Algorithm::default(),
requires_updating: true,
};
let mut current_options = CurrentOptions::from_options(options);
if let Some(state) = crate::weburl::try_load_state_from_url() {
info!("Loaded state from URL!");
current_options.current.options = state.options;
default_options.current.options = state.options;
}

commands.insert_resource(current_options);
commands.insert_resource(default_options);
}

mod top_level_types {
Expand Down
8 changes: 7 additions & 1 deletion src/board/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
solver::algs::Computation,
MainCamera, ProgramState,
};
use bevy::transform::commands;
use bevy_egui::{
egui::{Color32, Pos2, RichText, Ui},
*,
Expand Down Expand Up @@ -96,13 +97,18 @@ impl VizOptions {
mut viz_options: ResMut<VizOptions>,
mut contexts: EguiContexts,
mut to_reload: ResMut<CurrentOptions>,

markers: Query<Entity, (With<MarkerMarker>, With<ChessPoint>)>,
mut commands: Commands,
) {
egui::Window::new("viz_options_ui")
egui::Window::new("Visualization options")
.default_pos(Pos2::new(4200., 4200.))
.show(contexts.ctx_mut(), |ui| {
ui.heading("Visualization options:");

let copy = *viz_options;


(*viz_options).render(ui);
if *viz_options != copy {
(*to_reload).requires_updating();
Expand Down
14 changes: 14 additions & 0 deletions src/solver/algs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ pub struct Options {
pub selected_start: Option<ChessPoint>,
pub selected_algorithm: Algorithm,

// ignored by hash
pub show_markers: bool,
#[derivative(PartialEq = "ignore")]
// must be ignored by Hash
pub requires_updating: bool,
Expand All @@ -147,6 +149,18 @@ impl std::hash::Hash for Options {
}
}

impl Default for Options {
fn default() -> Self {
Options {
options: BoardOptions::default(),
selected_start: None,
selected_algorithm: Algorithm::default(),
requires_updating: true,
show_markers: true,
}
}
}

impl Deref for Options {
type Target = BoardOptions;

Expand Down
6 changes: 6 additions & 0 deletions src/solver/boardoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct BoardOptions {
options: Vec<Vec<CellOption>>,
}

impl Default for BoardOptions {
fn default() -> Self {
Self::new(8, 8)
}
}

#[derive(EnumIs)]
pub enum TargetRestriction {
/// All cells are endable.
Expand Down

0 comments on commit f940f17

Please sign in to comment.