File: tips.lua

package info (click to toggle)
widelands 2%3A1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684,084 kB
  • sloc: cpp: 196,737; ansic: 19,395; python: 8,515; sh: 1,734; xml: 700; makefile: 46; lisp: 25
file content (66 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
include "scripting/richtext.lua"

function get_general_tips()
   include "txts/tips/general_game.lua"
   return tips
end

function get_singleplayer_tips()
   include "txts/tips/singleplayer.lua"
   return tips
end

function get_multiplayer_tips()
   include "txts/tips/multiplayer.lua"
   return tips
end

function format_tips(tips)
   local text = ""
   for index, contents in pairs(tips) do
      text = text .. li(contents["text"])
   end
   return text
end

return {
   func = function(tribename, game_type)
      push_textdomain("tribes_encyclopedia")
      local text = h2(_("General"))
      text = text .. format_tips(get_general_tips())

      if tribename ~= nil and tribename ~= "" then
         local descr = wl.Game():get_tribe_description(tribename)
         local scriptpath = descr.directory
         local p
         if scriptpath:find("addons") == 1 then
            p = scriptpath .. "tips.lua"
         else
            p = "txts/tips/" .. tribename .. ".lua"
         end
         if path.file_exists(p) then
            tips = nil
            include(p)
            if tips then
               text = text .. h2(descr.descname) .. format_tips(tips)
               tips = nil
            end
         end
      end

      if (game_type == "singleplayer") then
         text = text .. h2(_("Single Player"))
         text = text .. format_tips(get_singleplayer_tips())
      else
         text = text .. h2(_("Multiplayer"))
         text = text .. format_tips(get_multiplayer_tips())
      end

      local result = {
        title = _("Tips"),
        text = text
      }
      pop_textdomain()
      return result
   end
}