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
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "entitysessionresult_obj" to get the IEntitySessionResult as the value
// Cast to IEntitySessionResult type
IEntitySessionResult result = (IEntitySessionResult) value;
if (value == null)
{
// do something appropriate, in this case probably just return nothing
return null;
}
var flags = result.Session.Flags;
var type = result.Session.Type;
var gap = result.LiveClassGap;
var pos = result.LiveClassPosition;
var best = result.FastestLapTime;
var min = 0;
float sectime;
var laps = result.LiveClassGapLaps;
if (type == SessionType.Practice)
{
if (best > 60)
{
min = (int) (best / 60);
sectime = best % 60;
return min + ":" + sectime.ToString("00.000");
}
if (best != 0.000)
{
return best.ToString("0.000");
}
else
return ("");
}
if (type == SessionType.Qualify)
{
if (best > 60)
{
min = (int) (best / 60);
sectime = best % 60;
return min + ":" + sectime.ToString("00.000");
}
if (best != 0.000)
{
return best.ToString("0.000");
}
else
return ("");
}
if (type == SessionType.Race)
{
if (result.DidNotStart)
return "DNS ";
if (result.Out)
return "OUT ";
if (result.LiveGap == 0.000 && pos != 1)
return "";
if (flags.HasFlag(SessionFlags.Caution) || flags.HasFlag(SessionFlags.CautionWaving))
return "";
if (result.Finished && pos == 1)
return gap.ToString("WIN ");
if (result.Finished && pos != 1)
return gap.ToString("0.000");
// Optional: there is no gap for P1 so show nothing
if (pos == 1)
return "LDR ";
// If car is lapped AND this is a race session,
// then show nr of gap laps instead of gap time
if (laps > 0 && type == SessionType.Race)
{
if (laps == 1)
return "-1 Lap"; // to avoid incorrect "1 Laps"
else
return -laps + " Laps";
}
if (result.Entity?.Car?.Movement?.IsInPits == true && type == SessionType.Race)
return "PIT ";
else
return gap.ToString("-0.000");
}
else
return "";
}
}
}
if (value is IEntitySessionResult)
{
var result = (IEntitySessionResult)value;
// continue
}
else
{
return "";
}
var result = value as IEntitySessionResult;
if (result == null)
{
return "";
}
// continue
if (value is IEntitySessionResult result)
{
// continue
}
else
{
return "";
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Windows.Media;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class SC_ClassColor : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
if (value == null)
{
// do something appropriate, in this case probably just return nothing
return null;
}
//IEntitySessionResult result = (IEntitySessionResult) value;
//var Classcolor = result.Entity.Car.Class.Color;
var Classcolor = value.ToString();
var numClasses = sim.Session.ClassManager.Classes.Count;
var hex = "#ffe617";
if (numClasses == 1)
return (Color) ColorConverter.ConvertFromString(hex);
else
return (Color) ColorConverter.ConvertFromString(Classcolor);
}
}
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using ATVO.ThemesSDK.Data.Entity;
using System.Drawing;
using System.Windows;
namespace Scripts
{
public class SC_Stand_Name_TD : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{ if (value == null)
{
// do something appropriate, in this case probably just return nothing
return null;
}
// If you bind to 'entitysessionresult_object':
var result = (IEntitySessionResult)value;
var entity = result.Entity;
var sname = result.Entity.Drivers[0].ShortName;
//var id = entity.Id;
var name = entity.Name;
int nameL = name.Length;
if (nameL < 5)
{name = name+" ";
nameL = name.Length;}
var first = name.Substring(0,4);
int temp = nameL - 4;
int temp1 = nameL - 5;
var end = name.Substring(temp,4);
// If it's a team session:
// - id will be Team ID, name will be Team name
// If it's a single driver session:
// - id will be driver customer ID, name will be driver name
if (entity is ITeam)
{
if (first == "Team" || first == "TEAM" || first == "team")
name = name.Substring(5,temp1);
nameL = name.Length;
if (end == "Team" || end == "TEAM" || end == "team")
name = name.Substring(0,temp1);
nameL = name.Length;
if (nameL > 20)
name = name.Substring(0,20);
return name;
//if (nameL > 25 && first == "Team" || first == "TEAM" || first == "team")
//return name.Substring(5,19);
//return name;
//if (first == "Team" || first == "TEAM" || first == "team")
//return name.Substring(5,temp1);
//if (nameL > 25 && end == "Team" || end == "TEAM" || end == "team")
//return name.Substring(0,19)+nameL;
//if (end == "Team" || end == "TEAM" || end == "team")
//return name.Substring(0,temp1 + nameL);
//else
//return name;
}
return sname;
}
}
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using ATVO.ThemesSDK.Data.Entity;
using System.Drawing;
using System.Windows;
namespace Scripts
{
public class SC_Stand_FontSize : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{ if (value == null)
{
// do something appropriate, in this case probably just return nothing
return null;
}
// If you bind to 'entitysessionresult_object':
var result = (IEntitySessionResult)value;
var entity = result.Entity;
// If it's a team session:
// - id will be Team ID, name will be Team name
// If it's a single driver session:
// - id will be driver customer ID, name will be driver name
if (entity is ITeam)
{
return 17;
}
return 24;
}
}
}
Emmanuel Suter wrote:
I think i've got the same problem on a lot of my scripts ....
To understand, you replaceIEntitySessionResult result = (IEntitySessionResult) value;
byvar result = value as IEntitySessionResult;
if (result == null)
{
return "";
}
??