Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw offers #39

Merged
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
f2d93cc
Revert "Reapply "Add more reserved usernames""
this-is-not-available Jul 10, 2024
2e9de91
Add frontend
this-is-not-available Jul 10, 2024
b3ab717
Reapply "Add more reserved usernames"
this-is-not-available Jul 10, 2024
9e2c00d
Merge branch 'main' into draw-offers
this-is-not-available Jul 10, 2024
60b0c6d
Corrected game conclusion. It should be 2 words
Naviary2 Jul 10, 2024
105faed
Game ending by draw offer should now display "Draw by agreement."
Naviary2 Jul 10, 2024
18ac3e6
Draw offer spam protection
this-is-not-available Jul 11, 2024
6730ed3
Minor adjustments
this-is-not-available Jul 11, 2024
f4af98c
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 11, 2024
93b049f
Move dev.css to correct place
this-is-not-available Jul 11, 2024
e6ce3c2
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 11, 2024
1248ea6
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 11, 2024
9f14473
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 11, 2024
1bf3075
Frontend changes
this-is-not-available Jul 11, 2024
9939ada
Add statustext for decliner
this-is-not-available Jul 11, 2024
d14373f
Don't obscure timers
this-is-not-available Jul 11, 2024
bec833b
Fixed bug
Naviary2 Jul 11, 2024
e8b57b1
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 11, 2024
077ddba
Refreshing no longer breaks draw offers
this-is-not-available Jul 11, 2024
b259246
Merge branch 'draw-offers' of https://github.com/this-is-not-availabl…
this-is-not-available Jul 11, 2024
7231b72
Move whosturn above draw offer
this-is-not-available Jul 11, 2024
f60e1e2
Revert "Move whosturn above draw offer"
this-is-not-available Jul 19, 2024
f907c10
Revert "Don't obscure timers"
this-is-not-available Jul 19, 2024
f6e238b
It looks good according to jermOSS
this-is-not-available Jul 19, 2024
059bac5
typo i think fixed
this-is-not-available Jul 19, 2024
54782e9
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 19, 2024
e9685d8
No longer popup
this-is-not-available Jul 19, 2024
22e52f8
Button is white and icons bigger
this-is-not-available Jul 19, 2024
ed695b7
Add comment
this-is-not-available Jul 19, 2024
f6f5d4e
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 20, 2024
ad61716
Added translations and added missing HTML
this-is-not-available Jul 20, 2024
e13ee01
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 23, 2024
b99765f
Not working :sob:
this-is-not-available Jul 23, 2024
6af3052
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 25, 2024
df6c8d5
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 26, 2024
a82a348
Merge branch 'Infinite-Chess:main' into draw-offers
this-is-not-available Jul 29, 2024
2fe49aa
Fixed logic and moved to guidrawoffer.js
this-is-not-available Jul 29, 2024
2eb5c20
Added termination to translation
this-is-not-available Jul 29, 2024
f593b5e
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
this-is-not-available Jul 29, 2024
946fa6a
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 29, 2024
a53bac0
yes
this-is-not-available Jul 29, 2024
e08fe9f
Increment version
this-is-not-available Jul 29, 2024
70083a7
Gui autocloses
this-is-not-available Jul 29, 2024
1ee720d
snake case
this-is-not-available Jul 29, 2024
361f9a7
??? it no transparent whyyyyy
this-is-not-available Jul 29, 2024
f42843d
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Jul 31, 2024
999e811
Translations and accept draw in pause menu
this-is-not-available Jul 31, 2024
4765fea
Don't carry accept draw to other game
this-is-not-available Jul 31, 2024
36eafe2
Moved automatic draw declining
this-is-not-available Jul 31, 2024
4c139cf
Fix previous to include closing of UI
this-is-not-available Jul 31, 2024
d8fe840
Server-sided auto declining
this-is-not-available Jul 31, 2024
f6a515b
Fixed perspective button
this-is-not-available Jul 31, 2024
6515d2d
Adjust font
this-is-not-available Jul 31, 2024
20b19aa
Merge branch 'Infinite-Chess:main' into draw-offers
this-is-not-available Jul 31, 2024
8b2f01f
JSDoc stuff
this-is-not-available Jul 31, 2024
e6bb926
Merge branch 'draw-offers' of https://github.com/this-is-not-availabl…
this-is-not-available Jul 31, 2024
a108e41
whoops missed a change
this-is-not-available Jul 31, 2024
f6e8446
stuff
this-is-not-available Jul 31, 2024
ffacad2
Move it inside other div
this-is-not-available Aug 1, 2024
b0b2a73
Remove the footer class
this-is-not-available Aug 1, 2024
9a9db2a
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Aug 1, 2024
6154633
Update version in toml
this-is-not-available Aug 1, 2024
a921774
Bug fix and hasColorDrawOffer
this-is-not-available Aug 1, 2024
5c61d4b
fix bugs
this-is-not-available Aug 1, 2024
8a1b348
Add config variable
this-is-not-available Aug 2, 2024
ff3a544
Change sound and remove some lines
this-is-not-available Aug 2, 2024
dc30b82
CSS improvements
this-is-not-available Aug 2, 2024
1a35425
Math fix :O
this-is-not-available Aug 3, 2024
d999a5f
Whoops wrong ordering in css
this-is-not-available Aug 3, 2024
69aec44
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Aug 3, 2024
f3ea438
Fix bug (found another)
this-is-not-available Aug 4, 2024
43ee31f
Other
this-is-not-available Aug 4, 2024
7f7d859
Bug fix
this-is-not-available Aug 4, 2024
111c126
Merge branch 'Infinite-Chess:main' into draw-offers
this-is-not-available Aug 5, 2024
f0e353a
Bug fix (client edition)
this-is-not-available Aug 5, 2024
78d4ad9
Merge branch 'draw-offers' of https://github.com/this-is-not-availabl…
this-is-not-available Aug 5, 2024
211fb6c
moved sound spritesheet with draw offer sound to dev utils
Naviary2 Aug 6, 2024
bc0c897
Lots of cleaning up
Naviary2 Aug 6, 2024
aa9167e
Merge remote-tracking branch 'upstream/main' into draw-offers
this-is-not-available Aug 6, 2024
cd8414b
reorder the code
this-is-not-available Aug 6, 2024
e4e7789
Fix uhhh.. what do i put here
this-is-not-available Aug 6, 2024
6687ee0
Add vendor specific to css
this-is-not-available Aug 6, 2024
df1324f
Moved many methods from gamemanager to new game1.js
Naviary2 Aug 9, 2024
8558ca0
Merge branch 'draw-offers' of https://github.com/this-is-not-availabl…
Naviary2 Aug 9, 2024
c831d4f
deleted whitespace
Naviary2 Aug 9, 2024
e6d48a5
Merge branch 'main' into draw-offers
Naviary2 Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dev-utils/sounds/infinite_chess/draw_offer.mp3
Binary file not shown.
91 changes: 88 additions & 3 deletions src/client/css/play.css
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ button.join-button, button.copy-button {
height: 84px;
box-shadow: 0px -1px 7px 0px rgba(0, 0, 0, 0.659);
display: flex;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.307), white, rgba(255, 255, 255, 0.84));
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.307), white, rgba(255, 255, 255, 0.84));
backdrop-filter: blur(8px); /* Apply a blur effect to the background */
-webkit-backdrop-filter: blur(5px); /* Fixes blur for Safari */
}
Expand Down Expand Up @@ -1224,7 +1224,7 @@ button.join-button, button.copy-button {
background-color: rgba(0, 0, 0, 0.849);
padding-bottom: 15vh;
display: grid;
grid-template: repeat(5, min(8vw, 86px)) / repeat(2, min(30vw, 320px));
grid-template: repeat(6, min(8vw, 86px)) / repeat(2, min(30vw, 320px));
gap: min(3vw, 32px);
justify-content: center;
align-content: center;
Expand Down Expand Up @@ -1258,11 +1258,96 @@ button.join-button, button.copy-button {
background: linear-gradient(to bottom, white, rgb(230, 230, 230), white);
}

.pauseUI p.paused, button.paused, button.resume, button.mainmenu {
.pauseUI p.paused, button.paused, button.resume, button.mainmenu, button.offerdraw {
grid-column: 1 / 3;
}


/* Draw Offer UI */

.draw_offer_ui {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font-size: 30px;
font-family: "Open Sans";
font-weight: bold;
padding: 15px;
margin-left: 14%;
margin-right: 14%;
width: 72%;
gap: 15px;
border-radius: 5px;
box-sizing: border-box;

/* Make it not a popup / tsevasa's suggestion */
border-color: transparent;
background-color: rgba(0, 0, 0, 0);
box-shadow: none;
}

@media only screen and (max-width: 1520px) { /* Mobile screens: make smaller in order to not obscure names */
.draw_offer_ui {
margin-left: 22%;
margin-right: 22%;
width: 56%;
}
}

.draw_offer_ui p.offer_title, .draw_offer_ui button {
font-size: min(3.5vw, 35px);
}

.draw_offer_ui p.offer_title {
color: black;
text-align: center;
vertical-align: middle;
line-height: 100%;
font-size: 30px;
font-family: "Open Sans";
font-weight: bold;
top: 50%;
bottom: 50;
}

.draw_offer_ui button {
background-color: rgb(255, 255, 255) !important;
box-shadow: 0px 0px 7px 1px #727272 !important;
border-radius: min(0.9vw, 10px);
color: rgb(0, 0, 0);
height: 100%;
aspect-ratio: 1/1;
background: rgb(227, 227, 227);
display: flex;
justify-content: center;
align-items: center;
}

.draw_offer_ui img {
position: relative;
height: 85%;
margin:1px;
top: 0px;
}

/* The accept draw button is naturally smaller */
.acceptdraw > .icon {
height: 95%;
}

.draw_offer_ui button:hover {
/* background-color: rgb(255, 255, 255); */
background: linear-gradient(to bottom, white, rgb(219, 219, 219), white);
}

.draw_offer_ui button:active {
/* box-shadow: 0 0 15px 0 rgba(255, 255, 255, 0.51); */
background: linear-gradient(to bottom, white, rgb(230, 230, 230), white);
}



/* Status text showing alerts and errors */

Expand Down
4 changes: 4 additions & 0 deletions src/client/img/checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/client/img/xmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/client/scripts/game/chess/gamefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ function gamefile(metadata, { moves = [], variantOptions, gameConclusion } = {})
this.attackers = undefined;
/** If 3-Check is enabled, this is a running count of checks given: `{ white: 0, black: 0 }` */
this.checksGiven = undefined;
/** Last draw offer */
this.drawOfferWhite = false;
this.drawOfferBlack = false;

this.ourPieces = organizedlines.buildStateFromKeyList(this.startSnapshot.position)
this.startSnapshot.pieceCount = gamefileutility.getPieceCountOfGame(this)
Expand Down
9 changes: 8 additions & 1 deletion src/client/scripts/game/chess/gamefileutility.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ const gamefileutility = (function(){
if (requestRemovalFromActiveGames) onlinegame.requestRemovalFromPlayersInActiveGames();
if (wincondition.isGameConclusionDecisive(gamefile.gameConclusion)) movesscript.flagLastMoveAsMate(gamefile);
clock.stop()
board.darkenColor()
main.renderThisFrame();
board.darkenColor();
guigameinfo.gameEnd(gamefile.gameConclusion);
guidrawoffer.closeDrawOffer();
guipause.disableDrawOfferButton();
onlinegame.cancelMoveSound();
onlinegame.resetServerRestarting();
onlinegame.deleteCustomVariantOptions();
guigameinfo.gameEnd(gamefile.gameConclusion)
onlinegame.onGameConclude();

Expand Down
6 changes: 4 additions & 2 deletions src/client/scripts/game/chess/wincondition.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const wincondition = (function() {

/**
* List of all win conditions that happen after a move being made.
* This excludes conclusions such as resignation, time, aborted, and disconnect,
* This excludes conclusions such as resignation, time, aborted, disconnect, and agreement.
* which can happen at any point in time.
*/
const decisiveGameConclusions = [...validWinConditions, 'stalemate', 'repetition', 'moverule', 'insuffmat']
Expand Down Expand Up @@ -199,7 +199,7 @@ const wincondition = (function() {
/**
* Calculates if the provided game conclusion is a decisive conclusion.
* This is any conclusion that can happen after a move is made.
* Excludes conclusions like resignation, time, aborted, and disconnect,
* Excludes conclusions like resignation, time, aborted, disconnect, and agreement.
* which can happen at any point in time.
* @param {string} gameConclusion - The gameConclusion
* @returns {boolean} *true* if the gameConclusion is decisive.
Expand Down Expand Up @@ -299,6 +299,8 @@ const wincondition = (function() {
return translations.termination.aborted;
case "disconnect": // Happens when a player leaves
return translations.termination.disconnect;
case "agreement":
return translations.termination.agreement
default:
console.error(`Cannot return English termination for unknown condition "${condition}"!`);
return 'Unknown';
Expand Down
77 changes: 77 additions & 0 deletions src/client/scripts/game/gui/guidrawoffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

/*
* This script handles our Draw offer menu
*/

"use strict";

const guidrawoffer = (function(){

// Variables
// Draw Offer UI
let isAcceptingDraw = false
const element_draw_offer_ui = document.getElementById('draw_offer_ui')
const element_acceptDraw = document.getElementById('acceptdraw')
const element_declineDraw = document.getElementById('declinedraw')

// Functions

/**
* Returns *true* if the user is deciding on accepting draw.
* @returns {boolean}
*/
function areWeAcceptingDraw() { return isAcceptingDraw; }

function openDrawOffer() {
isAcceptingDraw = true;
style.revealElement(element_draw_offer_ui)
// style.hideElement(element_whosturn)
sound.playSound_drawOffer()
initDrawOfferListeners()
}

function closeDrawOffer() {
isAcceptingDraw = false;
style.hideElement(element_draw_offer_ui)
//style.revealElement(element_whosturn)
closeDrawOfferListeners()
}

function initDrawOfferListeners() {
element_acceptDraw.addEventListener('click', callback_AcceptDraw)
element_declineDraw.addEventListener('click', callback_DeclineDraw)
}

function closeDrawOfferListeners() {
element_acceptDraw.removeEventListener('click', callback_AcceptDraw)
element_declineDraw.removeEventListener('click', callback_DeclineDraw)
}

async function callback_AcceptDraw(event) {
const gamefile = game.getGamefile();

if (gamefile.gameConclusion) return // game already over
onlinegame.acceptDraw()
closeDrawOffer()

gamefile.gameConclusion = 'draw agreement';
clock.stop()
gamefileutility.concludeGame(gamefile);
}

async function callback_DeclineDraw(event) {
onlinegame.declineDraw()
const gamefile = game.getGamefile();
closeDrawOffer()
statustext.showStatus(`Draw declined`, false, 2)
}

return Object.freeze({
areWeAcceptingDraw,
openDrawOffer,
closeDrawOffer,
callback_AcceptDraw,
callback_DeclineDraw
})

})();
5 changes: 4 additions & 1 deletion src/client/scripts/game/gui/guigameinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ const guigameinfo = (function(){

// Updates the whosTurn text to say who won!
function gameEnd(conclusion) {
// 'white checkmate' / 'black resignation' / 'draw stalemate' time/resignation/stalemate/repetition/checkmate/disconnect
// 'white checkmate' / 'black resignation' / 'draw stalemate' time/resignation/stalemate/repetition/checkmate/disconnect/agreement

const { victor, condition } = wincondition.getVictorAndConditionFromGameConclusion(conclusion)

style.hideElement(element_dot)

if (onlinegame.areInOnlineGame()) {


if (onlinegame.areWeColor(victor)) element_whosturn.textContent = condition === 'checkmate' ? translations["results"]["you_checkmate"]
: condition === 'time' ? translations["results"]["you_time"]
: condition === 'resignation' ? translations["results"]["you_resignation"]
Expand All @@ -91,6 +92,7 @@ const guigameinfo = (function(){
: condition === 'repetition' ? translations["results"]["draw_repetition"]
: condition === 'moverule' ? `${translations["results"]["draw_moverule"][0]}${(game.getGamefile().gameRules.moveRule / 2)}${translations["results"]["draw_moverule"][1]}`
: condition === 'insuffmat' ? translations["results"]["draw_insuffmat"]
: condition === 'agreement' ? translations["results"]["draw_agreement"]
: translations["results"]["draw_generic"]
else if (condition === 'aborted') element_whosturn.textContent = translations["results"]["aborted"]
else /* loss */ element_whosturn.textContent = condition === 'checkmate' ? translations["results"]["opponent_checkmate"]
Expand All @@ -103,6 +105,7 @@ const guigameinfo = (function(){
: condition === 'threecheck' ? translations["results"]["opponent_threecheck"]
: condition === 'koth' ? translations["results"]["opponent_koth"]
: translations["results"]["opponent_generic"]

} else { // Local game
if (condition === 'checkmate') element_whosturn.textContent = victor === 'white' ? translations["results"]["white_checkmate"]
: victor === 'black' ? translations["results"]["black_checkmate"]
Expand Down
Loading
Loading