Mission rotation

This commit is contained in:
Björn Dahlgren 2015-08-24 00:16:16 +02:00
parent 7c299a1c00
commit daaefa4fa1
17 changed files with 293 additions and 1 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,
});
});

View File

@ -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',
},
});
});

View File

@ -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);
}

View File

@ -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;
},
});
});

View File

@ -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);
},
});
});

View File

@ -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(),
};
},
});
});

View File

@ -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());
},
});
});

View File

@ -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");
},
});
});

View File

@ -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() {

View File

@ -0,0 +1,13 @@
<form>
<table class="table table-striped">
<thead>
<tr>
<th>Mission</th>
<th>&nbsp;</th>
</tr>
</thead>
<!-- want to insert collection items, here -->
<tbody></tbody>
</table>
</form>

View File

@ -0,0 +1,11 @@
<td>
<%-name%>
</td>
<td>
<a class="btn btn-primary btn-xs add pull-right">
<span class="glyphicon glyphicon-plus"></span>
Add
</a>
<div class="clearfix"></div>
</td>

View File

@ -0,0 +1,4 @@
<div class="row">
<div class="col-md-6 col-md-push-6" id="rotation"></div>
<div class="col-md-6 col-md-pull-6" id="available"></div>
</div>

View File

@ -0,0 +1,17 @@
<form>
<table class="table table-striped">
<thead>
<tr>
<th>Rotation</th>
</tr>
</thead>
<!-- want to insert collection items, here -->
<tbody></tbody>
</table>
</form>
<a class="btn btn-primary add-mission" href="#">
<span class="glyphicon glyphicon-plus"></span>
Add empty mission
</a>

View File

@ -0,0 +1,31 @@
<td>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="Name" value="<%- name %>">
</div>
</div>
<div class="form-group">
<label for="difficulty" class="col-sm-2 control-label">Difficulty</label>
<div class="col-sm-10">
<select id="difficulty" class="form-control">
<option value="recruit">Recruit</option>
<option value="regular">Regular</option>
<option value="veteran">Veteran</option>
<option value="mercenary">Mercenary</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-xs btn-danger delete">
<span class="glyphicon glyphicon-minus"></span>
Remove
</button>
</div>
</div>
</form>
</td>

View File

@ -8,6 +8,7 @@
<ul class="nav nav-tabs" style="margin-bottom: 15px;">
<li class="active"><a href="#tab-info" data-toggle="tab">Info</a></li>
<li><a href="#tab-mods" data-toggle="tab">Mods</a></li>
<li><a href="#tab-missions" data-toggle="tab">Missions</a></li>
<li><a href="#tab-players" data-toggle="tab">Players</a></li>
<li><a href="#tab-settings" data-toggle="tab">Settings</a></li>
</ul>
@ -16,6 +17,7 @@
<div class="tab-content">
<div class="tab-pane active" id="tab-info"></div>
<div class="tab-pane" id="tab-mods"></div>
<div class="tab-pane" id="tab-missions"></div>
<div class="tab-pane" id="tab-players"></div>
<div class="tab-pane" id="tab-settings"></div>
</div>