Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RuinPrefabCreatorPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
3 name: "Missing Ruin Prefabs Creator",
4 category: "Building Destruction",
5 description: "Create Prefabs for ruin models that do not have any",
6 wbModules: { "WorldEditor" },
7 awesomeFontCode: 0xF6BE)]
8class SCR_RuinPrefabCreatorPlugin : WorkbenchPlugin
9{
10 protected static const ResourceName RUIN_BASE = "{A7C1BCA45681EB56}Prefabs/Structures/Core/BuildingRuin_base.et";
11
12 //------------------------------------------------------------------------------------------------
13 override void Run()
14 {
15 if (!SCR_WorldEditorToolHelper.GetWorldEditorAPI())
16 {
17 Print("WorldEditorAPI is not available", LogLevel.ERROR);
18 return;
19 }
20
21 array<ResourceName> ruinModels = SCR_WorkbenchHelper.SearchWorkbenchResources({ "xob" }, { "_ruin" });
22 array<ResourceName> ruinPrefabs = SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_Ruin" });
23 array<ResourceName> prefablessRuins = GetRuinModelsWithoutPrefabs(ruinModels, ruinPrefabs);
24
25 Resource resource;
26 BaseResourceObject resourceObject;
27 IEntitySource entitySource;
28
29 Print("treating " + prefablessRuins.Count() + " prefabless ruins", LogLevel.NORMAL);
30 foreach (ResourceName resourceName : prefablessRuins)
31 {
32 string relativeFilePath = resourceName.GetPath();
33 string absoluteFilePath;
34 if (!Workbench.GetAbsolutePath(relativeFilePath, absoluteFilePath, false))
35 {
36 Print("Cannot get absolute file path for " + resourceName, LogLevel.WARNING);
37 continue;
38 }
39
40 string absoluteFilePathPrefix = absoluteFilePath.Substring(0, absoluteFilePath.IndexOf(relativeFilePath));
41
42 string fileName = FilePath.StripExtension(FilePath.StripPath(absoluteFilePath));
43 string relativePath = FilePath.StripFileName(resourceName.GetPath()); // ends with slash
44 if (!relativePath.StartsWith("Assets/")) // case-sensitive
45 {
46 Print("Cannot treat " + relativePath, LogLevel.NORMAL);
47 continue;
48 }
49
50 string relativePrefabFilePath = "Prefabs" + relativePath.Substring(6, relativePath.Length() - 6) + fileName + ".et";
51 string absolutePrefabFilePath = absoluteFilePathPrefix + relativePrefabFilePath;
52
53 if (FileIO.FileExists(absolutePrefabFilePath))
54 {
55 Print("Skipping " + relativeFilePath + " as " + absolutePrefabFilePath + " already exists", LogLevel.NORMAL);
56 continue;
57 }
58
59 ResourceName createdPrefab = SCR_PrefabHelper.CreatePrefabFromXOB(resourceName, absolutePrefabFilePath, RUIN_BASE, true);
60 if (!createdPrefab) // .IsEmpty()
61 {
62 Print("Cannot create Prefab at " + absolutePrefabFilePath, LogLevel.WARNING);
63 continue;
64 }
65
66 // good?
67 }
68 }
69
70 //------------------------------------------------------------------------------------------------
73 protected array<ResourceName> GetRuinModelsWithoutPrefabs(notnull array<ResourceName> ruinModels, notnull array<ResourceName> ruinPrefabs)
74 {
75 // - Find .xob _Ruin files that do not have an associated _Ruin Prefab
76
77 Resource resource;
78 BaseResourceObject baseResourceObject;
79 IEntitySource entitySource;
80 set<ResourceName> ruinXobSet = new set<ResourceName>(); // found xob set
81 foreach (ResourceName ruinPrefab : ruinPrefabs)
82 {
83 resource = Resource.Load(ruinPrefab);
84 if (!resource.IsValid())
85 {
86 Print("Invalid Ruin Prefab (invalid resource) " + ruinPrefab, LogLevel.WARNING);
87 continue;
88 }
89
90 baseResourceObject = resource.GetResource();
91 if (!baseResourceObject)
92 {
93 Print("Invalid Ruin Prefab (no baseResourceObject) " + ruinPrefab, LogLevel.WARNING);
94 continue;
95 }
96
97 entitySource = baseResourceObject.ToEntitySource();
98 if (!entitySource)
99 {
100 Print("Invalid Ruin Prefab (no entitySource) " + ruinPrefab, LogLevel.WARNING);
101 continue;
102 }
103
104 ResourceName ruinXOB = GetModelFromPrefab(entitySource);
105 if (!ruinXOB)
106 {
107 Print("Invalid Ruin Prefab (no model) " + ruinPrefab, LogLevel.NORMAL);
108 continue;
109 }
110
111 ruinXobSet.Insert(ruinXOB);
112 }
113
114 array<ResourceName> result = {};
115 foreach (ResourceName ruinXOB : ruinModels)
116 {
117 if (!ruinXobSet.Contains(ruinXOB))
118 result.Insert(ruinXOB);
119 }
120
121 return result;
122 }
123
124 //------------------------------------------------------------------------------------------------
125 protected static ResourceName GetModelFromPrefab(notnull IEntitySource entitySource)
126 {
127 IEntityComponentSource meshComp = SCR_BaseContainerTools.FindComponentSource(entitySource, MeshObject);
128 if (!meshComp)
129 return ResourceName.Empty;
130
131 ResourceName result;
132 meshComp.Get("Object", result);
133 return result;
134 }
135
136 /*
137 //------------------------------------------------------------------------------------------------
138 protected override void Configure()
139 {
140 // if (!Workbench.ScriptDialog("SCR_RuinPrefabCreatorPlugin", "<Description>", this))
141 // return;
142 }
143
144 //------------------------------------------------------------------------------------------------
145 [ButtonAttribute("Close", true)]
146 protected int ButtonClose()
147 {
148 return 1;
149 }
150 */
151
152 //------------------------------------------------------------------------------------------------
153 // constructor
154 protected void SCR_RuinPrefabCreatorPlugin();
155}
156#endif
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
ResourceName resourceName
Definition SCR_AIGroup.c:66
override void Run()
MeshObject.
Definition MeshObject.c:34
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
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.
Definition LogLevel.c:14