Files
Delta-v/Content.Client/IconSmoothing/IconSmoothSystem.cs
T
+27 f941121384 upstream merge (#1636)
* uncomment grappling gun

* Remove rest of Geras files (#30912)

remove remaining geras stuff

* tweak(AgeRequirement): Make the requiredAge more sensible (#30913)

* chrore(ageRequirement): fix grammar. atleast -> at least (#30914)

* Minor sprite fix to inhand med hardsuits and HoS turtleneck jumpsuit (#30918)

* Fixes inhand hardsuit cross color from https://github.com/space-wizards/space-station-14/issues/26516#issue-2213917971

* Fixed HoS Turtle not covering all butt pixels

---------

Co-authored-by: Zachary Yona <magicalusf@gmail.com>

* Add execution component to all energy sword weapons (#30909)

Co-authored-by: plykiya <plykiya@protonmail.com>

* Automatic changelog update

* chore(grammar): correct some mistakes (#30916)

* Add diamond mining drills, buff regular mining drills (#30814)

* why do I have to change so much just to add drills

* diamon

* Automatic changelog update

* give trash a reusable entity table (#30921)

* Contraband marking & examining (#28688)

* System & loc strings

* pass over syndie contraband

* fixes

* grand theft pass

* contrabandexamine -> contraband

* examine text generation update

* all composition parents necessary

* bring back minor contra so it has a less confusing message

* minor

* weapon pass

* jumpsuit pass

* feet pass

* AUUUUUUUUUGHHHHHHHHHHHHHHHHHH

* head

* AUUUUGH

* ear

* belt

* back

* fix

* bro

* rename for more clarity

* do da review

* add cvar for contraband examine

---------

Co-authored-by: EmoGarbage404 <retron404@gmail.com>
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>

* Automatic changelog update

* Automatic changelog update

* Removes variant cube migration (#30934)

add

* First Review Pass Contraband Fixes (#30930)

* First pass contra fix

* bam

* More

* Security crates are now marked as security restricted

* Syndicate raid suit is contra

* damn I forgot gatfruit

* Add conducting gloves to the maintenance loot table (#30904)

* add

* lower weight

* Fix DoDrop to DropNextTo in container cases (#30911)

* Fix DoDrop to DropNextTo in container cases
DoDrop is too heavy to calculation. In any other case we should use alternatives, for example DropNextTo helper method

* codestyle change

* Fix Reagent Fire Stacks (#30766)

* Fix Reagent Fire Stacks

* Comments on code

* little nicer wording?

* Lines 88 and 89, updated 'narsie' and 'ratvar' to 'Nar'Sie' and Ratva… (#30954)

Lines 88 and 89, updated 'narsie' and 'ratvar' to 'Nar'Sie' and Ratvar, per issue #30719.

* Automatic changelog update

* Fix permission check for whitelists in player panel (#30948)

* Automatic changelog update

* Grey mantle in winterdrobe (#29774)

* add the mantle

* fix a few things

* fix merge conflict stuff, remove from winterdrobe and lathe.

* Add mantle to loadouts (20 hour requirement)

* Automatic changelog update

* Sliceable doAfter (#30824)

* init

* wtf git

* Automatic changelog update

* Add capfruit, a gatfruit mutation. (#30850)

* add base

* add fake suffix and flavor fix

* address some reviews

* parent it

* fix test fail

* add FoodSequence support and address small review

* Automatic changelog update

* Fixes the grey mantle (#30971)

add the thing i missed

* Add keybinds for rotating and flipping objects (#30540)

* add keybinds for rotating and flipping objects

* no popup for verbs

* Automatic changelog update

* tweak(Shuttle_honki): Remove DeviceQuantumSpinInverter from honki shuttle. (#30618)

* Make the Borgs Names Appear When they Make an Announcement (#30107)

* Make the Borgs Names Appear When they Make an Announcement

* bwomp

* re-order

* Use Name instead of metadata

* goiup

* Automatic changelog update

* disable contraband examine

* rename our SliceFoodEvent

* Throngler Plushie Sprite (#30969)

Throngonkler Plush sprite

* Fix bug with rotating shelves (#30978)

* Main

* Update shelfs.yml

* Little bug fix

* No weather on concrete tiles (#30952)

* concrete weather

* miss

* development build ghostrole lottery changes (#30980)

debug ghostrole lottery changes

* Automatic changelog update

* Add a saline syringe to the combat medical kit (#29954)

saline

* Automatic changelog update

* fix the admin verbs trying to kill players by filling their lungs with plasma (#30991)

fix the admin tools trying to kill players by filling their lungs with plasma

* Custom Taco & Kebabs - FoodSequence 2 (#30905)

* control layer ordering

* sprite update

* taco!

* taco naming gen

* fix separator naming

* some proto fixes

* default naming separation

* fix taco naming

* rat update

* hamsterburger

* organs taco

* remove from spawners

* fixes

* fix separators and lemons

* Update food-sequence.ftl

* randomization offset

* fix

* kebabs refactor

* fix

* skewer weapon

* Update food_single.yml

* Update migration.yml

* suppermatter

* hamlet centered

* hamsburger

* Update dead-0.png

* 20 -> 4 burger layers max

* Update burger.yml

* canReact: false

* capfruit update

* Update burger.yml

* Update burger.yml

* Update produce.yml

* some fixes

* Update Resources/Textures/Objects/Consumable/Food/taco.rsi/meta.json

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Content.Shared/Nutrition/Components/FoodSequenceStartPointComponent.cs

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Update Content.Shared/Nutrition/Components/FoodSequenceStartPointComponent.cs

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* chicken

* Update food-sequence.ftl

* documentation

* fixes

* Update meat.yml

* Update meat.yml

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Automatic changelog update

* Fix popups not working properly with an eye offset (#30990)

* Adds a random smokable spawner (#30870)

* Textures to make lamps mappable to East/West.

* Adds a random smokable spawner

* remove double derma

* Increase chance for just basic cig

* Update to enitity tables

* Tweak values

* Remove space

---------

Co-authored-by: Jeff <velcroboy333@hotmail.com>

* Fix lizards being unable to eat custom burgers (#31005)

* Fix lizards being unable to eat custom burgers

* ensure tag comp

* Automatic changelog update

* Sedin (#27110)

* Sedin

* almost forgot this.

* what

* Did a few fixes, tried to readd popup

* Fix popup, ready for merge

* minor change

* Generalize seed removal/destruction system, add popups in general.

* fix

* fix (again)

* deadcode is no more

* Sedin buff (nerfing the recipe soon)

* godont

* webedit moment

ok listen I had to nuke my setup because my computer was being Dumb As Shit so let me do this ONE webedit

* CRIKEY

* Revert "CRIKEY"

This reverts commit 1c6959ffd9ba8bb1e97ccf2eb0b37b3ff4ec82ee.

I was not supposed to commit that >:/

* Alright, it should be good now but I havent tested it

* ready for merge/review

* prob -> probability

* Requested changes nodoc

* Review nodoc

* documento

* thumb up emoji

* Automatic changelog update

* Adds a Dinky Star Sticker for security officers (#29767)

* Sec-Star-TASTIC

* fix license

* now counts as trash

* Sticks to people + wearable

* no more sticky

* no more sticky

* mystery-space

* Update Loadout Yaml

* Automatic changelog update

* tweak(hospital): Reduce diamond stack from 30 to 1 (#31027)

* tweak(experiment): Reduce diamond stack from 30 to 1 (#31025)

* replace mapped diamond stacks with single

* Figurine voicelines (#30865)

* initial commit

* tweaks to the new voice lines

capitalizations of I's and the Y on hos 3 voice lines
also changed the captain figuring voice line 2 to something completely different

* capitalized one letter

man i really suck at capitalization

* more capitalization

i never thought this pr would need so many changes

* changed one comma to a dot

* Update Resources/Locale/en-US/datasets/figurines.ftl

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* Automatic changelog update

* Adding shock collar and electropack (#30529)

* Adding shock collar with the new ShockOnTrigger

* Cleaning and updating the shock collar

* Add StripDelay datafield to ClothingComponent

* Adding SelfUnremovableClothingComponent

* ShockCollar Update

* Correction of the shock collar

* Correction of the shock collar 2

* Renaming the DamageSpecifier DataField to Damage

* Fixing the damage field in ShockCollar

* Cleaning the ShockCollar

* Renaming ShockCollar to ClothingNeckShockCollar

* Adding ClothingNeckShockCollar as a stealTarget to a thief

* Fixing a typo of the sprite path in ClothingNeckShockCollar

* Cleaning the ShockOnTriggerComponent

* Revision of SelfUnremovableClothing

* Adding a ClothingBackpackElectropack

* Sprite fix

* Code review

* Shock Collar sprite update

* add commit hash

---------

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>

* Automatic changelog update

* Greatly improve the usability of the Gas Analyzer. (#30763)

* greatly improve how the gas analyzer behaves

* don't close the analyzer when the object goes out of range

* cleanup

* always switch to the device tab when a new device is analyzed

* modern api part one

* modern api part 2

* modern api part three

* file scope namespace

* Automatic changelog update

* Fix false and true in player-panel.ftl (#31043)

Fix false and true in player-panel

Add a new True string

* Contra Review Passs - Round 2 (#30942)

* Contra pass round two

* command too

* Stamps

* oopsied a bracket

* Namespace cleanup around Mind Roles (#30965)

* namespaces

* Comment does not need a semicolon

---------

Co-authored-by: Vasilis <vascreeper@yahoo.com>

* Contraband Review Pass - The Threequel (#30970)

Contraband pass number three

* Golden toilet (#31049)

* golden toilet

* Destructible

* sprite

* fix

* copyright

* Automatic changelog update

* Salvage Spawners (#31020)

* treasure entities and spawners

* no more smiles

* remove nyano shock collar code

* Event scheduler setting tweaks (#31018)

tweaks

* Automatic changelog update

* remove meteor swarms rule for a moment

* Revamped Meteor Swarm (#28974)

* meteor code and balanced values

* Meteor Swarms

* Update meteors.yml

* Update meteors.yml

* HOO! (fix overkill bug and buff space dust)

* undo BloodstreamComponent.cs changes

* DamageDistribution -> DamageTypes

* part 2.

* Missing meteor presets (#29044)

* add meteors into missing game presets

* changes for real

* implement code

* this too

* Meteors now leave behind a bit of ore (#30419)

* Meteors that leave behind asteroid ore

* bigger offset

* Bit more generic

* Better defaults

* hrm?

* I HATE CUSTOM SERIALIZERS

* More comments

* renamed a variable

---------

Co-authored-by: plykiya <plykiya@protonmail.com>

* refactor event schedulers to use explicit game rules (#29320)

* works, still has testing values, im sure I did stupid shit.

* shitvent crapfactor

* snap extra word out of existence

* shit I died of old

* remove useless inaccurate design comments

* Oopsie, handle requirement params in RandomRuleSystem too

* I'm a slash slinging hasher

* Address reviews, add admin alerts I forgor

* EntityMan saves the day

* address reviews 1

* eh, I actually don't care about the cargo gifts thing.

* started

* Do reviews

* you actually meant 1.2 lmao

* dependency inheritance is a fickle bitch

* I have no idea.

* Threads are for sheets not computers.

* fix traitor rule test

* fix round type tattling

* break things

* It worky

* Toolshed makes we want to drink depresso.

* Finished?

* remove debug values

* timings

* use defaults

* alphabetize

* bobby drop tables

* Float required fr fr

* continue

* more continence

* uno mas

* obsolution

* cleanup and documentations

* Yell at self

* use the right value defaults

* housekeeping

* Event scheduler setting tweaks (#31018)

tweaks

* Automatic changelog update

* remove(NukeopsRuleComponent): Remove a trap from the component file (#31029)

ah

* Fix bug with holding objects (#31009)

Main

* Automatic changelog update

* Replace obsolete map functions in IconSmoothSystem (#30958)

* first part

* second part

* Automatic changelog update

* Fix reagents with ReagentData being duplicated  (#30983)

Initial commit

* :trollface:

* :trollface:

* actually untroll

* a

* 50 burger

* add back old meteor code

* fix

* use some live config options in dev

* remove old shock collar icon

* make ammo more consistent and work more

* clean up lathes diff to upstream

* a

* move rubber bullets to deltav folder

* a

* untroll

* more untrolls

* more untrolls

* untroll

* :trollface:

* a

* b

* remove it for real

* add missing lathe recipes

* replace cvars with component field

* remove taco from roboisseur

* migrate cardboard box with smg mags

* remove kebabs

* a

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: Killerqu00 <47712032+Killerqu00@users.noreply.github.com>
Co-authored-by: Brandon Hu <103440971+Brandon-Huu@users.noreply.github.com>
Co-authored-by: Zachary Yona <58833995+Magicalus@users.noreply.github.com>
Co-authored-by: Zachary Yona <magicalusf@gmail.com>
Co-authored-by: Plykiya <58439124+Plykiya@users.noreply.github.com>
Co-authored-by: plykiya <plykiya@protonmail.com>
Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com>
Co-authored-by: Alzore <140123969+Blackern5000@users.noreply.github.com>
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: EmoGarbage404 <retron404@gmail.com>
Co-authored-by: Ubaser <134914314+UbaserB@users.noreply.github.com>
Co-authored-by: Token <esil.bektay@yandex.com>
Co-authored-by: Cojoke <83733158+Cojoke-dot@users.noreply.github.com>
Co-authored-by: LeoSantich <108027402+LeoSantich@users.noreply.github.com>
Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Co-authored-by: pigeonpeas <147350443+pigeonpeas@users.noreply.github.com>
Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: PoorMansDreams <150595537+PoorMansDreams@users.noreply.github.com>
Co-authored-by: IgorAnt028 <118114530+IgorAnt028@users.noreply.github.com>
Co-authored-by: NotSoDamn <75203942+NotSoDana@users.noreply.github.com>
Co-authored-by: Errant <35878406+Errant-4@users.noreply.github.com>
Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: Velcroboy <107660393+IamVelcroboy@users.noreply.github.com>
Co-authored-by: Jeff <velcroboy333@hotmail.com>
Co-authored-by: themias <89101928+themias@users.noreply.github.com>
Co-authored-by: Eris <eris@erisws.com>
Co-authored-by: FATFSAAM2 <saamboroujerdi@gmail.com>
Co-authored-by: to4no_fix <156101927+chavonadelal@users.noreply.github.com>
Co-authored-by: Mervill <mervills.email@gmail.com>
Co-authored-by: Vasilis <vascreeper@yahoo.com>
Co-authored-by: Nim <128169402+Nimfar11@users.noreply.github.com>
Co-authored-by: IProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com>
Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
2024-08-18 17:21:07 +00:00

542 lines
22 KiB
C#

using System.Numerics;
using Content.Shared.IconSmoothing;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Map.Enumerators;
using static Robust.Client.GameObjects.SpriteComponent;
namespace Content.Client.IconSmoothing
{
// TODO: just make this set appearance data?
/// <summary>
/// Entity system implementing the logic for <see cref="IconSmoothComponent"/>
/// </summary>
[UsedImplicitly]
public sealed partial class IconSmoothSystem : EntitySystem
{
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
private readonly Queue<EntityUid> _dirtyEntities = new();
private readonly Queue<EntityUid> _anchorChangedEntities = new();
private int _generation;
public void SetEnabled(EntityUid uid, bool value, IconSmoothComponent? component = null)
{
if (!Resolve(uid, ref component, false) || value == component.Enabled)
return;
component.Enabled = value;
DirtyNeighbours(uid, component);
}
public override void Initialize()
{
base.Initialize();
InitializeEdge();
SubscribeLocalEvent<IconSmoothComponent, AnchorStateChangedEvent>(OnAnchorChanged);
SubscribeLocalEvent<IconSmoothComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<IconSmoothComponent, ComponentStartup>(OnStartup);
}
private void OnStartup(EntityUid uid, IconSmoothComponent component, ComponentStartup args)
{
var xform = Transform(uid);
if (xform.Anchored)
{
component.LastPosition = TryComp<MapGridComponent>(xform.GridUid, out var grid)
? (xform.GridUid.Value, _mapSystem.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates))
: (null, new Vector2i(0, 0));
DirtyNeighbours(uid, component);
}
if (component.Mode != IconSmoothingMode.Corners || !TryComp(uid, out SpriteComponent? sprite))
return;
SetCornerLayers(sprite, component);
if (component.Shader != null)
{
sprite.LayerSetShader(CornerLayers.SE, component.Shader);
sprite.LayerSetShader(CornerLayers.NE, component.Shader);
sprite.LayerSetShader(CornerLayers.NW, component.Shader);
sprite.LayerSetShader(CornerLayers.SW, component.Shader);
}
}
public void SetStateBase(EntityUid uid, IconSmoothComponent component, string newState)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;
component.StateBase = newState;
SetCornerLayers(sprite, component);
}
private void SetCornerLayers(SpriteComponent sprite, IconSmoothComponent component)
{
sprite.LayerMapRemove(CornerLayers.SE);
sprite.LayerMapRemove(CornerLayers.NE);
sprite.LayerMapRemove(CornerLayers.NW);
sprite.LayerMapRemove(CornerLayers.SW);
var state0 = $"{component.StateBase}0";
sprite.LayerMapSet(CornerLayers.SE, sprite.AddLayerState(state0));
sprite.LayerSetDirOffset(CornerLayers.SE, DirectionOffset.None);
sprite.LayerMapSet(CornerLayers.NE, sprite.AddLayerState(state0));
sprite.LayerSetDirOffset(CornerLayers.NE, DirectionOffset.CounterClockwise);
sprite.LayerMapSet(CornerLayers.NW, sprite.AddLayerState(state0));
sprite.LayerSetDirOffset(CornerLayers.NW, DirectionOffset.Flip);
sprite.LayerMapSet(CornerLayers.SW, sprite.AddLayerState(state0));
sprite.LayerSetDirOffset(CornerLayers.SW, DirectionOffset.Clockwise);
}
private void OnShutdown(EntityUid uid, IconSmoothComponent component, ComponentShutdown args)
{
_dirtyEntities.Enqueue(uid);
DirtyNeighbours(uid, component);
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
var xformQuery = GetEntityQuery<TransformComponent>();
var smoothQuery = GetEntityQuery<IconSmoothComponent>();
// first process anchor state changes.
while (_anchorChangedEntities.TryDequeue(out var uid))
{
if (!xformQuery.TryGetComponent(uid, out var xform))
continue;
if (xform.MapID == MapId.Nullspace)
{
// in null-space. Almost certainly because it left PVS. If something ever gets sent to null-space
// for reasons other than this (or entity deletion), then maybe we still need to update ex-neighbor
// smoothing here.
continue;
}
DirtyNeighbours(uid, comp: null, xform, smoothQuery);
}
// Next, update actual sprites.
if (_dirtyEntities.Count == 0)
return;
_generation += 1;
var spriteQuery = GetEntityQuery<SpriteComponent>();
// Performance: This could be spread over multiple updates, or made parallel.
while (_dirtyEntities.TryDequeue(out var uid))
{
CalculateNewSprite(uid, spriteQuery, smoothQuery, xformQuery);
}
}
public void DirtyNeighbours(EntityUid uid, IconSmoothComponent? comp = null, TransformComponent? transform = null, EntityQuery<IconSmoothComponent>? smoothQuery = null)
{
smoothQuery ??= GetEntityQuery<IconSmoothComponent>();
if (!smoothQuery.Value.Resolve(uid, ref comp) || !comp.Running)
return;
_dirtyEntities.Enqueue(uid);
if (!Resolve(uid, ref transform))
return;
Vector2i pos;
EntityUid entityUid;
if (transform.Anchored && TryComp<MapGridComponent>(transform.GridUid, out var grid))
{
entityUid = transform.GridUid.Value;
pos = _mapSystem.CoordinatesToTile(transform.GridUid.Value, grid, transform.Coordinates);
}
else
{
// Entity is no longer valid, update around the last position it was at.
if (comp.LastPosition is not (EntityUid gridId, Vector2i oldPos))
return;
if (!TryComp(gridId, out grid))
return;
entityUid = gridId;
pos = oldPos;
}
// Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us.
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(1, 0)));
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(-1, 0)));
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(0, 1)));
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(0, -1)));
if (comp.Mode is IconSmoothingMode.Corners or IconSmoothingMode.NoSprite or IconSmoothingMode.Diagonal)
{
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(1, 1)));
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(-1, -1)));
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(-1, 1)));
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(1, -1)));
}
}
private void DirtyEntities(AnchoredEntitiesEnumerator entities)
{
// Instead of doing HasComp -> Enqueue -> TryGetComp, we will just enqueue all entities. Generally when
// dealing with walls neighboring anchored entities will also be walls, and in those instances that will
// require one less component fetch/check.
while (entities.MoveNext(out var entity))
{
_dirtyEntities.Enqueue(entity.Value);
}
}
private void OnAnchorChanged(EntityUid uid, IconSmoothComponent component, ref AnchorStateChangedEvent args)
{
if (!args.Detaching)
_anchorChangedEntities.Enqueue(uid);
}
private void CalculateNewSprite(EntityUid uid,
EntityQuery<SpriteComponent> spriteQuery,
EntityQuery<IconSmoothComponent> smoothQuery,
EntityQuery<TransformComponent> xformQuery,
IconSmoothComponent? smooth = null)
{
TransformComponent? xform;
Entity<MapGridComponent>? gridEntity = null;
// The generation check prevents updating an entity multiple times per tick.
// As it stands now, it's totally possible for something to get queued twice.
// Generation on the component is set after an update so we can cull updates that happened this generation.
if (!smoothQuery.Resolve(uid, ref smooth, false)
|| smooth.Mode == IconSmoothingMode.NoSprite
|| smooth.UpdateGeneration == _generation
|| !smooth.Enabled
|| !smooth.Running)
{
if (smooth is { Enabled: true } &&
TryComp<SmoothEdgeComponent>(uid, out var edge) &&
xformQuery.TryGetComponent(uid, out xform))
{
var directions = DirectionFlag.None;
if (TryComp(xform.GridUid, out MapGridComponent? grid))
{
var gridUid = xform.GridUid.Value;
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
gridEntity = (gridUid, grid);
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.North)), smoothQuery))
directions |= DirectionFlag.North;
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.South)), smoothQuery))
directions |= DirectionFlag.South;
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.East)), smoothQuery))
directions |= DirectionFlag.East;
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.West)), smoothQuery))
directions |= DirectionFlag.West;
}
CalculateEdge(uid, directions, component: edge);
}
return;
}
xform = xformQuery.GetComponent(uid);
smooth.UpdateGeneration = _generation;
if (!spriteQuery.TryGetComponent(uid, out var sprite))
{
Log.Error($"Encountered a icon-smoothing entity without a sprite: {ToPrettyString(uid)}");
RemCompDeferred(uid, smooth);
return;
}
var spriteEnt = (uid, sprite);
if (xform.Anchored)
{
if (TryComp(xform.GridUid, out MapGridComponent? grid))
{
gridEntity = (xform.GridUid.Value, grid);
}
else
{
Log.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridUid} was missing.");
return;
}
}
switch (smooth.Mode)
{
case IconSmoothingMode.Corners:
CalculateNewSpriteCorners(gridEntity, smooth, spriteEnt, xform, smoothQuery);
break;
case IconSmoothingMode.CardinalFlags:
CalculateNewSpriteCardinal(gridEntity, smooth, spriteEnt, xform, smoothQuery);
break;
case IconSmoothingMode.Diagonal:
CalculateNewSpriteDiagonal(gridEntity, smooth, spriteEnt, xform, smoothQuery);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private void CalculateNewSpriteDiagonal(Entity<MapGridComponent>? gridEntity, IconSmoothComponent smooth,
Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
if (gridEntity == null)
{
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}0");
return;
}
var gridUid = gridEntity.Value.Owner;
var grid = gridEntity.Value.Comp;
var neighbors = new Vector2[]
{
new(1, 0),
new(1, -1),
new(0, -1),
};
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
var rotation = xform.LocalRotation;
var matching = true;
for (var i = 0; i < neighbors.Length; i++)
{
var neighbor = (Vector2i)rotation.RotateVec(neighbors[i]);
matching = matching && MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos + neighbor), smoothQuery);
}
if (matching)
{
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}1");
}
else
{
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}0");
}
}
private void CalculateNewSpriteCardinal(Entity<MapGridComponent>? gridEntity, IconSmoothComponent smooth, Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
var dirs = CardinalConnectDirs.None;
if (gridEntity == null)
{
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int)dirs}");
return;
}
var gridUid = gridEntity.Value.Owner;
var grid = gridEntity.Value.Comp;
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.North)), smoothQuery))
dirs |= CardinalConnectDirs.North;
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.South)), smoothQuery))
dirs |= CardinalConnectDirs.South;
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.East)), smoothQuery))
dirs |= CardinalConnectDirs.East;
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.West)), smoothQuery))
dirs |= CardinalConnectDirs.West;
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int)dirs}");
var directions = DirectionFlag.None;
if ((dirs & CardinalConnectDirs.South) != 0x0)
directions |= DirectionFlag.South;
if ((dirs & CardinalConnectDirs.East) != 0x0)
directions |= DirectionFlag.East;
if ((dirs & CardinalConnectDirs.North) != 0x0)
directions |= DirectionFlag.North;
if ((dirs & CardinalConnectDirs.West) != 0x0)
directions |= DirectionFlag.West;
CalculateEdge(sprite, directions, sprite);
}
private bool MatchingEntity(IconSmoothComponent smooth, AnchoredEntitiesEnumerator candidates, EntityQuery<IconSmoothComponent> smoothQuery)
{
while (candidates.MoveNext(out var entity))
{
if (smoothQuery.TryGetComponent(entity, out var other) &&
other.SmoothKey == smooth.SmoothKey &&
other.Enabled)
{
return true;
}
}
return false;
}
private void CalculateNewSpriteCorners(Entity<MapGridComponent>? gridEntity, IconSmoothComponent smooth, Entity<SpriteComponent> spriteEnt, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
var (cornerNE, cornerNW, cornerSW, cornerSE) = gridEntity == null
? (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None)
: CalculateCornerFill(gridEntity.Value, smooth, xform, smoothQuery);
// TODO figure out a better way to set multiple sprite layers.
// This will currently re-calculate the sprite bounding box 4 times.
// It will also result in 4-8 sprite update events being raised when it only needs to be 1-2.
// At the very least each event currently only queues a sprite for updating.
// Oh god sprite component is a mess.
var sprite = spriteEnt.Comp;
sprite.LayerSetState(CornerLayers.NE, $"{smooth.StateBase}{(int)cornerNE}");
sprite.LayerSetState(CornerLayers.SE, $"{smooth.StateBase}{(int)cornerSE}");
sprite.LayerSetState(CornerLayers.SW, $"{smooth.StateBase}{(int)cornerSW}");
sprite.LayerSetState(CornerLayers.NW, $"{smooth.StateBase}{(int)cornerNW}");
var directions = DirectionFlag.None;
if ((cornerSE & cornerSW) != CornerFill.None)
directions |= DirectionFlag.South;
if ((cornerSE & cornerNE) != CornerFill.None)
directions |= DirectionFlag.East;
if ((cornerNE & cornerNW) != CornerFill.None)
directions |= DirectionFlag.North;
if ((cornerNW & cornerSW) != CornerFill.None)
directions |= DirectionFlag.West;
CalculateEdge(spriteEnt, directions, sprite);
}
private (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill(Entity<MapGridComponent> gridEntity, IconSmoothComponent smooth, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
var gridUid = gridEntity.Owner;
var grid = gridEntity.Comp;
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
var n = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.North)), smoothQuery);
var ne = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.NorthEast)), smoothQuery);
var e = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.East)), smoothQuery);
var se = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.SouthEast)), smoothQuery);
var s = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.South)), smoothQuery);
var sw = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.SouthWest)), smoothQuery);
var w = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.West)), smoothQuery);
var nw = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.NorthWest)), smoothQuery);
// ReSharper disable InconsistentNaming
var cornerNE = CornerFill.None;
var cornerSE = CornerFill.None;
var cornerSW = CornerFill.None;
var cornerNW = CornerFill.None;
// ReSharper restore InconsistentNaming
if (n)
{
cornerNE |= CornerFill.CounterClockwise;
cornerNW |= CornerFill.Clockwise;
}
if (ne)
{
cornerNE |= CornerFill.Diagonal;
}
if (e)
{
cornerNE |= CornerFill.Clockwise;
cornerSE |= CornerFill.CounterClockwise;
}
if (se)
{
cornerSE |= CornerFill.Diagonal;
}
if (s)
{
cornerSE |= CornerFill.Clockwise;
cornerSW |= CornerFill.CounterClockwise;
}
if (sw)
{
cornerSW |= CornerFill.Diagonal;
}
if (w)
{
cornerSW |= CornerFill.Clockwise;
cornerNW |= CornerFill.CounterClockwise;
}
if (nw)
{
cornerNW |= CornerFill.Diagonal;
}
// Local is fine as we already know it's parented to the grid (due to the way anchoring works).
switch (xform.LocalRotation.GetCardinalDir())
{
case Direction.North:
return (cornerSW, cornerSE, cornerNE, cornerNW);
case Direction.West:
return (cornerSE, cornerNE, cornerNW, cornerSW);
case Direction.South:
return (cornerNE, cornerNW, cornerSW, cornerSE);
default:
return (cornerNW, cornerSW, cornerSE, cornerNE);
}
}
// TODO consider changing this to use DirectionFlags?
// would require re-labelling all the RSI states.
[Flags]
private enum CardinalConnectDirs : byte
{
None = 0,
North = 1,
South = 2,
East = 4,
West = 8
}
[Flags]
private enum CornerFill : byte
{
// These values are pulled from Baystation12.
// I'm too lazy to convert the state names.
None = 0,
// The cardinal tile counter-clockwise of this corner is filled.
CounterClockwise = 1,
// The diagonal tile in the direction of this corner.
Diagonal = 2,
// The cardinal tile clockwise of this corner is filled.
Clockwise = 4,
}
private enum CornerLayers : byte
{
SE,
NE,
NW,
SW,
}
}
}