forked from mirrors/webxoss-core
improve test helper
improve helper function set language in serve page log action and state in textarea
This commit is contained in:
parent
4273196754
commit
d68a3cb1b1
2 changed files with 200 additions and 99 deletions
88
index.html
88
index.html
|
@ -7,26 +7,26 @@
|
||||||
<script>
|
<script>
|
||||||
var global = window;
|
var global = window;
|
||||||
// function require (file) {
|
// function require (file) {
|
||||||
// return window[file.replace(/^\.[\/\\]/,'').replace(/.js$/,'')];
|
// return window[file.replace(/^\.[\/\\]/,'').replace(/.js$/,'')];
|
||||||
// }
|
// }
|
||||||
function handleCardInfo() {
|
function handleCardInfo() {
|
||||||
// var defaultValueMap = {
|
// var defaultValueMap = {
|
||||||
// "rarity": "LR",
|
// "rarity": "LR",
|
||||||
// "cardType": "SIGNI",
|
// "cardType": "SIGNI",
|
||||||
// "color": "white",
|
// "color": "white",
|
||||||
// "level": 0,
|
// "level": 0,
|
||||||
// "limit": 0,
|
// "limit": 0,
|
||||||
// "power": 0,
|
// "power": 0,
|
||||||
// "limiting": "",
|
// "limiting": "",
|
||||||
// "classes": [],
|
// "classes": [],
|
||||||
// "costWhite": 0,
|
// "costWhite": 0,
|
||||||
// "costBlack": 0,
|
// "costBlack": 0,
|
||||||
// "costRed": 0,
|
// "costRed": 0,
|
||||||
// "costBlue": 0,
|
// "costBlue": 0,
|
||||||
// "costGreen": 0,
|
// "costGreen": 0,
|
||||||
// "costColorless": 0,
|
// "costColorless": 0,
|
||||||
// "guardFlag": false,
|
// "guardFlag": false,
|
||||||
// "multiEner": false,
|
// "multiEner": false,
|
||||||
// };
|
// };
|
||||||
for (var x in CardInfo) {
|
for (var x in CardInfo) {
|
||||||
var info = CardInfo[x];
|
var info = CardInfo[x];
|
||||||
|
@ -55,9 +55,9 @@
|
||||||
delete info.bettedCost;
|
delete info.bettedCost;
|
||||||
if (info.rise) info.rise = true;
|
if (info.rise) info.rise = true;
|
||||||
// for (var key in defaultValueMap) {
|
// for (var key in defaultValueMap) {
|
||||||
// if (info[key] === defaultValueMap[key]) {
|
// if (info[key] === defaultValueMap[key]) {
|
||||||
// delete info[key];
|
// delete info[key];
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
// var textarea = document.createElement('textarea');
|
// var textarea = document.createElement('textarea');
|
||||||
|
@ -94,9 +94,9 @@
|
||||||
};
|
};
|
||||||
props.forEach(function(rawprop) {
|
props.forEach(function(rawprop) {
|
||||||
// suffix.forEach(function (suf) {
|
// suffix.forEach(function (suf) {
|
||||||
// var prop = rawprop + suf;
|
// var prop = rawprop + suf;
|
||||||
// if (!info[prop]) return;
|
// if (!info[prop]) return;
|
||||||
// obj[prop] = info[prop];
|
// obj[prop] = info[prop];
|
||||||
// });
|
// });
|
||||||
obj[rawprop + "_ko"] = info[rawprop + "_en"];
|
obj[rawprop + "_ko"] = info[rawprop + "_en"];
|
||||||
});
|
});
|
||||||
|
@ -215,20 +215,38 @@
|
||||||
<select id="ghost-decks"></select>
|
<select id="ghost-decks"></select>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="startBattle();">Oben!</button>
|
<button onclick="startBattle();">oben!</button>
|
||||||
</div>
|
</div>
|
||||||
<div> ---- Helper Action ---- </div>
|
<div> ---- Helper Function ---- </div>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="upgrade()">upgrade</button>
|
<button onclick="grow();">grow!</button>
|
||||||
<button onclick="game.turnPlayer.draw(5)">draw</button>
|
<button onclick="draw()">draw</button>
|
||||||
<button onclick="game.turnPlayer.enerCharge(10);">ener charge</button>
|
<button onclick="charge();">ener charge</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input id="card-name" type="text" placeholder="WX01-100">
|
<input id="card-name" type="text" placeholder="wx15-001">
|
||||||
|
</div>
|
||||||
|
<button onclick="addTo('handZone');">add to hand</button>
|
||||||
|
<button onclick="addTo('lifeClothZone');">add to life cloth</button>
|
||||||
|
<button onclick="addTo('enerZone');">add to ener</button>
|
||||||
|
<button onclick="addTo('trashZone');">add to trash</button>
|
||||||
|
<div>
|
||||||
|
<button onclick="resetLrigDeck();">reset lrig deck</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<select id="select-language" onchange="changeLanguage();">
|
||||||
|
<option value="en">English</option>
|
||||||
|
<option value="zh_CN">简体中文</option>
|
||||||
|
<option value="zh_TW">繁體中文</option>
|
||||||
|
<option value="jp">日本語</option>
|
||||||
|
<option value="ko">한국어</option>
|
||||||
|
<option value="ru">русский</option>
|
||||||
|
<option value="it">Italiano</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<textarea id="log"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="addToHand()">add card</button>
|
|
||||||
<button onclick="addToLifeCloth()">add to life cloth</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<iframe class="float" src="../webxoss-client/DeckEditor/" width="1090px" height="690px" scrolling="no" frameborder="no" border="0"></iframe>
|
<iframe class="float" src="../webxoss-client/DeckEditor/" width="1090px" height="690px" scrolling="no" frameborder="no" border="0"></iframe>
|
||||||
</body>
|
</body>
|
||||||
|
@ -240,6 +258,12 @@ a {
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
resize: none;
|
||||||
|
width: 270px;
|
||||||
|
height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
.float {
|
.float {
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
211
testHelper.js
211
testHelper.js
|
@ -1,19 +1,15 @@
|
||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
// browser only
|
// browser only
|
||||||
|
|
||||||
function TestHelper() {
|
var $ = document.getElementById.bind(document);
|
||||||
this.deckNames = this.readDeckNames();
|
|
||||||
this.hostDeck = '';
|
|
||||||
this.ghostDeck = '';
|
|
||||||
|
|
||||||
this.cfg = {
|
function TestHelper() {
|
||||||
disableAudio: true,
|
this.noBGM = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TestHelper.prototype.disableAudio = function(doc) {
|
TestHelper.prototype.disableAudio = function(doc) {
|
||||||
// disable BGM
|
// disable BGM
|
||||||
if (!this.cfg.disableAudio) {
|
if (!this.noBGM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var bgm = doc.getElementById('checkbox-bgm');
|
var bgm = doc.getElementById('checkbox-bgm');
|
||||||
|
@ -24,10 +20,9 @@ TestHelper.prototype.disableAudio = function(doc) {
|
||||||
if (sound && sound.checked) {
|
if (sound && sound.checked) {
|
||||||
sound.click();
|
sound.click();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
TestHelper.prototype.initClient = function(win) {
|
TestHelper.prototype.initClient = function(win) {
|
||||||
var doc = win.document;
|
var doc = win.document;
|
||||||
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._doEmit('disconnect');
|
||||||
|
@ -36,30 +31,17 @@ TestHelper.prototype.initClient = function(win) {
|
||||||
io._handler(socket);
|
io._handler(socket);
|
||||||
|
|
||||||
this.disableAudio(doc);
|
this.disableAudio(doc);
|
||||||
}
|
log(win.document.title + ' added.');
|
||||||
TestHelper.prototype.readDeckNames = function() {
|
};
|
||||||
return JSON.parse(localStorage.getItem('deck_filenames')) || [];
|
|
||||||
}
|
|
||||||
TestHelper.prototype.getDeckPids = function(player) {
|
|
||||||
var name;
|
|
||||||
if (player === 'host') {
|
|
||||||
name = this.hostDeck;
|
|
||||||
} else {
|
|
||||||
name = this.ghostDeck;
|
|
||||||
}
|
|
||||||
if (name === '') {
|
|
||||||
name = this.deckNames[0]; // use WHITE_HOPE
|
|
||||||
}
|
|
||||||
return JSON.parse(localStorage.getItem('deck_file_' + name));
|
|
||||||
}
|
|
||||||
|
|
||||||
var helper = new TestHelper();
|
var helper = new TestHelper();
|
||||||
|
|
||||||
|
// prepare and start game
|
||||||
function startBattle() {
|
function startBattle() {
|
||||||
if (sockets.length) {
|
if (sockets.length) {
|
||||||
sockets.forEach(function(target) {
|
sockets.forEach(function(target) {
|
||||||
target._win.close();
|
target._win.close();
|
||||||
})
|
});
|
||||||
location.reload();
|
location.reload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -73,11 +55,12 @@ function startBattle() {
|
||||||
helper.initClient(win);
|
helper.initClient(win);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function oben() {
|
function oben() {
|
||||||
if (sockets.length !== 2) {
|
if (sockets.length !== 2) {
|
||||||
console.log('two client needed');
|
log('two client needed');
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
var createRoomMsg = {
|
var createRoomMsg = {
|
||||||
'roomName': 'test',
|
'roomName': 'test',
|
||||||
'nickname': 'host',
|
'nickname': 'host',
|
||||||
|
@ -85,28 +68,37 @@ function oben() {
|
||||||
'mayusRoom': true,
|
'mayusRoom': true,
|
||||||
}
|
}
|
||||||
sockets[0]._doEmit('createRoom', createRoomMsg);
|
sockets[0]._doEmit('createRoom', createRoomMsg);
|
||||||
|
log('Client<1> create room.');
|
||||||
|
|
||||||
var joinRoomMsg = {
|
var joinRoomMsg = {
|
||||||
'roomName': 'test',
|
'roomName': 'test',
|
||||||
'nickname': 'ghost',
|
'nickname': 'ghost',
|
||||||
'password': '',
|
'password': '',
|
||||||
}
|
}
|
||||||
sockets[1]._doEmit('joinRoom', joinRoomMsg);
|
sockets[1]._doEmit('joinRoom', joinRoomMsg);
|
||||||
|
log('Client<2> join room.');
|
||||||
|
|
||||||
|
sockets[1]._doEmit('ready', getDeckPids('host'));
|
||||||
|
log('Client<2> is ready.');
|
||||||
|
sockets[0]._doEmit('startGame', getDeckPids('ghost'));
|
||||||
|
log('oben!');
|
||||||
|
|
||||||
sockets[1]._doEmit('ready', helper.getDeckPids('host'));
|
|
||||||
sockets[0]._doEmit('startGame', helper.getDeckPids('ghost'));
|
|
||||||
updateBattle();
|
updateBattle();
|
||||||
}
|
}
|
||||||
|
|
||||||
var game; // in-play game
|
var game; // in-play game
|
||||||
function updateBattle() {
|
function updateBattle() {
|
||||||
if (roomManager.rooms.length === 0) {
|
if (roomManager.rooms.length === 0) {
|
||||||
console.log('no in-play game found');
|
log('no in-play game found.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
game = roomManager.rooms[0].game;
|
game = roomManager.rooms[0].game;
|
||||||
console.log('update game information successfully');
|
log('Handle game successfully.');
|
||||||
|
log('Now you can use helper function.');
|
||||||
}
|
}
|
||||||
function upgrade() {
|
|
||||||
|
// helper function
|
||||||
|
function grow() {
|
||||||
var p = game.turnPlayer;
|
var p = game.turnPlayer;
|
||||||
var cards = p.lrigDeck.cards.concat(p.lrigTrashZone.cards);
|
var cards = p.lrigDeck.cards.concat(p.lrigTrashZone.cards);
|
||||||
var lrigCards = [];
|
var lrigCards = [];
|
||||||
|
@ -116,42 +108,127 @@ function upgrade() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
game.moveCards(lrigCards, p.lrigZone);
|
game.moveCards(lrigCards, p.lrigZone);
|
||||||
|
log('grow lrig to level max.');
|
||||||
}
|
}
|
||||||
function addToHand() {
|
function draw(num) {
|
||||||
var cardName = document.getElementById('card-name').value;
|
if (!num) {
|
||||||
if (game.turnPlayer.getCard(cardName))
|
num = 5;
|
||||||
console.log('add ' + cardName + ' to hand');
|
}
|
||||||
else
|
var p = game.turnPlayer;
|
||||||
console.log('no matched card');
|
p.draw(num);
|
||||||
|
log('draw ' + num + ' cards.');
|
||||||
}
|
}
|
||||||
function addToLifeCloth() {
|
function charge(num) {
|
||||||
var cardName = document.getElementById('card-name').value;
|
if (!num) {
|
||||||
if (game.turnPlayer.putCardToLifeCloth(cardName))
|
num = 5;
|
||||||
console.log('put ' + cardName + ' to life cloth');
|
}
|
||||||
else
|
var p = game.turnPlayer;
|
||||||
console.log('no matched card');
|
p.enerCharge(num);
|
||||||
|
log('ener charge ' + num + '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchCard(arg) {
|
||||||
|
if (arg) {
|
||||||
|
arg = arg.toUpperCase();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var cid = 0;
|
||||||
|
game.cards.forEach(function(card) {
|
||||||
|
var info = CardInfo[card.cid];
|
||||||
|
var matched = info.pid === arg ||
|
||||||
|
info.cid === arg ||
|
||||||
|
info.wxid === arg;
|
||||||
|
if (matched) {
|
||||||
|
cid = card.cid;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!cid) return null;
|
||||||
|
var player = game.turnPlayer;
|
||||||
|
var cards = concat(player.mainDeck.cards,
|
||||||
|
player.trashZone.cards,
|
||||||
|
player.enerZone.cards,
|
||||||
|
player.lifeClothZone.cards);
|
||||||
|
|
||||||
|
cards.forEach(function(card) {
|
||||||
|
if (card.cid === cid) {
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var zones = [
|
||||||
|
'handZone',
|
||||||
|
'enerZone',
|
||||||
|
'trashZone',
|
||||||
|
'lifeClothZone',
|
||||||
|
];
|
||||||
|
function addTo(zone) {
|
||||||
|
if (zones.indexOf(zone) === -1) {
|
||||||
|
log('no such zone: ' + zone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var input = $('card-name').value;
|
||||||
|
if (input && matchCard(input)) {
|
||||||
|
var matchedCard = matchCard(input);
|
||||||
|
if (!matchedCard) {
|
||||||
|
log('no matched card');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
matchedCard.moveTo(game.turnPlayer[zone]);
|
||||||
|
log('add <' + matchedCard.name + '> to ' + zone + '.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetLrigDeck() {
|
||||||
|
game.moveCards(game.turnPlayer.lrigTrashZone.cards, game.turnPlayer.lrigDeck);
|
||||||
|
log('reset lrig deck.');
|
||||||
|
}
|
||||||
|
// log
|
||||||
|
function log(text) {
|
||||||
|
var logger = $('log');
|
||||||
|
logger.innerHTML += text;
|
||||||
|
logger.innerHTML += '\n';
|
||||||
|
}
|
||||||
|
// dom
|
||||||
|
function getDeckPids(player) {
|
||||||
|
var name = {
|
||||||
|
'host': $('host-decks').value || '',
|
||||||
|
'ghost': $('host-decks').value || '',
|
||||||
|
}[player];
|
||||||
|
if (!name) {
|
||||||
|
log('error in deck select');
|
||||||
|
}
|
||||||
|
return JSON.parse(localStorage.getItem('deck_file_' + name));
|
||||||
|
}
|
||||||
|
var deckNames = [];
|
||||||
|
function readDeckNames() {
|
||||||
|
return JSON.parse(localStorage.getItem('deck_filenames')) || [];
|
||||||
}
|
}
|
||||||
function initDeckSelect() {
|
function initDeckSelect() {
|
||||||
var hostDecks = document.getElementById('host-decks');
|
deckNames = readDeckNames();
|
||||||
var ghostDecks = document.getElementById('ghost-decks');
|
var hostDeckSelect = $('host-decks');
|
||||||
hostDecks.innerHTML = '';
|
var ghostDeckSelect = $('ghost-decks');
|
||||||
ghostDecks.innerHTML = '';
|
hostDeckSelect.innerHTML = '';
|
||||||
helper.deckNames.forEach(function(name) {
|
ghostDeckSelect.innerHTML = '';
|
||||||
var deckname = document.createElement('option');
|
deckNames.forEach(function(name) {
|
||||||
deckname.setAttribute('value', name);
|
var deckName = document.createElement('option');
|
||||||
deckname.innerHTML = name;
|
deckName.setAttribute('value', name);
|
||||||
hostDecks.appendChild(deckname);
|
deckName.innerHTML = name;
|
||||||
ghostDecks.appendChild(deckname.cloneNode(true));
|
hostDeckSelect.appendChild(deckName);
|
||||||
})
|
ghostDeckSelect.appendChild(deckName.cloneNode(true));
|
||||||
helper.hostDeck = hostDecks.value;
|
});
|
||||||
helper.ghostDeck = ghostDecks.value;
|
|
||||||
hostDecks.onchange = function() {
|
|
||||||
helper.hostDeck = this.value;
|
|
||||||
}
|
|
||||||
ghostDecks.onchange = function() {
|
|
||||||
helper.ghostDeck = this.value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
function changeLanguage() {
|
||||||
|
var lang = $('select-language').value;
|
||||||
|
localStorage.setItem('language', lang);
|
||||||
|
log('set language to ' + lang + '.');
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
|
$('select-language').value = localStorage.getItem('language');
|
||||||
initDeckSelect();
|
initDeckSelect();
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in a new issue