widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03543
[Merge] lp:~widelands-dev/widelands/bug-1408775 into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1408775 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1408775 in widelands: "Make autocrat & territorial lord the last win conditions, make Collectors the first "
https://bugs.launchpad.net/widelands/+bug/1408775
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1408775/+merge/248181
Win conditions order is now determined by an init.lua file.
I kept the file names in case a change would break savegames.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1408775 into lp:widelands.
=== added file 'scripting/win_conditions/init.lua'
--- scripting/win_conditions/init.lua 1970-01-01 00:00:00 +0000
+++ scripting/win_conditions/init.lua 2015-01-30 23:12:20 +0000
@@ -0,0 +1,12 @@
+-- This config file sets the order of the starting conditions
+dirname = path.dirname(__file__)
+
+return {
+ dirname .. "02_collectors.lua",
+ dirname .. "04_wood_gnome.lua",
+ dirname .. "03_territorial_time.lua",
+ dirname .. "03_territorial_lord.lua",
+ dirname .. "01_defeat_all.lua",
+ dirname .. "00_endless_game.lua",
+ dirname .. "05_endless_game_fogless.lua",
+}
=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc 2014-10-11 16:03:18 +0000
+++ src/network/netclient.cc 2015-01-30 23:12:20 +0000
@@ -124,12 +124,14 @@
d->desiredspeed = 1000;
file = nullptr;
- // Temporarily register win condition scripts to get the default
- std::set<std::string> win_condition_scripts =
- filter(g_fs->list_directory("scripting/win_conditions"),
- [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
- assert(win_condition_scripts.size());
- d->settings.win_condition_script = *win_condition_scripts.begin();
+ // Get the default win condition script
+ LuaInterface lua;
+ std::unique_ptr<LuaTable> win_conditions(lua.run_script("scripting/win_conditions/init.lua"));
+ std::string filename = win_conditions->get_string(1);
+ if (!g_fs->file_exists(filename)) {
+ throw wexception("Win condition file \"%s\" does not exist", filename.c_str());
+ }
+ d->settings.win_condition_script = filename;
}
NetClient::~NetClient ()
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2014-11-28 09:02:24 +0000
+++ src/network/nethost.cc 2015-01-30 23:12:20 +0000
@@ -57,6 +57,7 @@
#include "network/network_protocol.h"
#include "network/network_system.h"
#include "profile/profile.h"
+#include "scripting/lua_table.h"
#include "scripting/scripting.h"
#include "ui_basic/progresswindow.h"
#include "ui_fsmenu/launch_mpg.h"
@@ -294,14 +295,19 @@
}
void next_win_condition() override {
- if (m_win_condition_scripts.size() < 1) {
+ if (m_win_condition_scripts.empty()) {
if (!m_lua)
m_lua = new LuaInterface();
- std::set<std::string> win_conditions =
- filter(g_fs->list_directory("scripting/win_conditions"),
- [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
- m_win_condition_scripts.insert(
- m_win_condition_scripts.end(), win_conditions.begin(), win_conditions.end());
+ std::unique_ptr<LuaTable> win_conditions(m_lua->run_script("scripting/win_conditions/init.lua"));
+ for (int key : win_conditions->keys<int>()) {
+ std::string filename = win_conditions->get_string(key);
+ if (g_fs->file_exists(filename)) {
+ m_win_condition_scripts.push_back(filename);
+ } else {
+ throw wexception("Win condition file \"%s\" does not exist", filename.c_str());
+ }
+ }
+
m_cur_wincondition = -1;
}
=== modified file 'src/ui_fsmenu/launch_spg.cc'
--- src/ui_fsmenu/launch_spg.cc 2014-12-06 12:22:35 +0000
+++ src/ui_fsmenu/launch_spg.cc 2015-01-30 23:12:20 +0000
@@ -25,6 +25,7 @@
#include "base/i18n.h"
#include "base/warning.h"
+#include "base/wexception.h"
#include "graphic/graphic.h"
#include "graphic/text_constants.h"
#include "helper.h"
@@ -128,12 +129,15 @@
m_lua = new LuaInterface();
- std::set<std::string> win_conditions =
- filter(g_fs->list_directory("scripting/win_conditions"),
- [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
-
- m_win_condition_scripts.insert(
- m_win_condition_scripts.end(), win_conditions.begin(), win_conditions.end());
+ std::unique_ptr<LuaTable> win_conditions(m_lua->run_script("scripting/win_conditions/init.lua"));
+ for (int key : win_conditions->keys<int>()) {
+ std::string filename = win_conditions->get_string(key);
+ if (g_fs->file_exists(filename)) {
+ m_win_condition_scripts.push_back(filename);
+ } else {
+ throw wexception("Win condition file \"%s\" does not exist", filename.c_str());
+ }
+ }
m_cur_wincondition = -1;
win_condition_clicked();
Follow ups