diff options
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); + } + } +} + |