aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--TimeTravelCommand.cpp16
-rw-r--r--TimeTravelCommand.h16
-rw-r--r--ViewController.cpp3
-rw-r--r--docs/class-diag.puml250
5 files changed, 199 insertions, 87 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa0ef49..a74a6b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,7 @@ add_executable(main
MuseumPauseCommand.cpp
ArtistVisibilityCommand.cpp
TileDecayCommand.cpp
+ TimeTravelCommand.cpp
)
target_link_libraries(main
diff --git a/TimeTravelCommand.cpp b/TimeTravelCommand.cpp
new file mode 100644
index 0000000..c7dfc82
--- /dev/null
+++ b/TimeTravelCommand.cpp
@@ -0,0 +1,16 @@
+#include "TimeTravelCommand.h"
+#include "Museum.h"
+
+void TimeTravelCommand::forwards() {
+ return this->execute(+this->default_offset);
+}
+
+void TimeTravelCommand::backwards() {
+ return this->execute(-this->default_offset);
+}
+
+void TimeTravelCommand::execute(long offset) {
+ Museum & museum = this->get_museum();
+ // TODO
+}
+
diff --git a/TimeTravelCommand.h b/TimeTravelCommand.h
new file mode 100644
index 0000000..0a2de46
--- /dev/null
+++ b/TimeTravelCommand.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "Command.h"
+
+class TimeTravelCommand : public Command {
+ using Command::Command;
+
+public:
+ virtual void execute(long offset);
+ virtual void forwards();
+ virtual void backwards();
+
+private:
+ static constexpr long default_offset = 50;
+};
+
diff --git a/ViewController.cpp b/ViewController.cpp
index 303d5b9..52cdefc 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -6,6 +6,7 @@
#include "MuseumPauseCommand.h"
#include "OpenFileGUICommand.h"
#include "TileDecayCommand.h"
+#include "TimeTravelCommand.h"
#include "View.h"
#include "Museum.h"
@@ -79,9 +80,11 @@ void ViewController::ev_keydown(KeyboardCode key) {
break;
}
case KEY_LEFT: {
+ TimeTravelCommand(this->cmd_base).backwards();
break;
}
case KEY_RIGHT: {
+ TimeTravelCommand(this->cmd_base).forwards();
break;
}
default: break;
diff --git a/docs/class-diag.puml b/docs/class-diag.puml
index 8526346..a502503 100644
--- a/docs/class-diag.puml
+++ b/docs/class-diag.puml
@@ -17,6 +17,7 @@ exception Exception {
# va_format(va_list args, const char* fmt)
}
+together { /' LAYOUT '/
rectangle Group_FileReading as "File reading" <<group>> {
class FileReader <<Factory>> {
+open(url) : FileStrategy&
@@ -34,10 +35,7 @@ rectangle Group_FileReading as "File reading" <<group>> {
class HTTPFile {
- instance : HTTPFile <<static>>
}
- package CPR {
- class Response <<irrelevant>>
- class Url <<irrelevant>>
- }
+ package CPR { }
FileStrategy <|.. LocalFile
FileStrategy <|.. HTTPFile
@@ -45,17 +43,21 @@ rectangle Group_FileReading as "File reading" <<group>> {
FileStrategy <. FileReader
FileStrategy .> FileReader
- HTTPFile --> CPR.Response
- CPR.Response - CPR.Url
+ HTTPFile -> CPR
+
+ ' LAYOUT
+ LocalFile -r[hidden] HTTPFile
}
rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> {
class Parser {
- + parse(File, Deserializer) <<static>>
- + register_strategy(ParserStrategy) <<static>>
+ + parse(FileStrategy &, Deserializer &) <<static>>
+ + register_strategy(ParserStrategy *) <<static>>
+ --
+ - get_collection() : ParserCollection <<static>>
}
interface ParserStrategy {
- + parse(File, Deserializer) <<static>>
- + heuristic(File) : unsigned int <<static>>
+ + parse(FileStrategy &, Deserializer &) <<static>>
+ + heuristic(FileStrategy &) : unsigned int <<static>>
}
ParserStrategy .> Parser
@@ -65,45 +67,76 @@ rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>>
class XMLParser
class TXTParser
+ package pugixml { }
+
CSVParser ..|> ParserStrategy
TXTParser ..|> ParserStrategy
XMLParser ..|> ParserStrategy
+ XMLParser -> pugixml
+
class Deserializer {
- + set_target(Museum &)
- + add_artist(uniq<ArtistData>)
- + set_rows(unsigned int)
- + set_cols(unsigned int)
- + add_type(string, Color, unsigned int)
- + add_tile(unsigned int x, unsigned int y, uniq<TileData>)
+ + Deserializer(Museum &)
+ --
+ + set_canvas(CanvasData)
+ + set_tile(TileData)
+ + add_artist(ArtistData)
+ + add_type(type : string, Color, weight : unsigned int)
}
CSVParser -up-> Deserializer
XMLParser -up-> Deserializer
TXTParser -up-> Deserializer
- ' ParserStrategy ..> Deserializer
+ ' LAYOUT
+ CSVParser -r[hidden] TXTParser
+ TXTParser -r[hidden] XMLParser
}
+} /' LAYOUT '/
+together { /' LAYOUT '/
rectangle Group_Model as "Model" <<group>> {
+ class Museum {
+ + people : People
+ + canvas : Canvas
+ --
+ + update()
+ --
+ - paused : bool <<+get>> <<+set>>
+ - tick : unsigned long long
+ --
+ - working : bool
+ - worker : thread *
+ - work()
+ }
class Canvas {
- + get_tile(x, y)
- + set_tile(x, y, TileData)
- - data : CanvasData
- - tiles : Tile[]
+ + Canvas(Museum &)
+ --
+ + get_tile(x, y) : Tile &
+ + set_tile(TileData)
+ --
+ + update()
+ + data : CanvasData
+ + set_data(CanvasData)
+ --
+ - tiles : vector<Tile *>
+ - museum : Museum &
}
class People {
- + add_artist(uniq<ArtistData>)
- - artists : Artist[]
- }
- class Museum {
- - people : People
- - canvas : Canvas
+ + People(Museum &)
+ --
+ + add_artist(ArtistData)
+ + remove_artist(Artist &)
+ + get_artists() : forward_list<Artist *>
+ --
+ - artists : forward_list<Artist>
}
class Tile {
+ data : TileData
}
struct TileData {
+ + x : unsigned int
+ + y : unsigned int
+ type : string
}
class Artist {
@@ -135,7 +168,6 @@ rectangle Group_Model as "Model" <<group>> {
' LAYOUT
Artist -r[hidden] Tile
}
-
rectangle Group_TileAppearance as "Tile appearance" <<group>> {
struct Color {
red : unsigned int
@@ -152,36 +184,104 @@ rectangle Group_TileAppearance as "Tile appearance" <<group>> {
Color <.. TileAppearance
}
rectangle Group_TileBehavior as "Tile behavior" <<group>> {
- interface TileBehaviorStrategy
+ interface TileBehaviorStrategy {
+ + step(Artist *)
+ + update(Tile &)
+ + clone(Museum &) : uniq<TileBehaviorStrategy>
+ --
+ # TileBehaviorStrategy(type : string)
+ # TileBehaviorStrategy()
+ --
+ # interactions : unsigned int
+ # museum : Museum *
+ }
- class TileBehavior
+ class TileBehavior {
+ + get_strategy(string) : TileBehaviorStrategy & <<static>>
+ + register_strategy(string, TileBehaviorStrategy *) <<static>>
+ --
+ - get_collection() : TileBehaviorCollection & <<static>>
+ }
together {
- class NullTileBehavior
-
- class GrayTileBehavior
- class RedTileBehavior
- class BlueTileBehavior
- class YellowTileBehavior
-
+ class NullTileBehavior {
+ - type = "" <<static constexpr>>
+ }
+ class GrayTileBehavior {
+ - type = "G" : <<static constexpr>>
+ }
+ class RedTileBehavior {
+ - type = "R" : <<static constexpr>>
+ }
+ class BlueTileBehavior {
+ - type = "B" : <<static constexpr>>
+ --
+ - update_neighbor(here : Tile &, dx, dy)
+ - dx : int
+ - dy : int
+ }
+ class YellowTileBehavior {
+ - type = "Y" : <<static constexpr>>
+ --
+ - last_interactions : unsigned int
+ }
+
+ ' LAYOUT
+ TileBehavior -d[hidden]- NullTileBehavior
NullTileBehavior -d[hidden]- GrayTileBehavior
GrayTileBehavior -d[hidden]- RedTileBehavior
RedTileBehavior -d[hidden]- BlueTileBehavior
BlueTileBehavior -d[hidden]- YellowTileBehavior
}
- TileBehaviorStrategy <|.. NullTileBehavior
- TileBehaviorStrategy <|.. GrayTileBehavior
- TileBehaviorStrategy <|.. RedTileBehavior
- TileBehaviorStrategy <|.. BlueTileBehavior
- TileBehaviorStrategy <|.. YellowTileBehavior
+ TileBehaviorStrategy <|.[norank]. NullTileBehavior
+ TileBehaviorStrategy <|.[norank]. GrayTileBehavior
+ TileBehaviorStrategy <|.[norank]. RedTileBehavior
+ TileBehaviorStrategy <|.[norank]. BlueTileBehavior
+ TileBehaviorStrategy <|.[norank]. YellowTileBehavior
Tile --> "state" TileBehavior
TileBehavior .l> TileBehaviorStrategy
TileBehavior <. TileBehaviorStrategy
}
+} /' LAYOUT '/
+together { /' LAYOUT '/
+rectangle Group_Commands as "Commands" <<group>> {
+ class Command {
+ # museum : Museum&
+ # view : View&
+ # controller : ViewController&
+ --
+ + Command(command : const Command *)
+ + Command(museum, view, controller)
+ }
+
+ class MuseumPauseCommand {
+ + toggle()
+ + set(paused : bool)
+ }
+ class OpenFileGUICommand {
+ + execute()
+ }
+ class ArtistVisibilityCommand {
+ + toggle()
+ + set(paused : bool)
+ }
+ class LoadFilesCommand {
+ + execute(files)
+ }
+ class TileDecayCommand {
+ + execute(x, y)
+ }
+
+ Command <|-u- MuseumPauseCommand
+ Command <|-u- OpenFileGUICommand
+ Command <|-u- ArtistVisibilityCommand
+ Command <|-u- TileDecayCommand
+ Command <|-d- LoadFilesCommand
+}
rectangle Group_Visualization as "Visualization" <<group>> {
struct Rectangle {
x : unsigned int
@@ -192,8 +292,18 @@ rectangle Group_Visualization as "Visualization" <<group>> {
enum Scancode {
}
- package SDL2 { }
+ package SDL3 { }
class View {
+ + window_size(width, height)
+ + dialog_file(callback : fn(files : vec<string>, data), data)
+ + draw_rect(Rectangle, Color)
+ --
+ - window : SDL_Window *
+ - renderer : SDL_Renderer *
+ --
+ + open : bool
+ - worker : thread *
+ - work()
}
class ViewController {
+ update()
@@ -201,62 +311,28 @@ rectangle Group_Visualization as "Visualization" <<group>> {
ViewController ..> View
ViewController <-- View
- View -> SDL2
-}
-
-rectangle Group_Commands as "Commands" <<group>> {
- class Command {
- #museum : Museum&
- #view : View&
- #controller : ViewController&
- +Command(museum, view, controller)
- +Command(command : const Command *)
- }
-
- class MuseumPauseCommand {
- +toggle()
- +set(paused : bool)
- }
- class OpenFileGUICommand {
- +execute()
- }
- class ArtistVisibilityCommand {
- +toggle()
- +set(paused : bool)
- }
-
- Command <|-u- MuseumPauseCommand
- Command <|-u- OpenFileGUICommand
- Command <|-u- ArtistVisibilityCommand
-
- Command .d..> Museum
- Command ...d[norank]> View
- Command ...d[norank]> ViewController
+ View -> SDL3
}
+} /' LAYOUT '/
-' PeopleDeserializer <... People
-' CanvasDeserializer <... Canvas
-' Deserializer <... Museum
+Command .[norank]> Museum
+Command .[norank]> View
+Command .[norank]> ViewController
ParserStrategy ..> FileStrategy
-' Museum .> Deserializer : friend
Deserializer .> Museum
ViewController -[norank]> Command
-main --> Museum
-main --[norank]> Deserializer
-main --[norank]> View
-' DETAIL: main ..[norank]> FileReader
-' DETAIL: main ..[norank]> Parser
+main -d-> Museum
+main -u-> LoadFilesCommand
+main -[norank]> Deserializer
+main -[norank]> View
' LAYOUT
-Group_ParsingDeserialization -d[hidden] Group_FileReading
Group_TileBehavior -r[hidden] Group_TileAppearance
Group_Model -r[hidden] Group_ParsingDeserialization
-Group_Model -l[hidden] main
-' Group_Model -d[hidden] Group_TileBehavior
-' Group_Model -d[hidden] Group_TileAppearance
+Group_Commands -r[hidden] Group_Visualization
@enduml