From 4c6615d5455cbafea969d7dc0be945ea6f0b699b Mon Sep 17 00:00:00 2001 From: valkyrienyanko Date: Tue, 20 Aug 2024 15:45:12 -0500 Subject: [PATCH] Run code cleanup --- .editorconfig | 36 +++++----- Scripts/Autoloads/AudioManager.cs | 6 +- Scripts/Autoloads/OptionsManager.cs | 34 +++++----- Scripts/CameraController.cs | 4 +- Scripts/Chunk.cs | 91 +++++++++++++------------- Scripts/Geometry/Icosahedron.cs | 2 +- Scripts/Geometry/World3DUtils.cs | 14 ++-- Scripts/Planet.cs | 14 ++-- Scripts/UI/Options/UIOptionsAudio.cs | 4 +- Scripts/UI/Options/UIOptionsDisplay.cs | 20 ++---- Scripts/UI/Options/UIOptionsGeneral.cs | 4 +- Scripts/UI/Options/UIOptionsInput.cs | 26 ++++---- Scripts/UI/Options/UIOptionsNav.cs | 2 +- Scripts/UI/UICredits.cs | 22 +++---- 14 files changed, 139 insertions(+), 140 deletions(-) diff --git a/.editorconfig b/.editorconfig index e801fa9..896c9db 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ tab_width = 4 # New line preferences end_of_line = crlf -insert_final_newline = true +insert_final_newline = false #### .NET Coding Conventions #### @@ -43,13 +43,14 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members # Expression-level preferences dotnet_style_coalesce_expression = true -dotnet_style_collection_initializer = false:silent +dotnet_style_collection_initializer = true dotnet_style_explicit_tuple_names = true dotnet_style_namespace_match_folder = true dotnet_style_null_propagation = true -dotnet_style_object_initializer = false:silent +dotnet_style_object_initializer = true dotnet_style_operator_placement_when_wrapping = beginning_of_line dotnet_style_prefer_auto_properties = true +dotnet_style_prefer_collection_expression = when_types_loosely_match dotnet_style_prefer_compound_assignment = true dotnet_style_prefer_conditional_expression_over_assignment = true dotnet_style_prefer_conditional_expression_over_return = true @@ -76,9 +77,9 @@ dotnet_style_allow_statement_immediately_after_block_experimental = false #### C# Coding Conventions #### # var preferences -csharp_style_var_elsewhere = true -csharp_style_var_for_built_in_types = true -csharp_style_var_when_type_is_apparent = true +csharp_style_var_elsewhere = false +csharp_style_var_for_built_in_types = false +csharp_style_var_when_type_is_apparent = false # Expression-bodied members csharp_style_expression_bodied_accessors = true @@ -86,9 +87,9 @@ csharp_style_expression_bodied_constructors = false csharp_style_expression_bodied_indexers = true csharp_style_expression_bodied_lambdas = true csharp_style_expression_bodied_local_functions = true:suggestion -csharp_style_expression_bodied_methods = false -csharp_style_expression_bodied_operators = true:suggestion -csharp_style_expression_bodied_properties = false +csharp_style_expression_bodied_methods = false:suggestion +csharp_style_expression_bodied_operators = true +csharp_style_expression_bodied_properties = true # Pattern matching preferences csharp_style_pattern_matching_over_as_with_null_check = true @@ -102,14 +103,18 @@ csharp_style_prefer_switch_expression = true csharp_style_conditional_delegate_call = true # Modifier preferences -csharp_prefer_static_local_function = true -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_prefer_static_anonymous_function = true +csharp_prefer_static_local_function = false:silent +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_style_prefer_readonly_struct = true +csharp_style_prefer_readonly_struct_member = true # Code-block preferences -csharp_prefer_braces = false +csharp_prefer_braces = true csharp_prefer_simple_using_statement = true -csharp_style_namespace_declarations = file_scoped +csharp_style_namespace_declarations = file_scoped:error csharp_style_prefer_method_group_conversion = false +csharp_style_prefer_primary_constructors = true csharp_style_prefer_top_level_statements = true # Expression-level preferences @@ -132,6 +137,8 @@ csharp_using_directive_placement = outside_namespace # New line preferences csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false csharp_style_allow_embedded_statements_on_same_line_experimental = true @@ -223,6 +230,3 @@ 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.capitalization = pascal_case - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = none diff --git a/Scripts/Autoloads/AudioManager.cs b/Scripts/Autoloads/AudioManager.cs index fca76cd..05837cc 100644 --- a/Scripts/Autoloads/AudioManager.cs +++ b/Scripts/Autoloads/AudioManager.cs @@ -29,7 +29,7 @@ public static void PlayMusic(AudioStream song, bool instant = true, double fadeO }); // Fade in to current song - var volume = Options.MusicVolume; + float volume = Options.MusicVolume; var volumeRemapped = volume == 0 ? -80 : volume.Remap(0, 100, -40, 0); tween.Animate("volume_db", volumeRemapped, fadeIn) .SetTrans(Tween.TransitionType.Sine) @@ -54,9 +54,9 @@ public static void PlaySFX(AudioStream sound) }; // Randomize the pitch - var rng = new RandomNumberGenerator(); + RandomNumberGenerator rng = new(); rng.Randomize(); - var pitch = rng.RandfRange(0.8f, 1.2f); + float pitch = rng.RandfRange(0.8f, 1.2f); // Ensure the current pitch is not the same as the last while (Mathf.Abs(pitch - LastPitch) < 0.1f) diff --git a/Scripts/Autoloads/OptionsManager.cs b/Scripts/Autoloads/OptionsManager.cs index 0020279..d068bc0 100644 --- a/Scripts/Autoloads/OptionsManager.cs +++ b/Scripts/Autoloads/OptionsManager.cs @@ -15,7 +15,7 @@ public partial class OptionsManager : Node public static void SaveOptions() { - var error = ResourceSaver.Save(OptionsManager.Options, "user://options.tres"); + Error error = ResourceSaver.Save(OptionsManager.Options, "user://options.tres"); if (error != Error.Ok) GD.Print(error); @@ -23,7 +23,7 @@ public static void SaveOptions() public static void SaveHotkeys() { - var error = ResourceSaver.Save(OptionsManager.Hotkeys, "user://hotkeys.tres"); + Error error = ResourceSaver.Save(OptionsManager.Hotkeys, "user://hotkeys.tres"); if (error != Error.Ok) GD.Print(error); @@ -34,11 +34,11 @@ public static void ResetHotkeys() // Deep clone default hotkeys over Hotkeys.Actions = new(); - foreach (var element in DefaultHotkeys) + foreach (KeyValuePair> element in DefaultHotkeys) { - var arr = new Array(); + Array arr = new(); - foreach (var item in DefaultHotkeys[element.Key]) + foreach (InputEvent item in DefaultHotkeys[element.Key]) { arr.Add((InputEvent)item.Duplicate()); } @@ -85,7 +85,7 @@ public override void _Input(InputEvent @event) private void LoadOptions() { - var fileExists = FileAccess.FileExists("user://options.tres"); + bool fileExists = FileAccess.FileExists("user://options.tres"); Options = fileExists ? GD.Load("user://options.tres") : new(); @@ -93,16 +93,16 @@ private void LoadOptions() private static void LoadInputMap(Dictionary> hotkeys) { - var actions = InputMap.GetActions(); + Array actions = InputMap.GetActions(); - foreach (var action in actions) + foreach (StringName action in actions) InputMap.EraseAction(action); - foreach (var action in hotkeys.Keys) + foreach (StringName action in hotkeys.Keys) { InputMap.AddAction(action); - foreach (var @event in hotkeys[action]) + foreach (InputEvent @event in hotkeys[action]) InputMap.ActionAddEvent(action, @event); } } @@ -110,13 +110,13 @@ private static void LoadInputMap(Dictionary> hotke private void GetDefaultHotkeys() { // Get all the default actions defined in the input map - var actions = new Dictionary>(); + Dictionary> actions = new(); - foreach (var action in InputMap.GetActions()) + foreach (StringName action in InputMap.GetActions()) { actions.Add(action, new Array()); - foreach (var actionEvent in InputMap.ActionGetEvents(action)) + foreach (InputEvent actionEvent in InputMap.ActionGetEvents(action)) actions[action].Add(actionEvent); } @@ -125,7 +125,7 @@ private void GetDefaultHotkeys() private void LoadHotkeys() { - var fileExists = FileAccess.FileExists("user://hotkeys.tres"); + bool fileExists = FileAccess.FileExists("user://hotkeys.tres"); if (fileExists) { @@ -164,9 +164,9 @@ private void SetWinSize() DisplayServer.WindowSetSize(Options.WindowSize); // center window - var screenSize = DisplayServer.ScreenGetSize(); - var winSize = DisplayServer.WindowGetSize(); - DisplayServer.WindowSetPosition(screenSize / 2 - winSize / 2); + Vector2I screenSize = DisplayServer.ScreenGetSize(); + Vector2I winSize = DisplayServer.WindowGetSize(); + DisplayServer.WindowSetPosition((screenSize / 2) - (winSize / 2)); } } diff --git a/Scripts/CameraController.cs b/Scripts/CameraController.cs index a07d16c..ed547cd 100644 --- a/Scripts/CameraController.cs +++ b/Scripts/CameraController.cs @@ -42,9 +42,9 @@ private void Rotate(InputEventMouseMotion motion) if (!HoldingLeftClick) return; - var vel = motion.Relative * Sensitivity; + Vector2 vel = motion.Relative * Sensitivity; - var rot = Rotation; + Vector3 rot = Rotation; rot.X -= vel.Y; rot.Y -= vel.X; diff --git a/Scripts/Chunk.cs b/Scripts/Chunk.cs index 8404657..70d670c 100644 --- a/Scripts/Chunk.cs +++ b/Scripts/Chunk.cs @@ -8,10 +8,10 @@ public Chunk(Node parent, Vector3 posA, Vector3 posB, Vector3 posC, int resoluti { Parent = parent; - var vertices = BuildVertices(posA, posB, posC, resolution); - var indices = BuildIndices(resolution); + Vector3[] vertices = BuildVertices(posA, posB, posC, resolution); + int[] indices = BuildIndices(resolution); - var gMesh = new GMesh(vertices, indices) + GMesh gMesh = new(vertices, indices) { SimpleNormals = false, Colors = GenerateColors(vertices) @@ -29,15 +29,15 @@ public Chunk(Node parent, Vector3 posA, Vector3 posB, Vector3 posC, int resoluti private Color[] GenerateColors(Vector3[] vertices) { - var noise = new FastNoiseLite + FastNoiseLite noise = new() { Frequency = 0.2f }; - var colors = new Color[vertices.Length]; + Color[] colors = new Color[vertices.Length]; for (int i = 0; i < colors.Length; i++) { - var n = 1 + noise.GetNoise3Dv(vertices[i]) * 10; + float n = 1 + (noise.GetNoise3Dv(vertices[i]) * 10); if (vertices[i].Length() > 9.5f) colors[i] = new Color("316231"); // grass @@ -50,18 +50,19 @@ private Color[] GenerateColors(Vector3[] vertices) private Vector3[] BuildVertices(Vector3 posA, Vector3 posB, Vector3 posC, int res) { - var vertices = new List(); - - // The 3 main corners - vertices.Add(posA); - vertices.Add(posB); - vertices.Add(posC); + List vertices = new() + { + // The 3 main corners + posA, + posB, + posC + }; // The edge midpoints if (res >= 1) { - var edgeMidpointsLeft = GenerateEdgeMidPoints(posA, posC, res); - var edgeMidpointsRight = GenerateEdgeMidPoints(posA, posB, res); + Vector3[] edgeMidpointsLeft = GenerateEdgeMidPoints(posA, posC, res); + Vector3[] edgeMidpointsRight = GenerateEdgeMidPoints(posA, posB, res); vertices.AddRange(edgeMidpointsLeft); // left vertices.AddRange(edgeMidpointsRight); // right @@ -79,17 +80,17 @@ private Vector3[] BuildVertices(Vector3 posA, Vector3 posB, Vector3 posC, int re private List DeformVertices(List vertices) { - var noise = new FastNoiseLite + FastNoiseLite noise = new() { Frequency = 0.003f }; - var noiseStrength = 1000; - var planetRadius = 10; + int noiseStrength = 1000; + int planetRadius = 10; for (int i = 0; i < vertices.Count; i++) { - var n = noise.GetNoise3Dv(vertices[i] * noiseStrength); + float n = noise.GetNoise3Dv(vertices[i] * noiseStrength); vertices[i] = vertices[i].Normalized() * (planetRadius + n); } @@ -99,7 +100,7 @@ private List DeformVertices(List vertices) private int[] BuildIndices(int res) { - var indices = new List(); + List indices = new(); // If the resolution is 0 then there are no midpoints and thus there // is only 1 triangle @@ -111,24 +112,24 @@ private int[] BuildIndices(int res) // Index Legend // The 3 main corners - var topMiddle = 0; - var bottomRight = 1; - var bottomLeft = 2; + int topMiddle = 0; + int bottomRight = 1; + int bottomLeft = 2; // The first point in each midpoint array - var leftFirst = 3; // top left - var rightFirst = 3 + res; // top right - var bottomFirst = 3 + res * 2; // bottom right + int leftFirst = 3; // top left + int rightFirst = 3 + res; // top right + int bottomFirst = 3 + (res * 2); // bottom right // The center points - var center = 3 + res * 3; + int center = 3 + (res * 3); var centerBottomRight = center + GUMath.SumNaturalNumbers(res) - 1; var centerBottomLeft = centerBottomRight - res + 2; // The last point in each midpoint array - var leftLast = rightFirst - 1; - var rightLast = bottomFirst - 1; - var bottomLast = 3 + res * 3 - 1; + int leftLast = rightFirst - 1; + int rightLast = bottomFirst - 1; + int bottomLast = 3 + (res * 3) - 1; // Resolution can be greater than or equal to 1 here // Draw the corner triangles @@ -148,9 +149,9 @@ private int[] BuildIndices(int res) indices.AddRange(new int[] { centerBottomRight, rightLast, bottomFirst }); // Draw the outer edge triangles - var triOuterEdgeRight = IndicesOuterEdgeRight(res, rightFirst, center); - var triOuterEdgeLeft = IndicesOuterEdgeLeft(res, leftFirst, center); - var triOuterBottom = IndicesOuterBottom(res, bottomFirst, centerBottomRight); + List triOuterEdgeRight = IndicesOuterEdgeRight(res, rightFirst, center); + List triOuterEdgeLeft = IndicesOuterEdgeLeft(res, leftFirst, center); + List triOuterBottom = IndicesOuterBottom(res, bottomFirst, centerBottomRight); indices.AddRange(triOuterEdgeRight); indices.AddRange(triOuterEdgeLeft); @@ -160,7 +161,7 @@ private int[] BuildIndices(int res) if (res >= 3) { // Draw the center triangles - var triCenter = IndicesCenter(res, center); + List triCenter = IndicesCenter(res, center); indices.AddRange(triCenter); } @@ -170,7 +171,7 @@ private int[] BuildIndices(int res) private List IndicesOuterEdgeRight(int res, int rightFirst, int center) { - var indices = new List(); + List indices = new(); // Outer Right Edge Triangles // Upside @@ -200,7 +201,7 @@ private List IndicesOuterEdgeRight(int res, int rightFirst, int center) private List IndicesOuterEdgeLeft(int res, int leftFirst, int center) { - var indices = new List(); + List indices = new(); // Outer Left Edge Triangles // Upside @@ -230,7 +231,7 @@ private List IndicesOuterEdgeLeft(int res, int leftFirst, int center) private List IndicesOuterBottom(int res, int bottomFirst, int centerBottomRight) { - var indices = new List(); + List indices = new(); // Outer Bottom Edge Triangles // Upside @@ -260,7 +261,7 @@ private List IndicesOuterBottom(int res, int bottomFirst, int centerBottomR private List IndicesCenter(int res, int center) { - var indices = new List(); + List indices = new(); // Center Triangles // Upside @@ -304,17 +305,17 @@ private List IndicesCenter(int res, int center) private Vector3[] GenerateCenterPoints(Vector3[] edgeMidpointsLeft, Vector3[] edgeMidpointsRight, int resolution) { - var centerPoints = new Vector3[GUMath.SumNaturalNumbers(resolution)]; - - var index = 0; + Vector3[] centerPoints = new Vector3[GUMath.SumNaturalNumbers(resolution)]; + + int index = 0; for (int row = 1; row < resolution; row++) { for (int i = 0; i < row; i++) { - var t = (float)(i + 1) / (row + 1); + float t = (float)(i + 1) / (row + 1); - var pos = edgeMidpointsLeft[row].Lerp(edgeMidpointsRight[row], t); + Vector3 pos = edgeMidpointsLeft[row].Lerp(edgeMidpointsRight[row], t); centerPoints[index++] = pos; } @@ -325,13 +326,13 @@ private Vector3[] GenerateCenterPoints(Vector3[] edgeMidpointsLeft, Vector3[] ed private Vector3[] GenerateEdgeMidPoints(Vector3 posA, Vector3 posB, int resolution) { - var points = new Vector3[resolution]; + Vector3[] points = new Vector3[resolution]; for (int i = 0; i < resolution; i++) { // Calculate mid points - var t = (i + 1f) / (resolution + 1f); - var pos = posA.Lerp(posB, t); + float t = (i + 1f) / (resolution + 1f); + Vector3 pos = posA.Lerp(posB, t); points[i] = pos; } diff --git a/Scripts/Geometry/Icosahedron.cs b/Scripts/Geometry/Icosahedron.cs index 5cf48e6..7b3f25e 100644 --- a/Scripts/Geometry/Icosahedron.cs +++ b/Scripts/Geometry/Icosahedron.cs @@ -7,7 +7,7 @@ public class Icosahedron public Icosahedron(float radius = 1) { - var t = (1.0f + Mathf.Sqrt(5.0f)) / 2.0f; + float t = (1.0f + Mathf.Sqrt(5.0f)) / 2.0f; Vertices = new Vector3[] { diff --git a/Scripts/Geometry/World3DUtils.cs b/Scripts/Geometry/World3DUtils.cs index a0308ac..27aacd2 100644 --- a/Scripts/Geometry/World3DUtils.cs +++ b/Scripts/Geometry/World3DUtils.cs @@ -5,8 +5,8 @@ public class GMesh public bool SimpleNormals { get; set; } public Color[] Colors { get; set; } - private Vector3[] vertices; - private int[] indices; + private readonly Vector3[] vertices; + private readonly int[] indices; public GMesh(Vector3[] vertices, int[] indices) { @@ -19,11 +19,11 @@ public Mesh Generate() => SimpleNormals ? private Mesh GenerateWithSimpleNormals() { - var arrays = new Godot.Collections.Array(); + Godot.Collections.Array arrays = new(); arrays.Resize((int)Mesh.ArrayType.Max); arrays[(int)Mesh.ArrayType.Vertex] = vertices; - var normals = new Vector3[vertices.Length]; + Vector3[] normals = new Vector3[vertices.Length]; for (int i = 0; i < normals.Length; i++) normals[i] = vertices[i].Normalized(); @@ -36,7 +36,7 @@ private Mesh GenerateWithSimpleNormals() arrays[(int)Mesh.ArrayType.Index] = indices; - var mesh = new ArrayMesh(); + ArrayMesh mesh = new(); mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays); return mesh; @@ -44,7 +44,7 @@ private Mesh GenerateWithSimpleNormals() private Mesh GenerateWithComplexNormals() { - var st = new SurfaceTool(); + SurfaceTool st = new(); st.Begin(Mesh.PrimitiveType.Triangles); for (int i = 0; i < vertices.Length; i++) @@ -55,7 +55,7 @@ private Mesh GenerateWithComplexNormals() st.AddVertex(vertices[i]); } - foreach (var index in indices) + foreach (int index in indices) st.AddIndex(index); st.GenerateNormals(); diff --git a/Scripts/Planet.cs b/Scripts/Planet.cs index 9528265..93b2bf0 100644 --- a/Scripts/Planet.cs +++ b/Scripts/Planet.cs @@ -6,19 +6,19 @@ public override void _Ready() { //GetViewport().DebugDraw = Viewport.DebugDrawEnum.Overdraw; - var icosahedron = new Icosahedron(); - var vertices = icosahedron.Vertices; - var indices = icosahedron.Triangles; + Icosahedron icosahedron = new(); + Vector3[] vertices = icosahedron.Vertices; + int[] indices = icosahedron.Triangles; - var resolution = 128; + int resolution = 128; Logger.LogMs(() => { for (int i = 0; i < indices.Length; i += 3) { - var posA = vertices[indices[i]]; - var posB = vertices[indices[i + 1]]; - var posC = vertices[indices[i + 2]]; + Vector3 posA = vertices[indices[i]]; + Vector3 posB = vertices[indices[i + 1]]; + Vector3 posC = vertices[indices[i + 2]]; new Chunk(this, posA, posB, posC, resolution); } diff --git a/Scripts/UI/Options/UIOptionsAudio.cs b/Scripts/UI/Options/UIOptionsAudio.cs index bd8dcfb..cd2e495 100644 --- a/Scripts/UI/Options/UIOptionsAudio.cs +++ b/Scripts/UI/Options/UIOptionsAudio.cs @@ -14,13 +14,13 @@ public override void _Ready() private void SetupMusic() { - var slider = GetNode("Music/Music"); + HSlider slider = GetNode("Music/Music"); slider.Value = Options.MusicVolume; } private void SetupSounds() { - var slider = GetNode("Sounds/Sounds"); + HSlider slider = GetNode("Sounds/Sounds"); slider.Value = Options.SFXVolume; } diff --git a/Scripts/UI/Options/UIOptionsDisplay.cs b/Scripts/UI/Options/UIOptionsDisplay.cs index fd007bb..059df4d 100644 --- a/Scripts/UI/Options/UIOptionsDisplay.cs +++ b/Scripts/UI/Options/UIOptionsDisplay.cs @@ -41,10 +41,7 @@ private void SetupMaxFPS() SliderMaxFPS = GetNode("MaxFPS/HBox/MaxFPS"); SliderMaxFPS.Value = Options.MaxFPS; - if (Options.VSyncMode != DisplayServer.VSyncMode.Disabled) - SliderMaxFPS.Editable = false; - else - SliderMaxFPS.Editable = true; + SliderMaxFPS.Editable = Options.VSyncMode == VSyncMode.Disabled; } private void SetupWindowSize() @@ -52,7 +49,7 @@ private void SetupWindowSize() ResX = GetNode("WindowSize/HBox/WindowWidth"); ResY = GetNode("WindowSize/HBox/WindowHeight"); - var winSize = DisplayServer.WindowGetSize(); + Vector2I winSize = DisplayServer.WindowGetSize(); PrevNumX = winSize.X; PrevNumY = winSize.Y; @@ -81,8 +78,8 @@ private void ApplyWindowSize() DisplayServer.WindowSetSize(new Vector2I(PrevNumX, PrevNumY)); // Center window - var winSize = DisplayServer.WindowGetSize(); - DisplayServer.WindowSetPosition(DisplayServer.ScreenGetSize() / 2 - winSize / 2); + Vector2I winSize = DisplayServer.WindowGetSize(); + DisplayServer.WindowSetPosition((DisplayServer.ScreenGetSize() / 2) - (winSize / 2)); OptionsManager.Options.WindowSize = winSize; } @@ -106,7 +103,7 @@ private void _on_window_mode_item_selected(int index) } // Update UIWindowSize element on window mode change - var winSize = DisplayServer.WindowGetSize(); + Vector2I winSize = DisplayServer.WindowGetSize(); ResX.Text = winSize.X + ""; ResY.Text = winSize.Y + ""; @@ -138,14 +135,11 @@ private void _on_window_height_text_changed(string text) => private void _on_v_sync_mode_item_selected(int index) { - var vsyncMode = (DisplayServer.VSyncMode)index; + VSyncMode vsyncMode = (DisplayServer.VSyncMode)index; DisplayServer.WindowSetVsyncMode(vsyncMode); Options.VSyncMode = vsyncMode; - if (Options.VSyncMode != DisplayServer.VSyncMode.Disabled) - SliderMaxFPS.Editable = false; - else - SliderMaxFPS.Editable = true; + SliderMaxFPS.Editable = Options.VSyncMode == VSyncMode.Disabled; } private void _on_max_fps_value_changed(float value) diff --git a/Scripts/UI/Options/UIOptionsGeneral.cs b/Scripts/UI/Options/UIOptionsGeneral.cs index c825182..4e0334b 100644 --- a/Scripts/UI/Options/UIOptionsGeneral.cs +++ b/Scripts/UI/Options/UIOptionsGeneral.cs @@ -13,13 +13,13 @@ public override void _Ready() private void SetupLanguage() { - var optionButtonLanguage = GetNode("Language/Language"); + OptionButton optionButtonLanguage = GetNode("Language/Language"); optionButtonLanguage.Select((int)Options.Language); } private void _on_language_item_selected(int index) { - var locale = ((Language)index).ToString().Substring(0, 2).ToLower(); + string locale = ((Language)index).ToString().Substring(0, 2).ToLower(); TranslationServer.SetLocale(locale); diff --git a/Scripts/UI/Options/UIOptionsInput.cs b/Scripts/UI/Options/UIOptionsInput.cs index 8bb2034..591c34a 100644 --- a/Scripts/UI/Options/UIOptionsInput.cs +++ b/Scripts/UI/Options/UIOptionsInput.cs @@ -20,7 +20,7 @@ public override void _Input(InputEvent @event) { if (Input.IsActionJustPressed("remove_hotkey")) { - var action = BtnNewInput.Action; + StringName action = BtnNewInput.Action; // Update input map InputMap.ActionEraseEvent(action, BtnNewInput.InputEvent); @@ -74,7 +74,7 @@ public override void _Input(InputEvent @event) private void HandleInput(InputEvent @event) { - var action = BtnNewInput.Action; + StringName action = BtnNewInput.Action; // Prevent something very evil from happening! if (action == "fullscreen" && @event is InputEventMouseButton eventBtn) @@ -83,19 +83,19 @@ private void HandleInput(InputEvent @event) // Re-create the button // Preserve the index the button was originally at - var index = BtnNewInput.Btn.GetIndex(); + int index = BtnNewInput.Btn.GetIndex(); // Destroy the button BtnNewInput.Btn.QueueFree(); // Create the button - var btn = CreateButton(action, @event, BtnNewInput.HBox); + Button btn = CreateButton(action, @event, BtnNewInput.HBox); btn.Disabled = false; // Move the button to where it was originally at BtnNewInput.HBox.MoveChild(btn, index); - var actions = OptionsManager.Hotkeys.Actions; + Dictionary> actions = OptionsManager.Hotkeys.Actions; // Clear the specific action event actions[action].Remove(BtnNewInput.InputEvent); @@ -115,7 +115,7 @@ private void HandleInput(InputEvent @event) private Button CreateButton(string action, InputEvent inputEvent, HBoxContainer hbox) { - var readable = ""; + string readable = ""; if (inputEvent is InputEventKey key) { @@ -188,9 +188,9 @@ private void CreateButtonPlus(string action, HBoxContainer hbox) private void CreateHotkeys() { // Loop through the actions in alphabetical order - foreach (var action in OptionsManager.Hotkeys.Actions.Keys.OrderBy(x => x.ToString())) + foreach (StringName action in OptionsManager.Hotkeys.Actions.Keys.OrderBy(x => x.ToString())) { - var actionStr = action.ToString(); + string actionStr = action.ToString(); // Exlucde "remove_hotkey" action if (actionStr == "remove_hotkey") @@ -200,10 +200,10 @@ private void CreateHotkeys() if (actionStr.StartsWith("ui")) continue; - var hbox = new HBoxContainer(); + HBoxContainer hbox = new(); // For example convert ui_left to UI_LEFT - var name = action.ToString().ToUpper(); + string name = action.ToString().ToUpper(); // Add the action label. For example 'UI Left' hbox.AddChild(new GLabel(name) @@ -213,11 +213,11 @@ private void CreateHotkeys() }); // Add all the events after the action label - var hboxEvents = new HBoxContainer(); + HBoxContainer hboxEvents = new(); - var events = OptionsManager.Hotkeys.Actions[action]; + Array events = OptionsManager.Hotkeys.Actions[action]; - foreach (var @event in events) + foreach (InputEvent @event in events) { // Handle keys if (@event is InputEventKey eventKey) diff --git a/Scripts/UI/Options/UIOptionsNav.cs b/Scripts/UI/Options/UIOptionsNav.cs index 26b5055..32c5611 100644 --- a/Scripts/UI/Options/UIOptionsNav.cs +++ b/Scripts/UI/Options/UIOptionsNav.cs @@ -6,7 +6,7 @@ public partial class UIOptionsNav : Control public override void _Ready() { - var content = GetParent().GetNode("Content"); + Node content = GetParent().GetNode("Content"); foreach (Control child in content.GetChildren()) Tabs.Add(child.Name, child); diff --git a/Scripts/UI/UICredits.cs b/Scripts/UI/UICredits.cs index 0e2f8c1..53e9ead 100644 --- a/Scripts/UI/UICredits.cs +++ b/Scripts/UI/UICredits.cs @@ -19,15 +19,15 @@ public override void _Ready() SizeFlagsVertical = Control.SizeFlags.ShrinkBegin }; - var file = FileAccess.Open("res://credits.txt", FileAccess.ModeFlags.Read); + FileAccess file = FileAccess.Open("res://credits.txt", FileAccess.ModeFlags.Read); while (!file.EofReached()) { - var line = Tr(file.GetLine()); + string line = Tr(file.GetLine()); - var translatedLine = ""; + string translatedLine = ""; - foreach (var word in line.Split(' ')) + foreach (string word in line.Split(' ')) translatedLine += Tr(word) + " "; if (translatedLine.Contains("http")) @@ -44,13 +44,13 @@ public override void _Ready() AddChild(VBox); VBox.Position = new Vector2( - DisplayServer.WindowGetSize().X / 2 - VBox.Size.X / 2, + (DisplayServer.WindowGetSize().X / 2) - (VBox.Size.X / 2), DisplayServer.WindowGetSize().Y); } public override void _PhysicsProcess(double delta) { - var pos = VBox.Position; + Vector2 pos = VBox.Position; pos.Y -= Speed; VBox.Position = pos; @@ -72,12 +72,12 @@ public override void _Input(InputEvent @event) private void AddTextWithLink(string text) { - var indexOfHttp = text.IndexOf("http"); + int indexOfHttp = text.IndexOf("http"); - var textDesc = text.Substring(0, indexOfHttp); - var textLink = text.Substring(indexOfHttp); + string textDesc = text.Substring(0, indexOfHttp); + string textLink = text.Substring(indexOfHttp); - var hbox = new HBoxContainer + HBoxContainer hbox = new() { SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter }; @@ -109,7 +109,7 @@ private void _on_pause_pressed() private void _on_speed_pressed() { - var numSpeeds = 3; + int numSpeeds = 3; for (int i = 1; i < numSpeeds; i++) if (Speed == i)