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:
@@ -52,7 +52,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
|
||||
if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview))
|
||||
{
|
||||
_machinePreview = null;
|
||||
@@ -70,13 +70,14 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
||||
else if (_currentBoard != null)
|
||||
{
|
||||
//todo double trycomp is kinda stinky.
|
||||
if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var board) &&
|
||||
board.Prototype != null)
|
||||
{
|
||||
var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker),
|
||||
(_currentBoard.Value, board));
|
||||
PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost);
|
||||
}
|
||||
Dictionary<string, int> cost;
|
||||
if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoardComp) &&
|
||||
machineBoardComp.Prototype is not null)
|
||||
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
|
||||
else
|
||||
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
|
||||
|
||||
PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost);
|
||||
}
|
||||
|
||||
if (_currentBoard == itemSlot.Item)
|
||||
@@ -88,17 +89,30 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
||||
_currentBoard = itemSlot.Item;
|
||||
CostHeaderLabel.Visible = _currentBoard != null;
|
||||
|
||||
if (_currentBoard != null &&
|
||||
_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard) &&
|
||||
machineBoard.Prototype != null)
|
||||
if (_currentBoard is not null)
|
||||
{
|
||||
var proto = _prototypeManager.Index<EntityPrototype>(machineBoard.Prototype);
|
||||
_machinePreview = _entityManager.Spawn(proto.ID);
|
||||
_spriteSystem.ForceUpdate(_machinePreview.Value);
|
||||
MachineNameLabel.SetMessage(proto.Name);
|
||||
var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker),
|
||||
(_currentBoard.Value, machineBoard));
|
||||
CostLabel.SetMarkup(GetCostString(cost));
|
||||
string? prototype = null;
|
||||
Dictionary<string, int>? cost = null;
|
||||
|
||||
if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard))
|
||||
{
|
||||
prototype = machineBoard.Prototype;
|
||||
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
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Construction;
|
||||
using Content.Shared.Construction.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Shared.Timing;
|
||||
using YamlDotNet.Serialization.NodeTypeResolvers;
|
||||
|
||||
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)
|
||||
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;
|
||||
|
||||
if (!MaterialStorage.CanChangeMaterialAmount(uid, GetFlatpackCreationCost(ent, (machineBoard, boardComp))))
|
||||
if (!MaterialStorage.CanChangeMaterialAmount(uid, cost))
|
||||
return;
|
||||
|
||||
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)
|
||||
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;
|
||||
|
||||
var materialCost = GetFlatpackCreationCost(ent, (machineBoard, boardComp));
|
||||
if (!MaterialStorage.TryChangeMaterialAmount((ent, null), materialCost))
|
||||
if (!MaterialStorage.TryChangeMaterialAmount((ent, null), cost))
|
||||
return;
|
||||
|
||||
var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
|
||||
SetupFlatpack(flatpack, (machineBoard, boardComp));
|
||||
SetupFlatpack(flatpack, machineBoard);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Construction.Components
|
||||
namespace Content.Shared.Construction.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for construction graphs in building computers.
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -26,6 +26,13 @@
|
||||
security: "#DE3A3A"
|
||||
science: "#D381C9"
|
||||
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
|
||||
price: 500
|
||||
- type: Tag
|
||||
|
||||
@@ -31,9 +31,13 @@
|
||||
True: { visible: true }
|
||||
False: { visible: false }
|
||||
- type: FlatpackCreator
|
||||
baseMaterialCost:
|
||||
baseMachineCost:
|
||||
Steel: 600
|
||||
Plastic: 200
|
||||
baseComputerCost:
|
||||
Steel: 600
|
||||
Plastic: 200
|
||||
Glass: 200
|
||||
- type: Machine
|
||||
board: FlatpackerMachineCircuitboard
|
||||
- type: MaterialStorage
|
||||
@@ -68,6 +72,7 @@
|
||||
whitelist:
|
||||
components:
|
||||
- MachineBoard
|
||||
- ComputerBoard
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
machine_board: !type:Container
|
||||
|
||||
Reference in New Issue
Block a user