Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.
Users reporting for no reason may be locked out.
using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Collections.Generic;
namespace Scripts
{
public class FastLapTracker : IScript
{
private Dictionary<byte, ILap> _fastlaps = new Dictionary<byte, ILap>();
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Loop over every entity session result and check for fastest lap in class
foreach (var result in sim.Session.Current.Results)
{
// Get the class ID of this driver
var classId = result.Entity.Car.Class.Id;
// Get the currently recorded fastest lap for this driver's class
// Note: the lap may not exist yet, in that case we add an entry for this class but keep the lap as null.
ILap currentFastLap = null;
if (_fastlaps.ContainsKey(classId))
currentFastLap = _fastlaps[classId];
else
_fastlaps.Add(classId, null);
// Get fastest lap of this driver
var lap = result.FastestLap;
// Check if the driver fastlap is faster than the currently stored fast lap
// if there is no lap stored, this is a new lap and we consider it the fastest lap so far
if (currentFastLap == null || currentFastLap.Time > lap.Time)
{
// "lap" is the newest fast lap of this class
// Replace it as the latest fast lap
_fastlaps[classId] = lap;
// Now trigger whatever you want to do, e.g. show a widget.
TriggerFastLap(item.Theme, result, lap);
}
}
}
private void TriggerFastLap(ITheme theme, IEntitySessionResult result, ILap lap)
{
// Just an example: find a widget named after the class ID
var classId = result.Entity.Car.Class.Id;
var widgetName = "Wigdet_Fastlap_Class" + classId;
var widget = theme.Widgets.Find(widgetName);
if (widget != null)
{
widget.Show();
// Maybe start a timer that hides all fastlap widgets after few seconds
var timer = theme.Timers.Find("FastLapHideTimer");
timer.Start();
}
else
{
// Log that this widget doesnt exist
Console.WriteLine("Failed to find widget " + widgetName);
}
}
}
}