Skip to content

Commit

Permalink
🚿 Clean some coding style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
paulloz committed May 19, 2024
1 parent 0edca8d commit 4e912e2
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 45 deletions.
17 changes: 15 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ dotnet_naming_rule.non_field_members.severity = warning
dotnet_naming_rule.non_field_members.symbols = non_field_members
dotnet_naming_rule.non_field_members.style = pascal_case

dotnet_naming_rule.private_fields.severity = silent
dotnet_naming_rule.private_fields.severity = warning
dotnet_naming_rule.private_fields.symbols = private_fields
dotnet_naming_rule.private_fields.style = prefix_underscore
dotnet_naming_rule.private_fields.style = camel_case

dotnet_naming_rule.constants.severity = warning
dotnet_naming_rule.constants.symbols = constant_fields
dotnet_naming_rule.constants.style = constant_style

dotnet_naming_rule.static_readonly.severity = warning
dotnet_naming_rule.static_readonly.symbols = static_readonly_fields
dotnet_naming_rule.static_readonly.style = constant_style

dotnet_naming_rule.type_parameters.severity = warning
dotnet_naming_rule.type_parameters.symbols = type_parameters
dotnet_naming_rule.type_parameters.style = prefix_T
Expand All @@ -142,6 +146,10 @@ dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.static_readonly_fields.applicable_accessibilities = *
dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly

dotnet_naming_symbols.type_parameters.applicable_kinds = type_parameter
dotnet_naming_symbols.type_parameters.applicable_accessibilities = *
dotnet_naming_symbols.type_parameters.required_modifiers =
Expand All @@ -153,6 +161,11 @@ 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.camel_case.required_prefix =
dotnet_naming_style.camel_case.required_suffix =
dotnet_naming_style.camel_case.word_separator =
dotnet_naming_style.camel_case.capitalization = camel_case

dotnet_naming_style.prefix_I.required_prefix = I
dotnet_naming_style.prefix_I.required_suffix =
dotnet_naming_style.prefix_I.word_separator =
Expand Down
5 changes: 5 additions & 0 deletions GodotInk.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantEmptyObjectCreationArgumentList/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVarWhenEvident</s:String></wpf:ResourceDictionary>
10 changes: 5 additions & 5 deletions addons/GodotInk/Src/InkChoice.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ public partial class InkChoice
{
#pragma warning disable IDE0022
/// <summary>
/// This method is here for GDScript compatibility. Use <see cref="CanContinue" /> instead.
/// This method is here for GDScript compatibility. Use <see cref="Text" /> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetText() => Text;

/// <summary>
/// This method is here for GDScript compatibility. Use <see cref="CanContinue" /> instead.
/// This method is here for GDScript compatibility. Use <see cref="PathStringOnChoice" /> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetPathStringOnChoice() => PathStringOnChoice;

/// <summary>
/// This method is here for GDScript compatibility. Use <see cref="CanContinue" /> instead.
/// This method is here for GDScript compatibility. Use <see cref="SourcePath" /> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetSourcePath() => SourcePath;

/// <summary>
/// This method is here for GDScript compatibility. Use <see cref="CanContinue" /> instead.
/// This method is here for GDScript compatibility. Use <see cref="Index" /> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int GetIndex() => Index;

/// <summary>
/// This method is here for GDScript compatibility. Use <see cref="CanContinue" /> instead.
/// This method is here for GDScript compatibility. Use <see cref="Tags" /> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public Godot.Collections.Array<string> GetTags() => new(Tags);
Expand Down
19 changes: 10 additions & 9 deletions addons/GodotInk/Src/InkDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ public override void _Ready()
scroll = GetNode<ScrollContainer>("Container/Left/Scroll");

// Set icons.
loadButton.Icon = GetThemeIcon("Load", "EditorIcons");
startButton.Icon = GetThemeIcon("Play", "EditorIcons");
stopButton.Icon = GetThemeIcon("Stop", "EditorIcons");
clearButton.Icon = GetThemeIcon("Clear", "EditorIcons");
var editorTheme = EditorInterface.Singleton.GetEditorTheme();
loadButton.Icon = editorTheme.GetIcon("Load", "EditorIcons");
startButton.Icon = editorTheme.GetIcon("Play", "EditorIcons");
stopButton.Icon = editorTheme.GetIcon("Stop", "EditorIcons");
clearButton.Icon = editorTheme.GetIcon("Clear", "EditorIcons");

// Update UI.
UpdateTop();
Expand Down Expand Up @@ -157,7 +158,7 @@ private void ContinueStory()

if (currentText.Length > 0)
{
Label newLine = new()
var newLine = new Label()
{
AutowrapMode = TextServer.AutowrapMode.WordSmart,
Text = currentText,
Expand All @@ -182,7 +183,7 @@ private void ContinueStory()
Button button = new() { Text = choice.Text };
button.SetMeta(CHOICE_INDEX_META, choice.Index);

button.Connect(Button.SignalName.Pressed, Callable.From(ClickChoice));
button.Connect(BaseButton.SignalName.Pressed, Callable.From(ClickChoice));

storyChoices.AddChild(button);
}
Expand All @@ -192,7 +193,7 @@ private void ContinueStory()

private void ClickChoice()
{
if (storyChoices.GetChildren().OfType<Button>().First(button => button.ButtonPressed) is not Button button) return;
if (storyChoices.GetChildren().OfType<Button>().First(b => b.ButtonPressed) is not { } button) return;
if (!button.HasMeta(CHOICE_INDEX_META)) return;

try
Expand Down Expand Up @@ -241,8 +242,8 @@ private void RemoveAllStoryContent()

private void RemoveAllChoices()
{
foreach (Node n in storyChoices.GetChildren().OfType<Button>())
n.QueueFree();
foreach (Button button in storyChoices.GetChildren().OfType<Button>())
button.QueueFree();
}

public void WhenInkResourceReimported()
Expand Down
5 changes: 5 additions & 0 deletions addons/GodotInk/Src/InkList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public partial class InkList : RefCounted
{
private readonly Ink.Runtime.InkList inner;

public InkList()
{
inner = new Ink.Runtime.InkList();
}

public InkList(Ink.Runtime.InkList inner)
{
this.inner = inner;
Expand Down
52 changes: 32 additions & 20 deletions addons/GodotInk/Src/InkStory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void InitializeRuntimeStory()

/// <summary>
/// Check whether more content is available if you were to call <c>Continue()</c> - i.e.
/// are we mid story rather than at a choice point or at the end.
/// are we mid-story rather than at a choice point or at the end.
/// </summary>
public bool CanContinue => runtimeStory.canContinue;

Expand Down Expand Up @@ -148,7 +148,7 @@ public void ResetState()

/// <summary>
/// Get any global tags associated with the story. These are defined as
/// hash tags defined at the very top of the story.
/// hashtags defined at the very top of the story.
/// </summary>
public IReadOnlyList<string> GlobalTags => runtimeStory.globalTags;

Expand Down Expand Up @@ -234,10 +234,10 @@ public void ObserveVariable(string variableName, Callable observer)
internalObservers[variableName] = internalObserver;
}

if (observers.ContainsKey(variableName))
_ = observers[variableName].Add(observer);
if (observers.TryGetValue(variableName, out HashSet<Callable>? observerSet))
observerSet.Add(observer);
else
observers[variableName] = new() { observer };
observers[variableName] = new HashSet<Callable>() { observer };
}

/// <summary>
Expand All @@ -255,10 +255,10 @@ private Ink.Runtime.Story.VariableObserver BuildObserver()
{
return delegate (string name, object? value)
{
if (!observers.TryGetValue(name, out var callables)) return;
if (!observers.TryGetValue(name, out HashSet<Callable>? observerSet)) return;

Variant variant = ToVariant(value);
foreach (Callable callable in callables)
foreach (Callable callable in observerSet)
_ = callable.Call(name, variant);
};
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public void RemoveVariableObserver(Callable callable, string specificVariableNam
}

/// <summary>
/// An ink file can provide a fallback functions for when when an EXTERNAL has been left
/// An ink file can provide a fallback functions for when an EXTERNAL has been left
/// unbound by the client, and the fallback function will be called instead. Useful when
/// testing a story in play mode, when it's not possible to write a client-side C# external
/// function, but you don't want it to fail to run.
Expand Down Expand Up @@ -392,9 +392,11 @@ public Variant EvaluateFunction(string functionName, out string textOutput, para
/// to be performed in game code when this function is called.</param>
public void BindExternalFunction(string funcName, Callable callable, bool lookaheadSafe = false)
{
runtimeStory.BindExternalFunctionGeneral(funcName, trampoline, lookaheadSafe);
runtimeStory.BindExternalFunctionGeneral(funcName, Trampoline, lookaheadSafe);

object? trampoline(object?[] arguments) => FromVariant(callable.Call(ToVariants(arguments)));
return;

object? Trampoline(object?[] arguments) => FromVariant(callable.Call(ToVariants(arguments)));
}

/// <summary>
Expand All @@ -413,9 +415,11 @@ public void BindExternalFunction(string funcName, Callable callable, bool lookah
/// to be performed in game code when this function is called.</param>
public void BindExternalFunction(string funcName, Func<Variant> func, bool lookaheadSafe = false)
{
runtimeStory.BindExternalFunction(funcName, trampoline, lookaheadSafe);
runtimeStory.BindExternalFunction(funcName, Trampoline, lookaheadSafe);

return;

object? trampoline() => FromVariant(func.Invoke());
object? Trampoline() => FromVariant(func.Invoke());
}

/// <summary>
Expand All @@ -434,9 +438,11 @@ public void BindExternalFunction(string funcName, Func<Variant> func, bool looka
/// to be performed in game code when this function is called.</param>
public void BindExternalFunction<T>(string funcName, Func<T, Variant> func, bool lookaheadSafe = false)
{
runtimeStory.BindExternalFunction(funcName, (Func<T, object?>)trampoline, lookaheadSafe);
runtimeStory.BindExternalFunction(funcName, (Func<T, object?>)Trampoline, lookaheadSafe);

return;

object? trampoline(T a) => FromVariant(func.Invoke(a));
object? Trampoline(T a) => FromVariant(func.Invoke(a));
}

/// <summary>
Expand All @@ -455,9 +461,11 @@ public void BindExternalFunction<T>(string funcName, Func<T, Variant> func, bool
/// to be performed in game code when this function is called.</param>
public void BindExternalFunction<T1, T2>(string funcName, Func<T1, T2, Variant> func, bool lookaheadSafe = false)
{
runtimeStory.BindExternalFunction(funcName, (Func<T1, T2, object?>)trampoline, lookaheadSafe);
runtimeStory.BindExternalFunction(funcName, (Func<T1, T2, object?>)Trampoline, lookaheadSafe);

object? trampoline(T1 a, T2 b) => FromVariant(func.Invoke(a, b));
return;

object? Trampoline(T1 a, T2 b) => FromVariant(func.Invoke(a, b));
}

/// <summary>
Expand All @@ -476,9 +484,11 @@ public void BindExternalFunction<T1, T2>(string funcName, Func<T1, T2, Variant>
/// to be performed in game code when this function is called.</param>
public void BindExternalFunction<T1, T2, T3>(string funcName, Func<T1, T2, T3, Variant> func, bool lookaheadSafe = false)
{
runtimeStory.BindExternalFunction(funcName, (Func<T1, T2, T3, object?>)trampoline, lookaheadSafe);
runtimeStory.BindExternalFunction(funcName, (Func<T1, T2, T3, object?>)Trampoline, lookaheadSafe);

return;

object? trampoline(T1 a, T2 b, T3 c) => FromVariant(func.Invoke(a, b, c));
object? Trampoline(T1 a, T2 b, T3 c) => FromVariant(func.Invoke(a, b, c));
}

/// <summary>
Expand All @@ -497,9 +507,11 @@ public void BindExternalFunction<T1, T2, T3>(string funcName, Func<T1, T2, T3, V
/// to be performed in game code when this function is called.</param>
public void BindExternalFunction<T1, T2, T3, T4>(string funcName, Func<T1, T2, T3, T4, Variant> func, bool lookaheadSafe = false)
{
runtimeStory.BindExternalFunction(funcName, (Func<T1, T2, T3, T4, object?>)trampoline, lookaheadSafe);
runtimeStory.BindExternalFunction(funcName, (Func<T1, T2, T3, T4, object?>)Trampoline, lookaheadSafe);

return;

object? trampoline(T1 a, T2 b, T3 c, T4 d) => FromVariant(func.Invoke(a, b, c, d));
object? Trampoline(T1 a, T2 b, T3 c, T4 d) => FromVariant(func.Invoke(a, b, c, d));
}

/// <summary>
Expand Down
7 changes: 3 additions & 4 deletions addons/GodotInk/Src/InkStoryImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class InkStoryImporter : EditorImportPlugin
private const string OPT_MAIN_FILE = "is_main_file";
private const string OPT_COMPRESS = "compress";

private static readonly Regex includeRegex = new(@"^\s*INCLUDE\s*(?<Path>.*)\s*$", RegexOptions.Multiline | RegexOptions.Compiled);
private static readonly Regex INCLUDE_REGEX = new(@"^\s*INCLUDE\s*(?<Path>.*)\s*$", RegexOptions.Multiline | RegexOptions.Compiled);

#pragma warning disable IDE0022
public override string _GetImporterName() => "ink";
Expand Down Expand Up @@ -61,7 +61,7 @@ public override Error _Import(string sourceFile, string savePath, Gictionary opt
: ResourceSaver.Save(new StubInkStory(), destFile);

string[] additionalFiles = GetCache().Where(kvp => kvp.Value.Contains(sourceFile)).Select(kvp => kvp.Key).ToArray();
foreach (var additionalFile in additionalFiles)
foreach (string additionalFile in additionalFiles)
AppendImportExternalResource(additionalFile);

return returnValue;
Expand Down Expand Up @@ -101,8 +101,7 @@ private static Error ImportFromInk(string sourceFile, string destFile, bool shou
private static List<string> ExtractIncludes(string sourceFile)
{
using Godot.FileAccess file = Godot.FileAccess.Open(sourceFile, Godot.FileAccess.ModeFlags.Read);
return includeRegex.Matches(file.GetAsText())
.OfType<Match>()
return INCLUDE_REGEX.Matches(file.GetAsText())
.Select(match => sourceFile.GetBaseDir().PathJoin(match.Groups["Path"].Value.TrimEnd('\r')))
.ToList();
}
Expand Down
2 changes: 1 addition & 1 deletion addons/GodotInk/Src/InvalidInkException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GodotInk;

public class InvalidInkException : System.Exception
{
public InvalidInkException() : base()
public InvalidInkException()
{
}

Expand Down
8 changes: 4 additions & 4 deletions addons/GodotInk/Src/MarshalUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static Variant[] ToVariants(IReadOnlyList<object?> objects)
if (objects.Count <= 0)
return Array.Empty<Variant>();

Variant[] variants = new Variant[objects.Count];
for (int i = 0; i < objects.Count; ++i)
var variants = new Variant[objects.Count];
for (var i = 0; i < objects.Count; ++i)
variants[i] = ToVariant(objects[i]);
return variants;
}
Expand All @@ -87,8 +87,8 @@ public static Variant[] ToVariants(IReadOnlyList<object?> objects)
if (variants.Count <= 0)
return Array.Empty<object?>();

object?[] objects = new object[variants.Count];
for (int i = 0; i < variants.Count; ++i)
var objects = new object?[variants.Count];
for (var i = 0; i < variants.Count; ++i)
objects[i] = FromVariant(variants[i]);
return objects;
}
Expand Down

0 comments on commit 4e912e2

Please sign in to comment.