SKREEEEEE (#3706)
* Import bird sprites and define basic mob. * SKREEEEEEEEE * Move hair styles to new sprite accessory prototypes. Basic stuff, no multi-species stuff yet. * Vox hair styles and clothes * Make HumanoidCharacterProfile.Default() a static default to fix tests. Usages that wanted the previous random behavior now call Random(). * Remove names from hair style prototypes. (They're in localization files) * Update Content.Shared/Actions/ActionType.cs (sk)reeee github Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5ed935f30a
commit
0ac4c0e85c
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Preferences.Appearance
|
||||
{
|
||||
public sealed class SpriteAccessoryManager
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private readonly Dictionary<SpriteAccessoryCategories, List<SpriteAccessoryPrototype>> _index = new();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_prototypeManager.PrototypesReloaded += OnPrototypesReloaded;
|
||||
|
||||
foreach (var category in Enum.GetValues<SpriteAccessoryCategories>())
|
||||
{
|
||||
_index.Add(category, new List<SpriteAccessoryPrototype>());
|
||||
}
|
||||
|
||||
foreach (var prototype in _prototypeManager.EnumeratePrototypes<SpriteAccessoryPrototype>())
|
||||
{
|
||||
AddToIndexes(prototype);
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<SpriteAccessoryPrototype> AccessoriesForCategory(SpriteAccessoryCategories categories)
|
||||
{
|
||||
return _index[categories];
|
||||
}
|
||||
|
||||
public bool IsValidAccessoryInCategory(string accessory, SpriteAccessoryCategories categories)
|
||||
{
|
||||
return _prototypeManager.TryIndex(accessory, out SpriteAccessoryPrototype? accessoryPrototype)
|
||||
&& (accessoryPrototype.Categories & categories) != 0;
|
||||
}
|
||||
|
||||
private void OnPrototypesReloaded(PrototypesReloadedEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.ByType.TryGetValue(typeof(SpriteAccessoryPrototype), out var set))
|
||||
return;
|
||||
|
||||
foreach (var list in _index.Values)
|
||||
{
|
||||
list.RemoveAll(a => set.Modified.ContainsKey(a.ID));
|
||||
}
|
||||
|
||||
foreach (var prototype in set.Modified.Values)
|
||||
{
|
||||
var accessoryPrototype = (SpriteAccessoryPrototype) prototype;
|
||||
AddToIndexes(accessoryPrototype);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToIndexes(SpriteAccessoryPrototype accessoryPrototype)
|
||||
{
|
||||
for (var i = 0; i < sizeof(SpriteAccessoryCategories) * 8; i++)
|
||||
{
|
||||
var flag = (SpriteAccessoryCategories) (1 << i);
|
||||
if ((accessoryPrototype.Categories & flag) != 0)
|
||||
_index[flag].Add(accessoryPrototype);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user