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 2 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.Tests/DMProject/Tests/Image/appearance.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/obj/thingtocopy
TobleroneSwordfish marked this conversation as resolved.
Show resolved Hide resolved
name = "hello"
desc = "this is a thing"

/proc/RunTest()
var/obj/thingtocopy/T = new()
var/obj/otherthing = new()
otherthing.appearance = T.appearance
ASSERT(otherthing.name == T.name)
ASSERT(otherthing.desc == T.desc)
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
9 changes: 9 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 ?? string.Empty;
TobleroneSwordfish marked this conversation as resolved.
Show resolved Hide resolved
break;
case "icon":
if (_resourceManager.TryLoadIcon(value, out var icon)) {
appearance.Icon = icon.Id;
Expand Down Expand Up @@ -387,6 +392,8 @@ public DreamValue GetAppearanceVar(IconAppearance appearance, string varName) {
switch (varName) {
case "name":
return new(appearance.Name);
case "desc":
return new(appearance.Desc);
case "icon":
if (appearance.Icon == null)
return DreamValue.Null;
Expand Down Expand Up @@ -589,6 +596,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 +617,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
27 changes: 6 additions & 21 deletions OpenDreamRuntime/Objects/Types/DreamObjectAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

[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 @@
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 @@ -38,6 +31,12 @@

base.HandleDeletion(possiblyThreaded);
}
public string GetDesc() {

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are missing elsewhere Warning

Blank lines are missing, expected minimum 1 instead of 0
TobleroneSwordfish marked this conversation as resolved.
Show resolved Hide resolved
if (!TryGetVariable("desc", out DreamValue descVar) || !descVar.TryGetValueAsString(out string? desc))
return ObjectDefinition.Type.ToString();

Check warning

Code scanning / InspectCode

Redundant 'object.ToString()' call Warning

Redundant 'Object.ToString()' call
TobleroneSwordfish marked this conversation as resolved.
Show resolved Hide resolved

return desc;
}

protected override bool TryGetVar(string varName, out DreamValue value) {
switch (varName) {
Expand All @@ -50,13 +49,6 @@
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 +94,6 @@
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, GetDesc(), 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 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(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 @@
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 @@
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