Skip to content

Commit

Permalink
Simplify remote play logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz committed Feb 26, 2023
1 parent 46da31e commit c6e078f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
25 changes: 7 additions & 18 deletions app/appClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CardsRender from "../render/cardsRender.js";
import HiddenCardsRender from "../render/hiddenCardsRender.js";
import ControllableCardsRender from "../render/controllableCardsRender.js";
import RemoteControl from "../controller/remoteControl.js";
import {ROBOT_SIDE_LEFT, ROBOT_SIDE_RIGHT} from "../game/robot.js";
import {ROBOT_SIDE_RIGHT} from "../game/robot.js";

export default class AppClient {
/**
Expand Down Expand Up @@ -96,27 +96,16 @@ export default class AppClient {
clear(this.root)
this.timer.clear()

const leftCardsRender = this._createCardsRender(ROBOT_SIDE_LEFT, gameStartedPayload.leftRemoteControl, gameStartedPayload.rightRemoteControl)
const rightCardsRender = this._createCardsRender(ROBOT_SIDE_RIGHT, gameStartedPayload.rightRemoteControl, gameStartedPayload.leftRemoteControl)

new GameRender(
this.root,
this.eventManager,
leftCardsRender,
rightCardsRender,
gameStartedPayload.gameType === "against_remote_friend"
? new HiddenCardsRender()
: new CardsRender(),
gameStartedPayload.gameType === "against_remote_friend"
? new ControllableCardsRender(new RemoteControl(ROBOT_SIDE_RIGHT, this.serverConnection))
: new CardsRender(),
gameStartedPayload.tickTimeout,
)
}

_createCardsRender(side, thisRemoteControl, otherRemoteControl) {
if (!thisRemoteControl && !otherRemoteControl) {
return new CardsRender()
}

if (thisRemoteControl) {
return new ControllableCardsRender(new RemoteControl(side, this.serverConnection))
}

return new HiddenCardsRender()
}
}
6 changes: 0 additions & 6 deletions app/appServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default class AppServer {
return {
leftCardsRender: new ControllableCardsRender(new DirectControl(game.leftRobot)),
rightCardsRender: new HiddenCardsRender(),
remoteControllable: [],
}
}

Expand Down Expand Up @@ -130,7 +129,6 @@ export default class AppServer {
return {
leftCardsRender: new HiddenCardsRender(),
rightCardsRender: new HiddenCardsRender(),
remoteControllable: [],
}
}

Expand Down Expand Up @@ -184,7 +182,6 @@ export default class AppServer {
return {
leftCardsRender: new ControllableCardsRender(new DirectControl(game.leftRobot)),
rightCardsRender: new HiddenCardsRender(),
remoteControllable: [ROBOT_SIDE_RIGHT],
}
}

Expand All @@ -211,7 +208,6 @@ export default class AppServer {
return {
leftCardsRender: new CardsRender(),
rightCardsRender: new CardsRender(),
remoteControllable: [],
}
}

Expand Down Expand Up @@ -243,8 +239,6 @@ export default class AppServer {
const gameStartedPayload = {
tickTimeout: this.tickInterval,
gameType: this.gameType,
leftRemoteControl: gameSetup.remoteControllable.indexOf(ROBOT_SIDE_LEFT) > -1,
rightRemoteControl: gameSetup.remoteControllable.indexOf(ROBOT_SIDE_RIGHT) > -1,
};
eventManager.publish("gameStarted", gameStartedPayload)
this.onRemoteReady = ({connection}) => {
Expand Down

0 comments on commit c6e078f

Please sign in to comment.