Add messages on player join/leave
This commit is contained in:
parent
9bc8984a21
commit
2ee6d61231
@ -1,5 +1,7 @@
|
|||||||
#include "game.hpp"
|
#include "game.hpp"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "openworld.hpp"
|
#include "openworld.hpp"
|
||||||
|
|
||||||
@ -22,13 +24,26 @@ void game::Game::FinishFrame()
|
|||||||
void game::Game::PlayerJoined(Player& player)
|
void game::Game::PlayerJoined(Player& player)
|
||||||
{
|
{
|
||||||
player.SetWorld(default_world_);
|
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)
|
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)
|
bool game::Game::PlayerInput(Player& player, PlayerInputType type, bool enabled)
|
||||||
{
|
{
|
||||||
return false; // not handled here
|
return false; // not handled here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game::Game::BroadcastChat(const std::string& text)
|
||||||
|
{
|
||||||
|
for (auto player : players_)
|
||||||
|
{
|
||||||
|
player->SendChat(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
|
||||||
@ -21,9 +22,12 @@ public:
|
|||||||
void PlayerLeft(Player& player);
|
void PlayerLeft(Player& player);
|
||||||
bool PlayerInput(Player& player, PlayerInputType type, bool enabled);
|
bool PlayerInput(Player& player, PlayerInputType type, bool enabled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void BroadcastChat(const std::string& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<World> default_world_;
|
std::shared_ptr<World> default_world_;
|
||||||
|
std::set<Player*> players_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user