Skip to content

Commit

Permalink
Trenches - Add garbage collection for unbuilt trenches (#108)
Browse files Browse the repository at this point in the history
Add unbuilt trenches to garbage system
  • Loading branch information
Kexanone authored Sep 23, 2024
1 parent 7c0ca17 commit 431b2ac
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
14 changes: 14 additions & 0 deletions addons/trenches/Configs/Systems/ChimeraSystemsConfig.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SystemSettings : "{45C53F06BA17238D}configs/Systems/SystemsConfig.conf" {
Systems {
SCR_GarbageSystem "{5F10E7EA29B0EDEC}" {
Rules {
ComponentClassGarbageRule "{626E356A67F1AC10}" {
Filter "ACE_Trenches_OutlineGarbageComponent"
Lifetime 300
PlayerDistance 3.5
LifetimeResetPercentage 2
}
}
}
}
}
17 changes: 17 additions & 0 deletions addons/trenches/Configs/Systems/ChimeraSystemsConfig.conf.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MetaFileClass {
Name "{86E953538A28A98D}Configs/Systems/ChimeraSystemsConfig.conf"
Configurations {
CONFResourceClass PC {
}
CONFResourceClass XBOX_ONE : PC {
}
CONFResourceClass XBOX_SERIES : PC {
}
CONFResourceClass PS4 : PC {
}
CONFResourceClass PS5 : PC {
}
CONFResourceClass HEADLESS : PC {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
GenericEntity : "{AE4206993ACBAE48}Prefabs/Compositions/Misc/FreeRoamBuilding/ACE_DirtCover_01_long_v1.et" {
ID "5282DCB5DFC8538F"
components {
ACE_Trenches_OutlineGarbageComponent "{626E298C73057C81}" {
}
SCR_EditableEntityComponent "{5E50727929EC2547}" : "{8B8F72167C615EAA}Prefabs/Editor/Components/Compositions_SCR_EditableEntityComponent.ct" {
m_UIInfo SCR_EditableEntityUIInfo "{5298E609432D192D}" {
Name "#AR-EditableEntity_DirtCover_01_long_v1_Name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
GenericEntity : "{C81B764F6C5B4064}Prefabs/Compositions/Misc/FreeRoamBuilding/ACE_DirtCover_01_short.et" {
ID "5282DCB5DFC8538F"
components {
ACE_Trenches_OutlineGarbageComponent "{626E298C69997233}" {
}
SCR_EditableEntityComponent "{5E50727929EC2547}" : "{8B8F72167C615EAA}Prefabs/Editor/Components/Compositions_SCR_EditableEntityComponent.ct" {
m_UIInfo SCR_EditableEntityUIInfo "{5298E609432D192D}" {
Name "#AR-EditableEntity_DirtCover_01_short_Name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------------------------
class ACE_Trenches_OutlineGarbageComponentClass : ScriptComponentClass
{
}

//------------------------------------------------------------------------------------------------
//! Unbuilt structures with this component get handled by the garbage system
//! It gets dropped from the queue once built
class ACE_Trenches_OutlineGarbageComponent : ScriptComponent
{
//------------------------------------------------------------------------------------------------
//! Add to garbage system queue on init
override protected void OnPostInit(IEntity owner)
{
super.OnPostInit(owner);

if (!GetGame().InPlayMode() || !Replication.IsServer())
return;

SCR_GarbageSystem garbageSystem = SCR_GarbageSystem.GetByEntityWorld(owner);
if (!garbageSystem)
return;

SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(owner.FindComponent(SCR_CampaignBuildingCompositionComponent));
if (!compositionComponent)
return;

garbageSystem.Insert(owner);
compositionComponent.GetOnCompositionSpawned().Insert(OnCompositionSpawned);
}

//------------------------------------------------------------------------------------------------
//! Remove from garbage system queue when built
protected void OnCompositionSpawned(bool compositionSpawned)
{
SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(GetOwner().FindComponent(SCR_CampaignBuildingCompositionComponent));
if (!compositionComponent)
return;

compositionComponent.GetOnCompositionSpawned().Remove(OnCompositionSpawned);

SCR_GarbageSystem garbageSystem = SCR_GarbageSystem.GetByEntityWorld(GetOwner());
if (!garbageSystem)
return;

garbageSystem.Withdraw(GetOwner());
}
}

0 comments on commit 431b2ac

Please sign in to comment.