2020-06-09 13:48:19 -06:00
< html >
< head >
2020-09-02 11:48:56 -06:00
< title > Deckard + Company< / title >
2020-06-09 13:48:19 -06:00
< link href = "css.css" rel = "stylesheet" >
< script src = "https://labs.murkfall.net/bluesaxman/blue.js/raw/master/libs/bluecore.js" > < / script >
< / head >
< body >
2020-09-02 11:48:56 -06:00
< h1 > Welcome to Deckard + Company< h1 >
2020-06-09 13:48:19 -06:00
< / body >
< script >
2020-09-02 15:26:46 -06:00
window . server = "ws://localhost:8080/" ;
2020-09-02 11:48:56 -06:00
window . gameState = { } ;
2020-09-11 12:12:08 -06:00
window . gameState . users = [ ] ;
window . gameState . decks = [ ] ;
window . gameState . pools = [ ] ;
window . gameState . hands = [ ] ;
2020-06-09 13:48:19 -06:00
function updateEvent ( ) {
2020-09-11 12:12:08 -06:00
window . UI . users . innerHTML = "<span>Users:</span>" ;
window . UI . decks . innerHTML = "<span>Decks:</span>" ;
window . UI . hands . innerHTML = "<span>Hands:</span>" ;
window . UI . pools . innerHTML = "<span>Pools:</span>" ;
window . gameState . users . forEach ( function ( user ) {
window . UI . users [ user ] = elementPlace ( "#users" , "User_" + user , "username" , "li" ) ;
window . UI . users [ user ] . innerText = user ;
2020-06-09 13:48:19 -06:00
} ) ;
2020-09-11 12:12:08 -06:00
Object . keys ( window . gameState . decks ) . forEach ( function ( deckID ) {
var deck = window . gameState . decks [ deckID ] ;
window . UI . decks [ deckID ] = elementPlace ( "#decks" , "Deck_" + deck . name , "deck" , "li" ) ;
window . UI . decks [ deckID ] . innerText = deck . name + ":" + deck . size ;
} ) ;
Object . keys ( window . gameState . hands ) . forEach ( function ( handID ) {
var hand = window . gameState . hands [ handID ] ;
window . UI . hands [ handID ] = elementPlace ( "#hands" , "Hand_" + hand . name , "hand" , "li" ) ;
window . UI . hands [ handID ] . innerText = hand . name ;
window . UI . hands [ handID ] . cards = elementPlace ( "#Hand_" + hand . name , hand . name + "_cards" , null , "ol" ) ;
hand . cards . forEach ( function ( card , index ) {
window . UI . hands [ handID ] . cards [ index ] = elementPlace ( "#" + hand . name + "_cards" , null , "card" , "li" ) ;
window . UI . hands [ handID ] . cards [ index ] . innerHTML = card ;
} ) ;
} ) ;
Object . keys ( window . gameState . pools ) . forEach ( function ( poolID ) {
var pool = window . gameState . pools [ poolID ] ;
window . UI . pools [ poolID ] = elementPlace ( "#pools" , "Pool_" + pool . name , "pool" , "li" ) ;
window . UI . pools [ poolID ] . innerText = pool . name + ":" + pool . top ;
} ) ;
2020-06-09 13:48:19 -06:00
}
2020-09-02 15:26:46 -06:00
function startGameSession ( ) {
2020-09-10 11:48:31 -06:00
window . gameSession = new WebSocket ( server ) ;
2020-09-02 15:26:46 -06:00
gameSession . onmessage = function ( event ) {
var message = JSON . parse ( event . data ) ;
if ( message . userID ) { window . userID = message . userID ; }
if ( message . message ) { console . log ( message . message ) ; }
2020-09-11 12:12:08 -06:00
if ( message . request ) {
if ( "session" == message . request ) { window . gameSession . send ( '{"session":' + window . gameState . session + '}' ) ; }
if ( "user" == message . request ) { window . gameSession . send ( '{"user":"' + window . gameState . user + '"}' ) ; }
if ( "join" == message . request ) { window . gameSession . send ( '{"action":"join"}' ) ; }
if ( "update" == message . request ) { window . gameSession . send ( '{"action":"update"}' ) ; }
}
if ( message . users ) { window . gameState . users = message . users ; updateEvent ( ) ; }
if ( message . decks ) { window . gameState . decks = message . decks ; updateEvent ( ) ; }
if ( message . pools ) { window . gameState . pools = message . pools ; updateEvent ( ) ; }
if ( message . hands ) { window . gameState . hands = message . hands ; updateEvent ( ) ; }
if ( message . action ) {
if ( "addCard" == message . action ) {
window . gameState . hands [ message . hand ] . cards . push ( message . card ) ;
updateEvent ( ) ;
2020-09-02 15:26:46 -06:00
}
}
2020-09-10 11:48:31 -06:00
console . log ( message ) ;
2020-09-11 12:12:08 -06:00
2020-09-02 15:26:46 -06:00
} ;
2020-09-11 12:12:08 -06:00
gameSession . onconnect = function ( ) { } ;
2020-09-02 15:26:46 -06:00
gameSession . onclose = function ( event ) {
console . log ( event ) ;
} ;
}
2020-09-11 12:12:08 -06:00
//elementPlace("body","menu",null,"div");
//buttonAdd("#menu","upload","Upload Deck", function () {
// popupDialog("deckLoader","Select Deck definition File",true,inputDialog,{"inputType":"file"},function (f) {
// var myFile = new FileReader();
// myFile.onload = function (file) {
// // Probably validate the file somehow befor eating it
// var ourFile = JSON.parse(file.target.result);
// window.gameState.deck = [];
// deckFromJSON(ourFile);
// window.hand = [];
// sendGameState();
// }
// myFile.readAsText(f[0]);
// });
//},null,"div");
//buttonAdd("#menu","add","Add Deck", function () {
// popupDialog("deckLoader","Select Deck definition to add",true,inputDialog,{"inputType":"file"},function (f) {
// var myFile = new FileReader();
// myFile.onload = function (file) {
// var ourFile = JSON.parse(file.target.result);
// deckFromJSON(ourFile);
// sendGameState();
// }
// myFile.readAsText(f[0]);
//});
//}, null, "div");
//buttonAdd("#menu","shuffle", "Shuffle Deck", function () {
// shuffleDeck(window.gameState.deck);
// sendGameState();
//}, null, "div");
//buttonAdd("#menu","shuffleAll", "Shuffle Hand to Deck", function () {
// window.gameState.deck = window.gameState.deck.concat(window.hand);
// window.hand = [];
// shuffleDeck(window.gameState.deck);
// sendGameState();
//}, null, "div");
//buttonAdd("#menu","draw", "Draw Card", function () {
// if (window.gameState.deck.length > 0) {
// window.hand.unshift(window.gameState.deck.shift());
// sendGameState();
// }
//}, null, "div");
2020-06-09 13:48:19 -06:00
elementPlace ( "body" , "display" , null , "div" ) ;
window . UI = { } ;
2020-09-11 12:12:08 -06:00
window . UI . users = elementPlace ( "#display" , "users" , null , "ol" ) ;
window . UI . decks = elementPlace ( "#display" , "decks" , null , "ol" ) ;
window . UI . hands = elementPlace ( "#display" , "hands" , null , "ol" ) ;
window . UI . pools = elementPlace ( "#display" , "pools" , null , "ol" ) ;
2020-09-10 11:48:31 -06:00
var parms = new URLSearchParams ( window . location . search ) ;
2020-09-11 12:12:08 -06:00
if ( ! parms . get ( "s" ) ) {
2020-09-10 11:48:31 -06:00
popupDialog ( "gettingStarted" , "Welcome to Deckard and company" , false , inputDialog , { "content" : "Please enter a game ID or leave blank to start a new game" , "inputType" : "number" } ,
function ( value ) {
if ( Number . isInteger ( Number . parseInt ( value ) ) ) {
window . gameState . session = Number . parseInt ( value ) ;
} else {
window . gameState . session = null ;
}
2020-09-11 12:12:08 -06:00
window . location . search = '?s=' + window . gameState . session ;
// window.location.reload();
2020-09-10 11:48:31 -06:00
} ) ;
2020-09-11 12:12:08 -06:00
} else {
window . gameState . session = parms . get ( "s" ) ;
if ( ! window . gameState . user ) {
popupDialog ( "gettingStarted" , "Welcome to Deckard and company" , false , inputDialog , { "content" : "Please enter a username" , "inputType" : "text" } ,
function ( value ) {
if ( ( null != value ) && ( "" != value ) ) {
window . gameState . user = value ;
} else {
window . gameState . user = "Unknown" + ( new Date ( ) ) . getTime ( ) ;
}
startGameSession ( ) ;
} ) ;
} else { startGameSession ( ) ; }
2020-09-10 11:48:31 -06:00
}
2020-06-09 13:48:19 -06:00
< / script >
< / html >