Skip to content

Commit

Permalink
Fixed your rotation being incorrect when you are black in an online game
Browse files Browse the repository at this point in the history
  • Loading branch information
Naviary2 committed Jan 9, 2025
1 parent 62b4b48 commit f9021f5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
27 changes: 17 additions & 10 deletions src/client/scripts/esm/game/chess/gameslot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
* It also has the loader and unloader methods for the gamefile.
*/


import type { MetaData } from "../../chess/util/metadata.js";
import type { ClockValues } from "../../chess/logic/clock.js";


// @ts-ignore
import gamefile from "../../chess/logic/gamefile.js";
// @ts-ignore
Expand Down Expand Up @@ -50,20 +55,14 @@ import clock from "../../chess/logic/clock.js";
import guigameinfo from "../gui/guigameinfo.js";
// @ts-ignore
import guipause from "../gui/guipause.js";
// @ts-ignore
import perspective from "../rendering/perspective.js";
import guinavigation from "../gui/guinavigation.js";
import guipromotion from "../gui/guipromotion.js";
import loadingscreen from "../gui/loadingscreen.js";
import spritesheet from "../rendering/spritesheet.js";


// Type Definitions ---------------------------------------------------------------


import type { MetaData } from "../../chess/util/metadata.js";
import type { ClockValues } from "../../chess/logic/clock.js";
import gameloader from "./gameloader.js";


// Variables ---------------------------------------------------------------


Expand Down Expand Up @@ -102,15 +101,20 @@ function getGamefile(): gamefile | undefined {
return loadedGamefile;
}

function areInGame() {
function areInGame(): boolean {
return loadedGamefile !== undefined;
}

/** Returns true if a new gamefile is currently being loaded */
function areWeLoading() {
function areWeLoading(): boolean {
return gameIsLoading;
}

/** Returns what color we are viewing the current loaded game by default. */
function getOurColor(): string {
return youAreColor;
}

function isLoadedGameViewingWhitePerspective() {
if (!loadedGamefile) throw Error("Cannot ask if loaded game is from white's perspective when there isn't a loaded game.");
return youAreColor === 'white';
Expand Down Expand Up @@ -189,6 +193,8 @@ async function loadGamefile(
startStartingTransition();
console.log('Finished loading');

perspective.resetRotations();

// Regenerate the mesh of all the pieces.
piecesmodel.regenModel(newGamefile, options.getPieceRegenColorArgs());

Expand Down Expand Up @@ -283,6 +289,7 @@ export default {
getGamefile,
areInGame,
areWeLoading,
getOurColor,
isLoadedGameViewingWhitePerspective,
loadGamefile,
unloadGame,
Expand Down
3 changes: 2 additions & 1 deletion src/client/scripts/esm/game/gui/guipause.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function toggle() {

function updatePasteButtonTransparency() {
const moves = gameslot.getGamefile().moves;
const legalInPrivateMatch = onlinegame.getIsPrivate() && moves.length === 0;

const legalInPrivateMatch = onlinegame.areInOnlineGame() && onlinegame.getIsPrivate() && moves.length === 0;

if (onlinegame.areInOnlineGame() && !legalInPrivateMatch) element_pastegame.classList.add('opacity-0_5');
else element_pastegame.classList.remove('opacity-0_5');
Expand Down
3 changes: 0 additions & 3 deletions src/client/scripts/esm/game/misc/onlinegame/onlinegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ function initOnlineGame(options: {
afk.onGameStart();

tabnameflash.onGameStart({ isOurMove: isItOurTurn() });

// These make sure it will place us in black's perspective
// perspective.resetRotations();

serverHasConcludedGame = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ interface DrawOfferInfo {
* This handles all messages related to the active game we're in.
* @param {WebsocketMessage} data - The incoming server websocket message
*/
function routeMessage(data: WebsocketMessage) { // { sub, action, value, id }
function routeMessage(data: WebsocketMessage): void { // { sub, action, value, id }
// console.log(`Received ${data.action} from server! Message contents:`)
// console.log(data.value)

// This action is listened to, even when we're not in a game.

if (data.action === 'joingame') handleJoinGame(data.value);
if (data.action === 'joingame') return handleJoinGame(data.value);

// All other actions should be ignored if we're not in a game...

if (!onlinegame.areInOnlineGame()) {
console.log(`Received server 'game' message when we're not in an online game. Ignoring. Message: ${JSON.stringify(data.value)}`);
console.log(`Received server 'game' message when we're not in an online game. Ignoring. Message: ${JSON.stringify(data)}`);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/scripts/esm/game/rendering/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function disable() {
// Sets rotations to orthographic view. Sensitive to if we're white or black.
function resetRotations() {
rotX = 0;
rotZ = onlinegame.getOurColor() === 'black' ? 180 : 0; // Will be undefined if not in online game
rotZ = gameslot.getOurColor() === 'black' ? 180 : 0; // Will be undefined if not in online game
console.log(rotZ);

updateIsViewingBlackPerspective();

Expand Down

0 comments on commit f9021f5

Please sign in to comment.