From daaefa4fa170bb6cac402e623ae4dfe4d6937ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Mon, 24 Aug 2015 00:16:16 +0200 Subject: [PATCH] Mission rotation --- lib/manager.js | 1 + lib/server.js | 3 ++ .../js/app/collections/mission_rotations.js | 14 ++++++ public/js/app/models/mission_rotation.js | 16 ++++++ public/js/app/router.js | 6 ++- .../views/servers/missions/available/list.js | 28 +++++++++++ .../servers/missions/available/list_item.js | 25 ++++++++++ public/js/app/views/servers/missions/index.js | 50 +++++++++++++++++++ .../views/servers/missions/rotation/list.js | 28 +++++++++++ .../servers/missions/rotation/list_item.js | 39 +++++++++++++++ public/js/app/views/servers/view.js | 6 +++ .../tpl/servers/missions/available/list.html | 13 +++++ .../servers/missions/available/list_item.html | 11 ++++ public/js/tpl/servers/missions/index.html | 4 ++ .../tpl/servers/missions/rotation/list.html | 17 +++++++ .../servers/missions/rotation/list_item.html | 31 ++++++++++++ public/js/tpl/servers/view.html | 2 + 17 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 public/js/app/collections/mission_rotations.js create mode 100644 public/js/app/models/mission_rotation.js create mode 100644 public/js/app/views/servers/missions/available/list.js create mode 100644 public/js/app/views/servers/missions/available/list_item.js create mode 100644 public/js/app/views/servers/missions/index.js create mode 100644 public/js/app/views/servers/missions/rotation/list.js create mode 100644 public/js/app/views/servers/missions/rotation/list_item.js create mode 100644 public/js/tpl/servers/missions/available/list.html create mode 100644 public/js/tpl/servers/missions/available/list_item.html create mode 100644 public/js/tpl/servers/missions/index.html create mode 100644 public/js/tpl/servers/missions/rotation/list.html create mode 100644 public/js/tpl/servers/missions/rotation/list_item.html diff --git a/lib/manager.js b/lib/manager.js index fa3a11d..5e90181 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -98,6 +98,7 @@ Manager.prototype.save = (function () { battle_eye: server.battle_eye, headless: server.headless, max_players: server.max_players, + missions: server.missions, mods: server.mods, password: server.password, persistent: server.persistent, diff --git a/lib/server.js b/lib/server.js index c752e03..b9f3469 100644 --- a/lib/server.js +++ b/lib/server.js @@ -43,6 +43,7 @@ Server.prototype.update = function (options) { this.battle_eye = options.battle_eye; this.headless = options.headless; this.max_players = options.max_players; + this.missions = options.missions; this.mods = options.mods || []; this.password = options.password; this.persistent = options.persistent; @@ -83,6 +84,7 @@ Server.prototype.start = function() { headlessClients: this.headless ? ["127.0.0.1"] : null, hostname: createServerTitle(this.title), localClient: this.headless ? ["127.0.0.1"] : null, + missions: this.missions, mods: this.mods, password: this.password, passwordAdmin: this.admin_password, @@ -192,6 +194,7 @@ Server.prototype.toJSON = function () { headless: this.headless, id: this.id, max_players: this.max_players, + missions: this.missions, mods: this.mods, password: this.password, persistent: this.persistent, diff --git a/public/js/app/collections/mission_rotations.js b/public/js/app/collections/mission_rotations.js new file mode 100644 index 0000000..98a0c4f --- /dev/null +++ b/public/js/app/collections/mission_rotations.js @@ -0,0 +1,14 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + MissionRotation = require('app/models/mission_rotation'); + + return Backbone.Collection.extend({ + model: MissionRotation, + }); + +}); diff --git a/public/js/app/models/mission_rotation.js b/public/js/app/models/mission_rotation.js new file mode 100644 index 0000000..abc5af0 --- /dev/null +++ b/public/js/app/models/mission_rotation.js @@ -0,0 +1,16 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'); + + return Backbone.Model.extend({ + defaults: { + name: '', + difficulty: 'recruit', + }, + }); + +}); diff --git a/public/js/app/router.js b/public/js/app/router.js index 0044f37..c48e5b3 100644 --- a/public/js/app/router.js +++ b/public/js/app/router.js @@ -74,7 +74,11 @@ define(function (require) { server: function (id) { var server = servers.get(id); if (server) { - layoutView.content.show(new ServerView({model: server, mods: mods})); + layoutView.content.show(new ServerView({ + model: server, + missions: missions, + mods: mods, + })); } else { this.navigate("#", true); } diff --git a/public/js/app/views/servers/missions/available/list.js b/public/js/app/views/servers/missions/available/list.js new file mode 100644 index 0000000..59c9d4b --- /dev/null +++ b/public/js/app/views/servers/missions/available/list.js @@ -0,0 +1,28 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + ListItemView = require('app/views/servers/missions/available/list_item'), + tpl = require('text!tpl/servers/missions/available/list.html'); + + return Marionette.CompositeView.extend({ + itemView: ListItemView, + itemViewContainer: "tbody", + template: _.template(tpl), + + buildItemView: function(item, ItemViewType, itemViewOptions){ + var self = this; + var options = _.extend({model: item}, itemViewOptions); + var view = new ItemViewType(options); + view.on('add', function (model) { + self.trigger('add', model); + }); + return view; + }, + }); + +}); diff --git a/public/js/app/views/servers/missions/available/list_item.js b/public/js/app/views/servers/missions/available/list_item.js new file mode 100644 index 0000000..b21c4c6 --- /dev/null +++ b/public/js/app/views/servers/missions/available/list_item.js @@ -0,0 +1,25 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + tpl = require('text!tpl/servers/missions/available/list_item.html'), + + template = _.template(tpl); + + return Marionette.ItemView.extend({ + tagName: "tr", + template: template, + + events: { + "click .add": "add" + }, + + add: function () { + this.trigger('add', this.model); + }, + }); +}); diff --git a/public/js/app/views/servers/missions/index.js b/public/js/app/views/servers/missions/index.js new file mode 100644 index 0000000..8d54dc3 --- /dev/null +++ b/public/js/app/views/servers/missions/index.js @@ -0,0 +1,50 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + MissionRotations = require('app/collections/mission_rotations'), + AvailableListView = require('app/views/servers/missions/available/list'), + RotationListView = require('app/views/servers/missions/rotation/list'), + tpl = require('text!tpl/servers/missions/index.html'); + + return Marionette.Layout.extend({ + template: _.template(tpl), + + regions: { + availableView: "#available", + rotationView: "#rotation", + }, + + initialize: function (options) { + this.missions = options.missions; + this.server = options.server; + + this.rotationCollection = new MissionRotations(this.server.get('missions')); + }, + + onRender: function() { + var self = this; + + var availableListView = new AvailableListView({collection: this.missions}); + availableListView.on('add', function (model) { + self.rotationCollection.add([{ + name: model.get('name').replace('.pbo', ''), + }]); + }); + var rotationListView = new RotationListView({collection: this.rotationCollection}); + + this.availableView.show(availableListView); + this.rotationView.show(rotationListView); + }, + + serialize : function() { + return { + missions: this.rotationCollection.toJSON(), + }; + }, + }); +}); diff --git a/public/js/app/views/servers/missions/rotation/list.js b/public/js/app/views/servers/missions/rotation/list.js new file mode 100644 index 0000000..5c97fe2 --- /dev/null +++ b/public/js/app/views/servers/missions/rotation/list.js @@ -0,0 +1,28 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + MissionRotation = require('app/models/mission_rotation'), + ListItemView = require('app/views/servers/missions/rotation/list_item'), + tpl = require('text!tpl/servers/missions/rotation/list.html'); + + return Marionette.CompositeView.extend({ + itemView: ListItemView, + itemViewContainer: "tbody", + template: _.template(tpl), + + events: { + "click .add-mission": "addMission", + }, + + addMission: function (e) { + e.preventDefault(); + this.collection.add(new MissionRotation()); + }, + }); + +}); diff --git a/public/js/app/views/servers/missions/rotation/list_item.js b/public/js/app/views/servers/missions/rotation/list_item.js new file mode 100644 index 0000000..7abaca5 --- /dev/null +++ b/public/js/app/views/servers/missions/rotation/list_item.js @@ -0,0 +1,39 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'), + Marionette = require('marionette'), + tpl = require('text!tpl/servers/missions/rotation/list_item.html'), + + template = _.template(tpl); + + return Marionette.ItemView.extend({ + tagName: "tr", + template: template, + + events: { + "click button.delete": "delete", + "change select#difficulty": "changed", + "change input#name": "changed", + }, + + changed: function (e) { + var val = $(e.target).val(); + this.model.set(e.target.id, val); + }, + + delete: function (e) { + e.preventDefault(); + this.model.destroy(); + }, + + onRender: function() { + var difficulty = this.model.get('difficulty'); + var $option = this.$el.find("#difficulty option[value='" + difficulty + "']"); + $option.attr("selected", "selected"); + }, + }); +}); diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index b2474b6..d0e5799 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -9,6 +9,7 @@ define(function (require) { Mods = require('app/collections/mods'), FormView = require('app/views/servers/form'), InfoView = require('app/views/servers/info'), + MissionsView = require('app/views/servers/missions/index'), ModsListView = require('app/views/servers/mods/list'), PlayersView = require('app/views/servers/players'), tpl = require('text!tpl/servers/view.html'); @@ -18,6 +19,7 @@ define(function (require) { regions: { infoView: "#tab-info", + missionsView: "#tab-missions", modsView: "#tab-mods", playersView: "#tab-players", settingsView: "#tab-settings", @@ -33,11 +35,13 @@ define(function (require) { }, initialize: function (options) { + this.missions = options.missions; this.mods = options.mods; }, onRender: function() { this.infoView.show(new InfoView({model: this.model})); + this.missionsView.show(new MissionsView({missions: this.missions, server: this.model})); this.modsView.show(new ModsListView({collection: this.mods, server: this.model})); this.playersView.show(new PlayersView({model: this.model})); this.settingsView.show(new FormView({model: this.model})); @@ -45,6 +49,7 @@ define(function (require) { serverUpdated: function() { this.infoView.currentView.render(); + this.missionsView.currentView.render(); this.modsView.currentView.render(); this.playersView.currentView.render(); this.settingsView.currentView.render(); @@ -55,6 +60,7 @@ define(function (require) { var self = this; var oldId = this.model.get('id'); var data = this.settingsView.currentView.serialize(); + _.extend(data, this.missionsView.currentView.serialize()); _.extend(data, this.modsView.currentView.serialize()); this.model.save(data, { success: function() { diff --git a/public/js/tpl/servers/missions/available/list.html b/public/js/tpl/servers/missions/available/list.html new file mode 100644 index 0000000..f76ff03 --- /dev/null +++ b/public/js/tpl/servers/missions/available/list.html @@ -0,0 +1,13 @@ +
+ + + + + + + + + + +
Mission 
+
diff --git a/public/js/tpl/servers/missions/available/list_item.html b/public/js/tpl/servers/missions/available/list_item.html new file mode 100644 index 0000000..970eaf3 --- /dev/null +++ b/public/js/tpl/servers/missions/available/list_item.html @@ -0,0 +1,11 @@ + + <%-name%> + + + + + Add + + +
+ diff --git a/public/js/tpl/servers/missions/index.html b/public/js/tpl/servers/missions/index.html new file mode 100644 index 0000000..0af5c0c --- /dev/null +++ b/public/js/tpl/servers/missions/index.html @@ -0,0 +1,4 @@ +
+
+
+
diff --git a/public/js/tpl/servers/missions/rotation/list.html b/public/js/tpl/servers/missions/rotation/list.html new file mode 100644 index 0000000..f1fada7 --- /dev/null +++ b/public/js/tpl/servers/missions/rotation/list.html @@ -0,0 +1,17 @@ +
+ + + + + + + + + +
Rotation
+
+ + + + Add empty mission + diff --git a/public/js/tpl/servers/missions/rotation/list_item.html b/public/js/tpl/servers/missions/rotation/list_item.html new file mode 100644 index 0000000..ee8cf8b --- /dev/null +++ b/public/js/tpl/servers/missions/rotation/list_item.html @@ -0,0 +1,31 @@ + +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+ diff --git a/public/js/tpl/servers/view.html b/public/js/tpl/servers/view.html index 0c70204..1c04f7b 100644 --- a/public/js/tpl/servers/view.html +++ b/public/js/tpl/servers/view.html @@ -8,6 +8,7 @@ @@ -16,6 +17,7 @@
+