makes devicelist work if the map hasn't been initialized yet

instead of storing the address, it instead stores the entityUID if in mapping mode
This commit is contained in:
vulppine
2022-08-30 21:56:42 -07:00
parent fa8c16358f
commit 855720c9dc

View File

@@ -30,6 +30,8 @@ public sealed class NetworkConfiguratorSystem : EntitySystem
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<NetworkConfiguratorComponent, MapInitEvent>(OnMapInit);
//Interaction //Interaction
SubscribeLocalEvent<NetworkConfiguratorComponent, AfterInteractEvent>((uid, component, args) => OnUsed(uid, component, args.Target, args.User, args.CanReach)); //TODO: Replace with utility verb? SubscribeLocalEvent<NetworkConfiguratorComponent, AfterInteractEvent>((uid, component, args) => OnUsed(uid, component, args.Target, args.User, args.CanReach)); //TODO: Replace with utility verb?
@@ -63,6 +65,11 @@ public sealed class NetworkConfiguratorSystem : EntitySystem
} }
} }
private void OnMapInit(EntityUid uid, NetworkConfiguratorComponent component, MapInitEvent args)
{
component.Devices.Clear();
}
private void TryAddNetworkDevice(EntityUid? targetUid, EntityUid configuratorUid, EntityUid userUid, private void TryAddNetworkDevice(EntityUid? targetUid, EntityUid configuratorUid, EntityUid userUid,
NetworkConfiguratorComponent? configurator = null) NetworkConfiguratorComponent? configurator = null)
{ {
@@ -77,10 +84,17 @@ public sealed class NetworkConfiguratorSystem : EntitySystem
if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device, false)) if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device, false))
return; return;
if (string.IsNullOrEmpty(device.Address)) var address = device.Address;
if (string.IsNullOrEmpty(address))
{ {
_popupSystem.PopupCursor(Loc.GetString("network-configurator-device-failed", ("device", targetUid)), Filter.Entities(userUid)); if (MetaData(targetUid.Value).EntityLifeStage == EntityLifeStage.MapInitialized)
return; {
_popupSystem.PopupCursor(Loc.GetString("network-configurator-device-failed", ("device", targetUid)),
Filter.Entities(userUid));
return;
}
address = $"UID: {targetUid.Value.ToString()}";
} }
if (configurator.Devices.ContainsValue(targetUid.Value)) if (configurator.Devices.ContainsValue(targetUid.Value))
@@ -89,7 +103,7 @@ public sealed class NetworkConfiguratorSystem : EntitySystem
return; return;
} }
configurator.Devices.Add(device.Address, targetUid.Value); configurator.Devices.Add(address, targetUid.Value);
_popupSystem.PopupCursor(Loc.GetString("network-configurator-device-saved", ("address", device.Address), ("device", targetUid)), _popupSystem.PopupCursor(Loc.GetString("network-configurator-device-saved", ("address", device.Address), ("device", targetUid)),
Filter.Entities(userUid), PopupType.Medium); Filter.Entities(userUid), PopupType.Medium);