Skip to content

Commit

Permalink
save all possible bindings, dont falsely remove default bindings on load
Browse files Browse the repository at this point in the history
also add lua access to binding save and load
this adds access to saving and loading the mysterious 4th and 5th columns as well as modifying the 3rd (default) column. ScreenMapControllers still only shows 3 columns and does not allow mapping the deafult column, for legacy behavior
  • Loading branch information
poco0317 committed Jun 24, 2021
1 parent a2136a1 commit 43ca6aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Etterna/Screen/Others/ScreenMapControllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ static LocalizedString SAVE_PROMPT("ScreenMapControllers", "SavePrompt");

static const float g_fSecondsToWaitForInput = 0.05f;

// reserve the 3rd slot for hard-coded keys
static const int NUM_CHANGABLE_SLOTS = NUM_SHOWN_GAME_TO_DEVICE_SLOTS - 1;
// two keys are allowed to be bound by the player
static const int NUM_CHANGABLE_SLOTS = NUM_USER_GAME_TO_DEVICE_SLOTS;

REGISTER_SCREEN_CLASS(ScreenMapControllers);

Expand Down
41 changes: 25 additions & 16 deletions src/Etterna/Singletons/InputMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ static const AutoMappings g_DefaultKeyMappings = AutoMappings(
void
InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped()
{
// Clear default mappings. Default mappings are in the third slot.
FOREACH_ENUM(GameController, i)
FOREACH_ENUM(GameButton, j)
ClearFromInputMap(GameInput(i, j), 2);

vector<AutoMappingEntry> aMaps;
aMaps.reserve(32);

Expand All @@ -116,13 +111,16 @@ InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped()
GameInput GameI(m->m_bSecondController ? GameController_2
: GameController_1,
m->m_gb);
if (!IsMapped(DeviceI)) // if this key isn't already being used by
// another user-made mapping
// dont remap a button that is already being used
if (!IsMapped(DeviceI))
{
if (!GameI.IsValid())
ClearFromInputMap(DeviceI);
else
SetInputMap(DeviceI, GameI, 2);
else {
// dont remap a default column binding
if (!m_mappings.m_GItoDI[GameI.controller][GameI.button][2].IsValid())
SetInputMap(DeviceI, GameI, 2);
}
}
}
}
Expand Down Expand Up @@ -740,8 +738,8 @@ InputMapper::GetInputScheme() const
return m_pInputScheme;
}

const std::string DEVICE_INPUT_SEPARATOR =
":"; // this isn't used in any key names
// this isn't used in any key names
const std::string DEVICE_INPUT_SEPARATOR = ":";

void
InputMapper::ReadMappingsFromDisk()
Expand Down Expand Up @@ -1308,7 +1306,7 @@ InputMappings::Unmap(InputDevice id)
{
FOREACH_ENUM(GameButton, j)
{
for (int k = 0; k < NUM_USER_GAME_TO_DEVICE_SLOTS; k++) {
for (int k = 0; k < NUM_GAME_TO_DEVICE_SLOTS; k++) {
DeviceInput& di = m_GItoDI[i][j][k];
if (di.device == id)
di.MakeInvalid();
Expand Down Expand Up @@ -1394,10 +1392,9 @@ InputMappings::WriteMappings(const InputScheme* pInputScheme,
std::string sNameString = GameI.ToString(pInputScheme);

vector<std::string> asValues;
asValues.reserve(NUM_USER_GAME_TO_DEVICE_SLOTS);
for (int slot = 0; slot < NUM_USER_GAME_TO_DEVICE_SLOTS;
++slot) // don't save data from the last (keyboard automap)
// slot
asValues.reserve(NUM_GAME_TO_DEVICE_SLOTS);
for (int slot = 0; slot < NUM_GAME_TO_DEVICE_SLOTS;
++slot)
asValues.push_back(m_GItoDI[i][j][slot].ToString());

while (!asValues.empty() && asValues.back().empty())
Expand Down Expand Up @@ -1538,6 +1535,16 @@ class LunaInputMapper : public Luna<InputMapper>
lua_pushnil(L);
return 1;
}
static int SaveMappingsToDisk(T* p, lua_State* L)
{
p->SaveMappingsToDisk();
return 0;
}
static int ReadMappingsFromDisk(T* p, lua_State* L)
{
p->ReadMappingsFromDisk();
return 0;
}


LunaInputMapper()
Expand All @@ -1546,6 +1553,8 @@ class LunaInputMapper : public Luna<InputMapper>
ADD_METHOD(GetGameButtonsToMap);
ADD_METHOD(GetMenuButtonsToMap);
ADD_METHOD(GetButtonMapping);
ADD_METHOD(SaveMappingsToDisk);
ADD_METHOD(ReadMappingsFromDisk);
}
};

Expand Down
6 changes: 4 additions & 2 deletions src/Etterna/Singletons/InputMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include "RageUtil/Misc/RageInputDevice.h"
struct Game;

const int NUM_GAME_TO_DEVICE_SLOTS =
5; // five device inputs may map to one game input
// five device inputs may map to one game input
const int NUM_GAME_TO_DEVICE_SLOTS = 5;
// three device inputs are shown to the player
const int NUM_SHOWN_GAME_TO_DEVICE_SLOTS = 3;
// two are allowed to be bound by the player
const int NUM_USER_GAME_TO_DEVICE_SLOTS = 2;
extern const std::string DEVICE_INPUT_SEPARATOR;

Expand Down

0 comments on commit 43ca6aa

Please sign in to comment.