]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
The Flatpacker 1001 can now make flatpacks for computers. (#23471)
authorSpeltIncorrectyl <66873282+SpeltIncorrectyl@users.noreply.github.com>
Thu, 4 Jan 2024 04:23:47 +0000 (04:23 +0000)
committerGitHub <noreply@github.com>
Thu, 4 Jan 2024 04:23:47 +0000 (23:23 -0500)
* 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

Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs
Content.Server/Construction/FlatpackSystem.cs
Content.Shared/Construction/Components/ComputerBoardComponent.cs [moved from Content.Server/Construction/Components/ComputerBoardComponent.cs with 90% similarity]
Content.Shared/Construction/Components/FlatpackCreatorComponent.cs
Content.Shared/Construction/SharedFlatpackSystem.cs
Resources/Prototypes/Entities/Objects/Devices/flatpack.yml
Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml

index 3041f6a504c83900ef7e8f2da9b0a06906eb4c94..8f8fec64a3948fb72381c24bac505c5b678012d0 100644 (file)
@@ -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
         {
index b5f92281588ec45deb87767e9908ba7227c2d855..9cd8643cbd45fa827648ca564f5f1499d3198569 100644 (file)
@@ -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)
similarity index 90%
rename from Content.Server/Construction/Components/ComputerBoardComponent.cs
rename to Content.Shared/Construction/Components/ComputerBoardComponent.cs
index f3e897c3e42552b2d4050005020ff5729d718e6b..f80a6687781bd97ef09bdcea89cea8ca78823c44 100644 (file)
@@ -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.
index 0f52d6362848db21cdc82f1543c372a322e56bcd..1270591548fcbb639ad2fd22ca6ee3fe6ed55e38 100644 (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";
index 094f9d86d591dd2da6c410add32eacf0861e3a1c..6432f87e8ed9ce04565da1f19f1ee43c6b7566d1 100644 (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;
index 31578bdd9ce8e1d0eac4dcca2f377ca1c4539739..9d49d7e994107406405889c0c97e6dbc5df56f15 100644 (file)
       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
index 529d2ee9f0233d92f7dbff42941148d80fe52452..69e5678f4226727d0e23cfd64161a1a30279db75 100644 (file)
           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