3 name:
"Prefab Template Class Check",
4 description:
"PrefabsLibrary templates must not have a different class than their Prefabs counterpart; this tool verifies this.",
5 wbModules: {
"ResourceManager" },
7 awesomeFontCode: 0xF560)]
8class SCR_PrefabTemplateClassCheckPlugin : WorkbenchPlugin
10 [
Attribute(defvalue:
"0",
desc:
"Tries and replaces wrong classes (difference between Template declared class and parent Prefab class)")]
11 protected bool m_bFixTemplateClasses;
13 protected static const int MIN_DESCRIPTION_WIDTH = 110;
18 FindAndPrintDiscrepancies();
23 protected void FindAndPrintDiscrepancies()
25 array<string> addonGUIDs = {};
28 array<ResourceName> resourceNames = {};
30 foreach (
string addonGUID : addonGUIDs)
33 if (addonID ==
"core")
36 Print(
"Looking into " + addonID +
"/PrefabLibrary",
LogLevel.NORMAL);
40 int count = resourceNames.Count();
41 Print(
"Processing " + count +
" Templates class check",
LogLevel.NORMAL);
48 array<ResourceName> invalidTemplates = {};
49 array<ResourceName> orphanTemplates = {};
50 array<ref Tuple3<ResourceName, string, string>> classMismatches = {};
51 array<ref Tuple3<ResourceName, string, string>> selfMismatches = {};
53 Debug.BeginTimeMeasure();
58 if (!resource.IsValid())
64 baseContainer = resource.GetResource().ToBaseContainer();
71 baseContainerAncestor = baseContainer.GetAncestor();
72 if (!baseContainerAncestor)
78 string childClassName = classnameCache.Get(
resourceName);
81 childClassName = GetClassNameFromPrefabFile(
resourceName);
88 ResourceName ancestorResourceName = baseContainerAncestor.GetResourceName();
89 string ancestorClassName = classnameCache.Get(ancestorResourceName);
90 if (!ancestorClassName)
92 ancestorClassName = GetClassNameFromPrefabFile(ancestorResourceName);
93 if (!ancestorResourceName)
96 classnameCache.Insert(ancestorResourceName, ancestorClassName);
99 if (childClassName != ancestorClassName)
106 Debug.EndTimeMeasure(
"Processed " + count +
" Templates");
118 int fixedClassMismatches;
121 Print(
SCR_StringHelper.
PadRight(
string.Format(
"Template class (%1) differs from ancestor Prefab class (%2): ", tuple.param2, tuple.param3), MIN_DESCRIPTION_WIDTH) + tuple.param1,
LogLevel.WARNING);
122 if (m_bFixTemplateClasses)
124 if (ChangeTemplateClass(tuple.param1, tuple.param3))
126 Print(
"Successfully changed class " + tuple.param2 +
" to " + tuple.param3,
LogLevel.NORMAL);
127 fixedClassMismatches++;
131 Print(
"Could not change class " + tuple.param2 +
" to " + tuple.param3,
LogLevel.WARNING);
136 Print(
"Found " + invalidTemplates.Count() +
" invalid, " +
137 orphanTemplates.Count() +
" orphans, " +
138 classMismatches.Count() +
" class mismatches (" + fixedClassMismatches +
" fixed), " +
139 "over " + count +
" Templates",
LogLevel.NORMAL);
155 string absoluteFilePath;
156 if (!Workbench.GetAbsolutePath(
resourceName.GetPath(), absoluteFilePath,
true))
170 fileHandle.ReadLine(firstLine);
173 int spaceIndex = firstLine.IndexOf(
" ");
180 return firstLine.Substring(0, spaceIndex);
197 newClassName.TrimInPlace();
205 string absoluteFilePath;
206 if (!Workbench.GetAbsolutePath(
resourceName.GetPath(), absoluteFilePath,
true))
220 array<string> lines = {};
221 while (!fileHandle.IsEOF())
223 fileHandle.ReadLine(lineContent);
224 lines.Insert(lineContent);
229 int spaceIndex = lines[0].IndexOf(
" ");
236 lines[0] = newClassName + lines[0].Substring(spaceIndex, lines[0].Length() - spaceIndex);
245 foreach (
int lineNumber,
string line : lines)
247 fileHandle.WriteLine(line);
258 Workbench.ScriptDialog(
"bweh",
"Settings",
this);
ResourceName resourceName
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.
static string PadRight(string input, int length, string padding=SPACE)
static bool IsEmptyOrWhiteSpace(string input)
static array< ResourceName > SearchWorkbenchResources(array< string > fileExtensions=null, array< string > searchStrArray=null, string rootPath="", bool recursive=true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
FileMode
Mode for opening file. See FileSystem::Open.