Skip to content

Commit

Permalink
Merge pull request #110 from TEAM-AAAAAAAAAAAAAAAA/feat/ini/serverInfo
Browse files Browse the repository at this point in the history
feat: implement server info in Connection.hpp
  • Loading branch information
Bootoyka authored Nov 13, 2022
2 parents 745d9be + 5ae9122 commit b36f187
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/client/AssetLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ namespace asset
return smart;
}

static void LoadServerInfo(const std::string &key, const std::string &info)
{
getInstance()._serverInfo[key] = info;
}

/**
* @brief Get an Asset object from the map
* @param key of the asset to get
Expand Down Expand Up @@ -199,6 +204,8 @@ namespace asset

static sf::Keyboard::Key &GetKeybind(const std::string &key) { return getInstance()._keyMap[key]; }

static std::string GetServerInfo(const std::string &key) {return getInstance()._serverInfo[key];}

/**
* @brief Load a .ini file with boost loading assets into the map
*/
Expand All @@ -224,6 +231,8 @@ namespace asset
loadKeybind(value.first, value.second.data());
continue;
}
if (section.first == "server")
LoadServerInfo(value.first, value.second.data());
paths.push_back(value.second.data());

if (section.first == "texture")
Expand All @@ -234,6 +243,7 @@ namespace asset
LoadSFX(value.first, paths);
if (section.first == "font")
LoadFont(value.first, paths);

}
}
}
Expand Down Expand Up @@ -289,5 +299,7 @@ namespace asset
* Map of all the keybinds, loaded in the [keybinds] section of the .ini file
*/
std::unordered_map<std::string, sf::Keyboard::Key> _keyMap;

std::unordered_map<std::string, std::string> _serverInfo;
};
} // namespace asset
6 changes: 3 additions & 3 deletions src/client/entrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ int main()
ecs::Engine engine;
network::Message msg;

network::Client::setHost("localhost");
network::Client::setPort("8000");
asset::AssetLoader::LoadIniFile(asset::AssetLoader::smartPath("assets", "config.ini"));
network::Client::setHost(asset::AssetLoader::GetServerInfo("host"));
network::Client::setPort(asset::AssetLoader::GetServerInfo("port"));
msg.fill(0);
network::Client::connect();
network::Client::getOutgoingMessages().push(msg);
asset::AssetLoader::LoadIniFile(asset::AssetLoader::smartPath("assets", "config.ini"));
audio::AudioManager::playSFX("splash_screen");
ecs::WorldManager::setWaitingWorld(getMenuWorld);
audio::AudioManager::setBGMVolume(50);
Expand Down
2 changes: 1 addition & 1 deletion src/ecs/components/client/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace ecs::component {
struct Connection {

Connection(int port = 8000, const std::string &host = "localhost") : _port(std::to_string(port)), _host(host), _isSet(false) {}
Connection() : _port("8001"), _host(asset::AssetLoader::GetServerInfo("host")), _isSet(false) {}

void setPort(int port) {
_port = std::to_string(port);
Expand Down

0 comments on commit b36f187

Please sign in to comment.