split components
This commit is contained in:
@@ -9,7 +9,19 @@ namespace Content.Client._CP14.MagicSpell;
|
||||
public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem
|
||||
{
|
||||
[Dependency] private readonly IClientGameTiming _timing = default!;
|
||||
public bool MagicVisible { get; set; }
|
||||
|
||||
|
||||
private bool _markersVisible;
|
||||
|
||||
public bool MarkersVisible
|
||||
{
|
||||
get => _markersVisible;
|
||||
set
|
||||
{
|
||||
_markersVisible = value;
|
||||
UpdateVisibilityAll();
|
||||
}
|
||||
}
|
||||
|
||||
private TimeSpan _nextUpdate = TimeSpan.Zero;
|
||||
|
||||
@@ -17,7 +29,15 @@ public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14MagicVisionMarkerComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<CP14MagicVisionMarkerComponent, ComponentStartup>(OnStartupMarker);
|
||||
}
|
||||
|
||||
private void OnStartupMarker(Entity<CP14MagicVisionMarkerComponent> ent, ref ComponentStartup args)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(ent, out var sprite))
|
||||
return;
|
||||
|
||||
UpdateVisibility(ent, sprite);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -27,8 +47,22 @@ public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem
|
||||
if (_timing.CurTime < _nextUpdate)
|
||||
return;
|
||||
|
||||
_nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(1f);
|
||||
_nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(0.5f);
|
||||
|
||||
var queryFade = EntityQueryEnumerator<CP14MagicVisionFadeComponent, SpriteComponent>();
|
||||
while (queryFade.MoveNext(out var uid, out var fade, out var sprite))
|
||||
{
|
||||
UpdateOpaque((uid, fade), sprite);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVisibility(Entity<CP14MagicVisionMarkerComponent> ent, SpriteComponent sprite)
|
||||
{
|
||||
sprite.Visible = _markersVisible;
|
||||
}
|
||||
|
||||
private void UpdateVisibilityAll()
|
||||
{
|
||||
var query = EntityQueryEnumerator<CP14MagicVisionMarkerComponent, SpriteComponent>();
|
||||
while (query.MoveNext(out var uid, out var marker, out var sprite))
|
||||
{
|
||||
@@ -36,27 +70,10 @@ public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartup(Entity<CP14MagicVisionMarkerComponent> ent, ref ComponentStartup args)
|
||||
private void UpdateOpaque(Entity<CP14MagicVisionFadeComponent> ent, SpriteComponent sprite)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(ent, out var sprite))
|
||||
return;
|
||||
|
||||
ent.Comp.SpawnTime = _timing.CurTime;
|
||||
ent.Comp.EndTime = _timing.CurTime + ent.Comp.VisibilityTime;
|
||||
|
||||
UpdateVisibility(ent, sprite);
|
||||
}
|
||||
|
||||
private void UpdateVisibility(Entity<CP14MagicVisionMarkerComponent> ent, SpriteComponent sprite)
|
||||
{
|
||||
sprite.Visible = MagicVisible;
|
||||
|
||||
if (MagicVisible == false)
|
||||
return;
|
||||
|
||||
var progress = Math.Clamp((_timing.CurTime.TotalSeconds - ent.Comp.SpawnTime.TotalSeconds) / (ent.Comp.EndTime.TotalSeconds - ent.Comp.SpawnTime.TotalSeconds), 0, 1);
|
||||
var alpha = 1 - progress;
|
||||
Log.Info($"{ent.Owner.Id} - {alpha.ToString()}");
|
||||
sprite.Color = Color.White.WithAlpha((float)alpha);
|
||||
}
|
||||
}
|
||||
@@ -71,6 +88,6 @@ internal sealed class ShowMagicCommand : LocalizedCommands
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
_entitySystemManager.GetEntitySystem<CP14ClientMagicVisionSystem>().MagicVisible ^= true;
|
||||
_entitySystemManager.GetEntitySystem<CP14ClientMagicVisionSystem>().MarkersVisible ^= true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user