GE Lua Documentation

Press F to search!

saveDialTimes

Definition


-- @/lua/ge/extensions/gameplay/drag/saveSystem.lua:258

M.saveDialTimes = function(dragData, timeslip)
  -- Save dial times and history in one file
  -- Structure: { "configHash": { time_1_4: number, history: [full timeslip entries...] } }
  if not dragData or not dragData.racers then
    log('E', logTag, 'No drag data or racers to save dial times')
    return
  end

  local filePath = "settings/dragDialTimes.json"
  local dialTimes = jsonReadFile(filePath) or {}

  for vehId, racer in pairs(dragData.racers) do
    if racer.timers and racer.timers.time_1_4 and racer.isPlayable then
      local timesKey = M.generateHashFromFile(vehId)

      local currentTime = racer.timers.time_1_4.value or 10

      -- Initialize entry if it doesn't exist or migrate old format
      if not dialTimes[timesKey] then
        dialTimes[timesKey] = {
          time_1_4 = currentTime,
          history = {}
        }
      elseif not dialTimes[timesKey].history then
        -- Migrate old format entries that only have time_1_4
        dialTimes[timesKey].history = {}
      end

      -- Update best time if this is faster
      if currentTime < dialTimes[timesKey].time_1_4 then
        dialTimes[timesKey].time_1_4 = currentTime
      end

      -- Add full timeslip entry to history if provided
      if timeslip then
        local historyEntry = deepcopy(timeslip)
        historyEntry.stripId = dragData.strip and dragData.strip.id or "unknown"
        if timeslip.stripInfo and timeslip.stripInfo.tree then
          historyEntry.tree = timeslip.stripInfo.tree
        end

        -- Add config hash for each racer
        if historyEntry.racerInfos and dragData.racers then
          for i, racerInfo in ipairs(historyEntry.racerInfos) do
            for rVehId, rRacer in pairs(dragData.racers) do
              if rRacer.lane == racerInfo.laneNum then
                racerInfo.configHash = M.generateHashFromFile(rVehId)
                break
              end
            end
          end
        end

        table.insert(dialTimes[timesKey].history, historyEntry)
      end
    end
  end

  jsonWriteFile(filePath, dialTimes, true)
end

Callers

@/lua/ge/extensions/gameplay/drag/general.lua

local function saveDialTimes(timeslip)
  if dragData then
  if dragData then
    gameplay_drag_saveSystem.saveDialTimes(dragData, timeslip)
  end

  M.saveDialTimes(slipData)
  guihooks.trigger("onDragRaceTimeslipData", slipData)
@/lua/ge/extensions/gameplay/drag/utils.lua
    if racer.isPlayable then
      gameplay_drag_general.saveDialTimes()
    end