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 stuck repeating commands #1468

Merged
merged 1 commit into from
Sep 25, 2023
Merged
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
56 changes: 28 additions & 28 deletions OpenDreamRuntime/Input/DreamCommandSystem.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
using OpenDreamShared.Input;
using Robust.Server.Player;

namespace OpenDreamRuntime.Input {
sealed class DreamCommandSystem : SharedDreamCommandSystem {
[Dependency] private readonly DreamManager _dreamManager = default!;
namespace OpenDreamRuntime.Input;

private readonly List<(string Command, IPlayerSession session)> _repeatingCommands = new();
internal sealed class DreamCommandSystem : SharedDreamCommandSystem {
[Dependency] private readonly DreamManager _dreamManager = default!;

public override void Initialize() {
SubscribeNetworkEvent<CommandEvent>(OnCommandEvent);
SubscribeNetworkEvent<RepeatCommandEvent>(OnRepeatCommandEvent);
SubscribeNetworkEvent<StopRepeatCommandEvent>(OnStopRepeatCommandEvent);
}
private readonly HashSet<(string Command, IPlayerSession session)> _repeatingCommands = new();

public void RunRepeatingCommands() {
foreach (var (command, session) in _repeatingCommands) {
RunCommand(command, session);
}
}
public override void Initialize() {
SubscribeNetworkEvent<CommandEvent>(OnCommandEvent);
SubscribeNetworkEvent<RepeatCommandEvent>(OnRepeatCommandEvent);
SubscribeNetworkEvent<StopRepeatCommandEvent>(OnStopRepeatCommandEvent);
}

private void OnCommandEvent(CommandEvent e, EntitySessionEventArgs sessionEvent) {
RunCommand(e.Command, (IPlayerSession)sessionEvent.SenderSession);
public void RunRepeatingCommands() {
foreach (var (command, session) in _repeatingCommands) {
RunCommand(command, session);
}
}

private void OnRepeatCommandEvent(RepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);
private void OnCommandEvent(CommandEvent e, EntitySessionEventArgs sessionEvent) {
RunCommand(e.Command, (IPlayerSession)sessionEvent.SenderSession);
}

_repeatingCommands.Add(tuple);
}
private void OnRepeatCommandEvent(RepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);

private void OnStopRepeatCommandEvent(StopRepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);
_repeatingCommands.Add(tuple);
}

_repeatingCommands.Remove(tuple);
}
private void OnStopRepeatCommandEvent(StopRepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);

private void RunCommand(string command, IPlayerSession session) {
var connection = _dreamManager.GetConnectionBySession(session);
connection.HandleCommand(command);
}
_repeatingCommands.Remove(tuple);
}

private void RunCommand(string command, IPlayerSession session) {
var connection = _dreamManager.GetConnectionBySession(session);
connection.HandleCommand(command);
}
}