From 082bde40ca3fd39fff5daea26de4311cf2001f85 Mon Sep 17 00:00:00 2001 From: SpeltIncorrectyl <66873282+SpeltIncorrectyl@users.noreply.github.com> Date: Thu, 4 Jan 2024 04:23:47 +0000 Subject: [PATCH] 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 --- .../UI/FlatpackCreatorMenu.xaml.cs | 50 ++++++++++++------- Content.Server/Construction/FlatpackSystem.cs | 24 ++++++--- .../Components/ComputerBoardComponent.cs | 2 +- .../Components/FlatpackCreatorComponent.cs | 10 +++- .../Construction/SharedFlatpackSystem.cs | 32 +++++++++--- .../Entities/Objects/Devices/flatpack.yml | 7 +++ .../Structures/Machines/flatpacker.yml | 7 ++- 7 files changed, 97 insertions(+), 35 deletions(-) rename {Content.Server => Content.Shared}/Construction/Components/ComputerBoardComponent.cs (90%) diff --git a/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs b/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs index 3041f6a504..8f8fec64a3 100644 --- a/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs +++ b/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs @@ -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(_currentBoard, out var board) && - board.Prototype != null) - { - var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), - (_currentBoard.Value, board)); - PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost); - } + Dictionary cost; + if (_entityManager.TryGetComponent(_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(_currentBoard, out var machineBoard) && - machineBoard.Prototype != null) + if (_currentBoard is not null) { - var proto = _prototypeManager.Index(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? cost = null; + + if (_entityManager.TryGetComponent(_currentBoard, out var machineBoard)) + { + prototype = machineBoard.Prototype; + cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoard)); + } + else if (_entityManager.TryGetComponent(_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(prototype); + _machinePreview = _entityManager.Spawn(proto.ID); + _spriteSystem.ForceUpdate(_machinePreview.Value); + MachineNameLabel.SetMessage(proto.Name); + CostLabel.SetMarkup(GetCostString(cost)); + } } else { diff --git a/Content.Server/Construction/FlatpackSystem.cs b/Content.Server/Construction/FlatpackSystem.cs index b5f9228158..9cd8643cbd 100644 --- a/Content.Server/Construction/FlatpackSystem.cs +++ b/Content.Server/Construction/FlatpackSystem.cs @@ -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(machineBoard, out var boardComp)) + Dictionary? cost = null; + if (TryComp(machineBoard, out var machineBoardComponent)) + cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent)); + if (TryComp(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(machineBoard, out var boardComp)) + Dictionary? cost = null; + if (TryComp(machineBoard, out var machineBoardComponent)) + cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent)); + if (TryComp(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) diff --git a/Content.Server/Construction/Components/ComputerBoardComponent.cs b/Content.Shared/Construction/Components/ComputerBoardComponent.cs similarity index 90% rename from Content.Server/Construction/Components/ComputerBoardComponent.cs rename to Content.Shared/Construction/Components/ComputerBoardComponent.cs index f3e897c3e4..f80a668778 100644 --- a/Content.Server/Construction/Components/ComputerBoardComponent.cs +++ b/Content.Shared/Construction/Components/ComputerBoardComponent.cs @@ -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 { /// /// Used for construction graphs in building computers. diff --git a/Content.Shared/Construction/Components/FlatpackCreatorComponent.cs b/Content.Shared/Construction/Components/FlatpackCreatorComponent.cs index 0f52d63628..1270591548 100644 --- a/Content.Shared/Construction/Components/FlatpackCreatorComponent.cs +++ b/Content.Shared/Construction/Components/FlatpackCreatorComponent.cs @@ -42,9 +42,17 @@ public sealed partial class FlatpackCreatorComponent : Component /// /// A default cost applied to all flatpacks outside of the cost of constructing the machine. + /// This one is applied to machines specifically. /// [DataField] - public Dictionary, int> BaseMaterialCost = new(); + public Dictionary, int> BaseMachineCost = new(); + + /// + /// A default cost applied to all flatpacks outside of the cost of constructing the machine. + /// This one is applied to computers specifically. + /// + [DataField] + public Dictionary, int> BaseComputerCost = new(); [DataField, ViewVariables(VVAccess.ReadWrite)] public string SlotId = "board_slot"; diff --git a/Content.Shared/Construction/SharedFlatpackSystem.cs b/Content.Shared/Construction/SharedFlatpackSystem.cs index 094f9d86d5..6432f87e8e 100644 --- a/Content.Shared/Construction/SharedFlatpackSystem.cs +++ b/Content.Shared/Construction/SharedFlatpackSystem.cs @@ -115,13 +115,17 @@ public abstract class SharedFlatpackSystem : EntitySystem ent.Comp.PackEndTime += args.PausedTime; } - public void SetupFlatpack(Entity ent, Entity machineBoard) + public void SetupFlatpack(Entity 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(board, out var machineBoard) && machineBoard.Prototype is not null) + machinePrototypeId = machineBoard.Prototype; + else if (TryComp(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 GetFlatpackCreationCost(Entity entity, Entity machineBoard) + public Dictionary GetFlatpackCreationCost(Entity entity, Entity? machineBoard = null) { - var cost = MachinePart.GetMachineBoardMaterialCost(machineBoard, -1); - foreach (var (mat, amount) in entity.Comp.BaseMaterialCost) + Dictionary cost = new(); + Dictionary, 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; diff --git a/Resources/Prototypes/Entities/Objects/Devices/flatpack.yml b/Resources/Prototypes/Entities/Objects/Devices/flatpack.yml index 31578bdd9c..9d49d7e994 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/flatpack.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/flatpack.yml @@ -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 diff --git a/Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml b/Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml index 529d2ee9f0..69e5678f42 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml @@ -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