Adds tag support to construction (#3386)
This commit is contained in:
committed by
GitHub
parent
2ec0304072
commit
436d406585
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user