@@ -174,9 +174,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
for (int i = 0; i < subInputs.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(subInputs[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check all entered subtags and create any that dont exist
|
||||
for (int j = 0; j <= i; j++)
|
||||
@@ -296,6 +294,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
settingsObj.Tags.Add(tagName);
|
||||
settingsObj.Tags.Sort();
|
||||
settingsAsset.SetInstance(settingsObj);
|
||||
settingsAsset.Save();
|
||||
|
||||
// Reload editor window to reflect new tag
|
||||
assetWindow?.RefreshAsset();
|
||||
@@ -417,7 +416,6 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
{
|
||||
if (!uniqueText)
|
||||
return;
|
||||
|
||||
OnAddTagButtonClicked(nameTextBox.Text, tree, nameTextBox, addTagDropPanel, pickerData);
|
||||
};
|
||||
|
||||
|
||||
@@ -37,12 +37,8 @@ String JsonAssetBase::GetData() const
|
||||
if (Data == nullptr)
|
||||
return String::Empty;
|
||||
PROFILE_CPU_NAMED("JsonAsset.GetData");
|
||||
|
||||
// Get serialized data
|
||||
rapidjson_flax::StringBuffer buffer;
|
||||
rapidjson_flax::Writer<rapidjson_flax::StringBuffer> writer(buffer);
|
||||
Data->Accept(writer);
|
||||
|
||||
OnGetData(buffer);
|
||||
return String((const char*)buffer.GetString(), (int32)buffer.GetSize());
|
||||
}
|
||||
|
||||
@@ -83,6 +79,12 @@ bool JsonAssetBase::Init(const StringView& dataTypeName, const StringAnsiView& d
|
||||
return loadAsset() != LoadResult::Ok;
|
||||
}
|
||||
|
||||
void JsonAssetBase::OnGetData(rapidjson_flax::StringBuffer& buffer) const
|
||||
{
|
||||
PrettyJsonWriter writerObj(buffer);
|
||||
Data->Accept(writerObj.GetWriter());
|
||||
}
|
||||
|
||||
const String& JsonAssetBase::GetPath() const
|
||||
{
|
||||
#if USE_EDITOR
|
||||
@@ -144,6 +146,53 @@ void JsonAssetBase::GetReferences(const StringAnsiView& json, Array<Guid>& outpu
|
||||
FindIds(document, output);
|
||||
}
|
||||
|
||||
bool JsonAssetBase::Save(const StringView& path)
|
||||
{
|
||||
// Validate state
|
||||
if (WaitForLoaded())
|
||||
{
|
||||
LOG(Error, "Asset loading failed. Cannot save it.");
|
||||
return true;
|
||||
}
|
||||
if (IsVirtual() && path.IsEmpty())
|
||||
{
|
||||
LOG(Error, "To save virtual asset asset you need to specify the target asset path location.");
|
||||
return true;
|
||||
}
|
||||
ScopeLock lock(Locker);
|
||||
|
||||
// Serialize to json file
|
||||
rapidjson_flax::StringBuffer buffer;
|
||||
PrettyJsonWriter writerObj(buffer);
|
||||
JsonWriter& writer = writerObj;
|
||||
writer.StartObject();
|
||||
{
|
||||
// Json resource header
|
||||
writer.JKEY("ID");
|
||||
writer.Guid(GetID());
|
||||
writer.JKEY("TypeName");
|
||||
writer.String(DataTypeName);
|
||||
writer.JKEY("EngineBuild");
|
||||
writer.Int(FLAXENGINE_VERSION_BUILD);
|
||||
|
||||
// Json resource data
|
||||
rapidjson_flax::StringBuffer dataBuffer;
|
||||
OnGetData(dataBuffer);
|
||||
writer.JKEY("Data");
|
||||
writer.RawValue(dataBuffer.GetString(), (int32)dataBuffer.GetSize());
|
||||
}
|
||||
writer.EndObject();
|
||||
|
||||
// Save json to file
|
||||
if (File::WriteAllBytes(path.HasChars() ? path : GetPath(), (byte*)buffer.GetString(), (int32)buffer.GetSize()))
|
||||
{
|
||||
LOG(Error, "Cannot save \'{0}\'", ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void JsonAssetBase::GetReferences(Array<Guid>& output) const
|
||||
{
|
||||
if (Data == nullptr)
|
||||
|
||||
@@ -72,8 +72,19 @@ public:
|
||||
/// <param name="json">The Json string.</param>
|
||||
/// <param name="output">The output list of object IDs references by the asset (appended, not cleared).</param>
|
||||
API_FUNCTION() static void GetReferences(const StringAnsiView& json, API_PARAM(Out) Array<Guid, HeapAllocation>& output);
|
||||
|
||||
/// <summary>
|
||||
/// Saves this asset to the file. Supported only in Editor.
|
||||
/// </summary>
|
||||
/// <param name="path">The custom asset path to use for the saving. Use empty value to save this asset to its own storage location. Can be used to duplicate asset. Must be specified when saving virtual asset.</param>
|
||||
/// <returns>True if cannot save data, otherwise false.</returns>
|
||||
API_FUNCTION() bool Save(const StringView& path = StringView::Empty);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Gets the serialized Json data (from runtime state).
|
||||
virtual void OnGetData(rapidjson_flax::StringBuffer& buffer) const;
|
||||
|
||||
public:
|
||||
// [Asset]
|
||||
const String& GetPath() const override;
|
||||
|
||||
@@ -55,75 +55,6 @@ String LocalizedStringTable::GetPluralString(const String& id, int32 n) const
|
||||
return String::Format(result.GetText(), n);
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
bool LocalizedStringTable::Save(const StringView& path)
|
||||
{
|
||||
// Validate state
|
||||
if (WaitForLoaded())
|
||||
{
|
||||
LOG(Error, "Asset loading failed. Cannot save it.");
|
||||
return true;
|
||||
}
|
||||
if (IsVirtual() && path.IsEmpty())
|
||||
{
|
||||
LOG(Error, "To save virtual asset asset you need to specify the target asset path location.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ScopeLock lock(Locker);
|
||||
|
||||
// Serialize data
|
||||
rapidjson_flax::StringBuffer outputData;
|
||||
PrettyJsonWriter writerObj(outputData);
|
||||
JsonWriter& writer = writerObj;
|
||||
writer.StartObject();
|
||||
{
|
||||
writer.JKEY("Locale");
|
||||
writer.String(Locale);
|
||||
|
||||
if (FallbackTable.GetID().IsValid())
|
||||
{
|
||||
writer.JKEY("FallbackTable");
|
||||
writer.Guid(FallbackTable.GetID());
|
||||
}
|
||||
|
||||
writer.JKEY("Entries");
|
||||
writer.StartObject();
|
||||
for (auto& e : Entries)
|
||||
{
|
||||
writer.Key(e.Key);
|
||||
if (e.Value.Count() == 1)
|
||||
{
|
||||
writer.String(e.Value[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.StartArray();
|
||||
for (auto& q : e.Value)
|
||||
writer.String(q);
|
||||
writer.EndArray();
|
||||
}
|
||||
}
|
||||
writer.EndObject();
|
||||
}
|
||||
writer.EndObject();
|
||||
|
||||
// Save asset
|
||||
#if COMPILE_WITH_ASSETS_IMPORTER
|
||||
const bool saveResult = CreateJson::Create(path.HasChars() ? path : StringView(GetPath()), outputData, TypeName);
|
||||
if (saveResult)
|
||||
#endif
|
||||
{
|
||||
LOG(Error, "Cannot save \'{0}\'", ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Asset::LoadResult LocalizedStringTable::loadAsset()
|
||||
{
|
||||
// Base
|
||||
@@ -170,3 +101,41 @@ void LocalizedStringTable::unload(bool isReloading)
|
||||
FallbackTable = nullptr;
|
||||
Entries.Clear();
|
||||
}
|
||||
|
||||
void LocalizedStringTable::OnGetData(rapidjson_flax::StringBuffer& buffer) const
|
||||
{
|
||||
PrettyJsonWriter writerObj(buffer);
|
||||
JsonWriter& writer = writerObj;
|
||||
writer.StartObject();
|
||||
{
|
||||
writer.JKEY("Locale");
|
||||
writer.String(Locale);
|
||||
|
||||
if (FallbackTable.GetID().IsValid())
|
||||
{
|
||||
writer.JKEY("FallbackTable");
|
||||
writer.Guid(FallbackTable.GetID());
|
||||
}
|
||||
|
||||
writer.JKEY("Entries");
|
||||
writer.StartObject();
|
||||
for (auto& e : Entries)
|
||||
{
|
||||
writer.Key(e.Key);
|
||||
if (e.Value.Count() == 1)
|
||||
{
|
||||
writer.String(e.Value[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.StartArray();
|
||||
for (auto& q : e.Value)
|
||||
writer.String(q);
|
||||
writer.EndArray();
|
||||
}
|
||||
}
|
||||
writer.EndObject();
|
||||
}
|
||||
writer.EndObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,19 +61,9 @@ public:
|
||||
/// <returns>The localized text.</returns>
|
||||
API_FUNCTION() String GetPluralString(const String& id, int32 n) const;
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
/// <summary>
|
||||
/// Saves this asset to the file. Supported only in Editor.
|
||||
/// </summary>
|
||||
/// <param name="path">The custom asset path to use for the saving. Use empty value to save this asset to its own storage location. Can be used to duplicate asset. Must be specified when saving virtual asset.</param>
|
||||
/// <returns>True if cannot save data, otherwise false.</returns>
|
||||
API_FUNCTION() bool Save(const StringView& path = StringView::Empty);
|
||||
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// [JsonAssetBase]
|
||||
LoadResult loadAsset() override;
|
||||
void unload(bool isReloading) override;
|
||||
void OnGetData(rapidjson_flax::StringBuffer& buffer) const override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user