Skip to content
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
4 changes: 4 additions & 0 deletions Content.Tests/DMProject/Tests/Stdlib/List/remove.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
L = list(1,2,3,2,1)
L.Remove(list(2))
ASSERT(L ~= list(1,2,3,1))

L = list(1,2,3,2,1)
L.Remove(L)
ASSERT(L ~= list())
4 changes: 4 additions & 0 deletions OpenDreamClient/ClientVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ private void OnUpdateClientVerbsEvent(UpdateClientVerbsEvent e) {
_interfaceManager.DefaultInfo?.RefreshVerbs(this);
}

public void RefreshVerbs() {
_interfaceManager.DefaultInfo?.RefreshVerbs(this);
}

private void OnLocalPlayerAttached(EntityUid obj) {
// Our mob changed, update our verb panels
// A little hacky, but also wait half a second for verb information about our mob to arrive
Expand Down
18 changes: 18 additions & 0 deletions OpenDreamClient/Rendering/ClientAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using Robust.Client.Player;
using Robust.Shared.Map;
using Robust.Shared.Timing;
using Robust.Shared.Asynchronous;
using System.Threading;
using System.Threading.Tasks;

namespace OpenDreamClient.Rendering;

Expand Down Expand Up @@ -56,6 +59,7 @@ public int GetAnimationFrame(IGameTiming gameTiming) {
private readonly Dictionary<(int X, int Y, int Z), Flick> _turfFlicks = new();
private readonly Dictionary<EntityUid, Flick> _movableFlicks = new();
private bool _receivedAllAppearancesMsg;
private readonly float _timeToRefreshVerbs = 3f;

[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IDreamResourceManager _dreamResourceManager = default!;
Expand All @@ -68,6 +72,8 @@ public int GetAnimationFrame(IGameTiming gameTiming) {
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly ClientVerbSystem _verbSystem = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;

public override void Initialize() {
UpdatesOutsidePrediction = true;
Expand All @@ -77,6 +83,8 @@ public override void Initialize() {
SubscribeNetworkEvent<AnimationEvent>(OnAnimation);
SubscribeNetworkEvent<FlickEvent>(OnFlick);
SubscribeLocalEvent<DMISpriteComponent, WorldAABBEvent>(OnWorldAABB);

_ = StartVerbRefresher(new());
}

public override void Shutdown() {
Expand Down Expand Up @@ -363,4 +371,14 @@ public string GetName(ClientObjectReference reference) {
public Flick? GetMovableFlick(EntityUid entity) {
return _movableFlicks.GetValueOrDefault(entity);
}

private async Task StartVerbRefresher(CancellationTokenSource cancelSource) {
while (true) {
await Task.Delay(TimeSpan.FromSeconds(_timeToRefreshVerbs));
if (cancelSource.IsCancellationRequested)
break;

_taskManager.RunOnMainThread(_verbSystem.RefreshVerbs);
}
}
}
59 changes: 59 additions & 0 deletions OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,21 @@ public override IEnumerable<DreamValue> EnumerateValues() {
yield return new(verb);
}

public override bool ContainsKey(DreamValue value) {
if (!value.TryGetValueAsInteger(out var index)) {
return false;
}

return 1 <= index && index <= Verbs.Count;
}

public override bool ContainsValue(DreamValue value) {
if (!value.TryGetValueAsProc(out var verb))
return false;

return Verbs.Contains(verb);
}

public override void SetValue(DreamValue key, DreamValue value, bool allowGrowth = false) {
throw new Exception("Cannot set the values of a verbs list");
}
Expand All @@ -667,6 +682,18 @@ public override void AddValue(DreamValue value) {
_verbSystem?.UpdateClientVerbs(_client);
}

public override void RemoveValue(DreamValue value) {
if (!value.TryGetValueAsProc(out var verb))
return;

var valueIndex = Verbs.LastIndexOf(verb);

if (valueIndex != -1) {
Verbs.RemoveAt(valueIndex);
_verbSystem?.UpdateClientVerbs(_client);
}
}

public override void Cut(int start = 1, int end = 0) {
int verbCount = Verbs.Count + 1;
if (end == 0 || end > verbCount) end = verbCount;
Expand Down Expand Up @@ -716,6 +743,23 @@ public override IEnumerable<DreamValue> EnumerateValues() {
}
}

public override bool ContainsKey(DreamValue value) {
if (!value.TryGetValueAsInteger(out var index)) {
return false;
}

return 1 <= index && index <= GetVerbs().Length;
}

public override bool ContainsValue(DreamValue value) {
if (!value.TryGetValueAsProc(out var verb))
return false;
if (verb.VerbId == null)
return false;

return GetVerbs().Contains(verb.VerbId.Value);
}

public override void SetValue(DreamValue key, DreamValue value, bool allowGrowth = false) {
throw new Exception("Cannot set the values of a verbs list");
}
Expand All @@ -734,6 +778,21 @@ public override void AddValue(DreamValue value) {
});
}

public override void RemoveValue(DreamValue value) {
if (!value.TryGetValueAsProc(out var verb))
return;
if (verb.VerbId == null) {
return;
}

atomManager.UpdateAppearance(atom, appearance => {
var valueIndex = appearance.Verbs.LastIndexOf(verb.VerbId.Value);

if (valueIndex != -1)
appearance.Verbs.RemoveAt(valueIndex);
});
}

public override void Cut(int start = 1, int end = 0) {
atomManager.UpdateAppearance(atom, appearance => {
int count = appearance.Verbs.Count + 1;
Expand Down
9 changes: 7 additions & 2 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Linq;
using System.Text;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Objects.Types;
using DreamValueTypeFlag = OpenDreamRuntime.DreamValue.DreamValueTypeFlag;
Expand Down Expand Up @@ -150,7 +151,11 @@ private static int ListRemove(IDreamList list, ReadOnlySpan<DreamValue> args) {
var itemRemoved = 0;
foreach (var argument in args) {
if (argument.TryGetValueAsDreamList(out var argumentList)) {
foreach (DreamValue value in argumentList.EnumerateValues()) {
// In case this is a "listx.Remove(listx)" situation, copy the contents here to avoid modification while enumerating
// TODO: check for that case first to avoid unnecessary copy?
var subtraction = argumentList.EnumerateValues().ToList();

foreach (DreamValue value in subtraction) {
if (list.ContainsValue(value)) {
list.RemoveValue(value);

Expand Down
Loading