Skip to content

Commit c96afe5

Browse files
committed
fix many code warnings and suggestions
1 parent 2afd8de commit c96afe5

30 files changed

+185
-207
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ insert_final_newline = true
1111
trim_trailing_whitespace = true
1212
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
1313
dotnet_style_namespace_match_folder = true:suggestion
14+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
15+
dotnet_style_coalesce_expression = true:suggestion
16+
dotnet_style_null_propagation = true:suggestion
17+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
18+
dotnet_style_prefer_auto_properties = true:suggestion
19+
dotnet_style_object_initializer = true:suggestion
20+
dotnet_style_collection_initializer = true:suggestion
21+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
22+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
23+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
1424

1525
# C# files
1626
[*.csproj]
@@ -426,3 +436,4 @@ dotnet_diagnostic.SA1633.severity = none
426436
dotnet_diagnostic.RCS1217.severity = none
427437

428438
dotnet_diagnostic.RS0030.severity = error
439+
csharp_style_prefer_primary_constructors = true:suggestion

AvaGui/Models/DatFileType.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace AvaGui.Models
2+
{
3+
public enum DatFileType
4+
{
5+
Object,
6+
Scenario,
7+
SaveGame,
8+
Tutorial,
9+
G1,
10+
Music,
11+
SoundEffect, // css*.dat
12+
Language,
13+
Scores,
14+
}
15+
}

AvaGui/Models/FileSystemItemGroup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ public record FileSystemItemGroup(string Path, ObjectType ObjectType, Observable
2121

2222
public record FileSystemVehicleGroup(string Path, VehicleType VehicleType, ObservableCollection<FileSystemItemBase> SubNodes)
2323
: FileSystemItemBase(Path, VehicleType.ToString(), SubNodes);
24-
2524
}

AvaGui/Models/IUiObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.ComponentModel;
1+
using System.ComponentModel;
22

33
namespace AvaGui.Models
44
{
55
[TypeConverter(typeof(ExpandableObjectConverter))]
6-
public interface IUiObject { }
6+
public interface IUiObject;
77
}

AvaGui/Models/IndexObjectHeader.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using OpenLoco.ObjectEditor.Data;
22
using OpenLoco.ObjectEditor.Objects;
3-
using System;
43

54
namespace AvaGui.Models
65
{
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
using OpenLoco.ObjectEditor.Data;
22
using ReactiveUI;
3+
using ReactiveUI.Fody.Helpers;
34

45
namespace AvaGui.Models
56
{
6-
public class LanguageTranslation : ReactiveObject
7+
public class LanguageTranslation(LanguageId language, string translation) : ReactiveObject
78
{
8-
public LanguageTranslation(LanguageId language, string translation)
9-
{
10-
_language = language;
11-
_translation = translation;
12-
}
9+
[Reactive]
10+
public LanguageId Language { get; set; } = language;
1311

14-
private LanguageId _language;
15-
public LanguageId Language
16-
{
17-
get => _language;
18-
set => _ = this.RaiseAndSetIfChanged(ref _language, value);
19-
}
20-
21-
private string _translation;
22-
23-
public string Translation
24-
{
25-
get => _translation;
26-
set => _ = this.RaiseAndSetIfChanged(ref _translation, value);
27-
}
12+
[Reactive]
13+
public string Translation { get; set; } = translation;
2814
}
2915
}

AvaGui/Models/ObjectEditorModel.cs

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,9 @@
1616
using OpenLoco.ObjectEditor.Data;
1717
using OpenLoco.ObjectEditor;
1818
using System.Collections.ObjectModel;
19-
using ReactiveUI;
20-
using System.Reflection;
2119

2220
namespace AvaGui.Models
2321
{
24-
public enum DatFileType
25-
{
26-
Object,
27-
Scenario,
28-
SaveGame,
29-
Tutorial,
30-
G1,
31-
Music,
32-
SoundEffect, // css*.dat
33-
Language,
34-
Scores,
35-
}
36-
3722
public class ObjectEditorModel
3823
{
3924
public EditorSettings Settings { get; private set; }
@@ -48,23 +33,23 @@ public class ObjectEditorModel
4833

4934
public G1Dat? G1 { get; set; }
5035

51-
public Dictionary<string, byte[]> Music { get; set; } = [];
36+
public Dictionary<string, byte[]> Music { get; } = [];
5237

53-
public Dictionary<string, byte[]> MiscellaneousTracks { get; set; } = [];
38+
public Dictionary<string, byte[]> MiscellaneousTracks { get; } = [];
5439

55-
public Dictionary<string, byte[]> SoundEffects { get; set; } = [];
40+
public Dictionary<string, byte[]> SoundEffects { get; } = [];
5641

57-
public Dictionary<string, byte[]> Tutorials { get; set; } = [];
42+
public Dictionary<string, byte[]> Tutorials { get; } = [];
5843

59-
public Collection<string> MiscFiles { get; set; } = [];
44+
public Collection<string> MiscFiles { get; } = [];
6045

6146
public const string ApplicationName = "OpenLoco Object Editor";
6247

6348
public static string SettingsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationName);
6449

6550
public static string SettingsFile => Path.Combine(SettingsPath, "settings.json");
6651

67-
public ObservableCollection<LogLine> LoggerObservableLogs = new();
52+
public ObservableCollection<LogLine> LoggerObservableLogs = [];
6853

6954
public ObjectEditorModel()
7055
{
@@ -187,20 +172,9 @@ void CreateIndex(string[] allFiles, IProgress<float>? progress)
187172
sw.Start();
188173

189174
var fileCount = allFiles.Length;
190-
var parallelise = true; // todo: remove this or make a user setting
191175

192-
if (parallelise)
193-
{
194-
_ = Parallel.ForEach(allFiles, new ParallelOptions() { MaxDegreeOfParallelism = 16 }, (filename)
195-
=> count = LoadAndIndexFile(count, filename));
196-
}
197-
else
198-
{
199-
foreach (var filename in allFiles)
200-
{
201-
count = LoadAndIndexFile(count, filename);
202-
}
203-
}
176+
_ = Parallel.ForEach(allFiles, new ParallelOptions() { MaxDegreeOfParallelism = 16 }, (filename)
177+
=> count = LoadAndIndexFile(count, filename));
204178

205179
HeaderIndex = ccHeaderIndex.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
206180

@@ -294,7 +268,7 @@ void LoadKnownData(HashSet<string> allFilesInDir, HashSet<string> knownFilenames
294268
LoadKnownData(allDataFiles, [OriginalDataFiles.SoundEffect], SoundEffects);
295269
LoadKnownData(allDataFiles, OriginalDataFiles.Tutorials, Tutorials);
296270

297-
MiscFiles = [.. allDataFiles];
271+
//MiscFiles = [.. allDataFiles];
298272

299273
// load G1 only for now since we need it for palette
300274
G1 = SawyerStreamReader.LoadG1(Settings.GetDataFullPath(Settings.G1DatFileName));

AvaGui/Models/ObjectTypeToMaterialIconConverter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace AvaGui.Models
99
{
1010
public class ObjectTypeToMaterialIconConverter : IValueConverter
1111
{
12-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
1313
{
1414
if (Enum.TryParse<DatFileType>(value as string, out var datType) && DatTypeMapping.TryGetValue(datType, out var datIcon))
1515
{
@@ -37,7 +37,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
3737
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
3838
=> throw new NotImplementedException();
3939

40-
public static Dictionary<ObjectType, string> ObjectMapping = new Dictionary<ObjectType, string>()
40+
static readonly Dictionary<ObjectType, string> ObjectMapping = new()
4141
{
4242
{ ObjectType.InterfaceSkin, "Monitor" },
4343
{ ObjectType.Sound, "Speaker" },
@@ -75,7 +75,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
7575
{ ObjectType.ScenarioText, "ScriptText" },
7676
};
7777

78-
public static Dictionary<VehicleType, string> VehicleMapping = new Dictionary<VehicleType, string>()
78+
static readonly Dictionary<VehicleType, string> VehicleMapping = new()
7979
{
8080
{ VehicleType.Train, "Train" },
8181
{ VehicleType.Bus, "Bus" },
@@ -85,14 +85,14 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
8585
{ VehicleType.Ship, "Sailboat" },
8686
};
8787

88-
public static Dictionary<SourceGame, string> SourceGameMapping = new Dictionary<SourceGame, string>()
88+
static readonly Dictionary<SourceGame, string> SourceGameMapping = new()
8989
{
9090
{ SourceGame.Custom, "AccountEdit" },
9191
{ SourceGame.DataFile, "File" },
9292
{ SourceGame.Vanilla, "AccountTieHat" },
9393
};
9494

95-
public static Dictionary<DatFileType, string> DatTypeMapping = new Dictionary<DatFileType, string>()
95+
static readonly Dictionary<DatFileType, string> DatTypeMapping = new()
9696
{
9797
{ DatFileType.Object, "Apps" },
9898
{ DatFileType.Scenario, "MapClock" },

AvaGui/Models/UiG1.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public List<G1Element32> G1Elements
1616
set
1717
{
1818
G1.G1Elements.Clear();
19-
foreach (var x in value)
20-
{
21-
G1.G1Elements.Add(x);
22-
}
19+
G1.G1Elements.AddRange(value);
2320
}
2421
}
2522
}

AvaGui/Models/UiSoundObjectList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace AvaGui.Models
77
public class UiSoundObjectList : IUiObject
88
{
99
public string FileName { get; set; }
10-
public List<UiSoundObject> Audio { get; set; } = [];
10+
public List<UiSoundObject> Audio { get; } = [];
1111
}
1212
}

0 commit comments

Comments
 (0)