Ss14 graphics generic visualizer appearance

From space-sunrise/fish-station · View interactive version

Ss14 graphics generic visualizer appearance is an AI agent skill from the GitHub repository space-sunrise/fish-station. A practical and architectural guide to the combination of AppearanceComponent, AppearanceSystem, VisualizerSystem and GenericVisualizer in SS14. Use it when designing network visual states, YAML visualizations and client visualizer systems.

How to use this skill

Skill file

GenericVisualizer and Appearance in SS14

This skill only covers the pipeline Appearance + VisualizerSystem + GenericVisualizer :)

Low-level rendering and detailed SpriteSystem API can be analyzed in a separate sprite-skill.

When to choose this skill

Choose it if the task is about:

Source of truth and relevance

End-to-end architecture

  1. Server logic calculates the visual state.
  2. The server writes data to AppearanceComponent through SharedAppearanceSystem.SetData(...).
  3. The data enters the component state and is synchronized over the network.
  4. Client AppearanceSystem accepts state, updates the appearance data dictionary, and queues the update.
  5. During FrameUpdate, AppearanceChangeEvent is raised.
  6. Client visualizer systems (VisualizerSystem<T>) apply data to the sprite.
  7. If simple mapping of values ​​on layer-data is enough, GenericVisualizerSystem does this.

Idea: the server conveys not “how to draw”, but “what is visually true”; the client decides “how to draw” :)

Enum contract: which enums are needed and in what order

This topic usually involves two different enum contracts, sometimes three:

  1. AppearanceKey enum (shared)

These are the keys of the AppearanceData dictionary.

It is these enums that are passed to SetData / TryGetData / RemoveData.

  1. LayerKey enum (client + prototype visualization)

These are the keys of the sprite layers (layer map), by which you change visible/state/color/....

These enums are used in SpriteSystem and/or in GenericVisualizer YAML as layer key.

  1. AppearanceValue enum (optional, shared)

This is not a key, but a value of appearance data.

Example: ChargeState.Empty/Medium/Full.

Critically important: AppearanceKey enum and LayerKey enum are different roles and should not be mixed ⚠

Order of application in code and YAML

  1. Describe AppearanceKey enum in the shared contract.
  2. Describe LayerKey enum for addressing layers.
  3. The server writes the value: SetData(uid, AppearanceKey.SomeKey, value).
  4. Client:

Matching pattern

visuals:
  enum.AppearanceKeyEnum.SomeKey:
    enum.LayerKeyEnum.TargetLayer:
      "AppearanceValueToString":
        state: some_state
        visible: true
[Serializable, NetSerializable]
public enum LockerVisuals : byte // 1) AppearanceKey enum
{
    Open,
    ChargeState,
}

[Serializable, NetSerializable]
public enum LockerVisualLayers : byte // 2) LayerKey enum
{
    DoorOpen,
    DoorClosed,
    Indicator,
}

[Serializable, NetSerializable]
public enum LockerChargeState : byte // 3) AppearanceValue enum (optional)
{
    Empty,
    Medium,
    Full,
}

// Server: AppearanceKey + value only
_appearance.SetData(uid, LockerVisuals.Open, true, appearance);
_appearance.SetData(uid, LockerVisuals.ChargeState, LockerChargeState.Full, appearance);

// Client (custom visualizer): reads AppearanceKey, applies to LayerKey
if (_appearance.TryGetData(uid, LockerVisuals.Open, out bool open, args.Component))
{
    _sprite.LayerSetVisible((uid, args.Sprite), LockerVisualLayers.DoorOpen, open);
    _sprite.LayerSetVisible((uid, args.Sprite), LockerVisualLayers.DoorClosed, !open);
}

API parsing

1) `SharedAppearanceSystem`

Key methods:

Important:

2) Client `AppearanceSystem`

What is important to know:

If this is not done, exceptions may occur when applying state ⚠

3) Server `AppearanceSystem`

4) `VisualizerSystem<T>`

Contract:

5) `GenericVisualizerComponent`

Basic structure:

AppearanceKey -> LayerKey -> AppearanceValueString -> PrototypeLayerData.

Consequence:

6) `GenericVisualizerSystem`

Application algorithm:

  1. Follows the described visuals.
  2. For each appearance key, it tries to read the current value.
  3. Converts the value to a string (ToString()).
  4. Looks up the corresponding PrototypeLayerData in the variant dictionary.
  5. Reserves/gets a layer by key.
  6. Applies LayerSetData.

Practical conclusion:

Decision Tree: GenericVisualizer or custom visualizer

  1. Do you only need "value X -> state/visible/color/shader/offset/..." without complex logic?

Use GenericVisualizer ✅

  1. Do you need timers, animations, external system dependencies or complex calculations?

Write custom VisualizerSystem<T> ✅

  1. Do you need to dynamically create/delete many layers at runtime?

Usually custom visualizer ✅

  1. Do you need a composition of several appearance keys with non-trivial rules?

Usually custom visualizer ✅

Practical examples

Example 1: the server writes and clears the appearance flag

[NetSerializable, Serializable]
public enum LockerVisuals : byte
{
    Open,
}

private void UpdateLockerAppearance(EntityUid uid, AppearanceComponent appearance, bool open)
{
    // The server reports only the actual visual state.
    _appearance.SetData(uid, LockerVisuals.Open, open, appearance);

    if (!open)
    {
        // If necessary, the key can be explicitly removed.
        _appearance.RemoveData(uid, LockerVisuals.Open, appearance);
    }
}

Example 2: Client visualizer reads typed data

protected override void OnAppearanceChange(EntityUid uid, LockerVisualsComponent component, ref AppearanceChangeEvent args)
{
    if (args.Sprite == null)
        return;

    // We read AppearanceKey enum (LockerVisuals), and apply LayerKey enum (LockerVisualLayers).
    if (_appearance.TryGetData(uid, LockerVisuals.Open, out bool open, args.Component))
    {
        _sprite.LayerSetVisible((uid, args.Sprite), LockerVisualLayers.DoorOpen, open);
        _sprite.LayerSetVisible((uid, args.Sprite), LockerVisualLayers.DoorClosed, !open);
    }
}

Example 3: complex payload in appearance

[Serializable, NetSerializable]
public sealed class ShowLayerData
{
    public string Key = string.Empty;   // Target layer key.
    public bool Visible;                // Should I show the layer?
    public string? State;               // Optional RSI state.
}

private void PushLayerPayload(EntityUid uid, AppearanceComponent appearance, ShowLayerData data)
{
    // A complex payload is more convenient than a set of disparate Boolean flags.
    _appearance.SetData(uid, MapperVisuals.LayerData, data, appearance);
}

Example 4: Transferring visual data between entities

private void CopyAppearance(Entity<AppearanceComponent?> source, Entity<AppearanceComponent?> target)
{
    // Complete replacement of destination data.
    _appearance.CopyData(source, target);

    // Or merge mode (append) for partial enrichment.
    // _appearance.AppendData(source, target);
}

Example 5: GenericVisualizer YAML config (bool -> layer)

- type: GenericVisualizer
  visuals:
    enum.LockerVisuals.Open:
      enum.LockerVisualLayers.DoorOpen:
        "True":
          visible: true
      enum.LockerVisualLayers.DoorClosed:
        "True":
          visible: false
        "False":
          visible: true

Example 6: GenericVisualizer YAML config (enum value -> state/shader)

- type: GenericVisualizer
  visuals:
    enum.PowerVisuals.ChargeState:
      enum.PowerVisualLayers.Indicator:
        "Empty":
          state: empty
          shader: unshaded
        "Medium":
          state: medium
        "Full":
          state: full
          color: "#99ff99"

Example 7: when you need a custom visualizer instead of a GenericVisualizer

protected override void OnAppearanceChange(EntityUid uid, TriggerVisualsComponent component, ref AppearanceChangeEvent args)
{
    if (args.Sprite == null)
        return;

    if (!_appearance.TryGetData(uid, TriggerVisuals.Active, out bool active, args.Component))
        return;

    // This is no longer just mapping: it requires launching animation and additional functions. logics.
    _sprite.LayerSetRsiState((uid, args.Sprite), TriggerLayers.Core, active ? "active" : "idle");
    _animation.Play(uid, "pulse", active);
}

Patterns 🙂

Anti-patterns ❌

Checklist before change ✅

Common errors

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.