getTracks
Definition
-- @/lua/ge/extensions/scenario/quickRaceLoader.lua:339
-- this function parses the quickrace files, and returns a list of all tracks for one level.
local function getTracks(quickraceFiles, levelName, lvlName)
local tracks = {}
local procedurals = lvlName == "driver_training"
for _, trackFile in ipairs(quickraceFiles) do
local dir, filename, ext = path.split(trackFile, true)
if ext == 'json' or ext == 'race.json' then
local file = jsonReadFile(trackFile)
if not file then
log('E', 'failed to load this track ' , tostring(trackFile).. ' Check Json file')
elseif procedurals ~= not file.procedural then -- no this cannot be changed to procedurals == file.procedural, becaus then false == nil -> false
file.originalInfo = deepcopy(file)
file.sourceFile = trackFile
--file.ignoreAsMission = true
local dir, filename, ext = path.splitWithoutExt(trackFile, true)
file.trackName = filename
file.directory = dir
--file.raceFile = "/levels/"..levelName.."/quickrace/"..file.trackName..'.json'
file.difficulty = file.difficulty and tonumber(file.difficulty) or nil
file.prefabs = file.prefabs or {}
file.reversePrefabs = file.reversePrefabs or {}
file.forwardPrefabs = file.forwardPrefabs or {}
file.customMarker = 'default'
file.raceFile = ext == 'race.json' and trackFile or nil--FS:findFilesByRootPattern(file.directory, file.trackName..'.race.json', 0, true, false)
local officialPath = trackFile
file.official = FS:fileExists(officialPath) and isOfficialContentVPath(officialPath)
if file.luaFile then
file.luaFile = "/levels/"..levelName.."/quickrace/"..file.luaFile
else
file.luaFile = nil
end
if file.procedural then
file.customData.seed = math.random(500*500*500*500)
file.ignoreAsMission = true
end
-- find preview for forward and reverse
local tmp = FS:findFiles(file.directory, file.trackName..'.jpg', 0, true, false)
file.previews = {}
for _, p in pairs(tmp) do
table.insert(file.previews, p)
end
local tmp = FS:findFiles(file.directory, file.trackName..'_reverse.jpg', 0, true, false)
file.reversePreviews = {}
for _, p in pairs(tmp) do
table.insert(file.reversePreviews, p)
end
-- set spawnSpheres.
if not file.spawnSpheres then
file.spawnSpheres = {}
end
if not file.closed then
file.lapCount = 1
end
file.lapCount = file.lapCount or 1
file.spawnSpheres.standing = file.spawnSpheres.standing or file.trackName.."_standing_spawn"
file.spawnSpheres.standingReverse = file.spawnSpheres.standingReverse or file.trackName.."_standingReverse_spawn"
file.spawnSpheres.rolling = file.spawnSpheres.rolling or file.trackName.."_rolling_spawn"
file.spawnSpheres.rollingReverse = file.spawnSpheres.rollingReverse or file.trackName.."_rollingReverse_spawn"
file.tod = file.tod or 3
-- figure out if a html start file is existing
local htmldiscovered = false
if not file.startHTML then
file.startHTML = "quickrace/"..file.trackName .. '.html'
htmldiscovered = true
end
if not FS:fileExists("/levels/"..levelName..'/'..file.startHTML) then
if not htmldiscovered then
log('W', 'scenarios', 'start html not found, disabled: ' .. file.startHTML)
end
file.startHTML = nil
file.introType = 'none'
end
if not file.introType then
file.introType = 'htmlOnly'
end
if file.raceFile then
if file.classification then
file.lapCount = file.defaultLaps
file.closed = file.classification.closed
file.allowRollingStart = file.classification.allowRollingStart
file.reversible = file.classification.reversible
end
file.lapConfig = {}
file.startLineCheckpoint = ''
end
table.insert(tracks, file)
end
end
end
table.sort(tracks, function(a,b) return a.name < b.name end)
return tracks
end
Callers
@/lua/ge/extensions/scenario/quickRaceLoader.lua
--else
newLevel.tracks = M.getTracks(quickraceFiles, levelName, newLevel.levelName)
--end