User:Oflameo/Sandbox

From Zero-K
Jump to navigation Jump to search
factorycloak.pngCloakbot Factory
Name Role Aliases Cost HP
cloakcon.png Conjurer Construction 120 450
cloakraid.png Glaive Raider 65 200
cloakheavyraid.png Scythe Raider 250 820
cloakskirm.png Ronin Skirmisher 90 420
cloakriot.png Reaver Riot 220 820
cloakassault.png Knight Assault 350 2400
cloakarty.png Sling Artillery 110 350
cloaksnipe.png Phantom Artillery 750 560
cloakaa.png Gremlin Anti-Air 150 550
cloakbomb.png Imp Bomb 120 50
cloakjammer.png Iris Other 600 600

Lua widget code to generate:

local fileOutputDir = "temp/"

local function getDescString(unitDef)
	local desc = Spring.Utilities.GetDescription(unitDef)
	if desc:find("Raider") then
		return "Raider"
	elseif desc:find("Riot") then
		return "Riot"
	elseif desc:find("Skirmisher") then
		return "Skirmisher"
	elseif desc:find("Assault") then
		return "Assault"
	elseif desc:find("Artillery") then
		return "Artillery"
	elseif desc:find("Anti%-Air") then
		return "Anti-Air"
	elseif desc:find("Construction") then
		return "Construction"
	elseif desc:find("Scout") then
		return "Scout"
	elseif desc:find("Support") then
		return "Support"
	elseif desc:find("Anti-Heavy") then
		return "Anti-Heavy"
	elseif desc:find("Fighter") then
		return "Fighter"
	elseif desc:find("Bomber") then
		return "Bomber"
	elseif desc:find("Transport") then
		return "Transport"
	elseif desc:find("Bomb") then
		return "Bomb"
	else
		return "Other"
	end
end

local function generateTable(factoryDefName)
	local factoryDef = UnitDefNames[factoryDefName]

	local output = '{| class="wikitable" style="text-align:center;"\n'
	local imagePath = "http://manual.zero-k.info/unitpics/" .. factoryDefName .. ".png"
	output = output .. '! colspan="7" | ' .. imagePath .. "[[" .. factoryDef.humanName .. "]]\n"
	output = output .. "|-\n"
	output = output .. '! || Name || colspan="2" | Role || Aliases || Cost || HP\n'
	output = output .. "|-\n"
	
	for index, unitDefID in ipairs(factoryDef.buildOptions) do
		local unitDef = UnitDefs[unitDefID]
		local unitName = unitDef.name
		imagePath = "http://manual.zero-k.info/unitpics/" .. unitName .. ".png"
		local icon = '<img src="http://manual.zero-k.info/icons/' .. unitDef.iconType .. '.png" width="32px" />'
		output = output .. "| " .. imagePath .. " || [[" .. unitDef.humanName .. "]] || " 
			.. icon .. " || " .. getDescString(unitDef) .. " ||  || " .. unitDef.metalCost .. " || " 
			.. unitDef.health .. "\n"
		output = output .. "|-\n"
	end
	
	output = output .. "|}"
	
	return output
end

local function printTable(factoryDefName, outputDir)
	local str = generateTable(factoryDefName)
	local file = io.open (outputDir .. "/" .. factoryDefName .. ".txt", "w")
	if (file== nil) then Spring.Echo ("could not open file for writing!") return end
	file:write(str)
	file:flush()
	file:close()
end

function widget:Initialize()
	printTable("factorycloak", fileOutputDir)
end