Skip to content

Commit

Permalink
Fix circular dependency, tidy up use of lookingAtOurLiveGame
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenAsJade committed Oct 18, 2023
1 parent c0f8b30 commit 931a15a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/components/NetworkStatus/NetworkStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as React from "react";
import * as preferences from "preferences";
import { _ } from "translate";
import { socket } from "sockets";
import { lookingAtOurLiveGame } from "TimeControl";
import { lookingAtOurLiveGame } from "TimeControl/util";

//interface NetworkStatusProps {}

Expand Down
55 changes: 23 additions & 32 deletions src/lib/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import Debug from "debug";
import { GobanSocket, protocol, Goban, JGOFTimeControl } from "goban";
import { lookingAtOurLiveGame } from "TimeControl";
import { lookingAtOurLiveGame } from "TimeControl/util";

const debug = new Debug("sockets");

Expand Down Expand Up @@ -97,39 +97,30 @@ socket.on("latency", (latency, drift) => {

// If they are playing a live game at the moment, work out what timing they would like
// us to make sure that they have...
if (
typeof window !== "undefined" &&
window["global_goban"] &&
window["global_goban"].engine &&
window["global_goban"].engine.phase === "play" &&
window["user"]
) {
if (lookingAtOurLiveGame()) {
const goban = window["global_goban"] as Goban;
const time_control = goban.engine.time_control as JGOFTimeControl;

if (lookingAtOurLiveGame()) {
switch (time_control.system) {
case "fischer":
timing_needed = time_control.time_increment || time_control.initial_time;
break;

case "byoyomi":
timing_needed = time_control.period_time || time_control.main_time;
break;

case "canadian":
timing_needed = time_control.period_time || time_control.main_time;
break;

case "simple":
timing_needed = time_control.per_move;
break;

case "absolute":
// actually, they'd like it as fast as possible, but this probably suffices
timing_needed = time_control.total_time;
break;
}
switch (time_control.system) {
case "fischer":
timing_needed = time_control.time_increment || time_control.initial_time;
break;

case "byoyomi":
timing_needed = time_control.period_time || time_control.main_time;
break;

case "canadian":
timing_needed = time_control.period_time || time_control.main_time;
break;

case "simple":
timing_needed = time_control.per_move;
break;

case "absolute":
// actually, they'd like it as fast as possible, but this probably suffices
timing_needed = time_control.total_time;
break;
}
} else {
timing_needed = 0;
Expand Down

0 comments on commit 931a15a

Please sign in to comment.