Add messages on player join/leave

This commit is contained in:
tovjemam 2026-03-14 22:45:06 +01:00
parent 9bc8984a21
commit 2ee6d61231
2 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "game.hpp"
#include <format>
#include "player.hpp"
#include "openworld.hpp"
@ -22,13 +24,26 @@ void game::Game::FinishFrame()
void game::Game::PlayerJoined(Player& player)
{
player.SetWorld(default_world_);
players_.insert(&player);
BroadcastChat(std::format("{}^r se připoojil jupí jupí jupííí", player.GetName()));
}
void game::Game::PlayerLeft(Player& player)
{
players_.erase(&player);
BroadcastChat(std::format("{}^r se vodpojil zmrd", player.GetName()));
}
bool game::Game::PlayerInput(Player& player, PlayerInputType type, bool enabled)
{
return false; // not handled here
}
void game::Game::BroadcastChat(const std::string& text)
{
for (auto player : players_)
{
player->SendChat(text);
}
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <map>
#include <set>
#include "world.hpp"
@ -21,9 +22,12 @@ public:
void PlayerLeft(Player& player);
bool PlayerInput(Player& player, PlayerInputType type, bool enabled);
private:
void BroadcastChat(const std::string& text);
private:
std::shared_ptr<World> default_world_;
std::set<Player*> players_;
};