diff --git a/src/client/scripts/esm/game/chess/selection.js b/src/client/scripts/esm/game/chess/selection.js index a21b5052d..932b2d466 100644 --- a/src/client/scripts/esm/game/chess/selection.js +++ b/src/client/scripts/esm/game/chess/selection.js @@ -129,7 +129,11 @@ function update() { if (promoteTo) makePromotionMove(); return; } - if (movement.isScaleLess1Pixel_Virtual() || transition.areWeTeleporting() || gamefile.gameConclusion || guipause.areWePaused() || perspective.isLookingUp()) return; + if (movement.isScaleLess1Pixel_Virtual() || transition.areWeTeleporting()) { + if(draggingPiece) handleDragging(undefined, false); + return; + } + if (gamefile.gameConclusion || guipause.areWePaused() || perspective.isLookingUp()) return; // Calculate if the hover square is legal so we know if we need to render a ghost image... @@ -152,7 +156,7 @@ function update() { // Else we clicked, but there was no piece to select, *shrugs* } -function handleDragging(pieceHoveredType) { +function handleDragging(pieceHoveredType, allowDrop=true) { if (input.getTouchHelds().length > 1) { //Prevents accidental dragging when trying to zoom. if (didLastClickSelectPiece) return unselectPiece(); @@ -160,8 +164,9 @@ function handleDragging(pieceHoveredType) { } if (input.getPointerHeld()) { // still dragging. // Render the piece at the pointer. - draganimation.dragPiece(input.getPointerWorldLocation(), hoverSquare); + draganimation.dragPiece(input.getPointerWorldLocation(), allowDrop ? hoverSquare : null); } else { + if (!allowDrop) cancelDragging(); handleMovingSelectedPiece(hoverSquare, pieceHoveredType); const wasCapture = pieceHoveredType || hoverSquare.hasOwnProperty('enpassant'); draganimation.dropPiece(hoverSquareLegal, wasCapture); diff --git a/src/client/scripts/esm/game/rendering/draganimation.js b/src/client/scripts/esm/game/rendering/draganimation.js index bacb7cf98..de26c02a1 100644 --- a/src/client/scripts/esm/game/rendering/draganimation.js +++ b/src/client/scripts/esm/game/rendering/draganimation.js @@ -62,14 +62,17 @@ let hoveredCoords; let pieceType; function renderTransparentSquare() { - if(!startCoords) return; + if (!startCoords) return; let transparentModel = genTransparentModel(); transparentModel.render(); } function renderPiece() { - if(perspective.isLookingUp() || !worldLocation) return; - genOutlineModel().render(); + if (perspective.isLookingUp() || !worldLocation) return; + let outlineModel; + if (hoveredCoords) outlineModel = genOutlineModel(); + else outlineModel = genIntersectingLines(); + outlineModel.render(); genPieceModel().render(); } @@ -84,7 +87,7 @@ function genTransparentModel() { * @returns {BufferModel} The buffer model */ function genPieceModel() { - if(perspective.isLookingUp()) return; + if (perspective.isLookingUp()) return; const perspectiveEnabled = perspective.getEnabled(); const touchscreen = input.getPointerIsTouch(); const boardScale = movement.getBoardScale(); @@ -134,6 +137,18 @@ function genOutlineModel() { return buffermodel.createModel_Colored(new Float32Array(data), 3, "TRIANGLES"); } +function genIntersectingLines() { + const { left, right, bottom, top } = camera.getScreenBoundingBox(false); + const [ r, g, b, a ] = options.getDefaultOutlineColor(); + let data = [ + left, worldLocation[1], r, g, b, a, + right, worldLocation[1],r, g, b, a, + worldLocation[0], bottom, r, g, b, a, + worldLocation[0], top, r, g, b, a, + ]; + return buffermodel.createModel_Colored(new Float32Array(data), 2, "LINES"); +} + /** * Start dragging a piece. * @param {string} type - The type of piece being dragged @@ -147,11 +162,11 @@ function pickUpPiece(type, pieceCoords) { /** * Update the location of the piece being dragged. * @param {number[]} coords - the world coordinates the piece has been dragged to - * @param {number[]} [hoverSquare] - The square to draw a box outline around + * @param {number[]} [hoverSquare] - The square the piece would be moved to if dropped now. */ function dragPiece(coords, hoverSquare) { worldLocation = coords; - hoveredCoords = hoverSquare ?? space.convertWorldSpaceToCoords_Rounded(coords); + hoveredCoords = hoverSquare; frametracker.onVisualChange(); }