1
0
Fork 0

check code style

This commit is contained in:
deardrops 2017-02-11 11:08:07 +08:00 committed by WEBXOSS
parent 2c6895f477
commit 9aff9d258d
2 changed files with 66 additions and 53 deletions

View file

@ -197,7 +197,7 @@ function down (content, filename = 'down.txt') {
<body> <body>
<div> <div>
<span>Deck:</span> <a href="#" onclick="window.open('./webxoss-client/DeckEditor/')">Deck:</a>
<select id="deck-select"></select> <select id="deck-select"></select>
</div> </div>
<div> <div>
@ -215,5 +215,13 @@ function down (content, filename = 'down.txt') {
<button onclick="addToHand()">add card</button> <button onclick="addToHand()">add card</button>
<button onclick="addToLifeCloth()">add to life cloth</button> <button onclick="addToLifeCloth()">add to life cloth</button>
</div> </div>
<style type="text/css">
a {
outline: none;
color: inherit;
text-decoration: none;
-webkit-tap-highlight-color: transparent;
}
</style>
</body> </body>
</html> </html>

View file

@ -2,72 +2,86 @@
// browser only // browser only
function testHelper() { var game; // in-play game
function TestHelper() {
this.deckNames = this.readDeckNames(); this.deckNames = this.readDeckNames();
this.deckName = ''; this.deckName = '';
this.cfg = { this.cfg = {
disableAudio: true, disableAudio: true,
}
} }
window.onload = function() {
var deckSelect = document.getElementById('deck-select'); TestHelper.prototype.disableAudio = function (doc) {
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 // disable BGM
if (!this.cfg.disableAudio) return; if (!this.cfg.disableAudio) return;
var bgm = doc.getElementById('checkbox-bgm'); var bgm = doc.getElementById('checkbox-bgm');
var sound = doc.getElementById('checkbox-sound-effect'); var sound = doc.getElementById('checkbox-sound-effect');
if (bgm.checked) bgm.click() if (bgm.checked) bgm.click();
if (sound.checked) sound.click() if (sound.checked) sound.click();
} }
testHelper.prototype.initClient = function (win) { TestHelper.prototype.initClient = function (win) {
var doc = win.document; var doc = win.document;
var self = this; var self = this;
var socket = new FakeSocket(win); var socket = new FakeSocket(win);
win.addEventListener('unload',function () { win.addEventListener('unload',function () {
socket._doEmit('disconnect'); socket._dEomit('disconnect');
}); });
win.document.title = 'Client' + socket.id; win.document.title = 'Client' + socket.id;
io._handler(socket); io._handler(socket);
this.disableAudio(doc); this.disableAudio(doc);
} }
testHelper.prototype.readDeckNames = function () { TestHelper.prototype.readDeckNames = function () {
return JSON.parse(localStorage.getItem('deck_filenames')); return JSON.parse(localStorage.getItem('deck_filenames'));
} }
testHelper.prototype.readDeckByName = function (name) { TestHelper.prototype.readDeckByName = function (name) {
if (typeof name === 'undefined') if (typeof name === 'undefined')
name = this.deckNames[0]; if (this.deckName === '')
name = this.deckNames[0]; // use WHITE_HOPE
else
name = this.deckName; // (default) use selected deck
return JSON.parse(localStorage.getItem('deck_file_'+ name)); return JSON.parse(localStorage.getItem('deck_file_'+ name));
} }
var testHelper = new testHelper();
var helper = new TestHelper();
global.window.newClient = function () { global.window.newClient = function () {
var win = window.open('./webxoss-client/?local=true'); var win = window.open('./webxoss-client/?local=true');
win.addEventListener('load',function () { win.addEventListener('load',function () {
testHelper.initClient(win) helper.initClient(win);
}); });
} }
var game; 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 = helper.readDeckByName();
sockets[1]._doEmit('ready',deck);
sockets[0]._doEmit('startGame',deck);
}
global.window.updateBattle = function () { global.window.updateBattle = function () {
if (roomManager.rooms.length === 0) { if (roomManager.rooms.length === 0) {
game = false; console.log('no in-play game found');
console.log('no in-play game found')
return; return;
} }
game = roomManager.rooms[0].game; game = roomManager.rooms[0].game;
console.log('update game infomation successfully') console.log('update game infomation successfully');
} }
global.window.upgrade = function () { global.window.upgrade = function () {
var p = game.turnPlayer; var p = game.turnPlayer;
@ -85,37 +99,28 @@ global.window.addToHand = function () {
if (game.turnPlayer.getCard(cardName)) if (game.turnPlayer.getCard(cardName))
console.log('add ' + cardName + ' to hand'); console.log('add ' + cardName + ' to hand');
else else
console.log('no matched card') console.log('no matched card');
} }
global.window.addToLifeCloth = function () { global.window.addToLifeCloth = function () {
var cardName = document.getElementById('card-name').value; var cardName = document.getElementById('card-name').value;
if (game.turnPlayer.putCardToLifeCloth(cardName)) if (game.turnPlayer.putCardToLifeCloth(cardName))
console.log('put ' + cardName + ' to life cloth'); console.log('put ' + cardName + ' to life cloth');
else else
console.log('no matched card') 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(); window.onload = function() {
sockets[1]._doEmit('ready',deck); var deckSelect = document.getElementById('deck-select');
sockets[0]._doEmit('startGame',deck); helper.deckNames.forEach(function(name){
var deckNameItem = document.createElement('option');
deckNameItem.setAttribute('value',name);
deckNameItem.innerHTML = name;
deckSelect.appendChild(deckNameItem);
})
helper.deckName = deckSelect.value;
deckSelect.onchange = function() {
helper.deckName = this.value;
}
} }
// copy from test.js // copy from test.js