Merge lp:~widelands-dev/widelands/fh1-winconditions into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8382
Proposed branch: lp:~widelands-dev/widelands/fh1-winconditions
Merge into: lp:widelands
Diff against target: 826 lines (+465/-61)
9 files modified
data/scripting/formatting.lua (+3/-0)
data/scripting/richtext.lua (+413/-0)
data/scripting/win_conditions/artifacts.lua (+6/-7)
data/scripting/win_conditions/collectors.lua (+11/-13)
data/scripting/win_conditions/territorial_lord.lua (+8/-11)
data/scripting/win_conditions/territorial_time.lua (+12/-18)
data/scripting/win_conditions/win_condition_functions.lua (+1/-0)
data/scripting/win_conditions/win_condition_texts.lua (+4/-4)
data/scripting/win_conditions/wood_gnome.lua (+7/-8)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fh1-winconditions
Reviewer Review Type Date Requested Status
Klaus Halfmann code review Approve
kaputtnik (community) testing Approve
Review via email: mp+323987@code.launchpad.net

Commit message

Converted win condition scripts to new font renderer. Formatting functions for the new renderer live in data/scripting/richtext.lua

Description of the change

I decided to add a separate script for the formatting stuff. This way, we can keep the old renderer around until after the release so that savegames won't crash.

I will replace the online documentation for Richtext once we have support for campaign scenarios - I haven't touched the message boxes and objectives yet.

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

Uhm, this is all lua, what would be the way to test this?

I cannot judge much about that code.
I will however compile the code and play around with some winconditions

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2179. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/231575243.
Appveyor build 2014. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fh1_winconditions-2014.

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

I played this some time now and got an ugly crash, here:

Cmd_EnemyFlagAction::execute player(3): flag->owner(4) number=4
Assertion failed: (it != entries_.end()), function drop, file /Users/klaus/develop/widelands-repo/fh1-winconditions/src/graphic/texture_cache.cc, line 79.

3 libsystem_c.dylib 0x00007fffb52b3893 __assert_rtn + 320
4 widelands 0x000000010f9d6bad TextureCache::drop() + 845 (texture_cache.cc:79)
5 widelands 0x000000010f9d6121 TextureCache::insert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unique_ptr<Texture, std::__1::default_delete<Texture> >) + 801 (texture_cache.cc:63)
6 widelands 0x000000010f3b6aac RT::SdlTtfFont::render(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, RGBColor const&, int, TextureCache*) + 3932 (sdl_ttf_font.cc:131)
7 widelands 0x000000010f393ac5 RT::TextNode::render(TextureCache*) + 85 (rt_render.cc:521)
8 widelands 0x000000010f3a2764 RT::DivTagRenderNode::render(TextureCache*) + 3012 (rt_render.cc:746)
9 widelands 0x000000010f39bfeb RT::Renderer::render(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned short, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 315 (rt_render.cc:1487)
10 widelands 0x000000010f2b6876 (anonymous namespace)::RTImage::texture() const + 262 (font_handler1.cc:92)
11 widelands 0x000000010f2b6685 (anonymous namespace)::RTImage::width() const + 21 (font_handler1.cc:75)
12 widelands 0x000000010f2b3612 UI::FontHandler1::render(std::__1::basic_string<char, std::__1::char_traits<char>,

Maybe this is again the memory problem we face on trunk, no idea, mmh

Revision history for this message
GunChleoc (gunchleoc) wrote :

Yes, it must be a problem that we have in trunk already - the worst thing that should happen here is reverting to the old font renderer if the text can't be parsed and the ending up with empty text or lots of visible tags.

Revision history for this message
GunChleoc (gunchleoc) wrote :
Revision history for this message
kaputtnik (franku) wrote :

This looks really good now :-)

Played an hour or so but no crash anymore. The output of 'new size' is a bit annoying, i guess it switches between Kilobytes and Bytes (?):

TransientCache: Dropping 11 bytes, new size 4082. [...]
TransientCache: Dropping 4032 bytes, new size 31452972. [...]
[...]
TransientCache: Dropping 4 bytes, new size 4092.

But it never exceeds the size of 4093 (as far as i can see).

There are a lot of such outputs if you just move the mouse around, also moving the mouse on black areas. Don't know if this much processor time consuming. Maybe here is a chance of optimization?

review: Approve (testing)
Revision history for this message
kaputtnik (franku) wrote :

Sorry, wrong branch :-S

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

Code Revire is ok for me.
In case of an error some layout may be broken, well. We will find that.

review: Approve (code review)
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/scripting/formatting.lua'
2--- data/scripting/formatting.lua 2016-10-19 09:00:29 +0000
3+++ data/scripting/formatting.lua 2017-06-16 07:57:28 +0000
4@@ -1,3 +1,6 @@
5+-- TODO(GunChleoc): This is for the legacy font renderer. Remove when we remove the old renderer.
6+
7+
8 -- RST
9 -- formatting.lua
10 -- --------------
11
12=== added file 'data/scripting/richtext.lua'
13--- data/scripting/richtext.lua 1970-01-01 00:00:00 +0000
14+++ data/scripting/richtext.lua 2017-06-16 07:57:28 +0000
15@@ -0,0 +1,413 @@
16+-- TODO(GunChleoc): Wrap all tags and document allowed attributes when we're done
17+
18+-- RST
19+-- richtext.lua
20+-- ------------
21+--
22+-- Functions to simplify and unique text formatting in scenarios and help files.
23+-- Most of these functions are simple wrapper functions that make working with
24+-- widelands rich text formatting system more bearable.
25+-- Function names generally follow HTML names.
26+
27+
28+-- RST
29+-- .. function:: localize_list(items, listtype, former_textdomain)
30+--
31+-- Turns an array of string items into a localized string list with
32+-- appropriate concatenation.
33+--
34+-- e.g. localize_list({"foo", "bar", baz"}, "or", "widelands") will return
35+-- _"foo, bar or baz"
36+--
37+-- :arg items: An array of strings
38+-- :arg listtype: The type of concatenation to use.
39+-- Legal values are "&", "and", "or", and ";"
40+-- :arg former_textdomain: The textdomain to restore after running this function.
41+-- :returns: The concatenated list string, using localized concatenation operators.
42+--
43+-- Same algorithm as in src/base/i18n
44+function localize_list(items, listtype, former_textdomain)
45+ set_textdomain("widelands")
46+ local result = ""
47+ for i, item in pairs(items) do
48+ if (i == 1) then
49+ result = item
50+ elseif (i == #items) then
51+ if (listtype == "&") then
52+ result = _"%1$s & %2$s":bformat(result, item)
53+ elseif (listtype == "or") then
54+ result = _"%1$s or %2$s":bformat(result, item)
55+ elseif (listtype == ",") then
56+ result = _"%1$s, %2$s":bformat(result, item)
57+ else
58+ result = _"%1$s and %2$s":bformat(result, item)
59+ end
60+ else
61+ result = _"%1$s, %2$s":bformat(result, item)
62+ end
63+ end
64+ set_textdomain(former_textdomain)
65+ return result
66+end
67+
68+
69+-- RST
70+-- .. function:: rt(text_or_attributes[, text = nil])
71+--
72+-- Wraps a block of text into Lua rich text.
73+-- Only call this once for the whole text that gets sent to the backend.
74+-- There is no general need to wrap an rt tag around your text,
75+-- because the backend will take care of it.
76+-- So, only use this function if you wish to add some attributes to the tag.
77+--
78+-- Allowed attributes are:
79+-- padding, padding_r, padding_l, padding_b, padding_t: TODO(GunChleoc): Document
80+-- background: a background color or image
81+-- debug: add visual debug information and debug log
82+-- editor_mode: allow multiple blank spaces for editing
83+--
84+-- :arg attributes: the attributes for the rt tag.
85+-- :type attributes: :class:`string`
86+-- :arg text: the text to be enclosed in rich text tags.
87+-- :type text: :class:`string`
88+-- :returns: the wrapped rich text.
89+--
90+function rt(text_or_attributes, text)
91+ if text then
92+ return "<rt " .. text_or_attributes .. ">" .. text .. "</rt>"
93+ else
94+ return "<rt>" .. text_or_attributes .. "</rt>"
95+ end
96+end
97+
98+
99+-- RST
100+-- .. function:: img(src[, attributes = nil])
101+--
102+-- Turns an image src path into an image tag for richtext.
103+--
104+-- :arg src: the file path to the image.
105+-- :type src: :class:`string`
106+-- :arg attributes: the attributes for the div tag.
107+-- :type attributes: :class:`string`
108+--
109+-- Allowed attributes are:
110+-- color: a hex color to be applied to the image's player color mask, if it has any
111+-- ref: TODO(GunChleoc): I have no idea what it does.
112+--
113+-- :returns: the img tag.
114+--
115+function img(src, attributes)
116+ if attributes then
117+ return "<img src=" .. src .." " .. attributes .. ">"
118+ else
119+ return "<img src=" .. src .. ">"
120+ end
121+end
122+
123+
124+function title(font_face, text)
125+ return p_font("align=center", "size=38 face=".. font_face .. " color=2F9131", text)
126+end
127+
128+
129+-- RST
130+-- .. function:: h1(text_or_color[, text = nil])
131+--
132+-- Returns a paragraph formatted as a big heading with a small gap after it.
133+-- The mnemonic comes from HTML.
134+--
135+-- :returns: A paragraph with text formatted as heading.
136+function h1(text_or_color, text)
137+ if text then
138+ return p_font("", "size=18 bold=1 color=".. text_or_color, vspace(6) .. text .. vspace(1))
139+ else
140+ return p_font("", "size=18 bold=1 color=D1D1D1", vspace(6) .. text_or_color .. vspace(1))
141+ end
142+end
143+
144+-- RST
145+-- .. function:: h2(text)
146+--
147+-- Like :func:`h1` but smaller.
148+--
149+-- :returns: A paragraph with text formatted as heading.
150+function h2(text)
151+ return p_font("", "size=14 bold=1 color=D1D1D1", vspace(6) .. text .. vspace(1))
152+end
153+
154+-- RST
155+-- .. function:: h3(text)
156+--
157+-- Like :func:`h2` but smaller.
158+--
159+-- :returns: A paragraph with text formatted as heading.
160+--
161+function h3(text)
162+ return p_font("", "size=13 color=D1D1D1", vspace(4) .. text .. vspace(1))
163+end
164+
165+-- RST
166+-- .. function:: h4(text)
167+--
168+-- Like :func:`h3` but smaller.
169+--
170+-- :returns: A paragraph with text formatted as heading.
171+--
172+function h4(text)
173+ return p_font("", "size=12 italic=1 color=D1D1D1", text)
174+end
175+
176+-- RST
177+-- .. function:: p(text_or_attributes[, text = nil])
178+--
179+-- Returns one paragraph with text followed by a small vertical gap. Options
180+-- can be given as first argument similar to :func:`rt`.
181+--
182+-- Allowed attributes are documented in the open_p function.
183+--
184+-- :returns: The text wrapped in <p>%s</p>
185+function p(text_or_attributes, text)
186+ if text then
187+ return open_p(text_or_attributes) .. text .. close_p()
188+ else
189+ return open_p() .. text_or_attributes .. close_p()
190+ end
191+end
192+
193+
194+-- RST
195+-- .. function:: p(text_or_attributes[, text = nil])
196+--
197+-- Returns one paragraph with text followed by a small vertical gap. Options
198+-- can be given as first argument similar to :func:`rt`.
199+--
200+-- Allowed p attributes are documented in the open_p function.
201+--
202+-- Allowed font attributes are are documented in the font function.
203+--
204+-- :returns: The text wrapped in <p attributes><font attributes>text</font></p>
205+function p_font(p_or_font_or_attributes, text_or_font_attributes, text)
206+ if text then
207+ return ("<p %s>"):format(p_or_font_or_attributes) .. "<font " .. text_or_font_attributes .. ">" .. text .. close_p()
208+ else
209+ return "<p><font " .. p_or_font_or_attributes .. ">" .. text_or_font_attributes .. close_p()
210+ end
211+end
212+
213+
214+-- RST
215+-- .. function:: open_p([attributes = nil])
216+--
217+-- Returns a paragraph open tag and default font size. Options
218+-- can be given as first argument similar to :func:`rt`.
219+--
220+-- Allowed attributes are:
221+-- indent: indents the first line of the paragraph
222+-- align: horizontal alignment (left, center, right)
223+-- valign: vertical alignment (top, middle, bottom)
224+-- spacing: line spacing in pixels
225+--
226+-- :returns: <p> with added attributes and default font
227+function open_p(attributes)
228+ if attributes then
229+ return ("<p %s>"):format(attributes) .. "<font size=12>"
230+ else
231+ return "<p><font size=12>"
232+ end
233+end
234+
235+
236+-- RST
237+-- .. function:: close_p(t)
238+--
239+-- Closes a paragraph.
240+--
241+-- :returns: The closing tags for a paragraph
242+function close_p(t)
243+ return vspace(6) .. "</font></p>"
244+end
245+
246+-- RST
247+-- .. function:: font(attributes, text)
248+--
249+-- Wraps the text in font tags.
250+--
251+-- Allowed attributes are:
252+-- size: the font size in pt
253+-- face: sans, serif or condensed
254+-- color: a hex color
255+-- bold: if you add bold=1, the text will be bold
256+-- italic: if you add italic=1, the text will be italic
257+-- underline: if you add underline=1, the text will be underlined
258+-- shadow: if you add shadow=1, the text will have a shadow
259+-- ref: TODO(GunChleoc): I don't know what this does.
260+--
261+-- :returns: The text wrapped in font tags with the given attributes
262+--
263+function font(attributes, text)
264+ return ("<font %s>"):format(attributes) .. text .. "</font>"
265+end
266+
267+-- RST
268+-- .. function:: space(gap)
269+--
270+-- Adds a horizontal space
271+-- :arg gap: the size of the space as pixels.
272+--
273+-- :returns: a space tag
274+--
275+function space(gap)
276+ return "<space gap="..gap..">"
277+end
278+
279+-- RST
280+-- .. function:: vspace(gap)
281+--
282+-- Adds a vertical space
283+-- :arg gap: the size of the space as pixels.
284+--
285+-- :returns: a vspace tag
286+--
287+function vspace(gap)
288+ return "<vspace gap="..gap..">"
289+end
290+
291+-- RST
292+-- .. function:: dl(dt, dd)
293+--
294+-- This function imitates a HTML description list
295+-- :arg dt: "description term", will be rendered in bold.
296+-- :arg dd: "description data", will be rendered normally.
297+--
298+-- :returns: a p tag containing the formatted text
299+--
300+function dl(dt, dd)
301+ return p(b(dt) .. " " .. dd)
302+end
303+
304+-- RST
305+-- .. function:: li(text_or_symbol[, text = nil])
306+--
307+-- Adds the symbol in front of the text to create a list item and
308+-- wraps it in a paragraph
309+--
310+-- :arg symbol: the item symbol for the list, e.g. "•" or "→"
311+-- :arg text: the text of the list item
312+--
313+-- :returns: a p tag containint the formatted text
314+function li(text_or_symbol, text)
315+ if text then
316+ return p(text_or_symbol .. " " .. text .. vspace(6))
317+ else
318+ return p("• " .. text_or_symbol .. vspace(6))
319+ end
320+end
321+
322+-- RST
323+-- .. function:: li_arrow(text)
324+--
325+-- Creates a list item with an arrow
326+--
327+-- :arg text: the text of the list item
328+--
329+-- :returns: li("→", text)
330+function li_arrow(text)
331+ -- TODO(GunChleoc): Reverse arrow for rtl languages.
332+ return li("→", text)
333+end
334+
335+-- RST
336+-- .. function li_image(imagepath, text)
337+--
338+-- Places a paragraph of text to the right of an image
339+
340+-- :arg imagepath: the full path to the image file
341+-- :arg text_width_percent: the percentatge of space that the text will occupy
342+-- :arg text: the text to be placed next to the image
343+--
344+-- :returns: the text wrapped in a paragraph and placed next to the image, The outer tag is a div.
345+function li_image(imagepath, text_width_percent, text)
346+ return p("<br>") .. div("width=100%", "") ..
347+ div(p(img(imagepath))) ..
348+ div(p(space(6))) ..
349+ div("width="..text_width_percent.."%", p(text)) ..
350+ div("width=100%", "")
351+end
352+
353+-- RST
354+-- .. function:: a(link)
355+--
356+-- This function imitates a HTML link. We can't do real links yet, so the text just gets underlines.
357+-- :arg link: the text to format
358+--
359+-- :returns: a font tag containing the underlined text
360+--
361+function a(link)
362+ return font("underline=1", link)
363+end
364+
365+-- RST
366+-- .. function:: b(link)
367+--
368+-- This makes the text bold.
369+-- :arg link: the text to format
370+--
371+-- :returns: a font tag containing the bold text
372+--
373+function b(text)
374+ return font("bold=1", text)
375+end
376+
377+-- RST
378+-- .. function:: i(link)
379+--
380+-- This makes the text italic.
381+-- :arg link: the text to format
382+--
383+-- :returns: a font tag containing the italic text
384+--
385+function i(text)
386+ return font("italic=1", text)
387+end
388+
389+-- RST
390+-- .. function:: u(link)
391+--
392+-- This underlines the text.
393+-- :arg link: the text to format
394+--
395+-- :returns: a font tag containing the underlined text
396+--
397+function u(text)
398+ return font("underline=1", text)
399+end
400+
401+-- RST
402+-- .. function:: div(text_or_attributes[, text = nil])
403+--
404+-- Wraps a block of text into a div tag.
405+--
406+-- :arg attributes: the attributes for the div tag.
407+-- :type attributes: :class:`string`
408+--
409+-- Allowed attributes are:
410+-- padding, padding_r, padding_l, padding_b, padding_t: TODO(GunChleoc): Document
411+-- margin: TODO(GunChleoc): Document
412+-- float: TODO(GunChleoc): this does not work yet
413+-- margin: inner margin for the div
414+-- valign: vertical alignment
415+-- background: a background color or image
416+-- width: the width of the div in pixels or percent
417+--
418+-- :arg text: the text to be enclosed in div tags.
419+-- :type text: :class:`string`
420+-- :returns: the text wrapped in a div tag.
421+--
422+function div(text_or_attributes, text)
423+ if text then
424+ return ("<div %s>"):format(text_or_attributes) .. text .. "</div>"
425+ else
426+ return ("<div>") .. text_or_attributes .. "</div>"
427+ end
428+end
429
430=== modified file 'data/scripting/win_conditions/artifacts.lua'
431--- data/scripting/win_conditions/artifacts.lua 2016-09-20 17:01:35 +0000
432+++ data/scripting/win_conditions/artifacts.lua 2017-06-16 07:57:28 +0000
433@@ -4,7 +4,6 @@
434
435 include "scripting/coroutine.lua" -- for sleep
436 include "scripting/win_conditions/win_condition_functions.lua"
437-include "scripting/formatting.lua"
438
439 set_textdomain("win_conditions")
440
441@@ -53,7 +52,7 @@
442 local plrs = wl.Game().players
443 if #artifact_fields == 0 then
444 for idx, plr in ipairs(plrs) do
445- send_message(plr, _"No Artifacts", rt(p(_"There are no artifacts on this map. This should not happen. Please file a bug report on https://launchpad.net/widelands and specify your Widelands version and the map you tried to load.")), {popup = true})
446+ send_message(plr, _"No Artifacts", p(_"There are no artifacts on this map. This should not happen. Please file a bug report on https://launchpad.net/widelands and specify your Widelands version and the map you tried to load."), {popup = true})
447 end
448 return
449 end
450@@ -61,17 +60,17 @@
451 local found_artifact = {
452 -- TRANSLATORS: Keep this as short as possible. You can also translate this as "New artifact"
453 title = _"Artifact Found",
454- body = rt(p(_[[Your team found a new artifact.]]))
455+ body = p(_[[Your team found a new artifact.]])
456 }
457 local lost_artifact = {
458 -- TRANSLATORS: Keep this as short as possible.
459 title = _"Artifact Lost",
460- body = rt(p(_[[One of your team’s artifacts was stolen by an enemy.]]))
461+ body = p(_[[One of your team’s artifacts was stolen by an enemy.]])
462 }
463 local stole_artifact = {
464 -- TRANSLATORS: Keep this as short as possible.
465 title = _"Artifact Conquered",
466- body = rt(p(_[[Your team stole an artifact from an enemy.]]))
467+ body = p(_[[Your team stole an artifact from an enemy.]])
468 }
469
470 local function _broadcast_to_team(player, msg, f)
471@@ -174,10 +173,10 @@
472 local key = _getkey(plr)
473 -- If two or more teams have the same amount of artifacts, they are all considered winners.
474 if artifacts_per_team[key] == max_artifacts then
475- plr:send_message(won_game_over.title, rt(won_game_over.body .. msg))
476+ plr:send_message(won_game_over.title, won_game_over.body .. msg)
477 wl.game.report_result(plr, 1, make_extra_data(plr, wc_descname, wc_version, {score=artifacts_per_team[key]}))
478 else
479- plr:send_message(lost_game_over.title, rt(lost_game_over.body .. msg))
480+ plr:send_message(lost_game_over.title, lost_game_over.body .. msg)
481 wl.game.report_result(plr, 0, make_extra_data(plr, wc_descname, wc_version, {score=artifacts_per_team[key]}))
482 end
483 end
484
485=== modified file 'data/scripting/win_conditions/collectors.lua'
486--- data/scripting/win_conditions/collectors.lua 2016-12-01 21:14:28 +0000
487+++ data/scripting/win_conditions/collectors.lua 2017-06-16 07:57:28 +0000
488@@ -4,8 +4,6 @@
489
490 include "scripting/coroutine.lua" -- for sleep
491 include "scripting/messages.lua"
492-include "scripting/formatting.lua"
493-include "scripting/format_scenario.lua"
494 include "scripting/table.lua"
495 include "scripting/win_conditions/win_condition_functions.lua"
496
497@@ -108,7 +106,7 @@
498 plr:get_buildings(plr.tribe_name .. "_headquarters"), plr:get_buildings(plr.tribe_name .. "_warehouse"), plr:get_buildings(plr.tribe_name .. "_port")
499 )
500
501- descr = descr .. h2((_"Status for %s"):format(plr.name)) .. "<p line-spacing=3 font-size=12>"
502+ descr = descr .. h2((_"Status for %s"):format(plr.name))
503 local points = 0
504 for idx, ware in ipairs(point_table[plr.tribe_name .. "_order"]) do
505 local value = point_table[plr.tribe_name][ware]
506@@ -121,11 +119,11 @@
507
508 local warename = wl.Game():get_ware_description(ware).descname
509 -- TRANSLATORS: For example: 'gold (3 P) x 4 = 12 P', P meaning 'Points'
510- descr = descr .. listitem_bullet(_"%1$s (%2$i P) x %3$i = %4$i P"):bformat(
511+ descr = descr .. li(_"%1$s (%2$i P) x %3$i = %4$i P"):bformat(
512 warename, value, count, lpoints
513 )
514 end
515- descr = descr .. "</p>" .. h3(ngettext("Total: %i point", "Total: %i points", points)):format(points)
516+ descr = descr .. h3(ngettext("Total: %i point", "Total: %i points", points)):format(points)
517 team_points = team_points + points
518 end
519
520@@ -135,10 +133,10 @@
521
522 -- Send all players the momentary game state
523 local function _send_state(remaining_time, plrs)
524- local msg = ""
525+ local msg = vspace(8)
526 set_textdomain("win_conditions")
527 if remaining_time <= 0 then
528- msg = p(_"The game has ended.")
529+ msg = p(_"The game has ended.") .. vspace(8)
530 else
531 local h = math.floor(remaining_time / 60)
532 local m = remaining_time % 60
533@@ -157,14 +155,14 @@
534 end
535 end
536 -- TRANSLATORS: Context: 'The game will end in 2 hours and 30 minutes.'
537- msg = p(_"The game will end in %s."):format(time)
538+ msg = p(_"The game will end in %s."):format(time) .. vspace(8)
539 end
540
541 -- Points for players without team
542 for idx, plr in ipairs(plrs) do
543 if (plr.team == 0) then
544 local points, pstat = _calc_points({plr})
545- msg = msg .. "<p font-size=8> <br></p>" .. pstat
546+ msg = msg .. vspace(8) .. pstat
547 end
548 end
549 -- Team points
550@@ -173,11 +171,11 @@
551 local message = h1((_"Status for Team %d"):format(idx))
552 .. pstat
553 .. h2(ngettext("Team Total: %i point", "Team Total: %i points", points)):format(points)
554- msg = msg .. "<p font-size=8> <br></p>" .. message
555+ msg = msg .. vspace(8) .. message
556 end
557
558 for idx, plr in ipairs(plrs) do
559- send_message(plr, game_status.title, "<rt>" .. msg .. "</rt>", {popup = true})
560+ send_message(plr, game_status.title, msg, {popup = true})
561 end
562 end
563
564@@ -201,10 +199,10 @@
565 local lost_or_won = 0
566 if (info[2] < win_points) then
567 lost_or_won = 0
568- player:send_message(lost_game_over.title, rt(lost_game_over.body))
569+ player:send_message(lost_game_over.title, lost_game_over.body)
570 else
571 lost_or_won = 1
572- player:send_message(won_game_over.title, rt(won_game_over.body))
573+ player:send_message(won_game_over.title, won_game_over.body)
574 end
575 if (player.team == 0) then
576 wl.game.report_result(player, lost_or_won, make_extra_data(player, wc_descname, wc_version, {score=info[2]}))
577
578=== modified file 'data/scripting/win_conditions/territorial_lord.lua'
579--- data/scripting/win_conditions/territorial_lord.lua 2016-09-17 11:29:34 +0000
580+++ data/scripting/win_conditions/territorial_lord.lua 2017-06-16 07:57:28 +0000
581@@ -3,7 +3,6 @@
582 -- =======================================================================
583
584 include "scripting/coroutine.lua" -- for sleep
585-include "scripting/formatting.lua"
586 include "scripting/messages.lua"
587 include "scripting/table.lua"
588 include "scripting/win_conditions/win_condition_functions.lua"
589@@ -155,16 +154,14 @@
590 if candidateisteam then
591 candidate = (_"Team %i"):format(currentcandidate)
592 end
593- local msg1 = (_"%s owns more than half of the map’s area."):format(candidate)
594- msg1 = msg1 .. "\n"
595- msg1 = msg1 .. (ngettext("You’ve still got %i minute to prevent a victory.",
596+ local msg1 = p(_"%s owns more than half of the map’s area."):format(candidate)
597+ msg1 = msg1 .. p(ngettext("You’ve still got %i minute to prevent a victory.",
598 "You’ve still got %i minutes to prevent a victory.",
599 remaining_time / 60))
600 :format(remaining_time / 60)
601
602- local msg2 = _"You own more than half of the map’s area."
603- msg2 = msg2 .. "\n"
604- msg2 = msg2 .. (ngettext("Keep it for %i more minute to win the game.",
605+ local msg2 = p(_"You own more than half of the map’s area.")
606+ msg2 = msg2 .. p(ngettext("Keep it for %i more minute to win the game.",
607 "Keep it for %i more minutes to win the game.",
608 remaining_time / 60))
609 :format(remaining_time / 60)
610@@ -172,9 +169,9 @@
611 for idx, player in ipairs(plrs) do
612 if candidateisteam and currentcandidate == player.team
613 or not candidateisteam and currentcandidate == player.name then
614- send_message(player, game_status.title, rt(p(msg2)), {popup = true})
615+ send_message(player, game_status.title, msg2, {popup = true})
616 else
617- send_message(player, game_status.title, rt(p(msg1)), {popup = true})
618+ send_message(player, game_status.title, msg1, {popup = true})
619 end
620 end
621 end
622@@ -201,10 +198,10 @@
623 p.see_all = 1
624 if candidateisteam and currentcandidate == p.team
625 or not candidateisteam and currentcandidate == p.name then
626- p:send_message(won_game_over.title, rt(won_game_over.body))
627+ p:send_message(won_game_over.title, won_game_over.body)
628 wl.game.report_result(p, 1, make_extra_data(p, wc_descname, wc_version, {score=_landsizes[p.number]}))
629 else
630- p:send_message(lost_game_over.title, rt(lost_game_over.body))
631+ p:send_message(lost_game_over.title, lost_game_over.body)
632 wl.game.report_result(p, 0, make_extra_data(p, wc_descname, wc_version, {score=_landsizes[p.number]}))
633 end
634 end
635
636=== modified file 'data/scripting/win_conditions/territorial_time.lua'
637--- data/scripting/win_conditions/territorial_time.lua 2016-09-17 11:29:34 +0000
638+++ data/scripting/win_conditions/territorial_time.lua 2017-06-16 07:57:28 +0000
639@@ -6,7 +6,6 @@
640 -- here. Pull that out into a separate script and reuse.
641
642 include "scripting/coroutine.lua" -- for sleep
643-include "scripting/formatting.lua"
644 include "scripting/messages.lua"
645 include "scripting/table.lua"
646 include "scripting/win_conditions/win_condition_functions.lua"
647@@ -179,10 +178,9 @@
648 local function _status(points, has_had)
649 local msg = ""
650 for i=1,#points do
651- msg = msg .. "\n"
652 if (has_had == "has") then
653 msg = msg ..
654- listitem_bullet(
655+ li(
656 (wc_has_territory):bformat(
657 points[i][1],
658 _percent(points[i][2], #fields),
659@@ -190,7 +188,7 @@
660 #fields))
661 else
662 msg = msg ..
663- listitem_bullet(
664+ li(
665 (wc_had_territory):bformat(
666 points[i][1],
667 _percent(points[i][2], #fields),
668@@ -204,17 +202,15 @@
669
670 local function _send_state(points)
671 set_textdomain("win_conditions")
672- local msg1 = (_"%s owns more than half of the map’s area."):format(currentcandidate)
673- msg1 = msg1 .. "<br>"
674- msg1 = msg1 .. (ngettext("You’ve still got %i minute to prevent a victory.",
675+ local msg1 = p(_"%s owns more than half of the map’s area."):format(currentcandidate)
676+ msg1 = msg1 .. p(ngettext("You’ve still got %i minute to prevent a victory.",
677 "You’ve still got %i minutes to prevent a victory.",
678 remaining_time // 60))
679 :format(remaining_time // 60)
680 msg1 = p(msg1)
681
682- local msg2 = _"You own more than half of the map’s area."
683- msg2 = msg2 .. "<br>"
684- msg2 = msg2 .. (ngettext("Keep it for %i more minute to win the game.",
685+ local msg2 = p(_"You own more than half of the map’s area.")
686+ msg2 = msg2 .. p(ngettext("Keep it for %i more minute to win the game.",
687 "Keep it for %i more minutes to win the game.",
688 remaining_time // 60))
689 :format(remaining_time // 60)
690@@ -225,9 +221,9 @@
691 if remaining_time < remaining_max_time and _maxpoints(points) > ( #fields / 2 ) then
692 if candidateisteam and currentcandidate == team_str:format(pl.team)
693 or not candidateisteam and currentcandidate == pl.name then
694- msg = msg .. msg2 .. "\n\n"
695+ msg = msg .. msg2 .. vspace(8)
696 else
697- msg = msg .. msg1 .. "\n\n"
698+ msg = msg .. msg1 .. vspace(8)
699 end
700 -- TRANSLATORS: Refers to "You own more than half of the map’s area. Keep it for x more minute(s) to win the game."
701 msg = msg .. p((ngettext("Otherwise the game will end in %i minute.",
702@@ -240,10 +236,8 @@
703 remaining_max_time // 60))
704 :format(remaining_max_time // 60))
705 end
706- msg = msg .. "\n\n"
707- msg = msg .. "</rt>" .. rt(game_status.body) .. "<rt>"
708- msg = msg .. _status(points, "has")
709- send_message(pl, game_status.title, rt(msg), {popup = true})
710+ msg = msg .. vspace(8) .. game_status.body .. _status(points, "has")
711+ send_message(pl, game_status.title, msg, {popup = true})
712 end
713 end
714
715@@ -295,10 +289,10 @@
716 for i=1,#points do
717 if points[i][1] == team_str:format(pl.team) or points[i][1] == pl.name then
718 if points[i][2] >= maxpoints then
719- pl:send_message(won_game_over.title, wonmsg .. rt(_status(points, "had")))
720+ pl:send_message(won_game_over.title, wonmsg .. _status(points, "had"))
721 wl.game.report_result(pl, 1, make_extra_data(pl, wc_descname, wc_version, {score=_landsizes[pl.number]}))
722 else
723- pl:send_message(lost_game_over.title, lostmsg .. rt(_status(points, "had")))
724+ pl:send_message(lost_game_over.title, lostmsg .. _status(points, "had"))
725 wl.game.report_result(pl, 0, make_extra_data(pl, wc_descname, wc_version, {score=_landsizes[pl.number]}))
726 end
727 end
728
729=== modified file 'data/scripting/win_conditions/win_condition_functions.lua'
730--- data/scripting/win_conditions/win_condition_functions.lua 2016-03-15 08:42:41 +0000
731+++ data/scripting/win_conditions/win_condition_functions.lua 2017-06-16 07:57:28 +0000
732@@ -1,3 +1,4 @@
733+include "scripting/richtext.lua"
734 include "scripting/messages.lua"
735
736 -- RST
737
738=== modified file 'data/scripting/win_conditions/win_condition_texts.lua'
739--- data/scripting/win_conditions/win_condition_texts.lua 2016-09-20 17:01:35 +0000
740+++ data/scripting/win_conditions/win_condition_texts.lua 2017-06-16 07:57:28 +0000
741@@ -1,13 +1,13 @@
742-include "scripting/formatting.lua"
743+include "scripting/richtext.lua"
744
745 won_game = {
746 title = _"Congratulations!",
747- body = rt(p(_"You have won this game!"))
748+ body = p(_"You have won this game!")
749 }
750
751 lost_game = {
752 title = _"You are defeated!",
753- body = rt(p(_"You lost your last warehouse and are therefore defeated. You may continue as spectator if you want."))
754+ body = p(_"You lost your last warehouse and are therefore defeated. You may continue as spectator if you want.")
755 }
756
757 won_game_over = {
758@@ -23,5 +23,5 @@
759 game_status = {
760 title = _"Status",
761 -- TRANSLATORS: This is an overview for all players.
762- body = h3(_"Player overview:")
763+ body = h2(_"Player overview:")
764 }
765
766=== modified file 'data/scripting/win_conditions/wood_gnome.lua'
767--- data/scripting/win_conditions/wood_gnome.lua 2016-12-18 17:02:44 +0000
768+++ data/scripting/win_conditions/wood_gnome.lua 2017-06-16 07:57:28 +0000
769@@ -3,7 +3,6 @@
770 -- =======================================================================
771
772 include "scripting/coroutine.lua" -- for sleep
773-include "scripting/formatting.lua"
774 include "scripting/table.lua"
775 include "scripting/win_conditions/win_condition_functions.lua"
776
777@@ -92,14 +91,14 @@
778 local playerpoints = _calc_points()
779 local msg = p(ngettext("The game will end in %i minute.", "The game will end in %i minutes.", remaining_time))
780 :format(remaining_time)
781- msg = msg .. "<p font-size=8> <br></p>" .. game_status.body
782+ msg = msg .. vspace(8) .. game_status.body
783 for idx,plr in ipairs(plrs) do
784 local trees = (ngettext ("%i tree", "%i trees", playerpoints[plr.number]))
785 :format(playerpoints[plr.number])
786 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)
787 msg = msg .. p(_"%1$s has %2$s at the moment."):bformat(plr.name,trees)
788 end
789- broadcast(plrs, game_status.title, rt(msg))
790+ broadcast(plrs, game_status.title, msg)
791 end
792
793 -- Start a new coroutine that checks for defeated players
794@@ -143,14 +142,14 @@
795 end
796 table.sort(points, function(a,b) return a[2] < b[2] end)
797
798- local msg = "<p font-size=8> <br></p>" .. game_status.body
799+ local msg = vspace(8) .. game_status.body
800 for idx,plr in ipairs(plrs) do
801- msg = msg .. "<p font-size=8> <br></p>"
802+ msg = msg .. vspace(8)
803 local trees = (ngettext ("%i tree", "%i trees", playerpoints[plr.number])):format(playerpoints[plr.number])
804 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)
805 msg = msg .. p(_"%1$s had %2$s."):bformat(plr.name,trees)
806 end
807- msg = msg .. "<p font-size=8> <br></p>"
808+ msg = msg .. vspace(8)
809 local trees = (ngettext ("%i tree", "%i trees", playerpoints[points[#points][1].number]))
810 :format(playerpoints[points[#points][1].number])
811 -- TRANSLATORS: %1$s = player name, %2$s = x tree(s)
812@@ -160,12 +159,12 @@
813 for i=1,#points-1 do
814 privmsg = lost_game_over.body
815 privmsg = privmsg .. msg
816- points[i][1]:send_message(lost_game_over.title, rt(privmsg))
817+ points[i][1]:send_message(lost_game_over.title, privmsg)
818 wl.game.report_result(points[i][1], 0, make_extra_data(points[i][1], wc_descname, wc_version, {score=points[i][2]}))
819 end
820 privmsg = won_game_over.body
821 privmsg = privmsg .. msg
822- points[#points][1]:send_message(won_game_over.title, rt(privmsg))
823+ points[#points][1]:send_message(won_game_over.title, privmsg)
824 wl.game.report_result(points[#points][1], 1,
825 make_extra_data(points[#points][1], wc_descname, wc_version, {score=points[#points][2]}))
826 end

Subscribers

People subscribed via source and target branches

to status/vote changes: