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
|
||||
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)
|
||||
{
|
||||
oldLayers.Remove(key);
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
string 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>();
|
||||
|
||||
foreach (var (key, marking) in MarkingsByCategory(category))
|
||||
@@ -125,7 +125,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
string species, Sex sex)
|
||||
{
|
||||
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>();
|
||||
|
||||
foreach (var (key, marking) in MarkingsByCategory(category))
|
||||
@@ -197,7 +197,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
IoCManager.Resolve(ref prototypeManager);
|
||||
|
||||
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))
|
||||
{
|
||||
@@ -228,7 +228,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
IoCManager.Resolve(ref prototypeManager);
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -254,7 +254,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
IoCManager.Resolve(ref prototypeManager);
|
||||
var speciesProto = prototypeManager.Index<SpeciesPrototype>(species);
|
||||
if (
|
||||
!prototypeManager.TryIndex(speciesProto.SpriteSet, out HumanoidSpeciesBaseSpritesPrototype? baseSprites) ||
|
||||
!prototypeManager.TryIndex(speciesProto.SpriteSet, out var baseSprites) ||
|
||||
!baseSprites.Sprites.TryGetValue(layer, out var spriteName) ||
|
||||
!prototypeManager.TryIndex(spriteName, out HumanoidSpeciesSpriteLayer? sprite) ||
|
||||
sprite == null ||
|
||||
|
||||
@@ -152,7 +152,7 @@ public sealed partial class MarkingSet
|
||||
|
||||
var toRemove = new List<(MarkingCategories category, string id)>();
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -48,20 +48,20 @@ namespace Content.Shared.Humanoid
|
||||
switch (gender)
|
||||
{
|
||||
case Gender.Male:
|
||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.MaleFirstNames));
|
||||
return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames));
|
||||
case Gender.Female:
|
||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.FemaleFirstNames));
|
||||
return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames));
|
||||
default:
|
||||
if (_random.Prob(0.5f))
|
||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.MaleFirstNames));
|
||||
return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames));
|
||||
else
|
||||
return _random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>(speciesProto.FemaleFirstNames));
|
||||
return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames));
|
||||
}
|
||||
}
|
||||
|
||||
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.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
@@ -42,7 +44,7 @@ public sealed partial class SpeciesPrototype : IPrototype
|
||||
// sprite accessories.
|
||||
|
||||
[DataField("sprites")]
|
||||
public string SpriteSet { get; private set; } = default!;
|
||||
public ProtoId<HumanoidSpeciesBaseSpritesPrototype> SpriteSet { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[DataField("markingLimits")]
|
||||
public string MarkingPoints { get; private set; } = default!;
|
||||
public ProtoId<MarkingPointsPrototype> MarkingPoints { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Humanoid species variant used by this entity.
|
||||
@@ -82,13 +84,13 @@ public sealed partial class SpeciesPrototype : IPrototype
|
||||
public HumanoidSkinColor SkinColoration { get; private set; }
|
||||
|
||||
[DataField]
|
||||
public string MaleFirstNames { get; private set; } = "NamesFirstMale";
|
||||
public ProtoId<LocalizedDatasetPrototype> MaleFirstNames { get; private set; } = "NamesFirstMale";
|
||||
|
||||
[DataField]
|
||||
public string FemaleFirstNames { get; private set; } = "NamesFirstFemale";
|
||||
public ProtoId<LocalizedDatasetPrototype> FemaleFirstNames { get; private set; } = "NamesFirstFemale";
|
||||
|
||||
[DataField]
|
||||
public string LastNames { get; private set; } = "NamesLast";
|
||||
public ProtoId<LocalizedDatasetPrototype> LastNames { get; private set; } = "NamesLast";
|
||||
|
||||
[DataField]
|
||||
public SpeciesNaming Naming { get; private set; } = SpeciesNaming.FirstLast;
|
||||
|
||||
Reference in New Issue
Block a user