Snap to nearest cardinal on traversal (#10869)

This commit is contained in:
metalgearsloth
2022-08-29 15:59:19 +10:00
committed by GitHub
parent fe177f4a3e
commit 3fa666bd06
54 changed files with 222 additions and 49 deletions

View File

@@ -11,7 +11,6 @@ namespace Content.Client.Decals
public sealed class DecalOverlay : Overlay
{
private readonly DecalSystem _decals;
private readonly SharedTransformSystem _transform;
private readonly SpriteSystem _sprites;
private readonly IEntityManager _entManager;
private readonly IPrototypeManager _prototypeManager;
@@ -22,13 +21,11 @@ namespace Content.Client.Decals
public DecalOverlay(
DecalSystem decals,
SharedTransformSystem transforms,
SpriteSystem sprites,
IEntityManager entManager,
IPrototypeManager prototypeManager)
{
_decals = decals;
_transform = transforms;
_sprites = sprites;
_entManager = entManager;
_prototypeManager = prototypeManager;
@@ -39,10 +36,12 @@ namespace Content.Client.Decals
// Shouldn't need to clear cached textures unless the prototypes get reloaded.
var handle = args.WorldHandle;
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
var eyeAngle = args.Viewport.Eye?.Rotation ?? Angle.Zero;
foreach (var (gridId, zIndexDictionary) in _decals.DecalRenderIndex)
{
if (zIndexDictionary.Count == 0) continue;
if (zIndexDictionary.Count == 0)
continue;
if (!xformQuery.TryGetComponent(gridId, out var xform))
{
@@ -53,7 +52,9 @@ namespace Content.Client.Decals
if (xform.MapID != args.MapId)
continue;
handle.SetTransform(_transform.GetWorldMatrix(xform, xformQuery));
var (_, worldRot, worldMatrix) = xform.GetWorldPositionRotationMatrix(xformQuery);
handle.SetTransform(worldMatrix);
foreach (var (_, decals) in zIndexDictionary)
{
@@ -66,10 +67,23 @@ namespace Content.Client.Decals
_cachedTextures[decal.Id] = texture;
}
if (decal.Angle.Equals(Angle.Zero))
if (!_prototypeManager.TryIndex<DecalPrototype>(decal.Id, out var decalProto))
continue;
var cardinal = Angle.Zero;
if (decalProto.SnapCardinals)
{
var worldAngle = eyeAngle + worldRot;
cardinal = worldAngle.GetCardinalDir().ToAngle();
}
var angle = decal.Angle - cardinal;
if (angle.Equals(Angle.Zero))
handle.DrawTexture(texture, decal.Coordinates, decal.Color);
else
handle.DrawTexture(texture, decal.Coordinates, decal.Angle, decal.Color);
handle.DrawTexture(texture, decal.Coordinates, angle, decal.Color);
}
}
}
@@ -81,11 +95,9 @@ namespace Content.Client.Decals
{
if (_prototypeManager.TryIndex<DecalPrototype>(id, out var proto))
return proto.Sprite;
else
{
Logger.Error($"Unknown decal prototype: {id}");
return new SpriteSpecifier.Texture(new ResourcePath("/Textures/noSprite.png"));
}
Logger.Error($"Unknown decal prototype: {id}");
return new SpriteSpecifier.Texture(new ResourcePath("/Textures/noSprite.png"));
}
}
}