Content update for NetEntities (#18935)

This commit is contained in:
metalgearsloth
2023-09-11 09:42:41 +10:00
committed by GitHub
parent 389c8d1a2c
commit 5a0fc68be2
526 changed files with 3058 additions and 2215 deletions

View File

@@ -12,6 +12,7 @@ using Content.Server.Station.Systems;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared.Access.Components;
using Content.Shared.CartridgeLoader;
using Content.Shared.Light.Components;
using Content.Shared.PDA;
using Robust.Server.GameObjects;
@@ -67,6 +68,13 @@ namespace Content.Server.PDA
protected override void OnItemRemoved(EntityUid uid, PdaComponent pda, EntRemovedFromContainerMessage args)
{
if (args.Container.ID != pda.IdSlot.ID && args.Container.ID != pda.PenSlot.ID)
return;
// TODO: This is super cursed just use compstates please.
if (MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
return;
base.OnItemRemoved(uid, pda, args);
UpdatePdaUi(uid, pda);
}
@@ -105,9 +113,12 @@ namespace Content.Server.PDA
/// <summary>
/// Send new UI state to clients, call if you modify something like uplink.
/// </summary>
public void UpdatePdaUi(EntityUid uid, PdaComponent pda)
public void UpdatePdaUi(EntityUid uid, PdaComponent? pda = null)
{
if (!_ui.TryGetUi(uid, PdaUiKey.Key, out _))
if (!Resolve(uid, ref pda, false))
return;
if (!_ui.TryGetUi(uid, PdaUiKey.Key, out var ui))
return;
var address = GetDeviceNetAddress(uid);
@@ -119,8 +130,15 @@ namespace Content.Server.PDA
// TODO: Update the level and name of the station with each call to UpdatePdaUi is only needed for latejoin players.
// TODO: If someone can implement changing the level and name of the station when changing the PDA grid, this can be removed.
// TODO don't make this depend on cartridge loader!?!?
if (!TryComp(uid, out CartridgeLoaderComponent? loader))
return;
var programs = _cartridgeLoader.GetAvailablePrograms(uid, loader);
var id = CompOrNull<IdCardComponent>(pda.ContainedId);
var state = new PdaUpdateState(
programs,
GetNetEntity(loader.ActiveProgram),
pda.FlashlightOn,
pda.PenSlot.HasItem,
new PdaIdInfoText
@@ -136,7 +154,7 @@ namespace Content.Server.PDA
hasInstrument,
address);
_cartridgeLoader?.UpdateUiState(uid, state);
_ui.SetUiState(ui, state);
}
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaRequestUpdateInterfaceMessage msg)