aboutsummaryrefslogtreecommitdiff
path: root/Canvas.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-25 17:26:20 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-25 17:26:20 +0200
commitb31d7a677481b4a09168c43d203bfd6d7badf577 (patch)
tree13550fa7f33d21aea8a7b03981707db2c08fc9a2 /Canvas.cpp
parentc9f5ac8722190efeb58fda1eec9e6160d5204127 (diff)
implement mementos snapshots
Diffstat (limited to 'Canvas.cpp')
-rw-r--r--Canvas.cpp23
1 files changed, 23 insertions, 0 deletions
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<CanvasDataMemento>(this->data));
+ for (Tile * tile : this->tiles) {
+ data.push_back(make_unique<TileDataMemento>(tile->data));
+ }
+ return data;
+}
+
+void Canvas::restore(const Memories & memories) {
+ for (const unique_ptr<Memento> & memory : memories) {
+ auto canvas = dynamic_cast<CanvasDataMemento *>(memory.get());
+ if (canvas != nullptr) {
+ this->set_data(canvas->data);
+ }
+
+ auto tile = dynamic_cast<TileDataMemento *>(memory.get());
+ if (tile != nullptr) {
+ this->set_tile(tile->data);
+ }
+ }
+}
+