1 line
8.5 KiB
JavaScript
1 line
8.5 KiB
JavaScript
|
define(["jquery","storage"],function(e,t){var n=Class.extend({init:function(){this.currentPage=1,this.blinkInterval=null,this.previousState=null,this.isParchmentReady=!0,this.ready=!1,this.storage=new t,this.watchNameInputInterval=setInterval(this.toggleButton.bind(this),100),this.$playButton=e(".play"),this.$playDiv=e(".play div")},setGame:function(e){this.game=e,this.isMobile=this.game.renderer.mobile,this.isTablet=this.game.renderer.tablet,this.isDesktop=!this.isMobile&&!this.isTablet,this.supportsWorkers=!!window.Worker,this.ready=!0},center:function(){window.scrollTo(0,1)},canStartGame:function(){return this.isDesktop?this.game&&this.game.map&&this.game.map.isLoaded:this.game},tryStartingGame:function(e,t){var n=this,r=this.$playButton;if(e!=="")if(!this.ready||!this.canStartGame()){this.isMobile||r.addClass("loading"),this.$playDiv.unbind("click");var i=setInterval(function(){log.debug("waiting..."),n.canStartGame()&&(setTimeout(function(){n.isMobile||r.removeClass("loading")},1500),clearInterval(i),n.startGame(e,t))},100)}else this.$playDiv.unbind("click"),this.startGame(e,t)},startGame:function(e,t){var n=this;t&&t(),this.hideIntro(function(){n.isDesktop||n.game.loadMap(),n.start(e)})},start:function(t){var n=this,r=!n.storage.hasAlreadyPlayed();if(t&&!this.game.started){var i=!1,s=this.config;i||(log.debug("Starting game with build config."),this.game.setServerOptions(s.build.host,s.build.port,t)),this.center(),this.game.run(function(){e("body").addClass("started"),r&&n.toggleInstructions()})}},setMouseCoordinates:function(t){var n=e("#container").offset(),r=this.game.renderer.getScaleFactor(),i=this.game.renderer.getWidth(),s=this.game.renderer.getHeight(),o=this.game.mouse;o.x=t.pageX-n.left-(this.isMobile?0:5*r),o.y=t.pageY-n.top-(this.isMobile?0:7*r),o.x<=0?o.x=0:o.x>=i&&(o.x=i-1),o.y<=0?o.y=0:o.y>=s&&(o.y=s-1)},initHealthBar:function(){var t=this.game.renderer.getScaleFactor(),n=e("#healthbar").width()-12*t;this.game.onPlayerHealthChange(function(t,r){var i=Math.round(n/r*(t>0?t:0));e("#hitpoints").css("width",i+"px")}),this.game.onPlayerHurt(this.blinkHealthBar.bind(this))},blinkHealthBar:function(){var t=e("#hitpoints");t.addClass("white"),setTimeout(function(){t.removeClass("white")},500)},toggleButton:function(){var t=e("#parchment input").val(),n=e("#createcharacter .play");t&&t.length>0?(n.removeClass("disabled"),e("#character").removeClass("disabled")):(n.addClass("disabled"),e("#character").addClass("disabled"))},hideIntro:function(t){clearInterval(this.watchNameInputInterval),e("body").removeClass("intro"),setTimeout(function(){e("body").addClass("game"),t()},1e3)},showChat:function(){this.game.started&&(e("#chatbox").addClass("active"),e("#chatinput").focus(),e("#chatbutton").addClass("active"))},hideChat:function(){this.game.started&&(e("#chatbox").removeClass("active"),e("#chatinput").blur(),e("#chatbutton").removeClass("active"))},toggleInstructions:function(){e("#achievements").hasClass("active")&&(this.toggleAchievements(),e("#achievementsbutton").removeClass("active")),e("#instructions").toggleClass("active")},toggleAchievements:function(){e("#instructions").hasClass("active")&&(this.toggleInstructions(),e("#helpbutton").removeClass("active")),this.resetPage(),e("#achievements").toggleClass("active")},resetPage:function(){var t=this,n=e("#achievements");n.hasClass("active")&&n.bind(TRANSITIONEND,function(){n.removeClass("page"+t.currentPage).addClass("page1"),t.currentPage=1,n.unbind(TRANSITIONEND)})},initEquipmentIcons:function(){var t=this.game.renderer.getScaleFactor(),n=function(e){return"img/"+t+"/item-"+e+".png"},r=this.game.player.getWeaponName(),i=this.game.player.getSpriteName(),s=n(r),o=n(i);e("#weapon").css("background-image",'url("'+s+'")'),i!=="firefox"&&e("#armor").css("background-image",'url("'+o+'")')},hideWindows:function(){e("#achievements").hasClass("active")&&(this.toggleAchievements(),e("#achievementsbutton").removeClass("active")),e("#instructions").hasClass("active")&&(this.toggleInstructions(),e("#helpbutton").removeClass("active")),e("body").hasClass("credits")&&thi
|