Validate some SpeciesPrototype fields (#35965)
* Convert SpeciesPrototype strings to ProtoIds * Simplify protoman indexing calls
This commit is contained in:
@@ -58,7 +58,7 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
|
|||||||
|
|
||||||
// add default species layers
|
// add default species layers
|
||||||
var speciesProto = _prototypeManager.Index(component.Species);
|
var speciesProto = _prototypeManager.Index(component.Species);
|
||||||
var baseSprites = _prototypeManager.Index<HumanoidSpeciesBaseSpritesPrototype>(speciesProto.SpriteSet);
|
var baseSprites = _prototypeManager.Index(speciesProto.SpriteSet);
|
||||||
foreach (var (key, id) in baseSprites.Sprites)
|
foreach (var (key, id) in baseSprites.Sprites)
|
||||||
{
|
{
|
||||||
oldLayers.Remove(key);
|
oldLayers.Remove(key);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace Content.Shared.Humanoid.Markings
|
|||||||
string species)
|
string species)
|
||||||
{
|
{
|
||||||
var speciesProto = _prototypeManager.Index<SpeciesPrototype>(species);
|
var speciesProto = _prototypeManager.Index<SpeciesPrototype>(species);
|
||||||
var onlyWhitelisted = _prototypeManager.Index<MarkingPointsPrototype>(speciesProto.MarkingPoints).OnlyWhitelisted;
|
var onlyWhitelisted = _prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted;
|
||||||
var res = new Dictionary<string, MarkingPrototype>();
|
var res = new Dictionary<string, MarkingPrototype>();
|
||||||
|
|
||||||
foreach (var (key, marking) in MarkingsByCategory(category))
|
foreach (var (key, marking) in MarkingsByCategory(category))
|
||||||
@@ -125,7 +125,7 @@ namespace Content.Shared.Humanoid.Markings
|
|||||||
string species, Sex sex)
|
string species, Sex sex)
|
||||||
{
|
{
|
||||||
var speciesProto = _prototypeManager.Index<SpeciesPrototype>(species);
|
var speciesProto = _prototypeManager.Index<SpeciesPrototype>(species);
|
||||||
var onlyWhitelisted = _prototypeManager.Index<MarkingPointsPrototype>(speciesProto.MarkingPoints).OnlyWhitelisted;
|
var onlyWhitelisted = _prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted;
|
||||||
var res = new Dictionary<string, MarkingPrototype>();
|
var res = new Dictionary<string, MarkingPrototype>();
|
||||||
|
|
||||||
foreach (var (key, marking) in MarkingsByCategory(category))
|
foreach (var (key, marking) in MarkingsByCategory(category))
|
||||||
@@ -197,7 +197,7 @@ namespace Content.Shared.Humanoid.Markings
|
|||||||
IoCManager.Resolve(ref prototypeManager);
|
IoCManager.Resolve(ref prototypeManager);
|
||||||
|
|
||||||
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
||||||
var onlyWhitelisted = prototypeManager.Index<MarkingPointsPrototype>(speciesProto.MarkingPoints).OnlyWhitelisted;
|
var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted;
|
||||||
|
|
||||||
if (!TryGetMarking(marking, out var prototype))
|
if (!TryGetMarking(marking, out var prototype))
|
||||||
{
|
{
|
||||||
@@ -228,7 +228,7 @@ namespace Content.Shared.Humanoid.Markings
|
|||||||
IoCManager.Resolve(ref prototypeManager);
|
IoCManager.Resolve(ref prototypeManager);
|
||||||
|
|
||||||
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
||||||
var onlyWhitelisted = prototypeManager.Index<MarkingPointsPrototype>(speciesProto.MarkingPoints).OnlyWhitelisted;
|
var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted;
|
||||||
|
|
||||||
if (onlyWhitelisted && prototype.SpeciesRestrictions == null)
|
if (onlyWhitelisted && prototype.SpeciesRestrictions == null)
|
||||||
{
|
{
|
||||||
@@ -254,7 +254,7 @@ namespace Content.Shared.Humanoid.Markings
|
|||||||
IoCManager.Resolve(ref prototypeManager);
|
IoCManager.Resolve(ref prototypeManager);
|
||||||
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
||||||
if (
|
if (
|
||||||
!prototypeManager.TryIndex(speciesProto.SpriteSet, out HumanoidSpeciesBaseSpritesPrototype? baseSprites) ||
|
!prototypeManager.TryIndex(speciesProto.SpriteSet, out var baseSprites) ||
|
||||||
!baseSprites.Sprites.TryGetValue(layer, out var spriteName) ||
|
!baseSprites.Sprites.TryGetValue(layer, out var spriteName) ||
|
||||||
!prototypeManager.TryIndex(spriteName, out HumanoidSpeciesSpriteLayer? sprite) ||
|
!prototypeManager.TryIndex(spriteName, out HumanoidSpeciesSpriteLayer? sprite) ||
|
||||||
sprite == null ||
|
sprite == null ||
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public sealed partial class MarkingSet
|
|||||||
|
|
||||||
var toRemove = new List<(MarkingCategories category, string id)>();
|
var toRemove = new List<(MarkingCategories category, string id)>();
|
||||||
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
||||||
var onlyWhitelisted = prototypeManager.Index<MarkingPointsPrototype>(speciesProto.MarkingPoints).OnlyWhitelisted;
|
var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted;
|
||||||
|
|
||||||
foreach (var (category, list) in Markings)
|
foreach (var (category, list) in Markings)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,20 +48,20 @@ namespace Content.Shared.Humanoid
|
|||||||
switch (gender)
|
switch (gender)
|
||||||
{
|
{
|
||||||
case Gender.Male:
|
case Gender.Male:
|
||||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.MaleFirstNames));
|
return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames));
|
||||||
case Gender.Female:
|
case Gender.Female:
|
||||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.FemaleFirstNames));
|
return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames));
|
||||||
default:
|
default:
|
||||||
if (_random.Prob(0.5f))
|
if (_random.Prob(0.5f))
|
||||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.MaleFirstNames));
|
return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames));
|
||||||
else
|
else
|
||||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.FemaleFirstNames));
|
return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetLastName(SpeciesPrototype speciesProto)
|
public string GetLastName(SpeciesPrototype speciesProto)
|
||||||
{
|
{
|
||||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.LastNames));
|
return _random.Pick(_prototypeManager.Index(speciesProto.LastNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Content.Shared.Dataset;
|
||||||
|
using Content.Shared.Humanoid.Markings;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ public sealed partial class SpeciesPrototype : IPrototype
|
|||||||
// sprite accessories.
|
// sprite accessories.
|
||||||
|
|
||||||
[DataField("sprites")]
|
[DataField("sprites")]
|
||||||
public string SpriteSet { get; private set; } = default!;
|
public ProtoId<HumanoidSpeciesBaseSpritesPrototype> SpriteSet { get; private set; } = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default skin tone for this species. This applies for non-human skin tones.
|
/// Default skin tone for this species. This applies for non-human skin tones.
|
||||||
@@ -61,7 +63,7 @@ public sealed partial class SpeciesPrototype : IPrototype
|
|||||||
/// The limit of body markings that you can place on this species.
|
/// The limit of body markings that you can place on this species.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("markingLimits")]
|
[DataField("markingLimits")]
|
||||||
public string MarkingPoints { get; private set; } = default!;
|
public ProtoId<MarkingPointsPrototype> MarkingPoints { get; private set; } = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Humanoid species variant used by this entity.
|
/// Humanoid species variant used by this entity.
|
||||||
@@ -82,13 +84,13 @@ public sealed partial class SpeciesPrototype : IPrototype
|
|||||||
public HumanoidSkinColor SkinColoration { get; private set; }
|
public HumanoidSkinColor SkinColoration { get; private set; }
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public string MaleFirstNames { get; private set; } = "NamesFirstMale";
|
public ProtoId<LocalizedDatasetPrototype> MaleFirstNames { get; private set; } = "NamesFirstMale";
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public string FemaleFirstNames { get; private set; } = "NamesFirstFemale";
|
public ProtoId<LocalizedDatasetPrototype> FemaleFirstNames { get; private set; } = "NamesFirstFemale";
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public string LastNames { get; private set; } = "NamesLast";
|
public ProtoId<LocalizedDatasetPrototype> LastNames { get; private set; } = "NamesLast";
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public SpeciesNaming Naming { get; private set; } = SpeciesNaming.FirstLast;
|
public SpeciesNaming Naming { get; private set; } = SpeciesNaming.FirstLast;
|
||||||
|
|||||||
Reference in New Issue
Block a user