Files
wwdpublic/Content.Shared/_Arcadis/Computer/DiskBurnerSystem.cs
Eris d26d53b025 Modular Computers Part 2: Disk Burner (#1580)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

This is **Part 2** of the Modular Computers system, adding the
functional player facing stuff- the modular computer itself, a way to
make and burn disks via the Disk Burner and a related research.

Also comes with some cleanup changes to fix parts of the system that
broke in testing.

---

# TODO

<!--
A list of everything you have to do before this PR is "complete"
You probably won't have to complete everything before merging but it's
good to leave future references
-->

- [x] Actually run through this thing when my laptop is out of battery
(everything worked except CONSTRUCTING the disk burner)
- [ ] Add disk burning delay, make it more intuitive? Maybe a guidebook
entry?

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>

NO.

</p>
</details>

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- add: Added the Disk Burner, the Modular Computer as a board and a way
to make computer disks.

---------

Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
Signed-off-by: Eris <erisfiregamer1@gmail.com>
Signed-off-by: Eris <eris@erisws.com>
Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
(cherry picked from commit 7d59d26654da45df2783767512c2a4c1dc8af746)
2025-01-20 21:26:10 +03:00

118 lines
4.0 KiB
C#

using Content.Shared.Containers.ItemSlots;
using Content.Shared.Coordinates;
using Robust.Shared.Audio;
using Content.Shared.Audio;
using Robust.Shared.Network;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Audio.Systems;
using Content.Shared.Popups;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Robust.Shared.Timing;
using Content.Shared.Construction.Components;
using Content.Shared.Verbs;
using Robust.Shared.Utility;
namespace Content.Shared._Arcadis.Computer;
public sealed class DiskBurnerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DiskBurnerComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<DiskBurnerComponent, GetVerbsEvent<Verb>>(GetVerb);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
}
private void GetVerb(EntityUid uid, DiskBurnerComponent component, GetVerbsEvent<Verb> args)
{
args.Verbs.Add(new Verb
{
Act = () => BurnDisk(args.User, uid, component),
Text = Loc.GetString(component.VerbName),
// TODO VERB ICON find a better icon
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/settings.svg.192dpi.png")),
});
}
private void BurnDisk(EntityUid user, EntityUid entity, DiskBurnerComponent component)
{
if (!TryComp(entity, out ItemSlotsComponent? slots)
|| !_itemSlots.TryGetSlot(entity, component.DiskSlot, out var diskSlot)
|| !_itemSlots.TryGetSlot(entity, component.BoardSlot, out var boardSlot)
|| diskSlot.Item is null
|| boardSlot.Item is null
|| !TryComp(boardSlot.Item.Value, out ComputerBoardComponent? boardComp)
|| boardComp.ModularComputerProgramPrototype is null
|| !TryComp(diskSlot.Item.Value, out ComputerDiskComponent? diskComp))
{
_popupSystem.PopupPredicted(Loc.GetString("disk-burner-activate-not-ready"), entity, user);
return;
}
diskComp.ProgramPrototype = boardComp.ModularComputerProgramPrototype.Value;
_popupSystem.PopupPredicted(Loc.GetString("disk-burner-activate-finished"), entity, user);
}
private void OnExamined(EntityUid uid, DiskBurnerComponent component, ExaminedEvent args)
{
if (!TryComp(uid, out ItemSlotsComponent? slots)
|| !_itemSlots.TryGetSlot(uid, component.DiskSlot, out var diskSlot)
|| !_itemSlots.TryGetSlot(uid, component.BoardSlot, out var boardSlot))
{
args.PushMarkup(Loc.GetString("disk-burner-admemes-fail"));
return;
}
if (diskSlot.Item is null || boardSlot.Item is null)
{
var missing = new List<string>();
if (diskSlot.Item is null)
missing.Add("disk");
if (boardSlot.Item is null)
missing.Add("or");
args.PushMarkup(Loc.GetString("disk-burner-missing", ("missing", string.Join(", or ", missing))));
return;
}
if (!TryComp(diskSlot.Item.Value, out ComputerDiskComponent? diskComp))
{
args.PushMarkup(Loc.GetString("disk-burner-bad-disk"));
return;
}
if (!TryComp(boardSlot.Item.Value, out ComputerBoardComponent? boardComp))
{
args.PushMarkup(Loc.GetString("disk-burner-incompatible-board"));
return;
}
if (boardComp.ModularComputerProgramPrototype is null)
{
args.PushMarkup(Loc.GetString("disk-burner-incompatible-board"));
return;
}
args.PushMarkup(Loc.GetString("disk-burner-ready"));
}
}