Skip to content

Commit

Permalink
Add Desc to ImmutableAppearance
Browse files Browse the repository at this point in the history
And fix an error in OnIconSizeChanged
  • Loading branch information
wixoaGit committed Jan 23, 2025
1 parent 89427c1 commit 6e62e3f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion OpenDreamClient/Rendering/DMISpriteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public override void Shutdown() {
}

private void OnIconSizeChanged(EntityUid uid) {
_entityManager.TryGetComponent<TransformComponent>(uid, out var transform);
if (!_entityManager.TryGetComponent<TransformComponent>(uid, out var transform))
return;

_lookupSystem.FindAndAddToEntityTree(uid, xform: transform);
}

Expand Down
19 changes: 16 additions & 3 deletions OpenDreamShared/Dream/ImmutableAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public sealed class ImmutableAppearance : IEquatable<ImmutableAppearance> {
private bool _needsFinalizer;
private int? _storedHashCode;
private readonly SharedAppearanceSystem? _appearanceSystem;

[ViewVariables] public readonly string Name = MutableAppearance.Default.Name;
[ViewVariables] public readonly string? Desc = MutableAppearance.Default.Desc;
[ViewVariables] public readonly int? Icon = MutableAppearance.Default.Icon;
[ViewVariables] public readonly string? IconState = MutableAppearance.Default.IconState;
[ViewVariables] public readonly AtomDirection Direction = MutableAppearance.Default.Direction;
Expand Down Expand Up @@ -76,6 +78,7 @@ public ImmutableAppearance(MutableAppearance appearance, SharedAppearanceSystem?
_appearanceSystem = serverAppearanceSystem;

Name = appearance.Name;
Desc = appearance.Desc;
Icon = appearance.Icon;
IconState = appearance.IconState;
Direction = appearance.Direction;
Expand Down Expand Up @@ -142,6 +145,7 @@ public bool Equals(ImmutableAppearance? immutableAppearance) {
if (immutableAppearance == null) return false;

if (immutableAppearance.Name != Name) return false;
if (immutableAppearance.Desc != Desc) return false;
if (immutableAppearance.Icon != Icon) return false;
if (immutableAppearance.IconState != IconState) return false;
if (immutableAppearance.Direction != Direction) return false;
Expand All @@ -150,9 +154,9 @@ public bool Equals(ImmutableAppearance? immutableAppearance) {
if (immutableAppearance.PixelOffset2 != PixelOffset2) return false;
if (immutableAppearance.Color != Color) return false;
if (immutableAppearance.Alpha != Alpha) return false;
if (immutableAppearance.GlideSize != GlideSize) return false;
if (!immutableAppearance.GlideSize.Equals(GlideSize)) return false;
if (!immutableAppearance.ColorMatrix.Equals(ColorMatrix)) return false;
if (immutableAppearance.Layer != Layer) return false;
if (!immutableAppearance.Layer.Equals(Layer)) return false;
if (immutableAppearance.Plane != Plane) return false;
if (immutableAppearance.RenderSource != RenderSource) return false;
if (immutableAppearance.RenderTarget != RenderTarget) return false;
Expand All @@ -171,7 +175,6 @@ public bool Equals(ImmutableAppearance? immutableAppearance) {
if (immutableAppearance.MaptextSize != MaptextSize) return false;
if (immutableAppearance.MaptextOffset != MaptextOffset) return false;


for (int i = 0; i < Filters.Length; i++) {
if (immutableAppearance.Filters[i] != Filters[i]) return false;
}
Expand Down Expand Up @@ -218,6 +221,7 @@ public override int GetHashCode() {
HashCode hashCode = new HashCode();

hashCode.Add(Name);
hashCode.Add(Desc);
hashCode.Add(Icon);
hashCode.Add(IconState);
hashCode.Add(Direction);
Expand Down Expand Up @@ -283,6 +287,9 @@ public ImmutableAppearance(NetIncomingMessage buffer, IRobustSerializer serializ
case IconAppearanceProperty.Name:
Name = buffer.ReadString();
break;
case IconAppearanceProperty.Desc:
Desc = buffer.ReadString();
break;
case IconAppearanceProperty.Id:
_registeredId = buffer.ReadVariableUInt32();
break;
Expand Down Expand Up @@ -448,6 +455,7 @@ public MutableAppearance ToMutable() {
MutableAppearance result = MutableAppearance.Get();

result.Name = Name;
result.Desc = Desc;
result.Icon = Icon;
result.IconState = IconState;
result.Direction = Direction;
Expand Down Expand Up @@ -496,6 +504,11 @@ public void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serialize
buffer.Write(Name);
}

if (Desc != MutableAppearance.Default.Desc) {
buffer.Write((byte)IconAppearanceProperty.Desc);
buffer.Write(Desc);
}

if (Icon != null) {
buffer.Write((byte)IconAppearanceProperty.Icon);
buffer.WriteVariableInt32(Icon.Value);
Expand Down
1 change: 1 addition & 0 deletions OpenDreamShared/Dream/MutableAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public enum AnimationFlags {
//used for encoding for netmessages
public enum IconAppearanceProperty : byte {
Name,
Desc,
Icon,
IconState,
Direction,
Expand Down
6 changes: 2 additions & 4 deletions OpenDreamShared/Network/Messages/MsgAllAppearances.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Lidgren.Network;
using OpenDreamShared.Dream;
using Robust.Shared.Network;
Expand All @@ -12,6 +9,7 @@ namespace OpenDreamShared.Network.Messages;
public sealed class MsgAllAppearances(Dictionary<uint, ImmutableAppearance> allAppearances) : NetMessage {
public override MsgGroups MsgGroup => MsgGroups.EntityEvent;
public Dictionary<uint, ImmutableAppearance> AllAppearances = allAppearances;

public MsgAllAppearances() : this(new()) { }

public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) {
Expand Down

0 comments on commit 6e62e3f

Please sign in to comment.