Skip to content

Commit

Permalink
Implement atom.appearance.overlays (#2104)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Nov 21, 2024
1 parent 1c09fb0 commit 1f067c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
38 changes: 31 additions & 7 deletions OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ public bool IsValidAppearanceVar(string name) {
case "transform":
case "appearance":
case "verbs":
return true;

// Get/SetAppearanceVar doesn't handle these
case "overlays":
case "underlays":
return true;

// Get/SetAppearanceVar doesn't handle filters right now
case "filters":
default:
return false;
Expand Down Expand Up @@ -370,8 +370,14 @@ public void SetAppearanceVar(IconAppearance appearance, string varName, DreamVal
break;
case "appearance":
throw new Exception("Cannot assign the appearance var on an appearance");
// TODO: overlays, underlays, filters
// Those are handled separately by whatever is calling SetAppearanceVar currently

// These should be handled by the DreamObject if being accessed through that
case "overlays":
case "underlays":
throw new Exception($"Cannot assign the {varName} var on an appearance");

// TODO: filters
// It's handled separately by whatever is calling SetAppearanceVar currently
default:
throw new ArgumentException($"Invalid appearance var {varName}");
}
Expand Down Expand Up @@ -452,8 +458,26 @@ public DreamValue GetAppearanceVar(IconAppearance appearance, string varName) {
case "appearance":
IconAppearance appearanceCopy = new IconAppearance(appearance); // Return a copy
return new(appearanceCopy);
// TODO: overlays, underlays, filters
// Those are handled separately by whatever is calling GetAppearanceVar currently

// These should be handled by an atom if referenced through one
case "overlays":
case "underlays":
// In BYOND this just creates a new normal list
var lays = varName == "overlays" ? appearance.Overlays : appearance.Underlays;
var list = _objectTree.CreateList(lays.Count);

if (_appearanceSystem != null) {
foreach (var layId in lays) {
var lay = _appearanceSystem.MustGetAppearance(layId);

list.AddValue(new(lay));
}
}

return new(list);

// TODO: filters
// It's handled separately by whatever is calling GetAppearanceVar currently
default:
throw new ArgumentException($"Invalid appearance var {varName}");
}
Expand Down
22 changes: 8 additions & 14 deletions OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,27 +1254,21 @@ public override int GetLength() {
}

// proc args list
sealed class ProcArgsList : DreamList {
private readonly DMProcState _state;

public ProcArgsList(DreamObjectDefinition listDef, DMProcState state) : base(listDef, 0) {
_state = state;
}

internal sealed class ProcArgsList(DreamObjectDefinition listDef, DMProcState state) : DreamList(listDef, 0) {
public override DreamValue GetValue(DreamValue key) {
if (!key.TryGetValueAsInteger(out var index))
throw new Exception($"Invalid index into args list: {key}");
if (index < 1 || index > _state.ArgumentCount)
if (index < 1 || index > state.ArgumentCount)
throw new Exception($"Out of bounds index on args list: {index}");

return _state.GetArguments()[index - 1];
return state.GetArguments()[index - 1];
}

// TODO: This would preferably be an IEnumerable<> method. Probably as part of #985.
public override List<DreamValue> GetValues() {
List<DreamValue> values = new(_state.ArgumentCount);
List<DreamValue> values = new(state.ArgumentCount);

foreach (DreamValue value in _state.GetArguments()) {
foreach (DreamValue value in state.GetArguments()) {
values.Add(value);
}

Expand All @@ -1284,10 +1278,10 @@ public override List<DreamValue> GetValues() {
public override void SetValue(DreamValue key, DreamValue value, bool allowGrowth = false) {
if (!key.TryGetValueAsInteger(out var index))
throw new Exception($"Invalid index into args list: {key}");
if (index < 1 || index > _state.ArgumentCount)
if (index < 1 || index > state.ArgumentCount)
throw new Exception($"Out of bounds index on args list: {index}");

_state.SetArgument(index - 1, value);
state.SetArgument(index - 1, value);
}

public override void AddValue(DreamValue value) {
Expand All @@ -1303,7 +1297,7 @@ public override void Cut(int start = 1, int end = 0) {
}

public override int GetLength() {
return _state.ArgumentCount;
return state.ArgumentCount;
}
}

Expand Down

0 comments on commit 1f067c8

Please sign in to comment.