Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EntitySourceHelper.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
11 static bool CopyDataFromOldToNewComponent(notnull IEntitySource entitySource, notnull IEntityComponentSource componentSource, notnull IEntitySource entityDestination, notnull IEntityComponentSource componentDestination)
12 {
13 // entitySources can be the same, components not
14 if (componentSource == componentSource)
15 return false;
16
17 int sourceId = -1;
18 int destinationId = -1;
19 IEntityComponentSource testedComponent;
20 for (int i = entitySource.GetComponentCount() - 1; i >= 0; --i)
21 {
22 testedComponent = entitySource.GetComponent(i);
23 if (testedComponent == componentSource)
24 {
25 sourceId = i;
26 break;
27 }
28 }
29
30 if (sourceId == -1)
31 {
32 Print("Source component was not found in the provided source entity", LogLevel.ERROR);
33 return false;
34 }
35
36 for (int i = entityDestination.GetComponentCount() - 1; i >= 0; --i)
37 {
38 testedComponent = entityDestination.GetComponent(i);
39 if (testedComponent == componentDestination)
40 {
41 destinationId = i;
42 break;
43 }
44 }
45
46 if (destinationId == -1)
47 {
48 Print("Destination component was not found in the provided destination entity", LogLevel.ERROR);
49 return false;
50 }
51
52 return CopyVariablesFromTo(entitySource, componentSource, { new ContainerIdPathEntry("components", destinationId) });
53 }
54
55 //------------------------------------------------------------------------------------------------
60 // This method may be renamed later
61 protected static bool CopyVariablesFromTo(IEntitySource entitySource, IEntityComponentSource source, array<ref ContainerIdPathEntry> path)
62 {
63 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
64
65 string varName;
66 bool bValue;
67 float fValue;
68 int iValue;
69 string sValue;
70 vector vValue;
71 array<bool> abValue;
72 array<ref Color> acValue;
73 array<float> afValue;
74 array<int> aiValue;
75 array<string> asValue;
76 array<vector> avValue;
77 for (int i, count = source.GetNumVars(); i < count; i++)
78 {
79 varName = source.GetVarName(i);
80 if (!source.IsVariableSetDirectly(varName))
81 continue;
82
83 switch (source.GetDataVarType(i))
84 { // oh noes, the formatting
85 case DataVarType.BOOLEAN: { if (source.Get(varName, bValue) && worldEditorAPI.SetVariableValue(entitySource, path, varName, bValue.ToString(true))) continue; break; }
86 case DataVarType.SCALAR: { if (source.Get(varName, fValue) && worldEditorAPI.SetVariableValue(entitySource, path, varName, fValue.ToString())) continue; break; }
87 case DataVarType.INTEGER: { if (source.Get(varName, iValue) && worldEditorAPI.SetVariableValue(entitySource, path, varName, iValue.ToString())) continue; break; }
88 case DataVarType.RESOURCE_NAME:
89 case DataVarType.STRING: { if (source.Get(varName, sValue) && worldEditorAPI.SetVariableValue(entitySource, path, varName, sValue)) continue; break; }
90 case DataVarType.VECTOR3: { if (source.Get(varName, vValue) && worldEditorAPI.SetVariableValue(entitySource, path, varName, vValue.ToString(false))) continue; break; }
91
92 case DataVarType.OBJECT:
93 {
94 if (!source.Get(varName, null))
95 break;
96
97 BaseContainer sourceObj = source.GetObject(varName);
98 if (!sourceObj) // it's null, let's make sure it is null there too
99 {
100 if (worldEditorAPI.ClearVariableValue(entitySource, path, varName))
101 continue;
102
103 break;
104 }
105
106 // create, no check if exists
107 if (!worldEditorAPI.CreateObjectVariableMember(entitySource, path, varName, sourceObj.GetClassName()))
108 break;
109
110 array<ref ContainerIdPathEntry> path2 = SCR_ArrayHelperRefT<ContainerIdPathEntry>.GetCopy(path);
111 path2.Insert(new ContainerIdPathEntry(varName));
112
113 if (CopyVariablesFromTo(entitySource, sourceObj, path2))
114 continue;
115
116 break;
117 }
118
119 // arrays
120
121 case DataVarType.SCALAR_ARRAY: { if (source.Get(varName, afValue) && worldEditorAPI.SetVariableValue(entitySource, path, varName, SCR_StringHelper.Join(",", afValue))) continue; break; }
122// case DataVarType.VECTOR2_ARRAY: { break; }
123// case DataVarType.VECTOR3_ARRAY: { break; }
124// case DataVarType.VECTOR4_ARRAY: { break; }
125// case DataVarType.MATRIX_ARRAY: { break; }
126// case DataVarType.MATRIX34_ARRAY: { break; }
127// case DataVarType.COLOR_ARRAY: { break; }
128// case DataVarType.INTEGER_ARRAY: { break; }
129// case DataVarType.TEXTURE_ARRAY: { break; }
130// case DataVarType.BOOLEAN_ARRAY: { break; }
131// case DataVarType.RESOURCE_NAME_ARRAY:
132// case DataVarType.STRING_ARRAY: { break; }
133// case DataVarType.POINTER_ARRAY: { break; }
134// case DataVarType.FLAGS_ARRAY: { break; }
135// case DataVarType.OBJECT_ARRAY: { break; }
136
137 default:
138 {
139 Print("" + source.GetDataVarType(i) + " not supported", LogLevel.WARNING);
140 continue; // do not fail yet, many missing types as commented above
141 }
142 }
143
144 Print("A variable set manually cannot be auto-converted and must be done by hand: " + varName, LogLevel.WARNING);
145 return false;
146 }
147
148 return true;
149 }
150
151 //------------------------------------------------------------------------------------------------
154 static string GetShortestVectorString(vector value)
155 {
156 return string.Format("%1 %2 %3", value[0], value[1], value[2]); // 20% faster than ("" + value[0] + " " + value[1] + " " + value[2]);
157 }
158}
string path
void ContainerIdPathEntry(string propertyName, int index=-1)
Definition worldEditor.c:30
static string GetShortestVectorString(vector value)
static bool CopyVariablesFromTo(IEntitySource entitySource, IEntityComponentSource source, array< ref ContainerIdPathEntry > path)
static string Join(string separator, notnull array< string > pieces, bool joinEmptyEntries=true)
DataVarType
Definition DataVarType.c:18
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14