-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for saving/loading string-based attributes (#59)
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ns/GME/Scripts/Game/GME/Editor/Containers/AttributeVariables/SCR_BaseEditorAttributeVar.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
addons/GME/Scripts/Game/GME/Editor/Containers/Backend/SCR_EditorAttributeStruct.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |