Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:TrackInfobox: Difference between revisions

From Trackmania Wiki
Created page with "-- Module:TrackInfobox local p = {} local function safe(s) if not s then return '' end return mw.html.escape(tostring(s)) end function p.formatWR(frame) -- args: time_ms, player, fallback local time_ms = frame.args[1] or '' local player = frame.args[2] or '' local fallback = frame.args[3] or '' if time_ms == '' or time_ms == nil then if fallback ~= '' then return fallback end return 'Unknown' end local ms = tonumber(time_ms) if not ms then..."
(No difference)

Revision as of 12:24, 14 August 2025

Documentation for this module may be created at Module:TrackInfobox/doc

-- Module:TrackInfobox
local p = {}

local function safe(s)
  if not s then return '' end
  return mw.html.escape(tostring(s))
end

function p.formatWR(frame)
  -- args: time_ms, player, fallback
  local time_ms = frame.args[1] or ''
  local player = frame.args[2] or ''
  local fallback = frame.args[3] or ''

  if time_ms == '' or time_ms == nil then
    if fallback ~= '' then return fallback end
    return 'Unknown'
  end

  local ms = tonumber(time_ms)
  if not ms then
    if fallback ~= '' then return fallback end
    return 'Unknown'
  end

  local total_seconds = ms / 1000
  local mins = math.floor(total_seconds / 60)
  local secs = total_seconds - mins * 60
  local time_str = string.format("%d:%06.2f", mins, secs)

  if player ~= '' then
    return time_str .. ' by ' .. safe(player)
  else
    return time_str
  end
end

return p