mirror of
https://forge.murkfall.net/bluesaxman/deckard-and-company.git
synced 2026-03-13 08:54:20 -06:00
Codebase Nuke... things got too tangled
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
</body>
|
||||
<script>
|
||||
|
||||
window.server = "ws://localhost:8080/";
|
||||
window.gameState = {};
|
||||
window.gameState.deck = [];
|
||||
window.gameState,pool = [];
|
||||
@@ -27,6 +28,31 @@ function updateEvent() {
|
||||
});
|
||||
}
|
||||
|
||||
function sendGameState() {
|
||||
gameSession.send('{"type":"update","state":'+JSON.stringify(window.gameState)+'}');
|
||||
}
|
||||
|
||||
function startGameSession() {
|
||||
window.gameSession = new WebSocket(server+gameID);
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
gameSession.onconnect = function () {
|
||||
gameSession.send('{"type":"update","command":"requestState"}');
|
||||
};
|
||||
gameSession.onclose = function (event) {
|
||||
console.log(event);
|
||||
};
|
||||
}
|
||||
|
||||
function generateDeck(DDF) {
|
||||
var cards = [""];
|
||||
for (var attribute in DDF) {
|
||||
@@ -42,12 +68,7 @@ function generateDeck(DDF) {
|
||||
}
|
||||
|
||||
function shuffleDeck(deck) {
|
||||
deck.forEach(function (card,index) {
|
||||
var swapCardIndex = Math.floor( Math.random() * deck.length );
|
||||
var swapCard = deck[swapCardIndex];
|
||||
deck[swapCardIndex] = card;
|
||||
deck[index] = swapCard;
|
||||
});
|
||||
gameSession.send('{"type":"action","action":"shuffle"}');
|
||||
}
|
||||
|
||||
function deckFromJSON(ourFile) {
|
||||
@@ -70,7 +91,7 @@ buttonAdd("#menu","upload","Upload Deck", function () {
|
||||
window.gameState.deck = [];
|
||||
deckFromJSON(ourFile);
|
||||
window.hand = [];
|
||||
gameSession.send('{"state":'+JSON.stringify(window.gameState)+'}');
|
||||
sendGameState();
|
||||
}
|
||||
myFile.readAsText(f[0]);
|
||||
});
|
||||
@@ -81,25 +102,25 @@ buttonAdd("#menu","add","Add Deck", function () {
|
||||
myFile.onload = function (file) {
|
||||
var ourFile = JSON.parse(file.target.result);
|
||||
deckFromJSON(ourFile);
|
||||
gameSession.send('{"state":'+JSON.stringify(window.gameState)+'}');
|
||||
sendGameState();
|
||||
}
|
||||
myFile.readAsText(f[0]);
|
||||
});
|
||||
}, null, "div");
|
||||
buttonAdd("#menu","shuffle", "Shuffle Deck", function () {
|
||||
shuffleDeck(window.gameState.deck);
|
||||
gameSession.send('{"state":'+JSON.stringify(window.gameState)+'}');
|
||||
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);
|
||||
gameSession.send('{"state":'+JSON.stringify(window.gameState)+'}');
|
||||
sendGameState();
|
||||
}, null, "div");
|
||||
buttonAdd("#menu","draw", "Draw Card", function () {
|
||||
if (window.gameState.decks[0].length > 0) {
|
||||
window.hand.unshift(window.gameState.decks[0].shift());
|
||||
gameSession.send('{"state":'+JSON.stringify(window.gameState)+'}');
|
||||
if (window.gameState.deck.length > 0) {
|
||||
window.hand.unshift(window.gameState.deck.shift());
|
||||
sendGameState();
|
||||
}
|
||||
}, null, "div");
|
||||
elementPlace("body","display",null,"div");
|
||||
@@ -115,16 +136,16 @@ popupDialog("gettingStarted","Welcome to Deckard and company", false, inputDialo
|
||||
var tempses = new WebSocket(server);
|
||||
tempses.onmessage = function (event) {
|
||||
var message = JSON.parse(event.data);
|
||||
if (message.id) { gameID = message.id; }
|
||||
if (message.id) { window.gameID = message.id; }
|
||||
};
|
||||
}
|
||||
if (window.gameID) {
|
||||
startGameSession();
|
||||
} else {
|
||||
tempses.onclose = function () {
|
||||
startGameSession();
|
||||
};
|
||||
}
|
||||
window.gameSession = new WebSocket(server+gameID);
|
||||
gameSession.onmessage = function (event) {
|
||||
var message = JSON.parse(event.data);
|
||||
if (message.state) { gameState = message.state; updateEvent(); }
|
||||
if (message.message) { console.log(message.message); }
|
||||
if (message.command) {}
|
||||
};
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user