From b31d7a677481b4a09168c43d203bfd6d7badf577 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 17:26:20 +0200 Subject: implement mementos snapshots --- Canvas.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Canvas.cpp') diff --git a/Canvas.cpp b/Canvas.cpp index b7cc8a5..86b5bec 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -109,3 +109,26 @@ void Canvas::update_tiles() { } } +Memories Canvas::save() { + Memories data; + data.push_back(make_unique(this->data)); + for (Tile * tile : this->tiles) { + data.push_back(make_unique(tile->data)); + } + return data; +} + +void Canvas::restore(const Memories & memories) { + for (const unique_ptr & memory : memories) { + auto canvas = dynamic_cast(memory.get()); + if (canvas != nullptr) { + this->set_data(canvas->data); + } + + auto tile = dynamic_cast(memory.get()); + if (tile != nullptr) { + this->set_tile(tile->data); + } + } +} + -- cgit v1.2.3