aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ArtistVisibilityCommand.cpp6
-rw-r--r--ArtistVisibilityCommand.h2
-rw-r--r--BlueTileBehavior.cpp20
-rw-r--r--BlueTileBehavior.h12
-rw-r--r--CSVParser.cpp8
-rw-r--r--CSVParser.h8
-rw-r--r--Deserializer.cpp16
-rw-r--r--Deserializer.h4
-rw-r--r--FileReader.cpp14
-rw-r--r--FileReader.h18
-rw-r--r--FileStrategy.cpp6
-rw-r--r--FileStrategy.h14
-rw-r--r--GrayTileBehavior.cpp16
-rw-r--r--GrayTileBehavior.h12
-rw-r--r--HTTPFile.cpp18
-rw-r--r--HTTPFile.h14
-rw-r--r--LoadFilesCommand.cpp16
-rw-r--r--LocalFile.cpp22
-rw-r--r--LocalFile.h14
-rw-r--r--MuseumPauseCommand.cpp6
-rw-r--r--MuseumPauseCommand.h2
-rw-r--r--NullTileBehavior.cpp4
-rw-r--r--NullTileBehavior.h8
-rw-r--r--OpenFileGUICommand.cpp4
-rw-r--r--Parser.cpp14
-rw-r--r--Parser.h14
-rw-r--r--ParserStrategy.h10
-rw-r--r--RedTileBehavior.cpp18
-rw-r--r--RedTileBehavior.h12
-rw-r--r--TXTParser.cpp8
-rw-r--r--TXTParser.h8
-rw-r--r--Tile.cpp8
-rw-r--r--Tile.h4
-rw-r--r--TileAppearance.cpp12
-rw-r--r--TileAppearance.h2
-rw-r--r--TileBehavior.cpp10
-rw-r--r--TileBehavior.h10
-rw-r--r--TileBehaviorStrategy.cpp8
-rw-r--r--TileBehaviorStrategy.h8
-rw-r--r--TileDecayCommand.cpp4
-rw-r--r--TileDecayCommand.h2
-rw-r--r--ViewController.cpp12
-rw-r--r--XMLParser.cpp8
-rw-r--r--XMLParser.h8
-rw-r--r--YellowTileBehavior.cpp16
-rw-r--r--YellowTileBehavior.h12
-rw-r--r--docs/class-diag.puml122
47 files changed, 297 insertions, 297 deletions
diff --git a/ArtistVisibilityCommand.cpp b/ArtistVisibilityCommand.cpp
index b442daf..6c22dbc 100644
--- a/ArtistVisibilityCommand.cpp
+++ b/ArtistVisibilityCommand.cpp
@@ -1,12 +1,12 @@
-#include "ArtistVisibilityCommand.h"
+#include "ToggleArtistVisibilityCommand.h"
#include "ViewController.h"
-void ArtistVisibilityCommand::set(bool visible) {
+void ToggleArtistVisibilityCommand::set(bool visible) {
ViewController & controller = this->get_controller();
controller.set_artists_visible(visible);
}
-void ArtistVisibilityCommand::toggle() {
+void ToggleArtistVisibilityCommand::toggle() {
ViewController & controller = this->get_controller();
controller.set_artists_visible(!controller.get_artists_visible());
}
diff --git a/ArtistVisibilityCommand.h b/ArtistVisibilityCommand.h
index 416c801..47e2158 100644
--- a/ArtistVisibilityCommand.h
+++ b/ArtistVisibilityCommand.h
@@ -2,7 +2,7 @@
#include "Command.h"
-class ArtistVisibilityCommand : public Command {
+class ToggleArtistVisibilityCommand : public Command {
using Command::Command;
public:
diff --git a/BlueTileBehavior.cpp b/BlueTileBehavior.cpp
index a2b3422..d934d4b 100644
--- a/BlueTileBehavior.cpp
+++ b/BlueTileBehavior.cpp
@@ -1,15 +1,15 @@
#include <memory>
-#include "BlueTileBehavior.h"
-#include "YellowTileBehavior.h"
+#include "SetNeighborTileBehavior.h"
+#include "CreateArtistTileBehavior.h"
#include "Artist.h"
#include "Tile.h"
using namespace std;
-BlueTileBehavior BlueTileBehavior::instance { BlueTileBehavior::type };
+SetNeighborTileBehavior SetNeighborTileBehavior::instance { SetNeighborTileBehavior::type };
-void BlueTileBehavior::step(Artist * artist) {
+void SetNeighborTileBehavior::step(Artist * artist) {
this->interactions++;
if (dx != 0 || dy != 0) return;
if (artist == nullptr) return;
@@ -24,21 +24,21 @@ static void update_neighbor(Tile & here, int dx, int dy) {
if (neighbor == &here) return;
if (neighbor == nullptr) return;
- neighbor->set_type(BlueTileBehavior::type);
+ neighbor->set_type(SetNeighborTileBehavior::type);
}
-void BlueTileBehavior::update(Tile & tile) {
+void SetNeighborTileBehavior::update(Tile & tile) {
if (this->interactions < 1) return;
update_neighbor(tile, this->dx, this->dy);
update_neighbor(tile, -this->dx, -this->dy);
- tile.set_type(YellowTileBehavior::type);
+ tile.set_type(CreateArtistTileBehavior::type);
}
-unique_ptr<TileBehaviorStrategy> BlueTileBehavior::clone(Museum & museum) {
- auto instance = new BlueTileBehavior();
+unique_ptr<TileBehavior> SetNeighborTileBehavior::clone(Museum & museum) {
+ auto instance = new SetNeighborTileBehavior();
instance->museum = &museum;
- return unique_ptr<TileBehaviorStrategy>(instance);
+ return unique_ptr<TileBehavior>(instance);
}
diff --git a/BlueTileBehavior.h b/BlueTileBehavior.h
index 15257b3..d316420 100644
--- a/BlueTileBehavior.h
+++ b/BlueTileBehavior.h
@@ -1,19 +1,19 @@
#pragma once
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
-class BlueTileBehavior : public TileBehaviorStrategy {
+class SetNeighborTileBehavior : public TileBehavior {
public:
virtual void step(Artist *);
virtual void update(Tile &);
- virtual std::unique_ptr<TileBehaviorStrategy> clone(Museum &);
+ virtual std::unique_ptr<TileBehavior> clone(Museum &);
static constexpr const char * type = "B";
private:
- using TileBehaviorStrategy::TileBehaviorStrategy;
- static BlueTileBehavior instance;
- BlueTileBehavior() = default;
+ using TileBehavior::TileBehavior;
+ static SetNeighborTileBehavior instance;
+ SetNeighborTileBehavior() = default;
private:
int dx = 0;
diff --git a/CSVParser.cpp b/CSVParser.cpp
index 7d52cd7..824d5f4 100644
--- a/CSVParser.cpp
+++ b/CSVParser.cpp
@@ -6,16 +6,16 @@
#include "CSVParser.h"
#include "Exception.h"
-#include "Parser.h"
+#include "ParserFactory.h"
using namespace std;
CSVParser CSVParser::instance {};
CSVParser::CSVParser() {
- Parser::register_strategy(this);
+ ParserFactory::register_strategy(this);
}
-unsigned int CSVParser::heuristic(FileStrategy & f) {
+unsigned int CSVParser::heuristic(FileReader & f) {
const string content = f.read();
int global_columns = 0;
int columns = 1;
@@ -41,7 +41,7 @@ static size_t header_idx(vector<string> header, string field) {
return iter - header.begin();
}
-void CSVParser::parse(FileStrategy & f, Deserializer & d) {
+void CSVParser::parse(FileReader & f, MuseumDeserializer & d) {
vector<vector<string>> table = {};
istringstream rows(f.read());
diff --git a/CSVParser.h b/CSVParser.h
index 6698645..660cc18 100644
--- a/CSVParser.h
+++ b/CSVParser.h
@@ -1,11 +1,11 @@
#pragma once
-#include "ParserStrategy.h"
+#include "Parser.h"
-class CSVParser : public ParserStrategy {
+class CSVParser : public Parser {
public:
- virtual void parse(FileStrategy & f, Deserializer & d);
- virtual unsigned int heuristic(FileStrategy & f);
+ virtual void parse(FileReader & f, MuseumDeserializer & d);
+ virtual unsigned int heuristic(FileReader & f);
private:
static CSVParser instance;
diff --git a/Deserializer.cpp b/Deserializer.cpp
index 7215dd4..fca8d50 100644
--- a/Deserializer.cpp
+++ b/Deserializer.cpp
@@ -1,22 +1,22 @@
-#include "Deserializer.h"
-#include "TileAppearance.h"
+#include "MuseumDeserializer.h"
+#include "TileColorFactory.h"
-Deserializer::Deserializer(Museum & museum) : museum(museum) { }
+MuseumDeserializer::MuseumDeserializer(Museum & museum) : museum(museum) { }
-void Deserializer::add_artist(ArtistData data) {
+void MuseumDeserializer::add_artist(ArtistData data) {
this->museum.people.add_artist(data);
}
-void Deserializer::set_canvas(CanvasData data) {
+void MuseumDeserializer::set_canvas(CanvasData data) {
this->museum.canvas.set_data(data);
}
-void Deserializer::set_tile(TileData data) {
+void MuseumDeserializer::set_tile(TileData data) {
this->museum.canvas.set_tile(data);
}
-void Deserializer::add_type(std::string type, Color color, unsigned int weight) {
+void MuseumDeserializer::add_type(std::string type, Color color, unsigned int weight) {
if (type.length() == 0) return;
- TileAppearance::register_color(type, color);
+ TileColorFactory::register_color(type, color);
}
diff --git a/Deserializer.h b/Deserializer.h
index 50ae57d..7fecf56 100644
--- a/Deserializer.h
+++ b/Deserializer.h
@@ -6,9 +6,9 @@
#include "CanvasData.h"
#include "Color.h"
-class Deserializer {
+class MuseumDeserializer {
public:
- Deserializer(Museum & m);
+ MuseumDeserializer(Museum & m);
public:
void add_type(std::string type, Color color, unsigned int weight);
diff --git a/FileReader.cpp b/FileReader.cpp
index d2d888f..4b72b11 100644
--- a/FileReader.cpp
+++ b/FileReader.cpp
@@ -1,27 +1,27 @@
#include <memory>
+#include "FileReaderFactory.h"
#include "FileReader.h"
-#include "FileStrategy.h"
using namespace std;
-unique_ptr<FileStrategy> FileReader::open(const std::string url) {
- FileStrategy * reader = find_reader(url)->clone();
+unique_ptr<FileReader> FileReaderFactory::open(const std::string url) {
+ FileReader * reader = find_reader(url)->clone();
reader->open(url);
- return unique_ptr<FileStrategy>(reader);
+ return unique_ptr<FileReader>(reader);
}
-void FileReader::register_strategy(const std::string type, const FileStrategy * node) {
+void FileReaderFactory::register_strategy(const std::string type, const FileReader * node) {
static FactoryMap & map = get_map();
map[type] = node;
}
-FactoryMap & FileReader::get_map() {
+FactoryMap & FileReaderFactory::get_map() {
static FactoryMap map;
return map;
}
-const FileStrategy * FileReader::find_reader(const std::string type) {
+const FileReader * FileReaderFactory::find_reader(const std::string type) {
static FactoryMap & map = get_map();
// try to find protocol by prefix
diff --git a/FileReader.h b/FileReader.h
index 1cf62ba..0829985 100644
--- a/FileReader.h
+++ b/FileReader.h
@@ -4,24 +4,24 @@
#include <map>
#include <memory>
-#include "FileStrategy.h"
+#include "FileReader.h"
-using FactoryMap = std::map<std::string, const FileStrategy *>;
+using FactoryMap = std::map<std::string, const FileReader *>;
-class FileReader {
+class FileReaderFactory {
public:
- static std::unique_ptr<FileStrategy> open(const std::string url);
+ static std::unique_ptr<FileReader> open(const std::string url);
private:
- FileReader() = default;
- virtual ~FileReader() = default;
+ FileReaderFactory() = default;
+ virtual ~FileReaderFactory() = default;
private:
- static void register_strategy(const std::string type, const FileStrategy * node);
+ static void register_strategy(const std::string type, const FileReader * node);
static FactoryMap & get_map();
- static const FileStrategy * find_reader(const std::string type);
+ static const FileReader * find_reader(const std::string type);
private:
- friend FileStrategy;
+ friend FileReader;
};
diff --git a/FileStrategy.cpp b/FileStrategy.cpp
index 777aef5..b76de50 100644
--- a/FileStrategy.cpp
+++ b/FileStrategy.cpp
@@ -1,9 +1,9 @@
#include <string>
-#include "FileStrategy.h"
#include "FileReader.h"
+#include "FileReaderFactory.h"
-FileStrategy::FileStrategy(const std::string protocol) {
- FileReader::register_strategy(protocol, this);
+FileReader::FileReader(const std::string protocol) {
+ FileReaderFactory::register_strategy(protocol, this);
}
diff --git a/FileStrategy.h b/FileStrategy.h
index 6338d71..f896ec8 100644
--- a/FileStrategy.h
+++ b/FileStrategy.h
@@ -1,10 +1,10 @@
#pragma once
-class FileReader;
+class FileReaderFactory;
#include <string>
-class FileStrategy {
+class FileReader {
protected:
virtual void open(const std::string url) = 0;
public:
@@ -12,14 +12,14 @@ public:
virtual const std::string read() = 0;
public:
- virtual ~FileStrategy() = default;
+ virtual ~FileReader() = default;
protected:
- FileStrategy() = default;
- virtual FileStrategy * clone() const = 0;
+ FileReader() = default;
+ virtual FileReader * clone() const = 0;
protected:
- FileStrategy(const std::string protocol);
- friend FileReader;
+ FileReader(const std::string protocol);
+ friend FileReaderFactory;
};
diff --git a/GrayTileBehavior.cpp b/GrayTileBehavior.cpp
index 257c32d..2023bb8 100644
--- a/GrayTileBehavior.cpp
+++ b/GrayTileBehavior.cpp
@@ -1,21 +1,21 @@
#include <memory>
-#include "GrayTileBehavior.h"
-#include "RedTileBehavior.h"
+#include "StepTileBehavior.h"
+#include "DeleteArtistTileBehavior.h"
#include "Tile.h"
using namespace std;
-GrayTileBehavior GrayTileBehavior::instance { GrayTileBehavior::type };
+StepTileBehavior StepTileBehavior::instance { StepTileBehavior::type };
-void GrayTileBehavior::update(Tile & tile) {
+void StepTileBehavior::update(Tile & tile) {
if (this->interactions < 3) return;
- tile.set_type(RedTileBehavior::type);
+ tile.set_type(DeleteArtistTileBehavior::type);
}
-unique_ptr<TileBehaviorStrategy> GrayTileBehavior::clone(Museum & museum) {
- auto instance = new GrayTileBehavior();
+unique_ptr<TileBehavior> StepTileBehavior::clone(Museum & museum) {
+ auto instance = new StepTileBehavior();
instance->museum = &museum;
- return unique_ptr<TileBehaviorStrategy>(instance);
+ return unique_ptr<TileBehavior>(instance);
}
diff --git a/GrayTileBehavior.h b/GrayTileBehavior.h
index 72c3fd8..d044fe7 100644
--- a/GrayTileBehavior.h
+++ b/GrayTileBehavior.h
@@ -1,17 +1,17 @@
#pragma once
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
-class GrayTileBehavior : public TileBehaviorStrategy {
+class StepTileBehavior : public TileBehavior {
public:
virtual void update(Tile &);
- virtual std::unique_ptr<TileBehaviorStrategy> clone(Museum &);
+ virtual std::unique_ptr<TileBehavior> clone(Museum &);
static constexpr const char * type = "G";
private:
- using TileBehaviorStrategy::TileBehaviorStrategy;
- static GrayTileBehavior instance;
- GrayTileBehavior() = default;
+ using TileBehavior::TileBehavior;
+ static StepTileBehavior instance;
+ StepTileBehavior() = default;
};
diff --git a/HTTPFile.cpp b/HTTPFile.cpp
index 6da0919..d7f5dd4 100644
--- a/HTTPFile.cpp
+++ b/HTTPFile.cpp
@@ -1,26 +1,26 @@
#include <cpr/cpr.h>
-#include "HTTPFile.h"
+#include "HTTPFileReader.h"
-HTTPFile HTTPFile::instance(protocol);
+HTTPFileReader HTTPFileReader::instance(protocol);
-void HTTPFile::open(const std::string url) {
+void HTTPFileReader::open(const std::string url) {
_res = cpr::Get(cpr::Url{url});
}
-void HTTPFile::close() { }
+void HTTPFileReader::close() { }
-const std::string HTTPFile::read() {
+const std::string HTTPFileReader::read() {
return _res.text.data();
}
-HTTPFile::~HTTPFile() {
+HTTPFileReader::~HTTPFileReader() {
this->close();
}
-HTTPFile * HTTPFile::clone() const {
- return new HTTPFile(this);
+HTTPFileReader * HTTPFileReader::clone() const {
+ return new HTTPFileReader(this);
}
-HTTPFile::HTTPFile(const HTTPFile *) : FileStrategy() { }
+HTTPFileReader::HTTPFileReader(const HTTPFileReader *) : FileReader() { }
diff --git a/HTTPFile.h b/HTTPFile.h
index 39f058b..4b05e18 100644
--- a/HTTPFile.h
+++ b/HTTPFile.h
@@ -2,9 +2,9 @@
#include <cpr/cpr.h>
-#include "FileStrategy.h"
+#include "FileReader.h"
-class HTTPFile : FileStrategy {
+class HTTPFileReader : FileReader {
protected:
virtual void open(const std::string url);
public:
@@ -12,16 +12,16 @@ public:
virtual const std::string read();
public:
- virtual ~HTTPFile();
+ virtual ~HTTPFileReader();
private:
- HTTPFile(const HTTPFile *);
- virtual HTTPFile * clone() const;
+ HTTPFileReader(const HTTPFileReader *);
+ virtual HTTPFileReader * clone() const;
private:
- using FileStrategy::FileStrategy;
+ using FileReader::FileReader;
constexpr static const std::string protocol = "https://";
- static HTTPFile instance;
+ static HTTPFileReader instance;
private:
cpr::Response _res;
diff --git a/LoadFilesCommand.cpp b/LoadFilesCommand.cpp
index 9a0ca08..ae9f30a 100644
--- a/LoadFilesCommand.cpp
+++ b/LoadFilesCommand.cpp
@@ -2,12 +2,12 @@
#include <string>
#include "LoadFilesCommand.h"
-#include "Deserializer.h"
+#include "MuseumDeserializer.h"
#include "Exception.h"
+#include "FileReaderFactory.h"
#include "FileReader.h"
-#include "FileStrategy.h"
-#include "MuseumPauseCommand.h"
-#include "Parser.h"
+#include "ToggleMuseumPauseCommand.h"
+#include "ParserFactory.h"
using namespace std;
@@ -28,13 +28,13 @@ void LoadFilesCommand::execute(vector<string> files) {
}
void LoadFilesCommand::load_files(vector<string> files) {
- MuseumPauseCommand(this).set(true);
+ ToggleMuseumPauseCommand(this).set(true);
- Deserializer deserializer { this->get_museum() };
+ MuseumDeserializer deserializer { this->get_museum() };
for (string url : files) {
- unique_ptr<FileStrategy> file = FileReader::open(url);
+ unique_ptr<FileReader> file = FileReaderFactory::open(url);
try {
- Parser::parse(*file, deserializer);
+ ParserFactory::parse(*file, deserializer);
} catch (Exception & e) {
throw Exception("parser error: %s (%s)", e.what(), url.c_str());
}
diff --git a/LocalFile.cpp b/LocalFile.cpp
index d5bad67..1f9d574 100644
--- a/LocalFile.cpp
+++ b/LocalFile.cpp
@@ -1,12 +1,12 @@
#include <cstdio>
#include <iterator>
-#include "LocalFile.h"
+#include "LocalFileReader.h"
#include "Exception.h"
-LocalFile LocalFile::instance(protocol);
+LocalFileReader LocalFileReader::instance(protocol);
-void LocalFile::open(const std::string url) {
+void LocalFileReader::open(const std::string url) {
std::string path = url;
if (path.starts_with(protocol))
path = path.substr(protocol.size());
@@ -16,22 +16,22 @@ void LocalFile::open(const std::string url) {
throw Exception("cannot open file://%s\n", path.c_str());
}
-void LocalFile::close() {
+void LocalFileReader::close() {
if (this->file == nullptr) return;
if (this->file->is_open())
this->file->close();
}
-const std::string LocalFile::read() {
+const std::string LocalFileReader::read() {
if (this->content != nullptr)
return *this->content;
if (this->file == nullptr)
- throw Exception("FileStrategy read after destructor\n");
+ throw Exception("FileReader read after destructor\n");
if (!this->file->is_open())
- throw Exception("FileStrategy read after close\n");
+ throw Exception("FileReader read after close\n");
this->content = new std::string(
std::istreambuf_iterator<char>(*this->file),
@@ -41,7 +41,7 @@ const std::string LocalFile::read() {
return *this->content;
}
-LocalFile::~LocalFile() {
+LocalFileReader::~LocalFileReader() {
this->close();
if (this->file != nullptr) {
@@ -55,9 +55,9 @@ LocalFile::~LocalFile() {
}
}
-LocalFile * LocalFile::clone() const {
- return new LocalFile(this);
+LocalFileReader * LocalFileReader::clone() const {
+ return new LocalFileReader(this);
}
-LocalFile::LocalFile(const LocalFile *) : FileStrategy() { }
+LocalFileReader::LocalFileReader(const LocalFileReader *) : FileReader() { }
diff --git a/LocalFile.h b/LocalFile.h
index c80d0f4..6ea4f84 100644
--- a/LocalFile.h
+++ b/LocalFile.h
@@ -2,9 +2,9 @@
#include <fstream>
-#include "FileStrategy.h"
+#include "FileReader.h"
-class LocalFile : FileStrategy {
+class LocalFileReader : FileReader {
protected:
virtual void open(const std::string url);
public:
@@ -12,16 +12,16 @@ public:
virtual const std::string read();
public:
- virtual ~LocalFile();
+ virtual ~LocalFileReader();
private:
- LocalFile(const LocalFile *);
- virtual LocalFile * clone() const;
+ LocalFileReader(const LocalFileReader *);
+ virtual LocalFileReader * clone() const;
private:
- using FileStrategy::FileStrategy;
+ using FileReader::FileReader;
constexpr static const std::string protocol = "file://";
- static LocalFile instance;
+ static LocalFileReader instance;
private:
std::ifstream * file = nullptr;
diff --git a/MuseumPauseCommand.cpp b/MuseumPauseCommand.cpp
index e3d8556..57176af 100644
--- a/MuseumPauseCommand.cpp
+++ b/MuseumPauseCommand.cpp
@@ -1,12 +1,12 @@
-#include "MuseumPauseCommand.h"
+#include "ToggleMuseumPauseCommand.h"
#include "Museum.h"
-void MuseumPauseCommand::set(bool paused) {
+void ToggleMuseumPauseCommand::set(bool paused) {
Museum & museum = this->get_museum();
museum.set_pause(paused);
}
-void MuseumPauseCommand::toggle() {
+void ToggleMuseumPauseCommand::toggle() {
Museum & museum = this->get_museum();
museum.set_pause(!museum.get_pause());
}
diff --git a/MuseumPauseCommand.h b/MuseumPauseCommand.h
index 442a22a..15d1388 100644
--- a/MuseumPauseCommand.h
+++ b/MuseumPauseCommand.h
@@ -2,7 +2,7 @@
#include "Command.h"
-class MuseumPauseCommand : public Command {
+class ToggleMuseumPauseCommand : public Command {
using Command::Command;
public:
diff --git a/NullTileBehavior.cpp b/NullTileBehavior.cpp
index 3e671bc..7a056a4 100644
--- a/NullTileBehavior.cpp
+++ b/NullTileBehavior.cpp
@@ -8,9 +8,9 @@ NullTileBehavior NullTileBehavior::instance { NullTileBehavior::type };
void NullTileBehavior::update(Tile &) { }
-unique_ptr<TileBehaviorStrategy> NullTileBehavior::clone(Museum & museum) {
+unique_ptr<TileBehavior> NullTileBehavior::clone(Museum & museum) {
auto instance = new NullTileBehavior();
instance->museum = &museum;
- return unique_ptr<TileBehaviorStrategy>(instance);
+ return unique_ptr<TileBehavior>(instance);
}
diff --git a/NullTileBehavior.h b/NullTileBehavior.h
index 9b52c48..72aa196 100644
--- a/NullTileBehavior.h
+++ b/NullTileBehavior.h
@@ -1,16 +1,16 @@
#pragma once
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
-class NullTileBehavior : public TileBehaviorStrategy {
+class NullTileBehavior : public TileBehavior {
public:
virtual void update(Tile &);
- virtual std::unique_ptr<TileBehaviorStrategy> clone(Museum &);
+ virtual std::unique_ptr<TileBehavior> clone(Museum &);
static constexpr const char * type = "";
private:
- using TileBehaviorStrategy::TileBehaviorStrategy;
+ using TileBehavior::TileBehavior;
static NullTileBehavior instance;
NullTileBehavior() = default;
};
diff --git a/OpenFileGUICommand.cpp b/OpenFileGUICommand.cpp
index 1ea2c2f..13751b2 100644
--- a/OpenFileGUICommand.cpp
+++ b/OpenFileGUICommand.cpp
@@ -4,7 +4,7 @@
#include "OpenFileGUICommand.h"
#include "Exception.h"
#include "LoadFilesCommand.h"
-#include "MuseumPauseCommand.h"
+#include "ToggleMuseumPauseCommand.h"
#include "View.h"
using namespace std;
@@ -12,7 +12,7 @@ using namespace std;
void OpenFileGUICommand::execute() {
Museum * museum = &this->get_museum();
- MuseumPauseCommand(*museum).set(true);
+ ToggleMuseumPauseCommand(*museum).set(true);
this->get_view().dialog_file([](vector<string> files, void * data) -> void {
Museum * museum = static_cast<Museum *>(data);
try {
diff --git a/Parser.cpp b/Parser.cpp
index 4597a76..49c4d00 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -1,16 +1,16 @@
#include <algorithm>
-#include "Parser.h"
+#include "ParserFactory.h"
#include "Exception.h"
-void Parser::parse(FileStrategy & file, Deserializer & deserializer) {
- auto & col = Parser::get_collection();
+void ParserFactory::parse(FileReader & file, MuseumDeserializer & deserializer) {
+ auto & col = ParserFactory::get_collection();
if (col.size() < 1)
throw Exception("no parsers registered");
unsigned int best_score = 0;
- ParserStrategy * best_strategy = nullptr;
- for (ParserStrategy * strategy : col) {
+ Parser * best_strategy = nullptr;
+ for (Parser * strategy : col) {
unsigned int score = strategy->heuristic(file);
if (score <= best_score) continue;
@@ -24,8 +24,8 @@ void Parser::parse(FileStrategy & file, Deserializer & deserializer) {
best_strategy->parse(file, deserializer);
}
-void Parser::register_strategy(ParserStrategy * ps) {
- auto & col = Parser::get_collection();
+void ParserFactory::register_strategy(Parser * ps) {
+ auto & col = ParserFactory::get_collection();
if (std::find(col.begin(), col.end(), ps) != col.end()) return;
col.push_back(ps);
}
diff --git a/Parser.h b/Parser.h
index 38ce658..5430366 100644
--- a/Parser.h
+++ b/Parser.h
@@ -1,15 +1,15 @@
#pragma once
-#include "FileStrategy.h"
-#include "Deserializer.h"
-#include "ParserStrategy.h"
+#include "FileReader.h"
+#include "MuseumDeserializer.h"
+#include "Parser.h"
-class Parser {
- typedef std::vector<ParserStrategy*> ParserCollection;
+class ParserFactory {
+ typedef std::vector<Parser*> ParserCollection;
public:
- static void parse(FileStrategy & f, Deserializer & d);
- static void register_strategy(ParserStrategy * p);
+ static void parse(FileReader & f, MuseumDeserializer & d);
+ static void register_strategy(Parser * p);
private:
static ParserCollection & get_collection() {
diff --git a/ParserStrategy.h b/ParserStrategy.h
index 26dc347..01efb3c 100644
--- a/ParserStrategy.h
+++ b/ParserStrategy.h
@@ -1,11 +1,11 @@
#pragma once
-#include "FileStrategy.h"
-#include "Deserializer.h"
+#include "FileReader.h"
+#include "MuseumDeserializer.h"
-class ParserStrategy {
+class Parser {
public:
- virtual void parse(FileStrategy & f, Deserializer & d) = 0;
- virtual unsigned int heuristic(FileStrategy & f) = 0;
+ virtual void parse(FileReader & f, MuseumDeserializer & d) = 0;
+ virtual unsigned int heuristic(FileReader & f) = 0;
};
diff --git a/RedTileBehavior.cpp b/RedTileBehavior.cpp
index 0f0426d..091a251 100644
--- a/RedTileBehavior.cpp
+++ b/RedTileBehavior.cpp
@@ -1,28 +1,28 @@
#include <memory>
-#include "RedTileBehavior.h"
-#include "BlueTileBehavior.h"
+#include "DeleteArtistTileBehavior.h"
+#include "SetNeighborTileBehavior.h"
#include "Tile.h"
#include "Museum.h"
using namespace std;
-RedTileBehavior RedTileBehavior::instance { RedTileBehavior::type };
+DeleteArtistTileBehavior DeleteArtistTileBehavior::instance { DeleteArtistTileBehavior::type };
-void RedTileBehavior::step(Artist * artist) {
+void DeleteArtistTileBehavior::step(Artist * artist) {
this->interactions++;
if (artist != nullptr)
this->museum->people.remove_artist(*artist);
}
-void RedTileBehavior::update(Tile & tile) {
+void DeleteArtistTileBehavior::update(Tile & tile) {
if (this->interactions == 0) return;
- tile.set_type(BlueTileBehavior::type);
+ tile.set_type(SetNeighborTileBehavior::type);
}
-unique_ptr<TileBehaviorStrategy> RedTileBehavior::clone(Museum & museum) {
- auto instance = new RedTileBehavior();
+unique_ptr<TileBehavior> DeleteArtistTileBehavior::clone(Museum & museum) {
+ auto instance = new DeleteArtistTileBehavior();
instance->museum = &museum;
- return unique_ptr<TileBehaviorStrategy>(instance);
+ return unique_ptr<TileBehavior>(instance);
}
diff --git a/RedTileBehavior.h b/RedTileBehavior.h
index b7443c9..0b2b0d4 100644
--- a/RedTileBehavior.h
+++ b/RedTileBehavior.h
@@ -1,19 +1,19 @@
#pragma once
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
-class RedTileBehavior : public TileBehaviorStrategy {
+class DeleteArtistTileBehavior : public TileBehavior {
public:
virtual void step(Artist *);
virtual void update(Tile &);
- virtual std::unique_ptr<TileBehaviorStrategy> clone(Museum &);
+ virtual std::unique_ptr<TileBehavior> clone(Museum &);
static constexpr const char * type = "R";
private:
- using TileBehaviorStrategy::TileBehaviorStrategy;
- static RedTileBehavior instance;
- RedTileBehavior() = default;
+ using TileBehavior::TileBehavior;
+ static DeleteArtistTileBehavior instance;
+ DeleteArtistTileBehavior() = default;
};
diff --git a/TXTParser.cpp b/TXTParser.cpp
index 5aea092..e19f343 100644
--- a/TXTParser.cpp
+++ b/TXTParser.cpp
@@ -1,16 +1,16 @@
#include "TXTParser.h"
-#include "Parser.h"
+#include "ParserFactory.h"
TXTParser TXTParser::instance {};
TXTParser::TXTParser() {
- Parser::register_strategy(this);
+ ParserFactory::register_strategy(this);
}
-unsigned int TXTParser::heuristic(FileStrategy & f) {
+unsigned int TXTParser::heuristic(FileReader & f) {
return 0;
}
-void TXTParser::parse(FileStrategy & f, Deserializer & d) {
+void TXTParser::parse(FileReader & f, MuseumDeserializer & d) {
printf("%s\n", __PRETTY_FUNCTION__);
}
diff --git a/TXTParser.h b/TXTParser.h
index d67a7fb..064a0cf 100644
--- a/TXTParser.h
+++ b/TXTParser.h
@@ -1,11 +1,11 @@
#pragma once
-#include "ParserStrategy.h"
+#include "Parser.h"
-class TXTParser : public ParserStrategy {
+class TXTParser : public Parser {
public:
- virtual void parse(FileStrategy & f, Deserializer & d);
- virtual unsigned int heuristic(FileStrategy & f);
+ virtual void parse(FileReader & f, MuseumDeserializer & d);
+ virtual unsigned int heuristic(FileReader & f);
private:
static TXTParser instance;
diff --git a/Tile.cpp b/Tile.cpp
index a891f15..f4fa623 100644
--- a/Tile.cpp
+++ b/Tile.cpp
@@ -1,8 +1,8 @@
#include <cstdio>
#include "Tile.h"
-#include "TileAppearance.h"
-#include "TileBehavior.h"
+#include "TileColorFactory.h"
+#include "TileBehaviorFactory.h"
#include "Museum.h"
using namespace std;
@@ -18,8 +18,8 @@ void Tile::set_type(const string & type) {
void Tile::set_data(TileData & data) {
this->data = data;
- this->color = TileAppearance::get_color(this->data.type);
- this->behavior = TileBehavior::get_strategy(this->data.type).clone(this->museum);
+ this->color = TileColorFactory::get_color(this->data.type);
+ this->behavior = TileBehaviorFactory::get_strategy(this->data.type).clone(this->museum);
}
void Tile::update() {
diff --git a/Tile.h b/Tile.h
index 446b991..00da207 100644
--- a/Tile.h
+++ b/Tile.h
@@ -4,7 +4,7 @@
#include "TileData.h"
#include "Color.h"
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
class Museum;
@@ -15,7 +15,7 @@ public:
public:
TileData data;
Color color;
- std::unique_ptr<TileBehaviorStrategy> behavior = nullptr;
+ std::unique_ptr<TileBehavior> behavior = nullptr;
public:
void set_data(TileData & data);
diff --git a/TileAppearance.cpp b/TileAppearance.cpp
index b91301f..7c5b080 100644
--- a/TileAppearance.cpp
+++ b/TileAppearance.cpp
@@ -1,18 +1,18 @@
-#include "TileAppearance.h"
+#include "TileColorFactory.h"
using namespace std;
-Color TileAppearance::get_color(string type) {
- auto & type_map = TileAppearance::get_collection();
+Color TileColorFactory::get_color(string type) {
+ auto & type_map = TileColorFactory::get_collection();
if (type_map.contains(type))
return type_map.at(type);
- return TileAppearance::default_color;
+ return TileColorFactory::default_color;
}
-void TileAppearance::register_color(string type, Color color) {
- auto & type_map = TileAppearance::get_collection();
+void TileColorFactory::register_color(string type, Color color) {
+ auto & type_map = TileColorFactory::get_collection();
type_map[type] = color;
}
diff --git a/TileAppearance.h b/TileAppearance.h
index 2c89f48..83dfeed 100644
--- a/TileAppearance.h
+++ b/TileAppearance.h
@@ -5,7 +5,7 @@
#include "Color.h"
-class TileAppearance {
+class TileColorFactory {
typedef std::map<std::string, Color> TileAppearanceCollection;
public:
diff --git a/TileBehavior.cpp b/TileBehavior.cpp
index 6cabd40..99301ac 100644
--- a/TileBehavior.cpp
+++ b/TileBehavior.cpp
@@ -1,10 +1,10 @@
-#include "TileBehavior.h"
+#include "TileBehaviorFactory.h"
#include "Exception.h"
using namespace std;
-TileBehaviorStrategy & TileBehavior::get_strategy(string type) {
- auto & type_map = TileBehavior::get_collection();
+TileBehavior & TileBehaviorFactory::get_strategy(string type) {
+ auto & type_map = TileBehaviorFactory::get_collection();
if (type_map.contains(type))
return *type_map.at(type);
@@ -12,8 +12,8 @@ TileBehaviorStrategy & TileBehavior::get_strategy(string type) {
throw Exception("unknown behavior for tile type \"%s\"", type.c_str());
}
-void TileBehavior::register_strategy(string type, TileBehaviorStrategy * strategy) {
- auto & type_map = TileBehavior::get_collection();
+void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) {
+ auto & type_map = TileBehaviorFactory::get_collection();
type_map[type] = strategy;
}
diff --git a/TileBehavior.h b/TileBehavior.h
index 2298c07..33cd795 100644
--- a/TileBehavior.h
+++ b/TileBehavior.h
@@ -3,14 +3,14 @@
#include <map>
#include <string>
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
-class TileBehavior {
- typedef std::map<std::string, TileBehaviorStrategy *> TileBehaviorCollection;
+class TileBehaviorFactory {
+ typedef std::map<std::string, TileBehavior *> TileBehaviorCollection;
public:
- static TileBehaviorStrategy & get_strategy(std::string);
- static void register_strategy(std::string, TileBehaviorStrategy *);
+ static TileBehavior & get_strategy(std::string);
+ static void register_strategy(std::string, TileBehavior *);
private:
static TileBehaviorCollection & get_collection() {
diff --git a/TileBehaviorStrategy.cpp b/TileBehaviorStrategy.cpp
index 99566b8..9de896e 100644
--- a/TileBehaviorStrategy.cpp
+++ b/TileBehaviorStrategy.cpp
@@ -1,11 +1,11 @@
+#include "TileBehaviorFactory.h"
#include "TileBehavior.h"
-#include "TileBehaviorStrategy.h"
-TileBehaviorStrategy::TileBehaviorStrategy(const std::string type) {
- TileBehavior::register_strategy(type, this);
+TileBehavior::TileBehavior(const std::string type) {
+ TileBehaviorFactory::register_strategy(type, this);
}
-void TileBehaviorStrategy::step(Artist *) {
+void TileBehavior::step(Artist *) {
this->interactions++;
}
diff --git a/TileBehaviorStrategy.h b/TileBehaviorStrategy.h
index 0a24abb..b79e7f5 100644
--- a/TileBehaviorStrategy.h
+++ b/TileBehaviorStrategy.h
@@ -7,15 +7,15 @@ class Tile;
class Museum;
class Artist;
-class TileBehaviorStrategy {
+class TileBehavior {
public:
virtual void step(Artist *);
virtual void update(Tile &) = 0;
- virtual std::unique_ptr<TileBehaviorStrategy> clone(Museum & m) = 0;
+ virtual std::unique_ptr<TileBehavior> clone(Museum & m) = 0;
protected:
- TileBehaviorStrategy(const std::string type);
- TileBehaviorStrategy() = default;
+ TileBehavior(const std::string type);
+ TileBehavior() = default;
protected:
unsigned int interactions = 0;
diff --git a/TileDecayCommand.cpp b/TileDecayCommand.cpp
index e986cc5..ff5c6b2 100644
--- a/TileDecayCommand.cpp
+++ b/TileDecayCommand.cpp
@@ -1,7 +1,7 @@
-#include "TileDecayCommand.h"
+#include "StepTileCommand.h"
#include "Museum.h"
-void TileDecayCommand::execute(unsigned int x, unsigned int y) {
+void StepTileCommand::execute(unsigned int x, unsigned int y) {
Museum & museum = this->get_museum();
if (x >= museum.canvas.data.columns) return;
if (y >= museum.canvas.data.rows) return;
diff --git a/TileDecayCommand.h b/TileDecayCommand.h
index 6bb72de..ce9dccd 100644
--- a/TileDecayCommand.h
+++ b/TileDecayCommand.h
@@ -2,7 +2,7 @@
#include "Command.h"
-class TileDecayCommand : public Command {
+class StepTileCommand : public Command {
using Command::Command;
public:
diff --git a/ViewController.cpp b/ViewController.cpp
index f5c4e1e..a37c49a 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -1,11 +1,11 @@
#include "ViewController.h"
-#include "ArtistVisibilityCommand.h"
+#include "ToggleArtistVisibilityCommand.h"
#include "Exception.h"
#include "KeyboardCode.h"
#include "MouseCode.h"
-#include "MuseumPauseCommand.h"
+#include "ToggleMuseumPauseCommand.h"
#include "OpenFileGUICommand.h"
-#include "TileDecayCommand.h"
+#include "StepTileCommand.h"
#include "TimeTravelCommand.h"
#include "View.h"
#include "Museum.h"
@@ -71,11 +71,11 @@ void ViewController::ev_keydown(KeyboardCode key) {
try {
switch (key) {
case KEY_SPACE: {
- MuseumPauseCommand(this->cmd_base).toggle();
+ ToggleMuseumPauseCommand(this->cmd_base).toggle();
break;
}
case KEY_ENTER: {
- TileDecayCommand(this->cmd_base).execute(get<0>(this->mouse_pos), get<1>(this->mouse_pos));
+ StepTileCommand(this->cmd_base).execute(get<0>(this->mouse_pos), get<1>(this->mouse_pos));
break;
}
case KEY_O: {
@@ -83,7 +83,7 @@ void ViewController::ev_keydown(KeyboardCode key) {
break;
}
case KEY_A: {
- ArtistVisibilityCommand(this->cmd_base).toggle();
+ ToggleArtistVisibilityCommand(this->cmd_base).toggle();
break;
}
case KEY_LEFT: {
diff --git a/XMLParser.cpp b/XMLParser.cpp
index 6be26af..4bfde46 100644
--- a/XMLParser.cpp
+++ b/XMLParser.cpp
@@ -4,17 +4,17 @@
#include "XMLParser.h"
#include "Exception.h"
-#include "Parser.h"
+#include "ParserFactory.h"
#include "TileData.h"
using namespace std;
XMLParser XMLParser::instance {};
XMLParser::XMLParser() {
- Parser::register_strategy(this);
+ ParserFactory::register_strategy(this);
}
-unsigned int XMLParser::heuristic(FileStrategy & f) {
+unsigned int XMLParser::heuristic(FileReader & f) {
const string content = f.read();
int open_backets = 0;
int close_brackets = 0;
@@ -27,7 +27,7 @@ unsigned int XMLParser::heuristic(FileStrategy & f) {
return (open_backets + close_brackets) / penalty;
}
-void XMLParser::parse(FileStrategy & f, Deserializer & d) {
+void XMLParser::parse(FileReader & f, MuseumDeserializer & d) {
using namespace pugi;
const string content = f.read();
diff --git a/XMLParser.h b/XMLParser.h
index dab7290..16f8749 100644
--- a/XMLParser.h
+++ b/XMLParser.h
@@ -1,11 +1,11 @@
#pragma once
-#include "ParserStrategy.h"
+#include "Parser.h"
-class XMLParser : public ParserStrategy {
+class XMLParser : public Parser {
public:
- virtual void parse(FileStrategy & f, Deserializer & d);
- virtual unsigned int heuristic(FileStrategy & f);
+ virtual void parse(FileReader & f, MuseumDeserializer & d);
+ virtual unsigned int heuristic(FileReader & f);
private:
static XMLParser instance;
diff --git a/YellowTileBehavior.cpp b/YellowTileBehavior.cpp
index 4e35733..ae0cd7c 100644
--- a/YellowTileBehavior.cpp
+++ b/YellowTileBehavior.cpp
@@ -1,8 +1,8 @@
#include <memory>
#include <random>
-#include "YellowTileBehavior.h"
-#include "GrayTileBehavior.h"
+#include "CreateArtistTileBehavior.h"
+#include "StepTileBehavior.h"
#include "Tile.h"
#include "Museum.h"
@@ -12,14 +12,14 @@ using std::random_device;
using std::mt19937;
using namespace std;
-YellowTileBehavior YellowTileBehavior::instance { YellowTileBehavior::type };
+CreateArtistTileBehavior CreateArtistTileBehavior::instance { CreateArtistTileBehavior::type };
random_device dev{};
mt19937 rng(dev());
uniform_int_distribution<int> random_bool(0, 1);
uniform_real_distribution<float> random_float(-1, 1);
-void YellowTileBehavior::update(Tile & tile) {
+void CreateArtistTileBehavior::update(Tile & tile) {
unsigned int new_artists = this->interactions - this->last_interactions;
this->last_interactions = this->interactions;
@@ -35,12 +35,12 @@ void YellowTileBehavior::update(Tile & tile) {
}
if (this->interactions < 2) return;
- tile.set_type(GrayTileBehavior::type);
+ tile.set_type(StepTileBehavior::type);
}
-unique_ptr<TileBehaviorStrategy> YellowTileBehavior::clone(Museum & museum) {
- auto instance = new YellowTileBehavior();
+unique_ptr<TileBehavior> CreateArtistTileBehavior::clone(Museum & museum) {
+ auto instance = new CreateArtistTileBehavior();
instance->museum = &museum;
- return unique_ptr<TileBehaviorStrategy>(instance);
+ return unique_ptr<TileBehavior>(instance);
}
diff --git a/YellowTileBehavior.h b/YellowTileBehavior.h
index 8de0b75..6abd67f 100644
--- a/YellowTileBehavior.h
+++ b/YellowTileBehavior.h
@@ -1,18 +1,18 @@
#pragma once
-#include "TileBehaviorStrategy.h"
+#include "TileBehavior.h"
-class YellowTileBehavior : public TileBehaviorStrategy {
+class CreateArtistTileBehavior : public TileBehavior {
public:
virtual void update(Tile &);
- virtual std::unique_ptr<TileBehaviorStrategy> clone(Museum &);
+ virtual std::unique_ptr<TileBehavior> clone(Museum &);
static constexpr const char * type = "Y";
private:
- using TileBehaviorStrategy::TileBehaviorStrategy;
- static YellowTileBehavior instance;
- YellowTileBehavior() = default;
+ using TileBehavior::TileBehavior;
+ static CreateArtistTileBehavior instance;
+ CreateArtistTileBehavior() = default;
unsigned int last_interactions = 0;
};
diff --git a/docs/class-diag.puml b/docs/class-diag.puml
index 8495b16..a6fc1cf 100644
--- a/docs/class-diag.puml
+++ b/docs/class-diag.puml
@@ -19,49 +19,49 @@ exception Exception {
together { /' LAYOUT '/
rectangle Group_FileReading as "File reading" <<group>> {
- class FileReader <<Factory>> {
- +open(url) : FileStrategy&
+ class FileReaderFactory <<Factory>> {
+ +open(url) : FileReader&
}
- interface FileStrategy {
+ interface FileReader {
+ read() : string
+ close()
--
# open(string url)
- # clone() : FileStrategy* <<const>>
+ # clone() : FileReader* <<const>>
}
- class LocalFile {
- - instance : LocalFile <<static>>
+ class LocalFileReader {
+ - instance : LocalFileReader <<static>>
}
- class HTTPFile {
- - instance : HTTPFile <<static>>
+ class HTTPFileReader {
+ - instance : HTTPFileReader <<static>>
}
package CPR { }
- FileStrategy <|.u. LocalFile
- FileStrategy <|.u. HTTPFile
+ FileReader <|.u. LocalFileReader
+ FileReader <|.u. HTTPFileReader
- FileStrategy .l> FileReader
- FileStrategy <. FileReader
+ FileReader .l> FileReaderFactory
+ FileReader <. FileReaderFactory
- HTTPFile -l> CPR
+ HTTPFileReader -l> CPR
' LAYOUT
- HTTPFile -r[hidden] LocalFile
+ HTTPFileReader -r[hidden] LocalFileReader
}
rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> {
- class Parser {
- + parse(FileStrategy &, Deserializer &) <<static>>
- + register_strategy(ParserStrategy *) <<static>>
+ class ParserFactory {
+ + parse(FileReader &, MuseumDeserializer &) <<static>>
+ + register_strategy(Parser *) <<static>>
--
- get_collection() : ParserCollection <<static>>
}
- interface ParserStrategy {
- + parse(FileStrategy &, Deserializer &) <<static>>
- + heuristic(FileStrategy &) : unsigned int <<static>>
+ interface Parser {
+ + parse(FileReader &, MuseumDeserializer &) <<static>>
+ + heuristic(FileReader &) : unsigned int <<static>>
}
- ParserStrategy .> Parser
- ParserStrategy <. Parser
+ Parser .> ParserFactory
+ Parser <. ParserFactory
class CSVParser
class XMLParser
@@ -69,14 +69,14 @@ rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>>
package pugixml { }
- CSVParser ..|> ParserStrategy
- TXTParser ..|> ParserStrategy
- XMLParser ..|> ParserStrategy
+ CSVParser ..|> Parser
+ TXTParser ..|> Parser
+ XMLParser ..|> Parser
XMLParser -> pugixml
- class Deserializer {
- + Deserializer(Museum &)
+ class MuseumDeserializer {
+ + MuseumDeserializer(Museum &)
--
+ set_canvas(CanvasData)
+ set_tile(TileData)
@@ -84,9 +84,9 @@ rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>>
+ add_type(type : string, Color, weight : unsigned int)
}
- CSVParser -up-> Deserializer
- XMLParser -up-> Deserializer
- TXTParser -up-> Deserializer
+ CSVParser -up-> MuseumDeserializer
+ XMLParser -up-> MuseumDeserializer
+ TXTParser -up-> MuseumDeserializer
' LAYOUT
CSVParser -r[hidden] TXTParser
@@ -145,7 +145,7 @@ rectangle Group_Model as "Model" <<group>> {
class Tile {
+ data : TileData
+ color : Color
- + behavior : uniq<TileBehaviorStrategy>
+ + behavior : uniq<TileBehavior>
+ set_data(TileData &)
+ set_type(type : const string &)
+ update()
@@ -198,31 +198,31 @@ rectangle Group_TileAppearance as "Tile appearance" <<group>> {
green : unsigned int
blue : unsigned int
}
- class TileAppearance {
+ class TileColorFactory {
+ get_color(string) : Color <<static>>
+ register_color(string, Color) <<static>>
}
Tile --> Color
- Color <.. TileAppearance
+ Color <.. TileColorFactory
}
rectangle Group_TileBehavior as "Tile behavior" <<group>> {
- interface TileBehaviorStrategy {
+ interface TileBehavior {
+ step(Artist *)
+ update(Tile &)
- + clone(Museum &) : uniq<TileBehaviorStrategy>
+ + clone(Museum &) : uniq<TileBehavior>
--
- # TileBehaviorStrategy(type : string)
- # TileBehaviorStrategy()
+ # TileBehavior(type : string)
+ # TileBehavior()
--
# interactions : unsigned int
# museum : Museum *
}
- class TileBehavior {
- + get_strategy(string) : TileBehaviorStrategy & <<static>>
- + register_strategy(string, TileBehaviorStrategy *) <<static>>
+ class TileBehaviorFactory {
+ + get_strategy(string) : TileBehavior & <<static>>
+ + register_strategy(string, TileBehavior *) <<static>>
--
- get_collection() : TileBehaviorCollection & <<static>>
}
@@ -231,35 +231,35 @@ rectangle Group_TileBehavior as "Tile behavior" <<group>> {
class NullTileBehavior {
- type = "" <<static constexpr>>
}
- class GrayTileBehavior {
+ class StepTileBehavior {
- type = "G" : <<static constexpr>>
}
- class RedTileBehavior {
+ class DeleteArtistTileBehavior {
- type = "R" : <<static constexpr>>
}
- class BlueTileBehavior {
+ class SetNeighborTileBehavior {
- type = "B" : <<static constexpr>>
--
- dx : int
- dy : int
}
- class YellowTileBehavior {
+ class CreateArtistTileBehavior {
- type = "Y" : <<static constexpr>>
--
- last_interactions : unsigned int
}
}
- TileBehaviorStrategy <|.. NullTileBehavior
- TileBehaviorStrategy <|.. GrayTileBehavior
- TileBehaviorStrategy <|.. RedTileBehavior
- TileBehaviorStrategy <|.. BlueTileBehavior
- TileBehaviorStrategy <|.. YellowTileBehavior
+ TileBehavior <|.. NullTileBehavior
+ TileBehavior <|.. StepTileBehavior
+ TileBehavior <|.. DeleteArtistTileBehavior
+ TileBehavior <|.. SetNeighborTileBehavior
+ TileBehavior <|.. CreateArtistTileBehavior
- Tile --> "state" TileBehavior
+ Tile --> "state" TileBehaviorFactory
- TileBehavior .l> TileBehaviorStrategy
- TileBehavior <. TileBehaviorStrategy
+ TileBehaviorFactory .l> TileBehavior
+ TileBehaviorFactory <. TileBehavior
}
} /' LAYOUT '/
@@ -315,28 +315,28 @@ rectangle Group_Commands as "Commands" <<group>> {
+ Command(museum, view, controller)
}
- class MuseumPauseCommand {
+ class ToggleMuseumPauseCommand {
+ toggle()
+ set(paused : bool)
}
class OpenFileGUICommand {
+ execute()
}
- class ArtistVisibilityCommand {
+ class ToggleArtistVisibilityCommand {
+ toggle()
+ set(paused : bool)
}
class LoadFilesCommand {
+ execute(files)
}
- class TileDecayCommand {
+ class StepTileCommand {
+ execute(x, y)
}
- Command <|-u- MuseumPauseCommand
+ Command <|-u- ToggleMuseumPauseCommand
Command <|-u- OpenFileGUICommand
- Command <|-u- ArtistVisibilityCommand
- Command <|-u- TileDecayCommand
+ Command <|-u- ToggleArtistVisibilityCommand
+ Command <|-u- StepTileCommand
Command <|-d- LoadFilesCommand
}
} /' LAYOUT '/
@@ -345,8 +345,8 @@ Command .[norank]> Museum
Command .[norank]> View
Command .[norank]> ViewController
-ParserStrategy .l> FileStrategy
-Deserializer .l> Museum
+Parser .l> FileReader
+MuseumDeserializer .l> Museum
Museum --> Pathfinding
Museum --> Collision
@@ -355,7 +355,7 @@ ViewController -[norank]> Command
main -d-> Museum
main -u-> LoadFilesCommand
-' main -[norank]> Deserializer
+' main -[norank]> MuseumDeserializer
main -[norank]> View
main .r> Exception