webxoss-client/webxoss.js

3 lines
65 KiB
JavaScript
Raw Permalink Normal View History

"use strict";function callConstructor(t){var e=t.bind.apply(t,arguments);return new e}function applyToConstructor(t,e){var n=concat(null,toArr(e)),i=t.bind.apply(t,n);return new i}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
},this);var n=this.audio;return n.bgmFadeOut(function(){n.playBgm(t.selfColor)}),!0},Game.prototype.handlePackedMsgStart=function(){return this._packageCount++,!0},Game.prototype.handlePackedMsgEnd=function(){return this._packageCount--,!0},Game.prototype.handleMoveCard=function(t){var e=this.getObjBySid(t.card),n=this.getObjBySid(t.zone);return e.move(t.pid,n,t.up,t.faceup,t.bottom,t.isSide),!1},Game.prototype.handleUpCard=function(t){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),n=this,i=null;return t.cancelable&&(i=function(){n.input("PAY_ENER",null)}),this.dialog.selectEner(Localize("buttonTitle","PAY_ENER"),e,t.integers,t,function(t){n.input("PAY_ENER",t)},i),!0},Game.prototype.handleShowCards=function(t){if(this.skip)return!0;var e=t.cards.map(function(e,n){var i=this.getObjBySid(e);return i.pid=t.pids[n],i},this),n=this,i=t.label||"CONFIRM";return this.dialog.showCards(Localize("buttonTitle",i),e,function(){n.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),n=this,i=t.label||"CONFIRM";return this.dialog.showCards(Localize("buttonTitle",i),e,function(){n.input("OK")}),!0},Game.prototype.handleShowColors=function(t){if(this.skip)return!0;var e=t.colors.map(function(t){return Localize.color(t)}),n=this;return this.dialog.showText(Localize("buttonTitle","COLOR"),e.join(","),function(){n.input("OK")}),!0},Game.prototype.handleShowTypes=function(t){if(this.skip)return!0;var e=t.types.map(function(t){return Localize("cardType",t)}),n=this;return this.dialog.showText(Localize("prop","cardType"),e.join(","),function(){n.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"),n=this;return this.dialog.showText(Localize("gameText","SHOW_EFFECTS_DIALOG_TITLE"),e,function(){n.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 n=this;return this.dialog.showText(Localize.labelToDialogTitle(t.title),e,function(){n.input("OK")}),!0},Game.prototype.handleInformCards=function(t){return t.cards.forEach(function(e,n){var i=this.getObjBySid(e);i.pid=t.pids[n]},this),!0},Game.prototype.handleCardStates=function(t){var e=t.signiInfos,n=t.lrigInfos,i=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),n.forEach(function(t){var e=this.getObjBySid(t.card);e.removeStates(),e.addStates(t.states)},this),i&&i.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,n=t.min,i=t.max,o=t.defaultValue||0,s=Localize.labelToDialogTitle(e),a=this;return this.dialog.selectNumber(s,n,i,o,!1,function(t){a.input(e,t)}),!0},Game.prototype.handleSelectText=function(t){if(this.skip)return!0;var e=t.label,n=Localize.labelToDialogTitle(e),i=t.type||"gameText",o=t.texts.map(function(t){return Localize(i,t)},this),s=this;return this.dialog.selectText(n,o,!1,function(t){s.input(e,t
socket.emit("unready"),blocking=!0},$("button-start-game").onclick=function(t){if(blocking)return t.returnValue=!1;var e=deckManager.loadDeck($("select-decks").value);if(!e)return void msgBox.alert(Localize.index("FAILED_TO_READ_DECK"));var n=e;n.live=$("input-live").checked,localStorage.setItem("live",n.live),socket.emit("startGame",n),blocking=!0},$("link-edit-deck").onclick=function(t){return window.open($("link-edit-deck").href),t.preventDefault(),!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"),n=CardInfo[t.selfLrig],i=CardInfo[t.opponentLrig],o=Localize.classes(n)+" vs "+Localize.classes(i);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"],n=["guest","guest-spectator"],i=["host-spectator","guest-spectator"],o=inArr(position,e)&&inArr(t.position,n)||inArr(position,n)&&inArr(t.position,e),s=inArr(t.position,i);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/")});