#Conditional Hooks

$Application: FS2_Open
$On Game Init:
[
include("particleScript.lua")
]

$On Mission Start:
[
particleTrailScript:parseConfigFiles()
]

$State: GS_STATE_GAME_PLAY

$On HUD Draw:
[
--local display = hv.Player.CockpitDisplays["mainScreen"]
--if (display:isValid() and display:startRendering():isValid()) then
--    local x1, y1 = display:getOffset()
--    local width, height = display:getSize()
--
--    gr.setClip(x1, y1, width, height)
--
--    gr.setColor(0, 0, 0)
--    gr.drawRectangle(x1, y1, x1 + width, y1 + height, true)
--
--    gr.setColor(0, 255, 0, 255)
--
--    local time = mn.getMissionTime()
--
--    local secs = math.floor(time % 60)
--    local mins = math.floor((time - secs) / 60)
--    local msecs = (time - math.floor(time)) * 1000
--
--    local text = string.format("%02d:%02d.%03d", mins, secs, msecs)
--
--    local x = ((width - gr.getStringWidth(text)) / 2) + x1
--    local y = ((height - gr.CurrentFont.Height) / 2) + y1
----
----    gr.drawString(text, x, y)
--
--    gr.drawRectangle(x, y, x + gr.getStringWidth(text), y + gr.CurrentFont.Height)
--
--    gr.resetClip()
--    display:stopRendering()
--else
--    gr.setColor(255, 0, 0, 200)
--    gr.drawString("Failed to start display rendering!", 100, 300)
--end
]

$State: GS_STATE_GAME_PLAY
$On Frame:
[
if (type(particleFred) == "table") then
	particleFred:onFrame(time)
end

if (not particleTrailScript:shouldExecute()) then
	return
end

local time = ba.getFrametime()

local shouldSpawn = particleTrailScript:shouldSpawnNewParticles(ba.getFrametime(false))

particleTrailScript:doNormalInfoRun(time, shouldSpawn)

particleTrailScript:doObjectInfoRun(time, shouldSpawn)
]

$On Mission End:
[
particleTrailScript:resetTable()
]

#End
