Merge lp:~widelands-dev/widelands/bug-1814372-lua-gametype into lp:widelands

Proposed by Notabilis
Status: Merged
Merged at revision: 8963
Proposed branch: lp:~widelands-dev/widelands/bug-1814372-lua-gametype
Merge into: lp:widelands
Diff against target: 59 lines (+30/-1)
2 files modified
src/scripting/lua_root.cc (+29/-1)
src/scripting/lua_root.h (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1814372-lua-gametype
Reviewer Review Type Date Requested Status
Klaus Halfmann review, compile Approve
Review via email: mp+362638@code.launchpad.net

Commit message

Adding lua method to get the type of the current game, i.e., single or multiplayer.

Description of the change

This allows scripts to differentiate between single- and multiplayer games, allowing to adapt to restrictions of multiplayer games.

The idea for this came up while debugging desyncs, since the lua sleep() command can lead to desyncs in multiplayer if not used properly (i.e., for all players at the same time).

To post a comment you must log in.
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Mhh, I do not see any code changes and cannot pull the branch, whats the Problem?

Revision history for this message
Notabilis (notabilis27) wrote :
8963. By Notabilis

Aligning a line.

Revision history for this message
Notabilis (notabilis27) wrote :

Okay, looking better now.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Straighht forward, should not affect any current change
but can be user for later lua scripts.

@bunnybot merge

review: Approve (review, compile)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4421. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/490530673.
Appveyor build 4209. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1814372_lua_gametype-4209.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4421. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/490530673.

Revision history for this message
Toni Förster (stonerl) wrote :

Just a Travis hiccup.

@bunnybot merge force

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/scripting/lua_root.cc'
2--- src/scripting/lua_root.cc 2018-12-13 07:24:01 +0000
3+++ src/scripting/lua_root.cc 2019-02-03 07:42:46 +0000
4@@ -87,7 +87,7 @@
5 };
6 const PropertyType<LuaGame> LuaGame::Properties[] = {
7 PROP_RO(LuaGame, real_speed), PROP_RO(LuaGame, time), PROP_RW(LuaGame, desired_speed),
8- PROP_RW(LuaGame, allow_saving), {nullptr, nullptr, nullptr},
9+ PROP_RW(LuaGame, allow_saving), PROP_RO(LuaGame, type), {nullptr, nullptr, nullptr},
10 };
11
12 LuaGame::LuaGame(lua_State* /* L */) {
13@@ -163,6 +163,34 @@
14 return 1;
15 }
16
17+/* RST
18+ .. attribute:: type
19+
20+ (RO) One string out of 'undefined', 'singleplayer', 'netclient', 'nethost', 'replay',
21+ describing the type of game that is played.
22+*/
23+int LuaGame::get_type(lua_State* L) {
24+ // enum class GameType : uint8_t { kUndefined = 0, kSingleplayer, kNetClient, kNetHost, kReplay };
25+ switch (get_game(L).game_controller()->get_game_type()) {
26+ case GameController::GameType::kSingleplayer:
27+ lua_pushstring(L, "singleplayer");
28+ break;
29+ case GameController::GameType::kNetClient:
30+ lua_pushstring(L, "netclient");
31+ break;
32+ case GameController::GameType::kNetHost:
33+ lua_pushstring(L, "nethost");
34+ break;
35+ case GameController::GameType::kReplay:
36+ lua_pushstring(L, "replay");
37+ break;
38+ default:
39+ lua_pushstring(L, "undefined");
40+ break;
41+ }
42+ return 1;
43+}
44+
45 /*
46 ==========================================================
47 LUA METHODS
48
49=== modified file 'src/scripting/lua_root.h'
50--- src/scripting/lua_root.h 2018-09-08 08:19:51 +0000
51+++ src/scripting/lua_root.h 2019-02-03 07:42:46 +0000
52@@ -59,6 +59,7 @@
53 int set_desired_speed(lua_State*);
54 int get_allow_saving(lua_State*);
55 int set_allow_saving(lua_State*);
56+ int get_type(lua_State*);
57
58 /*
59 * Lua methods

Subscribers

People subscribed via source and target branches

to status/vote changes: