diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 17:26:20 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 17:26:20 +0200 |
commit | b31d7a677481b4a09168c43d203bfd6d7badf577 (patch) | |
tree | 13550fa7f33d21aea8a7b03981707db2c08fc9a2 /Canvas.cpp | |
parent | c9f5ac8722190efeb58fda1eec9e6160d5204127 (diff) |
implement mementos snapshots
Diffstat (limited to 'Canvas.cpp')
-rw-r--r-- | Canvas.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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); + } + } +} + |