Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
working on presenting shps
Browse files Browse the repository at this point in the history
  • Loading branch information
kbingman committed May 19, 2012
1 parent 82f2f06 commit f45f342
Show file tree
Hide file tree
Showing 20 changed files with 288 additions and 116 deletions.
4 changes: 1 addition & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var http = require('http'),
ss.client.define('main', {
view: 'app.html',
css: ['libs/bootstrap', 'index.css'],
code: ['libs/jquery.min.js', 'libs/bootstrap.js', 'app'],
system: '*',
code: ['libs/jquery.min.js', 'libs/bootstrap.js', 'app', 'system'],
tmpl: '*'
});

Expand All @@ -17,7 +16,6 @@ ss.client.define('admin', {
view: 'admin.html',
css: ['libs/bootstrap/bootstrap.css','libs/bootstrap/bootstrap-responsive.css', 'admin'],
code: ['libs/jquery.min.js', 'libs/bootstrap.js', 'admin', 'system'],
system: '*',
tmpl: '*'
});

Expand Down
41 changes: 24 additions & 17 deletions client/code/admin/players.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Main systems index view
var utilities = require('/utilities'),
indexPresenter = require('/presenters/players/index'),
showPresenter = require('/presenters/players/show');

ss.event.on('players', function(players) {
Admin.players = players;

var html = ss.tmpl['admin-players-index'].render({
players: players
});

$('#content').html(html);

indexPresenter.present(players);
return
});

Expand All @@ -17,17 +15,26 @@ ss.event.on('login', function(player) {
return
});

ss.event.on('updatePlayer', function(player){
Admin.players = Admin.players.remove(function(p){
return p._id == player._id;
});
Admin.players.push(player);
indexPresenter.present(Admin.players);
console.log(player);
return
})

exports.show = function (id) {
var player = Admin.players.find(function(p){
return p._id == id;
});
if(player){
showPresenter.present(player);
}
};




// exports.showPlayers = function(){
// var players = Admin.players.map(function(player){
// return player;
// });
//
// var html = ss.tmpl['admin-players-index'].render({
// // players: player
// });
// $('#content').html(html);
// }

16 changes: 16 additions & 0 deletions client/code/admin/presenters/players/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.present = function(players){

var html = ss.tmpl['admin-players-index'].render({
players: players
});

$('#content').html(html);

$('#players a').on('click', function(e){
e.preventDefault();
window.router.dispatch('on', $(e.currentTarget).attr('href').replace('#',''));
});

return

}
26 changes: 26 additions & 0 deletions client/code/admin/presenters/players/show.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var utilities = require('/utilities');

exports.present = function(player){

var html = ss.tmpl['admin-players-show'].render({
player: player
});

$('#modal').html(html);
utilities.openModal();

$('form#edit-player').submit(function(e){
e.preventDefault();

var params = utilities.jsonifyParams($(this).serializeArray());

ss.rpc('players.update', player._id, params, function(success){
console.log(success);
$('#modal').find('.modal').modal('hide');
window.router.setRoute('/players');
});
});

return

}
32 changes: 32 additions & 0 deletions client/code/admin/presenters/ships/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ exports.present = function(ship){
var html = ss.tmpl['admin-ships-edit'].render(exports.context(ship), partials);

$('#content').html(html);

// Events

$('fieldset.list button').on('click', function(e){
e.preventDefault();
var fieldset = $(this).parents('fieldset');
var value = fieldset.find('select').val();

Admin.ship.weapons.push(value);

ss.rpc('ships.update', Admin.ship._id, { weapons: Admin.ship.weapons }, function(success){
console.log(success);
window.router.dispatch('on', '/ships/' + Admin.ship._id);
});
});

$('fieldset.list a.remove').on('click', function(){
var value = $(this).prev('span').text();
Admin.ship.weapons = Admin.ship.weapons .remove(function(w){
return w == value;
});
ss.rpc('ships.update', Admin.ship._id, { weapons: Admin.ship.weapons }, function(success){
console.log(success);
window.router.dispatch('on', '/ships/' + Admin.ship._id);
});
});

var form = $('form#edit-ship-form');
form.find('div.radio button.btn').popover({ placement: 'bottom' });

utilities.setFormActions(Admin.ship, form);

}

exports.context = function(ship){
Expand Down
13 changes: 13 additions & 0 deletions client/code/admin/presenters/ships/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ exports.present = function(){
var html = ss.tmpl['admin-ships-new'].render(exports.context(ship), partials);

$('#content').html(html);

// Events
$('form#new-ship-form').on('submit', function(e){
e.preventDefault();

var params = utilities.jsonifyParams($(this).serializeArray());

ss.rpc('ships.create', params, function(success){
console.log(success);
window.router.setRoute('/ships/' + Admin.ship._id);
});
});
return;
}

exports.context = function(ship){
Expand Down
16 changes: 11 additions & 5 deletions client/code/admin/presenters/ships/update.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
exports.present = function(ship){
var html = ss.tmpl['admin-ships-ship'].render({
var html = ss.tmpl['admin-ships-ship'].render(exports.context(ship));

$('#ship-usc').html(html);
// draw(ship.price)
}

exports.context = function(ship){
return {
ship: ship,
weaponsSentence: ship.weapons.toSentence(),
price: ship.price ? ship.price.format() : 0
});

$('#ship-usc').html(html);
draw(ship.price)
}
}

// Private
// ------------------------------------------------------------

var draw = function(price) {
var height = price / 1000 * 42;
Expand Down
2 changes: 1 addition & 1 deletion client/code/admin/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var routes = {
'/players': {
on: function(){ ss.rpc('players.all'); },
'/:id': {
on: players.showPlayer
on: players.show
}
}

Expand Down
41 changes: 0 additions & 41 deletions client/code/admin/ships.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,7 @@ ss.event.on('updateShip', function(params) {
// Views
// ------------------------------------------------ //
exports.new = function(){

newPresenter.present();
// Events
$('form#new-ship-form').on('submit', function(e){
e.preventDefault();

var params = utilities.jsonifyParams($(this).serializeArray());

ss.rpc('ships.create', params, function(success){
console.log(success);
window.router.setRoute('/ships/' + Admin.ship._id);
});
});
}

exports.edit = function(){
Expand All @@ -64,34 +52,5 @@ exports.edit = function(){

editShipPresenter.present(Admin.ship);
updateShipPresenter.present(Admin.ship);
// Events

$('fieldset.list button').on('click', function(e){
e.preventDefault();
var fieldset = $(this).parents('fieldset');
var value = fieldset.find('select').val();

Admin.ship.weapons.push(value);

ss.rpc('ships.update', Admin.ship._id, { weapons: Admin.ship.weapons }, function(success){
console.log(success);
window.router.dispatch('on', '/ships/' + Admin.ship._id);
});
});

$('fieldset.list a.remove').on('click', function(){
var value = $(this).prev('span').text();
Admin.ship.weapons = Admin.ship.weapons .remove(function(w){
return w == value;
});
ss.rpc('ships.update', Admin.ship._id, { weapons: Admin.ship.weapons }, function(success){
console.log(success);
window.router.dispatch('on', '/ships/' + Admin.ship._id);
});
});

var form = $('form#edit-ship-form');
form.find('div.radio button.btn').popover({ placement: 'bottom' });

utilities.setFormActions(Admin.ship, form);
}
1 change: 0 additions & 1 deletion client/code/admin/utilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('sugar');
require('inflections');

exports.jsonifyParams = function(array){
Expand Down
3 changes: 3 additions & 0 deletions client/code/app/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ ss.server.on('reconnect', function(){
console.log('Connection back up :-)');
});


Sector = {};

ss.server.on('ready', function(){

// Wait for the DOM to finish loading
jQuery(function(){

require('sugar');
require('/map');
require('/player');
ss.rpc('systems.all');

});
Expand Down
37 changes: 5 additions & 32 deletions client/code/app/map.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
var map = require('/presenters/map');

ss.event.on('systems', function(systems) {
console.log(systems.length)
Sector.systems = systems;

var html = ss.tmpl['systems-map'].render({
systems : systems.map(function(system){
system.x = system.x - 24;
system.y = system.y - 24;
system.slug = system.stars[0].klass.toLowerCase();
return system;
})
Sector.homeworld = Sector.systems.find(function(s){
return s._id = Sector.player.homeworldId;
});
$('#content').html(html);

var canvas = $('canvas#canvas');
canvas.attr({
width: $(window).width(),
height: $(window).height()
})

// var canvas = document.getElementById("backdrop");
if (canvas[0].getContext) {
var ctx = canvas[0].getContext("2d");

ctx.strokeStyle = "hsla(30, 100%, 50%, 0.72)";
ctx.lineWidth = "2";
ctx.moveTo(431, 242);
ctx.lineTo(1101, 114);
ctx.stroke();

ctx.beginPath();
ctx.arc($(window).width() / 2, $(window).height() /2, 299, 0, Math.PI*2, true);
ctx.closePath();
ctx.stroke();
ctx.fillStyle = "hsla(30, 100%, 50%, 0.04)";
ctx.fill();

}
map.present(Sector.systems);

return;
});
Expand Down
27 changes: 27 additions & 0 deletions client/code/app/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ss.event.on('login', function(player) {
Sector.player = player;

ss.rpc('ships.all', function(success){
console.log(success)
});

return
});

ss.event.on('ships', function(ships){
Sector.player.ships = ships;
ships.forEach(function(s){
// Plot position
console.log(s.name);
})
});

ss.rpc('app.getCurrentPlayer', function(success){
console.log(success)
});






Loading

0 comments on commit f45f342

Please sign in to comment.