GE Lua Documentation

Press F to search!

getLevelPreview

Definition


-- @/lua/ge/extensions/core/levels.lua:261

local function getLevelPreview(levelName)
  if not levelName then
    return nil
  end

  local lowerLevelName = string.lower(levelName)

  -- Check cache first
  if previewCache[lowerLevelName] then
    return previewCache[lowerLevelName]
  end

  -- Find the level and get its default preview
  local level = getLevelByName(levelName)
  if level then
    local preview = nil
    if type(level.previews) == 'table' and #level.previews > 0 then
      preview = level.previews[1] -- Get the first preview
    end
    previewCache[lowerLevelName] = preview
    print(string.format("getLevelPreview: %s -> %s", levelName, preview or "nil"))
    return preview
  end

  -- Level not found, cache nil to avoid repeated lookups
  previewCache[lowerLevelName] = nil
  print(string.format("getLevelPreview: %s -> nil", levelName))
  return nil
end

Callers