webxoss-client/webxoss.js

3 lines
65 KiB
JavaScript
Raw Normal View History

2017-08-20 17:43:42 +02:00
"use strict";function callConstructor(t){var e=t.bind.apply(t,arguments);return new e}function applyToConstructor(t,e){var i=concat(null,toArr(e)),n=t.bind.apply(t,i);return new n}function nextTick(t){setTimeout(t,0)}function MessageBox(){this.eWarp=document.getElementById("msgbox-warp"),this.eWin=document.getElementById("msgbox-window"),this.eMsg=document.getElementById("msgbox-msg"),this.eInput=document.getElementById("msgbox-input"),this.ePreset=document.getElementById("msgbox-preset"),this.eOk=document.getElementById("msgbox-button-ok"),this.eCancel=document.getElementById("msgbox-button-cancel")}function IO(t){this.socket=t,this.listener=null,this.sendingMsg=null,this.datas=[],this.id=0,this.inputBlocked=!1,this.outputBlocked=!1,this.socket.removeAllListeners("gameMessage"),this.socket.on("gameMessage",this.receiveGameMessage.bind(this))}function Card(t,e){createjs.Container.prototype.initialize.call(this),this.game=t,this.isWhiteBack=e,this.width=Card.WIDTH,this.height=Card.HEIGHT,this.pid=0,this.zone=null,this.zIndex=0,this.changed=!0,this.isSide=!1,this.renderLayer=new createjs.Container,this.addChild(this.renderLayer),this.renderLayer.regX=this.width/2,this.renderLayer.regY=this.height/2,this.bitmap=new CardBitmap("",t.imageManager.noimage),this.renderLayer.addChild(this.bitmap),this.stateLayer=new createjs.Container,this.renderLayer.addChild(this.stateLayer),this.effectShape=new createjs.Shape,this.renderLayer.addChild(this.effectShape),this.buttonLayer=new ButtonList,this.buttonLayer.x=this.width/2,this.buttonLayer.y=this.height/2,this.renderLayer.addChild(this.buttonLayer),this.style=new Style({x:0,y:0,zIndex:0,top:!1,covered:!1,offX:0,offY:0,rotation:0,scaleX:-1,shadowColor:"#f7ff00",shadowBlur:0,flash:0,shine:0}),this.style.checkSkip=function(){return this.game.skip}.bind(this),this.on("mouseover",this.handleMouseover),this.on("mouseout",this.handleMouseout),this.game.addCard(this)}function CardBitmap(t,e){createjs.Container.prototype.initialize.call(this),this.setAltImage(t,e),this.setWidthHeight(Card.WIDTH,Card.HEIGHT),this.complete=e.complete,this.text=new createjs.Text(t),this.bitmap=new createjs.Bitmap(e),this.addChild(this.text,this.bitmap),this.changed=!0}function StateBitmap(t){var e=new createjs.Bitmap(t);return e.width=Card.WIDTH,e.height=Card.HEIGHT,e}function Style(t){this.transitingStyle={};for(var e in t)this.transitingStyle[e]=new TransitingValue(t[e]);this.changed=!0,this.checkSkip=null}function TransitingValue(t){this.changeTime=0,this.startValue=t,this.endValue=t,this.duration=0,this.timing=TransitingValue.cubic,this.done=!1}function Zone(t){createjs.Container.prototype.initialize.call(this),this.game=t.game,this.name=t.name,this.x=t.x,this.y=t.y,this.showAmount=!!t.showAmount,this._amount=0,this.opposite=!!t.opposite,this.checkable=!!t.checkable,this.cards=[],this.changed=!0,this.text=new createjs.Text("","bold 12px monospace"),this.text.textAlign="center",this.addChild(this.text),this.opposite&&(this.rotation=180,this.text.rotation=180),this.buttonLayer=new ButtonList,this.buttonLayer.rotation=-this.rotation,this.addChild(this.buttonLayer),this.checkable&&(this.viewCardsButton=new Button(Localize("buttonTitle","VIEW"),function(){this.game.dialog.showCards(Localize("buttonTitle","VIEW"),this.cards,function(){})}.bind(this)),this.viewCardsButton.alpha=.8),this.game.addZone(this)}function StackZone(t){Zone.apply(this,arguments),this.showPower=!!t.showPower,this.changed=!0,this._power=0,this.power=0,t.centerText?this.text.textBaseline="middle":(this.text.textBaseline="top",this.text.y=Card.HEIGHT/2,this.opposite&&(this.text.rotation=180,this.text.textBaseline="bottom")),this.stateLayer=new createjs.Container,this.stateShape=new createjs.Shape,this.stateLayer.addChild(this.stateShape),this.addChild(this.stateLayer)}function TileZone(t){Zone.apply(this,arguments),this.up=t.up,this.horizontal=t.horizontal,this.center=t.center,this.width=t.width,this.spacing=t.spacing,this.showAmount=!!t.showAmount,this.horizontal?(this.text.textBaseline="middle",this.opposite?this.text.textAlign="left":this.te
var e=this.getObjBySid(t.card);return e.up(),!1},Game.prototype.handleDownCard=function(t){var e=this.getObjBySid(t.card);return e.down(),!1},Game.prototype.handleFaceupCard=function(t){var e=this.getObjBySid(t.card);return e.pid=t.pid,e.faceup(),!1},Game.prototype.handleFacedownCard=function(t){var e=this.getObjBySid(t.card);return e.facedown(),!1},Game.prototype.handleShuffle=function(t){return t.cards.forEach(function(t){var e=this.getObjBySid(t);e.pid=0},this),!0},Game.prototype.handleSelect=function(t){return console.log(t),!!this.skip||(this.selector.addMsg(t),!0)},Game.prototype.handlePayEner=function(t){if(console.log("handlePayEner",t),this.skip)return!0;var e=t.cards.map(function(t){return this.getObjBySid(t)},this),i=this,n=null;return t.cancelable&&(n=function(){i.input("PAY_ENER",null)}),this.dialog.selectEner(Localize("buttonTitle","PAY_ENER"),e,t.integers,t,function(t){i.input("PAY_ENER",t)},n),!0},Game.prototype.handleShowCards=function(t){if(this.skip)return!0;var e=t.cards.map(function(e,i){var n=this.getObjBySid(e);return n.pid=t.pids[i],n},this),i=this,n=t.label||"CONFIRM";return this.dialog.showCards(Localize("buttonTitle",n),e,function(){i.input("OK")}),!0},Game.prototype.handleShowCardsById=function(t){if(this.skip)return!0;var e=t.ids.map(function(t,e){return{pid:t}},this),i=this,n=t.label||"CONFIRM";return this.dialog.showCards(Localize("buttonTitle",n),e,function(){i.input("OK")}),!0},Game.prototype.handleShowColors=function(t){if(this.skip)return!0;var e=t.colors.map(function(t){return Localize.color(t)}),i=this;return this.dialog.showText(Localize("buttonTitle","COLOR"),e.join(","),function(){i.input("OK")}),!0},Game.prototype.handleShowTypes=function(t){if(this.skip)return!0;var e=t.types.map(function(t){return Localize("cardType",t)}),i=this;return this.dialog.showText(Localize("prop","cardType"),e.join(","),function(){i.input("OK")}),!0},Game.prototype.handleShowEffects=function(t){if(this.skip)return!0;var e=t.effects.map(function(t){return Localize.desc(t)}).join("\n"),i=this;return this.dialog.showText(Localize("gameText","SHOW_EFFECTS_DIALOG_TITLE"),e,function(){i.input("OK")}),!0},Game.prototype.handleShowText=function(t){if(this.skip)return!0;var e="";"number"===t.type?e=t.content:"text"===t.type&&(e=Localize("gameText",t.content));var i=this;return this.dialog.showText(Localize.labelToDialogTitle(t.title),e,function(){i.input("OK")}),!0},Game.prototype.handleInformCards=function(t){return t.cards.forEach(function(e,i){var n=this.getObjBySid(e);n.pid=t.pids[i]},this),!0},Game.prototype.handleCardStates=function(t){var e=t.signiInfos,i=t.lrigInfos,n=t.zoneInfos;return e.forEach(function(t){var e=this.getObjBySid(t.card);e.zone.power=t.power,e.removeStates(),e.addStates(t.states)},this),i.forEach(function(t){var e=this.getObjBySid(t.card);e.removeStates(),e.addStates(t.states)},this),n&&n.forEach(function(t){var e=this.getObjBySid(t.zone);e.removeStates(),e.addStates(t.states)},this),!0},Game.prototype.handleActivate=function(t){var e=this.getObjBySid(t.card);return e.shine(),!1},Game.prototype.handleCardSelected=function(t){var e=this.getObjBySid(t.card);return e.flash(),!1},Game.prototype.handleSelectNumber=function(t){if(this.skip)return!0;var e=t.label,i=t.min,n=t.max,o=t.defaultValue||0,s=Localize.labelToDialogTitle(e),a=this;return this.dialog.selectNumber(s,i,n,o,!1,function(t){a.input(e,t)}),!0},Game.prototype.handleSelectText=function(t){if(this.skip)return!0;var e=t.label,i=Localize.labelToDialogTitle(e),n=t.type||"gameText",o=t.texts.map(function(t){return Localize(n,t)},this),s=this;return this.dialog.selectText(i,o,!1,function(t){s.input(e,t)}),!0},Game.prototype.handleSelectCardId=function(t){if(this.skip)return!0;try{var e=this,i=t.label,n=Localize.labelToDialogTitle(i);this.dialog.selectCardId(n,function(t){e.input(i,t)})}catch(t){window.alert(t.name+t.message)}return!0},Game.prototype.handleCoinChange=function(t){var e=t.player===this.player.sid?this.player:this.opponent;return e.coinZone.setText("Coin"+t.coin),!0},Game.prototype.handleConfirm=function(t){if(this.skip)
!1};var oldRoomName="";$("room-name").onblur=handleRenameRoom,$("room-name-form").onsubmit=handleRenameRoom;var stopFetchingLive=0,watchingLive=!1;socket.on("liveData",function(t){return stopFetchingLive?void stopFetchingLive--:t?(msgBox.close(),watchingLive=!0,gameStart("live"),game.skip=!0,t.forEach(function(t,e){game.io.receiveGameMessage({buffer:[{id:e,data:t}]})}),game.handleMsgQueue(),void(game.skip=!1)):void msgBox.alert(Localize.index("FAILED_TO_FETCH_DATA"))});var stopFetchingReplay=!1;socket.on("replayList",function(t){$("replay-list").innerHTML="",t.forEach(function(t){var e=newElement("li"),i=CardInfo[t.selfLrig],n=CardInfo[t.opponentLrig],o=Localize.classes(i)+" vs "+Localize.classes(n);o=o.replace(/\n/g,""),e.textContent=o,e.onclick=getReplayContent.bind(null,t.id),$("replay-list").appendChild(e)})}),socket.on("replayContent",function(t){if(!stopFetchingReplay){if(!t)return void msgBox.alert(Localize.index("FAILED_TO_FETCH_DATA"));msgBox.close(),playReplayContent(t)}}),socket.on("chat",function(t){var e=["host","host-spectator"],i=["guest","guest-spectator"],n=["host-spectator","guest-spectator"],o=inArr(position,e)&&inArr(t.position,i)||inArr(position,i)&&inArr(t.position,e),s=inArr(t.position,n);chatManager.addMsg(t.nickname,t.content,o,s)}),$("checkbox-bgm").onchange=function(t){audio.disableBgm(!$("checkbox-bgm").checked)},$("checkbox-sound-effect").onchange=function(t){audio.disableSoundEffect(!$("checkbox-sound-effect").checked)};var playingReplay=!1;$("span-play-replay").onclick=function(t){$("input-replay-file").value=null,msgBox.preset("replay"),updateReplayList()},$("button-replay-return").onclick=function(t){msgBox.close()},$("input-replay-file").onchange=function(t){readAndPlayReplayFile()},window.onbeforeunload=function(t){if(game&&"?local=true"!==location.search){var e=Localize.index("CONFIRM_CLOSE");return t.returnValue=e,e}},checkDomain(),/iPhone|Android/i.test(navigator.userAgent)&&($("link-edit-deck").onclick=function(t){window.confirm("Do you like to try our new DeckEditor for mobile phone?")&&(t.preventDefault(),location="/next/")});