120 lines
3.9 KiB
HTML
120 lines
3.9 KiB
HTML
<html>
|
|
<head>
|
|
<title>Deckard + Company</title>
|
|
<link href="css.css" rel="stylesheet">
|
|
<script src="https://labs.murkfall.net/bluesaxman/blue.js/raw/master/libs/bluecore.js"></script>
|
|
</head>
|
|
<body>
|
|
<h1>Welcome to Deckard + Company<h1>
|
|
</body>
|
|
<script>
|
|
|
|
window.server = "ws://localhost:8080/";
|
|
window.gameState = {};
|
|
window.gameState.deck = [];
|
|
window.gameState,pool = [];
|
|
window.hand = [];
|
|
|
|
function updateEvent() {
|
|
window.UI.deck.innerHTML = "";
|
|
window.UI.hand.innerHTML = "";
|
|
var theDeck = elementPlace("#deck","deckDisp","card","div");
|
|
theDeck.innerHTML = "<div>"+window.gameState.deck.length+"</div>";
|
|
window.hand.forEach(function (card,index) {
|
|
if (index < 10) {
|
|
var currentCard = elementPlace("#hand",null,"card","li");
|
|
currentCard.innerHTML = card;
|
|
}
|
|
});
|
|
}
|
|
|
|
function startGameSession() {
|
|
window.gameSession = new WebSocket(server);
|
|
gameSession.onmessage = function (event) {
|
|
var message = JSON.parse(event.data);
|
|
if (message.state) { gameState = message.state; updateEvent(); }
|
|
if (message.userID) { window.userID = message.userID; }
|
|
if (message.message) { console.log(message.message); }
|
|
if (message.command) {
|
|
if ("requestState" == message.command) {
|
|
sendGameState();
|
|
}
|
|
}
|
|
if (message.request) {
|
|
if ("session" == message.request) { mytest.send('{"session":'+window.gameState.session+'}'); }
|
|
if ("user" == message.request) { mytest.send('{"user":'+window.gameState.user+'}'); }
|
|
if ("join" == message.request) { mytest.send('{"action":"join"}'); }
|
|
if ("update" == message.request) { mytest.send('{"action":"update"}'); }
|
|
}
|
|
console.log(message);
|
|
};
|
|
gameSession.onconnect = function () {
|
|
gameSession.send('{"type":"update","command":"requestState"}');
|
|
};
|
|
gameSession.onclose = function (event) {
|
|
console.log(event);
|
|
};
|
|
}
|
|
|
|
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");
|
|
elementPlace("body","display",null,"div");
|
|
window.UI = {};
|
|
window.UI.deck = elementPlace("#display","deck",null,"div");
|
|
window.UI.hand = elementPlace("#display","hand",null,"ol");
|
|
var parms = new URLSearchParams(window.location.search);
|
|
if (parms.get("s")) {
|
|
window.gameState.session = parms.get("s");
|
|
} else {
|
|
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;
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
</html>
|