forked from itgmania/itgmania
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a "GameplayHelpers" file and move the margin gathering code
in there.
- Loading branch information
Showing
4 changed files
with
82 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <vector> | ||
|
||
#include "global.h" | ||
|
||
#include "EnumHelper.h" | ||
#include "GameplayHelpers.h" | ||
#include "GameState.h" | ||
#include "LuaManager.h" | ||
#include "ThemeManager.h" | ||
#include "Style.h" | ||
|
||
std::vector<NotefieldMargins> GetNotefieldMargins() { | ||
LuaReference margin_func; | ||
std::vector<NotefieldMargins> margins(2); | ||
|
||
THEME->GetMetric("ScreenGameplay", "MarginFunction", margin_func); | ||
if (margin_func.GetLuaType() != LUA_TFUNCTION) | ||
{ | ||
LuaHelpers::ReportScriptErrorFmt("MarginFunction metric for %s must be a function.", "ScreenGameplay"); | ||
return margins; | ||
} | ||
|
||
// Setup the lua. | ||
Lua* lua_ptr = LUA->Get(); | ||
margin_func.PushSelf(lua_ptr); | ||
lua_createtable(lua_ptr, 0, 0); | ||
int next_player_slot = 1; | ||
FOREACH_EnabledPlayer(pn) | ||
{ | ||
Enum::Push(lua_ptr, pn); | ||
lua_rawseti(lua_ptr, -2, next_player_slot); | ||
++next_player_slot; | ||
} | ||
|
||
Enum::Push(lua_ptr, GAMESTATE->GetCurrentStyle(PLAYER_INVALID)->m_StyleType); | ||
RString err = "Error running MarginFunction: "; | ||
|
||
// Run the lua code. | ||
if (LuaHelpers::RunScriptOnStack(lua_ptr, /*Error=*/err, /*Args=*/2, /*ReturnValues*/3, /*ReportOnError*/true)) | ||
{ | ||
std::string margin_error_msg = "Margin value must be a number."; | ||
|
||
// Pull the values off the lua stack. Note that the lua function is | ||
// returning the combined margins of P1 + P2 combined. Therefore, we | ||
// need to use the center to tell where P1's margin ends and P2's | ||
// begins, if applicable. | ||
margins[PLAYER_1].left = SafeFArg(lua_ptr, -3, margin_error_msg, 40); | ||
float center = SafeFArg(lua_ptr, -2, margin_error_msg, 80); | ||
margins[PLAYER_1].right = center / 2.0f; | ||
|
||
margins[PLAYER_2].left = center / 2.0f; | ||
margins[PLAYER_2].right = SafeFArg(lua_ptr, -1, margin_error_msg, 40); | ||
} | ||
lua_settop(lua_ptr, 0); | ||
LUA->Release(lua_ptr); | ||
return margins; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <vector> | ||
|
||
|
||
// A very simple pair floats that represent the pixels of the left and right | ||
// sides of a player's notefield margins. | ||
struct NotefieldMargins { | ||
float left = -1; | ||
float right = -1; | ||
}; | ||
|
||
// Use the lua MarginFunction (defined in metrics.ini) to calculate where the notefields | ||
// should be. This should (but doesn't have to) the engine's CenterP1 preference. | ||
// | ||
// By default points to GameplayMargins in Themes/_fallback/Scripts/03 Gameplay.lua | ||
std::vector<NotefieldMargins> GetNotefieldMargins(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters