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

Fix atom name/desc not copying on appearance set #2145

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Content.IntegrationTests/DMProject/Tests/atom_appearance.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/obj/thingtocopy
name = "hello"
desc = "this is a thing"

/proc/test_appearance()
var/obj/thingtocopy/T = new()
var/obj/otherthing = new()
otherthing.appearance = T.appearance
ASSERT(otherthing.name == T.name)
ASSERT(otherthing.desc == T.desc)
1 change: 1 addition & 0 deletions Content.IntegrationTests/DMProject/code.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
test_color_matrix()
test_range()
test_verb_duplicate()
test_appearance()
test_filter_init()
world.log << "IntegrationTests successful, /world/New() exiting..."
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private void Update() {
// Would be nice if we could use ViewVariables instead, but I couldn't find a nice way to do that
// Would be especially nice if we could use VV to make these editable
AddPropertyIfNotDefault("Name", appearance.Name, IconAppearance.Default.Name);
AddPropertyIfNotDefault("Desc", appearance.Desc, IconAppearance.Default.Desc);
AddPropertyIfNotDefault("Icon State", appearance.IconState, IconAppearance.Default.IconState);
AddPropertyIfNotDefault("Direction", appearance.Direction, IconAppearance.Default.Direction);
AddPropertyIfNotDefault("Inherits Direction", appearance.InheritsDirection, IconAppearance.Default.InheritsDirection);
Expand Down
11 changes: 11 additions & 0 deletions OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public void DeleteMovableEntity(DreamObjectMovable movable) {
public bool IsValidAppearanceVar(string name) {
switch (name) {
case "name":
case "desc":
case "icon":
case "icon_state":
case "dir":
Expand Down Expand Up @@ -248,6 +249,10 @@ public void SetAppearanceVar(IconAppearance appearance, string varName, DreamVal
value.TryGetValueAsString(out var name);
appearance.Name = name ?? string.Empty;
break;
case "desc":
value.TryGetValueAsString(out var desc);
appearance.Desc = desc;
break;
case "icon":
if (_resourceManager.TryLoadIcon(value, out var icon)) {
appearance.Icon = icon.Id;
Expand Down Expand Up @@ -387,6 +392,10 @@ public DreamValue GetAppearanceVar(IconAppearance appearance, string varName) {
switch (varName) {
case "name":
return new(appearance.Name);
case "desc":
if (appearance.Desc == null)
return DreamValue.Null;
return new(appearance.Desc);
case "icon":
if (appearance.Icon == null)
return DreamValue.Null;
Expand Down Expand Up @@ -589,6 +598,7 @@ public IconAppearance GetAppearanceFromDefinition(DreamObjectDefinition def) {
return appearance;

def.TryGetVariable("name", out var nameVar);
def.TryGetVariable("desc", out var descVar);
def.TryGetVariable("icon", out var iconVar);
def.TryGetVariable("icon_state", out var stateVar);
def.TryGetVariable("color", out var colorVar);
Expand All @@ -609,6 +619,7 @@ public IconAppearance GetAppearanceFromDefinition(DreamObjectDefinition def) {

appearance = new IconAppearance();
SetAppearanceVar(appearance, "name", nameVar);
SetAppearanceVar(appearance, "desc", descVar);
SetAppearanceVar(appearance, "icon", iconVar);
SetAppearanceVar(appearance, "icon_state", stateVar);
SetAppearanceVar(appearance, "color", colorVar);
Expand Down
28 changes: 7 additions & 21 deletions OpenDreamRuntime/Objects/Types/DreamObjectAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace OpenDreamRuntime.Objects.Types;

[Virtual]
public class DreamObjectAtom : DreamObject {
public string? Name;
public string? Desc;
public readonly DreamOverlaysList Overlays;
public readonly DreamOverlaysList Underlays;
public readonly DreamVisContentsList VisContents;
Expand All @@ -22,11 +20,6 @@ public DreamObjectAtom(DreamObjectDefinition objectDefinition) : base(objectDefi
AtomManager.AddAtom(this);
}

public override void Initialize(DreamProcArguments args) {
ObjectDefinition.Variables["name"].TryGetValueAsString(out Name);
ObjectDefinition.Variables["desc"].TryGetValueAsString(out Desc);
}

protected override void HandleDeletion(bool possiblyThreaded) {
// SAFETY: RemoveAtom is not threadsafe.
if (possiblyThreaded) {
Expand All @@ -39,6 +32,13 @@ protected override void HandleDeletion(bool possiblyThreaded) {
base.HandleDeletion(possiblyThreaded);
}

public string GetRTEntityDesc() {
if (!TryGetVariable("desc", out DreamValue descVar) || !descVar.TryGetValueAsString(out string? desc))
return ObjectDefinition.Type;

return desc;
}

protected override bool TryGetVar(string varName, out DreamValue value) {
switch (varName) {
// x/y/z/loc should be overriden by subtypes
Expand All @@ -50,13 +50,6 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
case "loc":
value = DreamValue.Null;
return true;

case "name":
value = (Name != null) ? new(Name) : DreamValue.Null;
return true;
case "desc":
value = (Desc != null) ? new(Desc) : DreamValue.Null;
return true;
case "appearance":
var appearanceCopy = new IconAppearance(AtomManager.MustGetAppearance(this)!);

Expand Down Expand Up @@ -102,13 +95,6 @@ protected override void SetVar(string varName, DreamValue value) {
case "z":
case "loc":
break;

case "name":
value.TryGetValueAsString(out Name);
break;
case "desc":
value.TryGetValueAsString(out Desc);
break;
case "appearance":
if (!AtomManager.TryCreateAppearanceFrom(value, out var newAppearance))
return; // Ignore attempts to set an invalid appearance
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Objects/Types/DreamObjectMovable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void Initialize(DreamProcArguments args) {

if (EntityManager.TryGetComponent(Entity, out MetaDataComponent? metaData)) {
MetaDataSystem?.SetEntityName(Entity, GetDisplayName(), metaData);
MetaDataSystem?.SetEntityDescription(Entity, Desc ?? string.Empty, metaData);
MetaDataSystem?.SetEntityDescription(Entity, GetRTEntityDesc(), metaData);
}

args.GetArgument(0).TryGetValueAsDreamObject<DreamObjectAtom>(out var loc);
Expand Down
4 changes: 4 additions & 0 deletions OpenDreamShared/Dream/IconAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed class IconAppearance : IEquatable<IconAppearance> {
public static readonly IconAppearance Default = new();

[ViewVariables] public string Name = string.Empty;
[ViewVariables] public string? Desc = string.Empty;
[ViewVariables] public int? Icon;
[ViewVariables] public string? IconState;
[ViewVariables] public AtomDirection Direction = AtomDirection.South;
Expand Down Expand Up @@ -82,6 +83,7 @@ public IconAppearance() {

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

if (appearance.Name != Name) return false;
if (appearance.Desc != Desc) return false;
if (appearance.Icon != Icon) return false;
if (appearance.IconState != IconState) return false;
if (appearance.Direction != Direction) return false;
Expand Down Expand Up @@ -207,6 +210,7 @@ public override int GetHashCode() {
HashCode hashCode = new HashCode();

hashCode.Add(Name);
hashCode.Add(Desc);
Dismissed Show dismissed Hide dismissed
hashCode.Add(Icon);
hashCode.Add(IconState);
hashCode.Add(Direction);
Expand Down
9 changes: 9 additions & 0 deletions OpenDreamShared/Network/Messages/MsgAllAppearances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public sealed class MsgAllAppearances(Dictionary<int, IconAppearance> allAppeara

private enum Property : byte {
Name,
Desc,
Icon,
IconState,
Direction,
Expand Down Expand Up @@ -66,6 +67,9 @@ public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer
case Property.Name:
appearance.Name = buffer.ReadString();
break;
case Property.Desc:
appearance.Desc = buffer.ReadString();
break;
case Property.Id:
appearanceId = buffer.ReadVariableInt32();
break;
Expand Down Expand Up @@ -230,6 +234,11 @@ public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer
buffer.Write(appearance.Name);
}

if (appearance.Desc != IconAppearance.Default.Desc) {
buffer.Write((byte)Property.Desc);
buffer.Write(appearance.Desc);
}

if (appearance.Icon != null) {
buffer.Write((byte)Property.Icon);
buffer.WriteVariableInt32(appearance.Icon.Value);
Expand Down
Loading