Vending visualizer update (#9962)
This commit is contained in:
@@ -73,7 +73,6 @@ namespace Content.Client.Entry
|
|||||||
// Do not add to these, they are legacy.
|
// Do not add to these, they are legacy.
|
||||||
factory.RegisterClass<SharedLatheComponent>();
|
factory.RegisterClass<SharedLatheComponent>();
|
||||||
factory.RegisterClass<SharedSpawnPointComponent>();
|
factory.RegisterClass<SharedSpawnPointComponent>();
|
||||||
factory.RegisterClass<SharedVendingMachineComponent>();
|
|
||||||
factory.RegisterClass<SharedReagentDispenserComponent>();
|
factory.RegisterClass<SharedReagentDispenserComponent>();
|
||||||
factory.RegisterClass<SharedChemMasterComponent>();
|
factory.RegisterClass<SharedChemMasterComponent>();
|
||||||
factory.RegisterClass<SharedGravityGeneratorComponent>();
|
factory.RegisterClass<SharedGravityGeneratorComponent>();
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Content.Shared.VendingMachines;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.Animations;
|
using Robust.Client.Animations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
using Robust.Client.ResourceManagement;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
||||||
@@ -139,7 +142,18 @@ namespace Content.Client.VendingMachines.UI
|
|||||||
base.OnChangeData(component);
|
base.OnChangeData(component);
|
||||||
|
|
||||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||||
var sprite = entMan.GetComponent<ISpriteComponent>(component.Owner);
|
var sprite = entMan.GetComponent<SpriteComponent>(component.Owner);
|
||||||
|
|
||||||
|
// TODO when moving to a system visualizer, re work how this is done
|
||||||
|
// Currently this only gets called during init, so unless it NEEEDS to be configurable, just make this party of the entity prototype.
|
||||||
|
if (component.TryGetData(VendingMachineVisuals.Inventory, out string? invId) &&
|
||||||
|
IoCManager.Resolve<IPrototypeManager>().TryIndex(invId, out VendingMachineInventoryPrototype? prototype) &&
|
||||||
|
IoCManager.Resolve<IResourceCache>().TryGetResource<RSIResource>(
|
||||||
|
SharedSpriteComponent.TextureRoot / $"Structures/Machines/VendingMachines/{prototype.SpriteName}.rsi", out var res))
|
||||||
|
{
|
||||||
|
sprite.BaseRSI = res.RSI;
|
||||||
|
}
|
||||||
|
|
||||||
var animPlayer = entMan.GetComponent<AnimationPlayerComponent>(component.Owner);
|
var animPlayer = entMan.GetComponent<AnimationPlayerComponent>(component.Owner);
|
||||||
if (!component.TryGetData(VendingMachineVisuals.VisualState, out VendingMachineVisualState state))
|
if (!component.TryGetData(VendingMachineVisuals.VisualState, out VendingMachineVisualState state))
|
||||||
{
|
{
|
||||||
|
|||||||
10
Content.Client/VendingMachines/VendingMachineComponent.cs
Normal file
10
Content.Client/VendingMachines/VendingMachineComponent.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Content.Shared.VendingMachines;
|
||||||
|
|
||||||
|
namespace Content.Client.VendingMachines;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
[ComponentReference(typeof(SharedVendingMachineComponent))]
|
||||||
|
public sealed class VendingMachineComponent : SharedVendingMachineComponent
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
7
Content.Client/VendingMachines/VendingMachineSystem.cs
Normal file
7
Content.Client/VendingMachines/VendingMachineSystem.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using Content.Shared.VendingMachines;
|
||||||
|
|
||||||
|
namespace Content.Client.VendingMachines;
|
||||||
|
|
||||||
|
public sealed class VendingMachineSystem : SharedVendingMachineSystem
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -8,17 +8,11 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
|
|||||||
namespace Content.Server.VendingMachines
|
namespace Content.Server.VendingMachines
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
|
[ComponentReference(typeof(SharedVendingMachineComponent))]
|
||||||
public sealed class VendingMachineComponent : SharedVendingMachineComponent
|
public sealed class VendingMachineComponent : SharedVendingMachineComponent
|
||||||
{
|
{
|
||||||
public bool Ejecting;
|
public bool Ejecting;
|
||||||
|
|
||||||
public TimeSpan AnimationDuration = TimeSpan.Zero;
|
|
||||||
|
|
||||||
[ViewVariables] [DataField("pack", customTypeSerializer:typeof(PrototypeIdSerializer<VendingMachineInventoryPrototype>))]
|
|
||||||
public string PackPrototypeId = string.Empty;
|
|
||||||
|
|
||||||
public string SpriteName = "";
|
|
||||||
|
|
||||||
public bool Broken;
|
public bool Broken;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
|||||||
|
|
||||||
namespace Content.Server.VendingMachines
|
namespace Content.Server.VendingMachines
|
||||||
{
|
{
|
||||||
public sealed class VendingMachineSystem : EntitySystem
|
public sealed class VendingMachineSystem : SharedVendingMachineSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
@@ -32,7 +32,7 @@ namespace Content.Server.VendingMachines
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<VendingMachineComponent, ComponentInit>(OnComponentInit);
|
|
||||||
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
SubscribeLocalEvent<VendingMachineComponent, InventorySyncRequestMessage>(OnInventoryRequestMessage);
|
SubscribeLocalEvent<VendingMachineComponent, InventorySyncRequestMessage>(OnInventoryRequestMessage);
|
||||||
SubscribeLocalEvent<VendingMachineComponent, VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
SubscribeLocalEvent<VendingMachineComponent, VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
||||||
@@ -43,9 +43,11 @@ namespace Content.Server.VendingMachines
|
|||||||
SubscribeLocalEvent<VendingMachineComponent, VendingMachineSelfDispenseEvent>(OnSelfDispense);
|
SubscribeLocalEvent<VendingMachineComponent, VendingMachineSelfDispenseEvent>(OnSelfDispense);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
|
protected override void OnComponentInit(EntityUid uid, SharedVendingMachineComponent sharedComponent, ComponentInit args)
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.OnComponentInit(uid, sharedComponent, args);
|
||||||
|
|
||||||
|
var component = (VendingMachineComponent) sharedComponent;
|
||||||
|
|
||||||
if (TryComp<ApcPowerReceiverComponent>(component.Owner, out var receiver))
|
if (TryComp<ApcPowerReceiverComponent>(component.Owner, out var receiver))
|
||||||
{
|
{
|
||||||
@@ -57,8 +59,6 @@ namespace Content.Server.VendingMachines
|
|||||||
var action = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(component.Action));
|
var action = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(component.Action));
|
||||||
_action.AddAction(uid, action, uid);
|
_action.AddAction(uid, action, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeFromPrototype(uid, component);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInventoryRequestMessage(EntityUid uid, VendingMachineComponent component, InventorySyncRequestMessage args)
|
private void OnInventoryRequestMessage(EntityUid uid, VendingMachineComponent component, InventorySyncRequestMessage args)
|
||||||
@@ -123,67 +123,6 @@ namespace Content.Server.VendingMachines
|
|||||||
EjectRandom(uid, true, component);
|
EjectRandom(uid, true, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitializeFromPrototype(EntityUid uid, VendingMachineComponent? vendComponent = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref vendComponent))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(vendComponent.PackPrototypeId)) { return; }
|
|
||||||
|
|
||||||
if (!_prototypeManager.TryIndex(vendComponent.PackPrototypeId, out VendingMachineInventoryPrototype? packPrototype))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MetaData(uid).EntityName = packPrototype.Name;
|
|
||||||
vendComponent.AnimationDuration = TimeSpan.FromSeconds(packPrototype.AnimationDuration);
|
|
||||||
vendComponent.SpriteName = packPrototype.SpriteName;
|
|
||||||
if (!string.IsNullOrEmpty(vendComponent.SpriteName))
|
|
||||||
{
|
|
||||||
if (TryComp<SpriteComponent>(vendComponent.Owner, out var spriteComp)) {
|
|
||||||
const string vendingMachineRSIPath = "Structures/Machines/VendingMachines/{0}.rsi";
|
|
||||||
spriteComp.BaseRSIPath = string.Format(vendingMachineRSIPath, vendComponent.SpriteName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AddInventoryFromPrototype(uid, packPrototype.StartingInventory, InventoryType.Regular, vendComponent);
|
|
||||||
AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, vendComponent);
|
|
||||||
AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, vendComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddInventoryFromPrototype(EntityUid uid, Dictionary<string, uint>? entries,
|
|
||||||
InventoryType type,
|
|
||||||
VendingMachineComponent? component = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref component) || entries == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var inventory = new List<VendingMachineInventoryEntry>();
|
|
||||||
|
|
||||||
foreach (var (id, amount) in entries)
|
|
||||||
{
|
|
||||||
if (_prototypeManager.HasIndex<EntityPrototype>(id))
|
|
||||||
{
|
|
||||||
inventory.Add(new VendingMachineInventoryEntry(type, id, amount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case InventoryType.Regular:
|
|
||||||
component.Inventory.AddRange(inventory);
|
|
||||||
break;
|
|
||||||
case InventoryType.Emagged:
|
|
||||||
component.EmaggedInventory.AddRange(inventory);
|
|
||||||
break;
|
|
||||||
case InventoryType.Contraband:
|
|
||||||
component.ContrabandInventory.AddRange(inventory);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Deny(EntityUid uid, VendingMachineComponent? vendComponent = null)
|
public void Deny(EntityUid uid, VendingMachineComponent? vendComponent = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref vendComponent))
|
if (!Resolve(uid, ref vendComponent))
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
namespace Content.Shared.VendingMachines
|
namespace Content.Shared.VendingMachines
|
||||||
{
|
{
|
||||||
[Virtual]
|
|
||||||
[NetworkedComponent()]
|
[NetworkedComponent()]
|
||||||
public class SharedVendingMachineComponent : Component
|
public abstract class SharedVendingMachineComponent : Component
|
||||||
{
|
{
|
||||||
|
[DataField("pack", customTypeSerializer: typeof(PrototypeIdSerializer<VendingMachineInventoryPrototype>))]
|
||||||
|
public string PackPrototypeId = string.Empty;
|
||||||
|
|
||||||
|
public TimeSpan AnimationDuration = TimeSpan.Zero;
|
||||||
|
|
||||||
[ViewVariables] public List<VendingMachineInventoryEntry> Inventory = new();
|
[ViewVariables] public List<VendingMachineInventoryEntry> Inventory = new();
|
||||||
[ViewVariables] public List<VendingMachineInventoryEntry> EmaggedInventory = new();
|
[ViewVariables] public List<VendingMachineInventoryEntry> EmaggedInventory = new();
|
||||||
[ViewVariables] public List<VendingMachineInventoryEntry> ContrabandInventory = new();
|
[ViewVariables] public List<VendingMachineInventoryEntry> ContrabandInventory = new();
|
||||||
@@ -32,6 +37,7 @@ namespace Content.Shared.VendingMachines
|
|||||||
public enum VendingMachineVisuals
|
public enum VendingMachineVisuals
|
||||||
{
|
{
|
||||||
VisualState,
|
VisualState,
|
||||||
|
Inventory,
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
65
Content.Shared/VendingMachines/SharedVendingMachineSystem.cs
Normal file
65
Content.Shared/VendingMachines/SharedVendingMachineSystem.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
||||||
|
|
||||||
|
namespace Content.Shared.VendingMachines;
|
||||||
|
|
||||||
|
public abstract class SharedVendingMachineSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<SharedVendingMachineComponent, ComponentInit>(OnComponentInit);;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnComponentInit(EntityUid uid, SharedVendingMachineComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
if (!_prototypeManager.TryIndex(component.PackPrototypeId, out VendingMachineInventoryPrototype? packPrototype))
|
||||||
|
return;
|
||||||
|
|
||||||
|
MetaData(uid).EntityName = packPrototype.Name;
|
||||||
|
component.AnimationDuration = TimeSpan.FromSeconds(packPrototype.AnimationDuration);
|
||||||
|
|
||||||
|
if (TryComp(component.Owner, out AppearanceComponent? appearance))
|
||||||
|
appearance.SetData(VendingMachineVisuals.Inventory, component.PackPrototypeId);
|
||||||
|
|
||||||
|
AddInventoryFromPrototype(uid, packPrototype.StartingInventory, InventoryType.Regular, component);
|
||||||
|
AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component);
|
||||||
|
AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddInventoryFromPrototype(EntityUid uid, Dictionary<string, uint>? entries,
|
||||||
|
InventoryType type,
|
||||||
|
SharedVendingMachineComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component) || entries == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var inventory = new List<VendingMachineInventoryEntry>();
|
||||||
|
|
||||||
|
foreach (var (id, amount) in entries)
|
||||||
|
{
|
||||||
|
if (_prototypeManager.HasIndex<EntityPrototype>(id))
|
||||||
|
{
|
||||||
|
inventory.Add(new VendingMachineInventoryEntry(type, id, amount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case InventoryType.Regular:
|
||||||
|
component.Inventory.AddRange(inventory);
|
||||||
|
break;
|
||||||
|
case InventoryType.Emagged:
|
||||||
|
component.EmaggedInventory.AddRange(inventory);
|
||||||
|
break;
|
||||||
|
case InventoryType.Contraband:
|
||||||
|
component.ContrabandInventory.AddRange(inventory);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ namespace Content.Shared.VendingMachines
|
|||||||
[DataField("animationDuration")]
|
[DataField("animationDuration")]
|
||||||
public double AnimationDuration { get; }
|
public double AnimationDuration { get; }
|
||||||
|
|
||||||
|
// TODO make this a proper sprite specifier for yaml linting.
|
||||||
[DataField("spriteName")]
|
[DataField("spriteName")]
|
||||||
public string SpriteName { get; } = string.Empty;
|
public string SpriteName { get; } = string.Empty;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user