using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Controls;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class Script : IScript
{
int[] PointStructure = new int[] { 0, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;
var pos = result.LivePosition;
int CurrentPoints = PointStructure[pos];
if (result.LivePosition == 0)
{
return "0";
}
//Lap Led Point
if (result.LapsLed > 0)
{
CurrentPoints++;
}
//Pole Position Point
if (result.StartPosition == 1)
{
CurrentPoints++;
}
//Winner Point
if (result.LivePosition == 1)
{
CurrentPoints++;
}
return CurrentPoints;
}
}
}
var text = label.DisplayText;
var number = int.Parse(text);
var theme = item.Theme;
var label = theme.Widgets.Find("MyWidget1").SubWidgets.Find("MySubWidget2").Labels.Find("TargetLabelName");
If it's a label in a Ticker it is more difficult. In that case it's probably easier to grab the reference to the Spreadsheet object (either the source file itself or if you've added it to the Theme you can get the Spreadsheet theme item).
var results = sim.Session.Current?.Results;
var sorted = results?.OrderBy(r => r.LapsLed)?.ToList();
if (sorted != null && sorted.Count > 0)
{
var most = sorted[0];
// Do what you want with this result
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Controls;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;
using ATVO.ThemesSDK.Data.Results;
using System.Linq;
using System.Data;
using System.Collections.Generic;
namespace Scripts
{
public class Script : IScript
{
ChampDriver driver;
int[] PointStructure = new int[] { 0, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
private Dictionary<int, ChampDriver> _standings = new Dictionary<int, ChampDriver>();
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
UpdateSessionStandings(sim);
LoadStandings(item.Theme);
IEntitySessionResult result = (IEntitySessionResult) value;
var pos = result.LivePosition;
int CurrentPoints = PointStructure[pos];
//Lap Led Point
if (result.LapsLed > 0)
{
CurrentPoints++;
}
//Pole Position Point
if (result.StartPosition == 1)
{
CurrentPoints++;
}
//Winner Point
if (result.LivePosition == 1)
{
CurrentPoints++;
}
int TotalPoints = CurrentPoints + driver.ChampPoints;
return TotalPoints;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
private void LoadStandings(Theme theme)
{
if (_standings.Count == 0)
{
// Read current standings from embedded csv
// Columns: customer_id, position, carnumber, drivername, points
var sheet = theme.Spreadsheets.Find("Champ_Standings.csv");
foreach (var row in sheet.Table.Data.Rows.OfType<DataRow>())
{
var custid = row[1];
var position = row[0];
var carnum = row[11];
var name = row[2];
var points = row[9];
var driver = new ChampDriver();
driver.CustomerId = Convert.ToInt32(custid);
driver.ChampPosition = Convert.ToInt32(position);
driver.CarNumber = carnum.ToString();
driver.Name = name.ToString();
driver.ChampPoints = Convert.ToInt32(points);
_standings.Add(driver.CustomerId, driver);
}
}
}
private void UpdateSessionStandings(ISimulation sim)
{
// Loop through entity results in the session and update the standings
foreach (var result in sim.Session.Current.Results)
{
// Check if there is a driver in the session who was NOT in the standings csv
if (!_standings.ContainsKey(result.Entity.Id))
{
// This driver isn't in the standings yet, let's add him
driver = new ChampDriver();
driver.CustomerId = result.Entity.Id;
driver.Name = result.Entity.Name;
driver.CarNumber = result.Entity.Car.Number;
driver.ChampPoints = 0;
_standings.Add(driver.CustomerId, driver);
}
else
{
// Otherwise, grab him from memory
driver = _standings[result.Entity.Id];
}
// Link him to the session entity
driver.Entity = result.Entity;
}
}
public class ChampDriver
{
public IEntity Entity {get;set;}
public int CustomerId {get;set;}
public string CarNumber {get;set;}
public string Name {get;set;}
public int ChampPosition {get;set;}
public int ChampPoints {get;set;}
public int LiveChampPosition {get;set;}
public int LiveChampPoints {get;set;}
}
}
}