diff options
author | Vittorio Romeo <vittorio.romeo@outlook.com> | 2020-06-19 19:56:02 +0100 |
---|---|---|
committer | Vittorio Romeo <vittorio.romeo@outlook.com> | 2020-06-19 19:56:02 +0100 |
commit | cbcd74051ca83f5fa8e0f91316aeb382e1fc3f81 (patch) | |
tree | d238d18ff10da70823c3ae830af2b33130910b34 | |
parent | cfe6509635436c7fe79b945fa36d51e4152f855b (diff) |
Implement control over cap colorcap_color_control
-rw-r--r-- | include/SSVOpenHexagon/Components/CPlayer.hpp | 4 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Core/HexagonGame.hpp | 4 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Data/CapColor.hpp | 33 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Data/StyleData.hpp | 33 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Utils/Color.hpp | 14 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Utils/Match.hpp | 41 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Utils/Utils.hpp | 3 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Components/CPlayer.cpp | 9 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/HGGraphics.cpp | 3 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/HGScripting.cpp | 121 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Data/CapColor.cpp | 41 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Data/StyleData.cpp | 14 |
12 files changed, 248 insertions, 72 deletions
diff --git a/include/SSVOpenHexagon/Components/CPlayer.hpp b/include/SSVOpenHexagon/Components/CPlayer.hpp index cb7af95f..1f14dfc7 100644 --- a/include/SSVOpenHexagon/Components/CPlayer.hpp +++ b/include/SSVOpenHexagon/Components/CPlayer.hpp @@ -32,7 +32,7 @@ private: Ticker swapBlinkTimer{5.f}; Ticker deadEffectTimer{80.f, false}; - void drawPivot(HexagonGame& mHexagonGame); + void drawPivot(HexagonGame& mHexagonGame, const sf::Color& mCapColor); void drawDeathEffect(HexagonGame& mHexagonGame); public: @@ -42,7 +42,7 @@ public: void setPlayerAngle(float newAng); void update(HexagonGame& mHexagonGame, FT mFT); - void draw(HexagonGame& mHexagonGame); + void draw(HexagonGame& mHexagonGame, const sf::Color& mCapColor); }; } // namespace hg diff --git a/include/SSVOpenHexagon/Core/HexagonGame.hpp b/include/SSVOpenHexagon/Core/HexagonGame.hpp index 8f8a19ba..30306a08 100644 --- a/include/SSVOpenHexagon/Core/HexagonGame.hpp +++ b/include/SSVOpenHexagon/Core/HexagonGame.hpp @@ -16,6 +16,7 @@ #include "SSVOpenHexagon/Utils/Utils.hpp" #include "SSVOpenHexagon/Utils/FPSWatcher.hpp" + namespace hg { @@ -87,6 +88,9 @@ private: const Vec2f txt_pos{8, 8}; + // Color of the polygon in the center. + CapColor capColor; + struct CExprVec2f { float x; diff --git a/include/SSVOpenHexagon/Data/CapColor.hpp b/include/SSVOpenHexagon/Data/CapColor.hpp new file mode 100644 index 00000000..f2c135cd --- /dev/null +++ b/include/SSVOpenHexagon/Data/CapColor.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2013-2015 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: http://opensource.org/licenses/AFL-3.0 + +#pragma once + +#include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" + +#include <variant> + +namespace hg +{ + +namespace CapColorMode +{ + +// clang-format off +struct Main { }; +struct MainDarkened { }; +struct ByIndex { int index; }; +// clang-format on + +} // namespace CapColorMode + +using CapColor = std::variant< // + CapColorMode::Main, // + CapColorMode::MainDarkened, // + CapColorMode::ByIndex // + >; + +[[nodiscard]] CapColor parseCapColor(const ssvuj::Obj& obj) noexcept; + +} // namespace hg diff --git a/include/SSVOpenHexagon/Data/StyleData.hpp b/include/SSVOpenHexagon/Data/StyleData.hpp index d5ff98be..8a26d69c 100644 --- a/include/SSVOpenHexagon/Data/StyleData.hpp +++ b/include/SSVOpenHexagon/Data/StyleData.hpp @@ -5,6 +5,7 @@ #pragma once #include "SSVOpenHexagon/Global/Common.hpp" +#include "SSVOpenHexagon/Data/CapColor.hpp" namespace hg { @@ -66,6 +67,8 @@ public: float _3dPerspectiveMult; sf::Color _3dOverrideColor; ColorData mainColorData; + CapColor capColor; + std::vector<ColorData> colorDatas; StyleData() = default; @@ -96,7 +99,8 @@ public: ssvuj::getExtr<float>(mRoot, "3D_perspective_multiplier", 1.f)}, _3dOverrideColor{ssvuj::getExtr<sf::Color>( mRoot, "3D_override_color", sf::Color::Transparent)}, - mainColorData{ssvuj::getObj(mRoot, "main")} + mainColorData{ssvuj::getObj(mRoot, "main")}, // + capColor{parseCapColor(ssvuj::getObj(mRoot, "cap_color"))} { currentHue = hueMin; @@ -119,39 +123,52 @@ public: rootPath = mPath; } - const Path& getRootPath() const + const Path& getRootPath() const noexcept { return rootPath; } - const sf::Color& getMainColor() const + const sf::Color& getMainColor() const noexcept { return currentMainColor; } - const std::vector<sf::Color>& getColors() const + const std::vector<sf::Color>& getColors() const noexcept { return currentColors; } - const sf::Color& getColor(int mIdx) const + const sf::Color& getColor(int mIdx) const noexcept { return currentColors[ssvu::getMod(mIdx, currentColors.size())]; } - float getCurrentHue() const + float getCurrentHue() const noexcept { return currentHue; } - float getCurrentSwapTime() const + + float getCurrentSwapTime() const noexcept { return currentSwapTime; } - const sf::Color& get3DOverrideColor() const + const sf::Color& get3DOverrideColor() const noexcept { return current3DOverrideColor; } + + CapColor& getCapColor() noexcept + { + return capColor; + } + + const CapColor& getCapColor() const noexcept + { + return capColor; + } + + sf::Color getCapColorResult() const noexcept; }; } // namespace hg diff --git a/include/SSVOpenHexagon/Utils/Color.hpp b/include/SSVOpenHexagon/Utils/Color.hpp new file mode 100644 index 00000000..bc3760ca --- /dev/null +++ b/include/SSVOpenHexagon/Utils/Color.hpp @@ -0,0 +1,14 @@ +// Copyright (c) 2013-2015 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: http://opensource.org/licenses/AFL-3.0 + +#pragma once + +#include <SFML/Graphics.hpp> + +namespace hg::Utils +{ + +sf::Color getColorDarkened(sf::Color mColor, float mMultiplier); + +} // namespace hg::Utils diff --git a/include/SSVOpenHexagon/Utils/Match.hpp b/include/SSVOpenHexagon/Utils/Match.hpp new file mode 100644 index 00000000..f2889c1e --- /dev/null +++ b/include/SSVOpenHexagon/Utils/Match.hpp @@ -0,0 +1,41 @@ +// Copyright (c) 2013-2015 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: http://opensource.org/licenses/AFL-3.0 + +#pragma once + +#include <type_traits> +#include <variant> +#include <utility> + +namespace hg::Utils +{ + +template <typename... Fs> +struct overload_set : Fs... +{ + template <typename... FFwds> + constexpr overload_set(FFwds&&... fFwds) : Fs{std::forward<FFwds>(fFwds)}... + { + } + + using Fs::operator()...; +}; + +template <typename... Fs> +overload_set(Fs...) -> overload_set<Fs...>; + +template <typename... Fs> +constexpr auto make_overload_set(Fs&&... fs) +{ + return overload_set<std::decay_t<Fs>...>{std::forward<Fs>(fs)...}; +} + +template <typename Variant, typename... Fs> +constexpr decltype(auto) match(Variant&& v, Fs&&... fs) +{ + return std::visit( + make_overload_set(std::forward<Fs>(fs)...), std::forward<Variant>(v)); +} + +} diff --git a/include/SSVOpenHexagon/Utils/Utils.hpp b/include/SSVOpenHexagon/Utils/Utils.hpp index 2c0692a5..b5033f42 100644 --- a/include/SSVOpenHexagon/Utils/Utils.hpp +++ b/include/SSVOpenHexagon/Utils/Utils.hpp @@ -11,7 +11,6 @@ #include "SSVOpenHexagon/Data/LevelData.hpp" #include "SSVOpenHexagon/Data/ProfileData.hpp" #include "SSVOpenHexagon/Data/MusicData.hpp" -#include "SSVOpenHexagon/Data/StyleData.hpp" namespace hg::Utils { @@ -111,8 +110,6 @@ public: return x * x * x * (x * (x * 6 - 15) + 10); } -sf::Color getColorDarkened(sf::Color mColor, float mMultiplier); - MusicData loadMusicFromJson(const ssvuj::Obj& mRoot); ProfileData loadProfileFromJson(const ssvuj::Obj& mRoot); diff --git a/src/SSVOpenHexagon/Components/CPlayer.cpp b/src/SSVOpenHexagon/Components/CPlayer.cpp index 390c642d..79e4c7bc 100644 --- a/src/SSVOpenHexagon/Components/CPlayer.cpp +++ b/src/SSVOpenHexagon/Components/CPlayer.cpp @@ -6,6 +6,7 @@ #include "SSVOpenHexagon/Components/CPlayer.hpp" #include "SSVOpenHexagon/Components/CWall.hpp" #include "SSVOpenHexagon/Utils/Utils.hpp" +#include "SSVOpenHexagon/Utils/Color.hpp" #include "SSVOpenHexagon/Global/Common.hpp" using namespace std; @@ -34,9 +35,9 @@ void CPlayer::setPlayerAngle(float newAng) angle = newAng; } -void CPlayer::draw(HexagonGame& mHexagonGame) +void CPlayer::draw(HexagonGame& mHexagonGame, const sf::Color& mCapColor) { - drawPivot(mHexagonGame); + drawPivot(mHexagonGame, mCapColor); if(deadEffectTimer.isRunning()) { @@ -60,7 +61,7 @@ void CPlayer::draw(HexagonGame& mHexagonGame) colorMain, getOrbitRad(pos, angle, size), pLeft, pRight); } -void CPlayer::drawPivot(HexagonGame& mHexagonGame) +void CPlayer::drawPivot(HexagonGame& mHexagonGame, const sf::Color& mCapColor) { const auto sides(mHexagonGame.getSides()); const float div{ssvu::tau / sides * 0.5f}; @@ -87,7 +88,7 @@ void CPlayer::drawPivot(HexagonGame& mHexagonGame) mHexagonGame.capTris.reserve_more(3); mHexagonGame.capTris.batch_unsafe_emplace_back( - colorDarkened, p1, p2, startPos); + mCapColor, p1, p2, startPos); } } diff --git a/src/SSVOpenHexagon/Core/HGGraphics.cpp b/src/SSVOpenHexagon/Core/HGGraphics.cpp index 5392ee5a..42989c4f 100644 --- a/src/SSVOpenHexagon/Core/HGGraphics.cpp +++ b/src/SSVOpenHexagon/Core/HGGraphics.cpp @@ -4,6 +4,7 @@ #include "SSVOpenHexagon/Global/Assets.hpp" #include "SSVOpenHexagon/Utils/Utils.hpp" +#include "SSVOpenHexagon/Utils/Color.hpp" #include "SSVOpenHexagon/Core/HexagonGame.hpp" using namespace std; @@ -62,7 +63,7 @@ void HexagonGame::draw() if(status.started) { - player.draw(*this); + player.draw(*this, styleData.getCapColorResult()); } if(Config::get3D()) diff --git a/src/SSVOpenHexagon/Core/HGScripting.cpp b/src/SSVOpenHexagon/Core/HGScripting.cpp index 9e45e32f..328d6349 100644 --- a/src/SSVOpenHexagon/Core/HGScripting.cpp +++ b/src/SSVOpenHexagon/Core/HGScripting.cpp @@ -19,44 +19,46 @@ namespace hg void HexagonGame::initLua_Utils() { - lua.writeVariable("u_log", [=](string mLog) { lo("lua") << mLog << "\n"; }); - lua.writeVariable("u_execScript", [=](string mName) { + lua.writeVariable( + "u_log", [this](string mLog) { lo("lua") << mLog << "\n"; }); + lua.writeVariable("u_execScript", [this](string mName) { runLuaFile(levelData->packPath + "Scripts/" + mName); }); lua.writeVariable( - "u_playSound", [=](string mId) { assets.playSound(mId); }); - lua.writeVariable("u_setMusic", [=](string mId) { + "u_playSound", [this](string mId) { assets.playSound(mId); }); + lua.writeVariable("u_setMusic", [this](string mId) { musicData = assets.getMusicData(mId); musicData.firstPlay = true; stopLevelMusic(); playLevelMusic(); }); lua.writeVariable("u_isKeyPressed", - [=](int mKey) { return window.getInputState()[KKey(mKey)]; }); + [this](int mKey) { return window.getInputState()[KKey(mKey)]; }); lua.writeVariable( - "u_getPlayerAngle", [=] { return player.getPlayerAngle(); }); + "u_getPlayerAngle", [this] { return player.getPlayerAngle(); }); lua.writeVariable("u_setPlayerAngle", - [=](float newAng) { player.setPlayerAngle(newAng); }); + [this](float newAng) { player.setPlayerAngle(newAng); }); lua.writeVariable("u_isMouseButtonPressed", - [=](int mKey) { return window.getInputState()[MBtn(mKey)]; }); + [this](int mKey) { return window.getInputState()[MBtn(mKey)]; }); - lua.writeVariable("u_isFastSpinning", [=] { return status.fastSpin > 0; }); - lua.writeVariable("u_forceIncrement", [=] { incrementDifficulty(); }); lua.writeVariable( - "u_kill", [=] { timeline.append<Do>([=] { death(true); }); }); + "u_isFastSpinning", [this] { return status.fastSpin > 0; }); + lua.writeVariable("u_forceIncrement", [this] { incrementDifficulty(); }); lua.writeVariable( - "u_eventKill", [=] { eventTimeline.append<Do>([=] { death(true); }); }); - lua.writeVariable("u_getDifficultyMult", [=] { return difficultyMult; }); - lua.writeVariable("u_getSpeedMultDM", [=] { return getSpeedMultDM(); }); - lua.writeVariable("u_getDelayMultDM", [=] { return getDelayMultDM(); }); + "u_kill", [this] { timeline.append<Do>([this] { death(true); }); }); + lua.writeVariable("u_eventKill", + [this] { eventTimeline.append<Do>([this] { death(true); }); }); + lua.writeVariable("u_getDifficultyMult", [this] { return difficultyMult; }); + lua.writeVariable("u_getSpeedMultDM", [this] { return getSpeedMultDM(); }); + lua.writeVariable("u_getDelayMultDM", [this] { return getDelayMultDM(); }); } void HexagonGame::initLua_Messages() { - lua.writeVariable("m_messageAdd", [=](string mMsg, float mDuration) { - eventTimeline.append<Do>([=] { + lua.writeVariable("m_messageAdd", [this](string mMsg, float mDuration) { + eventTimeline.append<Do>([=, this] { if(firstPlay && Config::getShowMessages()) { addMessage(mMsg, mDuration); @@ -65,8 +67,8 @@ void HexagonGame::initLua_Messages() }); lua.writeVariable( - "m_messageAddImportant", [=](string mMsg, float mDuration) { - eventTimeline.append<Do>([=] { + "m_messageAddImportant", [this](string mMsg, float mDuration) { + eventTimeline.append<Do>([=, this] { if(Config::getShowMessages()) { addMessage(mMsg, mDuration); @@ -77,16 +79,16 @@ void HexagonGame::initLua_Messages() void HexagonGame::initLua_MainTimeline() { - lua.writeVariable( - "t_wait", [=](float mDuration) { timeline.append<Wait>(mDuration); }); + lua.writeVariable("t_wait", + [this](float mDuration) { timeline.append<Wait>(mDuration); }); - lua.writeVariable("t_waitS", [=](float mDuration) { + lua.writeVariable("t_waitS", [this](float mDuration) { timeline.append<Wait>(ssvu::getSecondsToFT(mDuration)); }); - lua.writeVariable("t_waitUntilS", [=](float mDuration) { + lua.writeVariable("t_waitUntilS", [this](float mDuration) { timeline.append<Wait>(10); - timeline.append<Do>([=] { + timeline.append<Do>([=, this] { if(status.currentTime < mDuration) { timeline.jumpTo(timeline.getCurrentIndex() - 2); @@ -97,25 +99,25 @@ void HexagonGame::initLua_MainTimeline() void HexagonGame::initLua_EventTimeline() { - lua.writeVariable("e_eventStopTime", [=](float mDuration) { - eventTimeline.append<Do>([=] { status.timeStop = mDuration; }); + lua.writeVariable("e_eventStopTime", [this](float mDuration) { + eventTimeline.append<Do>([=, this] { status.timeStop = mDuration; }); }); - lua.writeVariable("e_eventStopTimeS", [=](float mDuration) { + lua.writeVariable("e_eventStopTimeS", [this](float mDuration) { eventTimeline.append<Do>( - [=] { status.timeStop = ssvu::getSecondsToFT(mDuration); }); + [=, this] { status.timeStop = ssvu::getSecondsToFT(mDuration); }); }); lua.writeVariable("e_eventWait", - [=](float mDuration) { eventTimeline.append<Wait>(mDuration); }); + [this](float mDuration) { eventTimeline.append<Wait>(mDuration); }); - lua.writeVariable("e_eventWaitS", [=](float mDuration) { + lua.writeVariable("e_eventWaitS", [this](float mDuration) { eventTimeline.append<Wait>(ssvu::getSecondsToFT(mDuration)); }); - lua.writeVariable("e_eventWaitUntilS", [=](float mDuration) { + lua.writeVariable("e_eventWaitUntilS", [this](float mDuration) { eventTimeline.append<Wait>(10); - eventTimeline.append<Do>([=] { + eventTimeline.append<Do>([=, this] { if(status.currentTime < mDuration) { eventTimeline.jumpTo(eventTimeline.getCurrentIndex() - 2); @@ -174,24 +176,25 @@ void HexagonGame::initLua_LevelControl() lsVar("MaxInc", &LevelStatus::maxIncrements); // backwards-compatible lsVar("MaxIncrements", &LevelStatus::maxIncrements); - lua.writeVariable("l_addTracked", [=](string mVar, string mName) { + lua.writeVariable("l_addTracked", [this](string mVar, string mName) { levelStatus.trackedVariables.emplace_back(mVar, mName); }); lua.writeVariable("l_setRotation", - [=](float mValue) { backgroundCamera.setRotation(mValue); }); + [this](float mValue) { backgroundCamera.setRotation(mValue); }); lua.writeVariable( - "l_getRotation", [=] { return backgroundCamera.getRotation(); }); + "l_getRotation", [this] { return backgroundCamera.getRotation(); }); lua.writeVariable( - "l_getLevelTime", [=] { return (float)status.currentTime; }); + "l_getLevelTime", [this] { return (float)status.currentTime; }); - lua.writeVariable("l_getOfficial", [=] { return Config::getOfficial(); }); + lua.writeVariable( + "l_getOfficial", [this] { return Config::getOfficial(); }); // TODO: test and consider re-enabling /* - lua.writeVariable("l_setLevel", [=](string mId) + lua.writeVariable("l_setLevel", [this](string mId) { setLevelData(assets.getLevelData(mId), true); stopLevelMusic(); @@ -234,35 +237,45 @@ void HexagonGame::initLua_StyleControl() sdVar("3dPerspectiveMult", &StyleData::_3dPerspectiveMult); lua.writeVariable("s_setStyle", - [=](string mId) { styleData = assets.getStyleData(mId); }); + [this](string mId) { styleData = assets.getStyleData(mId); }); // backwards-compatible lua.writeVariable("s_setCameraShake", - [=](int mValue) { levelStatus.cameraShake = mValue; }); + [this](int mValue) { levelStatus.cameraShake = mValue; }); // backwards-compatible lua.writeVariable( - "s_getCameraShake", [=] { return levelStatus.cameraShake; }); + "s_getCameraShake", [this] { return levelStatus.cameraShake; }); + + lua.writeVariable("s_setCapColorMain", + [this] { styleData.capColor = CapColorMode::Main{}; }); + + lua.writeVariable("s_setCapColorMainDarkened", + [this] { styleData.capColor = CapColorMode::MainDarkened{}; }); + + lua.writeVariable("s_setCapColorByIndex", [this](int mIndex) { + styleData.capColor = CapColorMode::ByIndex{mIndex}; + }); } void HexagonGame::initLua_WallCreation() { - lua.writeVariable("w_wall", [=](int mSide, float mThickness) { + lua.writeVariable("w_wall", [this](int mSide, float mThickness) { timeline.append<Do>( - [=] { createWall(mSide, mThickness, {getSpeedMultDM()}); }); + [=, this] { createWall(mSide, mThickness, {getSpeedMultDM()}); }); }); lua.writeVariable( - "w_wallAdj", [=](int mSide, float mThickness, float mSpeedAdj) { - timeline.append<Do>([=] { + "w_wallAdj", [this](int mSide, float mThickness, float mSpeedAdj) { + timeline.append<Do>([=, this] { createWall(mSide, mThickness, mSpeedAdj * getSpeedMultDM()); }); }); lua.writeVariable("w_wallAcc", - [=](int mSide, float mThickness, float mSpeedAdj, float mAcceleration, - float mMinSpeed, float mMaxSpeed) { - timeline.append<Do>([=] { + [this](int mSide, float mThickness, float mSpeedAdj, + float mAcceleration, float mMinSpeed, float mMaxSpeed) { + timeline.append<Do>([=, this] { createWall(mSide, mThickness, {mSpeedAdj * getSpeedMultDM(), mAcceleration, mMinSpeed * getSpeedMultDM(), @@ -271,9 +284,9 @@ void HexagonGame::initLua_WallCreation() }); lua.writeVariable("w_wallHModSpeedData", - [=](float mHMod, int mSide, float mThickness, float mSAdj, float mSAcc, - float mSMin, float mSMax, bool mSPingPong) { - timeline.append<Do>([=] { + [this](float mHMod, int mSide, float mThickness, float mSAdj, + float mSAcc, float mSMin, float mSMax, bool mSPingPong) { + timeline.append<Do>([=, this] { createWall(mSide, mThickness, {mSAdj * getSpeedMultDM(), mSAcc, mSMin, mSMax, mSPingPong}, mHMod); @@ -281,9 +294,9 @@ void HexagonGame::initLua_WallCreation() }); lua.writeVariable("w_wallHModCurveData", - [=](float mHMod, int mSide, float mThickness, float mCAdj, float mCAcc, - float mCMin, float mCMax, bool mCPingPong) { - timeline.append<Do>([=] { + [this](float mHMod, int mSide, float mThickness, float mCAdj, + float mCAcc, float mCMin, float mCMax, bool mCPingPong) { + timeline.append<Do>([=, this] { createWall(mSide, mThickness, {getSpeedMultDM()}, {mCAdj, mCAcc, mCMin, mCMax, mCPingPong}, mHMod); }); diff --git a/src/SSVOpenHexagon/Data/CapColor.cpp b/src/SSVOpenHexagon/Data/CapColor.cpp new file mode 100644 index 00000000..4e1a7136 --- /dev/null +++ b/src/SSVOpenHexagon/Data/CapColor.cpp @@ -0,0 +1,41 @@ +// Copyright (c) 2013-2015 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: http://opensource.org/licenses/AFL-3.0 + +#include "SSVOpenHexagon/Data/CapColor.hpp" + +#include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" + +#include <string> + +namespace hg +{ + +[[nodiscard]] CapColor parseCapColor(const ssvuj::Obj& obj) noexcept +{ + if(ssvuj::isObjType<std::string>(obj)) + { + const std::string str = ssvuj::getExtr<std::string>(obj); + + if(str == "main") + { + return CapColorMode::Main{}; + } + + if(str == "main_darkened") + { + return CapColorMode::MainDarkened{}; + } + } + + if(ssvuj::isObj(obj)) + { + const int index = ssvuj::getExtr<int>(obj, "index", 0); + return CapColorMode::ByIndex{index}; + } + + // Fallback case: + return CapColorMode::ByIndex{0}; +} + +} // namespace hg diff --git a/src/SSVOpenHexagon/Data/StyleData.cpp b/src/SSVOpenHexagon/Data/StyleData.cpp index aa9a3c14..13844ace 100644 --- a/src/SSVOpenHexagon/Data/StyleData.cpp +++ b/src/SSVOpenHexagon/Data/StyleData.cpp @@ -4,6 +4,8 @@ #include "SSVOpenHexagon/Data/StyleData.hpp" #include "SSVOpenHexagon/Utils/Utils.hpp" +#include "SSVOpenHexagon/Utils/Match.hpp" +#include "SSVOpenHexagon/Utils/Color.hpp" #include "SSVOpenHexagon/Global/Config.hpp" using namespace std; @@ -171,4 +173,16 @@ void StyleData::drawBackground(RenderTarget& mRenderTarget, mRenderTarget.draw(vertices); } +sf::Color StyleData::getCapColorResult() const noexcept +{ + return Utils::match( + capColor, // + [this](CapColorMode::Main) { return getMainColor(); }, // + [this](CapColorMode::MainDarkened) { + return Utils::getColorDarkened(getMainColor(), 1.4f); + }, // + [this](CapColorMode::ByIndex x) { return getColor(x.index); } // + ); +} + } // namespace hg |