mail[Wesnoth-commits] r40145 - /trunk/data/campaigns/Legend_of_Wesmere/lua/replace_map.lua


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on December 06, 2009 - 14:59:
Author: silene
Date: Sun Dec  6 14:59:12 2009
New Revision: 40145

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40145&view=rev
Log:
Removed a bit of 'tonumber' noise.

Modified:
    trunk/data/campaigns/Legend_of_Wesmere/lua/replace_map.lua

Modified: trunk/data/campaigns/Legend_of_Wesmere/lua/replace_map.lua
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/campaigns/Legend_of_Wesmere/lua/replace_map.lua?rev=40145&r1=40144&r2=40145&view=diff
==============================================================================
--- trunk/data/campaigns/Legend_of_Wesmere/lua/replace_map.lua (original)
+++ trunk/data/campaigns/Legend_of_Wesmere/lua/replace_map.lua Sun Dec  6 
14:59:12 2009
@@ -1,31 +1,33 @@
 local H = wesnoth.require "lua/helper.lua"
 local replace_map
-replace_map = wesnoth.register_wml_action("replace_map", function(cfg)
-                                                           if not cfg.x and 
not cfg.y then
-                                                              
replace_map(cfg)
-                                                           else
-                                                              local x1,x2 = 
string.match(cfg.x, "(%d+)-(%d+)")
-                                                              local y1,y2 = 
string.match(cfg.y, "(%d+)-(%d+)")
-                                                              local 
header,map = string.match(cfg.map_data, "(.-)\n\n(.*)")
-                                                              local b = 
string.match(header, "border_size=(%d+)")
-                                                              x2 = x2 + 2 * b
-                                                              y2 = y2 + 2 * b
-                                                              local t = {}
-                                                              local y = 1
-                                                              for row in 
string.gmatch(map, "[^\n]+") do
-                                                                 if y >= 
tonumber(y1) and y <= tonumber(y2) then
-                                                                    local r 
= {}
-                                                                    local x 
= 1
-                                                                    for tile 
in string.gmatch(row, "[^,]+") do
-                                                                       if x 
= tonumber(x1) and x <= tonumber(x2) then r[x - tonumber(x1) + 1] = tile end
-                                                                       x = x 
+ 1
-                                                                    end
-                                                                    t[y - 
tonumber(y1) + 1] = table.concat(r, ',')
-                                                                 end
-                                                                 y = y + 1
-                                                              end
-                                                              local s = 
table.concat(t, '\n')
-                                                              local new_map 
= string.format("border_size=%d\nusage=map\n\n%s", b, s)
-                                                              replace_map { 
map = new_map, expand = true, shrink = true }
-                                                           end
-                                                        end)
+replace_map = wesnoth.register_wml_action("replace_map",
+  function(cfg)
+    if not cfg.x and not cfg.y then
+       return replace_map(cfg)
+    end
+    local x1,x2 = string.match(cfg.x, "(%d+)-(%d+)")
+    local y1,y2 = string.match(cfg.y, "(%d+)-(%d+)")
+    local header,map = string.match(cfg.map_data, "(.-)\n\n(.*)")
+    local b = string.match(header, "border_size=(%d+)")
+    x1 = tonumber(x1)
+    y1 = tonumber(y1)
+    x2 = x2 + 2 * b
+    y2 = y2 + 2 * b
+    local t = {}
+    local y = 1
+    for row in string.gmatch(map, "[^\n]+") do
+      if y >= y1 and y <= y2 then
+        local r = {}
+        local x = 1
+        for tile in string.gmatch(row, "[^,]+") do
+          if x >= x1 and x <= x2 then r[x - x1 + 1] = tile end
+          x = x + 1
+        end
+        t[y - y1 + 1] = table.concat(r, ',')
+      end
+      y = y + 1
+    end
+    local s = table.concat(t, '\n')
+    local new_map = string.format("border_size=%d\nusage=map\n\n%s", b, s)
+    replace_map { map = new_map, expand = true, shrink = true }
+  end)




Related Messages


Powered by MHonArc, Updated Sun Dec 06 16:40:13 2009