Skip to content

Commit

Permalink
[Key] Small fix for multiplayer mode.
Browse files Browse the repository at this point in the history
If the 'config/keys.lua' file didn't exist custom keys were empty.
  • Loading branch information
Unarelith committed Jul 8, 2020
1 parent 4ac67ee commit e3dc327
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/lua-api-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Example:
default_key = "E"
```

Names are defined [here](https://github.com/Unarelith/GameKit/blob/master/source/core/input/KeyboardUtils.cpp).
Names are defined [here](https://wiki.libsdl.org/SDL_Keycode).

### `name`

Expand Down
9 changes: 8 additions & 1 deletion source/common/world/Key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ class Key : public gk::ISerializable {
: m_id(id), m_stringID(stringID), m_name(name) {}

void serialize(sf::Packet &packet) const override { packet << m_id << m_stringID << m_name << m_defaultKey; }
void deserialize(sf::Packet &packet) override { packet >> m_id >> m_stringID >> m_name >> m_defaultKey; }
void deserialize(sf::Packet &packet) override {
packet >> m_id >> m_stringID >> m_name >> m_defaultKey;

// Needed for multiplayer mode
if (m_keycode == SDLK_UNKNOWN)
m_keycode = SDL_GetKeyFromName(m_defaultKey.c_str());
}

u16 id() const { return m_id; }

Expand All @@ -59,6 +65,7 @@ class Key : public gk::ISerializable {
void setDefaultKey(const std::string &defaultKey) {
m_defaultKey = defaultKey;

// Needed for singleplayer mode
if (m_keycode == SDLK_UNKNOWN)
m_keycode = SDL_GetKeyFromName(m_defaultKey.c_str());
}
Expand Down

0 comments on commit e3dc327

Please sign in to comment.