Skip to content

Instantly share code, notes, and snippets.

@fluffytid
Last active December 7, 2021 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fluffytid/d34d15b8b8ae5c5150f2772dd5c22ee1 to your computer and use it in GitHub Desktop.
Save fluffytid/d34d15b8b8ae5c5150f2772dd5c22ee1 to your computer and use it in GitHub Desktop.
Interface for blind user to play bridge on realbridge.com
// ==UserScript==
// @name Audio/Keyboard Bridge Interface
// @namespace http://bridgegod.com/
// @version 0.14
// @description Interface for visually impaired users to play bridge, using audio only for output and keyboard for input
// @author Gonzalo Goded
// @match http://www.bridgegod.com/*
// @match https://www.bridgegod.com/*
// @match https://play.realbridge.online/*
// @match http://bridgegod.com/*
// @match https://bridgegod.com/*
// @require http://code.jquery.com/jquery-latest.js
// @require https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js
// @grant none
// ==/UserScript==
/*global declarer, inbid, cards, partner, turno, trick, historial, dealer*/
var $ = window.jQuery;
$ (function () {
BUI_start();
});
var KeyEvent = (typeof KeyEvent === "object") ? KeyEvent : [];
//you can change the keys easilly editing next lines, for a key reference see http://www.javascripter.net/faq/keyeventconstantsfirefox.htm
const LEFT_KEY = KeyEvent.DOM_VK_LEFT || 37; // The 4 arrows are used to select cards and bids
const UP_KEY = KeyEvent.DOM_VK_UP || 38;
const DOWN_KEY = KeyEvent.DOM_VK_DOWN || 40;
const RIGHT_KEY = KeyEvent.DOM_VK_RIGHT || 39;
const ACTION_KEY = KeyEvent.DOM_VK_SPACE || 32; //The action key is used to play/bid what was selected with the arrows. Normal bids are selected in 2 steps
const LOGIN_KEY = KeyEvent.DOM_VK_F6 || 117; //Presses the login button on the first screen where name is entered, this version is a bit unstable and it is advised to click F5 and then F6 after 3/4 seconds if sound starts to lag behind to reset all.
const NEW_AUDIO_KEY = KeyEvent.DOM_VK_F1 || 112; //Cancels all the sounds/words scheduled on the reader
const MUTE_KEY = KeyEvent.DOM_VK_1 || 49; //On realbridge mutes/unmutes the other 3 players
const TRICK_KEY = KeyEvent.DOM_VK_2 || 50; //Reads last round of bidding or ongoing trick
const BID_KEY = KeyEvent.DOM_VK_3 || 51; //reads the whole auction from the start (can be long)
const CLAIM_KEY = KeyEvent.DOM_VK_0 || 48; //claims all the remaining tricks (in the future less will be possible to be claimed)
const UNDO_KEY = KeyEvent.DOM_VK_BACK_SPACE || 8; //request an undo, except if we are awaiting step-2 after first step of a 2-step action (make a bid after level is selected, but before suit is selected), then it will cancel first step without telling anyone.
const HAND_KEY = KeyEvent.DOM_VK_CAPS_LOCK || 20; //reads all of cards we have left in hand
const HAND_S_KEY = KeyEvent.DOM_VK_A || 65; //reads spades in hand
const HAND_H_KEY = KeyEvent.DOM_VK_S || 83;
const HAND_D_KEY = KeyEvent.DOM_VK_D || 68;
const HAND_C_KEY = KeyEvent.DOM_VK_F || 70;
const DUMMY_KEY = KeyEvent.DOM_VK_TAB || 9; //reads all cards left in dummy
const DUMMY_S_KEY = KeyEvent.DOM_VK_Q || 81; //reads the spades in dummy
const DUMMY_H_KEY = KeyEvent.DOM_VK_W || 87;
const DUMMY_D_KEY = KeyEvent.DOM_VK_E || 69;
const DUMMY_C_KEY = KeyEvent.DOM_VK_R || 82;
const CONSOLE_KEY = KeyEvent.DOM_VK_F10 || 121;
const LANG_KEY = KeyEvent.DOM_VK_F9 || 120;
const BUI_audioPath = "https://bridgegod.com/audio/";
var BUI_audioPathL = {};
BUI_audioPathL.G = "";
BUI_audioPathL.S = "";
BUI_audioPathL.H = "";
BUI_audioPathL.D = "";
BUI_audioPathL.C = "";
var BUI_domain; //The domain in which we are playing
var BUI_status = 0; //1 for bidding, 2 for play, 0 for other
var BUI_audio = 0; //change audio to silence all sounds scheduled
var BUI_declarer;
var BUI_dealer;
var BUI_audiofinnish =0; //time last sounds is scheduled to finnish
var BUI_sounds = new Object;
var BUI_position = 0;//current cursor position
var BUI_bid_level = 0; //level of next bid selected
var BUI_lastSuitRead ="";
var BUI_passSwitch = "";
var BUI_partner = { "main": 'cho', "lho" : 'rho', "cho" : 'main', "rho" : 'lho', "" : 'nopes' };
var BUI_next = { "main": 'lho', "lho" : 'cho', "cho" : 'rho', "rho" : 'main', "" : 'nopes' };
var BUI_volume = {"partner" : 0 , "lho": 0 , "rho" : 0 };
var BUI_consoleP = 1;
var BUI_lang = 0;
var count_before, count_after;
setInterval(function(){
if (BUI_status>0)
{
if (BUI_domain == "BG")
{
return;
}
if (BUI_domain == "RB")
{
var x = document.getElementById("question_dialog");
if (x.style.opacity >0.5){
BUI_simulateClick("yes_button")
}
}
}
}, 2000);
setInterval(function(){
BUI_Narrator();
}, 500);
//$(window).keydown (keyboardHandlerJQ);
window.addEventListener ("keydown", BUI_keyboardHandlerJQ, false);
(async () => {
BUI_consoleP = await GM_getValue('consoleP', 0);
BUI_lang = await GM_getValue('lang', 0);
// Note awaiting the set -- required so the next get sees this set.
//await GM_setValue('count', (count_before*1) + 1);
BUI_placeConsole();
BUI_loadLang();
})();
function BUI_start(){
if (window.location.href.indexOf("bridgegod") > -1) {
BUI_domain = "BG";
}
if (window.location.href.indexOf("realbridge") > -1) {
BUI_domain = "RB";
//give ids to cards
var divs = document.querySelectorAll("body div");
for (var divelem in divs)
{
if ((typeof divs[divelem].innerHTML !== "undefined") && (divs[divelem].innerHTML.includes("cards_svg")) && (divs[divelem].innerHTML.length < 150) ) //its a card
{
for (let suit of ["S", "H", "D", "C"]){
for (let rank of ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A" ]){
if (divs[divelem].innerHTML.includes(rank+suit+".svg")){
let newid = "card_" + suit.toLowerCase() + rank.toLowerCase();
divs[divelem].id = newid;
}
}
}
}
}
var imgs = document.querySelectorAll("body div#bb_container img"); //bidding box images
for (divelem in imgs)
{
if (typeof imgs[divelem].src !== 'undefined') {
for (let suit of ["S", "H", "D", "C", "N"]){
for (let rank of ["1", "2", "3", "4", "5", "6", "7"]){
if (imgs[divelem].src.includes(rank+suit)){
let offset =5;
if (suit == "S") { offset = 4; }
if (suit == "H") { offset = 3; }
if (suit == "D") { offset = 2; }
if (suit == "C") { offset = 1; }
let bid = (rank-1)*5 + offset;
let newid = "bid" + bid;
imgs[divelem].id = newid;
}
if (imgs[divelem].src.includes("XXBB")){
imgs[divelem].id = "bredouble";
}
else if (imgs[divelem].src.includes("XBB")){
imgs[divelem].id = "bdouble";
}
if (imgs[divelem].src.includes("PASSBB")){
imgs[divelem].id = "bpass";
}
}
}
}
}
}
if (window.location.href.indexOf("bridgegbase") > -1) {
BUI_domain = "BB";
}
var div = document.createElement('div');
div.id = 'BUI_console';
div.innerHTML = 'Console<br>';
div.style.position = 'absolute';
div.style.width = '800px';
div.style.height = '100px';
div.style.left = '0px';
div.style.bottom = '0px';
div.style.zIndex = '1000';
div.style.overflowY = 'scroll';
div.style.background = 'white';
document.body.appendChild(div);
BUI_loadLang();
BUI_Narrator.status = 0;
BUI_Narrator.bid = [];
BUI_Narrator.trick = "";
BUI_placeConsole()
}
function BUI_loadLang()
{
var ext = ".wav";
if (BUI_lang == 0)
{
BUI_audioPathL.G = "";
BUI_audioPathL.S = "";
BUI_audioPathL.H = "";
BUI_audioPathL.D = "";
BUI_audioPathL.C = "";
}
if (BUI_lang == 1)
{
BUI_audioPathL.G = "german/";
BUI_audioPathL.S = "german/";
BUI_audioPathL.H = "german/";
BUI_audioPathL.D = "german/";
BUI_audioPathL.C = "german/";
}
if (BUI_lang == 2)
{
BUI_audioPathL.G = "italian/";
BUI_audioPathL.S = "italian/";
BUI_audioPathL.H = "italian/";
BUI_audioPathL.D = "italian/";
BUI_audioPathL.C = "italian/";
ext = ".mp3";
}
BUI_sounds.g = new Object;
BUI_sounds.s = new Object;
BUI_sounds.h = new Object;
BUI_sounds.d = new Object;
BUI_sounds.c = new Object;
BUI_sounds.g.s = new Audio(BUI_audioPath + BUI_audioPathL.G + "Spades" + ext);
BUI_sounds.g.h = new Audio(BUI_audioPath + BUI_audioPathL.G + "Hearts" + ext);
BUI_sounds.g.d = new Audio(BUI_audioPath + BUI_audioPathL.G + "Diamonds" + ext);
BUI_sounds.g.c = new Audio(BUI_audioPath + BUI_audioPathL.G + "Clubs" + ext);
BUI_sounds.g.n = new Audio(BUI_audioPath + BUI_audioPathL.G + "No-Trump" + ext);
BUI_sounds.g.pass = new Audio(BUI_audioPath + BUI_audioPathL.G + "Pass" + ext);
BUI_sounds.g.pass2 = new Audio(BUI_audioPath + BUI_audioPathL.G + "Pass2" + ext);
BUI_sounds.g.double = new Audio(BUI_audioPath + BUI_audioPathL.G + "Double" + ext);
BUI_sounds.g.redouble = new Audio(BUI_audioPath + BUI_audioPathL.G + "Redouble" + ext);
BUI_sounds.g["1"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "One" + ext);
BUI_sounds.g["2"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "Two" + ext);
BUI_sounds.g["3"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "Three" + ext);
BUI_sounds.g["4"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "Four" + ext);
BUI_sounds.g["5"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "Five" + ext);
BUI_sounds.g["6"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "Six" + ext);
BUI_sounds.g["7"] = new Audio(BUI_audioPath + BUI_audioPathL.G + "Seven" + ext);
BUI_sounds.g["8"] = new Audio(BUI_audioPath + BUI_audioPathL.S + "Eight.1" + ext);
BUI_sounds.g["9"] = new Audio(BUI_audioPath + BUI_audioPathL.S + "Nine.1" + ext);
BUI_sounds.g["10"] = new Audio(BUI_audioPath + BUI_audioPathL.S + "Ten.1" + ext);
for (var suit of ["s", "h", "d", "c"]){
BUI_sounds[suit]["2"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Two.1" + ext);
BUI_sounds[suit]["3"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Three.1" + ext);
BUI_sounds[suit]["4"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Four.1" + ext);
BUI_sounds[suit]["5"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Five.1" + ext);
BUI_sounds[suit]["6"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Six.1" + ext);
BUI_sounds[suit]["7"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Seven.1" + ext);
BUI_sounds[suit]["8"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Eight.1" + ext);
BUI_sounds[suit]["9"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Nine.1" + ext);
BUI_sounds[suit]["t"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Ten.1" + ext);
BUI_sounds[suit]["j"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "J.1" + ext);
BUI_sounds[suit]["q"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "Q.1" + ext);
BUI_sounds[suit]["k"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "K.1" + ext);
BUI_sounds[suit]["a"] = new Audio(BUI_audioPath + BUI_audioPathL[suit.toUpperCase()] + "A.1" + ext);
}
}
//self_vul_box
//self_name_container
//lho_name_container
//rho_name_container
//partner_name_container
//background-color: rgb(160, 160, 160) is grey, background-color: rgb(0, 255, 255) is yellow = turn
function BUI_trace(text)
{
var consola = document.getElementById("BUI_console");
consola.innerHTML += text;
consola.innerHTML += "<br>";
}
function BUI_checkStatus(){
//updates de current status between bidding and play
if (BUI_domain == "BG")
{
if (typeof inbid !== 'undefined') {
if (inbid)
{
BUI_status = 1;
}
else
{
BUI_status = 2;
BUI_declarer = declarer;
}
}
else {
BUI_status = 0;
BUI_dealer = "";
return;
}
BUI_dealer = dealer;
}
if (BUI_domain == "RB")
{
var turn = BUI_WhosTurn();
if (turn == "")
{
BUI_status = 0;
return;
}
var decl = document.getElementById("contract_declarer");
var self = document.getElementById("self_vul_box");
var rho = document.getElementById("rho_vul_box");
var lho = document.getElementById("lho_vul_box");
var cho = document.getElementById("partner_vul_box");
if (decl.textContent == "")
{//no declarer
BUI_status = 1;
}
else
{
//BUI_trace("contract_decl = " + decl.textContent);
if (decl.textContent[0] == self.textContent[0])
{
BUI_declarer = 'main';
}
if (decl.textContent[0] == cho.textContent[0])
{
BUI_declarer = 'cho';
}
if (decl.textContent[0] == rho.textContent[0])
{
BUI_declarer = 'rho';
}
if (decl.textContent[0] == lho.textContent[0])
{
BUI_declarer = 'lho';
}
//BUI_trace("BUI_declarer = " + BUI_declarer);
BUI_status = 2;
}
if (self.textContent.length>1)
{
BUI_dealer = 'main';
}
if (rho.textContent.length>1)
{
BUI_dealer = 'rho';
}
if (lho.textContent.length>1)
{
BUI_dealer = 'lho';
}
if (cho.textContent.length>1)
{
BUI_dealer = 'cho';
}
//BUI_trace("BUI_dealer = " + BUI_dealer);
}
}
function BUI_Narrator(){
//Narrates events on screen like each bid made and card played.
BUI_checkStatus();
//BUI_trace("Narrando");
if (BUI_status ==0)
{
//if (BUI_Narrator.status != 0) { BUI_trace("nuevo estado 0");}
BUI_Narrator.status = 0;
BUI_Narrator.bid = [];
BUI_Narrator.trick = "";
}
if (BUI_status ==1)
{
//if (BUI_Narrator.status != 1) { BUI_trace("nuevo estado 1");}
if (BUI_Narrator.status !=1)
{// new status.
BUI_Narrator.trick = "";
BUI_Narrator.bid = BUI_getBidding();
BUI_Narrator.status = 1;
return;
}
else
{// announce new bids
let bidding = BUI_getBidding()
//BUI_trace(" checkeando.... old = " + BUI_Narrator.bid.length + " new = " + bidding.length);
for (let i = BUI_Narrator.bid.length; i < bidding.length; i++)
{
//BUI_trace("cantando.... i = " + i + " bid = " + bidding[i]);
BUI_readBid(bidding[i]);
}
BUI_Narrator.bid = bidding;
}
}
if (BUI_status ==2)
{
if (BUI_Narrator.status !=2)
{// new status.
BUI_Narrator.trick = "";
let bidding = BUI_getBidding()
//BUI_trace(" checkeando.... old = " + BUI_Narrator.bid.length + " new = " + bidding.length);
if ((BUI_status ==1) && (BUI_Narrator.bid.length >0))
{
for (let i = BUI_Narrator.bid.length; i < bidding.length; i++)
{
//BUI_trace("cantando.... i = " + i + " bid = " + bidding[i]);
BUI_readBid(bidding[i]);
}
}
BUI_Narrator.bid = bidding;
BUI_Narrator.trick = "";
BUI_Narrator.status = 2;
return;
}
let tr = BUI_currentTrick();
if (BUI_Narrator.trick == tr)
{// no changes
return;
}
if (BUI_Narrator.trick.length > tr.length)
{// new trick TODO this would happen when someone plays too fast to new trick we don't have time to see the end of previous, would need to check previous cards.
if (BUI_Narrator.trick.length == 8)
{// we don't need to read anything new
BUI_Narrator.trick = "";
}
else
{//we need to read last card from last trick
let lasttrick = BUI_getLastTrick();
BUI_readtrick(lasttrick.replace(BUI_Narrator.trick,''));
}
}
if (BUI_Narrator.trick.length < tr.length)
{// new card(s) on same trick
BUI_readtrick(tr.replace(BUI_Narrator.trick,''));
}
BUI_Narrator.trick = tr;
}
}
function BUI_readplayer(cards){ // cards is an object with 4 attributes: s, h, d, c containing the cards on each suit as a string of characters, all lowercase.
for (var suit of ["s", "h", "d", "c"]){
if (cards[suit].length>0){
BUI_scheduleSound(BUI_sounds.g[cards[suit].length]);
BUI_scheduleSuit(suit, 2);
for (var i = 0; i < cards[suit].length; i++) {
BUI_scheduleCard(suit + cards[suit][i], 1);
}
}
}
}
function BUI_readsuit(cards, suit){
if (cards[suit].length>0){
BUI_scheduleSound(BUI_sounds.g[cards[suit].length]);
BUI_scheduleSuit(suit, 2);
for (var i = 0; i < cards[suit].length; i++) {
BUI_scheduleCard(suit + cards[suit][i], 1);
}
}
}
function BUI_formatAtoB(cards){ // cards is a string on the format: saqthj8dck2 returns the other format
//BUI_trace("format : " + cards);
var div = cards.split('h');
var s = div[0].substring(1);
var divi = div[1].split('d');
var h = divi[0];
var divis = divi[1].split('c');
var d = divis[0];
var c = divis[1];
var cars = {s: s, h:h, d:d, c:c};
return cars;
}
function BUI_readtrick(trick){ //format 2 characters per card on a string, all lowercase, example sqs2sa note that 't' is used for 10s
var leadsuit = trick[0];
var lastsuit = "";
for (var j=0; j< trick.length ; j+=2)
{
if ((trick[j] == leadsuit) && (trick[j] == lastsuit)) //when suit is the same as led it makes no sense to repear the suit denomination again
{
BUI_scheduleCard(trick[j] + trick[j+1], 1);
lastsuit = trick[j];
}
else
{
BUI_scheduleCard(trick[j] + trick[j+1], 2);
lastsuit = trick[j];
}
}
}
function BUI_scheduleSuit(suit, level){
BUI_scheduleSound(BUI_sounds.g[suit]);
}
function BUI_scheduleCard(card, level){
if (level >1)
{
BUI_scheduleSuit(card[0], level);
BUI_scheduleSound(BUI_sounds[card[0]][card[1]]);
}
else
{
BUI_scheduleSound(BUI_sounds[card[0]][card[1]]);
}
}
function BUI_scheduleSound(sound){
var d = new Date();
var n = d.getTime();
if (n< BUI_audiofinnish)
{//sounds scheduled didn't finnish yet
setTimeout(function(state) {
BUI_readSound(sound, state);
}, BUI_audiofinnish - n, BUI_audio);
BUI_audiofinnish += (sound.duration*1000);
//BUI_trace("CAF = " + BUI_audiofinnish);
}
else{
sound.play();
var delay = 0;
if (BUI_lang == 2)
{
delay = -400;
}
BUI_audiofinnish = n + (sound.duration*1000 + delay);
//BUI_trace("AF = " + BUI_audiofinnish);
}
}
function BUI_readSound(sound, state){
if (state ==BUI_audio)
{
sound.play();
var d = new Date();
var n = d.getTime();
//BUI_trace("sound scheduled at " + n + " st=" + state);
}
else
{
//BUI_trace("Sound canceled");
}
}
function BUI_WhosTurn(){//returns who's turn: main, lho, cho, rho
if (BUI_domain == "BG") //my webpage
{
if (typeof(turno) != "undefined")
{
return turno;
}
return "";
}
if (BUI_domain == "RB") //realbridge
{
var me = document.getElementById("self_name_container");
var lho = document.getElementById("lho_name_container");
var rho = document.getElementById("rho_name_container");
var cho = document.getElementById("partner_name_container");
//when it is your turn, background-color is RGB(0,255,255), when it is not, it is RGB(160,160,160), at least on non contrast-UI.
if (me == null)
{
return "";
}
if (me.style.backgroundColor.includes("255")) //its my turn
{
return "main";
}
if (lho.style.backgroundColor.includes("255")) //its lho's turn
{
return "lho";
}
if (rho.style.backgroundColor.includes("255")) //its rho's turn
{
return "rho";
}
if (cho.style.backgroundColor.includes("255")) //its partner's turn
{
return "cho";
}
return "";
}
}
function BUI_requestUndo(){
if (BUI_domain == "BG") //
{//no undos on bridgegod!
return ;
}
if (BUI_domain == "RB") //
{//
BUI_simulateClick("undo_button");
return ;
}
}
function BUI_login(){
if (BUI_domain == "BG") //
{//no login on bridgegod!
return ;
}
if (BUI_domain == "RB") //
{//
BUI_simulateClick("login_button");
return ;
}
}
function BUI_claim(){
if (BUI_domain == "BG") //
{
let cla = document.getElementById("claimbut");
if (cla.style.visibility == "hidden")
{//claim forbidden
return;
}
BUI_simulateClick("claimbut");
}
if (BUI_domain == "RB") //
{//
BUI_simulateClick("claim_button");
let but = document.getElementById("0_button");
if (but.style.opacity>0)
{
BUI_simulateClick("0_button");
return ;
}
for (let i = 13 ; i>0; i--)
{
let but = document.getElementById(i + "_button");
if (but.style.opacity>0)
{
BUI_simulateClick(i +"_button");
return ;
}
}
BUI_simulateClick("cancel_claim");
}
}
function BUI_mute(player){//only on RB
BUI_simulateClick(player + "_vol_button");
//var divs = document.querySelectorAll("div#" + player +"_name_container div");
var divss = document.querySelectorAll("div");
var divs = [divss[divss.length- 1], divss[divss.length- 2], divss[divss.length- 3]]; //The last 3 elements of the DOM are the black label, the marker and the line
var el, pest, rect, re;
//BUI_trace("player = " + player + " " + player +"_name_container");
for (var i = 0; i< divs.length ; i++)
{
//BUI_trace("i = " + i + "length " + divs.length);
if (divs[i].style.backgroundColor.includes("black"))
{
//BUI_trace("found i = " + i);
el = divs[i];
}
else
{
re = divs[i].getBoundingClientRect();
if (re.right-re.left <15)
{//its the marker
pest = divs[i];
}
}
}
if (BUI_volume[player] >5)
{//restore previous volume
rect = el.getBoundingClientRect();
BUI_triggerMostButtonsPos(el, BUI_volume[player]);
BUI_volume[player] = 0;
}
else
{//set volumen to zero
re = pest.getBoundingClientRect();
rect = el.getBoundingClientRect();
BUI_volume[player] = re.left;
for (i=5; i>-2; i--)
{
BUI_triggerMostButtonsPos(el, rect.left+i)
}
}
}
function BUI_calcualteCards(player){
var match = "";
if (player=="main")
{
match = "main";
}
if (player == BUI_partner[BUI_declarer])
{
match = "dummy";
}
if (("main" == BUI_partner[BUI_declarer]) && (player == 'cho'))
{
match = "dec-dummy";
}
if (BUI_domain == "BG")
{
let res ="";
for (var suit of ["s", "h", "d", "c"]){
//BUI_trace(suit + " " + cards +" " + player);
res+= suit + cards[player][suit];
}
return res;
}
if (BUI_domain == "RB")
{
let res = "";
for (let suit of ["s", "h", "d", "c"]){
res += suit;
for (let rank of ["a", "k", "q", "j", "t", "9", "8", "7", "6", "5", "4", "3", "2" ]){
if (match == BUI_RBAllocateCard(suit+rank))
{
//BUI_trace("matching card " + suit+rank + " match= " + match + " decl= " + BUI_declarer + " player " + player);
res += rank;
}
}
}
//BUI_trace("res calculated " + res);
return res;
}
}
function BUI_RBAllocateCard(card){
var c = document.getElementById("card_" + card);
if (c.style.zIndex < 10)
{//
return "";
}
else if (c.style.zIndex < 120)
{//
return "s" + ( c.style.zIndex -100);
}
else if (c.style.zIndex < 200)
{//
return "dummy";
}
else if (c.style.zIndex < 250)
{//
return "dec-dummy";
}
else if (c.style.zIndex < 1200)
{//
return "p" + ( c.style.zIndex -1100);
}
else if (c.style.zIndex < 95200)
{//
return "dummy";
}
else if (c.style.zIndex < 110000)
{//
return "main";
}
return "";//
}
function BUI_getBidding(){//gets the bidding
if (BUI_domain == "BG") //my webpage
{
//return historial;
let bidding = [];
let cont = true;
let tur = BUI_dealer;
let i=0;
while (cont)
{
//BUI_trace("tur " + tur);
if (historial.length > i*3)
{
let step = historial.substring(i*3 +1, i*3 +3);
bidding.push(step);
tur = BUI_next[tur];
i+=1;
}
else
{
cont = false;
}
}
//BUI_trace("todos han dicho " + bidding.toString());
return bidding;
}
if (BUI_domain == "RB") //realbridge
{
var bids = {};
bids.main = [];
bids.cho = [];
bids.rho = [];
bids.lho = [];
function getCurrentRotation(el){
var st = window.getComputedStyle(el, null);
var tm = st.getPropertyValue("-webkit-transform") ||
st.getPropertyValue("-moz-transform") ||
st.getPropertyValue("-ms-transform") ||
st.getPropertyValue("-o-transform") ||
st.getPropertyValue("transform") ||
"none";
if (tm != "none") {
var values = tm.split('(')[1].split(')')[0].split(',');
/*
a = values[0];
b = values[1];
angle = Math.round(Math.atan2(b,a) * (180/Math.PI));
*/
//return Math.round(Math.atan2(values[1],values[0]) * (180/Math.PI)); //this would return negative values the OP doesn't wants so it got commented and the next lines of code added
var angle = Math.round(Math.atan2(values[1],values[0]) * (180/Math.PI));
return (angle < 0 ? angle + 360 : angle); //adding 360 degrees here when angle < 0 is equivalent to adding (2 * Math.PI) radians before
}
return 0;
}
var imgs = document.querySelectorAll("body img");
for (var i in imgs)
{
if ((imgs[i].id == "") && (imgs[i].src.includes("bidbox/png")))
{
if ((imgs[i].style.zIndex>0) || (imgs[i].style.left.includes("-1000")))
{//its a biddingbox image
}
else
{
var res = 0;
if (imgs[i].src.includes("PASSBB"))
{
res = 0;
}
else if (imgs[i].src.includes("XXBB"))
{
res = -2
}
else if (imgs[i].src.includes("XBB"))
{
res = -1
}
else
{
for (let suit of ["NT", "S", "H", "D", "C"]){
for (let level of ["1", "2", "3", "4", "5", "6", "7"]){
if (imgs[i].src.includes(level + suit + "BB"))
{
if (suit == "NT")
{
res = 5;
}
if (suit == "S")
{
res = 4;
}
if (suit == "H")
{
res = 3;
}
if (suit == "D")
{
res = 2;
}
if (suit == "C")
{
res = 1;
}
res = res + ((level-1) * 5);
}
}
}
}
//res has the bid
let rot = getCurrentRotation(imgs[i]);
let pl = "rho";
if (rot<315)
{
pl = "cho";
}
if (rot<225)
{
pl = "lho";
}
if (rot<135)
{
pl = "main";
}
if (rot<45)
{
pl = "rho";
}
bids[pl].push(res);
}
}
}
//BUI_trace("yo he dicho " + bids.main.toString());
//BUI_trace("tu has dicho " + bids.cho.toString());
//BUI_trace("rho has dicho " + bids.rho.toString());
//BUI_trace("lho has dicho " + bids.lho.toString());
var bidding = [];
var cont = true;
var tur = BUI_dealer;
while (cont)
{
//BUI_trace("tur " + tur);
if (bids[tur].length > 0)
{
var step = bids[tur].shift();
bidding.push(step);
tur = BUI_next[tur];
}
else
{
cont = false;
}
}
//BUI_trace("todos han dicho " + bidding.toString());
return bidding;
}
}
function BUI_getLastTrick(){
if (BUI_domain == "RB")
{
let res = "";
res = {};
let max = 0;
for (let suit of ["s", "h", "d", "c"]){
for (let rank of ["a", "k", "q", "j", "t", "9", "8", "7", "6", "5", "4", "3", "2" ]){
let pos = BUI_RBAllocateCard(suit+rank);
if (pos.charAt(0) == "p")
{// its a card already played
BUI_trace("played card " + suit+rank + " pos= " + pos );
res[pos.substring(1)] = suit+rank;
if (pos.substring(1)>max)
{
max = pos.substring(1);
}
}
}
}
//BUI_trace("res calculated " + res);
BUI_trace("last played card " + res[max]);
var resul = "";
if (max >= 3)
{
resul = res[max-3] + res[max-2] + res[max-1] + res[max]
}
BUI_trace("result = " + resul);
return resul;
}
}
function BUI_readCardAtPos(player){
var card = BUI_CardAtPos(player);
var suit = card[0];
if (BUI_lastSuitRead == suit)
{
BUI_scheduleCard(card, 1);
}
else
{
BUI_lastSuitRead = suit;
BUI_scheduleCard(card, 2);
}
}
function BUI_readLevel(level){
BUI_scheduleSound(BUI_sounds.g[level]);
}
function BUI_readCall(bid){
if (bid == 0)
{
if (BUI_passSwitch == "")
{
BUI_scheduleSound(BUI_sounds.g.pass);
BUI_passSwitch = "2";
}
else
{
BUI_scheduleSound(BUI_sounds.g.pass2);
BUI_passSwitch = "";
}
}
else if (bid == -1)
{
BUI_scheduleSound(BUI_sounds.g.double);
}
else if (bid == -2)
{
BUI_scheduleSound(BUI_sounds.g.redouble);
}
}
function BUI_readSuit(position){
if (position == 1)
{
BUI_scheduleSound(BUI_sounds.g.c);
}
if (position == 2)
{
BUI_scheduleSound(BUI_sounds.g.d);
}
if (position == 3)
{
BUI_scheduleSound(BUI_sounds.g.h);
}
if (position == 4)
{
BUI_scheduleSound(BUI_sounds.g.s);
}
if (position == 5)
{
BUI_scheduleSound(BUI_sounds.g.n);
}
}
function BUI_playCardAtPos(player){
if (BUI_position < 0)
{
if (BUI_domain == "BG")
{
BUI_position = 0;
}
else
{
return;
}
}
var card = BUI_CardAtPos(player);
if (BUI_domain == "BG")
{
BUI_simulateClick("card_"+card);
}
if (BUI_domain == "RB")
{
//BUI_trace("simul " + card);
BUI_simulateClick("card_"+card);
}
}
function BUI_simulateClick(elem){
//BUI_trace("simulate: ");
var node = document.getElementById(elem);
BUI_triggerMostButtons(node);
}
function BUI_simulateClickPos(elem, pos){
//BUI_trace("simulate: ");
var node = document.getElementById(elem);
BUI_triggerMostButtonsPos(node, pos);
}
function BUI_selectLevel(){
if (BUI_domain == "BG") //On bridgegod we do not select bids on 2 steps so do nothing
{
}
if (BUI_domain == "RB") //On bridgegod we do not select bids on 2 steps so do nothing
{
}
}
function BUI_currentTrick(){
if (BUI_domain == "BG") //On bridgegod we do not select bids on 2 steps so do nothing
{
return trick;
}
if (BUI_domain == "RB")
{
let res = {};
for (let suit of ["s", "h", "d", "c"]){
for (let rank of ["a", "k", "q", "j", "t", "9", "8", "7", "6", "5", "4", "3", "2" ]){
let sit = BUI_RBAllocateCard(suit+rank);
//BUI_trace("card: " + suit + rank + " sits at " + sit);
if (sit.charAt(0) == "s")
{//its a card fromt the current trick, IE s0, s1, s2 or s3
res[sit.charAt(1)] = suit+rank;
}
}
}
var result = "";
let j = 0;
while (res.hasOwnProperty(j))
{
result = result + res[j];
j++;
}
//BUI_trace("trick: " + result);
return result;
}
}
function BUI_selectSuit(){
if (BUI_position <2){//click space before selecting = clubs
BUI_position = 1;
}
var bid = (BUI_bid_level-1)*5 + BUI_position;
if (BUI_domain == "BG")
{
BUI_simulateClick("bid"+bid);
return bid;
}
if (BUI_domain == "RB")
{
var elem = "bid"+bid;
var node = document.getElementById(elem);
var rect = node.getBoundingClientRect();
var wide = rect.right - rect.left;
var pos = rect.right - wide * ((BUI_position *2) -1) /10;
BUI_simulateClickPos(elem, pos);
return bid;
}
}
function BUI_selectCall(){
var call ="";
if (BUI_position == 0)
{
call = "pass";
}
if (BUI_position == -1)
{
call = "double";
}
if (BUI_position == -2)
{
call = "redouble";
}
var elem = "b"+call;
var node = document.getElementById(elem);
var rect = node.getBoundingClientRect();
var wide = rect.right - rect.left;
var pos = rect.right - (wide /2);
if (BUI_domain == "BG")
{
BUI_simulateClick("b"+call);
}
if (BUI_domain == "RB")
{
if (BUI_position == 0)
{
BUI_simulateClickPos("b"+call, pos );
}
if (BUI_position == -1)
{
BUI_simulateClickPos("b"+call, rect.right -5 );
}
if (BUI_position == -2)
{
BUI_simulateClickPos("b"+call, rect.left +5 );
}
}
}
function BUI_readBid(bid){
if (bid>0)//normal bid
{
var suit = bid % 5;
if (suit == 0)
{
suit= 5;
}
var level = Math.trunc((bid-1)/5) +1;
//BUI_trace("level = " + level);
//BUI_trace("suit = " + suit);
BUI_readLevel(level);
BUI_readSuit(suit);
}
else
{//pass, double or redouble
BUI_readCall(bid);
}
}
//waitForKeyElements ("#dispatchOnJobButton", triggerMostButtons);
function BUI_triggerMostButtons(jNode) {
//BUI_trace("event_send: ");
//BUI_triggerMouseEvent (jNode, "mouseover");
BUI_triggerMouseEvent (jNode, "mousemove"); // en RB esto selecciona una voz
BUI_triggerMouseEvent (jNode, "mousedown");
BUI_triggerMouseEvent (jNode, "mouseup");
BUI_triggerMouseEvent (jNode, "mousemove"); // en RB esto selecciona una voz
BUI_triggerMouseEvent (jNode, "click");
}
function BUI_triggerMostButtonsPos(jNode, pos) {
BUI_triggerMouseEventPos (jNode, "mousemove", pos); // on RB this selects a bid or card
BUI_triggerMouseEventPos (jNode, "mousedown", pos);
BUI_triggerMouseEventPos (jNode, "mouseup", pos);
BUI_triggerMouseEventPos (jNode, "click", pos);
}
function BUI_triggerMouseEvent (node, eventType) {
var rect = node.getBoundingClientRect();
// var clickEvent = document.createEvent('MouseEvents');
var clickEvent = new MouseEvent(eventType, {
clientX:(rect.left *1) + 5,
clientY:(rect.top *1) + 5,
bubbles: true,
cancelable: true,
view: window
});
//clickEvent.initEvent (eventType, true, true);
//BUI_trace("event: " + clickEvent.pageX + ", " + clickEvent.pageY + " " + eventType);
node.dispatchEvent (clickEvent);
document.body.dispatchEvent (clickEvent);
document.dispatchEvent (clickEvent);
}
function BUI_triggerMouseEventPos (node, eventType, pos) {
var rect = node.getBoundingClientRect();
// var clickEvent = document.createEvent('MouseEvents');
var clickEvent = new MouseEvent(eventType, {
clientX:pos,
clientY:(rect.top *1) + 15,
bubbles: true,
cancelable: true,
view: window
});
BUI_trace("event: " + clickEvent.pageX + ", " + clickEvent.pageY + " " + eventType);
node.dispatchEvent (clickEvent);
document.body.dispatchEvent (clickEvent);
document.dispatchEvent (clickEvent);
}
function BUI_CardAtPos(player){
var totalcards = BUI_calcualteCards(player)
var suit ="";
var extra = 1;
for (var i=0; i< (BUI_position + extra); i++)
{
//BUI_trace("iteracion " + i + " extra = " + extra + " card = " + totalcards[i]);
if ((totalcards[i] == 's') || (totalcards[i] == 'h') || (totalcards[i] == 'd') || (totalcards[i] == 'c'))
{//new suit
suit = totalcards[i];
extra+=1;
}
}
return suit + totalcards[i-1];
}
function BUI_playables(totalcards){
let turn = BUI_WhosTurn();
if ((turn == 'main') || ((turn == 'cho') && (BUI_declarer = 'main')))
{
let trick = BUI_currentTrick();
let suit = "";
let playable = "";
if ((trick.length >0) && (trick.length <8)) //trick length 8 means tricks is donw and we lead on next
{
suit = trick.charAt(0);
var rh = totalcards.split(suit)
var r1 = rh[1].split('s');
var r2 = r1[0].split('h');
var r3 = r2[0].split('d');
var r4 = r3[0].split('c');
playable = r4[0];
if (playable == "") {return totalcards};
var ss = "shdc";
var insert = ss.split(suit)
var res = suit + playable ;
return res;
}
else
{
return totalcards;
}
BUI_trace("playab " + playable);
BUI_trace("suit " + suit);
}
else
{
return "";
}
}
function BUI_placeConsole()
{
let ele = document.getElementById("BUI_console");
if (ele == null)
{
return;
}
if (BUI_consoleP == 0)
{
ele.style.opacity = "0";
}
else
{
ele.style.opacity = "1";
}
if (BUI_consoleP == 1)
{
ele.style.top ="0";
ele.style.bottom = null;
ele.style.left ="0";
ele.style.right = null;
}
if (BUI_consoleP == 2)
{
ele.style.top = null;
ele.style.bottom = "0";
ele.style.left ="0";
ele.style.right = null;
}
if (BUI_consoleP == 3)
{
ele.style.top = null;
ele.style.bottom = "0";
ele.style.left =null;
ele.style.right = "0";
}
if (BUI_consoleP == 4)
{
ele.style.top = 0;
ele.style.bottom = null;
ele.style.left =null;
ele.style.right = "0";
}
}
function BUI_keyboardHandlerJQ (zEvent) {
var bBlockDefaultAction = false;
if (document.activeElement.type == "text")
{//let people write on textbox
return;
}
//--- Assume we want only the plain keys, not the modified versions.
if (zEvent.altKey || zEvent.ctrlKey || zEvent.shiftKey) {
//-- Do nothing
}
else {
//console.log ("event = " + zEvent.which);
BUI_checkStatus();
if (zEvent.which == LEFT_KEY) {
//DO LEFT KEY ACTION HERE.
console.log ("Left arrow pressed.");
if (BUI_status == 2)//card play
{
let turn = BUI_WhosTurn();
if ((turn == 'main') || ((turn == 'cho') && (BUI_declarer = 'main')))
{
var min, max;
let totalcards = BUI_calcualteCards(turn)
let playablecards = BUI_playables(totalcards);
if (playablecards == totalcards)
{
min = 0;
max = totalcards.length - 5;
}
else
{
var suit = playablecards.charAt(0);
var rh = totalcards.split(suit)
rh[0] = rh[0].replace("s", "");
rh[0] = rh[0].replace("h", "");
rh[0] = rh[0].replace("d", "");
min = rh[0].length; //cards to the left of suit
rh[1] = rh[1].replace("c", "");
rh[1] = rh[1].replace("h", "");
rh[1] = rh[1].replace("d", "");
max = totalcards.length - rh[1].length + playablecards.length -6 ;
}
//BUI_trace("total " + totalcards + "playable " + playablecards.length + " min = " + min + " max = "+ max);
BUI_position --;
if (BUI_position < min)
{
BUI_position = max; //last position is length minus shdc
}
if (BUI_position > max) //last position is length minus shdc
{
BUI_position = max;
}
BUI_readCardAtPos(BUI_WhosTurn());
}
}
if ((BUI_status == 1)&& (BUI_WhosTurn()=='main'))// Bidding
{
if (BUI_bid_level == 0)//bid level not yet selected
{
BUI_position --;
if (BUI_position < 1)
{
BUI_position = 7; //last position is length minus shdc
}
BUI_readLevel(BUI_position);
}
else
{//selecting the suit
BUI_position --;
if (BUI_position < 1)
{
BUI_position = 5; //last position is no trump
}
BUI_readSuit(BUI_position);
}
}
bBlockDefaultAction = true;
}
else if (zEvent.which == RIGHT_KEY) {
//DO RIGHT KEY ACTION HERE.
console.log ("Right arrow pressed.");
if (BUI_status == 2)//card play
{
let turn = BUI_WhosTurn();
if ((turn == 'main') || ((turn == 'cho') && (BUI_declarer = 'main')))
{
let min, max;
let totalcards = BUI_calcualteCards(turn)
let playablecards = BUI_playables(totalcards);
if (playablecards == totalcards)
{
min = 0;
max = totalcards.length - 5;
}
else
{
let suit = playablecards.charAt(0);
let rh = totalcards.split(suit)
rh[0] = rh[0].replace("s", "");
rh[0] = rh[0].replace("h", "");
rh[0] = rh[0].replace("d", "");
min = rh[0].length; //cards to the left of suit
rh[1] = rh[1].replace("c", "");
rh[1] = rh[1].replace("h", "");
rh[1] = rh[1].replace("d", "");
max = totalcards.length - rh[1].length + playablecards.length -6 ;
}
BUI_position ++;
if (BUI_position < min)
{
BUI_position = min; //last position is length minus shdc
}
if (BUI_position > max) //last position is length minus shdc
{
BUI_position = min;
}
BUI_readCardAtPos(BUI_WhosTurn());
}
}
if ((BUI_status == 1)&& (BUI_WhosTurn()=='main'))// Bidding
{
if (BUI_bid_level == 0)//bid level not yet selected
{
if (BUI_position < 1)
{
BUI_position = 1; //last position is length minus shdc
}
else
{
BUI_position++;
if (BUI_position >7)
{
BUI_position = 1;
}
}
BUI_readLevel(BUI_position);
}
else
{//selecting the suit
BUI_position ++;
if (BUI_position > 5)
{
BUI_position = 1; //last position is no trump
}
BUI_readSuit(BUI_position);
}
}
bBlockDefaultAction = true;
}
else if (zEvent.which == UP_KEY) {
//DO RIGHT KEY ACTION HERE.
console.log ("Up arrow pressed.");
if (BUI_status == 2)//card play
{
let turn = BUI_WhosTurn();
if ((turn == 'main') || ((turn == 'cho') && (BUI_declarer = 'main')))
{
let min, max;
let totalcards = BUI_calcualteCards(turn)
let playablecards = BUI_playables(totalcards);
if (playablecards == totalcards)
{
min = 0;
max = totalcards.length - 5;
let card = BUI_CardAtPos(turn)
let orig = card.charAt(0);
let con = true;
while (con)
{
BUI_position ++ ;
if (BUI_position > max) //last position is length minus shdc
{
BUI_position = min;
con = false;
}
card = BUI_CardAtPos(turn);
if (orig != card.charAt(0))
{
con = false;
}
}
}
else
{//no effect when only a suit can be played
return
}
BUI_readCardAtPos(BUI_WhosTurn());
}
}
if ((BUI_status == 1)&& (BUI_WhosTurn()=='main'))// Bidding
{
if (BUI_bid_level == 0)//bid level not yet selected
{
if (BUI_position < 1)
{
BUI_position --;
if (BUI_position < -2)
{
BUI_position = 0;
}
}
else
{
BUI_position = 0;
}
BUI_readCall(BUI_position);
}
else
{//selecting the suit
}
}
bBlockDefaultAction = true;
}
else if (zEvent.which == DOWN_KEY) {
//DO RIGHT KEY ACTION HERE.
console.log ("Down arrow pressed.");
if (BUI_status == 2)//card play
{
let turn = BUI_WhosTurn();
if ((turn == 'main') || ((turn == 'cho') && (BUI_declarer = 'main')))
{
let min, max;
let totalcards = BUI_calcualteCards(turn)
let playablecards = BUI_playables(totalcards);
if (playablecards == totalcards)
{
min = 0;
max = totalcards.length - 5;
let card = BUI_CardAtPos(turn)
let orig = card.charAt(0);
let con = true;
while (con)
{
BUI_position -- ;
if (BUI_position < min) //last position is length minus shdc
{
BUI_position = max;
con = false;
}
card = BUI_CardAtPos(turn);
if (orig != card.charAt(0))
{
con = false;
}
}
}
else
{//no effect when only a suit can be played
return
}
BUI_readCardAtPos(BUI_WhosTurn());
}
}
if ((BUI_status == 1)&& (BUI_WhosTurn()=='main'))// Bidding
{
if (BUI_bid_level == 0)//bid level not yet selected
{
if (BUI_position < 1)
{
BUI_position ++;
if (BUI_position > 0)
{
BUI_position = -2;
}
}
else
{
BUI_position = 0;
}
BUI_readCall(BUI_position);
}
else
{//selecting the suit
}
}
bBlockDefaultAction = true;
}
else if (zEvent.which == ACTION_KEY) {
//selects the current card to be played
BUI_trace("ACTION_KEY pressed.");
if (BUI_status == 2)//card play
{
BUI_playCardAtPos(BUI_WhosTurn());
BUI_position = -1;//current cursor position
BUI_lastSuitRead ="";
}
if ((BUI_status == 1)&& (BUI_WhosTurn()=='main'))// Bidding
{
if (BUI_bid_level ==0) //we are selecting the level
{
if (BUI_position < 1){ //it is a call
BUI_selectCall();
//BUI_readCall(BUI_position); Narrator does this for us
BUI_bid_level = 0;
BUI_position = 0;
}
else
{
BUI_bid_level = BUI_position;
BUI_position = 0;
BUI_selectLevel();
BUI_readLevel(BUI_bid_level)
}
}
else
{//we are selecting a suit, and thus a full bid.
var bid = BUI_selectSuit();
//BUI_readBid(bid); Narrator does this for us
BUI_bid_level = 0;
BUI_position = 0;
}
}
bBlockDefaultAction = true;
}
else if (zEvent.which == NEW_AUDIO_KEY) {
//CANCELS SCHEDULED SOUNDS.
console.log ("NEW AUDIO pressed.");
BUI_audio ++;
BUI_audiofinnish = 0;
bBlockDefaultAction = true;
}
else if (zEvent.which == UNDO_KEY) {
//REQUESTS UNDO UNLESS WE JUST SELECTED A LEVEL OF BIDDING ON 2-STEP MECHANISM, THEN IT MOVES BACK TO LEVEL SELECTION
console.log ("UNDO KEY pressed.");
if ((BUI_status == 1)&& (BUI_bid_level !=0))// Bidding
{
//we are selecting the level
BUI_bid_level = 0;
// On bridgebase we might have to do something else
}
else
{// we need to request undo
BUI_requestUndo();
}
bBlockDefaultAction = true;
}
else if (zEvent.which == LOGIN_KEY) {
//REQUESTS UNDO UNLESS WE JUST SELECTED A LEVEL OF BIDDING ON 2-STEP MECHANISM, THEN IT MOVES BACK TO LEVEL SELECTION
console.log ("LOGIN KEY pressed.");
BUI_login();
bBlockDefaultAction = true;
}
else if (zEvent.which == BID_KEY) {
//READS THE BIDDING.
console.log ("BID KEY pressed.");
var bidding = BUI_getBidding();
for (var b in bidding)
{
BUI_readBid(bidding[b])
}
bBlockDefaultAction = true;
}
else if (zEvent.which == HAND_KEY) {
//Reads own hand.
if (BUI_domain == "BG")
{
BUI_readplayer(cards.main);
}
if (BUI_domain == "RB")
{
BUI_readplayer(BUI_formatAtoB(BUI_calcualteCards('main')));
}
BUI_trace("HAND_FULL_KEY pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == DUMMY_KEY) {
//Reads dummy unless dummy is us, then it reads partner(declarer)
BUI_checkStatus();
if (BUI_status == 2)//card play
{
if (BUI_domain == "BG")
{
if (BUI_declarer == "cho")
{//partner is declarer therefore we show declarer as dummy
BUI_readplayer(cards.cho);
}
else
{
BUI_readplayer(cards[partner[declarer]]);
}
}
if (BUI_domain == "RB")
{
var dummy = BUI_partner[BUI_declarer];
if (dummy == "main")
{
dummy = "cho";
}
BUI_readplayer(BUI_formatAtoB(BUI_calcualteCards(dummy)));
}
}
BUI_trace("DUMMY_KEY pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == HAND_S_KEY) {
//Reads spades from hand.
let card;
if (BUI_domain == "BG")
{
card =cards.main;
//BUI_readplayer(cards.main);
}
if (BUI_domain == "RB")
{
card = BUI_formatAtoB(BUI_calcualteCards('main'));
}
BUI_readsuit(card, "s");
BUI_trace("HAND_SUIT_KEY_S pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == HAND_H_KEY) {
//Reads spades from hand.
let card;
if (BUI_domain == "BG")
{
card =cards.main;
//BUI_readplayer(cards.main);
}
if (BUI_domain == "RB")
{
card = BUI_formatAtoB(BUI_calcualteCards('main'));
}
BUI_readsuit(card, "h");
BUI_trace("HAND_SUIT_KEY_H pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == HAND_D_KEY) {
//Reads spades from hand.
let card;
if (BUI_domain == "BG")
{
card =cards.main;
//BUI_readplayer(cards.main);
}
if (BUI_domain == "RB")
{
card = BUI_formatAtoB(BUI_calcualteCards('main'));
}
BUI_readsuit(card, "d");
BUI_trace("HAND_SUIT_KEY_D pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == HAND_C_KEY) {
//Reads spades from hand.
let card;
if (BUI_domain == "BG")
{
card =cards.main;
//BUI_readplayer(cards.main);
}
if (BUI_domain == "RB")
{
card = BUI_formatAtoB(BUI_calcualteCards('main'));
}
BUI_readsuit(card, "c");
BUI_trace("HAND_SUIT_KEY_C pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == DUMMY_S_KEY) {
//Reads dummy unless dummy is us, then it reads partner(declarer)
BUI_checkStatus();
if (BUI_status == 2)//card play
{
let card;
if (BUI_domain == "BG")
{
if (BUI_declarer == "cho")
{//partner is declarer therefore we show declarer as dummy
card = cards.cho;
}
else
{
card = cards[partner[declarer]];
}
}
if (BUI_domain == "RB")
{
let dummy = BUI_partner[BUI_declarer];
if (dummy == "main")
{
dummy = "cho";
}
card = BUI_formatAtoB(BUI_calcualteCards(dummy));
}
BUI_readsuit(card, "s");
}
BUI_trace("DUMMY_KEY pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == DUMMY_H_KEY) {
//Reads dummy unless dummy is us, then it reads partner(declarer)
BUI_checkStatus();
if (BUI_status == 2)//card play
{
let card;
if (BUI_domain == "BG")
{
if (BUI_declarer == "cho")
{//partner is declarer therefore we show declarer as dummy
card = cards.cho;
}
else
{
card = cards[partner[declarer]];
}
}
if (BUI_domain == "RB")
{
let dummy = BUI_partner[BUI_declarer];
if (dummy == "main")
{
dummy = "cho";
}
card = BUI_formatAtoB(BUI_calcualteCards(dummy));
}
BUI_readsuit(card, "h");
}
BUI_trace("DUMMY_KEY pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == DUMMY_D_KEY) {
//Reads dummy unless dummy is us, then it reads partner(declarer)
BUI_checkStatus();
if (BUI_status == 2)//card play
{
let card;
if (BUI_domain == "BG")
{
if (BUI_declarer == "cho")
{//partner is declarer therefore we show declarer as dummy
card = cards.cho;
}
else
{
card = cards[partner[declarer]];
}
}
if (BUI_domain == "RB")
{
let dummy = BUI_partner[BUI_declarer];
if (dummy == "main")
{
dummy = "cho";
}
card = BUI_formatAtoB(BUI_calcualteCards(dummy));
}
BUI_readsuit(card, "d");
}
BUI_trace("DUMMY_KEY pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == DUMMY_C_KEY) {
//Reads dummy unless dummy is us, then it reads partner(declarer)
BUI_checkStatus();
if (BUI_status == 2)//card play
{
let card;
if (BUI_domain == "BG")
{
if (BUI_declarer == "cho")
{//partner is declarer therefore we show declarer as dummy
card = cards.cho;
}
else
{
card = cards[partner[declarer]];
}
}
if (BUI_domain == "RB")
{
let dummy = BUI_partner[BUI_declarer];
if (dummy == "main")
{
dummy = "cho";
}
card = BUI_formatAtoB(BUI_calcualteCards(dummy));
}
BUI_readsuit(card, "c");
}
BUI_trace("DUMMY_KEY pressed.");
bBlockDefaultAction = true;
}
else if (zEvent.which == TRICK_KEY) {
//Reads the current trick cards.
BUI_trace("TRICK_KEY pressed.");
if (BUI_status == 2)//card play
{
var trick = BUI_currentTrick();
BUI_readtrick(trick);
}
if (BUI_status == 1)//bidding
{
let bidding = BUI_getBidding();
if (bidding.length >4)
{
for (let b =bidding.length -4; b < bidding.length; b++)
{
BUI_readBid(bidding[b])
}
}
else
{
for (let b in bidding)
{
BUI_readBid(bidding[b])
}
}
}
bBlockDefaultAction = true;
}
else if (zEvent.which == MUTE_KEY) {
//MUTEs /Unmutes everyone.
BUI_trace("MUTE_KEY pressed.");
if (BUI_domain == "RB") //
{//
BUI_mute("partner");
BUI_mute("rho");
BUI_mute("lho");
}
bBlockDefaultAction = true;
}
else if (zEvent.which == CLAIM_KEY) {
//MUTEs /Unmutes everyone.
BUI_trace("CLAIM_KEY pressed.");
if (BUI_domain == "RB") //
{//
BUI_claim();
}
if (BUI_domain == "BG") //
{//
BUI_claim();
}
bBlockDefaultAction = true;
}
else if (zEvent.which == CONSOLE_KEY) {
//changes teh console position.
BUI_trace("CONSOLE_KEY pressed.");
BUI_consoleP++;
if (BUI_consoleP > 4)
{
BUI_consoleP = 0;
}
BUI_placeConsole()
//BUI_trace("pos = " + BUI_consoleP);
GM_setValue('consoleP', BUI_consoleP);
bBlockDefaultAction = true;
}
else if (zEvent.which == LANG_KEY) {
//changes language.
BUI_trace("LANG_KEY pressed.");
BUI_lang++;
if (BUI_lang > 2)
{
BUI_lang = 0;
}
BUI_loadLang();
GM_setValue('lang', BUI_lang);
bBlockDefaultAction = true;
}
}
if (bBlockDefaultAction) {
zEvent.preventDefault ();
zEvent.stopPropagation ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment