This commit is contained in:
libccy 2016-04-10 23:26:14 +08:00
parent 154321ffc1
commit 084a8195dc
5 changed files with 261 additions and 62 deletions

View File

@ -2031,7 +2031,8 @@ character.yxs={
return 6-ai.get.value(card);
},
filterCard:function(card){
var info=lib.card[card.name].image;
var info=lib.card[card.name];
if(!info) return false;
return !info.image&&!info.fullimage;
},
discard:false,

View File

@ -47,7 +47,7 @@
};
var lib={
configprefix:'noname_0.9_',
versionOL:2,
versionOL:3,
updateURL:localStorage.getItem('noname_download_source')||'http://isha.applinzi.com/',
assetURL:'',
changeLog:[],
@ -3871,6 +3871,40 @@
game.send('result',result);
}
event.goto(0);
},
connection:function(ws){
var client={
ws:ws,
id:get.id(),
closed:false
};
lib.node.clients.push(client);
for(var i in lib.element.client){
client[i]=lib.element.client[i];
}
ws.on('message',function(messagestr){
var message;
try{
message=JSON.parse(messagestr);
if(!Array.isArray(message)||
typeof lib.message.server[message[0]]!=='function'){
throw('err');
}
for(var i=1;i<message.length;i++){
message[i]=get.parsedResult(message[i]);
}
}
catch(e){
console.log(e);
console.log('invalid message: '+messagestr);
return;
}
lib.message.server[message.shift()].apply(client,message);
});
ws.on('close',function(){
client.close();
});
client.send('opened');
},
css:function(path,file,before){
var style = document.createElement("link");
@ -11058,11 +11092,6 @@
_status.connectCallback(true);
delete _status.connectCallback;
}
game.send('init',lib.versionOL,{
id:game.onlineID,
avatar:lib.config.connect_avatar,
nickname:lib.config.connect_nickname
},lib.config.banned_info);
},
onmessage:function(messageevent){
var message;
@ -11755,6 +11784,79 @@
},
},
client:{
opened:function(){
game.send('init',lib.versionOL,{
id:game.onlineID,
avatar:lib.config.connect_avatar,
nickname:lib.config.connect_nickname
},lib.config.banned_info);
},
createroom:function(){
game.online=false;
lib.node={};
for(var i=0;i<ui.rooms.length;i++){
ui.rooms[i].delete();
}
delete ui.rooms;
game.switchMode('identity');
},
roomlist:function(list){
game.online=true;
lib.config.recentIP.remove(_status.ip);
lib.config.recentIP.unshift(_status.ip);
lib.config.recentIP.splice(5);
game.saveConfig('recentIP',lib.config.recentIP);
_status.connectMode=true;
game.clearArena();
ui.pause.hide();
ui.auto.hide();
if(ui.ipnode){
ui.ipnode.remove();
delete ui.ipnode;
}
if(ui.iptext){
ui.iptext.remove();
delete ui.iptext;
}
if(ui.ipbutton){
ui.ipbutton.remove();
delete ui.ipbutton;
}
if(ui.recentIP){
ui.recentIP.remove();
delete ui.recentIP;
}
clearTimeout(_status.createNodeTimeout);
var proceed=function(){
var list2=['re_caocao','liubei','sunquan'];
ui.rooms=[];
game.ip=get.trimip(_status.ip);
for(var i=0;i<3;i++){
var player=ui.create.player(ui.window);
player.dataset.position='c'+i;
player.classList.add('connect');
player.roomindex=i;
if(!list[i]||!list[i].config){
player.initOL('空房间',list2[i])
}
else{
var config=list[i].config;
player.initOL(get.cnNumber(parseInt(config.number))+'人'+get.translation(config.mode),list[i].owner[1]);
player.setNickname(list[i].owner[0]);
}
ui.rooms.push(player);
}
}
if(_status.event.getParent()){
game.forceOver('noover',proceed);
}
else{
proceed();
}
},
init:function(id,config,ip){
game.online=true;
game.onlineID=id;
@ -12159,6 +12261,9 @@
if(event.func){
event.func();
}
if(game.ws){
game.send('server','config',lib.configOL);
}
ui.create.connectPlayers(game.ip);
var me=game.connectPlayers[0];
@ -12286,9 +12391,14 @@
lib.configOL={};
lib.playerOL={};
lib.cardOL={};
ui.create.chat();
if(game.ws){
}
else{
var WebSocketServer=require('ws').Server;
var wss=new WebSocketServer({port:8080});
ui.create.chat();
var interfaces = require('os').networkInterfaces();
for(var devName in interfaces){
@ -12302,39 +12412,8 @@
if(game.ip) break;
}
wss.on('connection',function(ws){
var client={
ws:ws,
id:get.id(),
closed:false
};
lib.node.clients.push(client);
for(var i in lib.element.client){
client[i]=lib.element.client[i];
wss.on('connection',lib.init.connection);
}
ws.on('message',function(messagestr){
var message;
try{
message=JSON.parse(messagestr);
if(!Array.isArray(message)||
typeof lib.message.server[message[0]]!=='function'){
throw('err');
}
for(var i=1;i<message.length;i++){
message[i]=get.parsedResult(message[i]);
}
}
catch(e){
console.log(e);
console.log('invalid message: '+messagestr);
return;
}
lib.message.server[message.shift()].apply(client,message);
});
ws.on('close',function(){
client.close();
});
});
},
playAudio:function(){
if(_status.video&&arguments[1]!='video') return;
@ -15659,6 +15738,106 @@
delete window.mode;
callback(mode[name]);
});
},
switchMode:function(name){
window.mode={};
var script=lib.init.js(lib.assetURL+'mode',name,function(){
script.remove();
var mode=window.mode;
delete window.mode;
lib.config.mode=name;
var i,j,k;
for(i in mode[lib.config.mode].element){
if(!lib.element[i]) lib.element[i]=[];
for(j in mode[lib.config.mode].element[i]){
if(j=='init'){
if(!lib.element[i].inits) lib.element[i].inits=[];
lib.element[i].inits.push(lib.init.eval(mode[lib.config.mode].element[i][j]));
}
else{
lib.element[i][j]=lib.init.eval(mode[lib.config.mode].element[i][j]);
}
}
}
for(i in mode[lib.config.mode].ai){
if(typeof mode[lib.config.mode].ai[i]=='object'){
if(ai[i]==undefined) ai[i]={};
for(j in mode[lib.config.mode].ai[i]){
ai[i][j]=lib.init.eval(mode[lib.config.mode].ai[i][j]);
}
}
else{
ai[i]=lib.init.eval(mode[lib.config.mode].ai[i]);
}
}
for(i in mode[lib.config.mode].ui){
if(typeof mode[lib.config.mode].ui[i]=='object'){
if(ui[i]==undefined) ui[i]={};
for(j in mode[lib.config.mode].ui[i]){
ui[i][j]=lib.init.eval(mode[lib.config.mode].ui[i][j]);
}
}
else{
ui[i]=lib.init.eval(mode[lib.config.mode].ui[i]);
}
}
for(i in mode[lib.config.mode].game){
game[i]=lib.init.eval(mode[lib.config.mode].game[i]);
}
for(i in mode[lib.config.mode].get){
get[i]=lib.init.eval(mode[lib.config.mode].get[i]);
}
if(game.onwash){
lib.onwash.push(game.onwash);
delete game.onwash;
}
if(game.onover){
lib.onover.push(game.onover);
delete game.onover;
}
lib.config.current_mode=mode[lib.config.mode].config||[];
lib.config.banned=get.config('banned')||[];
lib.config.bannedcards=get.config('bannedcards')||[];
for(i in mode[lib.config.mode]){
if(i=='element') continue;
if(i=='game') continue;
if(i=='ai') continue;
if(i=='ui') continue;
if(i=='get') continue;
if(i=='config') continue;
if(i=='start') continue;
if(lib[i]==undefined) lib[i]=(get.objtype(mode[lib.config.mode][i])=='array')?[]:{};
for(j in mode[lib.config.mode][i]){
lib[i][j]=lib.init.eval(mode[lib.config.mode][i][j]);
}
}
var pilecfg=lib.config.customcardpile[get.config('cardpilename')];
if(pilecfg){
lib.config.bannedpile=pilecfg[0]||{};
lib.config.addedpile=pilecfg[1]||{};
}
try{
lib.storage=JSON.parse(localStorage.getItem(lib.configprefix+lib.config.mode));
if(typeof lib.storage!='object') throw('err');
if(lib.storage==null) throw('err');
}
catch(err){
lib.storage={};
localStorage.setItem(lib.configprefix+lib.config.mode,"{}");
}
_status.event={
finished:true,
next:[],
};
_status.paused=false;
game.createEvent('game',false).content=mode[lib.config.mode].start;
game.loop();
});
},
loadMode:function(mode){
var next=game.createEvent('loadMode');
@ -22677,7 +22856,15 @@
if(_status.clicked) return;
if(ui.intro) return;
if(this.classList.contains('connect')){
if(game.online) return;
if(game.online){
if(this.hasOwnProperty('roomindex')){
if(!_status.enteringroom){
_status.enteringroom=true;
game.send('server','enter',this.roomindex,lib.config.connect_nickname,lib.config.connect_avatar);
}
}
return;
}
if(this.playerid){
if(this.ws){
if(confirm('是否踢出'+this.nickname+'')){
@ -22985,6 +23172,9 @@
}
game.resume();
}
else if(_status.event.switchToAuto){
_status.event.switchToAuto();
}
if(game.online){
game.send('auto');
@ -23493,6 +23683,13 @@
},
};
var get={
trimip:function(str){
var len=str.length-5;
if(str.lastIndexOf(':8080')==len){
str=str.slice(0,len);
}
return str;
},
mode:function(){
if(_status.connectMode){
return lib.configOL.mode;

View File

@ -271,7 +271,7 @@ table{table-layout: fixed;}
.player.linked:not(.treasure).playerfocus{
transform: scale(1.1) rotate(-90deg);
}
.player.connect>div:not(.avatar):not(.name){
.player.connect>div:not(.avatar):not(.name):not(.nameol){
display: none !important;
}
@ -1008,6 +1008,10 @@ margin-bottom: 5px;
#window>.player.connect[data-position='6']{left:calc(50% - 120px);top:calc(500% / 7 + 5px);}
#window>.player.connect[data-position='7']{left:calc(75% - 60px);top:calc(500% / 7 + 5px);}
#window>.player.connect[data-position='c0']{left:calc(50% - 120px);top:calc(50% - 200px)}
#window>.player.connect[data-position='c1']{left:calc(50% - 120px);top:calc(50% - 60px)}
#window>.player.connect[data-position='c2']{left:calc(50% - 120px);top:calc(50% + 80px)}
.connectbutton{
top:calc(400% / 7 - 35px);
width:130px;

View File

@ -361,6 +361,10 @@
#window>.player.connect[data-position='6']{left:calc(400% / 7 - 300px / 7);top:calc(400% / 7 - 40px + 5px);}
#window>.player.connect[data-position='7']{left:calc(500% / 7 + 150px / 7);top:calc(400% / 7 - 40px + 5px);}
#window>.player.connect[data-position='c0']{left:calc(50% - 255px);top:calc(50% - 90px)}
#window>.player.connect[data-position='c1']{left:calc(50% - 75px);top:calc(50% - 90px)}
#window>.player.connect[data-position='c2']{left:calc(50% + 105px);top:calc(50% - 90px)}
.connectbutton{
top:calc(500% / 7 + 80px + 5px);
}

View File

@ -59,13 +59,6 @@ mode.connect={
node.innerHTML=this.innerHTML;
connect();
};
var trimIP=function(str){
var len=str.length-5;
if(str.lastIndexOf(':8080')==len){
str=str.slice(0,len);
}
return str;
};
lib.setPopped(ui.recentIP,function(){
if(!lib.config.recentIP.length) return;
var uiintro=ui.create.dialog('hidden');
@ -74,7 +67,7 @@ mode.connect={
});
var list=ui.create.div('.caption');
for(var i=0;i<lib.config.recentIP.length;i++){
ui.create.div('.text.textlink',list,clickLink).innerHTML=trimIP(lib.config.recentIP[i]);
ui.create.div('.text.textlink',list,clickLink).innerHTML=get.trimip(lib.config.recentIP[i]);
}
uiintro.add(list);
var clear=uiintro.add('<div class="text center">清除</div>');