From 76729b04f73282b8d781f724f7b1256238d27796 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:47:00 +0300 Subject: [PATCH] Improved handling of empty preview character setting --- CustomizePlus/Templates/TemplateEditorManager.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CustomizePlus/Templates/TemplateEditorManager.cs b/CustomizePlus/Templates/TemplateEditorManager.cs index 5e2e684..f651fa3 100644 --- a/CustomizePlus/Templates/TemplateEditorManager.cs +++ b/CustomizePlus/Templates/TemplateEditorManager.cs @@ -9,6 +9,7 @@ using CustomizePlus.Templates.Data; using CustomizePlus.Templates.Events; using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; +using OtterGui.Classes; using OtterGui.Log; using System; using System.Collections.Generic; @@ -94,7 +95,7 @@ public class TemplateEditorManager : IDisposable Enabled = false, Name = "Template editor profile", ProfileType = ProfileType.Editor, - CharacterName = configuration.EditorConfiguration.PreviewCharacterName! + CharacterName = configuration.EditorConfiguration.PreviewCharacterName ?? LowerString.Empty }; } @@ -123,10 +124,8 @@ public class TemplateEditorManager : IDisposable Name = "Template editor temporary template" }; - if (CharacterName == null) //safeguard - ChangeEditorCharacterInternal(_gameObjectService.GetCurrentPlayerName()); //will also set EditorProfile.CharacterName - else - EditorProfile.CharacterName = CharacterName; + if (string.IsNullOrWhiteSpace(CharacterName)) //safeguard + ChangeEditorCharacterInternal(_gameObjectService.GetCurrentPlayerName()); //will set EditorProfile.CharacterName EditorProfile.Templates.Clear(); //safeguard EditorProfile.Templates.Add(CurrentlyEditedTemplate); @@ -175,7 +174,7 @@ public class TemplateEditorManager : IDisposable public bool ChangeEditorCharacter(string characterName) { - if (!IsEditorActive || CharacterName == characterName || IsEditorPaused) + if (!IsEditorActive || CharacterName == characterName || IsEditorPaused || string.IsNullOrWhiteSpace(characterName)) return false; return ChangeEditorCharacterInternal(characterName); @@ -310,6 +309,11 @@ public class TemplateEditorManager : IDisposable string.IsNullOrWhiteSpace(_configuration.EditorConfiguration.PreviewCharacterName)) { var localPlayerName = _gameObjectService.GetCurrentPlayerName(); + if(string.IsNullOrWhiteSpace(localPlayerName)) + { + _logger.Warning("Can't retrieve local player name on login"); + return; + } if (_configuration.EditorConfiguration.PreviewCharacterName != localPlayerName) {