From 2c6895f4777ceeea4f6e48053f19bf0c20d6c571 Mon Sep 17 00:00:00 2001 From: deardrops Date: Fri, 10 Feb 2017 23:55:34 +0800 Subject: [PATCH] one-key oben game && select deck in Server page get Deck file names & Deck by localStorage lower-case spell the button text add placeholder to card name input --- FakeSocket.js | 2 +- test.html | 17 +++++++++++------ testHelper.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/FakeSocket.js b/FakeSocket.js index d095fce..8fc1652 100644 --- a/FakeSocket.js +++ b/FakeSocket.js @@ -3,7 +3,7 @@ window.FakeSocket = (function () { -var sockets = []; +window.sockets = []; window.addEventListener('message',function (event) { var win = event.source; diff --git a/test.html b/test.html index b6da4c0..f67a944 100644 --- a/test.html +++ b/test.html @@ -197,18 +197,23 @@ function down (content, filename = 'down.txt') {
- - + Deck: + +
+
+ + +
- +
-
- - + + + \ No newline at end of file diff --git a/testHelper.js b/testHelper.js index 3bc3284..5e678c0 100644 --- a/testHelper.js +++ b/testHelper.js @@ -3,10 +3,26 @@ // browser only function testHelper() { + this.deckNames = this.readDeckNames(); + this.deckName = ''; + this.cfg = { disableAudio: true, } } +window.onload = function() { + var deckSelect = document.getElementById('deck-select'); + testHelper.deckNames.forEach(function(name){ + var deckNameItem = document.createElement('option'); + deckNameItem.setAttribute('value',name); + deckNameItem.innerHTML = name; + deckSelect.appendChild(deckNameItem); + }) + testHelper.deckName = deckSelect.value; + deckSelect.onchange = function() { + testHelper.deckName = this.value; + } +} testHelper.prototype.disableAudio = function (doc) { // disable BGM if (!this.cfg.disableAudio) return; @@ -27,12 +43,16 @@ testHelper.prototype.initClient = function (win) { this.disableAudio(doc); } -testHelper.prototype.closeAllClient = function () { - for (var uid in this.clients) { - this.clients[uid].close(); - } +testHelper.prototype.readDeckNames = function () { + return JSON.parse(localStorage.getItem('deck_filenames')); +} +testHelper.prototype.readDeckByName = function (name) { + if (typeof name === 'undefined') + name = this.deckNames[0]; + return JSON.parse(localStorage.getItem('deck_file_'+ name)); } var testHelper = new testHelper(); + global.window.newClient = function () { var win = window.open('./webxoss-client/?local=true'); win.addEventListener('load',function () { @@ -74,7 +94,29 @@ global.window.addToLifeCloth = function () { else console.log('no matched card') } +global.window.oben = function () { + if (sockets.length !== 2) { + console.log("two client needed"); + return; + }; + var createRoomMsg = { + "roomName": "test", + "nickname": "player", + "password": "", + "mayusRoom": true + } + sockets[0]._doEmit('createRoom', createRoomMsg); + var joinRoomMsg = { + "roomName": "test", + "nickname": "player", + "password": "" + } + sockets[1]._doEmit('joinRoom', joinRoomMsg); + var deck = testHelper.readDeckByName(); + sockets[1]._doEmit('ready',deck); + sockets[0]._doEmit('startGame',deck); +} // copy from test.js var io = {