move button names from ship to LUS (#943)

* a bunch of button name plumbing

* remove the parts

* clang-format

* start moving things

* bit more

* clang format

* remove a line

* builds

* working
This commit is contained in:
briaguya
2025-10-17 05:58:18 -04:00
committed by GitHub
parent 9abb6790d3
commit 83230365de
12 changed files with 62 additions and 65 deletions
@@ -8,6 +8,7 @@
#include "ship/controller/physicaldevice/ConnectedPhysicalDeviceManager.h"
#include "ship/controller/physicaldevice/GlobalSDLDeviceSettings.h"
#include "ship/controller/controldevice/controller/mapping/ControllerDefaultMappings.h"
#include "libultraship/libultra/controller.h"
namespace LUS {
class ControlDeck final : public Ship::ControlDeck {
@@ -15,7 +16,8 @@ class ControlDeck final : public Ship::ControlDeck {
ControlDeck();
ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks);
ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks,
std::shared_ptr<Ship::ControllerDefaultMappings> controllerDefaultMappings);
std::shared_ptr<Ship::ControllerDefaultMappings> controllerDefaultMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::string> buttonNames);
OSContPad* GetPads();
void WriteToPad(void* pad) override;
@@ -15,8 +15,7 @@
namespace LUS {
class Controller : public Ship::Controller {
public:
Controller(uint8_t portIndex);
Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> additionalBitmasks);
Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> bitmasks);
void ReadToPad(void* pad) override;
@@ -13,7 +13,8 @@ namespace Ship {
class ControlDeck {
public:
ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks,
std::shared_ptr<ControllerDefaultMappings> controllerDefaultMappings);
std::shared_ptr<ControllerDefaultMappings> controllerDefaultMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::string> buttonNames);
~ControlDeck();
void Init(uint8_t* controllerBits);
@@ -31,6 +32,8 @@ class ControlDeck {
std::shared_ptr<ConnectedPhysicalDeviceManager> GetConnectedPhysicalDeviceManager();
std::shared_ptr<GlobalSDLDeviceSettings> GetGlobalSDLDeviceSettings();
std::shared_ptr<ControllerDefaultMappings> GetControllerDefaultMappings();
const std::unordered_map<CONTROLLERBUTTONS_T, std::string>& GetAllButtonNames() const;
std::string GetButtonNameForBitmask(CONTROLLERBUTTONS_T bitmask);
protected:
bool AllGameInputBlocked();
@@ -42,5 +45,6 @@ class ControlDeck {
std::shared_ptr<ConnectedPhysicalDeviceManager> mConnectedPhysicalDeviceManager;
std::shared_ptr<GlobalSDLDeviceSettings> mGlobalSDLDeviceSettings;
std::shared_ptr<ControllerDefaultMappings> mControllerDefaultMappings;
std::unordered_map<CONTROLLERBUTTONS_T, std::string> mButtonNames;
};
} // namespace Ship
@@ -20,8 +20,7 @@ namespace Ship {
class Controller : public ControlDevice {
public:
Controller(uint8_t portIndex);
Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> additionalBitmasks);
Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> bitmasks);
~Controller();
void ReloadAllMappingsFromConfig();
@@ -4,15 +4,10 @@
#include <memory>
#include <unordered_map>
#include <string>
#include "libultraship/libultra/controller.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
#define BUTTON_BITMASKS \
BTN_A, BTN_B, BTN_L, BTN_R, BTN_Z, BTN_START, BTN_CLEFT, BTN_CRIGHT, BTN_CUP, BTN_CDOWN, BTN_DLEFT, BTN_DRIGHT, \
BTN_DUP, BTN_DDOWN
class ControllerButton {
public:
ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask);
+2
View File
@@ -35,6 +35,8 @@
#include "ship/Context.h"
#include "ship/config/ConsoleVariable.h"
#include "libultraship/libultra/os.h"
#include <spdlog/fmt/fmt.h>
std::stack<std::string> currentDir;
@@ -9,15 +9,37 @@
namespace LUS {
ControlDeck::ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks,
std::shared_ptr<Ship::ControllerDefaultMappings> controllerDefaultMappings)
: Ship::ControlDeck(additionalBitmasks, controllerDefaultMappings), mPads(nullptr) {
std::shared_ptr<Ship::ControllerDefaultMappings> controllerDefaultMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::string> buttonNames)
: Ship::ControlDeck(additionalBitmasks, controllerDefaultMappings, buttonNames), mPads(nullptr) {
std::vector<CONTROLLERBUTTONS_T> bitmasks;
for (auto [bitmask, name] : buttonNames) {
bitmasks.push_back(bitmask);
}
bitmasks.insert(bitmasks.end(), additionalBitmasks.begin(), additionalBitmasks.end());
for (int32_t i = 0; i < MAXCONTROLLERS; i++) {
mPorts.push_back(std::make_shared<Ship::ControlPort>(i, std::make_shared<Controller>(i, additionalBitmasks)));
mPorts.push_back(std::make_shared<Ship::ControlPort>(i, std::make_shared<Controller>(i, bitmasks)));
}
}
ControlDeck::ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks)
: ControlDeck(additionalBitmasks, std::make_shared<LUS::ControllerDefaultMappings>()) {
: ControlDeck(additionalBitmasks, std::make_shared<LUS::ControllerDefaultMappings>(),
std::unordered_map<CONTROLLERBUTTONS_T, std::string>({
{ BTN_A, "A" },
{ BTN_B, "B" },
{ BTN_L, "L" },
{ BTN_R, "R" },
{ BTN_Z, "Z" },
{ BTN_START, "Start" },
{ BTN_CLEFT, "CLeft" },
{ BTN_CRIGHT, "CRight" },
{ BTN_CUP, "CUp" },
{ BTN_CDOWN, "CDown" },
{ BTN_DLEFT, "DLeft" },
{ BTN_DRIGHT, "DRight" },
{ BTN_DUP, "DUp" },
{ BTN_DDOWN, "DDown" },
})) {
}
ControlDeck::ControlDeck() : ControlDeck(std::vector<CONTROLLERBUTTONS_T>()) {
@@ -15,11 +15,8 @@
#define MINIMUM_RADIUS_TO_MAP_NOTCH 0.9
namespace LUS {
Controller::Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> additionalBitmasks)
: Ship::Controller(portIndex, additionalBitmasks) {
}
Controller::Controller(uint8_t portIndex) : Ship::Controller(portIndex, {}) {
Controller::Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> bitmasks)
: Ship::Controller(portIndex, bitmasks) {
}
void Controller::ReadToPad(void* pad) {
@@ -10,7 +10,8 @@
namespace Ship {
ControlDeck::ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks,
std::shared_ptr<ControllerDefaultMappings> controllerDefaultMappings) {
std::shared_ptr<ControllerDefaultMappings> controllerDefaultMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::string> buttonNames) {
mConnectedPhysicalDeviceManager = std::make_shared<ConnectedPhysicalDeviceManager>();
mGlobalSDLDeviceSettings = std::make_shared<GlobalSDLDeviceSettings>();
mControllerDefaultMappings = controllerDefaultMappings == nullptr ? std::make_shared<ControllerDefaultMappings>()
@@ -118,4 +119,18 @@ std::shared_ptr<GlobalSDLDeviceSettings> ControlDeck::GetGlobalSDLDeviceSettings
std::shared_ptr<ControllerDefaultMappings> ControlDeck::GetControllerDefaultMappings() {
return mControllerDefaultMappings;
}
const std::unordered_map<CONTROLLERBUTTONS_T, std::string>& ControlDeck::GetAllButtonNames() const {
return mButtonNames;
}
std::string ControlDeck::GetButtonNameForBitmask(CONTROLLERBUTTONS_T bitmask) {
// if we don't have a name for this bitmask,
// return the stringified bitmask
if (!mButtonNames.contains(bitmask)) {
return std::to_string(bitmask);
}
return mButtonNames[bitmask];
}
} // namespace Ship
@@ -1,4 +1,5 @@
#include "ship/controller/controldevice/controller/Controller.h"
#include "ship/controller/controldeck/ControlDeck.h"
#include <memory>
#include <algorithm>
#include "ship/Context.h"
@@ -16,12 +17,8 @@
namespace Ship {
Controller::Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> additionalBitmasks)
: ControlDevice(portIndex) {
for (auto bitmask : { BUTTON_BITMASKS }) {
mButtons[bitmask] = std::make_shared<ControllerButton>(portIndex, bitmask);
}
for (auto bitmask : additionalBitmasks) {
Controller::Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> bitmasks) : ControlDevice(portIndex) {
for (auto bitmask : bitmasks) {
mButtons[bitmask] = std::make_shared<ControllerButton>(portIndex, bitmask);
}
mLeftStick = std::make_shared<ControllerStick>(portIndex, LEFT_STICK);
@@ -31,9 +28,6 @@ Controller::Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> addit
mLED = std::make_shared<ControllerLED>(portIndex);
}
Controller::Controller(uint8_t portIndex) : Controller(portIndex, {}) {
}
Controller::~Controller() {
SPDLOG_TRACE("destruct controller");
}
@@ -12,6 +12,7 @@
#include "ship/Context.h"
#include "ship/window/Window.h"
#include "ship/controller/controldeck/ControlDeck.h"
namespace Ship {
ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask)
@@ -23,41 +24,7 @@ ControllerButton::~ControllerButton() {
}
std::string ControllerButton::GetConfigNameFromBitmask(CONTROLLERBUTTONS_T bitmask) {
switch (bitmask) {
case BTN_A:
return "A";
case BTN_B:
return "B";
case BTN_L:
return "L";
case BTN_R:
return "R";
case BTN_Z:
return "Z";
case BTN_START:
return "Start";
case BTN_CLEFT:
return "CLeft";
case BTN_CRIGHT:
return "CRight";
case BTN_CUP:
return "CUp";
case BTN_CDOWN:
return "CDown";
case BTN_DLEFT:
return "DLeft";
case BTN_DRIGHT:
return "DRight";
case BTN_DUP:
return "DUp";
case BTN_DDOWN:
return "DDown";
default:
// if we don't have a name for this bitmask,
// which happens with additionalBitmasks provided by ports,
// return the stringified bitmask
return std::to_string(bitmask);
}
return Ship::Context::GetInstance()->GetControlDeck()->GetButtonNameForBitmask(bitmask);
}
std::unordered_map<std::string, std::shared_ptr<ControllerButtonMapping>> ControllerButton::GetAllButtonMappings() {
@@ -5,6 +5,7 @@
#include "ship/config/ConsoleVariable.h"
#include "ship/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h"
#include "ship/controller/controldeck/ControlDeck.h"
#include "libultraship/libultra/controller.h"
#define SCALE_IMGUI_SIZE(value) ((value / 13.0f) * ImGui::GetFontSize())