Refactor stacks to use prototypes (#3387)

* Refactor stacks to use prototypes

* Fix not assigned warning

* Add names to stacks

* Make machine baords and material constructions use the name as well

* Remove defaulting stacks to prototype id

* Fix tests

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2021-02-25 06:18:29 +01:00
committed by GitHub
parent 7c32574547
commit fdcbece63d
33 changed files with 326 additions and 186 deletions

View File

@@ -2,6 +2,7 @@
using System;
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.GameObjects.Components;
using Content.Shared.Stacks;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
@@ -13,46 +14,15 @@ namespace Content.Server.Construction
/// <summary>
/// Spawns a stack of a specified type given an amount.
/// </summary>
public static IEntity SpawnStack(StackType stack, int amount, EntityCoordinates coordinates, IEntityManager? entityManager = null)
public static IEntity SpawnStack(StackPrototype stack, int amount, EntityCoordinates coordinates, IEntityManager? entityManager = null)
{
entityManager ??= IoCManager.Resolve<IEntityManager>();
string prototype;
switch (stack)
{
case StackType.Metal:
prototype = "SteelSheet1";
break;
case StackType.Glass:
prototype = "GlassSheet1";
break;
case StackType.MetalRod:
prototype = "MetalRodStack1";
break;
case StackType.Plasma:
prototype = "PlasmaStack1";
break;
case StackType.Plasteel:
prototype = "PlasteelSheet1";
break;
case StackType.Cable:
prototype = "ApcExtensionCableStack1";
break;
// TODO: Add more.
default:
throw new ArgumentOutOfRangeException(nameof(stack),"Stack type doesn't have a prototype specified yet!");
}
// TODO: Add more.
string prototype = stack.Spawn ?? throw new ArgumentOutOfRangeException(nameof(stack),
"Stack type doesn't have a prototype specified yet!");
var ent = entityManager.SpawnEntity(prototype, coordinates);
var stackComponent = ent.GetComponent<StackComponent>();
stackComponent.Count = Math.Min(amount, stackComponent.MaxCount);