From bd4acb769e46f52c03098e4cd97aae897073002c Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Wed, 27 Nov 2013 09:59:26 +0100 Subject: [gugus] new slipro digits managment --- scripts/gugus/functions.lua | 584 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 584 insertions(+) create mode 100644 scripts/gugus/functions.lua (limited to 'scripts/gugus/functions.lua') diff --git a/scripts/gugus/functions.lua b/scripts/gugus/functions.lua new file mode 100644 index 0000000..81ffcf6 --- /dev/null +++ b/scripts/gugus/functions.lua @@ -0,0 +1,584 @@ +-- ============================================================ +-- Left and Right Panel functions +-- ============================================================ + +--require ("scripts/gugus/sector.lua") + + -------------------------------- + -- 0.0.0:00:0 [0.] 0:00.0.0:0 -- + -- Ll : Lr [0.] Rl . Rr -- + -- L [0.] R -- + -------------------------------- + +mDebug = GetTicks() + +function GetWheelTemp(what) + local sim = GetContextInfo("simulation") + local unit = GetContextInfo("speedmetric") + + local temp = 0 + if what == "wtfl" then temp = GetCarInfo("wheeltempfrontleft") + elseif what == "wtfr" then temp = GetCarInfo("wheeltempfrontright") + elseif what == "wtrr" then temp = GetCarInfo("wheeltemprearright") + elseif what == "wtrl" then temp = GetCarInfo("wheeltemprearleft") + elseif what == "btfl" then temp = GetCarInfo("braketempfrontleft") + elseif what == "btfr" then temp = GetCarInfo("braketempfrontright") + elseif what == "btrr" then temp = GetCarInfo("braketemprearright") + elseif what == "btrl" then temp = GetCarInfo("braketemprearleft") + end + + if isAppRFactor(sim) or sim == "GTR2.exe" then temp = KtoC(temp) end + -- convert from C to K if needed + return GetTemp(temp, unit) +end + +function GetWheelPressure(what) + + local press = 0 + if what == "wpfl" then press = GetCarInfo("wheelpressfrontleft") + elseif what == "wpfr" then press = GetCarInfo("wheelpressfrontright") + elseif what == "wprr" then press = GetCarInfo("wheelpressrearright") + elseif what == "wprl" then press = GetCarInfo("wheelpressrearleft") + end + + return press / 6.88 +end + +function GetString(what, where) + -- where should be one of : L, R, Ll, Lr, Rl, Rr + + local fullSize = false + if where == "R" or where == "L" then fullSize = true end + + local Output = " " + if fullSize then Output = " " end + + -- GENERAL + + -- speed + if what == "speed" then + if fullSize then + Output = string.format(" %3d", GetCarInfo("speed")) + else + Output = string.format("%3d", GetCarInfo("speed")) + end + -- rpm + elseif what == "rpm" then + if fullSize then + Output = string.format(" %5d", GetCarInfo("rpm")) + else + Output = string.format("%5d", GetCarInfo("rpm")) + end + -- gear + elseif what == "gear" then + Output = string.format("%d", GetCarInfo("gear")) + elseif what == "pos" then + Output = string.format("P%02d", GetContextInfo("position")) + -- sector + elseif what == "sector" then + if where == "Ll" or where == "Rl" then + Output = string.format("S%1d ", GetCarInfo("sector")) + elseif where == "Lr" or where == "Rr" then + Output = string.format(" S%1d", GetCarInfo("sector")) + else -- fullSize + Output = string.format(" S%1d ", GetCarInfo("sector")) + end + + -- LAPS + -- laps completed + elseif what == "laps" then + local laps = GetContextInfo("laps") + if fullSize then + Output = string.format("L %3d ", laps) + else + if laps > 99 then + Output = string.format("%03d", laps) + else + Output = string.format("L%02d", laps) + end + end + -- total laps + elseif what == "totallaps" then + local totallaps = GetContextInfo("lapscount") + if fullSize then + if totallaps ~= 0 then + Output = string.format("t %3d ", totallaps) + else + Output = "t -- " + end + else + if totallaps > 99 then + Output = string.format("%03d", totallaps) + elseif totallaps ~= 0 then + Output = string.format("t%02d", totallaps) + else + Output = "t--" + end + end + -- remaining laps + elseif what == "remainlaps" then + tl = GetContextInfo("lapscount") + l = GetContextInfo("laps") + if fullSize then + if tl ~= 0 then + Output = string.format("r %3d ", tl - l) + else + Output = "r -- " + end + else + if tl ~= 0 then + Output = string.format("r%03d", tl - l) + else + Output = "r--" + end + end + + -- FUEL + -- fuel + elseif what == "fuel" then + fuel = GetFuel(GetCarInfo("fuel"), GetContextInfo("speedmetric")) + if fullSize then + if fuel >= 100 then + Output = string.format ( "F. %4d", fuel ) + elseif fuel >= 10 then + Output = string.format ( "F. %2.1f", fuel ) + else + Output = string.format ( "F. %1.1f", fuel ) + end + else + if fuel >= 100 then + -- specific for euro truck :) + if fuel >= 999 then + Output = "999" + else + Output = string.format("%03d", round(fuel) % 1000 ) + end + elseif fuel >= 10 then + Output = string.format("F%2d", math.floor(fuel) ) + elseif fuel >= 1 then + if where == "Rl" then + -- no dot after second digit + Output = string.format("F %d", fuel ) + else + Output = string.format("F%1.1f", fuel ) + end + else + if where == "Lr" then + -- no dot after first digit.. + Output = string.format("F .%d", fuel * 100 ) + else + Output = string.format("F.%02d", fuel * 100 ) + end + end + end + -- remaining laps with fuel + elseif what == "remainlapswithfuel" then + local rl = GetCarInfo("remainlapsintank") + if rl ~= 0 then + if rl > 99 then + Output = "r99" + else + Output = string.format("r%02d", GetCarInfo("remainlapsintank")) + end + else + Output = "r--" + end + + + -- ENGINE TEMP + -- water temp + elseif what == "water" then + wt = GetTemp(GetCarInfo("watertemp"), GetContextInfo("speedmetric")) + if fullSize then + Output = string.format("w %3d°", wt) + else + Output = string.format("%3d", wt) + end + -- oil temp + elseif what == "oil" then + oil = GetTemp(GetCarInfo("oiltemp"), GetContextInfo("speedmetric")) + if fullSize then + Output = string.format("o %3d°", oil) + else + Output = string.format("%3d", oil) + end + + + -- WHEEL TEMP + -- WHEEL PRESS + -- BRAKE TEMP + elseif what == "wtfl" or what == "wtfr" or what == "wtrl" or what == "wtrr" + or what == "btfl" or what == "btfr" or what == "btrl" or what == "btrr" then + if fullSize then + Output = string.format("%s.%3d", what, GetWheelTemp(what)) + else + Output = string.format("%3d", GetWheelTemp(what)) + end + + elseif what == "wpfl" or what == "wpfr" or what == "wprl" or what == "wprr" then + if fullSize then + Output = string.format("%s.%3d", what, GetWheelPressure(what)) + else + Output = string.format("%3d", GetWheelPressure(what)) + end + + -- DISTANCES + -- track size + elseif what == "track" then + track = GetContextInfo("tracksize") / 1000 + if fullSize then + Output = string.format(" %2.3f", track) + else + if track >= 10. then + if where ~= "Rl" then + Output = string.format("%2.1f", track) + else + Output = string.format(" %2d", track) + end + else + if where ~= "Lr" then + Output = string.format("%1.2f", track) + else + Output = string.format(" %1.1f", track) + end + end + end + -- total distance + elseif what == "trip" then + distance = GetContextInfo("lapdistance") / 1000 + if fullSize then + Output = string.format(" %2.3f", distance) + else + if distance >= 10. then + if where ~= "Rl" then + Output = string.format("%2.1f", distance) + else + Output = string.format(" %2d", distance) + end + else + if where ~= "Lr" then + Output = string.format("%1.2f", distance) + else + Output = string.format(" %1.1f", distance) + end + end + end + -- track % + elseif what == "trackpercent" then + track = GetContextInfo("lapdistance") + distance = GetContextInfo("lapdistance") + progress = (distance % track) * 100 / track + if fullSize then + Output = string.format(" %3.1f", progress) + else + Output = string.format("%3d", progress) + end + + -- + -- Formula 1 + -- + -- kers + elseif swValue == 27 then Output = GetCarInfo("kers") + -- kers max + elseif swValue == 28 then Output = GetCarInfo("kersmax") + -- kers percent + elseif swValue == 29 then Output = round(GetCarInfo("kers") * 100 / GetCarInfo("kersmax")) + + -- drs + elseif swValue == 30 then Output = GetCarInfo("drs") + + -- PIT + elseif what == "inpit" then + Output = GetContextInfo("inpits") + -- Safety Car + elseif what == "safetycar" then + Output = GetCarInfo("safetycar") + + end + + return Output +end + +function GetTimeString(what, where) + -- most commonly used vars + local time = nil + local splitTime = false + local Output = " " + + local fullSize = where == "L" or where == "R" + if fullSize then Output = " " end + + -- + -- TIMES + -- + + -- current lap time + if what == "currentlap" then time = GetTimeInfo("laptime") + -- best lap time + elseif what == "bestlaptime" then time = GetTimeInfo("bestlaptime") + -- last lap time + elseif what == "lastlaptime" then time = GetTimeInfo("lastlaptime") + + -- virtual best lap time (best sectors) + elseif what == "virtualbestlap" then + if mBestSectors[1] ~= 0 and mBestSectors[2] ~= 0 and mBestSectors[3] ~= 0 then + time = mBestSectors[1] + mBestSectors[2] + mBestSectors[3] + end + + -- current sector (1, 2 and 3) + elseif what == "currentsector" then + time = GetSectorTime("", 0) + -- previous sector (3, 1 and 2) + elseif what == "lastsector" then + time = GetSectorTime("", -1) + -- previous best sector (3, 1 and 2) + elseif what == "lastsectorbest" then + time = GetSectorTime("BEST", -1) + -- lastlap sector (1, 2 and 3) + elseif what == "lastlapsector" then + time = GetSectorTime("last", 0) + -- bestlap sector (1, 2 and 3) + elseif what == "bestlapsector" then + time = GetSectorTime("best", 0) + -- sector split + elseif what == "bestsector" then + time = GetSectorTime("BEST", 0) + -- sector split + elseif what == "lastsectorsplitVSlast" then + time = GetSectorSplit("last", -1) + splitTime = true + -- best lap sector split + elseif what == "lastsectorsplitVSbestlap" then + time = GetSectorSplit("best", -1) + splitTime = true + -- best sector split + elseif what == "lastsectorsplitVSbest" then + time = GetSectorSplit("BEST", -1) + splitTime = true + + elseif what == "currentsectorsplitVSlast" then + time = GetSectorSplit("last", 0) + splitTime = true + -- best lap sector split + elseif what == "currentsectorsplitVSbestlap" then + time = GetSectorSplit("best", 0) + splitTime = true + -- best sector split + elseif what == "currentsectorsplitVSbest" then + time = GetSectorSplit("BEST", 0) + splitTime = true + + -- real time diff vs best + elseif what == "diffbest" then + time = GetTimeInfo("realdiffbest") + splitTime = true + -- real time diff vs last + elseif what == "difflast" then + time = GetTimeInfo("realdifflast") + splitTime = true + + -- time remaining + elseif what == "timeremaining" then + time = GetTimeInfo("timeremaining") + -- time elapsed + elseif what == "timeelapsed" then + time = GetTimeInfo("timetotalelapsed") + + -- system time + elseif what == "clock" then + time = GetTimeInfo("systemtime") + end + + + if what ~= clock then + Output = TimeToString(time, where, splitTime) + else + local hr, mn, sc, cs, ms = timeDispatcher(time) + Output = string.format( " %2d.%02d ", hr, mn) + end + + if Output == nil then Output = "" end + ticks = GetTicks() + if mDebug ==nil or ticks < mDebug then + if time ~= nil then + if splitTime then + --print ("funct: ".. what.. " ["..where.."] -> " ..time.." =[split]= ".. Output ) + else + --print ("funct: ".. what.. " ["..where.."] -> " ..time.." == ".. Output ) + end + else + + print ("funct: ".. what.. " ["..where.."] -> nil == ".. Output ) + end + mDebug = ticks + 10000 + end + return Output +end + +function GetSectorTime(what, which) + local sector = GetCarInfo("sector") + which + if sector == 0 then sector = 3 end + local time = 0. + + if what == "" and which == 0 then + time = GetTimeInfo("laptime") + if sector == 1 then time = time + elseif sector == 2 then time = time - GetTimeInfo("sector1") + elseif sector == 3 then time = time - GetTimeInfo("sector1") - GetTimeInfo("sector2") + end + elseif what == "BEST" then + time = mBestSectors[sector] + else + GetTimeInfo(string.format("%ssector%d", what, sector)) + end + return time +end + +function GetSectorSplit(what, which) + return GetSectorTime("", which) - GetSectorTime(what, which) +end + +function TimeToString(time, where, splitTime) + + local Output = "000" + if where == "R" or where == "L" then Output = "0.00.000" end + + if time ~= nil then + + local hr = 0 + local mn = 0 + local sc = 0 + local cs = 0 + local ms = 0 + + hr, mn, sc, cs, ms = timeDispatcher(time) + + -- blinking second separator + local dot = "." + local colon = ":" + local min = "'" + --if cs >= 50 then + -- dot = "" + -- colon = "." + -- min = " " + --end + + if splitTime == false then + + if where == "R" or where == "L" then + if hr > 9 then + -- [L] HHH:MM:S + -- [R] HHH.MM:S + Output = string.format("%3d.%02d%s%d", hr, mn, colon, sc/10) + elseif hr > 0 then + if where == "R" then + -- [R] H:MM.SS.m + Output = string.format("%d:%02d%s%02d.%d", hr, mn, sc, cs/10) + else + -- [L] H.MM:SS.m + Output = string.format("%d.%02d:%02d.%d", hr, mn, sc, cs/10) + end + elseif mn > 0 then + --  MM.SS.m + Output = string.format(" %2d.%02d.%d", mn, sc, cs/10) + else + --  SS.mmm + Output = string.format(" %2d.%03d", sc, ms) + end + + else + if hr > 0 then + -- HHh + Output = string.format("%2dh", hr) + elseif mn > 9 then + if where ~= "Rl" then + -- MM.S + Output = string.format("%2d%s%d", mn, dot, sc/10) + else + -- MM' + Output = string.format("%2d%s", mn, min) + end + elseif mn > 0 then + if where ~= "Lr" then + -- M.SS + Output = string.format("%d.%02d", mn, sc) + else + --  M:S + Output = string.format(" %d%s%d", mn, colon, sc) + end + else + if where ~= "Rl" then + -- SS.m + Output = string.format("%2d.%d", sc, cs/10) + else + if sc > 9 then + --  SS + Output = string.format(" %2d", sc) + else + -- S.mm + Output = string.format("%d.%02d", sc, cs) + end + end + end + end + + else + -- splittimes -- + if hr > 0 then + -- -HHhMM + Output = string.format("%3dh%02d", hr, mn) + elseif mn > 0 then + -- -MM.SS.m + Output = string.format("%3d.%02d.%d", mn, sc, cs/10) + else + -- -SS.mmm + Output = string.format("%3d.%03d", sc, ms) + end + + end + + else + + if splitTime == false then + + -- 0.0.0:00:0 [0.] 0:00.0.0:0 -- + if where == "R" then + Output = "-:--.---" + elseif where == "L" then + Output = " -:--.-" + else + if where ~= "Rl" then + Output = "--.-" + else + Output = "-.--" + end + end + + else + -- 0.0.0:00:0 [0.] 0:00.0.0:0 -- + if where == "R" or where == "L" then + Output " --.---" + else + if where ~= "Rl" then + Output "--.-" + else + Output "-.--" + end + end + + end + end + + ticks = GetTicks() + if mDebug ==nil or ticks < mDebug then + if time == nil then time = "NIL" end + if Output == nil then Output = "NIL" end + print ( time .. " [" .. where .. "] " .. Output ) + mDebug = ticks + 10000 + end + + return Output + +end + +print ( "gugus> + switch positions" ) -- cgit v1.2.3