Skip to content

Commit

Permalink
Add cartridge fabricator
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryNorfolk committed Jan 11, 2025
1 parent a9d799b commit f5c299d
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Content.Shared.Tag;

namespace Content.Server._DV.Chemistry.Components;

[RegisterComponent]
public sealed partial class CartridgeFabricatorComponent : Component
{
[DataField]
public string InputSolution = "drink";

[DataField]
public string OutputSolution = "cartridge";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Content.Server._DV.Chemistry.Components;
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;
using YamlDotNet.Core.Tokens;

namespace Content.Server._DV.Chemistry.Systems;

public sealed class CartridgeFabricatorSystem : EntitySystem
{
[Dependency] private readonly SharedSolutionContainerSystem _container = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly TagSystem _tags = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

private static readonly ProtoId<TagPrototype>[] BottleTags = {"Bottle"};

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CartridgeFabricatorComponent, InteractUsingEvent>(OnInteractUsing);
}

private void OnInteractUsing(Entity<CartridgeFabricatorComponent> entity, ref InteractUsingEvent args)
{
if (!this.IsPowered(entity.Owner, EntityManager))
return;

if (!TryComp(args.Used, out SolutionContainerManagerComponent? manager))
return;

if (!_tags.HasAnyTag(args.Used, BottleTags))
return;

if (!_container.TryGetSolution((args.Used, manager),
entity.Comp.InputSolution,
out var _,
out var fromSolution))
return;

// Success, this is a bottle with an amount of _something_ in it.
args.Handled = true;

_popupSystem.PopupCursor("You made a thing!", args.User, PopupType.Medium);

var coords = Transform(entity.Owner).Coordinates;
var cartridge = Spawn("BaseEmptyHypoCartridge", coords);

var cartridgeManager = EnsureComp<SolutionContainerManagerComponent>(cartridge);
if (!_container.TryGetSolution((cartridge, cartridgeManager),
entity.Comp.OutputSolution,
out var cartridgeSolutionEnt,
out var _))
return; // Something very wrong here?

if (!_container.TryAddSolution(cartridgeSolutionEnt.Value, fromSolution))
return;

QueueDel(args.Used); // Ensure the old one is gone
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

- type: entity
id: CartridgeFabricatorMachineCircuitboard
parent: BaseMachineCircuitboard
name: cartridge fabricator machine board
description: A machine printed circuit board for a cartridge fabricator
components:
- type: Sprite
state: service
- type: MachineBoard
prototype: CartridgeFabricator
stackRequirements:
Manipulator: 2
Capacitor: 1
# replacing the console screen
Glass: 1
Cable: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
- type: entity
id: CartridgeFabricator
name: cartridge fabricator
parent: [ BaseMachinePowered, ConstructibleMachine ]
description: Converts bottles of chemicals into hypospray cartridges
components:
# TODO: Make this not the seed extractor
- type: Sprite
sprite: Structures/Machines/seed_extractor.rsi
snapCardinals: true
layers:
- state: seedextractor-off
- state: seedextractor-unlit
shader: unshaded
map: ["enum.PowerDeviceVisualLayers.Powered"]
- type: Physics
bodyType: Static
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-0.25,-0.4,0.25,0.4"
density: 190
mask:
- MachineMask
layer:
- MachineLayer
- type: Appearance
- type: GenericVisualizer
visuals:
enum.PowerDeviceVisuals.Powered:
enum.PowerDeviceVisualLayers.Powered:
True: { visible: true }
False: { visible: false }
- type: CartridgeFabricator
- type: Machine
board: CartridgeFabricatorMachineCircuitboard

0 comments on commit f5c299d

Please sign in to comment.