#include "Player.hpp" // Keep the same number as # of fields in `struct {}` in PlayerKeyBinds constexpr int kPlayerKeyBindCount = 4; // Here be dragons: this treats consecutive fiels as an array, technically UB std::span PlayerKeyBinds::GetKeyArray() { return { &keyLeft, kPlayerKeyBindCount }; } std::span PlayerKeyBinds::GetKeyStatusArray() { return { &pressedLeft, kPlayerKeyBindCount }; } void Player::Awaken() { } void Player::Resleep() { } void Player::Update() { if (keybinds.pressedLeft) { } if (keybinds.pressedRight) { } // TODO jump controller // TODO attack controller } void Player::HandleKeyInput(int key, int action) { bool pressed; if (action == GLFW_PRESS) { pressed = true; } else if (action == GLFW_REPEAT) { return; } else /* action == GLFW_RELEASE */ { pressed = false; } for (int i = 0; i < kPlayerKeyBindCount; ++i) { int kbKey = keybinds.GetKeyArray()[i]; bool& kbStatus = keybinds.GetKeyStatusArray()[i]; if (kbKey == key) { kbStatus = pressed; break; } } }