From 6c7fa070f6af3de0cd2dcc6202f7759ce648d16e Mon Sep 17 00:00:00 2001 From: Frank Tovar Date: Sun, 10 May 2026 18:37:30 +0200 Subject: [PATCH] cleanup code --- .editorconfig | 82 +++++++++---------- AGENTS.windows.md | 2 +- ReactorMaintenance.slnx | 18 ++-- .../Balancing.cs | 4 +- .../JunctionFlow.cs | 18 ++-- .../JunctionFlowAnalyzer.cs | 4 +- .../LevelEditor.cs | 6 +- .../LevelSerializer.cs | 14 ++-- .../LevelStateExtensions.cs | 4 +- .../LevelStateFactory.cs | 2 +- .../ReactorMaintenance.Simulation.csproj | 10 +-- .../Systems/SimulationCoreSystem.cs | 40 ++++----- src/ReactorMaintenance.Win2D/MainWindow.xaml | 52 ++++++------ .../MainWindow.xaml.cs | 46 +++++------ .../ReactorMaintenance.Win2D.csproj | 8 +- src/ReactorMaintenance.Win2D/app.manifest | 14 ++-- ...ReactorMaintenance.Simulation.Tests.csproj | 38 ++++----- .../SimulationEngineTests.cs | 66 +++++++-------- 18 files changed, 215 insertions(+), 213 deletions(-) diff --git a/.editorconfig b/.editorconfig index 12e4b6b..db68279 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,9 +20,9 @@ insert_final_newline = false # Organize usings dotnet_separate_import_directive_groups = false dotnet_sort_system_directives_first = false -file_header_template = +file_header_template = # this. and Me. preferences + -# this. and Me. preferences dotnet_style_qualification_for_event = false:suggestion dotnet_style_qualification_for_field = false:suggestion dotnet_style_qualification_for_method = false:suggestion @@ -125,7 +125,7 @@ csharp_new_line_before_else = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_open_brace = accessors,anonymous_methods,control_blocks,events,indexers,local_functions,methods,properties,types +csharp_new_line_before_open_brace = accessors, anonymous_methods, control_blocks, events, indexers, local_functions, methods, properties, types csharp_new_line_between_query_expression_clauses = true # Indentation preferences @@ -228,27 +228,27 @@ dotnet_naming_rule.local_should_be_camelcase.style = camelcase dotnet_naming_symbols.interface.applicable_kinds = interface dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interface.required_modifiers = +dotnet_naming_symbols.interface.required_modifiers = dotnet_naming_symbols.struct.applicable_kinds = struct dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.struct.required_modifiers = +dotnet_naming_symbols.struct.required_modifiers = dotnet_naming_symbols.delegate.applicable_kinds = delegate dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.delegate.required_modifiers = +dotnet_naming_symbols.delegate.required_modifiers = dotnet_naming_symbols.event.applicable_kinds = event dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.event.required_modifiers = +dotnet_naming_symbols.event.required_modifiers = dotnet_naming_symbols.property.applicable_kinds = property dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.property.required_modifiers = +dotnet_naming_symbols.property.required_modifiers = dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected -dotnet_naming_symbols.public_or_protected_field.required_modifiers = +dotnet_naming_symbols.public_or_protected_field.required_modifiers = dotnet_naming_symbols.static_field.applicable_kinds = field dotnet_naming_symbols.static_field.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected @@ -256,7 +256,7 @@ dotnet_naming_symbols.static_field.required_modifiers = static dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected -dotnet_naming_symbols.private_or_internal_field.required_modifiers = +dotnet_naming_symbols.private_or_internal_field.required_modifiers = dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected @@ -264,19 +264,19 @@ dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = stat dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types.required_modifiers = +dotnet_naming_symbols.types.required_modifiers = dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.non_field_members.required_modifiers = +dotnet_naming_symbols.non_field_members.required_modifiers = dotnet_naming_symbols.parameter.applicable_kinds = parameter dotnet_naming_symbols.parameter.applicable_accessibilities = * -dotnet_naming_symbols.parameter.required_modifiers = +dotnet_naming_symbols.parameter.required_modifiers = dotnet_naming_symbols.local.applicable_kinds = local dotnet_naming_symbols.local.applicable_accessibilities = local -dotnet_naming_symbols.local.required_modifiers = +dotnet_naming_symbols.local.required_modifiers = dotnet_naming_symbols.constant_field.applicable_kinds = field dotnet_naming_symbols.constant_field.applicable_accessibilities = * @@ -284,49 +284,49 @@ dotnet_naming_symbols.constant_field.required_modifiers = const # Naming styles -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_naming_style.begins_with_i.required_prefix = I -dotnet_naming_style.begins_with_i.required_suffix = -dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.capitalization = pascal_case dotnet_naming_style.begin_with_s.required_prefix = S -dotnet_naming_style.begin_with_s.required_suffix = -dotnet_naming_style.begin_with_s.word_separator = +dotnet_naming_style.begin_with_s.required_suffix = +dotnet_naming_style.begin_with_s.word_separator = dotnet_naming_style.begin_with_s.capitalization = pascal_case dotnet_naming_style.starts_with_m_.required_prefix = m_ -dotnet_naming_style.starts_with_m_.required_suffix = -dotnet_naming_style.starts_with_m_.word_separator = +dotnet_naming_style.starts_with_m_.required_suffix = +dotnet_naming_style.starts_with_m_.word_separator = dotnet_naming_style.starts_with_m_.capitalization = pascal_case dotnet_naming_style.starts_with_s_.required_prefix = s_ -dotnet_naming_style.starts_with_s_.required_suffix = -dotnet_naming_style.starts_with_s_.word_separator = +dotnet_naming_style.starts_with_s_.required_suffix = +dotnet_naming_style.starts_with_s_.word_separator = dotnet_naming_style.starts_with_s_.capitalization = pascal_case -dotnet_naming_style.end_with_delegate.required_prefix = +dotnet_naming_style.end_with_delegate.required_prefix = dotnet_naming_style.end_with_delegate.required_suffix = Delegate -dotnet_naming_style.end_with_delegate.word_separator = +dotnet_naming_style.end_with_delegate.word_separator = dotnet_naming_style.end_with_delegate.capitalization = pascal_case -dotnet_naming_style.end_with_event.required_prefix = +dotnet_naming_style.end_with_event.required_prefix = dotnet_naming_style.end_with_event.required_suffix = Event -dotnet_naming_style.end_with_event.word_separator = +dotnet_naming_style.end_with_event.word_separator = dotnet_naming_style.end_with_event.capitalization = pascal_case -dotnet_naming_style.camelcase.required_prefix = -dotnet_naming_style.camelcase.required_suffix = -dotnet_naming_style.camelcase.word_separator = +dotnet_naming_style.camelcase.required_prefix = +dotnet_naming_style.camelcase.required_suffix = +dotnet_naming_style.camelcase.word_separator = dotnet_naming_style.camelcase.capitalization = camel_case dotnet_naming_style.begins_with_c_.required_prefix = c_ -dotnet_naming_style.begins_with_c_.required_suffix = -dotnet_naming_style.begins_with_c_.word_separator = +dotnet_naming_style.begins_with_c_.required_suffix = +dotnet_naming_style.begins_with_c_.word_separator = dotnet_naming_style.begins_with_c_.capitalization = pascal_case # ReSharper properties @@ -381,7 +381,7 @@ resharper_csharp_wrap_chained_method_calls = chop_if_long resharper_extra_spaces = remove_all resharper_for_built_in_types = use_var resharper_indent_preprocessor_region = no_indent -resharper_instance_members_qualify_declared_in = +resharper_instance_members_qualify_declared_in = resharper_int_align_switch_expressions = false resharper_int_align_switch_sections = false resharper_keep_existing_arrangement = true @@ -476,7 +476,7 @@ dotnet_naming_rule.types_and_namespaces_rule.import_to_resharper = as_predefined dotnet_naming_rule.types_and_namespaces_rule.severity = none dotnet_naming_rule.types_and_namespaces_rule.style = pascal_case dotnet_naming_rule.types_and_namespaces_rule.symbols = types_and_namespaces_symbols -dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public, internal, protected, protected_internal, private_protected dotnet_naming_symbols.constants_symbols.applicable_kinds = field dotnet_naming_symbols.constants_symbols.required_modifiers = const dotnet_naming_symbols.event_symbols.applicable_accessibilities = * @@ -498,16 +498,16 @@ dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field -dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static, readonly dotnet_naming_symbols.property_symbols.applicable_accessibilities = * dotnet_naming_symbols.property_symbols.applicable_kinds = property -dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public, internal, protected, protected_internal, private_protected dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field -dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public, internal, protected, protected_internal, private_protected dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field -dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static, readonly dotnet_naming_symbols.types_and_namespaces_symbols.applicable_accessibilities = * -dotnet_naming_symbols.types_and_namespaces_symbols.applicable_kinds = namespace,class,struct,enum,delegate +dotnet_naming_symbols.types_and_namespaces_symbols.applicable_kinds = namespace, class, struct, enum, delegate # ReSharper inspection severities resharper_arrange_accessor_owner_body_highlighting = suggestion diff --git a/AGENTS.windows.md b/AGENTS.windows.md index f552514..4c3509e 100644 --- a/AGENTS.windows.md +++ b/AGENTS.windows.md @@ -1,4 +1,4 @@ # Windows-specific instructions - After the implementation is finished, run `python D:\Code\crlf.py $file1 $file2 ...` for changed files you recognize, in order to normalize all line endings of all touched files to CRLF. -- After every iteration, run `jb cleanupcode --build=False '$file1' '$file2' ...` for every C# file you touched. \ No newline at end of file +- After every iteration, run `jb cleanupcode '$file1' '$file2' ...` for every C# file you touched. \ No newline at end of file diff --git a/ReactorMaintenance.slnx b/ReactorMaintenance.slnx index 8ecfa60..4550a38 100644 --- a/ReactorMaintenance.slnx +++ b/ReactorMaintenance.slnx @@ -1,11 +1,11 @@  - - - - - - - - - + + + + + + + + + diff --git a/src/ReactorMaintenance.Simulation/Balancing.cs b/src/ReactorMaintenance.Simulation/Balancing.cs index cf086cf..77dfca5 100644 --- a/src/ReactorMaintenance.Simulation/Balancing.cs +++ b/src/ReactorMaintenance.Simulation/Balancing.cs @@ -4,8 +4,6 @@ namespace ReactorMaintenance.Simulation; public abstract class Balancing { - public static Balancing Current { get; set; } = new NormalBalancing(); - public float ClampValue(float value) { return Math.Clamp(value, MinValue, MaxValue); @@ -107,6 +105,8 @@ public abstract class Balancing return a > b ? a : b; } + public static Balancing Current { get; set; } = new NormalBalancing(); + public abstract int DefaultLevelWidth { get; } public abstract int DefaultLevelHeight { get; } public abstract int MinimumLevelSize { get; } diff --git a/src/ReactorMaintenance.Simulation/JunctionFlow.cs b/src/ReactorMaintenance.Simulation/JunctionFlow.cs index 5ba2ae1..8cca718 100644 --- a/src/ReactorMaintenance.Simulation/JunctionFlow.cs +++ b/src/ReactorMaintenance.Simulation/JunctionFlow.cs @@ -2,15 +2,6 @@ public sealed record JunctionFlow { - public GridPosition Position { get; init; } = new(0, 0); - public PropState Prop { get; init; } = new(); - public ECarrierType Carrier { get; init; } - public IReadOnlyList Branches { get; init; } = Array.Empty(); - public GridPosition? IncomingBranch { get; init; } - public IReadOnlyList OutgoingBranches { get; init; } = Array.Empty(); - public IReadOnlyList Errors { get; init; } = Array.Empty(); - public bool IsValid => Errors.Count == 0; - public float WeightFor(GridPosition outgoingBranch) { var index = IndexOfOutgoingBranch(outgoingBranch); @@ -31,4 +22,13 @@ public sealed record JunctionFlow return -1; } + + public GridPosition Position { get; init; } = new(0, 0); + public PropState Prop { get; init; } = new(); + public ECarrierType Carrier { get; init; } + public IReadOnlyList Branches { get; init; } = Array.Empty(); + public GridPosition? IncomingBranch { get; init; } + public IReadOnlyList OutgoingBranches { get; init; } = Array.Empty(); + public IReadOnlyList Errors { get; init; } = Array.Empty(); + public bool IsValid => Errors.Count == 0; } \ No newline at end of file diff --git a/src/ReactorMaintenance.Simulation/JunctionFlowAnalyzer.cs b/src/ReactorMaintenance.Simulation/JunctionFlowAnalyzer.cs index 2f58baa..e9d2814 100644 --- a/src/ReactorMaintenance.Simulation/JunctionFlowAnalyzer.cs +++ b/src/ReactorMaintenance.Simulation/JunctionFlowAnalyzer.cs @@ -2,6 +2,8 @@ public static class JunctionFlowAnalyzer { + private sealed record SourceBranch(GridPosition Position, int? Distance); + public static IReadOnlyList Analyze(LevelState level) { var flows = new List(); @@ -92,6 +94,4 @@ public static class JunctionFlowAnalyzer return null; } - - private sealed record SourceBranch(GridPosition Position, int? Distance); } \ No newline at end of file diff --git a/src/ReactorMaintenance.Simulation/LevelEditor.cs b/src/ReactorMaintenance.Simulation/LevelEditor.cs index e0511ba..c75468f 100644 --- a/src/ReactorMaintenance.Simulation/LevelEditor.cs +++ b/src/ReactorMaintenance.Simulation/LevelEditor.cs @@ -111,7 +111,7 @@ public static class LevelEditor return SetFloorProp(level, position, new() { Type = EPropType.Door }); return SetFloorProp(level, position, new() { Type = EPropType.Door }) with { - Doors = [.. level.Doors, new DoorState { A = position, B = neighbor }] + Doors = [.. level.Doors, new() { A = position, B = neighbor }] }; } @@ -125,7 +125,7 @@ public static class LevelEditor return levelWithProp with { Reactors = [ .. level.Reactors, - new ReactorBinding { + new() { ReactorId = id, ControlPosition = position, FuelConsumerPosition = position, @@ -152,7 +152,7 @@ public static class LevelEditor return next with { Leaks = [ .. next.Leaks, - new LeakState { + new() { Carrier = carrier, UndergroundPosition = position, AccessPosition = accessPosition diff --git a/src/ReactorMaintenance.Simulation/LevelSerializer.cs b/src/ReactorMaintenance.Simulation/LevelSerializer.cs index 0c9f8a1..65257c8 100644 --- a/src/ReactorMaintenance.Simulation/LevelSerializer.cs +++ b/src/ReactorMaintenance.Simulation/LevelSerializer.cs @@ -5,7 +5,11 @@ namespace ReactorMaintenance.Simulation; public static class LevelSerializer { - private const int c_CurrentVersion = 2; + private sealed record LevelFile + { + public int Version { get; init; } + public LevelState? Level { get; init; } + } public static string Serialize(LevelState level) { @@ -29,14 +33,10 @@ public static class LevelSerializer return level; } + private const int c_CurrentVersion = 2; + private static readonly JsonSerializerOptions s_Options = new() { WriteIndented = true, Converters = { new JsonStringEnumConverter() } }; - - private sealed record LevelFile - { - public int Version { get; init; } - public LevelState? Level { get; init; } - } } \ No newline at end of file diff --git a/src/ReactorMaintenance.Simulation/LevelStateExtensions.cs b/src/ReactorMaintenance.Simulation/LevelStateExtensions.cs index ec80c47..ad821aa 100644 --- a/src/ReactorMaintenance.Simulation/LevelStateExtensions.cs +++ b/src/ReactorMaintenance.Simulation/LevelStateExtensions.cs @@ -12,7 +12,7 @@ public static class LevelStateExtensions if (!level.InBounds(position)) throw new ArgumentOutOfRangeException(nameof(position), $"Position {position.X},{position.Y} is outside {level.Width}x{level.Height}."); - return position.Y * level.Width + position.X; + return (position.Y * level.Width) + position.X; } public static ECellTerrain GetTerrain(this LevelState level, GridPosition position) @@ -111,6 +111,6 @@ public static class LevelStateExtensions private static bool SameEdge(GridPosition edgeA, GridPosition edgeB, GridPosition a, GridPosition b) { - return edgeA == a && edgeB == b || edgeA == b && edgeB == a; + return (edgeA == a && edgeB == b) || (edgeA == b && edgeB == a); } } \ No newline at end of file diff --git a/src/ReactorMaintenance.Simulation/LevelStateFactory.cs b/src/ReactorMaintenance.Simulation/LevelStateFactory.cs index 81d0e3d..6cf2395 100644 --- a/src/ReactorMaintenance.Simulation/LevelStateFactory.cs +++ b/src/ReactorMaintenance.Simulation/LevelStateFactory.cs @@ -30,7 +30,7 @@ public static class LevelStateFactory for (var x = 0; x < width; x++) { if (x == 0 || y == 0 || x == width - 1 || y == height - 1) - terrain[y * width + x] = ECellTerrain.Wall; + terrain[(y * width) + x] = ECellTerrain.Wall; } } diff --git a/src/ReactorMaintenance.Simulation/ReactorMaintenance.Simulation.csproj b/src/ReactorMaintenance.Simulation/ReactorMaintenance.Simulation.csproj index de201d1..0e42146 100644 --- a/src/ReactorMaintenance.Simulation/ReactorMaintenance.Simulation.csproj +++ b/src/ReactorMaintenance.Simulation/ReactorMaintenance.Simulation.csproj @@ -1,9 +1,9 @@  - - net10.0 - enable - enable - + + net10.0 + enable + enable + diff --git a/src/ReactorMaintenance.Simulation/Systems/SimulationCoreSystem.cs b/src/ReactorMaintenance.Simulation/Systems/SimulationCoreSystem.cs index a62e16d..8351599 100644 --- a/src/ReactorMaintenance.Simulation/Systems/SimulationCoreSystem.cs +++ b/src/ReactorMaintenance.Simulation/Systems/SimulationCoreSystem.cs @@ -2,6 +2,24 @@ internal sealed class SimulationCoreSystem { + private sealed class SurfaceDelta + { + public SurfaceState Apply(SurfaceState surface) + { + return surface with { + Fuel = surface.Fuel + Fuel, + Coolant = surface.Coolant + Coolant, + Electricity = surface.Electricity + Electricity, + Heat = surface.Heat + Heat + }; + } + + public float Fuel { get; set; } + public float Coolant { get; set; } + public float Electricity { get; set; } + public float Heat { get; set; } + } + public LevelState MoveRobot(LevelState level, GridPosition destination) { if (!CanSpendAction(level) || !level.IsFloor(destination) || level.Robot.Position.ManhattanDistance(destination) != 1) @@ -252,7 +270,7 @@ internal sealed class SimulationCoreSystem if (surface[accessIndex].Blocks(leak.Carrier)) continue; - var amount = Balancing.Current.LeakBaseAmount + underground.Amount * Balancing.Current.LeakAmountScale + underground.Intensity * Balancing.Current.LeakIntensityScale; + var amount = Balancing.Current.LeakBaseAmount + (underground.Amount * Balancing.Current.LeakAmountScale) + (underground.Intensity * Balancing.Current.LeakIntensityScale); surface[accessIndex] = AddSurfaceCarrier(surface[accessIndex], leak.Carrier, amount); } @@ -447,7 +465,7 @@ internal sealed class SimulationCoreSystem ERulePredicateKind.TurnAtLeast => level.Global.Turn >= predicate.Turn, ERulePredicateKind.LevelStateIs => level.Global.LevelState == predicate.LevelState, ERulePredicateKind.ReactorReadyIs => ReactorMatches(level, predicate, reactor => reactor.Ready), - ERulePredicateKind.ReactorLostIs => (level.Global.LevelState == ELevelState.Lost) == predicate.BoolValue, + ERulePredicateKind.ReactorLostIs => level.Global.LevelState == ELevelState.Lost == predicate.BoolValue, ERulePredicateKind.ReactorWonIs => ReactorWonMatches(level, predicate), ERulePredicateKind.PropStateAt => level.InBounds(predicate.Position) && level.GetProp(predicate.Position).SwitchState == predicate.PropSwitchState, ERulePredicateKind.ConsumerStateAt => level.InBounds(predicate.Position) && level.GetProp(predicate.Position).ServiceState == predicate.ConsumerServiceState, @@ -684,23 +702,5 @@ internal sealed class SimulationCoreSystem } } - private sealed class SurfaceDelta - { - public SurfaceState Apply(SurfaceState surface) - { - return surface with { - Fuel = surface.Fuel + Fuel, - Coolant = surface.Coolant + Coolant, - Electricity = surface.Electricity + Electricity, - Heat = surface.Heat + Heat - }; - } - - public float Fuel { get; set; } - public float Coolant { get; set; } - public float Electricity { get; set; } - public float Heat { get; set; } - } - private readonly LevelValidator m_Validator = new(); } \ No newline at end of file diff --git a/src/ReactorMaintenance.Win2D/MainWindow.xaml b/src/ReactorMaintenance.Win2D/MainWindow.xaml index 6b712aa..84bcc3c 100644 --- a/src/ReactorMaintenance.Win2D/MainWindow.xaml +++ b/src/ReactorMaintenance.Win2D/MainWindow.xaml @@ -15,10 +15,10 @@ - - - - + + + + @@ -39,22 +39,24 @@ - - - - - - - - - - + + + + + + + + + + - - - - + + + + - + \ No newline at end of file diff --git a/src/ReactorMaintenance.Win2D/MainWindow.xaml.cs b/src/ReactorMaintenance.Win2D/MainWindow.xaml.cs index 97a8cf9..4a5d992 100644 --- a/src/ReactorMaintenance.Win2D/MainWindow.xaml.cs +++ b/src/ReactorMaintenance.Win2D/MainWindow.xaml.cs @@ -1,9 +1,9 @@ using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Text; +using Microsoft.Graphics.Canvas.UI; using Microsoft.Graphics.Canvas.UI.Xaml; using Microsoft.UI; using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using ReactorMaintenance.Simulation; using System.Globalization; @@ -22,7 +22,7 @@ public sealed partial class MainWindow { public Rect CellRect(GridPosition position) { - return new(OriginX + position.X * CellSize, OriginY + position.Y * CellSize, CellSize, CellSize); + return new(OriginX + (position.X * CellSize), OriginY + (position.Y * CellSize), CellSize, CellSize); } } @@ -202,7 +202,7 @@ public sealed partial class MainWindow var totalDeltaX = point.Position.X - m_LeftPointerDownPoint.X; var totalDeltaY = point.Position.Y - m_LeftPointerDownPoint.Y; - if (Math.Sqrt(totalDeltaX * totalDeltaX + totalDeltaY * totalDeltaY) > c_ClickPixelThreshold) + if (Math.Sqrt((totalDeltaX * totalDeltaX) + (totalDeltaY * totalDeltaY)) > c_ClickPixelThreshold) m_DragExceededClickThreshold = true; m_PanX += deltaX; @@ -319,7 +319,7 @@ public sealed partial class MainWindow drawing.DrawRectangle(rect, color, cell.State == EUndergroundState.Leaking ? 4 : 2); if (cell.Amount > 0 || cell.Intensity > 0) - drawing.FillCircle((float)(rect.X + rect.Width / 2), (float)(rect.Y + rect.Height / 2), (float)Math.Max(2, rect.Width * 0.08), color); + drawing.FillCircle((float)(rect.X + (rect.Width / 2)), (float)(rect.Y + (rect.Height / 2)), (float)Math.Max(2, rect.Width * 0.08), color); } private void DrawSurface(CanvasDrawingSession drawing, CanvasLayout layout) @@ -341,7 +341,7 @@ public sealed partial class MainWindow if (amount <= 0) return; - var alpha = (byte)Math.Clamp(40 + amount / Balancing.Current.MaxValue * 130, 40, 170); + var alpha = (byte)Math.Clamp(40 + (amount / Balancing.Current.MaxValue * 130), 40, 170); drawing.FillRectangle(Inset(rect, inset), ColorHelper.FromArgb(alpha, color.R, color.G, color.B)); } @@ -431,7 +431,7 @@ public sealed partial class MainWindow { var availableWidth = Math.Max(1, LevelCanvas.ActualWidth); var availableHeight = Math.Max(1, LevelCanvas.ActualHeight); - return new((availableWidth - cellSize * m_Level.Width) / 2, (availableHeight - cellSize * m_Level.Height) / 2); + return new((availableWidth - (cellSize * m_Level.Width)) / 2, (availableHeight - (cellSize * m_Level.Height)) / 2); } private void ClampPan() @@ -459,8 +459,8 @@ public sealed partial class MainWindow m_Zoom = Math.Clamp(m_Zoom * zoomFactor, c_MinZoom, c_MaxZoom); var newCellSize = GetBaseCellSize() * m_Zoom; var originWithoutPan = GetCenteredOrigin(newCellSize); - m_PanX = point.X - originWithoutPan.X - cellX * newCellSize; - m_PanY = point.Y - originWithoutPan.Y - cellY * newCellSize; + m_PanX = point.X - originWithoutPan.X - (cellX * newCellSize); + m_PanY = point.Y - originWithoutPan.Y - (cellY * newCellSize); ClampPan(); LevelCanvas.Invalidate(); } @@ -523,11 +523,11 @@ public sealed partial class MainWindow level = level.SetProp(new(11, 4), new() { Type = EPropType.AllSeeingEyeTerminal }); level = level.SetProp(new(11, 6), new() { Type = EPropType.RemedySupply, RemedyType = ERemedyType.HeatShield }); level = level.SetUnderground(new(4, 5), ECarrierType.Coolant, new() { State = EUndergroundState.Leaking }) with { - Leaks = [new LeakState { Carrier = ECarrierType.Coolant, UndergroundPosition = new(4, 5), AccessPosition = new(4, 5) }], - Doors = [new DoorState { A = new(8, 5), B = new(9, 5), State = EDoorState.Closed }], + Leaks = [new() { Carrier = ECarrierType.Coolant, UndergroundPosition = new(4, 5), AccessPosition = new(4, 5) }], + Doors = [new() { A = new(8, 5), B = new(9, 5), State = EDoorState.Closed }], Robot = new() { Position = new(10, 5) }, Reactors = [ - new ReactorBinding { + new() { ReactorId = 1, ControlPosition = new(10, 5), FuelConsumerPosition = new(5, 3), @@ -594,12 +594,12 @@ public sealed partial class MainWindow private static Rect Inset(Rect rect, double fraction) { var inset = rect.Width * fraction; - return new(rect.X + inset, rect.Y + inset, rect.Width - inset * 2, rect.Height - inset * 2); + return new(rect.X + inset, rect.Y + inset, rect.Width - (inset * 2), rect.Height - (inset * 2)); } private static Point Center(Rect rect) { - return new(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); + return new(rect.X + (rect.Width / 2), rect.Y + (rect.Height / 2)); } private static void DrawImage(CanvasDrawingSession drawing, CanvasBitmap? image, Rect rect, float opacity = 1) @@ -699,22 +699,22 @@ public sealed partial class MainWindow private static readonly Color c_FuelColor = ColorHelper.FromArgb(255, 220, 170, 68); private static readonly Color c_CoolantColor = ColorHelper.FromArgb(255, 57, 174, 196); private static readonly Color c_ElectricityColor = ColorHelper.FromArgb(255, 236, 226, 82); + private readonly IReadOnlyList m_EditorTools = []; private readonly SimulationEngine m_Simulation = new(); private StorageFile? m_CurrentFile; - private LevelState m_Level; - private IReadOnlyList m_EditorTools = []; - private bool m_LeftPointerDown; private bool m_DragExceededClickThreshold; - private Point m_LeftPointerDownPoint; + private CanvasBitmap? m_HeatSprite; private Point m_LastPanPoint; - private GridPosition? m_SelectedCell; - private EEditorTool m_SelectedTool = EEditorTool.Cursor; - private double m_Zoom = 1; + private CanvasBitmap? m_LeakSprite; + private bool m_LeftPointerDown; + private Point m_LeftPointerDownPoint; + private LevelState m_Level; private double m_PanX; private double m_PanY; - private CanvasBitmap? m_TerrainTilemap; private CanvasBitmap? m_RobotSprite; - private CanvasBitmap? m_LeakSprite; - private CanvasBitmap? m_HeatSprite; + private GridPosition? m_SelectedCell; + private EEditorTool m_SelectedTool = EEditorTool.Cursor; + private CanvasBitmap? m_TerrainTilemap; + private double m_Zoom = 1; } \ No newline at end of file diff --git a/src/ReactorMaintenance.Win2D/ReactorMaintenance.Win2D.csproj b/src/ReactorMaintenance.Win2D/ReactorMaintenance.Win2D.csproj index 31b7c9a..1f3e746 100644 --- a/src/ReactorMaintenance.Win2D/ReactorMaintenance.Win2D.csproj +++ b/src/ReactorMaintenance.Win2D/ReactorMaintenance.Win2D.csproj @@ -17,13 +17,13 @@ - - - + + + - + diff --git a/src/ReactorMaintenance.Win2D/app.manifest b/src/ReactorMaintenance.Win2D/app.manifest index dd5896e..1e12dc3 100644 --- a/src/ReactorMaintenance.Win2D/app.manifest +++ b/src/ReactorMaintenance.Win2D/app.manifest @@ -1,10 +1,10 @@  - - - - true/pm - PerMonitorV2 - - + + + + true/pm + PerMonitorV2 + + diff --git a/tests/ReactorMaintenance.Simulation.Tests/ReactorMaintenance.Simulation.Tests.csproj b/tests/ReactorMaintenance.Simulation.Tests/ReactorMaintenance.Simulation.Tests.csproj index 89d03a6..0023d27 100644 --- a/tests/ReactorMaintenance.Simulation.Tests/ReactorMaintenance.Simulation.Tests.csproj +++ b/tests/ReactorMaintenance.Simulation.Tests/ReactorMaintenance.Simulation.Tests.csproj @@ -1,27 +1,27 @@  - - net10.0 - enable - enable + + net10.0 + enable + enable - false - true - + false + true + - - - - - - + + + + + + - - - + + + - - - + + + diff --git a/tests/ReactorMaintenance.Simulation.Tests/SimulationEngineTests.cs b/tests/ReactorMaintenance.Simulation.Tests/SimulationEngineTests.cs index 64ae36b..0cb6df5 100644 --- a/tests/ReactorMaintenance.Simulation.Tests/SimulationEngineTests.cs +++ b/tests/ReactorMaintenance.Simulation.Tests/SimulationEngineTests.cs @@ -34,7 +34,7 @@ public sealed class SimulationEngineTests { var level = LevelState.Create("Leak", 6, 6); level = level.SetUnderground(new(2, 2), ECarrierType.Fuel, new() { State = EUndergroundState.Leaking, Amount = 5, Intensity = 5 }) with { - Leaks = [new LeakState { Carrier = ECarrierType.Fuel, UndergroundPosition = new(2, 2), AccessPosition = new(2, 2) }] + Leaks = [new() { Carrier = ECarrierType.Fuel, UndergroundPosition = new(2, 2), AccessPosition = new(2, 2) }] }; level = level.SetProp(new(2, 2), new() { Type = EPropType.Flow, Carrier = ECarrierType.Fuel }); @@ -50,7 +50,7 @@ public sealed class SimulationEngineTests level = level.SetUnderground(new(2, 2), ECarrierType.Fuel, new() { State = EUndergroundState.Leaking, Amount = 5, Intensity = 5 }); level = level.SetSurface(new(2, 2), new() { Fuel = 5 }) with { Robot = new() { Position = new(2, 2), FuelNeutralizers = 1 }, - Leaks = [new LeakState { Carrier = ECarrierType.Fuel, UndergroundPosition = new(2, 2), AccessPosition = new(2, 2) }] + Leaks = [new() { Carrier = ECarrierType.Fuel, UndergroundPosition = new(2, 2), AccessPosition = new(2, 2) }] }; var next = m_Engine.InteractLeak(level, ECarrierType.Fuel, true); @@ -65,7 +65,7 @@ public sealed class SimulationEngineTests { var level = LevelState.Create("Door", 6, 6); level = level.SetSurface(new(2, 2), new() { Heat = 8 }) with { - Doors = [new DoorState { A = new(2, 2), B = new(3, 2), State = EDoorState.Closed }] + Doors = [new() { A = new(2, 2), B = new(3, 2), State = EDoorState.Closed }] }; var next = m_Engine.AdvanceTurn(level); @@ -155,11 +155,11 @@ public sealed class SimulationEngineTests { var level = LevelState.Create("Rule", 6, 6) with { RuleEvents = [ - new RuleEventState { + new() { Phase = ERuleEventPhase.EndOfTurn, ForecastText = "containment failure", - Predicates = [new RulePredicate { Kind = ERulePredicateKind.TurnAtLeast, Turn = 0 }], - Effects = [new RuleEffect { Kind = ERuleEffectKind.MarkTerminalLoss, Message = "CONTAINMENT FAILURE" }] + Predicates = [new() { Kind = ERulePredicateKind.TurnAtLeast, Turn = 0 }], + Effects = [new() { Kind = ERuleEffectKind.MarkTerminalLoss, Message = "CONTAINMENT FAILURE" }] } ] }; @@ -177,10 +177,10 @@ public sealed class SimulationEngineTests level = AddLine(level, ECarrierType.Fuel, new(2, 2), new(3, 2)); level = level.SetProp(new(2, 2), new() { Type = EPropType.Flow, Carrier = ECarrierType.Fuel }) with { RuleEvents = [ - new RuleEventState { + new() { Phase = ERuleEventPhase.EndOfTurn, - Predicates = [new RulePredicate { Kind = ERulePredicateKind.NetworkBandAt, Position = new(3, 2), Carrier = ECarrierType.Fuel, NetworkValue = ENetworkValueKind.Amount, Band = EBand.Critical }], - Effects = [new RuleEffect { Kind = ERuleEffectKind.EmitWarning, Message = "fuel pressure high" }] + Predicates = [new() { Kind = ERulePredicateKind.NetworkBandAt, Position = new(3, 2), Carrier = ECarrierType.Fuel, NetworkValue = ENetworkValueKind.Amount, Band = EBand.Critical }], + Effects = [new() { Kind = ERuleEffectKind.EmitWarning, Message = "fuel pressure high" }] } ] }; @@ -195,10 +195,10 @@ public sealed class SimulationEngineTests { var level = BuildReadyLevel() with { RuleEvents = [ - new RuleEventState { + new() { Phase = ERuleEventPhase.EndOfTurn, - Predicates = [new RulePredicate { Kind = ERulePredicateKind.ReactorReadyIs, ReactorId = 1, BoolValue = true }], - Effects = [new RuleEffect { Kind = ERuleEffectKind.EmitWarning, Message = "reactor ready rule" }] + Predicates = [new() { Kind = ERulePredicateKind.ReactorReadyIs, ReactorId = 1, BoolValue = true }], + Effects = [new() { Kind = ERuleEffectKind.EmitWarning, Message = "reactor ready rule" }] } ] }; @@ -214,10 +214,10 @@ public sealed class SimulationEngineTests var level = LevelState.Create("Inventory rule", 6, 6) with { Robot = new() { Position = new(1, 1), FuelNeutralizers = 1 }, RuleEvents = [ - new RuleEventState { + new() { Phase = ERuleEventPhase.StartOfSimulation, - Predicates = [new RulePredicate { Kind = ERulePredicateKind.RobotInventoryAtLeast, Remedy = ERemedyType.FuelNeutralizer, InventoryCount = 1 }], - Effects = [new RuleEffect { Kind = ERuleEffectKind.EmitWarning, Message = "fuel kit detected" }] + Predicates = [new() { Kind = ERulePredicateKind.RobotInventoryAtLeast, Remedy = ERemedyType.FuelNeutralizer, InventoryCount = 1 }], + Effects = [new() { Kind = ERuleEffectKind.EmitWarning, Message = "fuel kit detected" }] } ] }; @@ -234,19 +234,19 @@ public sealed class SimulationEngineTests level = level.SetSurface(new(2, 2), new() { Fuel = 5, Heat = 5 }) with { Robot = new() { Position = new(1, 1), FuelNeutralizers = 2 }, Doors = [ - new DoorState { A = new(2, 2), B = new(1, 2), State = EDoorState.Closed }, - new DoorState { A = new(2, 2), B = new(3, 2), State = EDoorState.Closed }, - new DoorState { A = new(2, 2), B = new(2, 1), State = EDoorState.Closed }, - new DoorState { A = new(2, 2), B = new(2, 3), State = EDoorState.Closed } + new() { A = new(2, 2), B = new(1, 2), State = EDoorState.Closed }, + new() { A = new(2, 2), B = new(3, 2), State = EDoorState.Closed }, + new() { A = new(2, 2), B = new(2, 1), State = EDoorState.Closed }, + new() { A = new(2, 2), B = new(2, 3), State = EDoorState.Closed } ], RuleEvents = [ - new RuleEventState { + new() { Phase = ERuleEventPhase.StartOfSimulation, - Predicates = [new RulePredicate { Kind = ERulePredicateKind.TurnAtLeast, Turn = 0 }], + Predicates = [new() { Kind = ERulePredicateKind.TurnAtLeast, Turn = 0 }], Effects = [ - new RuleEffect { Kind = ERuleEffectKind.RemoveSurfaceHazard, Position = new(2, 2), Carrier = ECarrierType.Fuel, Amount = 2 }, - new RuleEffect { Kind = ERuleEffectKind.RemoveHeat, Position = new(2, 2), Amount = 3 }, - new RuleEffect { Kind = ERuleEffectKind.RemoveInventory, Remedy = ERemedyType.FuelNeutralizer, Amount = 1 } + new() { Kind = ERuleEffectKind.RemoveSurfaceHazard, Position = new(2, 2), Carrier = ECarrierType.Fuel, Amount = 2 }, + new() { Kind = ERuleEffectKind.RemoveHeat, Position = new(2, 2), Amount = 3 }, + new() { Kind = ERuleEffectKind.RemoveInventory, Remedy = ERemedyType.FuelNeutralizer, Amount = 1 } ] } ] @@ -266,10 +266,10 @@ public sealed class SimulationEngineTests level = level.SetTerrain(new(2, 2), ECellTerrain.Wall); level = level.SetUnderground(new(2, 2), ECarrierType.Electricity, new() { State = EUndergroundState.Intact }) with { RuleEvents = [ - new RuleEventState { + new() { Phase = ERuleEventPhase.StartOfSimulation, - Predicates = [new RulePredicate { Kind = ERulePredicateKind.TurnAtLeast, Turn = 0 }], - Effects = [new RuleEffect { Kind = ERuleEffectKind.StartLeak, Position = new(2, 2), AccessPosition = new(2, 3), Carrier = ECarrierType.Electricity }] + Predicates = [new() { Kind = ERulePredicateKind.TurnAtLeast, Turn = 0 }], + Effects = [new() { Kind = ERuleEffectKind.StartLeak, Position = new(2, 2), AccessPosition = new(2, 3), Carrier = ECarrierType.Electricity }] } ] }; @@ -287,11 +287,11 @@ public sealed class SimulationEngineTests var level = LevelState.Create("Invalid rules", 6, 6); level = level.SetTerrain(new(2, 2), ECellTerrain.Wall) with { RuleEvents = [ - new RuleEventState { - Predicates = [new RulePredicate { Kind = ERulePredicateKind.PropStateAt, Position = new(1, 1) }], + new() { + Predicates = [new() { Kind = ERulePredicateKind.PropStateAt, Position = new(1, 1) }], Effects = [ - new RuleEffect { Kind = ERuleEffectKind.AddSurfaceHazard, Position = new(2, 2), Carrier = ECarrierType.Fuel, Amount = 1 }, - new RuleEffect { Kind = ERuleEffectKind.RepairNetworkCell, Position = new(3, 3), Carrier = ECarrierType.Coolant } + new() { Kind = ERuleEffectKind.AddSurfaceHazard, Position = new(2, 2), Carrier = ECarrierType.Fuel, Amount = 1 }, + new() { Kind = ERuleEffectKind.RepairNetworkCell, Position = new(3, 3), Carrier = ECarrierType.Coolant } ] } ] @@ -312,7 +312,7 @@ public sealed class SimulationEngineTests level = level.SetTerrain(new(2, 2), ECellTerrain.Wall); level = level with { Surface = level.Surface.ToArray(), - Reactors = [new ReactorBinding { ControlPosition = new(3, 3), FuelConsumerPosition = new(1, 1), CoolantConsumerPosition = new(1, 1), ElectricityConsumerPosition = new(1, 1) }] + Reactors = [new() { ControlPosition = new(3, 3), FuelConsumerPosition = new(1, 1), CoolantConsumerPosition = new(1, 1), ElectricityConsumerPosition = new(1, 1) }] }; level.Surface[level.Index(new(2, 2))] = new() { Heat = 1 }; @@ -367,7 +367,7 @@ public sealed class SimulationEngineTests return level with { Robot = new() { Position = new(5, 3) }, Reactors = [ - new ReactorBinding { + new() { ReactorId = 1, ControlPosition = new(5, 3), FuelConsumerPosition = new(3, 2),