Skip to content

Commit f3666db

Browse files
authored
Add support for saving/loading string-based attributes (#59)
1 parent 913f179 commit f3666db

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

addons/GME/Scripts/Game/GME/Editor/Containers/AttributeVariables/SCR_BaseEditorAttributeVar.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//------------------------------------------------------------------------------------------------
2+
//! Add support for string-based attributes
23
modded class SCR_BaseEditorAttributeVar
34
{
45
protected string m_sGME_Value;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//------------------------------------------------------------------------------------------------
2+
//! Saved data for editor attribute.
3+
//! Add support for string-based attributes
4+
modded class SCR_EditorAttributeStruct: JsonApiStruct
5+
{
6+
//--- Serialized (names shortened to save memory)
7+
protected string GME_v0;
8+
9+
//------------------------------------------------------------------------------------------------
10+
void SCR_EditorAttributeStruct()
11+
{
12+
RegV("GME_v0");
13+
}
14+
15+
//------------------------------------------------------------------------------------------------
16+
override static void SerializeAttributes(out notnull array<ref SCR_EditorAttributeStruct> outEntries, SCR_EditorAttributeList attributeList = null, Managed item = null)
17+
{
18+
super.SerializeAttributes(outEntries, attributeList, item);
19+
20+
foreach (SCR_EditorAttributeStruct entry : outEntries)
21+
{
22+
SCR_BaseEditorAttribute attribute = attributeList.GetAttribute(entry.id);
23+
SCR_BaseEditorAttributeVar var = attribute.ReadVariable(item, null);
24+
entry.GME_v0 = var.GME_GetString();
25+
}
26+
}
27+
28+
//------------------------------------------------------------------------------------------------
29+
override static void DeserializeAttributes(notnull array<ref SCR_EditorAttributeStruct> entries, SCR_EditorAttributeList attributeList = null, Managed item = null)
30+
{
31+
super.DeserializeAttributes(entries, attributeList, item);
32+
33+
foreach (SCR_EditorAttributeStruct entry: entries)
34+
{
35+
if (entry.GME_v0.IsEmpty())
36+
continue;
37+
38+
SCR_BaseEditorAttribute attribute = attributeList.GetAttribute(entry.id);
39+
SCR_BaseEditorAttributeVar var = SCR_BaseEditorAttributeVar.GME_CreateString(entry.GME_v0);
40+
attribute.WriteVariable(item, var, null, -1);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)