widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03549
Re: [Merge] lp:~widelands-dev/widelands/bug-1408775 into lp:widelands
I have some code duplication because of the circular dependency with lua_table.h
Shall we wait until you have figured out separating this?
Diff comments:
> === 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"));
I tried putting it in game_settings.h, but I ran into trouble because lua_table.h still depends on logic.
> + 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();
>
--
https://code.launchpad.net/~widelands-dev/widelands/bug-1408775/+merge/248181
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1408775.
References