Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widget:GetInfo()
- return {
- name = "zzz print unitdefs",
- desc = "write to file unit definitions",
- author = "Svatopluk",
- date = "11/12/2015",
- license = "Hail Svatopluk 3x",
- layer = 100,
- enabled = true -- loaded by default?
- }
- end
- -- local function repeatString(str, times)
- -- local result = ""
- -- local i=1
- -- while i < level do
- -- result = result .. str
- -- i = i + 1
- -- end
- -- return result
- -- end
- local function toStringRecursive(value, level)
- local valType = type(value)
- local valStr = ""
- if valType == "table" then
- valStr = "table {\n"
- for tableKey,tableValue in pairs(value) do
- valStr = valStr .. string.rep("\t", level + 1) .. tostring(tableKey) .. "=" .. toStringRecursive(tableValue, level + 1) .. "\n"
- end
- valStr = valStr.. string.rep("\t", level) .. "}"
- else
- valStr = tostring(value)
- -- valStr = "other (type " .. valType .. ")"if valType == "string" then
- -- valStr = value
- -- elseif valType == "number" then
- -- valStr = "" .. value
- -- elseif valType == "boolean" then
- -- if value == true then
- -- valStr = "true"
- -- else
- -- valStr = "false"
- -- end
- -- elseif valType == "function" then
- -- valStr = "function()"
- -- else
- end
- return valStr
- end
- function writeFileLine(f, msg)
- f:write(msg)
- f:write("\n")
- f:flush()
- end
- function widget:Initialize()
- local myOutFile
- myOutFile = io.open("./LuaUI/Widgets/dev_print_unitdefs.lua.txt", "w")
- writeFileLine(myOutFile, "Unit definitions:")
- for id,unitDef in pairs(UnitDefs) do
- writeFileLine(myOutFile, "id=" .. id .. " {")
- for name,param in unitDef:pairs() do
- writeFileLine(myOutFile, "\t" .. tostring(name) .. "=" .. toStringRecursive(param, 1))
- end
- writeFileLine(myOutFile, "}")
- end
- myOutFile:close()
- myOutFile = io.open("./LuaUI/Widgets/dev_print_unitdefs.lua.names.txt", "w")
- writeFileLine(myOutFile, "Unit definitions:")
- for id,unitDef in pairs(UnitDefs) do
- writeFileLine(myOutFile, "id=" .. id .. " {")
- writeFileLine(myOutFile, "\t" .. "name" .. "=" .. unitDef.name)
- writeFileLine(myOutFile, "\t" .. "humanName" .. "=" .. unitDef.humanName)
- writeFileLine(myOutFile, "}")
- end
- myOutFile:close()
- --note: if you have unit name, u can get unitdef with UnitDefNames["unitname"]
- end
Advertisement
Add Comment
Please, Sign In to add comment