mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Store and load last difficulty setting
This commit is contained in:
parent
c87b0e6d65
commit
5f95955535
@ -140,6 +140,12 @@ CServerHandler::CServerHandler()
|
|||||||
{
|
{
|
||||||
uuid = boost::uuids::to_string(boost::uuids::random_generator()());
|
uuid = boost::uuids::to_string(boost::uuids::random_generator()());
|
||||||
registerTypesLobbyPacks(*applier);
|
registerTypesLobbyPacks(*applier);
|
||||||
|
|
||||||
|
auto lastDifficulty = settings["general"]["lastDifficulty"];
|
||||||
|
if (lastDifficulty.isNumber())
|
||||||
|
{
|
||||||
|
si->difficulty = lastDifficulty.Integer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerHandler::threadRunNetwork()
|
void CServerHandler::threadRunNetwork()
|
||||||
@ -193,8 +199,16 @@ void CServerHandler::startLocalServerAndConnect(bool connectToLobby)
|
|||||||
serverRunner.reset(new ServerThreadRunner());
|
serverRunner.reset(new ServerThreadRunner());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto si = std::make_shared<StartInfo>();
|
||||||
|
|
||||||
|
auto lastDifficulty = settings["general"]["lastDifficulty"];
|
||||||
|
if (lastDifficulty.isNumber())
|
||||||
|
{
|
||||||
|
si->difficulty = lastDifficulty.Integer();
|
||||||
|
}
|
||||||
|
|
||||||
logNetwork->trace("\tStarting local server");
|
logNetwork->trace("\tStarting local server");
|
||||||
serverRunner->start(getLocalPort(), connectToLobby);
|
serverRunner->start(getLocalPort(), connectToLobby, si);
|
||||||
logNetwork->trace("\tConnecting to local server");
|
logNetwork->trace("\tConnecting to local server");
|
||||||
connectToServer(getLocalHostname(), getLocalPort());
|
connectToServer(getLocalHostname(), getLocalPort());
|
||||||
logNetwork->trace("\tWaiting for connection");
|
logNetwork->trace("\tWaiting for connection");
|
||||||
|
@ -23,10 +23,15 @@
|
|||||||
ServerThreadRunner::ServerThreadRunner() = default;
|
ServerThreadRunner::ServerThreadRunner() = default;
|
||||||
ServerThreadRunner::~ServerThreadRunner() = default;
|
ServerThreadRunner::~ServerThreadRunner() = default;
|
||||||
|
|
||||||
void ServerThreadRunner::start(uint16_t port, bool connectToLobby)
|
void ServerThreadRunner::start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo)
|
||||||
{
|
{
|
||||||
server = std::make_unique<CVCMIServer>(port, connectToLobby, true);
|
server = std::make_unique<CVCMIServer>(port, connectToLobby, true);
|
||||||
|
|
||||||
|
if (startingInfo)
|
||||||
|
{
|
||||||
|
server->si = startingInfo; //Else use default
|
||||||
|
}
|
||||||
|
|
||||||
threadRunLocalServer = boost::thread([this]{
|
threadRunLocalServer = boost::thread([this]{
|
||||||
setThreadName("runServer");
|
setThreadName("runServer");
|
||||||
server->run();
|
server->run();
|
||||||
@ -68,7 +73,7 @@ int ServerProcessRunner::exitCode()
|
|||||||
return child->exit_code();
|
return child->exit_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerProcessRunner::start(uint16_t port, bool connectToLobby)
|
void ServerProcessRunner::start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo)
|
||||||
{
|
{
|
||||||
boost::filesystem::path serverPath = VCMIDirs::get().serverPath();
|
boost::filesystem::path serverPath = VCMIDirs::get().serverPath();
|
||||||
boost::filesystem::path logPath = VCMIDirs::get().userLogsPath() / "server_log.txt";
|
boost::filesystem::path logPath = VCMIDirs::get().userLogsPath() / "server_log.txt";
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class CVCMIServer;
|
class CVCMIServer;
|
||||||
|
struct StartInfo;
|
||||||
|
|
||||||
class IServerRunner
|
class IServerRunner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void start(uint16_t port, bool connectToLobby) = 0;
|
virtual void start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) = 0;
|
||||||
virtual void shutdown() = 0;
|
virtual void shutdown() = 0;
|
||||||
virtual void wait() = 0;
|
virtual void wait() = 0;
|
||||||
virtual int exitCode() = 0;
|
virtual int exitCode() = 0;
|
||||||
@ -28,7 +29,7 @@ class ServerThreadRunner : public IServerRunner, boost::noncopyable
|
|||||||
std::unique_ptr<CVCMIServer> server;
|
std::unique_ptr<CVCMIServer> server;
|
||||||
boost::thread threadRunLocalServer;
|
boost::thread threadRunLocalServer;
|
||||||
public:
|
public:
|
||||||
void start(uint16_t port, bool connectToLobby) override;
|
void start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) override;
|
||||||
void shutdown() override;
|
void shutdown() override;
|
||||||
void wait() override;
|
void wait() override;
|
||||||
int exitCode() override;
|
int exitCode() override;
|
||||||
@ -50,7 +51,7 @@ class ServerProcessRunner : public IServerRunner, boost::noncopyable
|
|||||||
std::unique_ptr<boost::process::child> child;
|
std::unique_ptr<boost::process::child> child;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void start(uint16_t port, bool connectToLobby) override;
|
void start(uint16_t port, bool connectToLobby, std::shared_ptr<StartInfo> startingInfo) override;
|
||||||
void shutdown() override;
|
void shutdown() override;
|
||||||
void wait() override;
|
void wait() override;
|
||||||
int exitCode() override;
|
int exitCode() override;
|
||||||
|
@ -162,6 +162,10 @@ void CLobbyScreen::startScenario(bool allowOnlyAI)
|
|||||||
tabRand->saveOptions(*CSH->si->mapGenOptions);
|
tabRand->saveOptions(*CSH->si->mapGenOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save chosen difficulty
|
||||||
|
Settings lastDifficulty = settings.write["general"]["lastDifficulty"];
|
||||||
|
lastDifficulty->Integer() = getCurrentDifficulty();
|
||||||
|
|
||||||
if (CSH->validateGameStart(allowOnlyAI))
|
if (CSH->validateGameStart(allowOnlyAI))
|
||||||
{
|
{
|
||||||
CSH->sendStartGame(allowOnlyAI);
|
CSH->sendStartGame(allowOnlyAI);
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"lastSave",
|
"lastSave",
|
||||||
"lastSettingsTab",
|
"lastSettingsTab",
|
||||||
"lastCampaign",
|
"lastCampaign",
|
||||||
|
"lastDifficulty",
|
||||||
"saveFrequency",
|
"saveFrequency",
|
||||||
"notifications",
|
"notifications",
|
||||||
"extraDump",
|
"extraDump",
|
||||||
@ -85,6 +86,10 @@
|
|||||||
"type" : "string",
|
"type" : "string",
|
||||||
"default" : ""
|
"default" : ""
|
||||||
},
|
},
|
||||||
|
"lastDifficulty" : {
|
||||||
|
"type" : "number",
|
||||||
|
"default" : 1
|
||||||
|
},
|
||||||
"saveFrequency" : {
|
"saveFrequency" : {
|
||||||
"type" : "number",
|
"type" : "number",
|
||||||
"default" : 1
|
"default" : 1
|
||||||
|
Loading…
Reference in New Issue
Block a user