var socket = require("socket.io-client"); var Backbone = require("backbone"); require("./backbone.modal-min"); var Handlebars = require('handlebars/runtime').default; var $ = require("jquery"); window.$ = $; Handlebars.registerPartial("card", require("../templates/cards.handlebars")); Handlebars.registerHelper("health", function(lives){ var out = ""; for(var i = 0; i < 2; i++) { out += "Your foe left the battle!') }) app.receive("played:medic", function(data){ var cards = JSON.parse(data.cards); console.log("played medic"); self.set("medicDiscard", { cards: cards }); }) app.receive("played:agile", function(data){ console.log("played agile"); self.set("setAgile", data.cardID); }) app.receive("played:horn", function(data){ console.log("played horn"); self.set("setHorn", data.cardID); }) app.receive("redraw:cards", function(){ self.set("isReDrawing", true); }) app.receive("redraw:close", function(){ self.set("isReDrawing", false); }) app.receive("update:hand", function(data){ app.trigger("update:hand", data); }) app.receive("update:fields", function(data){ app.trigger("update:fields", data); }) app.receive("update:info", function(data){ app.trigger("update:info", data); }) app.on("startMatchmaking", this.startMatchmaking, this); app.on("joinRoom", this.joinRoom, this); app.on("setName", this.setName, this); app.on("setDeck", this.setDeck, this); app.send("request:name", this.get("name") == "unnamed" ? null : {name: this.get("name")}); }, startMatchmaking: function(){ this.set("inMatchmakerQueue", true); this.get("app").send("request:matchmaking"); }, joinRoom: function(){ this.get("app").send("request:joinRoom"); this.set("inMatchmakerQueue", false); }, 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}); }, setDeck: function(deckKey){ console.log("deck: ", deckKey); this.set("deckKey", deckKey); this.get("app").send("set:deck", {deck: deckKey}); } }); var Lobby = Backbone.View.extend({ defaults: { id: "" }, className: "container", template: require("../templates/lobby.handlebars"), 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 .startMatchmaking": "startMatchmaking", /*"click .join-room": "joinRoom",*/ "blur .name-input": "changeName", "change #deckChoice": "setDeck" }, render: function(){ this.$el.html(this.template(this.user.attributes)); /*this.$el.find("#deckChoice option[value='" + this.app.user.get("setDeck") + "']").attr("selected", "selected")*/ return this; }, startMatchmaking: function(){ this.app.trigger("startMatchmaking"); }, joinRoom: function(){ this.app.trigger("joinRoom"); }, setDeck: function(e){ var val = $(e.target).val(); this.app.trigger("setDeck", val); this.$el.find("#deckChoice option[value='" + val + "']").attr("selected", "selected") }, changeName: function(e){ var name = $(e.target).val(); this.app.trigger("setName", name); } }); module.exports = App;