From 37e8fa7b767916c764567a877c4af2803d4d5cb2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 5 May 2023 14:54:42 +0200 Subject: [PATCH] Fix creating localization table on blank project #1060 --- .../CustomEditors/Dedicated/LocalizationSettingsEditor.cs | 5 ++++- Source/Editor/Windows/Assets/JsonAssetWindow.cs | 4 ++++ Source/Engine/Content/Content.cpp | 5 ----- Source/Engine/Content/JsonAsset.cs | 5 +++++ Source/Engine/Localization/LocalizedStringTable.cpp | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/LocalizationSettingsEditor.cs b/Source/Editor/CustomEditors/Dedicated/LocalizationSettingsEditor.cs index e784048af..071810ffa 100644 --- a/Source/Editor/CustomEditors/Dedicated/LocalizationSettingsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/LocalizationSettingsEditor.cs @@ -145,7 +145,10 @@ namespace FlaxEditor.CustomEditors.Dedicated else { // No localization so initialize with empty table - var path = Path.Combine(Path.Combine(Path.GetDirectoryName(GameSettings.Load().Localization.Path), "Localization", culture.Name + ".json")); + var folder = Path.Combine(Path.GetDirectoryName(GameSettings.Load().Localization.Path), "Localization"); + if (!Directory.Exists(folder)) + Directory.CreateDirectory(folder); + var path = Path.Combine(Path.Combine(folder, culture.Name + ".json")); var table = FlaxEngine.Content.CreateVirtualAsset(); table.Locale = culture.Name; if (!table.Save(path)) diff --git a/Source/Editor/Windows/Assets/JsonAssetWindow.cs b/Source/Editor/Windows/Assets/JsonAssetWindow.cs index ecc68581c..e6606f35f 100644 --- a/Source/Editor/Windows/Assets/JsonAssetWindow.cs +++ b/Source/Editor/Windows/Assets/JsonAssetWindow.cs @@ -126,6 +126,10 @@ namespace FlaxEditor.Windows.Assets _presenter.NoSelectionText = "Failed to load asset. See log for more. " + ex.Message.Replace('\n', ' '); } } + else if (string.IsNullOrEmpty(dataTypeName)) + { + _presenter.NoSelectionText = "Empty data type."; + } else { _presenter.NoSelectionText = string.Format("Missing type '{0}'.", dataTypeName); diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index a30fa7b78..e58aa458d 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -1002,17 +1002,12 @@ Asset* Content::load(const Guid& id, const ScriptingTypeHandle& type, AssetInfo& } #if ASSETS_LOADING_EXTRA_VERIFICATION - - // Ensure we have valid asset info - ASSERT(assetInfo.TypeName.HasChars() && assetInfo.Path.HasChars()); - // Check if file exists if (!FileSystem::FileExists(assetInfo.Path)) { LOG(Error, "Cannot find file '{0}'", assetInfo.Path); return nullptr; } - #endif // Find asset factory based in its type diff --git a/Source/Engine/Content/JsonAsset.cs b/Source/Engine/Content/JsonAsset.cs index 3278a3377..afd83bafd 100644 --- a/Source/Engine/Content/JsonAsset.cs +++ b/Source/Engine/Content/JsonAsset.cs @@ -35,6 +35,11 @@ namespace FlaxEngine return null; var dataTypeName = DataTypeName; + if (string.IsNullOrEmpty(dataTypeName)) + { + Debug.LogError(string.Format("Missing typename of data in Json asset '{0}'.", Path), this); + return null; + } var assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { diff --git a/Source/Engine/Localization/LocalizedStringTable.cpp b/Source/Engine/Localization/LocalizedStringTable.cpp index 74c9b6774..e14328f89 100644 --- a/Source/Engine/Localization/LocalizedStringTable.cpp +++ b/Source/Engine/Localization/LocalizedStringTable.cpp @@ -15,6 +15,7 @@ REGISTER_JSON_ASSET(LocalizedStringTable, "FlaxEngine.LocalizedStringTable", tru LocalizedStringTable::LocalizedStringTable(const SpawnParams& params, const AssetInfo* info) : JsonAssetBase(params, info) { + DataTypeName = TypeName; } void LocalizedStringTable::AddString(const StringView& id, const StringView& value)