1
0
Fork 0

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
This commit is contained in:
deardrops 2017-02-10 23:55:34 +08:00 committed by WEBXOSS
parent a37636e4b8
commit 2c6895f477
3 changed files with 58 additions and 11 deletions

View file

@ -3,7 +3,7 @@
window.FakeSocket = (function () {
var sockets = [];
window.sockets = [];
window.addEventListener('message',function (event) {
var win = event.source;

View file

@ -197,18 +197,23 @@ function down (content, filename = 'down.txt') {
<body>
<div>
<button onclick="newClient();">newClient</button>
<button onclick="updateBattle();">updateBattle</button>
<span>Deck:</span>
<select id="deck-select"></select>
</div>
<div>
<button onclick="newClient();">new client</button>
<button onclick="oben();">oben!</button>
<button onclick="updateBattle();">update battle</button>
</div>
<div>
<button onclick="upgrade()">upgrade</button>
<button onclick="game.turnPlayer.draw(5)">draw</button>
<button onclick="game.turnPlayer.enerCharge(10);">enerCharge</button>
<button onclick="game.turnPlayer.enerCharge(10);">ener charge</button>
</div>
<div>
<input id="card-name" type="text"></div>
<button onclick="addToHand()">addCard</button>
<button onclick="addToLifeCloth()">addToLifeCloth</button>
<input id="card-name" type="text" placeholder="WX01-100"></div>
<button onclick="addToHand()">add card</button>
<button onclick="addToLifeCloth()">add to life cloth</button>
</div>
</body>
</html>

View file

@ -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 = {