The Flatpacker 1001 can now make flatpacks for computers. (#23471)

* moved ComputerBoardComponent to Content.Shared

* made flatpacker accept computer boards

* made flatpack system and ui function with computer boards

* fixed it so that flatpacks of computers are correctly coloured to fit their computer board colour

* unhardcoded the computer flatpack assembly cost

* Combined GetFlatpackCreationCost(...) with GetflatpackCreationCostForComputer(...)

* removed code duplication in SharedFlatpackSystem

* removed code duplication from FlatpackCreatorMenu.xaml.cs

* remove code duplication from FlatpackSystem (on the server)

* fixed indentation error
This commit is contained in:
SpeltIncorrectyl
2024-01-04 04:23:47 +00:00
committed by GitHub
parent f533a1a543
commit 082bde40ca
7 changed files with 97 additions and 35 deletions

View File

@@ -0,0 +1,15 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Construction.Components
{
/// <summary>
/// Used for construction graphs in building computers.
/// </summary>
[RegisterComponent]
public sealed partial class ComputerBoardComponent : Component
{
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? Prototype { get; private set; }
}
}

View File

@@ -42,9 +42,17 @@ public sealed partial class FlatpackCreatorComponent : Component
/// <summary>
/// A default cost applied to all flatpacks outside of the cost of constructing the machine.
/// This one is applied to machines specifically.
/// </summary>
[DataField]
public Dictionary<ProtoId<MaterialPrototype>, int> BaseMaterialCost = new();
public Dictionary<ProtoId<MaterialPrototype>, int> BaseMachineCost = new();
/// <summary>
/// A default cost applied to all flatpacks outside of the cost of constructing the machine.
/// This one is applied to computers specifically.
/// </summary>
[DataField]
public Dictionary<ProtoId<MaterialPrototype>, int> BaseComputerCost = new();
[DataField, ViewVariables(VVAccess.ReadWrite)]
public string SlotId = "board_slot";

View File

@@ -115,13 +115,17 @@ public abstract class SharedFlatpackSystem : EntitySystem
ent.Comp.PackEndTime += args.PausedTime;
}
public void SetupFlatpack(Entity<FlatpackComponent?> ent, Entity<MachineBoardComponent?> machineBoard)
public void SetupFlatpack(Entity<FlatpackComponent?> ent, EntityUid? board)
{
if (!Resolve(ent, ref ent.Comp) || !Resolve(machineBoard, ref machineBoard.Comp))
if (!Resolve(ent, ref ent.Comp))
return;
if (machineBoard.Comp.Prototype is not { } machinePrototypeId)
return;
EntProtoId machinePrototypeId;
string? entityPrototype;
if (TryComp<MachineBoardComponent>(board, out var machineBoard) && machineBoard.Prototype is not null)
machinePrototypeId = machineBoard.Prototype;
else if (TryComp<ComputerBoardComponent>(board, out var computerBoard) && computerBoard.Prototype is not null)
machinePrototypeId = computerBoard.Prototype;
var comp = ent.Comp!;
var machinePrototype = PrototypeManager.Index(machinePrototypeId);
@@ -133,13 +137,25 @@ public abstract class SharedFlatpackSystem : EntitySystem
comp.Entity = machinePrototypeId;
Dirty(ent, comp);
Appearance.SetData(ent, FlatpackVisuals.Machine, MetaData(machineBoard).EntityPrototype?.ID ?? string.Empty);
if (board is null)
return;
Appearance.SetData(ent, FlatpackVisuals.Machine, MetaData(board.Value).EntityPrototype?.ID ?? string.Empty);
}
public Dictionary<string, int> GetFlatpackCreationCost(Entity<FlatpackCreatorComponent> entity, Entity<MachineBoardComponent> machineBoard)
public Dictionary<string, int> GetFlatpackCreationCost(Entity<FlatpackCreatorComponent> entity, Entity<MachineBoardComponent>? machineBoard = null)
{
var cost = MachinePart.GetMachineBoardMaterialCost(machineBoard, -1);
foreach (var (mat, amount) in entity.Comp.BaseMaterialCost)
Dictionary<string, int> cost = new();
Dictionary<ProtoId<MaterialPrototype>, int> baseCost;
if (machineBoard is not null)
{
cost = MachinePart.GetMachineBoardMaterialCost(machineBoard.Value, -1);
baseCost = entity.Comp.BaseMachineCost;
}
else
baseCost = entity.Comp.BaseComputerCost;
foreach (var (mat, amount) in baseCost)
{
cost.TryAdd(mat, 0);
cost[mat] -= amount;