GE Lua Documentation

Press F to search!

getLevels

Definition


-- @/lua/ge/extensions/scenario/scenariosLoader.lua:525

local function getLevels(subdirectory)
  local levelList = core_levels.getLevelNames()
  local levels = {}

  for _, levelName in ipairs(levelList) do
    local path = '/levels/' .. levelName .. '/scenarios/' .. subdirectory
    local foundFiles =  FS:findFiles(path, '*.json', -1, true, false)

    local busScenarios = {}
    for i,filepath in ipairs(foundFiles) do
      local ext = string.match(filepath, "(%.%w+)")
      if ext == '.json' then
        table.insert(busScenarios, filepath)
      end
    end

    -- TODO: make this more generic. Perhaps think about how it can be applied to different "Job" types
    if (#busScenarios > 0) then
      local newLevel = {}
      newLevel.levelName = levelName
      newLevel.levelInfo = jsonReadFile('/levels/'..levelName..'/info.json') -- this contains the level info for the UI!
      newLevel.official = isOfficialContentVPath('/levels/'..levelName..'/info.json')
      newLevel.previews = customPreviewLoader(newLevel, levelName)

      newLevel.scenarios = {}

      -- hardcoded for now...
      local busLineFiles = FS:findFiles('/levels/'.. levelName .. '/buslines/', '*.buslines.json', -1, true, false)
      local routes = {}
      for _, file in pairs(busLineFiles) do
        local busLine = jsonReadFile(file)
        for _, route in pairs(busLine.routes) do
          -- For now we assume there is only one bus scenario therefore
          -- we just use this as a 'template' for each route.
          local scenario = loadScenario(busScenarios[1])
          -- assign scenario name to route direction
          scenario.name = route.routeID .. ' ' .. route.direction
          -- check if starting position for the line exists
          if route.spawnLocation then
            scenario.spawnLocation = route.spawnLocation
          end

          if route.previews then
            scenario.previews ="/levels/".. levelName .."/buslines/" .. route.previews[1]
          end

          if route.vehicle then
            scenario.userSelectedVehicle = route.vehicle
          end

          if route.tasklist then
            scenario.stopCount = 0;
            for _, task in pairs(route.tasklist) do
              scenario.stopCount = scenario.stopCount + 1
            end
          end

          -- scenario.busdriver.simulatePassengers = true
          scenario.busdriver.strictStop = true
          scenario.busdriver.traffic = false
          scenario.busdriver.routeID = route.routeID
          scenario.busdriver.variance = route.variance
          table.insert(newLevel.scenarios, scenario)
        end
      end
      table.insert(levels, newLevel)
    end
  end

  return levels
end

Callers

@/lua/ge/extensions/gameplay/missions/proceduralMissionGenerators/busModeMissions.lua
local function generate()
  local data = scenario_scenariosLoader.getLevels('bus')
  local missions = {}
@/ui/modules/busRoute/busRoute.js

  bngApi.engineLua('scenario_scenariosLoader.getLevels("bus")', function(res) {
    showList(res)