[Key] Small fix for multiplayer mode.

If the 'config/keys.lua' file didn't exist custom keys were empty.
This commit is contained in:
Quentin Bazin 2020-07-08 04:31:21 +02:00
parent 4ac67eedd4
commit e3dc327b71
2 changed files with 9 additions and 2 deletions

View File

@ -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`

View File

@ -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; }
@ -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());
}