Skip to content

Commit

Permalink
Premoves kind of work???
Browse files Browse the repository at this point in the history
renamed some server files too
  • Loading branch information
berg44 committed Sep 7, 2023
1 parent 32a92a6 commit 6d42d00
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 22 deletions.
4 changes: 2 additions & 2 deletions soos-client/src/components/town/Town.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Town = (props: TownProps) => {
let townSize = 10, points:string = "";

let svg = null;
switch (gameTown.townLevel) {
switch (gameTown.townLevel + (premove?1:0)) {
case 0:
case 1:
townSize = settlementSize;
Expand Down Expand Up @@ -85,7 +85,7 @@ export const Town = (props: TownProps) => {
// </svg >
// );

svg = makeTownSVG(townSize,points,playerColor,highlighted);
svg = makeTownSVG(townSize,points,playerColor,highlighted||premove);

const { x, y } = vertexCoordsToPixels(gameTown.coords!);

Expand Down
14 changes: 8 additions & 6 deletions soos-client/src/features/gameView/GameView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export const GameView = (props: GameViewProps) => {
socket.emit('playerId', receivePlayerId);

socket.on('updateGameState', updateGameState);
socket.on('premoves', setPremoves);
socket.on('setPremoves', setPremoves);

return () => {
// socket.off("playerId", receivePlayerId);
socket.off('updateGameState', updateGameState);
socket.off('premoves', setPremoves);
socket.off('setPremoves', setPremoves);
};
}, []);

Expand All @@ -105,8 +105,9 @@ export const GameView = (props: GameViewProps) => {
resources={game.players[playerId].cards}
closeWindowHandler={() => setIsTradeWindowShowing(false)}
executeTradeHandler={(tradeIn: number, tradeFor: number) => {
game.executeTrade(tradeIn, tradeFor, playerId);
game.forceUpdate();
//game.executeTrade(tradeIn, tradeFor, playerId);
//game.forceUpdate();
socket.emit('trade',tradeIn,tradeFor);
}}
/>,
);
Expand Down Expand Up @@ -166,8 +167,9 @@ export const GameView = (props: GameViewProps) => {

<button
onClick={() => {
game.nextPlayer();
sendGameStateToServer();
//game.nextPlayer();
//sendGameStateToServer();
socket.emit('nextTurn');
}}
className="NextTurnButton"
disabled={game.gamePhase !== GamePhase.MainGameplay}
Expand Down
16 changes: 12 additions & 4 deletions soos-client/src/features/gameView/components/board/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ export const Board = (props: BoardProps) => {

let roadBuildActions = possibleBuildActions.filter(pba => pba.type === BuildActionType.Road);

if ((game.gamePhase === GamePhase.PlaceSettlement1 || game.gamePhase === GamePhase.PlaceSettlement2)
if (playerId!==undefined && ((game.gamePhase === GamePhase.PlaceSettlement1 || game.gamePhase === GamePhase.PlaceSettlement2)
&& game.currPlayerIdx === playerId
&& game.claimedSettlement) {
&& game.claimedSettlement) || makingPremoves) {
// custom roadBuildActions for setup phase
roadBuildActions = game.getValidBuildActions(playerId, BuildActionType.Road);
}
for (const premoveAction of premoves){
if(premoveAction.type===BuildActionType.Road)
roadBuildActions.push(premoveAction);
}

const roads = [];
for (const road of game.map.roads) {
Expand All @@ -106,10 +110,14 @@ export const Board = (props: BoardProps) => {
<Road
gameRoad={road}
highlighted={!!buildAction}
premove={makingPremoves && road.playerIdx === playerId}
premove={false && makingPremoves && road.playerIdx === playerId}
onClick={() => {
if (buildAction) {
socket.emit('build', buildAction);
if(makingPremoves){
socket.emit('premove', buildAction);
} else {
socket.emit('build', buildAction);
}
}
}}
key={`r:${roadCoords.hexCoords.x},${roadCoords.hexCoords.y},${roadCoords.direction}`}
Expand Down
5 changes: 4 additions & 1 deletion soos-gamelogic/src/game-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ export default class GameMap {
return;
}
visitedVertices[vertexCoords.toString()] = true;

const vertTown = this.townAt(vertexCoords);
if(vertTown && !vertTown.isUnclaimed() &&vertTown.playerIdx && vertTown.playerIdx!== playerIdx){
return; // can't build past opponents towns!
}
const egressRoads = this.getRoads(vertexCoords);
for (const road of egressRoads) {
// off edge of map
Expand Down
1 change: 0 additions & 1 deletion soos-gamelogic/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ export default class Game {

actionViable(action: BuildActionType): boolean {
//negative cost indicates any one resource less than requirement is an option
//TODO: implement ports eventually...
let defaultReturnValue = true;
for (const resource of AllResourceTypes) {

Expand Down
6 changes: 3 additions & 3 deletions soos-server/src/routes/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import express from 'express';

import { userApiRouter } from './user.js';
import { socketApiRouter } from './socket.js';
import { gameApiRouter } from './game.js';
import { userApiRouter } from './serveruser.js';
import { socketApiRouter } from './serversocket.js';
import { gameApiRouter } from './servergame.js';

const router = express.Router();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions soos-server/src/routes/socket-io/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Socket, Server } from 'socket.io';
import { Game } from 'soos-gamelogic';
import ServerAction from '../../server-action.js';

import { registerGeneralSocketListeners } from './general.js';
import { registerLobbySocketListeners } from './lobby.js';
import { registerGameSocketListeners } from './game.js';
import { registerGeneralSocketListeners } from './servergeneral.js';
import { registerLobbySocketListeners } from './serverlobby.js';
import { registerGameSocketListeners } from './servergame.js';

export const registerSocketListeners = (
socket: Socket,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Socket, Server } from 'socket.io';

import { EdgeCoords, Game, gameFromString } from 'soos-gamelogic';
import { AllResourceTypes, EdgeCoords, Game, ResourceType, gameFromString } from 'soos-gamelogic';
import ServerAction from '../../server-action.js';
import { BuildAction, hydrateBuildAction } from 'soos-gamelogic/dist/src/build-actions.js';
import { gameManager, GameSlot } from '../../db/game-manager.js';
Expand Down Expand Up @@ -190,9 +190,29 @@ export const registerGameSocketListeners = (
}

saveGame(context);
socket.emit('premoves', gameMoves);
socket.emit('setPremoves', gameMoves);
});

socket.on('nextTurn', ()=>{
if (!context) {
return new Error();
}
if(true){//context.playerIndex===context.game.currPlayerIdx){
context.game.nextPlayer();
saveGame(context);
io.to(context.activeGamecode).emit('updateGameState', context.game.toString());
}
});

socket.on('trade', (offer:ResourceType, target:ResourceType)=>{
if (!context) {
return new Error();
}

context.game.executeTrade(offer,target,context.playerIndex);
saveGame(context);
io.to(context.activeGamecode).emit('updateGameState', context.game.toString());
});
/*This is never called, commenting out for now.
socket.on('logPremoves', () => {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 6d42d00

Please sign in to comment.