Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions DawnLib/src/API/Terminal/TerminalKeywordBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics.CodeAnalysis;
using Dawn.Internal;
using Dawn.Utils;
using UnityEngine;

namespace Dawn;
public class TerminalKeywordBuilder
Expand All @@ -28,11 +29,11 @@ private set
internal static List<TerminalKeyword> WordsThatAcceptInput { get; private set; } = [];
private TerminalKeyword _keyword;

private static bool WordAlreadyExists(string word, out TerminalKeyword existingKeyword)
private static bool WordAlreadyExists(string word, [NotNullWhen(true)] out TerminalKeyword? existingKeyword)
{
if (TerminalRefs.Instance == null)
{
existingKeyword = null!;
existingKeyword = null;
foreach (TerminalKeyword keyword in AllTerminalKeywords)
{
if (word.CompareStringsInvariant(keyword.word))
Expand All @@ -55,7 +56,7 @@ private static bool WordAlreadyExists(string word, out TerminalKeyword existingK
// <remarks>WARNING: Do not use this constructor if you do not wish to override other existing terminal keywords with the same word!</remarks>
internal TerminalKeywordBuilder(string name, string word)
{
if (WordAlreadyExists(word, out TerminalKeyword existingKeywordWithSameWord))
if (WordAlreadyExists(word, out var existingKeywordWithSameWord))
{
_keyword = existingKeywordWithSameWord;
DawnPlugin.Logger.LogWarning($"Keyword Override! Replacing keyword [{_keyword.word}] results");
Expand All @@ -74,7 +75,7 @@ internal TerminalKeywordBuilder(string name, string word)
// <remarks>DawnKeywordType determines if a matching keyword is overwritten or if the keyword word will be modified at creation</remarks>
internal TerminalKeywordBuilder(string name, string word, ITerminalKeyword.DawnKeywordType keywordPriority)
{
if (WordAlreadyExists(word, out TerminalKeyword existingKeywordWithSameWord))
if (WordAlreadyExists(word, out var existingKeywordWithSameWord))
{
ITerminalKeyword.DawnKeywordType existingPriority = existingKeywordWithSameWord.GetKeywordPriority();
if (existingPriority <= keywordPriority)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static TerminalKeyword CheckForExactSentencesPrefix(On.Terminal.orig_Che
self.SetLastVerb(null!);
self.SetLastNoun(null!);

if (self.DawnTryResolveKeyword(playerWord, out TerminalKeyword NonNullResult))
if (self.DawnTryResolveKeyword(playerWord, out var NonNullResult))
{
self.UpdateLastKeywordParsed(NonNullResult);
self.SetLastCommand(playerWord.GetExactMatch(NonNullResult.word));
Expand All @@ -121,7 +121,7 @@ private static TerminalKeyword CheckForExactSentencesPrefix(On.Terminal.orig_Che

private static TerminalKeyword ParseWordPrefix(On.Terminal.orig_ParseWord orig, Terminal self, string playerWord, int specificityRequired)
{
if (self.DawnTryResolveKeyword(playerWord, out TerminalKeyword NonNullResult))
if (self.DawnTryResolveKeyword(playerWord, out var NonNullResult))
{
self.UpdateLastKeywordParsed(NonNullResult);
self.SetLastCommand(playerWord.GetExactMatch(NonNullResult.word));
Expand Down Expand Up @@ -163,7 +163,7 @@ private static void AssignTerminalPriorites(On.Terminal.orig_Start orig, Termina

if (string.IsNullOrEmpty(keyword.GetKeywordDescription()))
{
if (keyword.TryGetKeywordInfoText(out string result))
if (keyword.TryGetKeywordInfoText(out var result))
{
keyword.SetKeywordDescription(result.Trim());
}
Expand Down
14 changes: 8 additions & 6 deletions DawnLib/src/Utils/Extensions/TerminalExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Dawn.Internal;

Expand Down Expand Up @@ -67,7 +69,7 @@ public static TerminalKeyword GetLastVerb(this Terminal terminal)
return ((ITerminal)terminal).DawnLastVerb;
}

public static bool TryGetKeywordInfoText(this TerminalKeyword terminalKeyword, out string text)
public static bool TryGetKeywordInfoText(this TerminalKeyword terminalKeyword, [NotNullWhen(true)] out string? text)
{
text = string.Empty;
CompatibleNoun matchedCompatibleNoun = TerminalRefs.InfoKeyword.compatibleNouns.FirstOrDefault(x => x.noun.word == terminalKeyword.word);
Expand All @@ -80,7 +82,7 @@ public static bool TryGetKeywordInfoText(this TerminalKeyword terminalKeyword, o
return true;
}

public static bool TryGetKeyword(this Terminal terminal, string keyWord, out TerminalKeyword terminalKeyword)
public static bool TryGetKeyword(this Terminal terminal, string keyWord, [NotNullWhen(true)] out TerminalKeyword? terminalKeyword)
{
List<TerminalKeyword> keyWordList = [.. terminal.terminalNodes.allKeywords];

Expand All @@ -94,7 +96,7 @@ public static bool TryGetKeyword(this Terminal terminal, string keyWord, out Ter
}
}

terminalKeyword = null!;
terminalKeyword = null;
return false;
}

Expand Down Expand Up @@ -313,9 +315,9 @@ private static TerminalKeyword GetBestMatchFromList(string input, List<TerminalK
return word;
}

public static bool DawnTryResolveKeyword(this Terminal terminal, string input, out TerminalKeyword word)
public static bool DawnTryResolveKeyword(this Terminal terminal, string input, [NotNullWhen(true)] out TerminalKeyword? word)
{
word = null!;
word = null;

//empty input, return false
if (string.IsNullOrWhiteSpace(input))
Expand Down
Loading