Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SlotManagerComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(insertable: false)]
2 class SCR_SpawnerSlotManagerClass : GenericEntityClass
3 {
4 }
5 
7 class SCR_SpawnerSlotManager : GenericEntity
8 {
9  protected static SCR_SpawnerSlotManager s_Instance;
10 
11  protected ref array <SCR_EntitySpawnerSlotComponent> m_aSlots = {};
13 
14  protected ref ScriptInvoker m_OnSlotCreated;
15  protected ref ScriptInvoker m_OnSlotRemoved;
16  protected ref ScriptInvoker m_OnSlotUpdated;
17 
18  //------------------------------------------------------------------------------------------------
20  ScriptInvoker GetOnSlotCreated()
21  {
22  if (!m_OnSlotCreated)
23  m_OnSlotCreated = new ScriptInvoker();
24 
25  return m_OnSlotCreated;
26  }
27 
28  //------------------------------------------------------------------------------------------------
30  ScriptInvoker GetOnSlotRemoved()
31  {
32  if (!m_OnSlotRemoved)
33  m_OnSlotRemoved = new ScriptInvoker();
34 
35  return m_OnSlotRemoved;
36  }
37 
38  //------------------------------------------------------------------------------------------------
40  ScriptInvoker GetOnSlotUpdated()
41  {
42  if (!m_OnSlotUpdated)
43  m_OnSlotUpdated = new ScriptInvoker();
44 
45  return m_OnSlotUpdated;
46  }
47 
48  //------------------------------------------------------------------------------------------------
50  static SCR_SpawnerSlotManager GetInstance()
51  {
52  if (s_Instance)
53  return s_Instance;
54 
55  s_Instance = SCR_SpawnerSlotManager.Cast(GetGame().SpawnEntity(SCR_SpawnerSlotManager, GetGame().GetWorld()));
56  if (!s_Instance)
57  return null;
58 
59  s_Instance.SetupSlotUpdatedInvoker();
60  return s_Instance;
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  protected void SetupSlotUpdatedInvoker()
65  {
67  if (core)
68  core.Event_OnEntityTransformChanged.Insert(OnSlotUpdated);
69  }
70 
71  //------------------------------------------------------------------------------------------------
74  void RegisterSlot(SCR_EntitySpawnerSlotComponent slot)
75  {
76  m_aSlots.Insert(slot);
77 
79  m_EditableEntityCore.Event_OnEntityTransformChanged.Insert(OnSlotUpdated);
80 
81  if (m_OnSlotCreated)
82  m_OnSlotCreated.Invoke(slot);
83  }
84 
85  //------------------------------------------------------------------------------------------------
88  void UnregisterSlot(notnull SCR_EntitySpawnerSlotComponent slot)
89  {
90  if (m_aSlots.Contains(slot))
91  m_aSlots.RemoveItem(slot);
92 
93  if (m_OnSlotRemoved)
94  m_OnSlotRemoved.Invoke(slot);
95  }
96 
97  //------------------------------------------------------------------------------------------------
99  void OnSlotUpdated(notnull SCR_EditableEntityComponent editableComponent)
100  {
101  IEntity slotOwner = editableComponent.GetOwner();
102  if (!slotOwner)
103  return;
104 
105  SCR_EntitySpawnerSlotComponent slot = SCR_EntitySpawnerSlotComponent.Cast(slotOwner.FindComponent(SCR_EntitySpawnerSlotComponent));
106  if (slot && m_OnSlotUpdated)
107  m_OnSlotUpdated.Invoke(slot, slotOwner.GetOrigin());
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  protected override void EOnInit(IEntity owner)
112  {
113  super.EOnInit(owner);
114 
116  if (core)
117  core.Event_OnEntityTransformChanged.Insert(OnSlotUpdated);
118  else
119  Print("SCR_EditableEntityCore not found! Slot transformation won't be updated!", LogLevel.WARNING);
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  // destructor
125  {
126  if (s_Instance == this)
127  s_Instance = null;
128  }
129 }
SpawnEntity
protected IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition: SCR_CatalogEntitySpawnerComponent.c:1008
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
SCR_SpawnerSlotManagerClass
Definition: SCR_SlotManagerComponent.c:2
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SetupSlotUpdatedInvoker
protected void SetupSlotUpdatedInvoker()
Definition: SCR_SlotManagerComponent.c:64
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetOnSlotCreated
ScriptInvoker GetOnSlotCreated()
Definition: SCR_SlotManagerComponent.c:20
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
m_EditableEntityCore
protected SCR_EditableEntityCore m_EditableEntityCore
Definition: SCR_SlotManagerComponent.c:12
m_aSlots
protected ref array< SCR_EntitySpawnerSlotComponent > m_aSlots
Definition: SCR_SlotManagerComponent.c:11
RegisterSlot
void RegisterSlot(SCR_EntitySpawnerSlotComponent slot)
Definition: SCR_SlotManagerComponent.c:74
m_OnSlotUpdated
protected ref ScriptInvoker m_OnSlotUpdated
Definition: SCR_SlotManagerComponent.c:16
GetOnSlotRemoved
ScriptInvoker GetOnSlotRemoved()
Definition: SCR_SlotManagerComponent.c:30
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EOnInit
protected override void EOnInit(IEntity owner)
Definition: SCR_SlotManagerComponent.c:111
~SCR_SpawnerSlotManager
void ~SCR_SpawnerSlotManager()
Definition: SCR_SlotManagerComponent.c:124
UnregisterSlot
void UnregisterSlot(notnull SCR_EntitySpawnerSlotComponent slot)
Definition: SCR_SlotManagerComponent.c:88
GetOnSlotUpdated
ScriptInvoker GetOnSlotUpdated()
Definition: SCR_SlotManagerComponent.c:40
OnSlotUpdated
void OnSlotUpdated(notnull SCR_EditableEntityComponent editableComponent)
Definition: SCR_SlotManagerComponent.c:99
m_OnSlotCreated
protected ref ScriptInvoker m_OnSlotCreated
Definition: SCR_SlotManagerComponent.c:14
m_OnSlotRemoved
protected ref ScriptInvoker m_OnSlotRemoved
Definition: SCR_SlotManagerComponent.c:15