From d9a0d9da88331405282e977f84f86383f9bdc289 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 17 Sep 2025 08:36:31 -0400 Subject: [PATCH] Add .gitignore files and clean up tracked files --- .gitignore | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Client.cs | 6 +++-- Managers.cs | 32 +++++++++++++++--------- NPC.cs | 13 +++++----- 4 files changed, 100 insertions(+), 21 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e3176f --- /dev/null +++ b/.gitignore @@ -0,0 +1,70 @@ +# C# / .NET +## Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +## Visual Studio +.vs/ +*.suo +*.user +*.userosscache +*.sln.docstates +*.userprefs + +## Mono auto generated files +mono_crash.* + +## .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +## NuGet +*.nupkg +*.snupkg +**/[Pp]ackages/* +!**/[Pp]ackages/build/ +*.nuget.props +*.nuget.targets + +## Visual Studio Code +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +## JetBrains Rider +.idea/ +*.sln.iml + +## macOS +.DS_Store +.AppleDouble +.LSOverride + +## Windows +Thumbs.db +ehthumbs.db +Desktop.ini + +## Build results +*.dll +*.exe +*.pdb +*.cache +*.ilk +*.log +*.vspscc +*.vssscc \ No newline at end of file diff --git a/Client.cs b/Client.cs index 8121954..926ae7e 100644 --- a/Client.cs +++ b/Client.cs @@ -313,7 +313,8 @@ public class Client : IDisposable { _refreshToken = responseData?.GetValueOrDefault("refresh_token")?.ToString() ?? ""; var expiresIn = 3600; - if (responseData?.TryGetValue("expires_in", out var expiresInObj) == true) { + if (responseData?.TryGetValue("expires_in", out var expiresInObj) == + true) { if (expiresInObj is JsonElement jsonEl) { expiresIn = jsonEl.GetInt32(); } else { @@ -387,7 +388,8 @@ public class Client : IDisposable { } var expiresIn = 3600; - if (responseData?.TryGetValue("expires_in", out var expiresInObj) == true) { + if (responseData?.TryGetValue("expires_in", out var expiresInObj) == + true) { if (expiresInObj is JsonElement jsonEl) { expiresIn = jsonEl.GetInt32(); } else { diff --git a/Managers.cs b/Managers.cs index f3769d8..e9fddbe 100644 --- a/Managers.cs +++ b/Managers.cs @@ -129,7 +129,9 @@ public class UniverseManager { response.TryGetValue("public_universes", out var universesObj)) { // Handle System.Text.Json if (universesObj is System.Text.Json.JsonElement jsonElement) { - return System.Text.Json.JsonSerializer.Deserialize>>(jsonElement.GetRawText()); + return System.Text.Json.JsonSerializer + .Deserialize>>( + jsonElement.GetRawText()); } else if (universesObj is List> list) { return list; } @@ -151,7 +153,9 @@ public class UniverseManager { response.TryGetValue("universes", out var universesObj)) { // Handle System.Text.Json if (universesObj is System.Text.Json.JsonElement jsonElement) { - return System.Text.Json.JsonSerializer.Deserialize>>(jsonElement.GetRawText()); + return System.Text.Json.JsonSerializer + .Deserialize>>( + jsonElement.GetRawText()); } else if (universesObj is List> list) { return list; } @@ -228,10 +232,9 @@ public class ChatManager { var context = completionResponse.NpcContext; var moodTransition = completionResponse.MoodTransition; - _client.RaiseDialogueReceived( - new DialogueReceivedEventArgs { Response = content, - Context = context, - MoodTransition = moodTransition }); + _client.RaiseDialogueReceived(new DialogueReceivedEventArgs { + Response = content, Context = context, MoodTransition = moodTransition + }); } return completionResponse; @@ -303,19 +306,23 @@ public class ChatCompletionResponse { public ChatCompletionResponse(Dictionary data) { Choices = new List(); - + if (data?.ContainsKey("choices") == true) { var choicesObj = data["choices"]; if (choicesObj is JsonElement choicesJson) { // Handle JsonElement array foreach (var choiceElement in choicesJson.EnumerateArray()) { - var choiceDict = JsonSerializer.Deserialize>(choiceElement.GetRawText()); + var choiceDict = + JsonSerializer.Deserialize>( + choiceElement.GetRawText()); Choices.Add(new ChatChoice(choiceDict)); } } else if (choicesObj is List choicesList) { - Choices = choicesList - ?.Select(c => new ChatChoice(c as Dictionary)) - .ToList() ?? new List(); + Choices = + choicesList + ?.Select(c => new ChatChoice(c as Dictionary)) + .ToList() ?? + new List(); } } @@ -339,7 +346,8 @@ public class ChatChoice { if (data?.ContainsKey("message") == true) { var msgObj = data["message"]; if (msgObj is JsonElement msgJson) { - var msgDict = JsonSerializer.Deserialize>(msgJson.GetRawText()); + var msgDict = JsonSerializer.Deserialize>( + msgJson.GetRawText()); Message = new ChatMessage { Role = msgDict?.GetValueOrDefault("role")?.ToString() ?? "assistant", Content = msgDict?.GetValueOrDefault("content")?.ToString() ?? "" diff --git a/NPC.cs b/NPC.cs index 34626b5..9b45f4c 100644 --- a/NPC.cs +++ b/NPC.cs @@ -67,10 +67,11 @@ public class NPC { /// private void SetupFromData(Dictionary npcData) { // Check if data is nested in "spawned_npc" first - if (npcData.ContainsKey("spawned_npc") && npcData["spawned_npc"] is Dictionary spawnedData) { + if (npcData.ContainsKey("spawned_npc") && + npcData["spawned_npc"] is Dictionary spawnedData) { npcData = spawnedData; } - + // Handle npc_id conversion - API might return String or int if (npcData.TryGetValue("npc_id", out var npcIdRaw)) { if (npcIdRaw is JsonElement npcIdJson) { @@ -283,11 +284,9 @@ public class NPC { /// Convert NPC to dictionary for API params /// public Dictionary ToDictionary() { - return new Dictionary { - ["npc_id"] = NpcId, - ["universe_id"] = UniverseId, - ["seed"] = Seed - }; + return new Dictionary { ["npc_id"] = NpcId, + ["universe_id"] = UniverseId, + ["seed"] = Seed }; } ///