Adds tag support to construction (#3386)

This commit is contained in:
Vera Aguilera Puerto
2021-02-24 16:26:56 +01:00
committed by GitHub
parent 2ec0304072
commit 436d406585
11 changed files with 110 additions and 62 deletions

View File

@@ -259,12 +259,8 @@ namespace Content.Client.Construction
stepList.AddItem(Loc.GetString("{0}. Use a {1}.", stepNumber++, toolStep.Tool.GetToolName()), icon); stepList.AddItem(Loc.GetString("{0}. Use a {1}.", stepNumber++, toolStep.Tool.GetToolName()), icon);
break; break;
case PrototypeConstructionGraphStep prototypeStep: case ArbitraryInsertConstructionGraphStep arbitraryStep:
stepList.AddItem(Loc.GetString("{0}. Add {1}.", stepNumber++, prototypeStep.Name), icon); stepList.AddItem(Loc.GetString("{0}. Add {1}.", stepNumber++, arbitraryStep.Name), icon);
break;
case ComponentConstructionGraphStep componentStep:
stepList.AddItem(Loc.GetString("{0}. Add {1}.", stepNumber++, componentStep.Name), icon);
break; break;
case NestedConstructionGraphStep nestedStep: case NestedConstructionGraphStep nestedStep:
@@ -282,19 +278,16 @@ namespace Content.Client.Construction
switch (subStep) switch (subStep)
{ {
case MaterialConstructionGraphStep materialStep: case MaterialConstructionGraphStep materialStep:
if (!(prototype.Type == ConstructionType.Item)) stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}x {4}.", stepNumber, parallelNumber, subStepNumber++, materialStep.Amount, materialStep.Material), icon); if (prototype.Type != ConstructionType.Item)
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}x {4}.", stepNumber, parallelNumber, subStepNumber++, materialStep.Amount, materialStep.Material), icon);
break; break;
case ToolConstructionGraphStep toolStep: case ToolConstructionGraphStep toolStep:
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Use a {3}.", stepNumber, parallelNumber, subStepNumber++, toolStep.Tool.GetToolName()), icon); stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Use a {3}.", stepNumber, parallelNumber, subStepNumber++, toolStep.Tool.GetToolName()), icon);
break; break;
case PrototypeConstructionGraphStep prototypeStep: case ArbitraryInsertConstructionGraphStep arbitraryStep:
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}.", stepNumber, parallelNumber, subStepNumber++, prototypeStep.Name), icon); stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}.", stepNumber, parallelNumber, subStepNumber++, arbitraryStep.Name), icon);
break;
case ComponentConstructionGraphStep componentStep:
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}.", stepNumber, parallelNumber, subStepNumber++, componentStep.Name), icon);
break; break;
} }
} }
@@ -357,11 +350,8 @@ namespace Content.Client.Construction
break; break;
case ComponentConstructionGraphStep componentStep: case ArbitraryInsertConstructionGraphStep arbitraryStep:
return componentStep.Icon?.Frame0(); return arbitraryStep.Icon?.Frame0();
case PrototypeConstructionGraphStep prototypeStep:
return prototypeStep.Icon?.Frame0();
case NestedConstructionGraphStep: case NestedConstructionGraphStep:
return null; return null;

View File

@@ -186,8 +186,7 @@ namespace Content.Server.GameObjects.Components.Construction
{ {
case MaterialConstructionGraphStep _: case MaterialConstructionGraphStep _:
case ToolConstructionGraphStep _: case ToolConstructionGraphStep _:
case PrototypeConstructionGraphStep _: case ArbitraryInsertConstructionGraphStep _:
case ComponentConstructionGraphStep _:
if (await HandleStep(eventArgs, edge, firstStep)) if (await HandleStep(eventArgs, edge, firstStep))
{ {
if(edge.Steps.Count > 1) if(edge.Steps.Count > 1)
@@ -258,17 +257,8 @@ namespace Content.Server.GameObjects.Components.Construction
switch (insertStep) switch (insertStep)
{ {
case PrototypeConstructionGraphStep prototypeStep: case ArbitraryInsertConstructionGraphStep arbitraryStep:
if (prototypeStep.EntityValid(eventArgs.Using) if (arbitraryStep.EntityValid(eventArgs.Using)
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
{
valid = true;
}
break;
case ComponentConstructionGraphStep componentStep:
if (componentStep.EntityValid(eventArgs.Using)
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished) && await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
{ {
valid = true; valid = true;

View File

@@ -185,46 +185,24 @@ namespace Content.Server.GameObjects.EntitySystems
break; break;
case ComponentConstructionGraphStep componentStep: case ArbitraryInsertConstructionGraphStep arbitraryStep:
foreach (var entity in EnumerateNearby(user)) foreach (var entity in EnumerateNearby(user))
{ {
if (!componentStep.EntityValid(entity)) if (!arbitraryStep.EntityValid(entity))
continue; continue;
if (string.IsNullOrEmpty(componentStep.Store)) if (string.IsNullOrEmpty(arbitraryStep.Store))
{ {
if (!container.Insert(entity)) if (!container.Insert(entity))
continue; continue;
} }
else if (!GetContainer(componentStep.Store).Insert(entity)) else if (!GetContainer(arbitraryStep.Store).Insert(entity))
continue; continue;
handled = true; handled = true;
break; break;
} }
break;
case PrototypeConstructionGraphStep prototypeStep:
foreach (var entity in EnumerateNearby(user))
{
if (!prototypeStep.EntityValid(entity))
continue;
if (string.IsNullOrEmpty(prototypeStep.Store))
{
if (!container.Insert(entity))
continue;
}
else if (!GetContainer(prototypeStep.Store).Insert(entity))
{
continue;
}
handled = true;
break;
}
break; break;
} }

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Serialization; using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Shared.Construction namespace Content.Shared.Construction
@@ -15,5 +16,11 @@ namespace Content.Shared.Construction
serializer.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid); serializer.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid);
serializer.DataField(this, x => x.Name, "name", string.Empty); serializer.DataField(this, x => x.Name, "name", string.Empty);
} }
public override void DoExamine(FormattedMessage message, bool inDetailsRange)
{
if (string.IsNullOrEmpty(Name)) return;
message.AddMarkup(Loc.GetString("construction-insert-arbitrary-entity", ("stepName", Name)));
}
} }
} }

View File

@@ -14,7 +14,6 @@ namespace Content.Shared.Construction
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(this, x => x.Component, "component", string.Empty); serializer.DataField(this, x => x.Component, "component", string.Empty);
} }
public override bool EntityValid(IEntity entity) public override bool EntityValid(IEntity entity)

View File

@@ -89,6 +89,20 @@ namespace Content.Shared.Construction
return component; return component;
} }
if (mapping.TryGetNode("tag", out _))
{
var tags = new TagConstructionGraphStep();
tags.ExposeData(stepSerializer);
return tags;
}
if (mapping.TryGetNode("allTags", out _) || mapping.TryGetNode("anyTags", out _))
{
var tags = new MultipleTagsConstructionGraphStep();
tags.ExposeData(stepSerializer);
return tags;
}
if(mapping.TryGetNode("steps", out _)) if(mapping.TryGetNode("steps", out _))
{ {
var nested = new NestedConstructionGraphStep(); var nested = new NestedConstructionGraphStep();

View File

@@ -0,0 +1,44 @@
#nullable enable
using System.Collections;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Tag;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Construction
{
public class MultipleTagsConstructionGraphStep : ArbitraryInsertConstructionGraphStep
{
private List<string>? _allTags = null;
private List<string>? _anyTags = null;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _allTags, "allTags", null);
serializer.DataField(ref _anyTags, "anyTags", null);
}
private static bool IsNullOrEmpty<T>(ICollection<T>? list)
{
return list == null || list.Count == 0;
}
public override bool EntityValid(IEntity entity)
{
// This step can only happen if either list has tags.
if (IsNullOrEmpty(_allTags) && IsNullOrEmpty(_anyTags))
return false; // Step is somehow invalid, we return.
if (_allTags != null && !entity.HasAllTags(_allTags))
return false; // We don't have all the tags needed.
if (_anyTags != null && !entity.HasAnyTag(_anyTags))
return false; // We don't have any of the tags needed.
// This entity is valid!
return true;
}
}
}

View File

@@ -0,0 +1,25 @@
#nullable enable
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Tag;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Construction
{
public class TagConstructionGraphStep : ArbitraryInsertConstructionGraphStep
{
private string? _tag = null;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _tag, "tag", null);
}
public override bool EntityValid(IEntity entity)
{
return !string.IsNullOrEmpty(_tag) && entity.HasTag(_tag);
}
}
}

View File

@@ -13,3 +13,5 @@ construction-insert-entity-with-component = Next, insert an entity with a {$comp
# Shown when examining an in-construction object # Shown when examining an in-construction object
construction-insert-exact-entity = Next, insert {$entityName}. construction-insert-exact-entity = Next, insert {$entityName}.
# Shown when examining an in-construction object
construction-insert-arbitrary-entity = Next, insert {$stepName}.

View File

@@ -6,8 +6,7 @@
edges: edges:
- to: entity - to: entity
steps: steps:
# Replace with tag ASAP - tag: ConveyorAssembly
- prototype: ConveyorAssembly
icon: icon:
sprite: Constructible/Power/conveyor.rsi sprite: Constructible/Power/conveyor.rsi
state: conveyor_loose state: conveyor_loose

View File

@@ -50,7 +50,7 @@
- !type:EntityAnchored - !type:EntityAnchored
anchored: true anchored: true
steps: steps:
- prototype: FirelockElectronics - tag: FirelockElectronics
name: Firelock Electronics name: Firelock Electronics
icon: icon:
sprite: "Constructible/Misc/module.rsi" sprite: "Constructible/Misc/module.rsi"