fix: EntityPrototypeView now only creates entities when the UI is open

Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Fildrance
2025-01-27 16:25:52 +03:00
committed by GitHub
parent d5e6e91b58
commit de55d1bc52
2 changed files with 26 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ END TEMPLATE-->
### Bugfixes
*None yet*
* EntityPrototypeView control now avoids creating entities if the prototype is set while the control is not on the UI tree.
### Other

View File

@@ -22,8 +22,6 @@ public class EntityPrototypeView : SpriteView
public void SetPrototype(EntProtoId? entProto)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();
if (entProto == _currentPrototype
&& EntMan.TryGetComponent(Entity?.Owner, out MetaDataComponent? meta)
&& meta.EntityPrototype?.ID == _currentPrototype)
@@ -32,14 +30,10 @@ public class EntityPrototypeView : SpriteView
}
_currentPrototype = entProto;
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);
if (_currentPrototype != null)
if (_ourEntity != null)
{
_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
UpdateEntity();
}
}
@@ -48,12 +42,34 @@ public class EntityPrototypeView : SpriteView
base.EnteredTree();
if (_currentPrototype != null)
SetPrototype(_currentPrototype);
{
UpdateEntity();
}
}
protected override void ExitedTree()
{
base.ExitedTree();
EntMan.TryQueueDeleteEntity(_ourEntity);
_ourEntity = null;
}
private void UpdateEntity()
{
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);
if (_currentPrototype != null)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();
_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
}
else
{
_ourEntity = null;
}
}
}