From 4cb7ca42003c177e3acc80075d7594e555966106 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 18 Oct 2024 16:37:02 +0200 Subject: fix command design pattern --- ToggleMuseumPauseCommand.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ToggleMuseumPauseCommand.cpp') diff --git a/ToggleMuseumPauseCommand.cpp b/ToggleMuseumPauseCommand.cpp index 57176af..bdd2ef6 100644 --- a/ToggleMuseumPauseCommand.cpp +++ b/ToggleMuseumPauseCommand.cpp @@ -1,13 +1,17 @@ #include "ToggleMuseumPauseCommand.h" #include "Museum.h" -void ToggleMuseumPauseCommand::set(bool paused) { - Museum & museum = this->get_museum(); - museum.set_pause(paused); +ToggleMuseumPauseCommand::ToggleMuseumPauseCommand(Museum & m) : museum(m) { + this->toggle = true; } -void ToggleMuseumPauseCommand::toggle() { - Museum & museum = this->get_museum(); - museum.set_pause(!museum.get_pause()); +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); } -- cgit v1.2.3