diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-21 17:54:56 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-21 17:54:56 +0200 |
commit | 10ce9f45b9551dc103272c2b2374db1c1e3b8bcb (patch) | |
tree | 4fba15ce11c42dbfadca5cf6ff7a4c0b774ff507 | |
parent | 90652f512e9621e0dfac497439c7c80bf113d9d5 (diff) |
add ControlBooleanCommand
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | ControlBooleanCommand.cpp | 16 | ||||
-rw-r--r-- | ControlBooleanCommand.h | 18 | ||||
-rw-r--r-- | Museum.cpp | 4 | ||||
-rw-r--r-- | Museum.h | 4 | ||||
-rw-r--r-- | ToggleArtistVisibilityCommand.cpp | 8 | ||||
-rw-r--r-- | ToggleArtistVisibilityCommand.h | 10 | ||||
-rw-r--r-- | ToggleMuseumPauseCommand.cpp | 16 | ||||
-rw-r--r-- | ToggleMuseumPauseCommand.h | 12 | ||||
-rw-r--r-- | ViewController.h | 5 |
10 files changed, 45 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 897495e..9f45d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ add_executable(main TimeTravelCommand.cpp CollisionContext.cpp QuadTree.cpp + ControlBooleanCommand.cpp ) target_link_libraries(main diff --git a/ControlBooleanCommand.cpp b/ControlBooleanCommand.cpp new file mode 100644 index 0000000..411b428 --- /dev/null +++ b/ControlBooleanCommand.cpp @@ -0,0 +1,16 @@ +#include "ControlBooleanCommand.h" + +ControlBooleanCommand::ControlBooleanCommand(bool & t) : target(t) { + this->toggle = true; +} + +ControlBooleanCommand::ControlBooleanCommand(bool & t, bool set) : target(t) { + this->toggle = false; + this->value = set; +} + +void ControlBooleanCommand::execute() { + if (this->toggle) this->value = !this->target; + this->target = this->value; +} + diff --git a/ControlBooleanCommand.h b/ControlBooleanCommand.h new file mode 100644 index 0000000..2067e37 --- /dev/null +++ b/ControlBooleanCommand.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Command.h" + +class ControlBooleanCommand : public Command { +public: + ControlBooleanCommand(bool & target); + ControlBooleanCommand(bool & target, bool set); + +public: + virtual void execute(); + +private: + bool toggle = true; + bool value; + bool & target; +}; + @@ -48,7 +48,3 @@ void Museum::work() { } } -void Museum::set_pause(bool paused) { - this->paused = paused; -} - @@ -20,14 +20,12 @@ public: CollisionContext collision; public: - void set_pause(bool paused); - bool get_pause() { return this->paused; } + bool paused = true; void update(); void skip_forward(); void skip_backward(); private: - bool paused = true; unsigned long jump = 0; private: diff --git a/ToggleArtistVisibilityCommand.cpp b/ToggleArtistVisibilityCommand.cpp index 17583de..3c5d08b 100644 --- a/ToggleArtistVisibilityCommand.cpp +++ b/ToggleArtistVisibilityCommand.cpp @@ -1,11 +1,5 @@ #include "ToggleArtistVisibilityCommand.h" #include "ViewController.h" -ToggleArtistVisibilityCommand::ToggleArtistVisibilityCommand(ViewController & c) : controller(c) { -} - -void ToggleArtistVisibilityCommand::execute() { - bool value = !this->controller.get_artists_visible(); - this->controller.set_artists_visible(value); -} +ToggleArtistVisibilityCommand::ToggleArtistVisibilityCommand(ViewController & c) : ControlBooleanCommand(c.draw_artists) { } diff --git a/ToggleArtistVisibilityCommand.h b/ToggleArtistVisibilityCommand.h index 1653d08..62df654 100644 --- a/ToggleArtistVisibilityCommand.h +++ b/ToggleArtistVisibilityCommand.h @@ -1,17 +1,11 @@ #pragma once -#include "Command.h" +#include "ControlBooleanCommand.h" class ViewController; -class ToggleArtistVisibilityCommand : public Command { +class ToggleArtistVisibilityCommand : public ControlBooleanCommand { public: ToggleArtistVisibilityCommand(ViewController & c); - -public: - virtual void execute(); - -private: - ViewController & controller; }; diff --git a/ToggleMuseumPauseCommand.cpp b/ToggleMuseumPauseCommand.cpp index bdd2ef6..82e2d30 100644 --- a/ToggleMuseumPauseCommand.cpp +++ b/ToggleMuseumPauseCommand.cpp @@ -1,17 +1,7 @@ #include "ToggleMuseumPauseCommand.h" +#include "ControlBooleanCommand.h" #include "Museum.h" -ToggleMuseumPauseCommand::ToggleMuseumPauseCommand(Museum & m) : museum(m) { - this->toggle = true; -} - -ToggleMuseumPauseCommand::ToggleMuseumPauseCommand(Museum & m, bool set) : museum(m) { - this->toggle = false; - this->value = set; -} - -void ToggleMuseumPauseCommand::execute() { - if (this->toggle) this->value = !this->museum.get_pause(); - this->museum.set_pause(this->value); -} +ToggleMuseumPauseCommand::ToggleMuseumPauseCommand(Museum & m) : ControlBooleanCommand(m.paused) { } +ToggleMuseumPauseCommand::ToggleMuseumPauseCommand(Museum & m, bool set) : ControlBooleanCommand(m.paused, set) { } diff --git a/ToggleMuseumPauseCommand.h b/ToggleMuseumPauseCommand.h index 40e0b24..0bfb27b 100644 --- a/ToggleMuseumPauseCommand.h +++ b/ToggleMuseumPauseCommand.h @@ -1,20 +1,12 @@ #pragma once -#include "Command.h" +#include "ControlBooleanCommand.h" class Museum; -class ToggleMuseumPauseCommand : public Command { +class ToggleMuseumPauseCommand : public ControlBooleanCommand { public: ToggleMuseumPauseCommand(Museum & m); ToggleMuseumPauseCommand(Museum & m, bool set); - -public: - virtual void execute(); - -private: - Museum & museum; - bool toggle = true; - bool value; }; diff --git a/ViewController.h b/ViewController.h index fb15fde..708079b 100644 --- a/ViewController.h +++ b/ViewController.h @@ -21,10 +21,6 @@ public: void ev_mousedown(MouseCode code); void ev_mousemove(unsigned x, unsigned y); -public: - void set_artists_visible(bool visible) { this->draw_artists = visible; } - bool get_artists_visible() { return this->draw_artists; } - private: void update_size(); void update_tiles(); @@ -38,6 +34,7 @@ private: View & view; const Command * cmd_base = nullptr; +public: bool draw_artists = true; bool draw_pathfinding = false; bool draw_quadtree = true; |