Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Dec 6, 2018
1 parent 5372072 commit 7b42699
Show file tree
Hide file tree
Showing 42 changed files with 1,007 additions and 478 deletions.
1 change: 0 additions & 1 deletion AcManager.Controls/AcListPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down
7 changes: 5 additions & 2 deletions AcManager.Controls/Assets/AcItemWrapperSpecific.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@
<c:RatingBar DockPanel.Dock="Right" Rating="{Binding Rating}" x:Name="PART_RatingIcon" VerticalAlignment="Center" Margin="0 0 4 0"
Style="{StaticResource CompactRatingBar.ReadOnly}" />

<mui:BbCodeBlock TextWrapping="NoWrap" Text="{Binding DisplayName}" Mode="WithoutBbCodes" Margin="10 2 4 2"
FontSize="{DynamicResource SmallFontSize}" TextTrimming="CharacterEllipsis" HorizontalAlignment="Stretch" x:Name="PART_DisplayNameText" />
<mui:BbCodeBlock TextWrapping="NoWrap" Text="{Binding DisplayName}" Mode="WithoutBbCodes" Margin="10 2 4 2" TextTrimming="CharacterEllipsis"
HorizontalAlignment="Stretch" x:Name="PART_DisplayNameText" ToolTip="{Binding DisplayName}" DockPanel.Dock="Top" />
<mui:BbCodeBlock TextWrapping="NoWrap" Text="{Binding ManagerDescription}" Mode="WithoutBbCodes" Margin="10 2 4 2"
FontSize="{DynamicResource SmallFontSize}" TextTrimming="CharacterEllipsis" HorizontalAlignment="Stretch" FontWeight="Normal"
ToolTip="{Binding ManagerDescription}" />
</DockPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Enabled}" Value="False">
Expand Down
8 changes: 8 additions & 0 deletions AcManager.Tools/AcManager.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@
<Compile Include="Helpers\SettingEntry.cs" />
<Compile Include="Helpers\SharpCompressExtension.cs" />
<Compile Include="Helpers\TemperatureUnitMode.cs" />
<Compile Include="Helpers\Tyres\TyresAppropriateLevel.cs" />
<Compile Include="Helpers\Tyres\TyresEntry.cs" />
<Compile Include="Helpers\Tyres\TyresEntryTester.cs" />
<Compile Include="Helpers\Tyres\TyresExtension.cs" />
<Compile Include="Helpers\Tyres\TyresPlace.cs" />
<Compile Include="Helpers\Tyres\TyresSet.cs" />
<Compile Include="Helpers\Vdf.cs" />
<Compile Include="Helpers\VisualCppTool.cs" />
<Compile Include="Helpers\WebBrowserHelper.cs" />
Expand Down Expand Up @@ -512,6 +518,8 @@
<Compile Include="Objects\RemoteCarSetupObject.cs" />
<Compile Include="Objects\ServerPresetDetailsMode.cs" />
<Compile Include="Objects\ServerPresetObject.Ftp.cs" />
<Compile Include="Objects\ServerPresetObject.LegalTyres.cs" />
<Compile Include="Objects\ServerPresetObject.Setups.cs" />
<Compile Include="Objects\TrackObject.Extra.cs" />
<Compile Include="Objects\TrackObject.Skins.cs" />
<Compile Include="Objects\CarObject.Stats.cs" />
Expand Down
12 changes: 6 additions & 6 deletions AcManager.Tools/Helpers/AcSettings/VideoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ public bool Fullscreen {
}
}

private bool _verticalSyncronization;
private bool _verticalSynchronization;

public bool VerticalSyncronization {
get => _verticalSyncronization;
set => Apply(value, ref _verticalSyncronization);
public bool VerticalSynchronization {
get => _verticalSynchronization;
set => Apply(value, ref _verticalSynchronization);
}

private bool _framerateLimitEnabled;
Expand Down Expand Up @@ -686,7 +686,7 @@ protected override void LoadFromIni() {
Resolution = resolution;
}

VerticalSyncronization = section.GetBool("VSYNC", false);
VerticalSynchronization = section.GetBool("VSYNC", false);
AntiAliasingLevel = section.GetEntry("AASAMPLES", AntiAliasingLevels);
AnisotropicLevel = section.GetEntry("ANISOTROPIC", AnisotropicLevels, "8");
ShadowMapSize = section.ContainsKey(@"__CM_ORIGINAL_SHADOW_MAP_SIZE")
Expand Down Expand Up @@ -742,7 +742,7 @@ protected override void SetToIni(IniFile ini) {
}

section.Set("FULLSCREEN", Fullscreen);
section.Set("VSYNC", VerticalSyncronization);
section.Set("VSYNC", VerticalSynchronization);
section.Set("AASAMPLES", AntiAliasingLevel);
section.Set("ANISOTROPIC", AnisotropicLevel);
section.Set("SHADOW_MAP_SIZE", ShadowMapSize);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel;

namespace AcManager.Tools.Tyres {
namespace AcManager.Tools.Helpers.Tyres {
public enum TyresAppropriateLevel {
[Description("Full match")]
A = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using JetBrains.Annotations;
using StringBasedFilter;

namespace AcManager.Tools.Tyres {
namespace AcManager.Tools.Helpers.Tyres {
public sealed class TyresEntry : Displayable, IDraggable {
public static bool OptionRoundNicely = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using AcManager.Tools.Filters.Testers;
using StringBasedFilter;

namespace AcManager.Tools.Tyres {
namespace AcManager.Tools.Helpers.Tyres {
public class TyresEntryTester : IParentTester<TyresEntry> {
public static readonly TyresEntryTester Instance = new TyresEntryTester();

Expand Down
201 changes: 201 additions & 0 deletions AcManager.Tools/Helpers/Tyres/TyresExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AcManager.Tools.Objects;
using AcTools.DataFile;
using FirstFloor.ModernUI.Helpers;
using JetBrains.Annotations;

namespace AcManager.Tools.Helpers.Tyres {
public static class TyresExtension {
public static readonly string ThermalPrefix = @"THERMAL@";

[CanBeNull]
public static TyresSet GetOriginalTyresSet([NotNull] this CarObject car) {
var tyres = car.AcdData?.GetIniFile("tyres.ini");
if (tyres?.IsEmptyOrDamaged() != false) return null;

var front = TyresEntry.Create(car, @"__CM_FRONT_ORIGINAL", true);
var rear = TyresEntry.Create(car, @"__CM_REAR_ORIGINAL", true);
if (front != null && rear != null) {
return new TyresSet(front, rear);
} else {
return null;
}
}

[NotNull]
public static IEnumerable<TyresSet> GetTyresSets([NotNull] this CarObject car) {
var tyres = car.AcdData?.GetIniFile("tyres.ini");
if (tyres?.IsEmptyOrDamaged() != false) return new TyresSet[0];

var defaultSet = tyres["COMPOUND_DEFAULT"].GetInt("INDEX", 0);
return TyresEntry.GetTyres(car).Where(x => x.Item1 != null && x.Item2 != null).Select((x, i) => new TyresSet(x.Item1, x.Item2) {
DefaultSet = i == defaultSet
});
}

public static void Save([NotNull] this TyresSet sets, int setsVersion, [NotNull] CarObject car,
[CanBeNull] TyresEntry originalTyresFront, [CanBeNull] TyresEntry originalTyresRear, bool keepCurves = false) {
Save(new[] { sets }, setsVersion, car, originalTyresFront, originalTyresRear, keepCurves);
}

public static void Save([NotNull] this IEnumerable<TyresSet> sets, int setsVersion, [NotNull] CarObject car,
[CanBeNull] TyresEntry originalTyresFront, [CanBeNull] TyresEntry originalTyresRear, bool keepCurves = false) {
try {
var uniqueSets = sets.Distinct(TyresSet.TyresSetComparer).ToList();

if (uniqueSets.Count == 0) {
throw new Exception("At least one set is required");
}

if (!uniqueSets.All(x => x.Front.Version == setsVersion && x.Rear.Version == setsVersion)) {
throw new Exception("Versions are different");
}

var data = car.AcdData;
if (data == null) {
throw new Exception("Data is unreadable");
}

var tyresIni = data.GetIniFile("tyres.ini");
tyresIni["HEADER"].Set("VERSION", setsVersion);

var defaultIndex = uniqueSets.FindIndex(x => x.DefaultSet);
tyresIni["COMPOUND_DEFAULT"].Set("INDEX", defaultIndex == -1 ? 0 : defaultIndex);

if (originalTyresFront != null) {
tyresIni["__CM_FRONT_ORIGINAL"] = originalTyresFront.MainSection;
tyresIni["__CM_THERMAL_FRONT_ORIGINAL"] = originalTyresFront.ThermalSection;
}

if (originalTyresRear != null) {
tyresIni["__CM_REAR_ORIGINAL"] = originalTyresRear.MainSection;
tyresIni["__CM_THERMAL_REAR_ORIGINAL"] = originalTyresRear.ThermalSection;
}

SetTyres(true);
SetTyres(false);

void SetTyres(bool isRear) {
var key = isRear ? "REAR" : "FRONT";
var thermalKey = $"THERMAL_{key}";

var currentTyres = keepCurves ? tyresIni.GetSections(key, -1).ToList() : null;
var currentThermalTyres = keepCurves ? tyresIni.GetSections(thermalKey, -1).ToList() : null;

tyresIni.SetSections(key, -1, uniqueSets.Select((x, i) => {
var entry = isRear ? x.Rear : x.Front;
var curveName = currentTyres?.ElementAtOrDefault(i)?.GetNonEmpty("WEAR_CURVE");
if (!keepCurves || curveName == null) {
var curve = data.GetRawFile($@"__cm_tyre_wearcurve_{key.ToLowerInvariant()}_{i}.lut");
curve.Content = entry.WearCurveData ?? "";
curve.Save();
curveName = curve.Name;
}

return FixDigits(new IniFileSection(data, entry.MainSection) {
["NAME"] = x.GetName(),
["SHORT_NAME"] = x.GetShortName(),
["WEAR_CURVE"] = curveName,
["__CM_SOURCE_ID"] = entry.SourceCarId
});
}));

tyresIni.SetSections(thermalKey, -1, uniqueSets.Select((x, i) => {
var entry = isRear ? x.Rear : x.Front;
var curveName = currentThermalTyres?.ElementAtOrDefault(i)?.GetNonEmpty("PERFORMANCE_CURVE");
if (!keepCurves || curveName == null) {
var curve = data.GetRawFile($@"__cm_tyre_perfcurve_{key.ToLowerInvariant()}_{i}.lut");
curve.Content = entry.PerformanceCurveData ?? "";
curve.Save();
curveName = curve.Name;
}

return FixDigits(new IniFileSection(data, entry.ThermalSection) {
["PERFORMANCE_CURVE"] = curveName
});
}));
}

IniFileSection FixDigits(IniFileSection result) {
foreach (var key in result.Keys.ToList()) {
var digits = GetValueDigits(key);
if (digits != null) {
result.Set(key, result.GetDouble(key, 0d), "F" + digits);
}
}
return result;
}

tyresIni.Save(true);
} catch (Exception e) {
NonfatalError.Notify("Can’t save changes", e);
}
}

public static int? GetValueDigits(string key) {
switch (key) {
case "DAMP":
case "DCAMBER_1":
case "FALLOFF_SPEED":
case "FZ0":
case "PRESSURE_IDEAL":
case "PRESSURE_SPRING_GAIN":
case "PRESSURE_STATIC":
case "RATE":
case "ROLLING_RESISTANCE_0":
case "ROLLING_RESISTANCE_SLIP":
return 0;
case "BRAKE_DX_MOD":
case "COOL_FACTOR":
case "CX_MULT":
case "DCAMBER_0":
case "FALLOFF_LEVEL":
case "FRICTION_LIMIT_ANGLE":
case "GRAIN_GAIN":
case "PRESSURE_FLEX_GAIN":
case "PRESSURE_RR_GAIN":
case "ROLLING_K":
case "XMU":
return 2;
case "CAMBER_GAIN":
case "DX_REF":
case "DY_REF":
return 3;
case "ANGULAR_INERTIA":
case "BLISTER_GAMMA":
case "DX0":
case "DX1":
case "DY0":
case "DY1":
case "GRAIN_GAMMA":
case "FLEX_GAIN":
case "LS_EXPY":
case "LS_EXPX":
case "PRESSURE_D_GAIN":
case "RADIUS_ANGULAR_K":
case "RIM_RADIUS":
case "SURFACE_TRANSFER":
case "WIDTH":
return 4;
case "FRICTION_K":
case "PATCH_TRANSFER":
case "RADIUS":
case "RELAXATION_LENGTH":
case "SURFACE_ROLLING_K":
return 5;
case "INTERNAL_CORE_TRANSFER":
case "SPEED_SENSITIVITY":
return 6;
case "CORE_TRANSFER":
case "ROLLING_RESISTANCE_1":
return 7;
case "FLEX":
return 8;
default:
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows.Controls;
using System.Windows.Media;

namespace AcManager.Tools.Tyres {
namespace AcManager.Tools.Helpers.Tyres {
public class TyresPlace : Border {
static TyresPlace() {
DefaultStyleKeyProperty.OverrideMetadata(typeof(TyresPlace), new FrameworkPropertyMetadata(typeof(TyresPlace)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using FirstFloor.ModernUI.Windows;
using JetBrains.Annotations;

namespace AcManager.Tools.Tyres {
namespace AcManager.Tools.Helpers.Tyres {
public sealed class TyresSet : Displayable, IDraggable {
private int _index;

Expand Down
9 changes: 7 additions & 2 deletions AcManager.Tools/Helpers/WindowsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ public static void OpenFile([NotNull] string filename) {

[NotNull]
public static IEnumerable<string> GetInputFiles(this DragEventArgs e) {
return e.Data.GetData(DataFormats.FileDrop) as string[] ??
(e.Data.GetData(DataFormats.UnicodeText) as string)?.Split('\n')
return e.Data.GetInputFiles();
}

[NotNull]
public static IEnumerable<string> GetInputFiles(this IDataObject data) {
return data.GetData(DataFormats.FileDrop) as string[] ??
(data.GetData(DataFormats.UnicodeText) as string)?.Split('\n')
.Select(x => x.Trim())
.Select(x => x.Length > 1 && x.StartsWith(@"""") && x.EndsWith(@"""")
? x.Substring(1, x.Length - 2) : x) ?? new string[0];
Expand Down
23 changes: 13 additions & 10 deletions AcManager.Tools/Objects/CarObject.Setups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ public void UpdateAcdData() {
CommandManager.InvalidateRequerySuggested();
}

private bool _acdDataRead;
private bool _acdDataRead ;
private DataWrapper _acdData;
private readonly object _acdDataSync = new object();

/// <summary>
/// Null only if data is damaged so much it’s unreadable.
/// </summary>
[CanBeNull]
public DataWrapper AcdData {
get {
try {
if (_acdDataRead) return _acdData;
_acdDataRead = true;

_acdData = DataWrapper.FromCarDirectory(Location);
return _acdData;
} catch (Exception e) {
NonfatalError.NotifyBackground("Can’t read data", e);
return null;
if (_acdDataRead) return _acdData;
lock (_acdDataSync) {
try {
_acdData = DataWrapper.FromCarDirectory(Location);
_acdDataRead = true;
return _acdData;
} catch (Exception e) {
NonfatalError.NotifyBackground("Can’t read data", e);
_acdDataRead = true;
return null;
}
}
}
}
Expand Down
Loading

0 comments on commit 7b42699

Please sign in to comment.