PORT: Allows Markings to Set Custom Layers for Specific Sprites (#2516)
* multilayer markings * vestigial reptilian tail sprites added * i fix :) --------- Co-authored-by: mq <113324899+mqole@users.noreply.github.com>
This commit is contained in:
@@ -146,7 +146,7 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
|
||||
|
||||
var customBaseLayers = new Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo>();
|
||||
|
||||
var speciesPrototype = _prototypeManager.Index<SpeciesPrototype>(profile.Species);
|
||||
var speciesPrototype = _prototypeManager.Index(profile.Species); // Floof
|
||||
var markings = new MarkingSet(speciesPrototype.MarkingPoints, _markingManager, _prototypeManager);
|
||||
|
||||
// Add markings that doesn't need coloring. We store them until we add all other markings that doesn't need it.
|
||||
@@ -343,32 +343,116 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
|
||||
bool visible,
|
||||
Entity<HumanoidAppearanceComponent, SpriteComponent> entity)
|
||||
{
|
||||
var humanoid = entity.Comp1;
|
||||
var sprite = entity.Comp2;
|
||||
// hi! mq here.
|
||||
// if youre dealing with upstream merge conflicts, and you see a bunch of stuff up here, chances are its been moved in between some other shit.
|
||||
// i love the documentation on this file but i can only look at layer maps for so long before i feel myself becoming ben affleck.
|
||||
// sorry for any confusion.
|
||||
|
||||
if (!_sprite.LayerMapTryGet((entity.Owner, sprite), markingPrototype.BodyPart, out var targetLayer, false))
|
||||
return;
|
||||
|
||||
visible &= !IsHidden(humanoid, markingPrototype.BodyPart);
|
||||
visible &= humanoid.BaseLayers.TryGetValue(markingPrototype.BodyPart, out var setting)
|
||||
&& setting.AllowsMarkings;
|
||||
// FLOOF ADD START
|
||||
// make a handy dict of filename -> colors
|
||||
// cus we might need to access it by filename to link
|
||||
// one sprite's colors to another
|
||||
var colorDict = new Dictionary<string, Color>();
|
||||
for (var i = 0; i < markingPrototype.Sprites.Count; i++)
|
||||
{
|
||||
var spriteName = markingPrototype.Sprites[i] switch
|
||||
{
|
||||
SpriteSpecifier.Rsi rsi => rsi.RsiState,
|
||||
SpriteSpecifier.Texture texture => texture.TexturePath.Filename,
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (spriteName != null)
|
||||
{
|
||||
if (colors != null && i < colors.Count)
|
||||
colorDict.Add(spriteName, colors[i]);
|
||||
else
|
||||
colorDict.Add(spriteName, Color.White);
|
||||
}
|
||||
}
|
||||
// now, rearrange them, copying any parented colors to children set to
|
||||
// inherit them
|
||||
if (markingPrototype.ColorLinks != null)
|
||||
{
|
||||
foreach (var (child, parent) in markingPrototype.ColorLinks)
|
||||
{
|
||||
if (colorDict.TryGetValue(parent, out var color))
|
||||
{
|
||||
colorDict[child] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
// and, since we can't rely on the iterator knowing where the heck to put
|
||||
// each sprite when we have one marking setting multiple layers,
|
||||
// lets just kinda sorta do that ourselves
|
||||
var layerDict = new Dictionary<string, int>();
|
||||
// FLOOF ADD END
|
||||
for (var j = 0; j < markingPrototype.Sprites.Count; j++)
|
||||
{
|
||||
var markingSprite = markingPrototype.Sprites[j];
|
||||
|
||||
if (markingSprite is not SpriteSpecifier.Rsi rsi)
|
||||
return;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// FLOOF CHANGE START
|
||||
var layerSlot = markingPrototype.BodyPart;
|
||||
// first, try to see if there are any custom layers for this marking
|
||||
if (markingPrototype.Layering != null)
|
||||
{
|
||||
var name = rsi.RsiState;
|
||||
if (markingPrototype.Layering.TryGetValue(name, out var layerName))
|
||||
{
|
||||
layerSlot = Enum.Parse<HumanoidVisualLayers>(layerName);
|
||||
}
|
||||
}
|
||||
// update the layerDict
|
||||
// if it doesnt have this, add it at 0, otherwise increment it
|
||||
if (layerDict.TryGetValue(layerSlot.ToString(), out var layerIndex))
|
||||
{
|
||||
layerDict[layerSlot.ToString()] = layerIndex + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
layerDict.Add(layerSlot.ToString(), 0);
|
||||
}
|
||||
|
||||
// THIS IS THE UPSTREAM STUFF!!! RIGHT HERE!!!
|
||||
var humanoid = entity.Comp1;
|
||||
var sprite = entity.Comp2;
|
||||
|
||||
if (!_sprite.LayerMapTryGet((entity.Owner, sprite), layerSlot, out var targetLayer, false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
visible &= !IsHidden(humanoid, markingPrototype.BodyPart);
|
||||
visible &= humanoid.BaseLayers.TryGetValue(markingPrototype.BodyPart, out var setting)
|
||||
&& setting.AllowsMarkings;
|
||||
// FLOOF CHANGE END
|
||||
|
||||
var layerId = $"{markingPrototype.ID}-{rsi.RsiState}";
|
||||
|
||||
if (!_sprite.LayerMapTryGet((entity.Owner, sprite), layerId, out _, false))
|
||||
if (!_sprite.LayerMapTryGet((entity.Owner, sprite), layerId, out layerIndex, false)) // imp layerindex
|
||||
{
|
||||
var layer = _sprite.AddLayer((entity.Owner, sprite), markingSprite, targetLayer + j + 1);
|
||||
// for layers that are supposed to be behind everything,
|
||||
// adding 1 to the layer index makes it not be behind
|
||||
// everything. fun! FLOOF ADD =3
|
||||
// var targLayerAdj = targetLayer == 0 ? 0 + j : targetLayer + j + 1;
|
||||
var targLayerAdj = targetLayer + layerDict[layerSlot.ToString()] + 1;
|
||||
var layer = _sprite.AddLayer((entity.Owner, sprite), markingSprite, targLayerAdj);
|
||||
_sprite.LayerMapSet((entity.Owner, sprite), layerId, layer);
|
||||
_sprite.LayerSetSprite((entity.Owner, sprite), layerId, rsi);
|
||||
}
|
||||
|
||||
// imp special via beck. check if there's a shader defined in the markingPrototype's shader datafield, and if there is...
|
||||
if (markingPrototype.Shader != null)
|
||||
{
|
||||
// use spriteComponent's layersetshader function to set the layer's shader to that which is specified.
|
||||
sprite.LayerSetShader(layerId, markingPrototype.Shader);
|
||||
}
|
||||
// end imp special
|
||||
|
||||
_sprite.LayerSetVisible((entity.Owner, sprite), layerId, visible);
|
||||
|
||||
if (!visible || setting == null) // this is kinda implied
|
||||
@@ -377,10 +461,18 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
|
||||
// Okay so if the marking prototype is modified but we load old marking data this may no longer be valid
|
||||
// and we need to check the index is correct.
|
||||
// So if that happens just default to white?
|
||||
if (colors != null && j < colors.Count)
|
||||
_sprite.LayerSetColor((entity.Owner, sprite), layerId, colors[j]);
|
||||
else
|
||||
_sprite.LayerSetColor((entity.Owner, sprite), layerId, Color.White);
|
||||
// FLOOF ADD =3
|
||||
_sprite.LayerSetColor((entity.Owner, sprite), layerId, colorDict.TryGetValue(rsi.RsiState, out var color) ? color : Color.White);
|
||||
|
||||
// FLOOF REMOVE
|
||||
// if (colors != null && j < colors.Count)
|
||||
// {
|
||||
// _sprite.LayerSetColor((entity.Owner, sprite), layerId, colors[j]);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _sprite.LayerSetColor((entity.Owner, sprite), layerId, Color.White);
|
||||
// }
|
||||
|
||||
if (humanoid.MarkingsDisplacement.TryGetValue(markingPrototype.BodyPart, out var displacementData) && markingPrototype.CanBeDisplaced)
|
||||
_displacement.TryAddDisplacement(displacementData, (entity.Owner, sprite), targetLayer + j + 1, layerId, out _);
|
||||
|
||||
Reference in New Issue
Block a user