2 using Microsoft.Xna.Framework;
27 static class DecalManager
29 public static readonly PrefabCollection<DecalPrefab> Prefabs =
new PrefabCollection<DecalPrefab>();
31 public static int GrimeSpriteCount {
get;
private set; } = 0;
33 public static readonly PrefabCollection<GrimeSprite> GrimeSprites =
new PrefabCollection<GrimeSprite>(
34 onAdd: (sprite, b) => GrimeSpriteCount = Math.Max(GrimeSpriteCount, sprite.IndexInFile + 1),
36 GrimeSpriteCount = GrimeSprites.AllPrefabs
37 .SelectMany(kvp => kvp.Value)
38 .Where(p => p != s).Select(p => p.IndexInFile + 1).MaxOrNull() ?? 0,
39 onSort:
null, onAddOverrideFile:
null, onRemoveOverrideFile:
null);
41 public static void LoadFromFile(DecalsFile configFile)
43 XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
44 if (doc ==
null) {
return; }
46 bool allowOverriding =
false;
47 var mainElement = doc.Root.FromPackage(configFile.ContentPackage);
48 if (doc.Root.IsOverride())
50 mainElement = mainElement.FirstElement();
51 allowOverriding =
true;
55 foreach (var sourceElement
in mainElement.Elements())
57 var element = sourceElement.IsOverride() ? sourceElement.FirstElement() : sourceElement;
58 bool isOverride = allowOverriding || sourceElement.IsOverride();
59 string name = element.Name.ToString().ToLowerInvariant();
64 GrimeSprites.Add(
new GrimeSprite(
new Sprite(element), configFile, grimeIndex), isOverride);
68 var prefab =
new DecalPrefab(element, configFile);
69 Prefabs.Add(prefab, isOverride);
75 public static void RemoveByFile(DecalsFile configFile)
77 Prefabs.RemoveByFile(configFile);
78 GrimeSprites.RemoveByFile(configFile);
81 public static void SortAll()
84 GrimeSprites.SortAll();
87 public static Decal CreateDecal(
string decalName,
float scale, Vector2 worldPosition, Hull hull,
int? spriteIndex =
null)
89 string lowerCaseDecalName = decalName.ToLowerInvariant();
90 if (!Prefabs.ContainsKey(lowerCaseDecalName))
92 DebugConsole.ThrowError(
"Decal prefab " + decalName +
" not found!");
96 DecalPrefab prefab = Prefabs[lowerCaseDecalName];
98 return new Decal(prefab, scale, worldPosition, hull, spriteIndex);
GrimeSprite(Sprite spr, DecalsFile file, int indexInFile)