📄 unitdefs.lua
字号:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------- file: unitdefs.lua-- brief: unitdef parser-- author: Dave Rodgers---- Copyright (C) 2007.-- Licensed under the terms of the GNU GPL, v2 or later.------------------------------------------------------------------------------------------------------------------------------------------------------------------local unitDefs = {}local shared = {} -- shared amongst the lua unitdef enviromentslocal preProcFile = 'gamedata/unitdefs_pre.lua'local postProcFile = 'gamedata/unitdefs_post.lua'local FBI = FBIparser or VFS.Include('gamedata/parse_fbi.lua')local TDF = TDFparser or VFS.Include('gamedata/parse_tdf.lua')local DownloadBuilds = VFS.Include('gamedata/download_builds.lua')local system = VFS.Include('gamedata/system.lua')-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Run a pre-processing script if one exists--if (VFS.FileExists(preProcFile)) then Shared = shared -- make it global UnitDefs = unitDefs -- make it global VFS.Include(preProcFile) UnitDefs = nil Shared = nilend-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Load the FBI/SWU unitdef files--local fbiFiles = {}do fbiFiles = VFS.DirList('units/', '*.fbi') local swus = VFS.DirList('units/', '*.swu') for _, f in ipairs(swus) do table.insert(fbiFiles, f) endendfor _, filename in ipairs(fbiFiles) do local ud, err = FBI.Parse(filename) if (ud == nil) then Spring.Echo('Error parsing ' .. filename .. ': ' .. err) elseif (ud.unitname == nil) then Spring.Echo('Missing unitName in ' .. filename) else ud.filename = filename ud.unitname = string.lower(ud.unitname) unitDefs[ud.unitname] = ud endend-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Load the raw LUA format unitdef files-- (these will override the FBI/SWU versions)--local luaFiles = VFS.DirList('units/', '*.lua')for _, filename in ipairs(luaFiles) do local udEnv = {} udEnv._G = udEnv udEnv.Shared = shared udEnv.GetFilename = function() return filename end setmetatable(udEnv, { __index = system }) local success, uds = pcall(VFS.Include, filename, udEnv) if (not success) then Spring.Echo('Error parsing ' .. filename .. ': ' .. uds) elseif (type(uds) ~= 'table') then Spring.Echo('Bad return table from: ' .. filename) else for udName, ud in pairs(uds) do if ((type(udName) == 'string') and (type(ud) == 'table')) then ud.filename = filename unitDefs[udName] = ud else Spring.Echo('Bad return table entry from: ' .. filename) end end end end-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Insert the download build entries--DownloadBuilds.Execute(unitDefs)-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Run a post-processing script if one exists--if (VFS.FileExists(postProcFile)) then Shared = shared -- make it global UnitDefs = unitDefs -- make it global VFS.Include(postProcFile) UnitDefs = nil Shared = nilend-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Basic checks to kill unitDefs that will crash ".give all"--for name, def in pairs(unitDefs) do local cob = 'scripts/' .. name .. '.cob' if (not VFS.FileExists(cob)) then unitDefs[name] = nil Spring.Echo('WARNING: removed ' .. name .. ' unitDef, missing cob script') end local obj = def.objectname if (obj == nil) then unitDefs[name] = nil Spring.Echo('WARNING: removed ' .. name .. ' unitDef, missing objectname param') for k,v in pairs(def) do print('',k,v) end else local objfile = 'objects3d/' .. obj if ((not VFS.FileExists(objfile)) and (not VFS.FileExists(objfile .. '.3do')) and (not VFS.FileExists(objfile .. '.s3o'))) then unitDefs[name] = nil Spring.Echo('WARNING: removed ' .. name .. ' unitDef, missing model file (' .. obj .. ')') end endendfor name, def in pairs(unitDefs) do local badOptions = {} local buildOptions = def.buildoptions if (buildOptions) then for i, option in ipairs(buildOptions) do if (unitDefs[option] == nil) then table.insert(badOptions, i) Spring.Echo('WARNING: removed the "' .. option ..'" entry' .. ' from the "' .. name .. '" build menu') end end if (#badOptions > 0) then local removed = 0 for _, badIndex in ipairs(badOptions) do table.remove(buildOptions, badIndex - removed) removed = removed + 1 end end endend----------------------------------------------------------------------------------------------------------------------------------------------------------------return unitDefs----------------------------------------------------------------------------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -