Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

randomize iconSmoothing #28158

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion Content.Client/IconSmoothing/IconSmoothComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed partial class IconSmoothComponent : Component
/// Prepended to the RSI state.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("base")]
public string StateBase { get; private set; } = string.Empty;
public string StateBase { get; set; } = string.Empty;

[DataField("shader", customTypeSerializer:typeof(PrototypeIdSerializer<ShaderPrototype>))]
public string? Shader;
Expand All @@ -45,6 +45,12 @@ public sealed partial class IconSmoothComponent : Component
/// Used by <see cref="IconSmoothSystem"/> to reduce redundant updates.
/// </summary>
internal int UpdateGeneration { get; set; }

/// <summary>
/// If not empty, <see cref="StateBase"/> will be randomly selected from this list. Allows to randomize the visual.
/// </summary>
[DataField]
public List<string> RandomStates = new();
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/IconSmoothing/IconSmoothSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Numerics;
using Content.Shared.IconSmoothing;
using Content.Shared.Random.Helpers;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Map.Enumerators;
using Robust.Shared.Random;
using static Robust.Client.GameObjects.SpriteComponent;

namespace Content.Client.IconSmoothing
Expand All @@ -19,6 +21,8 @@ public sealed partial class IconSmoothSystem : EntitySystem
private readonly Queue<EntityUid> _dirtyEntities = new();
private readonly Queue<EntityUid> _anchorChangedEntities = new();

[Dependency] private readonly IRobustRandom _random = default!;

private int _generation;

public void SetEnabled(EntityUid uid, bool value, IconSmoothComponent? component = null)
Expand All @@ -42,6 +46,10 @@ public override void Initialize()

private void OnStartup(EntityUid uid, IconSmoothComponent component, ComponentStartup args)
{
//Randomize visual
if (component.RandomStates.Count > 0)
component.StateBase = _random.Pick(component.RandomStates);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check if StateBase has already been set (so loading initialized maps preserves the existing state)

Ideally, this would be randomized at mapinit instead as well, but that seems to be a taller ask.

Copy link
Contributor Author

@TheShuEd TheShuEd May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StateBase always set. its have default "base" value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also its client-side component and system, server dont save this data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The randomization should probably be shared, then (Separate component?). Otherwise clients will get inconsistent visuals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason why I don't want to add this to the shared is that storing random information from RandomSprite on the server loads all the objects on procedurally generated biomes, and clogs up memory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's that big of an issue, especially when the alternative is inconsistent (per client) visuals.


var xform = Transform(uid);
if (xform.Anchored)
{
Expand Down