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

@@ -52,7 +52,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)
{ {
base.FrameUpdate(args); base.FrameUpdate(args);
if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview)) if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview))
{ {
_machinePreview = null; _machinePreview = null;
@@ -70,13 +70,14 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
else if (_currentBoard != null) else if (_currentBoard != null)
{ {
//todo double trycomp is kinda stinky. //todo double trycomp is kinda stinky.
if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var board) && Dictionary<string, int> cost;
board.Prototype != null) if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoardComp) &&
{ machineBoardComp.Prototype is not null)
var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
(_currentBoard.Value, board)); else
PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost); cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
}
PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost);
} }
if (_currentBoard == itemSlot.Item) if (_currentBoard == itemSlot.Item)
@@ -88,17 +89,30 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
_currentBoard = itemSlot.Item; _currentBoard = itemSlot.Item;
CostHeaderLabel.Visible = _currentBoard != null; CostHeaderLabel.Visible = _currentBoard != null;
if (_currentBoard != null && if (_currentBoard is not null)
_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard) &&
machineBoard.Prototype != null)
{ {
var proto = _prototypeManager.Index<EntityPrototype>(machineBoard.Prototype); string? prototype = null;
_machinePreview = _entityManager.Spawn(proto.ID); Dictionary<string, int>? cost = null;
_spriteSystem.ForceUpdate(_machinePreview.Value);
MachineNameLabel.SetMessage(proto.Name); if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard))
var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), {
(_currentBoard.Value, machineBoard)); prototype = machineBoard.Prototype;
CostLabel.SetMarkup(GetCostString(cost)); cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoard));
}
else if (_entityManager.TryGetComponent<ComputerBoardComponent>(_currentBoard, out var computerBoard))
{
prototype = computerBoard.Prototype;
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
}
if (prototype is not null && cost is not null)
{
var proto = _prototypeManager.Index<EntityPrototype>(prototype);
_machinePreview = _entityManager.Spawn(proto.ID);
_spriteSystem.ForceUpdate(_machinePreview.Value);
MachineNameLabel.SetMessage(proto.Name);
CostLabel.SetMarkup(GetCostString(cost));
}
} }
else else
{ {

View File

@@ -5,6 +5,7 @@ using Content.Shared.Construction;
using Content.Shared.Construction.Components; using Content.Shared.Construction.Components;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using YamlDotNet.Serialization.NodeTypeResolvers;
namespace Content.Server.Construction; namespace Content.Server.Construction;
@@ -33,10 +34,16 @@ public sealed class FlatpackSystem : SharedFlatpackSystem
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard) if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
return; return;
if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp)) Dictionary<string, int>? cost = null;
if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
if (TryComp<ComputerBoardComponent>(machineBoard, out var computerBoardComponent))
cost = GetFlatpackCreationCost(ent);
if (cost is null)
return; return;
if (!MaterialStorage.CanChangeMaterialAmount(uid, GetFlatpackCreationCost(ent, (machineBoard, boardComp)))) if (!MaterialStorage.CanChangeMaterialAmount(uid, cost))
return; return;
comp.Packing = true; comp.Packing = true;
@@ -68,15 +75,20 @@ public sealed class FlatpackSystem : SharedFlatpackSystem
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard) if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
return; return;
if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp)) Dictionary<string, int>? cost = null;
if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
if (TryComp<ComputerBoardComponent>(machineBoard, out var computerBoardComponent))
cost = GetFlatpackCreationCost(ent);
if (cost is null)
return; return;
var materialCost = GetFlatpackCreationCost(ent, (machineBoard, boardComp)); if (!MaterialStorage.TryChangeMaterialAmount((ent, null), cost))
if (!MaterialStorage.TryChangeMaterialAmount((ent, null), materialCost))
return; return;
var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates); var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
SetupFlatpack(flatpack, (machineBoard, boardComp)); SetupFlatpack(flatpack, machineBoard);
} }
public override void Update(float frameTime) public override void Update(float frameTime)

View File

@@ -1,7 +1,7 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Construction.Components namespace Content.Shared.Construction.Components
{ {
/// <summary> /// <summary>
/// Used for construction graphs in building computers. /// Used for construction graphs in building computers.

View File

@@ -42,9 +42,17 @@ public sealed partial class FlatpackCreatorComponent : Component
/// <summary> /// <summary>
/// A default cost applied to all flatpacks outside of the cost of constructing the machine. /// A default cost applied to all flatpacks outside of the cost of constructing the machine.
/// This one is applied to machines specifically.
/// </summary> /// </summary>
[DataField] [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)] [DataField, ViewVariables(VVAccess.ReadWrite)]
public string SlotId = "board_slot"; public string SlotId = "board_slot";

View File

@@ -115,13 +115,17 @@ public abstract class SharedFlatpackSystem : EntitySystem
ent.Comp.PackEndTime += args.PausedTime; 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; return;
if (machineBoard.Comp.Prototype is not { } machinePrototypeId) EntProtoId machinePrototypeId;
return; 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 comp = ent.Comp!;
var machinePrototype = PrototypeManager.Index(machinePrototypeId); var machinePrototype = PrototypeManager.Index(machinePrototypeId);
@@ -133,13 +137,25 @@ public abstract class SharedFlatpackSystem : EntitySystem
comp.Entity = machinePrototypeId; comp.Entity = machinePrototypeId;
Dirty(ent, comp); 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); Dictionary<string, int> cost = new();
foreach (var (mat, amount) in entity.Comp.BaseMaterialCost) 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.TryAdd(mat, 0);
cost[mat] -= amount; cost[mat] -= amount;

View File

@@ -26,6 +26,13 @@
security: "#DE3A3A" security: "#DE3A3A"
science: "#D381C9" science: "#D381C9"
supply: "#A46106" supply: "#A46106"
cpu_command: "#334E6D"
cpu_medical: "#52B4E9"
cpu_service: "#9FED58"
cpu_engineering: "#EFB341"
cpu_security: "#DE3A3A"
cpu_science: "#D381C9"
cpu_supply: "#A46106"
- type: StaticPrice - type: StaticPrice
price: 500 price: 500
- type: Tag - type: Tag

View File

@@ -31,9 +31,13 @@
True: { visible: true } True: { visible: true }
False: { visible: false } False: { visible: false }
- type: FlatpackCreator - type: FlatpackCreator
baseMaterialCost: baseMachineCost:
Steel: 600 Steel: 600
Plastic: 200 Plastic: 200
baseComputerCost:
Steel: 600
Plastic: 200
Glass: 200
- type: Machine - type: Machine
board: FlatpackerMachineCircuitboard board: FlatpackerMachineCircuitboard
- type: MaterialStorage - type: MaterialStorage
@@ -68,6 +72,7 @@
whitelist: whitelist:
components: components:
- MachineBoard - MachineBoard
- ComputerBoard
- type: ContainerContainer - type: ContainerContainer
containers: containers:
machine_board: !type:Container machine_board: !type:Container