3class SCR_RegisterPlaceableEntitiesPlugin : WorkbenchPlugin
5 [
Attribute(
desc:
"File to which the resulting list will be saved.",
params:
"class=SCR_PlaceableEntitiesRegistry conf")]
6 protected ResourceName m_sConfig;
11 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
12 WBProgressDialog progress =
new WBProgressDialog(
"Scanning...", resourceManager);
15 if (m_sConfig.IsEmpty())
21 Resource configContainer = BaseContainerTools.LoadContainer(m_sConfig);
25 SCR_PlaceableEntitiesRegistry registry = SCR_PlaceableEntitiesRegistry.Cast(BaseContainerTools.CreateInstanceFromContainer(configContainer.GetResource().ToBaseContainer()));
28 Print(
string.Format(
"SCR_PlaceableEntitiesRegistry class not found in '%1'!", m_sConfig),
LogLevel.ERROR);
32 string filesystem = SCR_AddonTool.ToFileSystem(registry.GetAddon());
33 string directory = registry.GetSourceDirectory().GetPath();
36 array<ResourceName> resources = {};
38 SearchResourcesFilter filter =
new SearchResourcesFilter();
39 filter.fileExtensions = {
"et" };
40 filter.rootPath = filesystem + directory;
41 ResourceDatabase.SearchResources(filter, resources.Insert);
43 array<ResourceName> prefabs = {};
47 BaseResourceObject object;
49 IEntityComponentSource editableEntityComponent;
50 IEntityComponentSource component;
51 int resourcesCount = resources.Count();
52 float prevProgress, currProgress;
53 foreach (
int i, ResourceName prefab : resources)
55 container = BaseContainerTools.LoadContainer(prefab);
59 object = container.GetResource();
60 entity =
object.ToEntitySource();
63 int componentCount = entity.GetComponentCount();
64 editableEntityComponent = null;
65 for (
int c = 0; c < componentCount; c++)
67 component = entity.GetComponent(c);
69 if (component.GetClassName().ToType().IsInherited(SCR_EditableEntityComponent))
70 editableEntityComponent = component;
74 if (editableEntityComponent)
77 if (!SCR_EditableEntityComponentClass.HasFlag(editableEntityComponent,
EEditableEntityFlag.PLACEABLE))
80 Print(
string.Format(
"Registered '%1'", prefab),
LogLevel.DEBUG);
81 prefabs.Insert(prefab);
84 currProgress = i / resourcesCount;
85 if (currProgress - prevProgress >= 0.01)
87 progress.SetProgress(currProgress);
88 prevProgress = currProgress;
95 registry.SetPrefabs(prefabs);
96 container = BaseContainerTools.CreateContainerFromInstance(registry);
99 BaseContainerTools.SaveContainer(container.GetResource().ToBaseContainer(), m_sConfig);
100 resourceManager.SetOpenedResource(m_sConfig);
101 resourceManager.Save();
102 Print(
string.Format(
"Entities from '%1' saved to '%2'", directory, m_sConfig.GetPath()),
LogLevel.DEBUG);
109 if (Workbench.ScriptDialog(
"Register Placeable Entities",
"Register all entity prefabs that have SCR_EditableEntityComponent\nwith PLACEABLE flag into target config.\nThe game uses it to get the list of all entities available for placing.\n\nMake sure you don't have the target config open!",
this))
129 protected bool Cancel()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_RespawnComponentClass OK
Result code for request/assign response.
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", 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.
EEditableEntityFlag
Unique flags of the entity.
SCR_FieldOfViewSettings Attribute