shadowm

Untitled

Jun 25th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. ---
  2. -- Handle saved games generated before the 'fairy' race was
  3. -- renamed to 'faerie' in AtS 0.9.4, including file paths.
  4. ---
  5.  
  6. local helper = wesnoth.require "lua/helper.lua"
  7.  
  8. function faerie_spelling_transition_handler()
  9.     local function _log(text)
  10.         wesnoth.fire("wml_message", { message = text, logger = "error" })
  11.     end
  12.  
  13.     _log "BEGIN: faerie spelling transition handler"
  14.  
  15.     local fn_patn = '/fairies/'
  16.     local fn_repl = '/faeries/'
  17.  
  18.     local function do_recursive_fixup(ucfg)
  19.         if ucfg.image ~= nil
  20.             and type(ucfg.image) == "string"
  21.             and string.match(ucfg.image, fn_patn)
  22.         then
  23.             local newval = string.gsub(ucfg.image, fn_patn, fn_repl)
  24.             _log(string.format("  IMAGE PATH FIX: %s -> %s", ucfg.image, newval))
  25.             ucfg.image = newval
  26.         end
  27.  
  28.         for i, node in ipairs(helper.shallow_literal(ucfg)) do
  29.             -- _log("TABLE: " .. node[1]) -- node tag
  30.             do_recursive_fixup(node[2]) -- node contents
  31.         end
  32.     end
  33.  
  34.     local function fixup(ucfg)
  35.         ucfg.race = "faerie"
  36.  
  37.         if ucfg.profile == 'images/units/fairies/fairy.png' then
  38.             ucfg.profile = 'images/units/faeries/fire.png'
  39.         elseif string.match(ucfg.profile, fn_patn) then
  40.             ucfg.profile = string.gsub(ucfg.profile, fn_patn, fn_repl)
  41.         end
  42.  
  43.         do_recursive_fixup(ucfg)
  44.     end
  45.  
  46.     ---
  47.     -- Fix units on the map and recall list.
  48.     ---
  49.  
  50.     local filter = { race = "fairy" }
  51.  
  52.     for i, u in ipairs(wesnoth.get_units(filter)) do
  53.         _log(string.format("  RACE ID FIX: %s (%s) [gamemap]", u.id, tostring(u.name)))
  54.  
  55.         local ucfg_new = u.__cfg
  56.         fixup(ucfg_new)
  57.         wesnoth.put_unit(ucfg_new)
  58.     end
  59.  
  60.     for i, u in ipairs(wesnoth.get_recall_units(filter)) do
  61.         _log(string.format("  RACE ID FIX: %s (%s) [recall]", u.id, tostring(u.name)))
  62.  
  63.         local ucfg_new = u.__cfg
  64.         fixup(ucfg_new)
  65.         wesnoth.put_recall_unit(ucfg_new)
  66.     end
  67.  
  68.     ---
  69.     -- Fix stored units.
  70.     ---
  71.  
  72.     -- NO FUCK THIS
  73.     --local fixup_containers = {}
  74.  
  75.     _log "END: faerie spelling transition handler"
  76. end
  77.  
  78. -- Register a preload event handler to bootstrap ourselves.
  79.  
  80. wesnoth.fire("event", {
  81.     name = "preload",
  82.     { "lua", { code = "faerie_spelling_transition_handler()" } }
  83. })
Advertisement
Add Comment
Please, Sign In to add comment