Guest User

dev_print_unitdefs.lua

a guest
Nov 12th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. function widget:GetInfo()
  2.   return {
  3.         name        = "zzz print unitdefs",
  4.         desc        = "write to file unit definitions",
  5.         author      = "Svatopluk",
  6.         date        = "11/12/2015",
  7.         license     = "Hail Svatopluk 3x",
  8.         layer       = 100,
  9.         enabled   = true  --  loaded by default?
  10.   }
  11. end
  12.  
  13.  
  14.  
  15. -- local function repeatString(str, times)
  16.     -- local result = ""
  17.     -- local i=1
  18.     -- while i < level do
  19.         -- result = result .. str
  20.         -- i = i + 1
  21.     -- end
  22.     -- return result
  23. -- end
  24.  
  25. local function toStringRecursive(value, level)
  26.     local valType = type(value)
  27.     local valStr = ""
  28.     if valType == "table" then
  29.         valStr = "table {\n"
  30.         for tableKey,tableValue in pairs(value) do
  31.             valStr = valStr .. string.rep("\t", level + 1) .. tostring(tableKey) .. "=" .. toStringRecursive(tableValue, level + 1) .. "\n"
  32.         end
  33.         valStr = valStr.. string.rep("\t", level) .. "}"
  34.     else
  35.         valStr = tostring(value)
  36.         -- valStr = "other (type " .. valType .. ")"if valType == "string" then
  37.         -- valStr = value
  38.     -- elseif valType == "number" then
  39.         -- valStr = "" .. value
  40.     -- elseif valType == "boolean" then
  41.         -- if value == true then
  42.             -- valStr = "true"
  43.         -- else
  44.             -- valStr = "false"
  45.         -- end
  46.     -- elseif valType == "function" then
  47.         -- valStr = "function()"
  48.     -- else
  49.     end
  50.     return valStr
  51. end
  52.  
  53.  
  54.  
  55. function writeFileLine(f, msg)
  56.     f:write(msg)
  57.     f:write("\n")
  58.     f:flush()
  59. end
  60.  
  61.  
  62. function widget:Initialize()
  63.     local myOutFile
  64.     myOutFile = io.open("./LuaUI/Widgets/dev_print_unitdefs.lua.txt", "w")
  65.     writeFileLine(myOutFile, "Unit definitions:")
  66.     for id,unitDef in pairs(UnitDefs) do
  67.         writeFileLine(myOutFile, "id=" .. id .. " {")
  68.         for name,param in unitDef:pairs() do
  69.             writeFileLine(myOutFile, "\t" .. tostring(name) .. "=" .. toStringRecursive(param, 1))
  70.         end
  71.         writeFileLine(myOutFile, "}")
  72.     end
  73.     myOutFile:close()
  74.    
  75.     myOutFile = io.open("./LuaUI/Widgets/dev_print_unitdefs.lua.names.txt", "w")
  76.     writeFileLine(myOutFile, "Unit definitions:")
  77.     for id,unitDef in pairs(UnitDefs) do
  78.         writeFileLine(myOutFile, "id=" .. id .. " {")
  79.         writeFileLine(myOutFile, "\t" .. "name" .. "=" .. unitDef.name)
  80.         writeFileLine(myOutFile, "\t" .. "humanName" .. "=" .. unitDef.humanName)
  81.         writeFileLine(myOutFile, "}")
  82.     end
  83.     myOutFile:close()
  84.     --note: if you have unit name, u can get unitdef with UnitDefNames["unitname"]
  85. end
Advertisement
Add Comment
Please, Sign In to add comment