Skip to content

Commit

Permalink
add InputMapping array union
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Nov 11, 2023
1 parent 70a9142 commit e924f88
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/src/includes/_home.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,3 @@ uColor | int;
SHORT_TILE_CODE | int;
STRINGID | int;
FEAT | int;
KEY | int;
1 change: 1 addition & 0 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ int | [left](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=left) |
int | [right](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=right) |
int | [up](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=up) |
int | [down](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=down) |
array<[RAW_KEY](#RAW_KEY), 12> | [mapping](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=mapping) | Can be indexed with [INPUT_FLAG](#INPUT_FLAG), keyboard uses [RAW_KEY](#RAW_KEY) values, controller just uses button numbers.

### PlayerInputs

Expand Down
3 changes: 2 additions & 1 deletion src/game_api/aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ using WORLD_SHADER = uint8_t; // NoAlias
using SHORT_TILE_CODE = uint8_t;
using STRINGID = uint32_t;
using FEAT = uint8_t;
using KEY = int64_t;
using KEY = int64_t; // NoAlias
using RAW_KEY = int8_t; // NoAlias

inline constexpr uint8_t MAX_PLAYERS = 4;

Expand Down
4 changes: 3 additions & 1 deletion src/game_api/script/usertypes/player_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ void register_usertypes(sol::state& lua)
"up",
sol::readonly(&InputMapping::up),
"down",
sol::readonly(&InputMapping::down));
sol::readonly(&InputMapping::down),
"mapping",
sol::readonly(&InputMapping::mapping));
/// Used in StateMemory
lua.new_usertype<PlayerInputs>(
"PlayerInputs",
Expand Down
32 changes: 20 additions & 12 deletions src/game_api/state_structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@ struct RobinHoodTableEntry

struct InputMapping
{
uint8_t jump;
uint8_t attack;
uint8_t bomb;
uint8_t rope;
uint8_t walk_run;
uint8_t use_door_buy;
uint8_t pause_menu;
uint8_t journal;
uint8_t left;
uint8_t right;
uint8_t up;
uint8_t down;
union
{
struct
{
int8_t jump;
int8_t attack;
int8_t bomb;
int8_t rope;
int8_t walk_run;
int8_t use_door_buy;
int8_t pause_menu;
int8_t journal;
int8_t left;
int8_t right;
int8_t up;
int8_t down;
};
/// Can be indexed with INPUT_FLAG, keyboard uses RAW_KEY values, controller just uses button numbers.
std::array<RAW_KEY, 12> mapping;
};
};

struct PlayerSlot
Expand Down

0 comments on commit e924f88

Please sign in to comment.