1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: explosions.lua
-- brief: explosions/*.tdf parser
-- author: Dave Rodgers
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local explosionDefs = {}
local shared = {} -- shared amongst the lua explosiondef enviroments
local preProcFile = 'gamedata/explosions_pre.lua'
local postProcFile = 'gamedata/explosions_post.lua'
local TDF = TDFparser or VFS.Include('gamedata/parse_tdf.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
ExplosionDefs = explosionDefs -- make it global
VFS.Include(preProcFile)
ExplosionDefs = nil
Shared = nil
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- Load the TDF explosiondef files
--
local function ParseColorString(str)
local color = { 1.0, 1.0, 0.8 }
local i = 1
for word in string.gmatch(str, '[^,]+') do
local val = tonumber(word)
if (val) then
color[i] = val
end
i = i + 1
if (i > 3) then
break
end
end
return color
end
local function FixGroundFlashColor(ed)
for spawnName, groundFlash in pairs(ed) do
if ((spawnName == 'groundflash') and (type(groundFlash) == 'table')) then
local colorStr = groundFlash.color
if (type(colorStr) == 'string') then
groundFlash.color = ParseColorString(colorStr)
end
end
end
end
local tdfFiles = VFS.DirList('gamedata/explosions/', '*.tdf')
for _, filename in ipairs(tdfFiles) do
local eds, err = TDF.Parse(filename)
if (eds == nil) then
Spring.Echo('Error parsing ' .. filename .. ': ' .. err)
else
for name, ed in pairs(eds) do
ed.filename = filename
explosionDefs[name] = ed
FixGroundFlashColor(ed)
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- Load the raw LUA format explosiondef files
-- (these will override the TDF versions)
--
local luaFiles = VFS.DirList('gamedata/explosions', '*.lua')
for _, filename in ipairs(luaFiles) do
local edEnv = {}
edEnv._G = edEnv
edEnv.Shared = shared
edEnv.GetFilename = function() return filename end
setmetatable(edEnv, { __index = system })
local success, eds = pcall(VFS.Include, filename, edEnv)
if (not success) then
Spring.Echo('Error parsing ' .. filename .. ': ' .. eds)
elseif (eds == nil) then
Spring.Echo('Missing return table from: ' .. filename)
else
for edName, ed in pairs(eds) do
if ((type(edName) == 'string') and (type(ed) == 'table')) then
ed.filename = filename
explosionDefs[edName] = ed
end
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- Run a post-processing script if one exists
--
if (VFS.FileExists(postProcFile)) then
Shared = shared -- make it global
ExplosionDefs = explosionDefs -- make it global
VFS.Include(postProcFile)
ExplosionDefs = nil
Shared = nil
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
return explosionDefs
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
|