3[
WorkbenchPluginAttribute(name:
"Data To Spreadsheet plugin",
category:
"", shortcut:
"Alt+Shift+E", wbModules: {
"ResourceManager" }, awesomeFontCode: 0xF6DD)]
4class SCR_DataToSpreadsheetPlugin : ResourceManagerPlugin
6 [
Attribute(
"",
UIWidgets.ResourceNamePicker,
"Pick a config with Spreadsheet parser configuration.",
"conf", null,
"Settings")]
10 protected bool m_bCommaAsDelimiter;
12 [
Attribute(
"1",
desc:
"Use Prefab Array from config instead of the current Resource Browser selection.",
category:
"Settings")]
13 protected bool m_bUseSelectionFromConfig;
16 bool m_bPrintToConsole;
18 protected string m_sExportString;
19 protected string m_sHeaderString;
20 protected bool m_bGenerateHeader;
21 protected bool m_bRunExport;
22 protected bool m_bReadData;
23 protected bool m_bSaveRequired;
27 protected static const string DESCRIPTION =
"This plugin allows to transfer data between Workbench and spreadsheets\nExport button grabs data from Workbench to clipboard\nImport button grabs data from clipboard to Workbench";
31 protected void ImportButton()
35 m_mImportData.Clear();
38 string input =
System.ImportFromClipboard();
45 array<string> parsedText = {};
46 input.Split(
"\n", parsedText,
false);
49 array<string> parsedHeader = {};
50 parsedText[0].Split(
"\t", parsedHeader,
false);
51 if (m_bPrintToConsole)
55 for (
int i = 1, count = parsedText.Count(); i < count; ++i)
57 array<string> parsedLine = {};
59 parsedText[i].Split(
"\t", parsedLine,
false);
62 if (parsedLine.Count() == 1)
65 if (parsedHeader.Count() != parsedLine.Count())
67 Print(
"Invalid data - number of columns in one of the line doesn't match the amount of columns in header",
LogLevel.ERROR);
72 for (
int i2 = 1, count2 = parsedLine.Count(); i2 < count2; ++i2)
74 data.Insert(parsedHeader[i2].Trim(), parsedLine[i2].Trim());
75 if (m_bPrintToConsole)
79 m_mImportData.Insert(parsedLine[0],
new SCR_DataToSpreadsheetElement(
data));
82 if (parsedText.Count() == 1)
84 Print(
"No data to import was detected - check content of clipboard",
LogLevel.WARNING);
91 protected void ExportButton()
98 protected bool CancelButton()
106 Workbench.ScriptDialog(
"Data To Spreadsheets", DESCRIPTION,
this);
114 array<ref ContainerIdPathEntry> containerPath = {};
115 ProcessAttributes(entSrc, containerPath, prefabName, prefabConfig.m_aAttributesArray);
120 protected void ProcessAttributes(
IEntitySource entSrc, array<ref ContainerIdPathEntry> containerPath,
ResourceName prefabName, array<ref SCR_DataToSpreadsheetTemplatesBase> TemplateData)
123 foreach (SCR_DataToSpreadsheetTemplatesBase currentEntry : TemplateData)
125 switch (currentEntry.ReturnType())
129 SCR_DataToSpreadsheetTemplatesComponent entry = SCR_DataToSpreadsheetTemplatesComponent.Cast(currentEntry);
134 array<ref ContainerIdPathEntry> containerPathSub = {};
137 containerPathSub.Insert(obj);
141 ProcessAttributes(component, containerPathSub, prefabName, entry.GetAttributes());
147 SCR_DataToSpreadsheetTemplatesAttribute entry = SCR_DataToSpreadsheetTemplatesAttribute.Cast(currentEntry);
148 ProcessAttribute(entSrc, containerPath, prefabName, entry);
154 SCR_DataToSpreadsheetTemplatesObject entry = SCR_DataToSpreadsheetTemplatesObject.Cast(currentEntry);
155 BaseContainer container = entSrc.GetObject(entry.m_sObjectName);
159 array<ref ContainerIdPathEntry> containerPathSub = {};
162 containerPathSub.Insert(obj);
166 ProcessAttributes(container, containerPathSub, prefabName, entry.GetAttributes());
172 SCR_DataToSpreadsheetTemplatesObjectArray entry = SCR_DataToSpreadsheetTemplatesObjectArray.Cast(currentEntry);
174 array<ref ContainerIdPathEntry> containerPathSub =
new array<ref ContainerIdPathEntry>;
177 containerPathSub.Insert(obj);
180 ProcessAttributesList(containerList, containerPathSub, prefabName, entry.GetAttributes());
189 if (childName.IsEmpty())
192 string arrayItemName;
194 for (
int i, cnt = containerList.Count(); i < cnt; i++)
196 containerListElement = containerList[i];
197 arrayItemName = containerListElement.GetName();
199 if (arrayItemName.IsEmpty())
200 arrayItemName = containerListElement.GetClassName();
202 if (arrayItemName.IsEmpty())
205 arrayItemName.ToLower();
207 if (arrayItemName == childName)
208 return containerListElement;
214 void ProcessAttributesList(
BaseContainerList containerList, array<ref ContainerIdPathEntry> containerPath,
ResourceName prefabName, array<ref SCR_DataToSpreadsheetTemplatesBase> TemplateData)
217 foreach (SCR_DataToSpreadsheetTemplatesBase currentEntry : TemplateData)
219 switch (currentEntry.ReturnType())
223 SCR_DataToSpreadsheetTemplatesObject entry = SCR_DataToSpreadsheetTemplatesObject.Cast(currentEntry);
224 BaseContainer container = GetChildFromList(containerList, entry.m_sObjectName);
225 array<ref ContainerIdPathEntry> containerPathSub =
new array<ref ContainerIdPathEntry>;
228 containerPathSub.Insert(obj);
231 ProcessAttributes(container, containerPathSub, prefabName, entry.GetAttributes());
237 SCR_DataToSpreadsheetTemplatesObjectIndex entry = SCR_DataToSpreadsheetTemplatesObjectIndex.Cast(currentEntry);
238 BaseContainer container = containerList.Get(entry.m_iObjectIndex);
239 array<ref ContainerIdPathEntry> containerPathSub =
new array<ref ContainerIdPathEntry>;
242 containerPathSub.Insert(obj);
245 ProcessAttributes(container, containerPathSub, prefabName, entry.GetAttributes());
251 Print(
"Incorrect element");
261 void ProcessAttribute(
IEntitySource entSrcAttribute, array<ref ContainerIdPathEntry> containerPath,
ResourceName prefabName, SCR_DataToSpreadsheetTemplatesAttribute currentAttribute)
264 string attributeName = currentAttribute.m_sAttributeName;
265 int attributeType = currentAttribute.m_eAttributeType;
267 if (attributeType == SCR_EDataToSpreadsheetDataType.INT)
270 entSrcAttribute.Get(attributeName, currentValue);
271 if (currentValue.IsEmpty())
272 entSrcAttribute.GetDefaultAsString(attributeName, currentValue);
274 value = currentValue;
277 if (attributeType == SCR_EDataToSpreadsheetDataType.FLOAT)
280 entSrcAttribute.Get(attributeName, currentValue);
281 if (currentValue.IsEmpty())
282 entSrcAttribute.GetDefaultAsString(attributeName, currentValue);
284 if (m_bCommaAsDelimiter)
285 currentValue.Replace(
".",
",");
287 value = currentValue;
290 if (attributeType == SCR_EDataToSpreadsheetDataType.STRING)
293 entSrcAttribute.Get(attributeName, currentValue);
294 if (currentValue.IsEmpty())
295 entSrcAttribute.GetDefaultAsString(attributeName, currentValue);
297 value = currentValue;
300 if (attributeType == SCR_EDataToSpreadsheetDataType.RESOURCE)
303 entSrcAttribute.Get(attributeName, currentValue);
304 if (currentValue.IsEmpty())
305 entSrcAttribute.GetDefaultAsString(attributeName, currentValue);
307 value = currentValue;
310 if (m_bPrintToConsole)
315 m_sExportString += value +
"\t";
316 if (m_bGenerateHeader)
317 m_sHeaderString += attributeName +
"\t";
321 SCR_DataToSpreadsheetElement
data;
322 if (!m_mImportData.Find(prefabName,
data))
325 string importedData =
data.GetData(attributeName);
326 if (importedData.IsEmpty())
331 if (!importedData.Compare(value))
334 if (m_bCommaAsDelimiter && (attributeType == SCR_EDataToSpreadsheetDataType.INT || attributeType == SCR_EDataToSpreadsheetDataType.FLOAT))
336 importedData.Replace(
",",
".");
337 value.Replace(
",",
".");
339 if(attributeType == SCR_EDataToSpreadsheetDataType.FLOAT)
341 if(importedData.ToFloat() == value.ToFloat())
345 entSrcAttribute.Set(attributeName, importedData);
346 m_bSaveRequired =
true;
347 PrintFormat(
"Detected difference in data '%1' '%2' '%3'", importedData, value, attributeName, level:
LogLevel.NORMAL);
352 protected void ExportToExcel(
bool useListFromConfig)
354 if (!m_sPrefabConfig)
363 Print(
"Invalid Prefab Config file - either its not correct type or its missing",
LogLevel.ERROR);
367 SCR_DataToSpreadsheetTemplates prefabConfig = SCR_DataToSpreadsheetTemplates.Cast(
BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
368 array<ref ResourceName> selection = {};
369 if (useListFromConfig)
371 selection = prefabConfig.m_aPrefabsArray;
376 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
377 if (!resourceManager)
381 resourceManager.GetResourceBrowserSelection(selection.Insert,
true);
385 if (selection.IsEmpty())
387 Print(
"No elements are selected in Resource Browser",
LogLevel.WARNING);
391 if (m_bPrintToConsole)
397 m_sExportString =
"";
398 m_sHeaderString =
"Name\t";
399 m_bGenerateHeader =
true;
405 if (m_bPrintToConsole)
408 m_sExportString += prefabName +
"\t";
412 if (prefabName.EndsWith(
".et"))
416 else if (prefabName.EndsWith(
".xob") || prefabName.EndsWith(
".edds"))
419 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
420 meta = resourceManager.GetMetaFile(prefabName.GetPath());
423 prefabSource = meta.ToBaseContainer();
427 Print(
string.Format(
"Failed to get meta file for: %1", prefabName),
LogLevel.ERROR);
433 prefabSource = prefab.GetResource().ToBaseContainer();
436 ProcessData(prefabSource, prefabName, prefabConfig);
438 m_sExportString +=
"\n";
439 m_bGenerateHeader =
false;
445 m_bSaveRequired =
false;
451 m_sHeaderString +=
"\n";
452 m_sExportString.Replace(
"\t\n",
"\n");
454 System.ExportToClipboard(m_sHeaderString + m_sExportString);
459 protected override void Run()
464 if (Workbench.ScriptDialog(
"Data To Spreadsheets", DESCRIPTION,
this) == 0)
468 ExportToExcel(m_bUseSelectionFromConfig);
473enum SCR_EDataToSpreadsheetDataType
481class SCR_DataToSpreadsheetElement
483 protected ref map<string, string> m_mElements;
488 string GetData(
string attribute)
490 return m_mElements.Get(attribute);
496 void SCR_DataToSpreadsheetElement(notnull map<string, string>
data)
503class SCR_DataToSpreadsheetTemplates
505 [
Attribute(
desc:
"Array of prefabs which will be processed")]
506 ref array<ref ResourceName> m_aPrefabsArray;
508 [
Attribute(
desc:
"Array of attributes which will be processed")]
509 ref array<ref SCR_DataToSpreadsheetTemplatesBase> m_aAttributesArray;
512[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"Template Base - Has no function")]
513class SCR_DataToSpreadsheetTemplatesBase
525 array<ref SCR_DataToSpreadsheetTemplatesBase> GetAttributes();
528[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"Component: ",
"m_sComponentName")]
529class SCR_DataToSpreadsheetTemplatesComponent : SCR_DataToSpreadsheetTemplatesBase
532 string m_sComponentName;
535 ref array<ref SCR_DataToSpreadsheetTemplatesBase> m_aAttributesArray;
538 override string ReturnType()
544 override ref array<ref SCR_DataToSpreadsheetTemplatesBase> GetAttributes()
546 return m_aAttributesArray;
551class SCR_DataToSpreadsheetTemplatesAttribute : SCR_DataToSpreadsheetTemplatesBase
554 string m_sAttributeName;
556 [
Attribute(
"2", UIWidgets.ComboBox,
desc:
"Specifies type of parameter", enums: ParamEnumArray.FromEnum(SCR_EDataToSpreadsheetDataType))]
557 SCR_EDataToSpreadsheetDataType m_eAttributeType;
560 override string ReturnType()
566[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"Object: ",
"m_sObjectName")]
567class SCR_DataToSpreadsheetTemplatesObject : SCR_DataToSpreadsheetTemplatesBase
570 string m_sObjectName;
572 [
Attribute(
desc:
"Array of attributes which will be exported or modified inside container belonging to prefab")]
573 ref array<ref SCR_DataToSpreadsheetTemplatesBase> m_aAttributesArray;
576 override string ReturnType()
582 override array<ref SCR_DataToSpreadsheetTemplatesBase> GetAttributes()
584 return m_aAttributesArray;
588[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"Object Array: ",
"m_ObjectName")]
589class SCR_DataToSpreadsheetTemplatesObjectArray: SCR_DataToSpreadsheetTemplatesBase
594 [
Attribute(
desc:
"Array of attributes which will be modified inside component belonging to prefab. If component is not present, new one will be created")]
595 ref array<ref SCR_DataToSpreadsheetTemplatesBase> m_AttributesArray;
597 override string ReturnType()
599 return "ObjectArray";
601 override ref array<ref SCR_DataToSpreadsheetTemplatesBase> GetAttributes()
603 return m_AttributesArray;
607[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"Object Index: ",
"m_iObjectIndex")]
608class SCR_DataToSpreadsheetTemplatesObjectIndex : SCR_DataToSpreadsheetTemplatesBase
613 [
Attribute(
desc:
"Array of attributes which will be exported or modified inside container belonging to prefab")]
614 ref array<ref SCR_DataToSpreadsheetTemplatesBase> m_aAttributesArray;
617 override string ReturnType()
619 return "ObjectIndex";
623 override array<ref SCR_DataToSpreadsheetTemplatesBase> GetAttributes()
625 return m_aAttributesArray;
void ContainerIdPathEntry(string propertyName, int index=-1)
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
override string GetData()
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Object holding reference to resource. In destructor release the resource.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute