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