make hotbar size and layout configurable

Add hotbar-size, hotbar-layout and inventory-layout to config/defaults.toml,
player.get_hotbar_size / player.set_hotbar_size and
hud.is_hotbar_visible / hud.set_hotbar_visible.
This commit is contained in:
ostermine 2026-10-15 15:52:22 +03:00
parent 2e2233a489
commit aa670f3c9d
16 changed files with 188 additions and 20 deletions

View file

@ -41,6 +41,12 @@ Player::Player(
name(name),
speed(speed),
chosenSlot(0),
hotbarSize(glm::max(
1,
static_cast<int>(
level.content.getDefaults()["hotbar-size"].asInteger(10)
)
)),
position(position),
inventory(std::move(inv)),
eid(eid),
@ -153,13 +159,22 @@ void Player::attemptToChooseSpawnpoint() {
}
void Player::setChosenSlot(int index) {
chosenSlot = index;
chosenSlot = glm::clamp(index, 0, hotbarSize - 1);
}
int Player::getChosenSlot() const {
return chosenSlot;
}
void Player::setHotbarSize(int size) {
hotbarSize = glm::max(1, size);
setChosenSlot(chosenSlot);
}
int Player::getHotbarSize() const {
return hotbarSize;
}
float Player::getSpeed() const {
return speed;
}

View file

@ -49,6 +49,7 @@ class Player : public Serializable {
float speed;
int chosenSlot;
int hotbarSize;
glm::vec3 position;
glm::vec3 spawnpoint {std::nanf(""), std::nanf(""), std::nanf("")};
std::shared_ptr<Inventory> inventory;
@ -96,6 +97,10 @@ public:
int getChosenSlot() const;
void setHotbarSize(int size);
int getHotbarSize() const;
float getSpeed() const;
bool isSuspended() const;