Skip to content

Commit

Permalink
Add support for saving/loading string-based attributes (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kexanone authored Nov 1, 2024
1 parent 913f179 commit f3666db
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//------------------------------------------------------------------------------------------------
//! Add support for string-based attributes
modded class SCR_BaseEditorAttributeVar
{
protected string m_sGME_Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//------------------------------------------------------------------------------------------------
//! Saved data for editor attribute.
//! Add support for string-based attributes
modded class SCR_EditorAttributeStruct: JsonApiStruct
{
//--- Serialized (names shortened to save memory)
protected string GME_v0;

//------------------------------------------------------------------------------------------------
void SCR_EditorAttributeStruct()
{
RegV("GME_v0");
}

//------------------------------------------------------------------------------------------------
override static void SerializeAttributes(out notnull array<ref SCR_EditorAttributeStruct> outEntries, SCR_EditorAttributeList attributeList = null, Managed item = null)
{
super.SerializeAttributes(outEntries, attributeList, item);

foreach (SCR_EditorAttributeStruct entry : outEntries)
{
SCR_BaseEditorAttribute attribute = attributeList.GetAttribute(entry.id);
SCR_BaseEditorAttributeVar var = attribute.ReadVariable(item, null);
entry.GME_v0 = var.GME_GetString();
}
}

//------------------------------------------------------------------------------------------------
override static void DeserializeAttributes(notnull array<ref SCR_EditorAttributeStruct> entries, SCR_EditorAttributeList attributeList = null, Managed item = null)
{
super.DeserializeAttributes(entries, attributeList, item);

foreach (SCR_EditorAttributeStruct entry: entries)
{
if (entry.GME_v0.IsEmpty())
continue;

SCR_BaseEditorAttribute attribute = attributeList.GetAttribute(entry.id);
SCR_BaseEditorAttributeVar var = SCR_BaseEditorAttributeVar.GME_CreateString(entry.GME_v0);
attribute.WriteVariable(item, var, null, -1);
}
}
}

0 comments on commit f3666db

Please sign in to comment.