/*("http://localhost:16918")*/ var socketCluster = require("socketcluster-client"); var Backbone = require("backbone"); require("./backbone.modal-min"); var Handlebars = require("handlebars"); var $ = require("jquery"); //var Lobby = require("./client-lobby"); window.$ = $; Handlebars.registerHelper("health", function(lives, options){ var out = ""; for(var i = 0; i < 2; i++) { out += "' + '' + ''), templateCards: Handlebars.compile('{{#each this}}' + '
' + '{{#if _boost}}+{{_boost}}{{/if}}' + '' + '
' + '{{/each}}'), initialize: function(options){ var self = this; this.side = options.side; this.app = options.app; this.battleView = options.battleView; this.infoData = this.infoData || {}; this.leader = this.leader || {}; this.field = this.field || {}; }, render: function(){ this.renderInfo(); this.renderCloseField(); this.renderRangeField(); this.renderSiegeField(); this.renderWeatherField(); return this; }, renderInfo: function(){ var d = this.infoData; var l = this.leader; this.$info = this.$el.find(".game-info" + this.side); this.$info.find(".info-name").html(d.name); this.$info.find(".score").html(d.score); this.$info.find(".hand-card").html(d.hand); this.$info.find(".gwent-lives").html(this.lives(d.lives)); this.$info.find(".field-leader").html(this.template(l)) if(this.app.user.get("waiting") && this.side === ".player"){ this.$info.addClass("removeBackground"); } if(!this.app.user.get("waiting") && this.side === ".foe"){ this.$info.addClass("removeBackground"); } this.$info.find(".passing").html(d.passing ? "Passed" : ""); }, renderCloseField: function(){ if(!this.field.close) return; this.$fields = this.$el.find(".battleside" + this.side); var $field = this.$fields.find(".field-close").parent(); var cards = this.field.close._cards; var score = this.field.close._score; var html = this.templateCards(cards); $field.find(".field-close").html(html) $field.find(".large-field-counter").html(score) }, renderRangeField: function(){ if(!this.field.ranged) return; this.$fields = this.$el.find(".battleside" + this.side); var $field = this.$fields.find(".field-range").parent(); var cards = this.field.ranged._cards; var score = this.field.ranged._score; var html = this.templateCards(cards); $field.find(".field-range").html(html) $field.find(".large-field-counter").html(score) }, renderSiegeField: function(){ if(!this.field.siege) return; this.$fields = this.$el.find(".battleside" + this.side); var $field = this.$fields.find(".field-siege").parent(); var cards = this.field.siege._cards; var score = this.field.siege._score; var html = this.templateCards(cards); $field.find(".field-siege").html(html) $field.find(".large-field-counter").html(score) }, renderWeatherField: function(){ if(!this.field.weather) return; var $weatherField = this.$el.find(".field-weather"); var cards = this.field.weather._cards; $weatherField.html(this.templateCards(cards)); return this; }, lives: function(lives){ var out = ""; for(var i = 0; i < 2; i++) { out += "Your foe left the battle!') }) app.on("createRoom", this.createRoom, this); app.on("joinRoom", this.joinRoom, this); app.on("setName", this.setName, this); app.send("request:name", this.get("name") == "unnamed" ? null : {name: this.get("name")}); }, createRoom: function(){ this.get("app").send("request:createRoom"); }, joinRoom: function(){ this.get("app").send("request:joinRoom"); }, subscribeRoom: function(){ var room = this.get("room"); var app = this.get("app"); app.socket.subscribe(room); }, setName: function(name){ this.get("app").send("request:name", {name: name}); } }); var Lobby = Backbone.View.extend({ defaults: { id: "" }, className: "container", template: Handlebars.compile($("#matchmaker-template").html()), initialize: function(options){ this.user = options.user; this.app = options.app; this.listenTo(this.app.user, "change", this.render); $(this.el).prependTo('body'); this.render(); }, events: { "click .create-room": "createRoom", "click .join-room": "joinRoom", "blur .name-input": "changeName" }, render: function(){ this.$el.html(this.template(this.user.attributes)); return this; }, createRoom: function(){ this.app.trigger("createRoom"); }, joinRoom: function(){ this.app.trigger("joinRoom"); }, changeName: function(e){ var name = $(e.target).val(); this.app.trigger("setName", name); } }); module.exports = App;