-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stuck repeating commands (#1468)
- Loading branch information
Showing
1 changed file
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |