Added world sprite system (#397)

* Added world sprite system

* Added important comment
This commit is contained in:
Tornado Tech
2024-08-20 01:41:56 +10:00
committed by GitHub
parent 34f90f1bce
commit f6d81c04c0
5 changed files with 114 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
namespace Content.Client._CP14.WorldSprite;
/// <summary>
/// RUN, IF YOU SEE THE CODE TO THIS FUCKING THING, YOU'LL DIE ON THE SPOT.
/// </summary>
[RegisterComponent]
public sealed partial class CP14WorldSpriteComponent : Component
{
public bool Inited;
}

View File

@@ -0,0 +1,65 @@
using Content.Shared._CP14.WorldSprite;
using Content.Shared.Throwing;
using Robust.Client.GameObjects;
using Robust.Shared.Map.Components;
namespace Content.Client._CP14.WorldSprite;
public sealed class CP14WorldSpriteSystem : EntitySystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
#if DEBUG
SubscribeLocalEvent<CP14WorldSpriteComponent, ComponentInit>(OnComponentInit);
#endif
SubscribeLocalEvent<CP14WorldSpriteComponent, EntParentChangedMessage>(OnParentChanged);
SubscribeLocalEvent<CP14WorldSpriteComponent, ThrownEvent>(OnThrown);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<CP14WorldSpriteComponent>();
while (query.MoveNext(out var uid, out var worldSpriteComponent))
{
if (worldSpriteComponent.Inited)
continue;
Update(uid);
}
}
#if DEBUG
private void OnComponentInit(Entity<CP14WorldSpriteComponent> entity, ref ComponentInit args)
{
if (!HasComp<AppearanceComponent>(entity))
Log.Error($"Requires an {nameof(AppearanceComponent)} for {entity}");
}
#endif
private void OnParentChanged(Entity<CP14WorldSpriteComponent> entity, ref EntParentChangedMessage args)
{
Update(entity);
}
private void OnThrown(Entity<CP14WorldSpriteComponent> entity, ref ThrownEvent args)
{
// Idk, but throw don't call reparent
Update(entity, args.User);
}
private void Update(EntityUid entity, EntityUid? parent = null)
{
parent ??= Transform(entity).ParentUid;
var inWorld = HasComp<MapComponent>(parent) || HasComp<MapGridComponent>(parent);
_appearance.SetData(entity, WorldSpriteVisualLayers.Layer, inWorld);
}
}

View File

@@ -4,7 +4,8 @@ namespace Content.Server.Entry
public static class IgnoredComponents
{
public static string[] List => new[] {
"CP14WaveShader", //CP14 Wave shader
"CP14WaveShader", // CP14 Wave shader
"CP14WorldSprite", // CP14 World Sprite
"ConstructionGhost",
"IconSmooth",
"InteractionOutline",

View File

@@ -0,0 +1,6 @@
namespace Content.Shared._CP14.WorldSprite;
public enum WorldSpriteVisualLayers : byte
{
Layer,
}

View File

@@ -0,0 +1,31 @@
- type: entity
parent: BaseItem
id: CP14DebugWorldSprite
name: strange copper bar
suffix: CP, DEBUG
components:
# Just copy me, I am block with name Bob
- type: Appearance
- type: CP14WorldSprite
- type: GenericVisualizer
visuals:
enum.WorldSpriteVisualLayers.Layer:
world:
True:
visible: true
False:
visible: false
content:
True:
visible: false
False:
visible: true
# Just copy me, I am block with name Bob
- type: Sprite
sprite: /Textures/_CP14/Objects/Materials/copper_bar.rsi
layers:
- map: ["world"]
state: bar
- map: ["content"]
state: bar_2