The Flatpacker 1001 can now make flatpacks for computers. (#23471)

* moved ComputerBoardComponent to Content.Shared

* made flatpacker accept computer boards

* made flatpack system and ui function with computer boards

* fixed it so that flatpacks of computers are correctly coloured to fit their computer board colour

* unhardcoded the computer flatpack assembly cost

* Combined GetFlatpackCreationCost(...) with GetflatpackCreationCostForComputer(...)

* removed code duplication in SharedFlatpackSystem

* removed code duplication from FlatpackCreatorMenu.xaml.cs

* remove code duplication from FlatpackSystem (on the server)

* fixed indentation error
This commit is contained in:
SpeltIncorrectyl
2024-01-04 04:23:47 +00:00
committed by GitHub
parent f533a1a543
commit 082bde40ca
7 changed files with 97 additions and 35 deletions

View File

@@ -52,7 +52,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
protected override void FrameUpdate(FrameEventArgs args)
{
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
{