Skip to content

Commit

Permalink
#225 SIQuester: enhance tags and package info copy-paste operations
Browse files Browse the repository at this point in the history
New rounds are created with only counter as a name, no tail is added.
Also fix SIGame error.
  • Loading branch information
VladimirKhil committed May 18, 2024
1 parent a1a60bf commit 66f468c
Show file tree
Hide file tree
Showing 24 changed files with 441 additions and 162 deletions.
5 changes: 0 additions & 5 deletions src/Common/SIEngine/ISIEnginePlayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public interface ISIEnginePlayHandler
/// <param name="selectCallback">Selection callbacks.</param>
void AskForQuestionSelection(IReadOnlyCollection<(int, int)> options, Action<int, int> selectCallback);

/// <summary>
/// Cancels question selection request.
/// </summary>
void CancelQuestionSelection();

/// <summary>
/// Handles question selection.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public bool RemoveQuestion(int themeIndex, int questionIndex)

if (result && _stage == Stage.WaitSelection && !_questionsTable.Any())
{
_playHandler.CancelQuestionSelection();
_stage = Stage.RoundTable;
_endRoundCallback();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/SIPackages/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public Round CreateRound(string type, string? name)
{
var round = new Round
{
Name = name ?? $"{Rounds.Count + 1}{Resources.RoundTrailing}",
Name = name ?? (Rounds.Count + 1).ToString(),
Type = type
};

Expand Down
9 changes: 0 additions & 9 deletions src/Common/SIPackages/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Common/SIPackages/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@
<data name="Round" xml:space="preserve">
<value>Round</value>
</data>
<data name="RoundTrailing" xml:space="preserve">
<value> round</value>
</data>
<data name="Sources" xml:space="preserve">
<value>Sources</value>
</data>
Expand Down
3 changes: 0 additions & 3 deletions src/Common/SIPackages/Properties/Resources.ru-RU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@
<data name="Round" xml:space="preserve">
<value>Раунд</value>
</data>
<data name="RoundTrailing" xml:space="preserve">
<value>-й раунд</value>
</data>
<data name="Sources" xml:space="preserve">
<value>Источники</value>
</data>
Expand Down
89 changes: 5 additions & 84 deletions src/SICore/SICore/Clients/Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,12 +1459,12 @@ private void OnDisconnect(string[] args)
{
if (_logic.StopReason == StopReason.Pause || ClientData.TInfo.Pause)
{
_logic.AddHistory($"Managed game pause autoremoved.");
OnPauseCore(false);
_logic.AddHistory("Managed game pause autoremoved");
_logic.OnPauseCore(false);
return;
}

_logic.AddHistory($"Managed game move autostarted.");
_logic.AddHistory("Managed game move autostarted");

ClientData.MoveDirection = MoveDirections.Next;
_logic.Stop(StopReason.Move);
Expand Down Expand Up @@ -1851,7 +1851,7 @@ private void OnMove(Message message, string[] args)
// Resume paused game
if (ClientData.TInfo.Pause)
{
OnPauseCore(false);
_logic.OnPauseCore(false);
return;
}

Expand Down Expand Up @@ -1914,86 +1914,7 @@ private void OnPause(Message message, string[] args)
return;
}

OnPauseCore(args[1] == "+");
}

private void OnPauseCore(bool isPauseEnabled)
{
// Game host or showman requested a game pause

if (isPauseEnabled)
{
if (ClientData.TInfo.Pause)
{
return;
}

if (_logic.Stop(StopReason.Pause))
{
ClientData.TInfo.Pause = true;
Logic.AddHistory("Pause activated");
}

return;
}

if (_logic.StopReason == StopReason.Pause)
{
// We are currently moving into pause mode. Resuming
ClientData.TInfo.Pause = false;
_logic.AddHistory("Immediate pause resume");
_logic.CancelStop();
return;
}

if (!ClientData.TInfo.Pause)
{
return;
}

ClientData.TInfo.Pause = false;

var pauseDuration = DateTime.UtcNow.Subtract(ClientData.PauseStartTime);

var times = new int[Constants.TimersCount];

for (var i = 0; i < Constants.TimersCount; i++)
{
times[i] = (int)(ClientData.PauseStartTime.Subtract(ClientData.TimerStartTime[i]).TotalMilliseconds / 100);
ClientData.TimerStartTime[i] = ClientData.TimerStartTime[i].Add(pauseDuration);
}

if (ClientData.IsPlayingMediaPaused)
{
ClientData.IsPlayingMediaPaused = false;
ClientData.IsPlayingMedia = true;
}

if (ClientData.IsThinkingPaused)
{
ClientData.IsThinkingPaused = false;
ClientData.IsThinking = true;
}

_logic.AddHistory($"Pause resumed ({_logic.Runner.PrintOldTasks()} {_logic.StopReason})");

try
{
var maxPressingTime = ClientData.Settings.AppSettings.TimeSettings.TimeForThinkingOnQuestion * 10;
times[1] = maxPressingTime - _logic.ResumeExecution();
}
catch (Exception exc)
{
throw new Exception($"Resume execution error: {_logic.PrintHistory()}", exc);
}

if (_logic.StopReason == StopReason.Decision)
{
_logic.ExecuteImmediate(); // Decision could be ready
}

_gameActions.SpecialReplic(LO[nameof(R.GameResumed)]);
_gameActions.SendMessageWithArgs(Messages.Pause, isPauseEnabled ? '+' : '-', times[0], times[1], times[2]);
_logic.OnPauseCore(args[1] == "+");
}

private void OnAtom()
Expand Down
86 changes: 85 additions & 1 deletion src/SICore/SICore/Clients/Game/GameLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,12 @@ private void FinishRound(bool move = true)

if (move)
{
ScheduleExecution(Tasks.MoveNext, 40);
PlanExecution(Tasks.MoveNext, 40);

if (ClientData.TInfo.Pause)
{
OnPauseCore(false);
}
}
else
{
Expand All @@ -744,6 +749,85 @@ private void FinishRound(bool move = true)
}
}

internal void OnPauseCore(bool isPauseEnabled)
{
// Game host or showman requested a game pause

if (isPauseEnabled)
{
if (ClientData.TInfo.Pause)
{
return;
}

if (Stop(StopReason.Pause))
{
ClientData.TInfo.Pause = true;
AddHistory("Pause activated");
}

return;
}

if (StopReason == StopReason.Pause)
{
// We are currently moving into pause mode. Resuming
ClientData.TInfo.Pause = false;
AddHistory("Immediate pause resume");
CancelStop();
return;
}

if (!ClientData.TInfo.Pause)
{
return;
}

ClientData.TInfo.Pause = false;

var pauseDuration = DateTime.UtcNow.Subtract(ClientData.PauseStartTime);

var times = new int[Constants.TimersCount];

for (var i = 0; i < Constants.TimersCount; i++)
{
times[i] = (int)(ClientData.PauseStartTime.Subtract(ClientData.TimerStartTime[i]).TotalMilliseconds / 100);
ClientData.TimerStartTime[i] = ClientData.TimerStartTime[i].Add(pauseDuration);
}

if (ClientData.IsPlayingMediaPaused)
{
ClientData.IsPlayingMediaPaused = false;
ClientData.IsPlayingMedia = true;
}

if (ClientData.IsThinkingPaused)
{
ClientData.IsThinkingPaused = false;
ClientData.IsThinking = true;
}

AddHistory($"Pause resumed ({Runner.PrintOldTasks()} {StopReason})");

try
{
var maxPressingTime = ClientData.Settings.AppSettings.TimeSettings.TimeForThinkingOnQuestion * 10;
times[1] = maxPressingTime - ResumeExecution();
}
catch (Exception exc)
{
throw new Exception($"Resume execution error: {PrintHistory()}", exc);
}

if (StopReason == StopReason.Decision)
{
ExecuteImmediate(); // Decision could be ready
}

_gameActions.SpecialReplic(LO[nameof(R.GameResumed)]);
_gameActions.SendMessageWithArgs(Messages.Pause, isPauseEnabled ? '+' : '-', times[0], times[1], times[2]);
}

private void Engine_RoundEmpty()
{
_gameActions.ShowmanReplic(GetRandomString(LO[nameof(R.AllQuestions)]));
Expand Down
6 changes: 0 additions & 6 deletions src/SICore/SICore/Clients/Game/PlayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ public void AskForQuestionSelection(IReadOnlyCollection<(int, int)> options, Act
GameLogic?.ScheduleExecution(Tasks.AskToChoose, 20);
}

public void CancelQuestionSelection()
{
GameLogic?.ClearContinuation();
GameLogic?.PlanExecution(Tasks.MoveNext, 1);
}

public void OnQuestionSelected(int themeIndex, int questionIndex) => GameLogic?.OnQuestionSelected(themeIndex, questionIndex);

public void OnFinalThemes(IReadOnlyList<Theme> themes, bool willPlayAllThemes, bool isFirstPlay)
Expand Down
Loading

0 comments on commit 66f468c

Please sign in to comment.