aboutsummaryrefslogtreecommitdiff
path: root/Canvas.cpp
diff options
context:
space:
mode:
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);
+ }
+ }
+}
+