GunChleoc has proposed merging lp:~widelands-dev/widelands/fh1-winconditions
into lp:widelands.
Commit message:
Converted win condition scripts to new font renderer. Formatting functions for
the new renderer live in data/scripting/richtext.lua
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fh1-winconditions/+merge/323987
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.
--
Your team Widelands Developers is requested to review the proposed merge of
lp:~widelands-dev/widelands/fh1-winconditions into lp:widelands.
=== modified file 'data/scripting/formatting.lua'
--- data/scripting/formatting.lua 2016-10-19 09:00:29 +
+++ data/scripting/formatting.lua 2017-05-12 14:03:15 +
@@ -1,3 +1,6 @@
+-- TODO(GunChleoc): This is for the legacy font renderer. Remove when we remove the old renderer.
+
+
-- RST
-- formatting.lua
-- --
=== added file 'data/scripting/richtext.lua'
--- data/scripting/richtext.lua 1970-01-01 00:00:00 +
+++ data/scripting/richtext.lua 2017-05-12 14:03:15 +
@@ -0,0 +1,412 @@
+-- NOCOM(GunChleoc): Wrap all tags and document allowed attributes when we're done
+-- RST
+-- formatting.lua
+-- --
+--
+-- Functions to simplify and unique text formatting in scenarios and help files.
+-- Most of these functions are simple wrapper functions that make working with
+-- widelands rich text formatting system more bearable.
+-- Function names generally follow HTML names.
+
+
+-- RST
+-- .. function:: localize_list(items, listtype, former_textdomain)
+--
+--Turns an array of string items into a localized string list with
+--appropriate concatenation.
+--
+--e.g. localize_list({"foo", "bar", baz"}, "or", "widelands") will return
+--_"foo, bar or baz"
+--
+--:arg items: An array of strings
+--:arg listtype: The type of concatenation to use.
+-- Legal values are "&", "and", "or", and ";"
+--:arg former_textdomain: The textdomain to restore after running this function.
+--:returns: The concatenated list string, using localized concatenation operators.
+--
+-- Same algorithm as in src/base/i18n
+function localize_list(items, listtype, former_textdomain)
+ set_textdomain("widelands")
+ local result = ""
+ for i, item in pairs(items) do
+ if (i == 1) then
+ result = item
+ elseif (i == #items) then
+ if (listtype == "&") then
+result = _"%1$s & %2$s":bformat(result, item)
+ elseif (listtype == "or") then
+result = _"%1$s or %2$s":bformat(result, item)
+ elseif (listtype == ",") then
+result = _"%1$s, %2$s":bformat(result, item)
+ else
+result = _"%1$s and %2$s":bformat(result, item)
+ end
+ else
+ result = _"%1$s, %2$s":bformat(result, item)
+ end
+ end
+ set_textdomain(former_textdomain)
+ return result
+end
+
+
+-- RST
+-- .. function:: rt(text_or_attributes[, text = nil])
+--
+--Wraps a block of text into Lua rich text.
+--Only call this once for the whole text that gets sent to the backend.
+--There is no general need to wrap an rt tag around your text,
+--because the backend will take care of it.
+--So, only use this function if you wish to add some attributes to the tag.
+--
+--Allowed attributes are:
+-- padding, padding_r, padding_l, padding_b, padding_t: NOCOM(GunChleoc): Document
+-- background: a background color or image
+-- debug: add visual debug information and debug log
+-- editor_mode: allow multiple blank spaces for editing
+--
+--:arg attributes: the attributes for the rt tag.
+--:type attributes: :class:`string`
+--:arg text: the text to be enclosed in rich text tags.
+--:type text: :class:`string`
+--:returns: the wrapped rich text.
+--
+function rt(text_or_attributes, text)
+ if text then
+ return "" .. text .. ""
+ else
+ return "" .. text_or_attributes .. ""
+ end
+end
+
+
+-- RST
+-- .. function:: img(src[, attributes = nil])
+--
+--Turns an image src path into an image tag for richtext.
+--
+--:arg src: the file path to the image.
+--:type src: :class:`string`
+--:arg attributes: the attributes for the div tag.
+--:type attributes: :class:`string`
+--
+--Allowed attributes are:
+-- color: a hex color to be applied to the image's player color mask, if it has any
+-- ref: NOCOM(GunChleoc): I have no idea what it does.
+--
+--:returns: the img tag.
+--
+function img(src, attributes)
+ if attributes then
+ return ""
+ else
+ return