ToolConstructionGraphStep.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Content.Shared.Examine;
  2. using Content.Shared.Tools;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  5. namespace Content.Shared.Construction.Steps
  6. {
  7. [DataDefinition]
  8. public sealed partial class ToolConstructionGraphStep : ConstructionGraphStep
  9. {
  10. [DataField("tool", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
  11. public string Tool { get; private set; } = string.Empty;
  12. [DataField("fuel")] public float Fuel { get; private set; } = 10;
  13. [DataField("examine")] public string ExamineOverride { get; private set; } = string.Empty;
  14. public override void DoExamine(ExaminedEvent examinedEvent)
  15. {
  16. if (!string.IsNullOrEmpty(ExamineOverride))
  17. {
  18. examinedEvent.PushMarkup(Loc.GetString(ExamineOverride));
  19. return;
  20. }
  21. if (string.IsNullOrEmpty(Tool) || !IoCManager.Resolve<IPrototypeManager>().TryIndex(Tool, out ToolQualityPrototype? quality))
  22. return;
  23. examinedEvent.PushMarkup(Loc.GetString("construction-use-tool-entity", ("toolName", Loc.GetString(quality.ToolName))));
  24. }
  25. public override ConstructionGuideEntry GenerateGuideEntry()
  26. {
  27. var quality = IoCManager.Resolve<IPrototypeManager>().Index<ToolQualityPrototype>(Tool);
  28. return new ConstructionGuideEntry()
  29. {
  30. Localization = "construction-presenter-tool-step",
  31. Arguments = new (string, object)[]{("tool", quality.ToolName)},
  32. Icon = quality.Icon,
  33. };
  34. }
  35. }
  36. }