LatheSystem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Robust.Client.GameObjects;
  2. using Content.Shared.Lathe;
  3. using Content.Shared.Power;
  4. using Content.Client.Power;
  5. using Content.Shared.Research.Prototypes;
  6. namespace Content.Client.Lathe;
  7. public sealed class LatheSystem : SharedLatheSystem
  8. {
  9. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<LatheComponent, AppearanceChangeEvent>(OnAppearanceChange);
  14. }
  15. private void OnAppearanceChange(EntityUid uid, LatheComponent component, ref AppearanceChangeEvent args)
  16. {
  17. if (args.Sprite == null)
  18. return;
  19. // Lathe specific stuff
  20. if (_appearance.TryGetData<bool>(uid, LatheVisuals.IsRunning, out var isRunning, args.Component))
  21. {
  22. if (args.Sprite.LayerMapTryGet(LatheVisualLayers.IsRunning, out var runningLayer) &&
  23. component.RunningState != null &&
  24. component.IdleState != null)
  25. {
  26. var state = isRunning ? component.RunningState : component.IdleState;
  27. args.Sprite.LayerSetState(runningLayer, state);
  28. }
  29. }
  30. if (_appearance.TryGetData<bool>(uid, PowerDeviceVisuals.Powered, out var powered, args.Component) &&
  31. args.Sprite.LayerMapTryGet(PowerDeviceVisualLayers.Powered, out var powerLayer))
  32. {
  33. args.Sprite.LayerSetVisible(powerLayer, powered);
  34. if (component.UnlitIdleState != null &&
  35. component.UnlitRunningState != null)
  36. {
  37. var state = isRunning ? component.UnlitRunningState : component.UnlitIdleState;
  38. args.Sprite.LayerSetState(powerLayer, state);
  39. }
  40. }
  41. }
  42. ///<remarks>
  43. /// Whether or not a recipe is available is not really visible to the client,
  44. /// so it just defaults to true.
  45. ///</remarks>
  46. protected override bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component)
  47. {
  48. return true;
  49. }
  50. }
  51. public enum LatheVisualLayers : byte
  52. {
  53. IsRunning
  54. }