Skip to content

Commit

Permalink
Print controls dictionary from module.cfg. Created key_bindings, butt…
Browse files Browse the repository at this point in the history
…on_bindings and axes_bindings structs.
  • Loading branch information
al0fdf committed Oct 4, 2024
1 parent 1679034 commit afbf8e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace controls
{
const char** control_names()
{
static const char* names[] = { "up", "down", "left", "right", "attack", "jump", "tongue", nullptr };
// Null-terminated list of action names
static const char* names[] = { "up", "down", "left", "right", "attack", "jump", "tongue", "sprint", nullptr };
return names;
}

Expand Down Expand Up @@ -94,6 +95,7 @@ namespace controls

int first_invalid_cycle_var = -1;

// List of SDL keycodes
key_type sdlk[NUM_CONTROLS] = {
SDLK_UP,
SDLK_DOWN,
Expand Down Expand Up @@ -342,6 +344,10 @@ namespace controls
if(joystick::button(2)) {
state.keys |= 0x40;
}
// sprint
if(joystick::button(3)) {
state.keys |= 0x80;
}

if(g_user_ctrl_output.is_null() == false) {
state.user = g_user_ctrl_output.write_json();
Expand All @@ -353,6 +359,8 @@ namespace controls

g_user_ctrl_output = variant();

// some kind of buffer for controls
// Seems actively used for controller input
controls[local_player].push_back(state);
highest_confirmed[local_player]++;

Expand Down
9 changes: 9 additions & 0 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "formula_constants.hpp"
#include "http_client.hpp"
#include "json_parser.hpp"
#include "logger.hpp"
#include "md5.hpp"
#include "module.hpp"
#include "preferences.hpp"
Expand Down Expand Up @@ -510,6 +511,14 @@ namespace module
def_font, def_font_cjk, speech_dialog_bg_color};
m.default_preferences = v["default_preferences"];
m.version_ = module_version;

if(v.has_key("controls")) {
LOG_INFO(v["controls"]);
}




loaded_paths().insert(loaded_paths().begin(), m);

if(initial) {
Expand Down
12 changes: 12 additions & 0 deletions src/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ namespace module
{
enum BASE_PATH_TYPE { BASE_PATH_GAME, BASE_PATH_USER, NUM_PATH_TYPES };

// For importing the input definition from module.cfg
typedef std::vector<std::string> key_list;

typedef std::map<std::string, key_list> key_bindings;
typedef std::map<std::string, key_list> button_bindings;
typedef std::map<std::string, key_list> axes_bindings;

struct modules
{
std::string name_;
Expand All @@ -57,6 +64,11 @@ namespace module
std::vector<std::string> included_modules_;

variant default_preferences;

key_bindings key_bindings;
button_bindings button_bindings;
axes_bindings axes_bindings;

};


Expand Down

0 comments on commit afbf8e5

Please sign in to comment.