]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Flatpacks and the Flatpacker 1001 (#23338)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Wed, 3 Jan 2024 06:16:02 +0000 (01:16 -0500)
committerGitHub <noreply@github.com>
Wed, 3 Jan 2024 06:16:02 +0000 (17:16 +1100)
* Flatpacker and flatpacks

* ok that's good enough

* convert solars/AME to flatpacks

* mats, mats, we are the mats

* basic mechanics are DONE

* thing

* final UI

* sloth

* rped jumpscare

* rename

40 files changed:
Content.Client/Construction/FlatpackSystem.cs [new file with mode: 0644]
Content.Client/Construction/UI/FlatpackCreatorBoundUserInterface.cs [new file with mode: 0644]
Content.Client/Construction/UI/FlatpackCreatorMenu.xaml [new file with mode: 0644]
Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs [new file with mode: 0644]
Content.Client/Materials/UI/MaterialDisplay.xaml
Content.Client/Materials/UI/MaterialStorageControl.xaml.cs
Content.Server/Ame/Components/AmePartComponent.cs [deleted file]
Content.Server/Ame/EntitySystems/AmePartSystem.cs [deleted file]
Content.Server/Construction/FlatpackSystem.cs [new file with mode: 0644]
Content.Shared/Construction/Components/FlatpackComponent.cs [new file with mode: 0644]
Content.Shared/Construction/Components/FlatpackCreatorComponent.cs [new file with mode: 0644]
Content.Shared/Construction/MachinePartSystem.cs
Content.Shared/Construction/SharedFlatpackSystem.cs [new file with mode: 0644]
Content.Shared/Lathe/SharedLatheSystem.cs
Content.Shared/Materials/SharedMaterialStorageSystem.cs
Resources/Locale/en-US/construction/components/flatpack.ftl [new file with mode: 0644]
Resources/Locale/en-US/research/technologies.ftl
Resources/Locale/en-US/wires/wire-names.ftl
Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml
Resources/Prototypes/Entities/Objects/Devices/flatpack.yml [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Devices/station_beacon.yml
Resources/Prototypes/Entities/Objects/Power/antimatter_part.yml
Resources/Prototypes/Entities/Objects/Power/solar_parts.yml
Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml [new file with mode: 0644]
Resources/Prototypes/Entities/Structures/Machines/lathe.yml
Resources/Prototypes/Entities/Structures/Power/Generation/solar.yml
Resources/Prototypes/Recipes/Lathes/electronics.yml
Resources/Prototypes/Research/industrial.yml
Resources/Prototypes/tags.yml
Resources/Textures/Objects/Devices/flatpack.rsi/base.png [new file with mode: 0644]
Resources/Textures/Objects/Devices/flatpack.rsi/icon-default.png [new file with mode: 0644]
Resources/Textures/Objects/Devices/flatpack.rsi/meta.json [new file with mode: 0644]
Resources/Textures/Objects/Devices/flatpack.rsi/overlay.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/flatpacker.rsi/base.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/flatpacker.rsi/inserting.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/flatpacker.rsi/meta.json [new file with mode: 0644]
Resources/Textures/Structures/Machines/flatpacker.rsi/packing.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/flatpacker.rsi/panel.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/flatpacker.rsi/screen.png [new file with mode: 0644]
SpaceStation14.sln.DotSettings

diff --git a/Content.Client/Construction/FlatpackSystem.cs b/Content.Client/Construction/FlatpackSystem.cs
new file mode 100644 (file)
index 0000000..911ff12
--- /dev/null
@@ -0,0 +1,48 @@
+using Content.Shared.Construction;
+using Content.Shared.Construction.Components;
+using Robust.Client.GameObjects;
+using Robust.Shared.Prototypes;
+
+namespace Content.Client.Construction;
+
+/// <inheritdoc/>
+public sealed class FlatpackSystem : SharedFlatpackSystem
+{
+    [Dependency] private readonly AppearanceSystem _appearance = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<FlatpackComponent, AppearanceChangeEvent>(OnAppearanceChange);
+    }
+
+    private void OnAppearanceChange(Entity<FlatpackComponent> ent, ref AppearanceChangeEvent args)
+    {
+        var (_, comp) = ent;
+        if (!_appearance.TryGetData<string>(ent, FlatpackVisuals.Machine, out var machineBoardId) || args.Sprite == null)
+            return;
+
+        if (!PrototypeManager.TryIndex<EntityPrototype>(machineBoardId, out var machineBoardPrototype))
+            return;
+
+        if (!machineBoardPrototype.TryGetComponent<SpriteComponent>(out var sprite))
+            return;
+
+        Color? color = null;
+        foreach (var layer in sprite.AllLayers)
+        {
+            if (layer.RsiState.Name is not { } spriteState)
+                continue;
+
+            if (!comp.BoardColors.TryGetValue(spriteState, out var c))
+                continue;
+            color = c;
+            break;
+        }
+
+        if (color != null)
+            args.Sprite.LayerSetColor(FlatpackVisualLayers.Overlay, color.Value);
+    }
+}
diff --git a/Content.Client/Construction/UI/FlatpackCreatorBoundUserInterface.cs b/Content.Client/Construction/UI/FlatpackCreatorBoundUserInterface.cs
new file mode 100644 (file)
index 0000000..86f1b8b
--- /dev/null
@@ -0,0 +1,40 @@
+using Content.Shared.Construction.Components;
+using JetBrains.Annotations;
+
+namespace Content.Client.Construction.UI
+{
+    [UsedImplicitly]
+    public sealed class FlatpackCreatorBoundUserInterface : BoundUserInterface
+    {
+        [ViewVariables]
+        private FlatpackCreatorMenu? _menu;
+
+        public FlatpackCreatorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
+        {
+        }
+
+        protected override void Open()
+        {
+            base.Open();
+
+            _menu = new FlatpackCreatorMenu(Owner);
+            _menu.OnClose += Close;
+
+            _menu.PackButtonPressed += () =>
+            {
+                SendMessage(new FlatpackCreatorStartPackBuiMessage());
+            };
+
+            _menu.OpenCentered();
+        }
+
+        protected override void Dispose(bool disposing)
+        {
+            base.Dispose(disposing);
+            if (!disposing)
+                return;
+
+            _menu?.Dispose();
+        }
+    }
+}
diff --git a/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml b/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml
new file mode 100644 (file)
index 0000000..5dffc5a
--- /dev/null
@@ -0,0 +1,43 @@
+<controls:FancyWindow
+    xmlns="https://spacestation14.io"
+    xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
+    xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
+    xmlns:ui="clr-namespace:Content.Client.Materials.UI"
+    Title="{Loc 'flatpacker-ui-title'}"
+    MinSize="550 350">
+    <BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True" Margin="10">
+        <BoxContainer SizeFlagsStretchRatio="2" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
+            <BoxContainer Orientation="Vertical">
+                <SpriteView Name="MachineSprite" Scale="4 4" HorizontalAlignment="Center" MinSize="128 128"/>
+                <RichTextLabel Name="MachineNameLabel" HorizontalAlignment="Center" StyleClasses="LabelKeyText"/>
+            </BoxContainer>
+            <Control MinHeight="10"/>
+            <Button Name="PackButton" Text="{Loc 'flatpacker-ui-pack-button'}" MaxWidth="150" Margin="0 0 0 10"/>
+            <BoxContainer Orientation="Vertical" VerticalExpand="True">
+                <Label Name="CostHeaderLabel" Text="{Loc 'flatpacker-ui-cost-label'}" HorizontalAlignment="Left"/>
+                <PanelContainer VerticalExpand="True"
+                                HorizontalExpand="True">
+                    <PanelContainer.PanelOverride>
+                        <gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
+                    </PanelContainer.PanelOverride>
+                    <BoxContainer Orientation="Vertical" VerticalExpand="True">
+                        <RichTextLabel Name="CostLabel" HorizontalAlignment="Center"/>
+                    </BoxContainer>
+                </PanelContainer>
+            </BoxContainer>
+        </BoxContainer>
+        <Control MinWidth="10"/>
+        <BoxContainer SizeFlagsStretchRatio="3" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
+            <Label Text="{Loc 'flatpacker-ui-materials-label'}" HorizontalAlignment="Center" Margin="0 0 0 5"/>
+            <PanelContainer
+                VerticalExpand="True"
+                HorizontalExpand="True"
+                RectClipContent="True">
+                <PanelContainer.PanelOverride>
+                    <gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
+                </PanelContainer.PanelOverride>
+                <ui:MaterialStorageControl Name="MaterialStorageControl"/>
+            </PanelContainer>
+        </BoxContainer>
+    </BoxContainer>
+</controls:FancyWindow>
diff --git a/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs b/Content.Client/Construction/UI/FlatpackCreatorMenu.xaml.cs
new file mode 100644 (file)
index 0000000..3041f6a
--- /dev/null
@@ -0,0 +1,147 @@
+using System.Linq;
+using Content.Client.Materials;
+using Content.Client.Message;
+using Content.Client.UserInterface.Controls;
+using Content.Shared.Construction.Components;
+using Content.Shared.Containers.ItemSlots;
+using Content.Shared.Materials;
+using Robust.Client.AutoGenerated;
+using Robust.Client.GameObjects;
+using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Timing;
+using Robust.Shared.Utility;
+
+namespace Content.Client.Construction.UI;
+
+[GenerateTypedNameReferences]
+public sealed partial class FlatpackCreatorMenu : FancyWindow
+{
+    [Dependency] private readonly IEntityManager _entityManager = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+
+    private readonly ItemSlotsSystem _itemSlots;
+    private readonly FlatpackSystem _flatpack;
+    private readonly MaterialStorageSystem _materialStorage;
+    private readonly SpriteSystem _spriteSystem;
+
+    private readonly EntityUid _owner;
+
+    private EntityUid? _currentBoard = EntityUid.Invalid;
+    private EntityUid? _machinePreview;
+
+    public event Action? PackButtonPressed;
+
+    public FlatpackCreatorMenu(EntityUid uid)
+    {
+        RobustXamlLoader.Load(this);
+        IoCManager.InjectDependencies(this);
+
+        _itemSlots = _entityManager.System<ItemSlotsSystem>();
+        _flatpack = _entityManager.System<FlatpackSystem>();
+        _materialStorage = _entityManager.System<MaterialStorageSystem>();
+        _spriteSystem = _entityManager.System<SpriteSystem>();
+
+        _owner = uid;
+
+        PackButton.OnPressed += _ => PackButtonPressed?.Invoke();
+
+        MaterialStorageControl.SetOwner(uid);
+    }
+
+    protected override void FrameUpdate(FrameEventArgs args)
+    {
+        base.FrameUpdate(args);
+        
+        if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview))
+        {
+            _machinePreview = null;
+            MachineSprite.SetEntity(_machinePreview);
+        }
+
+        if (!_entityManager.TryGetComponent<FlatpackCreatorComponent>(_owner, out var flatpacker) ||
+            !_itemSlots.TryGetSlot(_owner, flatpacker.SlotId, out var itemSlot))
+            return;
+
+        if (flatpacker.Packing)
+        {
+            PackButton.Disabled = true;
+        }
+        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);
+            }
+        }
+
+        if (_currentBoard == itemSlot.Item)
+            return;
+
+        if (_machinePreview != null)
+            _entityManager.DeleteEntity(_machinePreview);
+
+        _currentBoard = itemSlot.Item;
+        CostHeaderLabel.Visible = _currentBoard != null;
+
+        if (_currentBoard != null &&
+            _entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard) &&
+            machineBoard.Prototype != 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));
+        }
+        else
+        {
+            _machinePreview = null;
+            MachineNameLabel.SetMessage(" ");
+            CostLabel.SetMessage(Loc.GetString("flatpacker-ui-no-board-label"));
+            PackButton.Disabled = true;
+        }
+
+        MachineSprite.SetEntity(_machinePreview);
+    }
+
+    //todo beautify
+    private string GetCostString(Dictionary<string, int> costs)
+    {
+        var orderedCosts = costs.OrderBy(p => p.Value);
+        var msg = new FormattedMessage();
+        foreach (var (mat, amount) in orderedCosts)
+        {
+            var matProto = _prototypeManager.Index<MaterialPrototype>(mat);
+
+            var sheetVolume = _materialStorage.GetSheetVolume(matProto);
+            var sheets = (float) -amount / sheetVolume;
+            var amountText = Loc.GetString("lathe-menu-material-amount",
+                ("amount", sheets),
+                ("unit", Loc.GetString(matProto.Unit)));
+            var text = Loc.GetString("lathe-menu-tooltip-display",
+                ("amount", amountText),
+                ("material", Loc.GetString(matProto.Name)));
+
+            msg.AddMarkup(text);
+            msg.PushNewline();
+        }
+        msg.Pop();
+
+        return msg.ToMarkup();
+    }
+
+    public override void Close()
+    {
+        base.Close();
+
+        _entityManager.DeleteEntity(_machinePreview);
+        _machinePreview = null;
+    }
+}
index 653a3f0463a14abc51688c303fcd37fafcd96d7d..097736ddd38dde1437466fb2609b1f8ced396c72 100644 (file)
@@ -16,7 +16,6 @@
         </BoxContainer>
         <BoxContainer Name="Content"
                       Orientation="Horizontal"
-                      HorizontalExpand="True"
                       HorizontalAlignment="Right">
             <!--Here go buttons which added in c#-->
         </BoxContainer>
index c95bd1957f72193cd0f62452a729a0a2b0039131..3ef247d52978d3668e6fbbe9eac89b202088a3c2 100644 (file)
@@ -37,9 +37,9 @@ public sealed partial class MaterialStorageControl : BoxContainer
         if (_owner == null)
             return;
 
-        if (!_entityManager.TryGetComponent<MaterialStorageComponent>(_owner, out var materialStorage))
+        if (_entityManager.Deleted(_owner) || !_entityManager.TryGetComponent<MaterialStorageComponent>(_owner, out var materialStorage))
         {
-            Dispose();
+            _owner = null;
             return;
         }
 
diff --git a/Content.Server/Ame/Components/AmePartComponent.cs b/Content.Server/Ame/Components/AmePartComponent.cs
deleted file mode 100644 (file)
index 2d29474..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-using Content.Shared.Tools;
-using Robust.Shared.Audio;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-
-namespace Content.Server.Ame.Components;
-
-/// <summary>
-/// Packaged AME machinery that can be deployed to construct an AME.
-/// </summary>
-[RegisterComponent]
-public sealed partial class AmePartComponent : Component
-{
-    /// <summary>
-    /// The sound played when the AME shielding is unpacked.
-    /// </summary>
-    [DataField("unwrapSound")]
-    public SoundSpecifier UnwrapSound = new SoundPathSpecifier("/Audio/Effects/unwrap.ogg");
-
-    /// <summary>
-    /// The tool quality required to deploy the packaged AME shielding.
-    /// </summary>
-    [DataField("qualityNeeded", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
-    public string QualityNeeded = "Pulsing";
-}
diff --git a/Content.Server/Ame/EntitySystems/AmePartSystem.cs b/Content.Server/Ame/EntitySystems/AmePartSystem.cs
deleted file mode 100644 (file)
index a75c092..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-using System.Linq;
-using Content.Server.Administration.Logs;
-using Content.Server.Ame.Components;
-using Content.Server.Popups;
-using Content.Server.Tools;
-using Content.Shared.Database;
-using Content.Shared.Hands.Components;
-using Content.Shared.Interaction;
-using Robust.Shared.Audio;
-using Robust.Shared.Audio.Systems;
-using Robust.Shared.Map;
-
-namespace Content.Server.Ame.EntitySystems;
-
-public sealed class AmePartSystem : EntitySystem
-{
-    [Dependency] private readonly IMapManager _mapManager = default!;
-    [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
-    [Dependency] private readonly PopupSystem _popupSystem = default!;
-    [Dependency] private readonly ToolSystem _toolSystem = default!;
-    [Dependency] private readonly IAdminLogManager _adminLogger = default!;
-
-    public override void Initialize()
-    {
-        base.Initialize();
-
-        SubscribeLocalEvent<AmePartComponent, InteractUsingEvent>(OnPartInteractUsing);
-    }
-
-    private void OnPartInteractUsing(EntityUid uid, AmePartComponent component, InteractUsingEvent args)
-    {
-        if (!_toolSystem.HasQuality(args.Used, component.QualityNeeded))
-            return;
-
-        if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridUid(EntityManager), out var mapGrid))
-            return; // No AME in space.
-
-        var snapPos = mapGrid.TileIndicesFor(args.ClickLocation);
-        if (mapGrid.GetAnchoredEntities(snapPos).Any(sc => HasComp<AmeShieldComponent>(sc)))
-        {
-            _popupSystem.PopupEntity(Loc.GetString("ame-part-component-shielding-already-present"), uid, args.User);
-            return;
-        }
-
-        var ent = Spawn("AmeShielding", mapGrid.GridTileToLocal(snapPos));
-
-        _adminLogger.Add(LogType.Construction, LogImpact.Low, $"{ToPrettyString(args.User):player} unpacked {ToPrettyString(ent)} at {Transform(ent).Coordinates} from {ToPrettyString(uid)}");
-
-        _audioSystem.PlayPvs(component.UnwrapSound, uid);
-
-        QueueDel(uid);
-    }
-}
diff --git a/Content.Server/Construction/FlatpackSystem.cs b/Content.Server/Construction/FlatpackSystem.cs
new file mode 100644 (file)
index 0000000..b5f9228
--- /dev/null
@@ -0,0 +1,98 @@
+using Content.Server.Audio;
+using Content.Server.Power.Components;
+using Content.Server.Power.EntitySystems;
+using Content.Shared.Construction;
+using Content.Shared.Construction.Components;
+using Content.Shared.Containers.ItemSlots;
+using Robust.Shared.Timing;
+
+namespace Content.Server.Construction;
+
+/// <inheritdoc/>
+public sealed class FlatpackSystem : SharedFlatpackSystem
+{
+    [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly AmbientSoundSystem _ambientSound = default!;
+    [Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<FlatpackCreatorComponent, FlatpackCreatorStartPackBuiMessage>(OnStartPack);
+        SubscribeLocalEvent<FlatpackCreatorComponent, PowerChangedEvent>(OnPowerChanged);
+    }
+
+    private void OnStartPack(Entity<FlatpackCreatorComponent> ent, ref FlatpackCreatorStartPackBuiMessage args)
+    {
+        var (uid, comp) = ent;
+        if (!this.IsPowered(ent, EntityManager) || comp.Packing)
+            return;
+
+        if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
+            return;
+
+        if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp))
+            return;
+
+        if (!MaterialStorage.CanChangeMaterialAmount(uid, GetFlatpackCreationCost(ent, (machineBoard, boardComp))))
+            return;
+
+        comp.Packing = true;
+        comp.PackEndTime = _timing.CurTime + comp.PackDuration;
+        Appearance.SetData(uid, FlatpackCreatorVisuals.Packing, true);
+        _ambientSound.SetAmbience(uid, true);
+        Dirty(uid, comp);
+    }
+
+    private void OnPowerChanged(Entity<FlatpackCreatorComponent> ent, ref PowerChangedEvent args)
+    {
+        if (args.Powered)
+            return;
+        FinishPacking(ent, true);
+    }
+
+    private void FinishPacking(Entity<FlatpackCreatorComponent> ent, bool interrupted)
+    {
+        var (uid, comp) = ent;
+
+        comp.Packing = false;
+        Appearance.SetData(uid, FlatpackCreatorVisuals.Packing, false);
+        _ambientSound.SetAmbience(uid, false);
+        Dirty(uid, comp);
+
+        if (interrupted)
+            return;
+
+        if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
+            return;
+
+        if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp))
+            return;
+
+        var materialCost = GetFlatpackCreationCost(ent, (machineBoard, boardComp));
+        if (!MaterialStorage.TryChangeMaterialAmount((ent, null), materialCost))
+            return;
+
+        var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
+        SetupFlatpack(flatpack, (machineBoard, boardComp));
+    }
+
+    public override void Update(float frameTime)
+    {
+        base.Update(frameTime);
+
+        var query = EntityQueryEnumerator<FlatpackCreatorComponent>();
+        while (query.MoveNext(out var uid, out var comp))
+        {
+            if (!comp.Packing)
+                continue;
+
+            if (_timing.CurTime < comp.PackEndTime)
+                continue;
+
+            FinishPacking((uid, comp), false);
+        }
+    }
+}
diff --git a/Content.Shared/Construction/Components/FlatpackComponent.cs b/Content.Shared/Construction/Components/FlatpackComponent.cs
new file mode 100644 (file)
index 0000000..5cb1780
--- /dev/null
@@ -0,0 +1,51 @@
+using Content.Shared.Tools;
+using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.Construction.Components;
+
+/// <summary>
+/// This is used for an object that can instantly create a machine upon having a tool applied to it.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(SharedFlatpackSystem))]
+public sealed partial class FlatpackComponent : Component
+{
+    /// <summary>
+    /// The tool quality that, upon used to interact with this object, will create the <see cref="Entity"/>
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public ProtoId<ToolQualityPrototype> QualityNeeded = "Pulsing";
+
+    /// <summary>
+    /// The entity that is spawned when this object is unpacked.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public EntProtoId? Entity;
+
+    /// <summary>
+    /// Sound effect played upon the object being unpacked.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public SoundSpecifier UnpackSound = new SoundPathSpecifier("/Audio/Effects/unwrap.ogg");
+
+    /// <summary>
+    /// A dictionary relating a machine board sprite state to a color used for the overlay.
+    /// Kinda shitty but it gets the job done.
+    /// </summary>
+    [DataField]
+    public Dictionary<string, Color> BoardColors = new();
+}
+
+[Serializable, NetSerializable]
+public enum FlatpackVisuals : byte
+{
+    Machine
+}
+
+public enum FlatpackVisualLayers : byte
+{
+    Overlay
+}
diff --git a/Content.Shared/Construction/Components/FlatpackCreatorComponent.cs b/Content.Shared/Construction/Components/FlatpackCreatorComponent.cs
new file mode 100644 (file)
index 0000000..0f52d63
--- /dev/null
@@ -0,0 +1,69 @@
+using Content.Shared.Materials;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+
+namespace Content.Shared.Construction.Components;
+
+/// <summary>
+/// This is used for a machine that creates flatpacks at the cost of materials
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+[Access(typeof(SharedFlatpackSystem))]
+[AutoGenerateComponentState]
+public sealed partial class FlatpackCreatorComponent : Component
+{
+    /// <summary>
+    /// Whether or not packing is occuring
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    [AutoNetworkedField]
+    public bool Packing;
+
+    /// <summary>
+    /// The time at which packing ends
+    /// </summary>
+    [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
+    [AutoNetworkedField]
+    public TimeSpan PackEndTime;
+
+    /// <summary>
+    /// How long packing lasts.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public TimeSpan PackDuration = TimeSpan.FromSeconds(3);
+
+    /// <summary>
+    /// The prototype used when spawning a flatpack.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public EntProtoId BaseFlatpackPrototype = "BaseFlatpack";
+
+    /// <summary>
+    /// A default cost applied to all flatpacks outside of the cost of constructing the machine.
+    /// </summary>
+    [DataField]
+    public Dictionary<ProtoId<MaterialPrototype>, int> BaseMaterialCost = new();
+
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public string SlotId = "board_slot";
+}
+
+[Serializable, NetSerializable]
+public enum FlatpackCreatorUIKey : byte
+{
+    Key
+}
+
+[Serializable, NetSerializable]
+public enum FlatpackCreatorVisuals : byte
+{
+    Packing
+}
+
+[Serializable, NetSerializable]
+public sealed class FlatpackCreatorStartPackBuiMessage : BoundUserInterfaceMessage
+{
+
+}
index d84557b2de0f0b1381afbdc80bec4512f8ac1386..b13dc20c6d51393cefb01af61dd21c7ccb95c064 100644 (file)
@@ -1,6 +1,10 @@
+using System.Linq;
 using Content.Shared.Construction.Components;
 using Content.Shared.Construction.Prototypes;
 using Content.Shared.Examine;
+using Content.Shared.Lathe;
+using Content.Shared.Materials;
+using Content.Shared.Stacks;
 using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Construction
@@ -11,6 +15,7 @@ namespace Content.Shared.Construction
     public sealed class MachinePartSystem : EntitySystem
     {
         [Dependency] private readonly IPrototypeManager _prototype = default!;
+        [Dependency] private readonly SharedLatheSystem _lathe = default!;
 
         public override void Initialize()
         {
@@ -61,5 +66,87 @@ namespace Content.Shared.Construction
             args.PushMarkup(Loc.GetString("machine-part-component-on-examine-type-text", ("type",
                 Loc.GetString(_prototype.Index<MachinePartPrototype>(component.PartType).Name))));
         }
+
+        public Dictionary<string, int> GetMachineBoardMaterialCost(Entity<MachineBoardComponent> entity, int coefficient = 1)
+        {
+            var (_, comp) = entity;
+
+            var materials = new Dictionary<string, int>();
+            foreach (var (partId, amount) in comp.Requirements)
+            {
+                var partProto = _prototype.Index<MachinePartPrototype>(partId);
+
+                if (!_lathe.TryGetRecipesFromEntity(partProto.StockPartPrototype, out var recipes))
+                    continue;
+
+                var partRecipe = recipes[0];
+                if (recipes.Count > 1)
+                    partRecipe = recipes.MinBy(p => p.RequiredMaterials.Values.Sum());
+
+                foreach (var (mat, matAmount) in partRecipe!.RequiredMaterials)
+                {
+                    materials.TryAdd(mat, 0);
+                    materials[mat] += matAmount * amount * coefficient;
+                }
+            }
+
+            foreach (var (stackId, amount) in comp.MaterialIdRequirements)
+            {
+                var stackProto = _prototype.Index<StackPrototype>(stackId);
+
+                if (_prototype.TryIndex(stackProto.Spawn, out var defaultProto) &&
+                    defaultProto.TryGetComponent<PhysicalCompositionComponent>(out var physComp))
+                {
+                    foreach (var (mat, matAmount) in physComp.MaterialComposition)
+                    {
+                        materials.TryAdd(mat, 0);
+                        materials[mat] += matAmount * amount * coefficient;
+                    }
+                }
+                else if (_lathe.TryGetRecipesFromEntity(stackProto.Spawn, out var recipes))
+                {
+                    var partRecipe = recipes[0];
+                    if (recipes.Count > 1)
+                        partRecipe = recipes.MinBy(p => p.RequiredMaterials.Values.Sum());
+
+                    foreach (var (mat, matAmount) in partRecipe!.RequiredMaterials)
+                    {
+                        materials.TryAdd(mat, 0);
+                        materials[mat] += matAmount * amount * coefficient;
+                    }
+                }
+            }
+
+            var genericPartInfo = comp.ComponentRequirements.Values.Concat(comp.ComponentRequirements.Values);
+            foreach (var info in genericPartInfo)
+            {
+                var amount = info.Amount;
+                var defaultProtoId = info.DefaultPrototype;
+
+                if (_lathe.TryGetRecipesFromEntity(defaultProtoId, out var recipes))
+                {
+                    var partRecipe = recipes[0];
+                    if (recipes.Count > 1)
+                        partRecipe = recipes.MinBy(p => p.RequiredMaterials.Values.Sum());
+
+                    foreach (var (mat, matAmount) in partRecipe!.RequiredMaterials)
+                    {
+                        materials.TryAdd(mat, 0);
+                        materials[mat] += matAmount * amount * coefficient;
+                    }
+                }
+                else if (_prototype.TryIndex(defaultProtoId, out var defaultProto) &&
+                         defaultProto.TryGetComponent<PhysicalCompositionComponent>(out var physComp))
+                {
+                    foreach (var (mat, matAmount) in physComp.MaterialComposition)
+                    {
+                        materials.TryAdd(mat, 0);
+                        materials[mat] += matAmount * amount * coefficient;
+                    }
+                }
+            }
+
+            return materials;
+        }
     }
 }
diff --git a/Content.Shared/Construction/SharedFlatpackSystem.cs b/Content.Shared/Construction/SharedFlatpackSystem.cs
new file mode 100644 (file)
index 0000000..094f9d8
--- /dev/null
@@ -0,0 +1,150 @@
+using System.Numerics;
+using Content.Shared.Construction.Components;
+using Content.Shared.Administration.Logs;
+using Content.Shared.Database;
+using Content.Shared.Examine;
+using Content.Shared.Interaction;
+using Content.Shared.Materials;
+using Content.Shared.Popups;
+using Content.Shared.Tools.Systems;
+using Robust.Shared.Audio.Systems;
+using Robust.Shared.Containers;
+using Robust.Shared.Map;
+using Robust.Shared.Map.Components;
+using Robust.Shared.Network;
+using Robust.Shared.Physics.Components;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Construction;
+
+public abstract class SharedFlatpackSystem : EntitySystem
+{
+    [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+    [Dependency] private readonly IMapManager _mapManager = default!;
+    [Dependency] private readonly INetManager _net = default!;
+    [Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
+    [Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly SharedContainerSystem _container = default!;
+    [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
+    [Dependency] private readonly SharedMapSystem _map = default!;
+    [Dependency] protected readonly MachinePartSystem MachinePart = default!;
+    [Dependency] protected readonly SharedMaterialStorageSystem MaterialStorage = default!;
+    [Dependency] private readonly MetaDataSystem _metaData = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly SharedToolSystem _tool = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<FlatpackComponent, InteractUsingEvent>(OnFlatpackInteractUsing);
+        SubscribeLocalEvent<FlatpackComponent, ExaminedEvent>(OnFlatpackExamined);
+
+        SubscribeLocalEvent<FlatpackCreatorComponent, ContainerIsRemovingAttemptEvent>(OnCreatorRemovingAttempt);
+        SubscribeLocalEvent<FlatpackCreatorComponent, EntityUnpausedEvent>(OnCreatorUnpaused);
+    }
+
+    private void OnFlatpackInteractUsing(Entity<FlatpackComponent> ent, ref InteractUsingEvent args)
+    {
+        var (uid, comp) = ent;
+        if (!_tool.HasQuality(args.Used, comp.QualityNeeded) || _container.IsEntityInContainer(ent))
+            return;
+
+        var xform = Transform(ent);
+
+        if (xform.GridUid is not { } grid || !TryComp<MapGridComponent>(grid, out var gridComp))
+            return;
+
+        args.Handled = true;
+
+        if (comp.Entity == null)
+        {
+            Log.Error($"No entity prototype present for flatpack {ToPrettyString(ent)}.");
+
+            if (_net.IsServer)
+                QueueDel(ent);
+            return;
+        }
+
+        var buildPos = _map.TileIndicesFor(grid, gridComp, xform.Coordinates);
+        var intersecting = _entityLookup.GetEntitiesIntersecting(buildPos.ToEntityCoordinates(grid, _mapManager).Offset(new Vector2(0.5f, 0.5f))
+            , LookupFlags.Dynamic | LookupFlags.Static);
+
+        // todo make this logic smarter.
+        // This should eventually allow for shit like building microwaves on tables and such.
+        foreach (var intersect in intersecting)
+        {
+            if (!TryComp<PhysicsComponent>(intersect, out var intersectBody))
+                continue;
+
+            if (!intersectBody.Hard || !intersectBody.CanCollide)
+                continue;
+
+            // this popup is on the server because the mispredicts on the intersection is crazy
+            if (_net.IsServer)
+                _popup.PopupEntity(Loc.GetString("flatpack-unpack-no-room"), uid, args.User);
+            return;
+        }
+
+        if (_net.IsServer)
+        {
+            var spawn = Spawn(comp.Entity, _map.GridTileToLocal(grid, gridComp, buildPos));
+            _adminLogger.Add(LogType.Construction, LogImpact.Low,
+                $"{ToPrettyString(args.User):player} unpacked {ToPrettyString(spawn):entity} at {xform.Coordinates} from {ToPrettyString(uid):entity}");
+            QueueDel(uid);
+        }
+
+        _audio.PlayPredicted(comp.UnpackSound, args.Used, args.User);
+    }
+
+    private void OnFlatpackExamined(Entity<FlatpackComponent> ent, ref ExaminedEvent args)
+    {
+        if (!args.IsInDetailsRange)
+            return;
+        args.PushMarkup(Loc.GetString("flatpack-examine"));
+    }
+
+    private void OnCreatorRemovingAttempt(Entity<FlatpackCreatorComponent> ent, ref ContainerIsRemovingAttemptEvent args)
+    {
+        if (args.Container.ID == ent.Comp.SlotId && ent.Comp.Packing)
+            args.Cancel();
+    }
+
+    private void OnCreatorUnpaused(Entity<FlatpackCreatorComponent> ent, ref EntityUnpausedEvent args)
+    {
+        ent.Comp.PackEndTime += args.PausedTime;
+    }
+
+    public void SetupFlatpack(Entity<FlatpackComponent?> ent, Entity<MachineBoardComponent?> machineBoard)
+    {
+        if (!Resolve(ent, ref ent.Comp) || !Resolve(machineBoard, ref machineBoard.Comp))
+            return;
+
+        if (machineBoard.Comp.Prototype is not { } machinePrototypeId)
+            return;
+
+        var comp = ent.Comp!;
+        var machinePrototype = PrototypeManager.Index(machinePrototypeId);
+
+        var meta = MetaData(ent);
+        _metaData.SetEntityName(ent, Loc.GetString("flatpack-entity-name", ("name", machinePrototype.Name)), meta);
+        _metaData.SetEntityDescription(ent, Loc.GetString("flatpack-entity-description", ("name", machinePrototype.Name)), meta);
+
+        comp.Entity = machinePrototypeId;
+        Dirty(ent, comp);
+
+        Appearance.SetData(ent, FlatpackVisuals.Machine, MetaData(machineBoard).EntityPrototype?.ID ?? string.Empty);
+    }
+
+    public Dictionary<string, int> GetFlatpackCreationCost(Entity<FlatpackCreatorComponent> entity, Entity<MachineBoardComponent> machineBoard)
+    {
+        var cost = MachinePart.GetMachineBoardMaterialCost(machineBoard, -1);
+        foreach (var (mat, amount) in entity.Comp.BaseMaterialCost)
+        {
+            cost.TryAdd(mat, 0);
+            cost[mat] -= amount;
+        }
+
+        return cost;
+    }
+}
index 9debaa77190ddd5539538513a0f3d335562f1fb1..b41a91f9c3476f92fea4f6a3e5554d094421b4e9 100644 (file)
@@ -1,8 +1,10 @@
+using System.Diagnostics.CodeAnalysis;
 using Content.Shared.Emag.Systems;
 using Content.Shared.Materials;
 using Content.Shared.Research.Prototypes;
 using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
+using Robust.Shared.Utility;
 
 namespace Content.Shared.Lathe;
 
@@ -14,11 +16,15 @@ public abstract class SharedLatheSystem : EntitySystem
     [Dependency] private readonly IPrototypeManager _proto = default!;
     [Dependency] private readonly SharedMaterialStorageSystem _materialStorage = default!;
 
+    private readonly Dictionary<string, List<LatheRecipePrototype>> _inverseRecipeDictionary = new();
+
     public override void Initialize()
     {
         base.Initialize();
 
         SubscribeLocalEvent<EmagLatheRecipesComponent, GotEmaggedEvent>(OnEmagged);
+        SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReloaded);
+        BuildInverseRecipeDictionary();
     }
 
     [PublicAPI]
@@ -53,4 +59,28 @@ public abstract class SharedLatheSystem : EntitySystem
         => reduce ? (int) MathF.Ceiling(original * multiplier) : original;
 
     protected abstract bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component);
+
+    private void OnPrototypesReloaded(PrototypesReloadedEventArgs obj)
+    {
+        if (!obj.WasModified<LatheRecipePrototype>())
+            return;
+        BuildInverseRecipeDictionary();
+    }
+
+    private void BuildInverseRecipeDictionary()
+    {
+        _inverseRecipeDictionary.Clear();
+        foreach (var latheRecipe in _proto.EnumeratePrototypes<LatheRecipePrototype>())
+        {
+            _inverseRecipeDictionary.GetOrNew(latheRecipe.Result).Add(latheRecipe);
+        }
+    }
+
+    public bool TryGetRecipesFromEntity(string prototype, [NotNullWhen(true)] out List<LatheRecipePrototype>? recipes)
+    {
+        recipes = new();
+        if (_inverseRecipeDictionary.TryGetValue(prototype, out var r))
+            recipes.AddRange(r);
+        return recipes.Count != 0;
+    }
 }
index a0cd7a9e456cb48e8b219dff006f1bd578593f3b..9f7c87df3c98482462de531d1a376ca5a21d8349 100644 (file)
@@ -81,7 +81,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
     {
         if (!Resolve(uid, ref component))
             return 0; //you have nothing
-        return !component.Storage.TryGetValue(material, out var amount) ? 0 : amount;
+        return component.Storage.GetValueOrDefault(material, 0);
     }
 
     /// <summary>
@@ -123,9 +123,35 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
     {
         if (!Resolve(uid, ref component))
             return false;
-        return CanTakeVolume(uid, volume, component) &&
-               (component.MaterialWhiteList == null || component.MaterialWhiteList.Contains(materialId)) &&
-               (!component.Storage.TryGetValue(materialId, out var amount) || amount + volume >= 0);
+
+        if (!CanTakeVolume(uid, volume, component))
+            return false;
+
+        if (component.MaterialWhiteList != null && !component.MaterialWhiteList.Contains(materialId))
+            return false;
+
+        var amount = component.Storage.GetValueOrDefault(materialId);
+        return amount + volume >= 0;
+    }
+
+    /// <summary>
+    /// Checks if the specified materials can be changed by the specified volumes.
+    /// </summary>
+    /// <param name="entity"></param>
+    /// <param name="materials"></param>
+    /// <returns>If the amount can be changed</returns>
+    public bool CanChangeMaterialAmount(Entity<MaterialStorageComponent?> entity, Dictionary<string,int> materials)
+    {
+        if (!Resolve(entity, ref entity.Comp))
+            return false;
+
+        foreach (var (material, amount) in materials)
+        {
+            if (!CanChangeMaterialAmount(entity, material, amount, entity.Comp))
+                return false;
+        }
+
+        return true;
     }
 
     /// <summary>
@@ -136,20 +162,47 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
     /// <param name="materialId"></param>
     /// <param name="volume"></param>
     /// <param name="component"></param>
+    /// <param name="dirty"></param>
     /// <returns>If it was successful</returns>
-    public bool TryChangeMaterialAmount(EntityUid uid, string materialId, int volume, MaterialStorageComponent? component = null)
+    public bool TryChangeMaterialAmount(EntityUid uid, string materialId, int volume, MaterialStorageComponent? component = null, bool dirty = true)
     {
         if (!Resolve(uid, ref component))
             return false;
         if (!CanChangeMaterialAmount(uid, materialId, volume, component))
             return false;
-        if (!component.Storage.ContainsKey(materialId))
-            component.Storage.Add(materialId, 0);
+        component.Storage.TryAdd(materialId, 0);
         component.Storage[materialId] += volume;
 
         var ev = new MaterialAmountChangedEvent();
         RaiseLocalEvent(uid, ref ev);
-        Dirty(component);
+
+        if (dirty)
+            Dirty(uid, component);
+        return true;
+    }
+
+    /// <summary>
+    /// Changes the amount of a specific material in the storage.
+    /// Still respects the filters in place.
+    /// </summary>
+    /// <param name="entity"></param>
+    /// <param name="materials"></param>
+    /// <returns>If the amount can be changed</returns>
+    public bool TryChangeMaterialAmount(Entity<MaterialStorageComponent?> entity, Dictionary<string,int> materials)
+    {
+        if (!Resolve(entity, ref entity.Comp))
+            return false;
+
+        if (!CanChangeMaterialAmount(entity, materials))
+            return false;
+
+        foreach (var (material, amount) in materials)
+        {
+            if (!TryChangeMaterialAmount(entity, material, amount, entity.Comp, false))
+                return false;
+        }
+
+        Dirty(entity, entity.Comp);
         return true;
     }
 
@@ -225,7 +278,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
             insertingComp.MaterialColor = lastMat?.Color;
         }
         _appearance.SetData(receiver, MaterialStorageVisuals.Inserting, true);
-        Dirty(insertingComp);
+        Dirty(receiver, insertingComp);
 
         var ev = new MaterialEntityInsertedEvent(material);
         RaiseLocalEvent(receiver, ref ev);
@@ -245,7 +298,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
         var ev = new GetMaterialWhitelistEvent(uid);
         RaiseLocalEvent(uid, ref ev);
         component.MaterialWhiteList = ev.Whitelist;
-        Dirty(component);
+        Dirty(uid, component);
     }
 
     private void OnInteractUsing(EntityUid uid, MaterialStorageComponent component, InteractUsingEvent args)
diff --git a/Resources/Locale/en-US/construction/components/flatpack.ftl b/Resources/Locale/en-US/construction/components/flatpack.ftl
new file mode 100644 (file)
index 0000000..8449da7
--- /dev/null
@@ -0,0 +1,11 @@
+flatpack-unpack-no-room = No room to unpack!
+flatpack-examine = Use a [color=yellow]multitool[/color] to unpack this.
+flatpack-entity-name = {$name} flatpack
+flatpack-entity-description = A flatpack used for constructing {INDEFINITE($name)} {$name}.
+
+flatpacker-item-slot-name = Machine board slot
+flatpacker-ui-title = Flatpacker 1001
+flatpacker-ui-materials-label = Materials
+flatpacker-ui-cost-label = Packing Cost
+flatpacker-ui-no-board-label = No board present!
+flatpacker-ui-pack-button = Pack
index 9693c5be41eb43c64637a80396d3926b44e254c4..c978aeaa580b83f8ef2eec17a80ec2adbe80a13a 100644 (file)
@@ -8,6 +8,7 @@ research-discipline-civilian-services = Civilian Services
 research-technology-fulton = Fultons
 research-technology-salvage-equipment = Salvage Equipment
 research-technology-advanced-powercells = Advanced Powercells
+research-technology-mechanical-compression = Mechanical Compression
 research-technology-compact-power = Compact Power
 research-technology-industrial-engineering = Industrial Engineering
 research-technology-power-generation = Power Generation
index 4a94dc9ac61f5ee455230f76cffa8a730d11f31c..041d07d130a8d40f3ba4762451695fa195f53547 100644 (file)
@@ -36,6 +36,7 @@ wires-board-name-firelock = Firelock Control
 wires-board-name-windoor = Windoor Control
 wires-board-name-mech = Mech
 wires-board-name-fatextractor = FatExtractor
+wires-board-name-flatpacker = Flatpacker
 
 # names that get displayed in the wire hacking hud & admin logs.
 
index 8a9b3f16b3603d9d941912dd01e0449b49ac1382..d683195f2f62f196642c605270d306909c44dc14 100644 (file)
           DefaultPrototype: ForkPlastic
           ExamineName: Utensil
 
+- type: entity
+  parent: BaseMachineCircuitboard
+  id: FlatpackerMachineCircuitboard
+  name: Flatpacker 1001 machine board
+  components:
+  - type: MachineBoard
+    prototype: MachineFlatpacker
+    requirements:
+      Manipulator: 2
+      MatterBin: 1
+    materialRequirements:
+      Steel: 1
+
 - type: entity
   id: EmitterCircuitboard
   parent: BaseMachineCircuitboard
diff --git a/Resources/Prototypes/Entities/Objects/Devices/flatpack.yml b/Resources/Prototypes/Entities/Objects/Devices/flatpack.yml
new file mode 100644 (file)
index 0000000..31578bd
--- /dev/null
@@ -0,0 +1,33 @@
+- type: entity
+  parent: BaseItem
+  id: BaseFlatpack
+  name: base flatpack
+  description: A flatpack used for constructing something.
+  categories:
+  - hideSpawnMenu
+  components:
+  - type: Item
+    size: Normal
+  - type: Sprite
+    sprite: Objects/Devices/flatpack.rsi
+    layers:
+    - state: base
+    - state: overlay
+      color: "#cec8ac"
+      map: ["enum.FlatpackVisualLayers.Overlay"]
+    - state: icon-default
+  - type: Appearance
+  - type: Flatpack
+    boardColors:
+      command: "#334E6D"
+      medical: "#52B4E9"
+      service: "#9FED58"
+      engineering: "#EFB341"
+      security: "#DE3A3A"
+      science: "#D381C9"
+      supply: "#A46106"
+  - type: StaticPrice
+    price: 500
+  - type: Tag
+    tags:
+    - DroneUsable
index da389bc0a719f6ecea060caf1fd8c8c0509dbb5f..5f1a06a28322b76628f12555160b790e39d89ff6 100644 (file)
@@ -97,7 +97,7 @@
 - type: entity
   parent: BaseItem
   id: StationBeaconPart
-  name: station beacon assembly
+  name: station beacon flatpack
   description: A flatpack used for constructing a station beacon.
   components:
   - type: Item
index a3674178bf5a280dcb8fc2b548ff4ae04e3d865a..62aa0dccdd523481644ae5773a7d5842379b660f 100644 (file)
@@ -1,8 +1,8 @@
 - type: entity
   parent: BaseItem
   id: AmePart
-  name: AME part
-  description: A flatpack used for constructing an antimatter engine reactor. Use a multitool to unpack it.
+  name: AME flatpack
+  description: A flatpack used for constructing an antimatter engine reactor.
   components:
   - type: Item
     size: Normal
@@ -10,7 +10,8 @@
   - type: Sprite
     sprite: Objects/Power/AME/ame_part.rsi
     state: box
-  - type: AmePart
+  - type: Flatpack
+    entity: AmeShielding
   - type: StaticPrice
     price: 500
   - type: GuideHelp
index 7c8e7fa495111d6e9dcb2ff411257c976f2c4b37..0fcd11f9b00c95ae730e1443d25852340111b740 100644 (file)
@@ -1,14 +1,16 @@
 - type: entity
   parent: BaseItem
   id: SolarAssemblyPart
-  name: solar assembly part
+  name: solar assembly flatpack
+  description: A flatpack used for constructing a solar assembly.
   components:
   - type: Item
     size: Normal
+  - type: Flatpack
+    entity: SolarAssembly
   - type: Sprite
     sprite: Objects/Power/solar_parts.rsi
     state: solar_assembly_parts
   - type: Tag
     tags:
-      - SolarAssemblyPart
-      - DroneUsable
+    - DroneUsable
diff --git a/Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml b/Resources/Prototypes/Entities/Structures/Machines/flatpacker.yml
new file mode 100644 (file)
index 0000000..529d2ee
--- /dev/null
@@ -0,0 +1,82 @@
+- type: entity
+  id: MachineFlatpacker
+  parent: [ BaseMachinePowered, ConstructibleMachine ]
+  name: Flatpacker 1001
+  description: An industrial machine used for expediting machine construction across the station.
+  components:
+  - type: Sprite
+    sprite: Structures/Machines/flatpacker.rsi
+    snapCardinals: true
+    layers:
+    - state: base
+    - state: screen
+      map: ["enum.PowerDeviceVisualLayers.Powered"]
+      shader: unshaded
+    - state: panel
+      map: ["enum.WiresVisualLayers.MaintenancePanel"]
+    - state: packing
+      map: ["anim"]
+      visible: false
+    - state: inserting
+      visible: false
+      map: ["enum.MaterialStorageVisualLayers.Inserting"]
+  - type: GenericVisualizer
+    visuals:
+      enum.PowerDeviceVisuals.Powered:
+        enum.PowerDeviceVisualLayers.Powered:
+          True: { visible: true }
+          False: { visible: false }
+      enum.FlatpackCreatorVisuals.Packing:
+        anim:
+          True: { visible: true }
+          False: { visible: false }
+  - type: FlatpackCreator
+    baseMaterialCost:
+      Steel: 600
+      Plastic: 200
+  - type: Machine
+    board: FlatpackerMachineCircuitboard
+  - type: MaterialStorage
+    whitelist:
+      tags:
+      - Sheet
+      - RawMaterial
+      - Ingot
+  - type: AmbientSound
+    enabled: false
+    volume: 5
+    range: 3
+    sound:
+      path: /Audio/Items/rped.ogg
+  - type: WiresPanel
+  - type: WiresVisuals
+  - type: Wires
+    boardName: wires-board-name-flatpacker
+    layoutId: Flatpacker
+  - type: Appearance
+  - type: ActivatableUI
+    key: enum.FlatpackCreatorUIKey.Key
+  - type: ActivatableUIRequiresPower
+  - type: UserInterface
+    interfaces:
+    - key: enum.FlatpackCreatorUIKey.Key
+      type: FlatpackCreatorBoundUserInterface
+  - type: ItemSlots
+    slots:
+      board_slot:
+        name: flatpacker-item-slot-name
+        whitelist:
+          components:
+          - MachineBoard
+  - type: ContainerContainer
+    containers:
+      machine_board: !type:Container
+      machine_parts: !type:Container
+      board_slot: !type:ContainerSlot
+  - type: Construction
+    containers:
+    - machine_parts
+    - machine_board
+    - board_slot
+  - type: StaticPrice
+    price: 2000
index 4600a23ca9c8704af97f9dcc59345d8196ec2d84..899047c324c101108ea351673b2f7f71ee92cfd2 100644 (file)
       - MicrowaveMachineCircuitboard
       - ElectricGrillMachineCircuitboard
       - FatExtractorMachineCircuitboard
+      - FlatpackerMachineCircuitboard
       - SheetifierMachineCircuitboard
       - ShuttleConsoleCircuitboard
       - RadarConsoleCircuitboard
index 750bdadf069c10b0bfb4d006462116e9f865f67d..445ee0728d22924bedce528ddaa43ec59f5c52f2 100644 (file)
@@ -41,7 +41,7 @@
     loadNode: output
     sprite: Structures/Power/Generation/solar_panel.rsi
     state: static
-    collectionName: SolarPanel   
+    collectionName: SolarPanel
   - type: Anchorable
   - type: Pullable
   - type: Electrified
   - type: Construction
     graph: SolarPanel
     node: solarassembly
+    defaultTarget: solarpanel
 
 - type: entity
   id: SolarTracker
index 38c4c247ac49bc29ec475acbdbebefe8644fc46a..3b5c04f4fe9a3933e7034ca7335653af7b109971 100644 (file)
      Steel: 100
      Glass: 900
 
+- type: latheRecipe
+  id: FlatpackerMachineCircuitboard
+  result: FlatpackerMachineCircuitboard
+  completetime: 4
+  materials:
+    Steel: 100
+    Glass: 900
+    Gold: 100
+
 - type: latheRecipe
   id: SheetifierMachineCircuitboard
   result: SheetifierMachineCircuitboard
index f287bcd953386b59bd916a4461e5dc1e9fe3a38f..d991645be0f0a6f90b8b7cd90611a390812e3eab 100644 (file)
   recipeUnlocks:
   - PowerCellHigh
 
+- type: technology
+  id: MechanicalCompression
+  name: research-technology-mechanical-compression
+  icon:
+    sprite: Structures/Machines/flatpacker.rsi
+    state: base
+  discipline: Industrial
+  tier: 1
+  cost: 10000
+  recipeUnlocks:
+  - FlatpackerMachineCircuitboard
+
 - type: technology
   id: CompactPower
   name: research-technology-compact-power
index a8e8ef148816199876bdf70a1cb352deadc7a25a..44e8d9593f6b3823650031cb13e6cbe70f9bf232 100644 (file)
 - type: Tag
   id: Soap
 
-- type: Tag
-  id: SolarAssemblyPart
-
 - type: Tag
   id: SolarTrackerElectronics
 
diff --git a/Resources/Textures/Objects/Devices/flatpack.rsi/base.png b/Resources/Textures/Objects/Devices/flatpack.rsi/base.png
new file mode 100644 (file)
index 0000000..628808a
Binary files /dev/null and b/Resources/Textures/Objects/Devices/flatpack.rsi/base.png differ
diff --git a/Resources/Textures/Objects/Devices/flatpack.rsi/icon-default.png b/Resources/Textures/Objects/Devices/flatpack.rsi/icon-default.png
new file mode 100644 (file)
index 0000000..da9da03
Binary files /dev/null and b/Resources/Textures/Objects/Devices/flatpack.rsi/icon-default.png differ
diff --git a/Resources/Textures/Objects/Devices/flatpack.rsi/meta.json b/Resources/Textures/Objects/Devices/flatpack.rsi/meta.json
new file mode 100644 (file)
index 0000000..6381b5c
--- /dev/null
@@ -0,0 +1,20 @@
+{
+    "version": 1,
+    "license": "CC0-1.0",
+    "copyright": "Created by EmoGarbage404 (github) for SS14",
+    "size": {
+        "x": 32,
+        "y": 32
+    },
+    "states": [
+        {
+            "name": "base"
+        },
+        {
+            "name": "overlay"
+        },
+        {
+            "name": "icon-default"
+        }
+    ]
+}
diff --git a/Resources/Textures/Objects/Devices/flatpack.rsi/overlay.png b/Resources/Textures/Objects/Devices/flatpack.rsi/overlay.png
new file mode 100644 (file)
index 0000000..c066933
Binary files /dev/null and b/Resources/Textures/Objects/Devices/flatpack.rsi/overlay.png differ
diff --git a/Resources/Textures/Structures/Machines/flatpacker.rsi/base.png b/Resources/Textures/Structures/Machines/flatpacker.rsi/base.png
new file mode 100644 (file)
index 0000000..b92a8de
Binary files /dev/null and b/Resources/Textures/Structures/Machines/flatpacker.rsi/base.png differ
diff --git a/Resources/Textures/Structures/Machines/flatpacker.rsi/inserting.png b/Resources/Textures/Structures/Machines/flatpacker.rsi/inserting.png
new file mode 100644 (file)
index 0000000..e8226a9
Binary files /dev/null and b/Resources/Textures/Structures/Machines/flatpacker.rsi/inserting.png differ
diff --git a/Resources/Textures/Structures/Machines/flatpacker.rsi/meta.json b/Resources/Textures/Structures/Machines/flatpacker.rsi/meta.json
new file mode 100644 (file)
index 0000000..0082154
--- /dev/null
@@ -0,0 +1,42 @@
+{
+  "version": 1,
+  "license": "CC0-1.0",
+  "copyright": "Based on flatpacker sprites from vgstation, adapted by EmoGarbage404 (github)",
+  "size": {
+    "x": 32,
+    "y": 32
+  },
+  "states": [
+    {
+      "name": "base"
+    },
+    {
+      "name": "panel"
+    },
+    {
+      "name": "screen"
+    },
+    {
+      "name": "packing",
+      "delays": [
+        [
+          0.1,
+          0.1,
+          0.1,
+          0.1
+        ]
+      ]
+    },
+    {
+      "name": "inserting",
+      "delays": [
+        [
+          0.2,
+          0.2,
+          0.2,
+          0.2
+        ]
+      ]
+    }
+  ]
+}
diff --git a/Resources/Textures/Structures/Machines/flatpacker.rsi/packing.png b/Resources/Textures/Structures/Machines/flatpacker.rsi/packing.png
new file mode 100644 (file)
index 0000000..2b07b99
Binary files /dev/null and b/Resources/Textures/Structures/Machines/flatpacker.rsi/packing.png differ
diff --git a/Resources/Textures/Structures/Machines/flatpacker.rsi/panel.png b/Resources/Textures/Structures/Machines/flatpacker.rsi/panel.png
new file mode 100644 (file)
index 0000000..b21c6df
Binary files /dev/null and b/Resources/Textures/Structures/Machines/flatpacker.rsi/panel.png differ
diff --git a/Resources/Textures/Structures/Machines/flatpacker.rsi/screen.png b/Resources/Textures/Structures/Machines/flatpacker.rsi/screen.png
new file mode 100644 (file)
index 0000000..cd09bb9
Binary files /dev/null and b/Resources/Textures/Structures/Machines/flatpacker.rsi/screen.png differ
index 7d681e02b1d43d4877b049566c956f8dc0bd5cad..42cf8d1cabbc0c86f75694f5fa712365f66348f3 100644 (file)
@@ -602,6 +602,7 @@ public sealed partial class $CLASS$ : Shared$CLASS$ {
        <s:Boolean x:Key="/Default/UserDictionary/Words/=firelocks/@EntryIndexedValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/UserDictionary/Words/=diminishingly/@EntryIndexedValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/UserDictionary/Words/=flashable/@EntryIndexedValue">True</s:Boolean>
+       <s:Boolean x:Key="/Default/UserDictionary/Words/=Flatpack/@EntryIndexedValue">True</s:Boolean>
     <s:Boolean x:Key="/Default/UserDictionary/Words/=Fluidsynth/@EntryIndexedValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/UserDictionary/Words/=formattable/@EntryIndexedValue">True</s:Boolean>
     <s:Boolean x:Key="/Default/UserDictionary/Words/=freepats/@EntryIndexedValue">True</s:Boolean>