mirror of
https://github.com/webxoss/webxoss-core.git
synced 2024-11-20 06:49:53 +01:00
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:
parent
a37636e4b8
commit
2c6895f477
3 changed files with 58 additions and 11 deletions
|
@ -3,7 +3,7 @@
|
||||||
window.FakeSocket = (function () {
|
window.FakeSocket = (function () {
|
||||||
|
|
||||||
|
|
||||||
var sockets = [];
|
window.sockets = [];
|
||||||
|
|
||||||
window.addEventListener('message',function (event) {
|
window.addEventListener('message',function (event) {
|
||||||
var win = event.source;
|
var win = event.source;
|
||||||
|
|
17
test.html
17
test.html
|
@ -197,18 +197,23 @@ function down (content, filename = 'down.txt') {
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="newClient();">newClient</button>
|
<span>Deck:</span>
|
||||||
<button onclick="updateBattle();">updateBattle</button>
|
<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>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="upgrade()">upgrade</button>
|
<button onclick="upgrade()">upgrade</button>
|
||||||
<button onclick="game.turnPlayer.draw(5)">draw</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>
|
||||||
<div>
|
<div>
|
||||||
<input id="card-name" type="text"></div>
|
<input id="card-name" type="text" placeholder="WX01-100"></div>
|
||||||
<button onclick="addToHand()">addCard</button>
|
<button onclick="addToHand()">add card</button>
|
||||||
<button onclick="addToLifeCloth()">addToLifeCloth</button>
|
<button onclick="addToLifeCloth()">add to life cloth</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -3,10 +3,26 @@
|
||||||
// browser only
|
// browser only
|
||||||
|
|
||||||
function testHelper() {
|
function testHelper() {
|
||||||
|
this.deckNames = this.readDeckNames();
|
||||||
|
this.deckName = '';
|
||||||
|
|
||||||
this.cfg = {
|
this.cfg = {
|
||||||
disableAudio: true,
|
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) {
|
testHelper.prototype.disableAudio = function (doc) {
|
||||||
// disable BGM
|
// disable BGM
|
||||||
if (!this.cfg.disableAudio) return;
|
if (!this.cfg.disableAudio) return;
|
||||||
|
@ -27,12 +43,16 @@ testHelper.prototype.initClient = function (win) {
|
||||||
|
|
||||||
this.disableAudio(doc);
|
this.disableAudio(doc);
|
||||||
}
|
}
|
||||||
testHelper.prototype.closeAllClient = function () {
|
testHelper.prototype.readDeckNames = function () {
|
||||||
for (var uid in this.clients) {
|
return JSON.parse(localStorage.getItem('deck_filenames'));
|
||||||
this.clients[uid].close();
|
}
|
||||||
}
|
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();
|
var testHelper = 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 () {
|
||||||
|
@ -74,7 +94,29 @@ global.window.addToLifeCloth = function () {
|
||||||
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();
|
||||||
|
sockets[1]._doEmit('ready',deck);
|
||||||
|
sockets[0]._doEmit('startGame',deck);
|
||||||
|
}
|
||||||
// copy from test.js
|
// copy from test.js
|
||||||
|
|
||||||
var io = {
|
var io = {
|
||||||
|
|
Loading…
Reference in a new issue