From c2b23a4c59235b7144b22dafc21f47efb09ef128 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sun, 15 May 2022 10:30:33 +0300 Subject: [PATCH] Move HolderManager and ClassicGraphicsManager to context --- src/modes/classicmode/classicfactory.cpp | 6 +++- .../initializers/mockarrownoteinitializer.h | 10 ------ src/modes/classicmode/editor/mockelement.h | 32 ------------------- src/modes/classicmode/game/classicarrownote.h | 2 +- src/modes/classicmode/game/classicgame.cpp | 14 ++++---- src/modes/classicmode/game/classicgame.h | 6 ++-- .../classicmode/game/classicmapcreator.cpp | 12 +++++-- .../classicmode/game/classicmapcreator.h | 6 ++-- src/modes/classicmode/game/gamecontext.cpp | 13 +++++++- src/modes/classicmode/game/gamecontext.h | 12 +++++-- .../graphics/classicgraphicsfactory.cpp | 2 -- .../graphics/classicscenegraphicsmanager.h | 1 - 12 files changed, 50 insertions(+), 66 deletions(-) delete mode 100644 src/modes/classicmode/editor/initializers/mockarrownoteinitializer.h delete mode 100644 src/modes/classicmode/editor/mockelement.h diff --git a/src/modes/classicmode/classicfactory.cpp b/src/modes/classicmode/classicfactory.cpp index 22a4169..fd424f4 100644 --- a/src/modes/classicmode/classicfactory.cpp +++ b/src/modes/classicmode/classicfactory.cpp @@ -5,6 +5,7 @@ #include "core/timeline.h" #include "game/classicgame.h" +#include "game/gamecontext.h" #include "editor/classiceditor.h" #include "editor/selectionmanager.h" @@ -17,8 +18,11 @@ std::unique_ptr classic::getGame(const std::shared_ptr(core_factory); const auto timeline = std::make_shared>(); const auto graphics_manager = std::make_shared>(timeline, factory, visibility_offset); + const auto hold_manager = std::make_shared(); - return std::make_unique(timeline, graphics_manager); + const auto context = std::make_shared(hold_manager, graphics_manager); + + return std::make_unique(timeline, context); } std::unique_ptr classic::getEditor(const std::shared_ptr& core_factory) diff --git a/src/modes/classicmode/editor/initializers/mockarrownoteinitializer.h b/src/modes/classicmode/editor/initializers/mockarrownoteinitializer.h deleted file mode 100644 index f6a3317..0000000 --- a/src/modes/classicmode/editor/initializers/mockarrownoteinitializer.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "classicmode/noteinitializer.h" -#include "classicmode/elementinitializer.h" - -struct MockArrowNoteInitializer -{ - NoteInitializer initializer; - std::vector elements; -}; diff --git a/src/modes/classicmode/editor/mockelement.h b/src/modes/classicmode/editor/mockelement.h deleted file mode 100644 index bcc0dff..0000000 --- a/src/modes/classicmode/editor/mockelement.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "classicmode/classicactions.h" - -#include "core/gameevent.h" -#include "core/point.h" - -#include -#include -#include - -class ClassicAnimationScenario; -class ClassicNoteGraphics; -class ClassicSelectionGraphics; - -struct MockElement -{ - std::shared_ptr sprite; - std::shared_ptr selection; - bool selected; - - std::array, 5> animations; - - kku::Point position; - std::vector falling_curve_interpolation; - - Type type = Type::NONE; - - // Each note may consist of several buttons. - // For example, ↑ → or ↓ → ← - // Note Element represents this idea. -}; diff --git a/src/modes/classicmode/game/classicarrownote.h b/src/modes/classicmode/game/classicarrownote.h index 6f9dc00..e2fada0 100644 --- a/src/modes/classicmode/game/classicarrownote.h +++ b/src/modes/classicmode/game/classicarrownote.h @@ -14,7 +14,7 @@ public: struct Init { - const Context * const context; + Context * const context; const kku::microsec perfect_offset = 0; const std::vector& intervals = {}; diff --git a/src/modes/classicmode/game/classicgame.cpp b/src/modes/classicmode/game/classicgame.cpp index 626dffc..e78daf3 100644 --- a/src/modes/classicmode/game/classicgame.cpp +++ b/src/modes/classicmode/game/classicgame.cpp @@ -1,14 +1,14 @@ #include "classicgame.h" #include "classicmode/classicnote.h" #include "classicmapcreator.h" +#include "gamecontext.h" #include "graphics/classicscenegraphicsmanager.h" #include "holdmanager.h" ClassicGame::ClassicGame(const std::shared_ptr>& timeline, - const std::shared_ptr& graphics_manager) : + const std::shared_ptr& context) : _timeline(timeline), - _graphics_manager(graphics_manager), - _hold_manager(std::make_unique()) + _context(context) {} ClassicGame::~ClassicGame() @@ -16,7 +16,7 @@ ClassicGame::~ClassicGame() void ClassicGame::run() { - auto beatmap = classic::createBeatmap("aa", _hold_manager); + auto beatmap = classic::createBeatmap("aa", _context); _timeline->setNotes(beatmap.notes); } @@ -42,7 +42,7 @@ void ClassicGame::input(kku::GameEvent&& input) case kku::SystemEvent::Type::KeyRelease: { - _hold_manager->checkRelease(std::get(input.event.data).view); + _context->getHoldManager()->checkRelease(std::get(input.event.data).view); } break; @@ -61,10 +61,10 @@ void ClassicGame::update(kku::UpdateData&& updatedata) }*/ _timeline->update(updatedata.timestamp); - _graphics_manager->update(updatedata.timestamp); + _context->getGraphicsManager()->update(updatedata.timestamp); } void ClassicGame::display() const { - _graphics_manager->display(); + _context->getGraphicsManager()->display(); } diff --git a/src/modes/classicmode/game/classicgame.h b/src/modes/classicmode/game/classicgame.h index ed5e8c2..0e61e98 100644 --- a/src/modes/classicmode/game/classicgame.h +++ b/src/modes/classicmode/game/classicgame.h @@ -10,12 +10,13 @@ class ClassicGraphicsManager; class HoldManager; +class GameContext; class ClassicGame final : public kku::Game { public: explicit ClassicGame(const std::shared_ptr>& timeline, - const std::shared_ptr& graphics_manager); + const std::shared_ptr& context); virtual ~ClassicGame() override; virtual void run() override; @@ -26,6 +27,5 @@ public: private: const std::shared_ptr> _timeline; - const std::shared_ptr _graphics_manager; - const std::shared_ptr _hold_manager; + const std::shared_ptr _context; }; diff --git a/src/modes/classicmode/game/classicmapcreator.cpp b/src/modes/classicmode/game/classicmapcreator.cpp index 60c41c1..55b611f 100644 --- a/src/modes/classicmode/game/classicmapcreator.cpp +++ b/src/modes/classicmode/game/classicmapcreator.cpp @@ -6,7 +6,7 @@ #include "graphics/animations/classicdyinganimationscenario.h" // -auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr& hold_manager) -> Beatmap +auto classic::createBeatmap(const std::string& filepath, Context * const context) -> Beatmap { (void) filepath; @@ -31,7 +31,13 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr +#include +#include #include "core/time.h" #include "classicmode/classicnote.h" -class HoldManager; +class Context; namespace classic { @@ -16,7 +18,7 @@ struct Beatmap kku::microsec visibility_offset; }; -Beatmap createBeatmap(const std::string& filepath, const std::shared_ptr& hold_manager); +Beatmap createBeatmap(const std::string& filepath, Context * const context); } diff --git a/src/modes/classicmode/game/gamecontext.cpp b/src/modes/classicmode/game/gamecontext.cpp index 5fd4d87..f73195b 100644 --- a/src/modes/classicmode/game/gamecontext.cpp +++ b/src/modes/classicmode/game/gamecontext.cpp @@ -3,7 +3,8 @@ #include "game/holdmanager.h" #include "graphics/animations/classicanimationscenario.h" -GameContext::GameContext(HoldManager *hold_manager, ClassicGraphicsManager *graphics_manager) : +GameContext::GameContext(const std::shared_ptr& hold_manager, + const std::shared_ptr& graphics_manager) : _hold_manager(hold_manager), _graphics_manager(graphics_manager) {} @@ -83,3 +84,13 @@ void GameContext::update(ClassicArrowNote *note, const kku::microsec& music_offs if (element.animations[note->getState()]) element.animations[note->getState()]->update(music_offset); } + +std::shared_ptr GameContext::getHoldManager() const +{ + return _hold_manager; +} + +std::shared_ptr GameContext::getGraphicsManager() const +{ + return _graphics_manager; +} diff --git a/src/modes/classicmode/game/gamecontext.h b/src/modes/classicmode/game/gamecontext.h index 1848af0..4778d1f 100644 --- a/src/modes/classicmode/game/gamecontext.h +++ b/src/modes/classicmode/game/gamecontext.h @@ -1,5 +1,6 @@ #pragma once +#include #include "classicmode/context.h" class HoldManager; @@ -8,12 +9,17 @@ class ClassicGraphicsManager; class GameContext : public Context { public: - explicit GameContext(HoldManager *hold_manager, ClassicGraphicsManager *graphics_manager); + explicit GameContext(const std::shared_ptr& hold_manager, + const std::shared_ptr& graphics_manager); virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const override; virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const override; + std::shared_ptr getHoldManager() const; + std::shared_ptr getGraphicsManager() const; + + private: - HoldManager * const _hold_manager; - ClassicGraphicsManager * const _graphics_manager; + const std::shared_ptr _hold_manager; + const std::shared_ptr _graphics_manager; }; diff --git a/src/modes/classicmode/graphics/classicgraphicsfactory.cpp b/src/modes/classicmode/graphics/classicgraphicsfactory.cpp index bd9e49f..0bb0c5b 100644 --- a/src/modes/classicmode/graphics/classicgraphicsfactory.cpp +++ b/src/modes/classicmode/graphics/classicgraphicsfactory.cpp @@ -4,8 +4,6 @@ ClassicGraphicsFactory::ClassicGraphicsFactory(const std::shared_ptr SpriteData { auto shape = _core_factory->getRectangle(); diff --git a/src/modes/classicmode/graphics/classicscenegraphicsmanager.h b/src/modes/classicmode/graphics/classicscenegraphicsmanager.h index a35156c..786dc70 100644 --- a/src/modes/classicmode/graphics/classicscenegraphicsmanager.h +++ b/src/modes/classicmode/graphics/classicscenegraphicsmanager.h @@ -6,7 +6,6 @@ #include "core/timeline.h" #include "core/spritecontainer.h" -#include "editor/mockelement.h" #include "game/arrowelement.h" #include "graphics/animations/classicflyinganimationscenario.h"