diff options
author | Vittorio Romeo <vittorio.romeo@outlook.com> | 2020-06-18 13:47:27 +0100 |
---|---|---|
committer | Vittorio Romeo <vittorio.romeo@outlook.com> | 2020-06-18 13:47:27 +0100 |
commit | 1c95c26b70eb900eb30da6e96ba8869d7de8ee32 (patch) | |
tree | b449816e4661d5f8ded00b65b79cfd0ca672a783 | |
parent | 97badef34e7c3a071c0928c144442ec49547136a (diff) |
Expose all style and level variables to LUAexpose_to_lua
-rw-r--r-- | _RELEASE/config.json | 2 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Core/HexagonGame.hpp | 8 | ||||
-rw-r--r-- | include/SSVOpenHexagon/Data/StyleData.hpp | 21 | ||||
-rw-r--r-- | src/SSVOpenHexagon/Core/HGScripting.cpp | 216 |
4 files changed, 160 insertions, 87 deletions
diff --git a/_RELEASE/config.json b/_RELEASE/config.json index 37ed9371..a13be31e 100644 --- a/_RELEASE/config.json +++ b/_RELEASE/config.json @@ -12,7 +12,7 @@ "debug" : false,
"draw_text_outlines" : false,
"flash_enabled" : true,
- "fullscreen" : true,
+ "fullscreen" : false,
"fullscreen_auto_resolution" : false,
"fullscreen_height" : 1080,
"fullscreen_width" : 1920,
diff --git a/include/SSVOpenHexagon/Core/HexagonGame.hpp b/include/SSVOpenHexagon/Core/HexagonGame.hpp index 4d29de3b..e696e9e1 100644 --- a/include/SSVOpenHexagon/Core/HexagonGame.hpp +++ b/include/SSVOpenHexagon/Core/HexagonGame.hpp @@ -97,6 +97,14 @@ private: CExprVec2f{-1, 1}, CExprVec2f{1, -1}, CExprVec2f{1, 1}}; // LUA-related methods + void initLua_Utils(); + void initLua_Messages(); + void initLua_MainTimeline(); + void initLua_EventTimeline(); + void initLua_LevelControl(); + void initLua_StyleControl(); + void initLua_WallCreation(); + void initLua(); void runLuaFile(const std::string& mFileName) { diff --git a/include/SSVOpenHexagon/Data/StyleData.hpp b/include/SSVOpenHexagon/Data/StyleData.hpp index a47a9452..d5ff98be 100644 --- a/include/SSVOpenHexagon/Data/StyleData.hpp +++ b/include/SSVOpenHexagon/Data/StyleData.hpp @@ -46,11 +46,24 @@ private: public: std::string id; - float hueMin, hueMax, hueIncrement, pulseMin, pulseMax, pulseIncrement; + float hueMin; + float hueMax; + float hueIncrement; + float pulseMin; + float pulseMax; + float pulseIncrement; bool huePingPong; - float maxSwapTime, _3dDepth, _3dSkew, _3dSpacing, _3dDarkenMult, - _3dAlphaMult, _3dAlphaFalloff, _3dPulseMax, _3dPulseMin, _3dPulseSpeed, - _3dPerspectiveMult; + float maxSwapTime; + float _3dDepth; + float _3dSkew; + float _3dSpacing; + float _3dDarkenMult; + float _3dAlphaMult; + float _3dAlphaFalloff; + float _3dPulseMax; + float _3dPulseMin; + float _3dPulseSpeed; + float _3dPerspectiveMult; sf::Color _3dOverrideColor; ColorData mainColorData; std::vector<ColorData> colorDatas; diff --git a/src/SSVOpenHexagon/Core/HGScripting.cpp b/src/SSVOpenHexagon/Core/HGScripting.cpp index 5998b2a5..890fe06c 100644 --- a/src/SSVOpenHexagon/Core/HGScripting.cpp +++ b/src/SSVOpenHexagon/Core/HGScripting.cpp @@ -17,9 +17,8 @@ using namespace ssvuj; namespace hg { -void HexagonGame::initLua() +void HexagonGame::initLua_Utils() { - // Utils lua.writeVariable("u_log", [=](string mLog) { lo("lua") << mLog << "\n"; }); lua.writeVariable("u_execScript", [=](string mName) { runLuaFile(levelData->packPath + "Scripts/" + mName); @@ -34,7 +33,8 @@ void HexagonGame::initLua() }); lua.writeVariable("u_isKeyPressed", [=](int mKey) { return window.getInputState()[KKey(mKey)]; }); - lua.writeVariable("u_isMouseButtonPressed", [=] (int mKey) { return window.getInputState()[MBtn(mKey)]; }); + lua.writeVariable("u_isMouseButtonPressed", + [=](int mKey) { return window.getInputState()[MBtn(mKey)]; }); lua.writeVariable("u_isFastSpinning", [=] { return status.fastSpin > 0; }); lua.writeVariable("u_forceIncrement", [=] { incrementDifficulty(); }); lua.writeVariable( @@ -44,8 +44,10 @@ void HexagonGame::initLua() lua.writeVariable("u_getDifficultyMult", [=] { return difficultyMult; }); lua.writeVariable("u_getSpeedMultDM", [=] { return getSpeedMultDM(); }); lua.writeVariable("u_getDelayMultDM", [=] { return getDelayMultDM(); }); +} - // Messages +void HexagonGame::initLua_Messages() +{ lua.writeVariable("m_messageAdd", [=](string mMsg, float mDuration) { eventTimeline.append<Do>([=] { if(firstPlay && Config::getShowMessages()) @@ -54,6 +56,7 @@ void HexagonGame::initLua() } }); }); + lua.writeVariable( "m_messageAddImportant", [=](string mMsg, float mDuration) { eventTimeline.append<Do>([=] { @@ -63,13 +66,17 @@ void HexagonGame::initLua() } }); }); +} - // Main timeline control +void HexagonGame::initLua_MainTimeline() +{ lua.writeVariable( "t_wait", [=](float mDuration) { timeline.append<Wait>(mDuration); }); + lua.writeVariable("t_waitS", [=](float mDuration) { timeline.append<Wait>(ssvu::getSecondsToFT(mDuration)); }); + lua.writeVariable("t_waitUntilS", [=](float mDuration) { timeline.append<Wait>(10); timeline.append<Do>([=] { @@ -79,20 +86,26 @@ void HexagonGame::initLua() } }); }); +} - // Event timeline control +void HexagonGame::initLua_EventTimeline() +{ lua.writeVariable("e_eventStopTime", [=](float mDuration) { eventTimeline.append<Do>([=] { status.timeStop = mDuration; }); }); + lua.writeVariable("e_eventStopTimeS", [=](float mDuration) { eventTimeline.append<Do>( [=] { status.timeStop = ssvu::getSecondsToFT(mDuration); }); }); + lua.writeVariable("e_eventWait", [=](float mDuration) { eventTimeline.append<Wait>(mDuration); }); + lua.writeVariable("e_eventWaitS", [=](float mDuration) { eventTimeline.append<Wait>(ssvu::getSecondsToFT(mDuration)); }); + lua.writeVariable("e_eventWaitUntilS", [=](float mDuration) { eventTimeline.append<Wait>(10); eventTimeline.append<Do>([=] { @@ -102,84 +115,73 @@ void HexagonGame::initLua() } }); }); +} + +void HexagonGame::initLua_LevelControl() +{ + + const auto lsVar = [this](const std::string& name, auto pmd) { + using Type = std::decay_t<decltype(levelStatus.*pmd)>; + + lua.writeVariable(std::string{"l_get"} + name, + [this, pmd]() -> Type { return levelStatus.*pmd; }); + + lua.writeVariable(std::string{"l_set"} + name, + [this, pmd](Type mValue) { levelStatus.*pmd = mValue; }); + }; + + lsVar("SpeedMult", &LevelStatus::speedMult); + lsVar("SpeedInc", &LevelStatus::speedInc); + lsVar("RotationSpeed", &LevelStatus::rotationSpeed); + lsVar("RotationSpeedInc", &LevelStatus::rotationSpeedInc); + lsVar("RotationSpeedMax", &LevelStatus::rotationSpeedMax); + lsVar("DelayMult", &LevelStatus::delayMult); + lsVar("DelayInc", &LevelStatus::delayInc); + lsVar("FastSpin", &LevelStatus::fastSpin); + lsVar("IncTime", &LevelStatus::incTime); + lsVar("PulseMin", &LevelStatus::pulseMin); + lsVar("PulseMax", &LevelStatus::pulseMax); + lsVar("PulseSpeed", &LevelStatus::pulseSpeed); + lsVar("PulseSpeedR", &LevelStatus::pulseSpeedR); + lsVar("PulseDelayMax", &LevelStatus::pulseDelayMax); + lsVar("PulseDelayHalfMax", &LevelStatus::pulseDelayHalfMax); + lsVar("BeatPulseMax", &LevelStatus::beatPulseMax); + lsVar("BeatPulseDelayMax", &LevelStatus::beatPulseDelayMax); + lsVar("RadiusMin", &LevelStatus::radiusMin); + lsVar("WallSkewLeft", &LevelStatus::wallSkewLeft); + lsVar("WallSkewRight", &LevelStatus::wallSkewRight); + lsVar("WallAngleLeft", &LevelStatus::wallAngleLeft); + lsVar("WallAngleRight", &LevelStatus::wallAngleRight); + lsVar("3dEffectMultiplier", &LevelStatus::_3dEffectMultiplier); + lsVar("CameraShake", &LevelStatus::cameraShake); + lsVar("Sides", &LevelStatus::sides); + lsVar("SidesMax", &LevelStatus::sidesMax); + lsVar("SidesMin", &LevelStatus::sidesMin); + lsVar("SwapEnabled", &LevelStatus::swapEnabled); + lsVar("TutorialMode", &LevelStatus::tutorialMode); + lsVar("IncEnabled", &LevelStatus::incEnabled); + lsVar("RndSideChangesEnabled", &LevelStatus::rndSideChangesEnabled); + lsVar("DarkenUnevenBackgroundChunk", + &LevelStatus::darkenUnevenBackgroundChunk); + lsVar("CurrentIncrements", &LevelStatus::currentIncrements); + lsVar("MaxInc", &LevelStatus::maxIncrements); // backwards-compatible + lsVar("MaxIncrements", &LevelStatus::maxIncrements); - // Level control - lua.writeVariable("l_setSpeedMult", - [=](float mValue) { levelStatus.speedMult = mValue; }); - lua.writeVariable( - "l_setSpeedInc", [=](float mValue) { levelStatus.speedInc = mValue; }); - lua.writeVariable("l_setRotationSpeed", - [=](float mValue) { levelStatus.rotationSpeed = mValue; }); - lua.writeVariable("l_setRotationSpeedMax", - [=](float mValue) { levelStatus.rotationSpeedMax = mValue; }); - lua.writeVariable("l_setRotationSpeedInc", - [=](float mValue) { levelStatus.rotationSpeedInc = mValue; }); - lua.writeVariable("l_setDelayMult", - [=](float mValue) { levelStatus.delayMult = mValue; }); - lua.writeVariable( - "l_setDelayInc", [=](float mValue) { levelStatus.delayInc = mValue; }); - lua.writeVariable( - "l_setFastSpin", [=](float mValue) { levelStatus.fastSpin = mValue; }); - lua.writeVariable( - "l_setSides", [=](unsigned int mValue) { levelStatus.sides = mValue; }); - lua.writeVariable("l_setSidesMin", - [=](unsigned int mValue) { levelStatus.sidesMin = mValue; }); - lua.writeVariable("l_setSidesMax", - [=](unsigned int mValue) { levelStatus.sidesMax = mValue; }); - lua.writeVariable( - "l_setIncTime", [=](float mValue) { levelStatus.incTime = mValue; }); - lua.writeVariable( - "l_setPulseMin", [=](float mValue) { levelStatus.pulseMin = mValue; }); - lua.writeVariable( - "l_setPulseMax", [=](float mValue) { levelStatus.pulseMax = mValue; }); - lua.writeVariable("l_setPulseSpeed", - [=](float mValue) { levelStatus.pulseSpeed = mValue; }); - lua.writeVariable("l_setPulseSpeedR", - [=](float mValue) { levelStatus.pulseSpeedR = mValue; }); - lua.writeVariable("l_setPulseDelayMax", - [=](float mValue) { levelStatus.pulseDelayMax = mValue; }); - lua.writeVariable("l_setBeatPulseMax", - [=](float mValue) { levelStatus.beatPulseMax = mValue; }); - lua.writeVariable("l_setBeatPulseDelayMax", - [=](float mValue) { levelStatus.beatPulseDelayMax = mValue; }); - lua.writeVariable("l_setWallSkewLeft", - [=](float mValue) { levelStatus.wallSkewLeft = mValue; }); - lua.writeVariable("l_setWallSkewRight", - [=](float mValue) { levelStatus.wallSkewRight = mValue; }); - lua.writeVariable("l_setWallAngleLeft", - [=](float mValue) { levelStatus.wallAngleLeft = mValue; }); - lua.writeVariable("l_setWallAngleRight", - [=](float mValue) { levelStatus.wallAngleRight = mValue; }); - lua.writeVariable("l_setRadiusMin", - [=](float mValue) { levelStatus.radiusMin = mValue; }); - lua.writeVariable("l_setSwapEnabled", - [=](bool mValue) { levelStatus.swapEnabled = mValue; }); - lua.writeVariable("l_setTutorialMode", - [=](bool mValue) { levelStatus.tutorialMode = mValue; }); - lua.writeVariable("l_setIncEnabled", - [=](bool mValue) { levelStatus.incEnabled = mValue; }); - lua.writeVariable("l_setMaxInc", - [=](SizeT mValue) { levelStatus.maxIncrements = mValue; }); lua.writeVariable("l_addTracked", [=](string mVar, string mName) { levelStatus.trackedVariables.emplace_back(mVar, mName); }); - lua.writeVariable("l_enableRndSideChanges", - [=](bool mValue) { levelStatus.rndSideChangesEnabled = mValue; }); - lua.writeVariable("l_darkenUnevenBackgroundChunk", - [=](bool mValue) { levelStatus.darkenUnevenBackgroundChunk = mValue; }); - lua.writeVariable( - "l_getRotationSpeed", [=] { return levelStatus.rotationSpeed; }); + lua.writeVariable("l_setRotation", [=](float mValue) { backgroundCamera.setRotation(mValue); }); + lua.writeVariable( "l_getRotation", [=] { return backgroundCamera.getRotation(); }); - lua.writeVariable("l_getSides", [=] { return levelStatus.sides; }); - lua.writeVariable("l_getSpeedMult", [=] { return levelStatus.speedMult; }); - lua.writeVariable("l_getDelayMult", [=] { return levelStatus.delayMult; }); - lua.writeVariable("l_getMaxInc", [=] { return levelStatus.maxIncrements; }); + lua.writeVariable( "l_getLevelTime", [=] { return (float)status.currentTime; }); + lua.writeVariable("l_getOfficial", [=] { return Config::getOfficial(); }); + // TODO: test and consider re-enabling /* lua.writeVariable("l_setLevel", [=](string mId) @@ -189,31 +191,67 @@ void HexagonGame::initLua() playLevelMusic(); }); */ +} - // Style control - lua.writeVariable("s_setPulseInc", - [=](float mValue) { styleData.pulseIncrement = mValue; }); - lua.writeVariable( - "s_setHueInc", [=](float mValue) { styleData.hueIncrement = mValue; }); - lua.writeVariable("s_getHueInc", [=] { return styleData.hueIncrement; }); +void HexagonGame::initLua_StyleControl() +{ + const auto sdVar = [this](const std::string& name, auto pmd) { + using Type = std::decay_t<decltype(styleData.*pmd)>; + + lua.writeVariable(std::string{"s_get"} + name, + [this, pmd]() -> Type { return styleData.*pmd; }); + + lua.writeVariable(std::string{"s_set"} + name, + [this, pmd](Type mValue) { styleData.*pmd = mValue; }); + }; + + sdVar("HueMin", &StyleData::hueMin); + sdVar("HueMax", &StyleData::hueMax); + sdVar("HueInc", &StyleData::hueIncrement); // backwards-compatible + sdVar("HueIncrement", &StyleData::hueIncrement); + sdVar("PulseMin", &StyleData::pulseMin); + sdVar("PulseMax", &StyleData::pulseMax); + sdVar("PulseInc", &StyleData::pulseIncrement); // backwards-compatible + sdVar("PulseIncrement", &StyleData::pulseIncrement); + sdVar("HuePingPong", &StyleData::huePingPong); + sdVar("MaxSwapTime", &StyleData::maxSwapTime); + sdVar("3dDepth", &StyleData::_3dDepth); + sdVar("3dSkew", &StyleData::_3dSkew); + sdVar("3dSpacing", &StyleData::_3dSpacing); + sdVar("3dDarkenMult", &StyleData::_3dDarkenMult); + sdVar("3dAlphaMult", &StyleData::_3dAlphaMult); + sdVar("3dAlphaFalloff", &StyleData::_3dAlphaFalloff); + sdVar("3dPulseMax", &StyleData::_3dPulseMax); + sdVar("3dPulseMin", &StyleData::_3dPulseMin); + sdVar("3dPulseSpeed", &StyleData::_3dPulseSpeed); + sdVar("3dPerspectiveMult", &StyleData::_3dPerspectiveMult); + + lua.writeVariable("s_setStyle", + [=](string mId) { styleData = assets.getStyleData(mId); }); + + // backwards-compatible lua.writeVariable("s_setCameraShake", [=](int mValue) { levelStatus.cameraShake = mValue; }); + + // backwards-compatible lua.writeVariable( "s_getCameraShake", [=] { return levelStatus.cameraShake; }); - lua.writeVariable("s_setStyle", - [=](string mId) { styleData = assets.getStyleData(mId); }); +} - // Wall creation +void HexagonGame::initLua_WallCreation() +{ lua.writeVariable("w_wall", [=](int mSide, float mThickness) { timeline.append<Do>( [=] { factory.createWall(mSide, mThickness, {getSpeedMultDM()}); }); }); + lua.writeVariable("w_wallAdj", [=](int mSide, float mThickness, float mSpeedAdj) { timeline.append<Do>([=] { factory.createWall(mSide, mThickness, mSpeedAdj * getSpeedMultDM()); }); }); + lua.writeVariable("w_wallAcc", [=](int mSide, float mThickness, float mSpeedAdj, float mAcceleration, float mMinSpeed, float mMaxSpeed) { @@ -224,6 +262,7 @@ void HexagonGame::initLua() mMaxSpeed * getSpeedMultDM()}); }); }); + lua.writeVariable("w_wallHModSpeedData", [=](float mHMod, int mSide, float mThickness, float mSAdj, float mSAcc, float mSMin, float mSMax, bool mSPingPong) { @@ -233,6 +272,7 @@ void HexagonGame::initLua() mHMod); }); }); + lua.writeVariable("w_wallHModCurveData", [=](float mHMod, int mSide, float mThickness, float mCAdj, float mCAcc, float mCMin, float mCMax, bool mCPingPong) { @@ -242,4 +282,16 @@ void HexagonGame::initLua() }); }); } + +void HexagonGame::initLua() +{ + initLua_Utils(); + initLua_Messages(); + initLua_MainTimeline(); + initLua_EventTimeline(); + initLua_LevelControl(); + initLua_StyleControl(); + initLua_WallCreation(); +} + } // namespace hg |