Merge lp:~widelands-dev/widelands/bug-1544864 into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7833
Proposed branch: lp:~widelands-dev/widelands/bug-1544864
Merge into: lp:widelands
Diff against target: 289 lines (+78/-73)
6 files modified
data/tribes/scripting/help/building_help.lua (+3/-3)
src/scripting/lua_map.cc (+56/-53)
src/scripting/lua_map.h (+1/-2)
test/maps/lua_testsuite.wmf/scripting/baseimmovables.lua (+5/-5)
test/maps/lua_testsuite.wmf/scripting/constructionsite.lua (+4/-2)
test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua (+9/-8)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1544864
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+285994@code.launchpad.net

Commit message

Removed LuaBaseImmovable::get_size. The corresponding functions in LuaBuildingDescription and LuaImmovableDescription now return strings instead of ints for consistency and easier reading.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 691. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/109182358.
Appveyor build 542. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1544864-542.

Revision history for this message
SirVer (sirver) wrote :

beautiful!

@bunnybot merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/tribes/scripting/help/building_help.lua'
2--- data/tribes/scripting/help/building_help.lua 2016-01-28 05:24:34 +0000
3+++ data/tribes/scripting/help/building_help.lua 2016-02-14 16:39:57 +0000
4@@ -449,11 +449,11 @@
5 elseif (building_description.is_port) then
6 result = result .. text_line(_"Space required:",_"Port plot","images/wui/overlays/port.png")
7 else
8- if (building_description.size == 1) then
9+ if (building_description.size == "small") then
10 result = result .. text_line(_"Space required:",_"Small plot","images/wui/overlays/small.png")
11- elseif (building_description.size == 2) then
12+ elseif (building_description.size == "medium") then
13 result = result .. text_line(_"Space required:",_"Medium plot","images/wui/overlays/medium.png")
14- elseif (building_description.size == 3) then
15+ elseif (building_description.size == "big") then
16 result = result .. text_line(_"Space required:",_"Big plot","images/wui/overlays/big.png")
17 else
18 result = result .. p(_"Space required:" .. _"Unknown")
19
20=== modified file 'src/scripting/lua_map.cc'
21--- src/scripting/lua_map.cc 2016-02-14 09:59:59 +0000
22+++ src/scripting/lua_map.cc 2016-02-14 16:39:57 +0000
23@@ -1550,20 +1550,32 @@
24 /* RST
25 .. attribute:: size
26
27- (RO) the size of the immovable as an int.
28+ (RO) The size of this immovable. Can be either of
29+
30+ * :const:`none` -- Example: mushrooms. Immovables will be destroyed when
31+ something else is built on this field.
32+ * :const:`small` -- Example: trees or flags
33+ * :const:`medium` -- Example: Medium sized buildings
34+ * :const:`big` -- Example: Big sized buildings or rocks
35 */
36 int LuaImmovableDescription::get_size(lua_State * L) {
37- // TODO(GunChleoc): see this todo, that is also mentioned below for
38- // buildings. I think we can do that now, every description is wrapped I
39- // think. Essentially that means every instance of something on the map
40- // (like a building) get's a .description that has the static data for the
41- // building/immovable. maybe in a followup branch, but definitvely before b19, since that is backwards
42- // incompatible.
43- // TODO(SirVer): size should be similar to
44- // https://wl.widelands.org/docs/wl/autogen_wl_map/#wl.map.BaseImmovable.size.
45- // In fact, as soon as all descriptions are wrapped (also for other
46- // immovables besides buildings) we should get rid of BaseImmovable.size.
47- lua_pushinteger(L, get()->get_size());
48+ switch (get()->get_size()) {
49+ case BaseImmovable::NONE:
50+ lua_pushstring(L, "none");
51+ break;
52+ case BaseImmovable::SMALL:
53+ lua_pushstring(L, "small");
54+ break;
55+ case BaseImmovable::MEDIUM:
56+ lua_pushstring(L, "medium");
57+ break;
58+ case BaseImmovable::BIG:
59+ lua_pushstring(L, "big");
60+ break;
61+ default:
62+ report_error(L, "Unknown size %i in LuaImmovableDescription::get_size: %s",
63+ get()->get_size(), get()->name().c_str());
64+ }
65 return 1;
66 }
67
68@@ -1642,13 +1654,9 @@
69 PROP_RO(LuaBuildingDescription, enhancement),
70 PROP_RO(LuaBuildingDescription, is_mine),
71 PROP_RO(LuaBuildingDescription, is_port),
72+ PROP_RO(LuaBuildingDescription, size),
73 PROP_RO(LuaBuildingDescription, returned_wares),
74 PROP_RO(LuaBuildingDescription, returned_wares_enhanced),
75- // TODO(SirVer): size should be similar to
76- // https://wl.widelands.org/docs/wl/autogen_wl_map/#wl.map.BaseImmovable.size.
77- // In fact, as soon as all descriptions are wrapped (also for other
78- // immovables besides buildings) we should get rid of BaseImmovable.size.
79- PROP_RO(LuaBuildingDescription, size),
80 PROP_RO(LuaBuildingDescription, vision_range),
81 PROP_RO(LuaBuildingDescription, workarea_radius),
82 {nullptr, nullptr, nullptr},
83@@ -1801,6 +1809,33 @@
84 }
85
86 /* RST
87+ .. attribute:: size
88+
89+ (RO) The size of this building. Can be either of
90+
91+ * :const:`small` -- Small sized buildings
92+ * :const:`medium` -- Medium sized buildings
93+ * :const:`big` -- Big sized buildings
94+*/
95+int LuaBuildingDescription::get_size(lua_State * L) {
96+ switch (get()->get_size()) {
97+ case BaseImmovable::SMALL:
98+ lua_pushstring(L, "small");
99+ break;
100+ case BaseImmovable::MEDIUM:
101+ lua_pushstring(L, "medium");
102+ break;
103+ case BaseImmovable::BIG:
104+ lua_pushstring(L, "big");
105+ break;
106+ default:
107+ report_error(L, "Unknown size %i in LuaBuildingDescription::get_size: %s",
108+ get()->get_size(), get()->name().c_str());
109+ }
110+ return 1;
111+}
112+
113+/* RST
114 .. attribute:: returned_wares
115
116 (RO) a list of wares returned upon dismantling.
117@@ -1821,17 +1856,6 @@
118
119
120 /* RST
121- .. attribute:: size
122-
123- (RO) the size of the building: 1 = small, 2 = medium, 3 = big.
124-*/
125-int LuaBuildingDescription::get_size(lua_State * L) {
126- lua_pushinteger(L, get()->get_size());
127- return 1;
128-}
129-
130-
131-/* RST
132 .. attribute:: vision range
133
134 (RO) the vision_range of the building as an int.
135@@ -3095,6 +3119,10 @@
136 return CAST_TO_LUA(TrainingSiteDescr, LuaTrainingSiteDescription);
137 case (MapObjectType::WAREHOUSE):
138 return CAST_TO_LUA(WarehouseDescr, LuaWarehouseDescription);
139+ case (MapObjectType::IMMOVABLE):
140+ return CAST_TO_LUA(ImmovableDescr, LuaImmovableDescription);
141+ case (MapObjectType::WORKER):
142+ return CAST_TO_LUA(WorkerDescr, LuaWorkerDescription);
143 default:
144 return CAST_TO_LUA(MapObjectDescr, LuaMapObjectDescription);
145 }
146@@ -3213,7 +3241,6 @@
147 {nullptr, nullptr},
148 };
149 const PropertyType<LuaBaseImmovable> LuaBaseImmovable::Properties[] = {
150- PROP_RO(LuaBaseImmovable, size),
151 PROP_RO(LuaBaseImmovable, fields),
152 {nullptr, nullptr, nullptr},
153 };
154@@ -3223,30 +3250,6 @@
155 PROPERTIES
156 ==========================================================
157 */
158-/* RST
159- .. attribute:: size
160-
161- (RO) The size of this immovable. Can be either of
162-
163- * :const:`none` -- Example: mushrooms. Immovables will be destroyed when
164- something else is build on this field.
165- * :const:`small` -- Example: trees or flags
166- * :const:`medium` -- Example: Medium sized buildings
167- * :const:`big` -- Example: Big sized buildings or rocks
168-*/
169-int LuaBaseImmovable::get_size(lua_State * L) {
170- BaseImmovable * o = get(L, get_egbase(L));
171-
172- switch (o->get_size()) {
173- case BaseImmovable::NONE: lua_pushstring(L, "none"); break;
174- case BaseImmovable::SMALL: lua_pushstring(L, "small"); break;
175- case BaseImmovable::MEDIUM: lua_pushstring(L, "medium"); break;
176- case BaseImmovable::BIG: lua_pushstring(L, "big"); break;
177- default:
178- report_error(L, "Unknown size in LuaBaseImmovable::get_size: %i", o->get_size());
179- }
180- return 1;
181-}
182
183 /* RST
184 .. attribute:: fields
185
186=== modified file 'src/scripting/lua_map.h'
187--- src/scripting/lua_map.h 2016-02-13 13:03:55 +0000
188+++ src/scripting/lua_map.h 2016-02-14 16:39:57 +0000
189@@ -277,10 +277,10 @@
190 int get_enhancement(lua_State *);
191 int get_is_mine(lua_State *);
192 int get_is_port(lua_State *);
193+ int get_size(lua_State *);
194 int get_isproductionsite(lua_State *);
195 int get_returned_wares(lua_State *);
196 int get_returned_wares_enhanced(lua_State *);
197- int get_size(lua_State *);
198 int get_vision_range(lua_State *);
199 int get_workarea_radius(lua_State *);
200
201@@ -726,7 +726,6 @@
202 /*
203 * Properties
204 */
205- int get_size(lua_State * L);
206 int get_fields(lua_State * L);
207
208 /*
209
210=== modified file 'test/maps/lua_testsuite.wmf/scripting/baseimmovables.lua'
211--- test/maps/lua_testsuite.wmf/scripting/baseimmovables.lua 2015-10-31 15:04:53 +0000
212+++ test/maps/lua_testsuite.wmf/scripting/baseimmovables.lua 2016-02-14 16:39:57 +0000
213@@ -116,19 +116,19 @@
214 end
215
216 function immovable_property_tests:test_size_none()
217- assert_equal("none", self.none.size)
218+ assert_equal("none", self.none.descr.size)
219 end
220 function immovable_property_tests:test_size_small()
221- assert_equal("small", self.small.size)
222+ assert_equal("small", self.small.descr.size)
223 end
224 function immovable_property_tests:test_size_medium()
225- assert_equal("medium", self.medium.size)
226+ assert_equal("medium", self.medium.descr.size)
227 end
228 function immovable_property_tests:test_size_big()
229- assert_equal("big", self.big.size)
230+ assert_equal("big", self.big.descr.size)
231 end
232 function immovable_property_tests:test_size_fortress()
233- assert_equal("big", self.big_building.size)
234+ assert_equal("big", self.big_building.descr.size)
235 end
236 function immovable_property_tests:test_name_pebble()
237 assert_equal("pebble1", self.none.descr.name)
238
239=== modified file 'test/maps/lua_testsuite.wmf/scripting/constructionsite.lua'
240--- test/maps/lua_testsuite.wmf/scripting/constructionsite.lua 2015-10-31 12:11:44 +0000
241+++ test/maps/lua_testsuite.wmf/scripting/constructionsite.lua 2016-02-14 16:39:57 +0000
242@@ -36,8 +36,10 @@
243 end
244
245 function constructionsite_tests:test_size()
246- assert_equal("small", self.l.size)
247- assert_equal("big", self.f.size)
248+
249+local building = egbase:get_building_description(self.l.building)
250+ assert_equal("small", egbase:get_building_description(self.l.building).size)
251+ assert_equal("big", egbase:get_building_description(self.f.building).size)
252 end
253
254 function constructionsite_tests:test_building()
255
256=== modified file 'test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua'
257--- test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua 2016-02-13 13:03:55 +0000
258+++ test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua 2016-02-14 16:39:57 +0000
259@@ -107,10 +107,10 @@
260 end
261
262 function test_descr:test_immovable_size()
263- assert_equal(0, egbase:get_immovable_description("bush1").size)
264- assert_equal(1, egbase:get_immovable_description("cornfield_ripe").size)
265- assert_equal(1, egbase:get_immovable_description("alder_summer_sapling").size)
266- assert_equal(1, egbase:get_immovable_description("alder_summer_old").size)
267+ assert_equal("none", egbase:get_immovable_description("bush1").size)
268+ assert_equal("small", egbase:get_immovable_description("cornfield_ripe").size)
269+ assert_equal("small", egbase:get_immovable_description("alder_summer_sapling").size)
270+ assert_equal("small", egbase:get_immovable_description("alder_summer_old").size)
271 end
272
273 function test_descr:test_immovable_has_attribute()
274@@ -257,10 +257,11 @@
275 end
276
277 function test_descr:test_size()
278- assert_equal(1, egbase:get_building_description("barbarians_lumberjacks_hut").size)
279- assert_equal(2, egbase:get_building_description("barbarians_reed_yard").size)
280- assert_equal(3, egbase:get_building_description("barbarians_fortress").size)
281- assert_equal(1, egbase:get_building_description("barbarians_coalmine").size)
282+ assert_equal("small", egbase:get_building_description("barbarians_lumberjacks_hut").size)
283+ assert_equal("medium", egbase:get_building_description("barbarians_reed_yard").size)
284+ assert_equal("big", egbase:get_building_description("barbarians_fortress").size)
285+ assert_equal("small", egbase:get_building_description("barbarians_coalmine").size)
286+ assert_equal("none", egbase:get_immovable_description("pebble1").size)
287 end
288
289 function test_descr:test_type()

Subscribers

People subscribed via source and target branches

to status/vote changes: