Adds tag support to construction (#3386)
This commit is contained in:
committed by
GitHub
parent
2ec0304072
commit
436d406585
@@ -259,12 +259,8 @@ namespace Content.Client.Construction
|
||||
stepList.AddItem(Loc.GetString("{0}. Use a {1}.", stepNumber++, toolStep.Tool.GetToolName()), icon);
|
||||
break;
|
||||
|
||||
case PrototypeConstructionGraphStep prototypeStep:
|
||||
stepList.AddItem(Loc.GetString("{0}. Add {1}.", stepNumber++, prototypeStep.Name), icon);
|
||||
break;
|
||||
|
||||
case ComponentConstructionGraphStep componentStep:
|
||||
stepList.AddItem(Loc.GetString("{0}. Add {1}.", stepNumber++, componentStep.Name), icon);
|
||||
case ArbitraryInsertConstructionGraphStep arbitraryStep:
|
||||
stepList.AddItem(Loc.GetString("{0}. Add {1}.", stepNumber++, arbitraryStep.Name), icon);
|
||||
break;
|
||||
|
||||
case NestedConstructionGraphStep nestedStep:
|
||||
@@ -282,19 +278,16 @@ namespace Content.Client.Construction
|
||||
switch (subStep)
|
||||
{
|
||||
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;
|
||||
|
||||
case ToolConstructionGraphStep toolStep:
|
||||
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Use a {3}.", stepNumber, parallelNumber, subStepNumber++, toolStep.Tool.GetToolName()), icon);
|
||||
break;
|
||||
|
||||
case PrototypeConstructionGraphStep prototypeStep:
|
||||
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}.", stepNumber, parallelNumber, subStepNumber++, prototypeStep.Name), icon);
|
||||
break;
|
||||
|
||||
case ComponentConstructionGraphStep componentStep:
|
||||
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}.", stepNumber, parallelNumber, subStepNumber++, componentStep.Name), icon);
|
||||
case ArbitraryInsertConstructionGraphStep arbitraryStep:
|
||||
stepList.AddItem(Loc.GetString(" {0}.{1}.{2}. Add {3}.", stepNumber, parallelNumber, subStepNumber++, arbitraryStep.Name), icon);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -357,11 +350,8 @@ namespace Content.Client.Construction
|
||||
|
||||
break;
|
||||
|
||||
case ComponentConstructionGraphStep componentStep:
|
||||
return componentStep.Icon?.Frame0();
|
||||
|
||||
case PrototypeConstructionGraphStep prototypeStep:
|
||||
return prototypeStep.Icon?.Frame0();
|
||||
case ArbitraryInsertConstructionGraphStep arbitraryStep:
|
||||
return arbitraryStep.Icon?.Frame0();
|
||||
|
||||
case NestedConstructionGraphStep:
|
||||
return null;
|
||||
|
||||
@@ -186,8 +186,7 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
{
|
||||
case MaterialConstructionGraphStep _:
|
||||
case ToolConstructionGraphStep _:
|
||||
case PrototypeConstructionGraphStep _:
|
||||
case ComponentConstructionGraphStep _:
|
||||
case ArbitraryInsertConstructionGraphStep _:
|
||||
if (await HandleStep(eventArgs, edge, firstStep))
|
||||
{
|
||||
if(edge.Steps.Count > 1)
|
||||
@@ -258,17 +257,8 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
|
||||
switch (insertStep)
|
||||
{
|
||||
case PrototypeConstructionGraphStep prototypeStep:
|
||||
if (prototypeStep.EntityValid(eventArgs.Using)
|
||||
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ComponentConstructionGraphStep componentStep:
|
||||
if (componentStep.EntityValid(eventArgs.Using)
|
||||
case ArbitraryInsertConstructionGraphStep arbitraryStep:
|
||||
if (arbitraryStep.EntityValid(eventArgs.Using)
|
||||
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
|
||||
{
|
||||
valid = true;
|
||||
|
||||
@@ -185,46 +185,24 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
break;
|
||||
|
||||
case ComponentConstructionGraphStep componentStep:
|
||||
case ArbitraryInsertConstructionGraphStep arbitraryStep:
|
||||
foreach (var entity in EnumerateNearby(user))
|
||||
{
|
||||
if (!componentStep.EntityValid(entity))
|
||||
if (!arbitraryStep.EntityValid(entity))
|
||||
continue;
|
||||
|
||||
if (string.IsNullOrEmpty(componentStep.Store))
|
||||
if (string.IsNullOrEmpty(arbitraryStep.Store))
|
||||
{
|
||||
if (!container.Insert(entity))
|
||||
continue;
|
||||
}
|
||||
else if (!GetContainer(componentStep.Store).Insert(entity))
|
||||
else if (!GetContainer(arbitraryStep.Store).Insert(entity))
|
||||
continue;
|
||||
|
||||
handled = true;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
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.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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace Content.Shared.Construction
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(this, x => x.Component, "component", string.Empty);
|
||||
|
||||
}
|
||||
|
||||
public override bool EntityValid(IEntity entity)
|
||||
|
||||
@@ -89,6 +89,20 @@ namespace Content.Shared.Construction
|
||||
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 _))
|
||||
{
|
||||
var nested = new NestedConstructionGraphStep();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Content.Shared/Construction/TagConstructionGraphStep.cs
Normal file
25
Content.Shared/Construction/TagConstructionGraphStep.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,3 +13,5 @@ construction-insert-entity-with-component = Next, insert an entity with a {$comp
|
||||
# Shown when examining an in-construction object
|
||||
construction-insert-exact-entity = Next, insert {$entityName}.
|
||||
|
||||
# Shown when examining an in-construction object
|
||||
construction-insert-arbitrary-entity = Next, insert {$stepName}.
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
edges:
|
||||
- to: entity
|
||||
steps:
|
||||
# Replace with tag ASAP
|
||||
- prototype: ConveyorAssembly
|
||||
- tag: ConveyorAssembly
|
||||
icon:
|
||||
sprite: Constructible/Power/conveyor.rsi
|
||||
state: conveyor_loose
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
- !type:EntityAnchored
|
||||
anchored: true
|
||||
steps:
|
||||
- prototype: FirelockElectronics
|
||||
- tag: FirelockElectronics
|
||||
name: Firelock Electronics
|
||||
icon:
|
||||
sprite: "Constructible/Misc/module.rsi"
|
||||
|
||||
Reference in New Issue
Block a user