#include "blitz/game/Game.h"

namespace blitz {
namespace game {

Player* Game::GetPlayerById(PlayerID id) {
	auto it = m_Players.find(id);

	if (it == m_Players.end())
		return nullptr;

	return &it->second;
}

const Player* Game::GetPlayerById(PlayerID id) const {
	auto it = m_Players.find(id);

	if (it == m_Players.end())
		return nullptr;

	return &it->second;
}

void Game::AddPlayer(PlayerID player, const std::string& name) {
	static float MAX_HP = 100;

	game::Player newPlayer{player};
	newPlayer.SetName(name);
	newPlayer.SetHP(MAX_HP);

	GetPlayers().insert({player, newPlayer});
}

void Game::RemovePlayer(PlayerID player) {
	auto it = GetPlayers().find(player);

	if (it == GetPlayers().end())
		return;

	GetPlayers().erase(it);
}

}  // namespace game
}  // namespace blitz
