Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

copying levels, dashboard and ui improvements

  • Loading branch information...
commit 7f9b81b53ff47a545107600550593b9dfdb0d5e1 1 parent f7bb5a5
@jomoho authored
View
0  .monitor
No changes.
View
4 grid.js
@@ -97,4 +97,6 @@ Grid.prototype.resize= function(width, height, clear){
}
this.blit(copy,0,0);
};
-
+Grid.prototype.rename = function(name){
+ this.name = name;
+};
View
59 helpers.js
@@ -0,0 +1,59 @@
+/*
+ * Javascript Humane Dates
+ * Copyright (c) 2008 Dean Landolt (deanlandolt.com)
+ * Re-write by Zach Leatherman (zachleat.com)
+ *
+ * Adopted from the John Resig's pretty.js
+ * at http://ejohn.org/blog/javascript-pretty-date
+ * and henrah's proposed modification
+ * at http://ejohn.org/blog/javascript-pretty-date/#comment-297458
+ *
+ * Licensed under the MIT license.
+ */
+
+
+module.exports.date = function humane_date(date){
+ var time_formats = [
+ [60, 'Just Now'],
+ [90, '1 Minute'], // 60*1.5
+ [3600, 'Minutes', 60], // 60*60, 60
+ [5400, '1 Hour'], // 60*60*1.5
+ [86400, 'Hours', 3600], // 60*60*24, 60*60
+ [129600, '1 Day'], // 60*60*24*1.5
+ [604800, 'Days', 86400], // 60*60*24*7, 60*60*24
+ [907200, '1 Week'], // 60*60*24*7*1.5
+ [2628000, 'Weeks', 604800], // 60*60*24*(365/12), 60*60*24*7
+ [3942000, '1 Month'], // 60*60*24*(365/12)*1.5
+ [31536000, 'Months', 2628000], // 60*60*24*365, 60*60*24*(365/12)
+ [47304000, '1 Year'], // 60*60*24*365*1.5
+ [3153600000, 'Years', 31536000], // 60*60*24*365*100, 60*60*24*365
+ [4730400000, '1 Century'], // 60*60*24*365*100*1.5
+ ];
+ date = new Date(''+date);
+ var dt = new Date(),
+ seconds = ((dt - date) / 1000),
+ token = ' Ago',
+ i = 0,
+ format;
+
+ if (seconds < 0) {
+ seconds = Math.abs(seconds);
+ token = '';
+ }
+
+ while (format = time_formats[i++]) {
+ if (seconds < format[0]) {
+ if (format.length == 2) {
+ return format[1] + (i > 1 ? token : ''); // Conditional so we don't return Just Now Ago
+ } else {
+ return Math.round(seconds / format[2]) + ' ' + format[1] + (i > 1 ? token : '');
+ }
+ }
+ }
+
+ // overflow for centuries
+ if(seconds > 4730400000)
+ return Math.round(seconds / 4730400000) + ' Centuries' + token;
+
+ return date+'';
+};
View
53 io.js
@@ -87,33 +87,38 @@ activateProtocol = function(io, client, fn){
//syncing
client.on(client.channel, function(msg){
- msg.user = client.user._id;
- redisclient.publish(client.channel, JSON.stringify(msg));
-
+ msg.user = client.user._id;
+
if(msg.type === 'function' && msg.name){
- levels.load(level._id, function(err, level){
- var grid = new Grid({
- width: level.width,
- height: level.height,
- name: level.name,
- data: level.data
- });
- var args = [];
- for(var i in msg.args){
- args[i] = msg.args[i];
- }
- grid[msg.name].apply(grid, args);
- level.lastUpdate= Date.now();
- level.name = grid.name;
- level.width = grid.width;
- level.height = grid.height;
- level.data = JSON.stringify(grid.data);
- level.save(function(err){
- if(err){
- console.log(err);
+ if(msg.context === 'grid'){
+ levels.load(level._id, function(err, level){
+ var grid = new Grid({
+ width: level.width,
+ height: level.height,
+ name: level.name,
+ data: level.data
+ });
+ var args = [];
+ for(var i in msg.args){
+ args[i] = msg.args[i];
}
+ grid[msg.name].apply(grid, args);
+ level.lastUpdate= Date.now();
+ level.name = grid.name;
+ level.width = grid.width;
+ level.height = grid.height;
+ level.data = JSON.stringify(grid.data);
+ level.save(function(err){
+ if(err){
+ console.log(err);
+ }
+ });
});
- });
+ }else if(msg.context === 'chat'){
+ msg.args[0].time = Date.now();
+ msg.args[0].username = client.user.name;
+ }
+ redisclient.publish(client.channel, JSON.stringify(msg));
}
});
fn(level);
View
32 levels.js
@@ -1,6 +1,7 @@
var mongoose = require('mongoose'),
crypto = require('crypto'),
- redis = require('redis');
+ redis = require('redis'),
+ users = require('./users');
var Schema = mongoose.Schema,
LevelSchema,
@@ -85,14 +86,18 @@ LevelSchema = new Schema({
'date': {type: Date, 'default': Date.now},
'lastUpdate': {type: Date, 'default': Date.now},
'creator': {type: Schema.ObjectId},
+ 'creatorName': {type: String, 'default': 'anonymous'},
'width': {type: Number, 'default': 16},
'height': {type: Number, 'default': 16},
'data': {type: String, 'default': initData()}
});
-
+LevelSchema.pre('save', function(next) {
+ console.log(this.creator);
+ next();
+});
mongoose.model('Level', LevelSchema);
-Level = mongoose.model('Level');
+module.exports.Level = Level = mongoose.model('Level');
module.exports.load = function(id, fn){
Level.findById( id, function(err, lvl){
@@ -104,14 +109,27 @@ module.exports.load = function(id, fn){
});
};
-module.exports.create = function( fn){
- var lvl = new Level();
- lvl.save(function(err){
+module.exports.create = function(userId, fn){
+ users.User.findOne({_id: userId}, function(err, user){
if(err){
console.log(err);
+ fn(err, null);
}
- fn(err, lvl);
+ console.log(user.name + ' created a level');
+ var level = new Level();
+ level.creator = user._id;
+ level.creatorName = user.name;
+
+
+ level.save(function(err){
+ if(err){
+ console.log(err);
+ }
+ console.log(user.name + ' created the level: '+ level.name);
+ fn(err, level);
+ });
});
+
};
module.exports.update = function(lvl){
lvl.lastUpdate = Date.now();
View
144 server.js
@@ -12,7 +12,8 @@ var express = require('express'),
redisclient = redis.createClient(),
markdown = require('node-markdown').Markdown,
io = require('./io'),
- Grid = require('./grid').Grid;
+ Grid = require('./grid').Grid,
+ help = require('./helpers');
//environement for google analytics and the like
var env = {
@@ -36,6 +37,7 @@ app.configure(function(){
}
});
});
+var dt = Date.now();
app.configure('development', function(){
app.use(express.static(__dirname + '/static'));
@@ -60,6 +62,12 @@ app.dynamicHelpers({
sessionId: function(req, res){
return req.session.sid;
},
+ origin: function(req,res){
+ return req.route.path;
+ },
+ user: function(req, res){
+ return req.session.user;
+ },
flash: function(req, res){
return req.flash();
},
@@ -79,7 +87,7 @@ app.dynamicHelpers({
});
var title= function(name){
- return 'togather - '+name;
+ return 'Togather - '+name;
};
var initSession = function (req, res, next){
next();
@@ -101,20 +109,47 @@ var all = [initSession],
* pages
*/
app.get('/', all, function(req, res){
- res.render('front', {locals: {
- title: title('Welcome')
- }});
+
+ if(req.session.user){
+ levels.Level.find({creator: req.session.user._id})
+ .sort('lastUpdate', 'descending')
+ .exec(function(err, levels){
+ if(err){
+ req.flash('warn', err.message);
+ }
+ res.render('dashboard', {locals: {
+ title: title('Dashboard'),
+ levels: decorateLevels(req, res, levels)
+ }});
+ });
+
+ }else{
+ res.render('front', {locals: {
+ title: title('Welcome')
+ }});
+ }
+
});
-app.get('/edit', login, function(req, res){
- res.redirect('/levels');
+
+app.get('/dev', admin, function(req, res){
+ res.render('dev', {locals: {
+ title: title('dev console')
+ }});
});
-app.get('/create', login, function(req, res){
- levels.create(function(err, lvl){
- res.redirect('/edit/'+lvl._id);
+
+app.get('/level/create', login, function(req, res){
+ levels.create(req.session.user._id, function(err, lvl){
+ if(err){
+ req.flash('warn', err.message);
+ res.redirect('/level/list');
+
+ }else{
+ res.redirect('/level/'+lvl._id+'/edit');
+ }
});
});
-app.get('/edit/:level', login, function(req, res){
+app.get('/level/:level/edit', login, function(req, res){
if(req.params.level==='newlevel'){
res.redirect('/create');
}else{
@@ -136,17 +171,83 @@ app.get('/edit/:level', login, function(req, res){
});
}
});
-app.get('/levels', login, function(req, res){
- levels.getAll( function(err, levels){
+app.get('/level/:level/copy', login, function(req, res){
+ if(req.params.level==='newlevel'){
+ res.redirect('/create');
+ }else{
+ levels.load(req.params.level, function(err, level){
+ if(err){
+ req.flash('warn', 'level not found');
+ res.redirect('/level/list');
+ return;
+ }
+
+ levels.create(req.session.user._id, function(err, clevel){
+ if(err){
+ req.flash('warn', err.message);
+ res.redirect('/level/list');
+
+ }else{
+ clevel.name= 're: ' + level.name;
+ clevel.width= level.width;
+ clevel.height= level.height;
+ clevel.data = level.data;
+ clevel.save(function(err){
+ res.redirect('/level/'+level._id+'/edit');
+ });
+
+
+ }
+ });
+ });
+ }
+});
+var decorateLevels= function(req, res, levellist){
+ for(var i =0; i< levellist.length; i++){
+ levellist[i].prettydate = help.date(levellist[i].date+'');
+ levellist[i].prettyupdate = help.date(levellist[i].lastUpdate+'');
+ if(levellist[i].creator == req.session.user._id || req.session.user.role==='admin'){
+ levellist[i].owner = true;
+ }
+ }
+ return levellist;
+};
+app.get('/level/list', login, function(req, res){
+
+ levels.getAll( function(err, levellist){
+
res.render('list',{
locals: {
title: title('Levels'),
- levels: levels
+ levels: decorateLevels(req, res, levellist)
}
});
});
});
-app.get('json/levels/:from/:to', login, function(req, res){
+var deleteLevel = function(req, res){
+ levels.load(req.params.level, function(err, level){
+ if(level.creator == req.session.user._id || req.session.user.role==='admin'){
+ level.remove(function(err){
+ req.flash('info', 'removed level');
+ if(req.body.origin){
+ res.redirect(req.body.origin);
+ }else{
+ res.redirect('/');
+ }
+
+ });
+ }else{
+ req.flash('warn', 'You can not remove this level!');
+ res.redirect('/level/list');
+ }
+
+ });
+};
+
+app.get('/level/:level/delete', deleteLevel);
+app.del('/level/:level', login, deleteLevel);
+
+app.get('json/level/:from/:to', login, function(req, res){
var from = parseInt(req.params.from, 10),
to = parseInt(req.params.from, 10),
num = to-from;
@@ -174,7 +275,9 @@ app.get('json/levels', login, function(req, res){
* user management
*/
app.get('/profile', login, function(req, res){
- res.render('user/profile', {locals: {user: req.session.user}});
+ res.render('user/profile', {locals: {
+ title: title('profile')
+ }});
});
app.get('/login', all, function(req, res){
res.render('user/login', {locals: {
@@ -201,6 +304,15 @@ app.post('/login', all, function(req, res){
}
});
});
+app.get('/logout', login, function(req, res){
+ delete req.session.user;
+ req.session.regenerate(function(err){
+
+ //delete req.session.user;
+ //req.session.user =;
+ res.redirect('/');
+ });
+});
app.get('/register', all, function(req, res){
res.render('user/register', {locals: {
title: title('Register')
View
115 static/css/style.css
@@ -6,6 +6,21 @@ body{
padding: 0;
margin: 0;
}
+h1,h2,h3,h4,h5,h6{
+ color: #fe7b2b;
+ font-family: 'Leckerli One', Arial, Helvetica, Serif;
+ __text-shadow: #69aedb 1px 1px 0px;
+ font-weight: normal;
+}
+a{
+ color: #fe7b2b;
+ text-decoration: none;
+ text-shadow: #69aedb 1px 1px 0;
+}
+a:hover{
+ color: #fe7b2b;
+ text-shadow: none;
+}
#container, #head, .flash{
width: 928px;
margin: 0 auto;
@@ -18,38 +33,61 @@ body{
margin: 8px auto;
background: #fefecc;
}
-#container{
- margin-bottom: 148px;
- font-family: 'Delius', Arial, Helvetica, Serif;
-}
-a{
- color: #fe7b2b;
- text-decoration: none;
- text-shadow: #69aedb 1px 1px 0;
-}
-a:hover{
- color: #fe7b2b;
- text-shadow: none;
-}
#head{
background: url('/img/jomoho_profile_64.png') transparent no-repeat;
background-position: 4px 10px;
height: 64px;
text-indent: 64px;
+ position: relative;
+}
+#head #title{
text-decoration: none;
color: #fe7b2b;
text-shadow: #69aedb 2px 2px 0;
font-size: 32px;
font-family: 'Leckerli One', Arial, Helvetica, Serif;
}
+#user{
+ position: absolute;
+ top: 64px;
+ right: 16px;
+ font-size: 18px;
+ font-weight: bold;
+}
+#container{
+ margin-bottom: 148px;
+ font-family: 'Delius', Arial, Helvetica, Serif;
+}
#create-level{
font-size: 18;
font-weight: bold;
}
+#level-list{
+
+}
+#level-list li{
+ list-style: none;
+}
+#level-list li.head{
+ background: rgba(64,64,64, 0.3);
+ color: #646464;
+ font-weight: bold;
+ margin-bottom: 8px;
+}
+#level-list li .row{
+ width: 168px;
+ padding: 8px 16px;
+ display: inline-block;
+}
+#level-list li .row.last{
+ width: 96px;
+ display: inline-block;
+}
#canvas{
position:absolute;
}
#chat, #help{
+ font-family: arial, sans;
position: absolute;
z-index:2;
top: 0;
@@ -63,7 +101,7 @@ a:hover{
margin-top: 96px;
}
#chat-text{
- font-size: 10px;
+ font-size: 12px;
}
#chat-text.time, #chat-text.name{
@@ -84,12 +122,6 @@ a:hover{
font-size: 11px;
}
-#chat-button img{
- background-position: -160px 0;
-}
-#chat-button.hidden img{
- background-position: -192px 0;
-}
#menu{
position: absolute;
top: 16px;
@@ -169,6 +201,33 @@ a:hover{
-moz-border-radius: 16px;
-webkit-border-radius: 16px;
}
+#info-button img{
+ background-position: 0 0;
+}
+#sound-button img{
+ background-position: -32px 0;
+}
+#sound-button.mute img{
+ background-position: -64px 0;
+}
+#music-button img{
+ background-position: -96px 0;
+}
+#music-button.mute img{
+ background-position: -128px 0;
+}
+#chat-button img{
+ background-position: -160px 0;
+}
+#chat-button.hidden img{
+ background-position: -192px 0;
+}
+#edit-button img{
+ background-position: -224px 0;
+}
+#tools #drag img{
+ background-position: 0 -32px;
+}
#tools #pick img{
background-position: -32px -32px;
}
@@ -178,6 +237,22 @@ a:hover{
#tools #settings img{
background-position: -96px -32px;
}
+#help-button img{
+ background-position: -224px 0px;
+}
+#home-button img{
+ background-position: -128px -32px;
+}
+#play-button img{
+ background-position: -160px -32px;
+}
+#profile-button img{
+ background-position: -192px -32px;
+}
+#help-button img{
+ background-position: -224px -32px;
+}
+
#sidebar{
position: absolute;
right: 0;
View
BIN  static/img/back.jpg
Deleted file not rendered
View
BIN  static/img/icons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 static/js/Level.js
@@ -2,7 +2,19 @@
define(['jo/jo', 'jo/TileMap'],function(jo, TileMap){
var lvl = TileMap.extend({
- onNode: true
+ objects: [],
+ add: function(options){
+ if(!options){
+ throw new Error('options need to be defined!');
+ }
+ if(!options.name){
+
+ }
+ this.objects[options.name] = new jo.entities[options.type](options);
+ },
+ rename: function(name){
+ this.name = name;
+ }
});
return lvl;
});
View
35 static/js/chat.js
@@ -0,0 +1,35 @@
+define([],function(){
+ var Chat = function(){
+ this.history = [];
+ var self = this;
+
+ $('#chat-form').submit(function(e){
+ var msg = $('#chat-input').val();
+ if(msg !== ''){
+ self.post({time: '$time', username: '$id', text:msg });
+ }
+
+ $('#chat-input').val('');
+ e.preventDefault();
+ return false;
+ });
+ };
+ Chat.prototype.post = function(msg){
+ console.log(msg);
+ this.history.push(msg);
+
+ if(this.history.length>15){
+ this.history.shift();
+ }
+ $('#chat-text').html(this.render());
+ };
+ Chat.prototype.render = function(){
+ var r = '';
+ for(var i in this.history){
+ var time= new Date(this.history[i].time);
+ r+= '<p><span class="time">['+time.toLocaleTimeString()+'] </span><b class="name">'+this.history[i].username+': </b>'+this.history[i].text+'</p>';
+ }
+ return r;
+ };
+ return Chat;
+});
View
17 static/js/editor.js
@@ -1,5 +1,5 @@
-require(['jo/jo', 'jo/Game','jo/Camera', 'jo/Animation', 'Level', 'ioclient', 'sidebar','game/main'],
- function(jo, Game, Camera, Animation, Level, ioclient, sidebar, game){
+require(['jo/jo', 'jo/Game','jo/Camera', 'jo/Animation', 'Level', 'ioclient', 'sidebar', 'chat','game/main'],
+ function(jo, Game, Camera, Animation, Level, ioclient, sidebar, Chat, game){
//one global variable to rule them all very useful with the browser console
$jo=jo;
@@ -12,7 +12,7 @@ require(['jo/jo', 'jo/Game','jo/Camera', 'jo/Animation', 'Level', 'ioclient', 's
'img/tileset.png'], '/');
editor.cam = new jo.Camera(0,0);
-
+ editor.chat = new Chat();
editor.sb = sidebar;
});
@@ -34,9 +34,14 @@ require(['jo/jo', 'jo/Game','jo/Camera', 'jo/Animation', 'Level', 'ioclient', 's
}
editor.map.tileSet = editor.ts;
- ioclient.sync('resize', editor.map);
- ioclient.sync('put', editor.map);
- ioclient.sync('shift', editor.map);
+ ioclient.sync('resize', editor.map, 'grid');
+ ioclient.sync('put', editor.map, 'grid');
+ ioclient.sync('shift', editor.map, 'grid');
+ ioclient.sync('rename', editor.map, 'grid');
+
+ ioclient.sync('post', editor.chat, 'chat', true);
+
+
$('#loading').hide();
}
});
View
180 static/js/game/main.js
@@ -31,19 +31,9 @@ define(['../jo/jo',
game.ts.solid = [0,1,2,3];
game.ts.start = 5;
game.ts.exit = 4;
- game.addObject('player', new Actor({name: 'player', position: new jo.Point(100, 64)}));
- game.records = [];
-
-
- var s = game.map.find(game.ts.start);
- var pl = game.getObject('player');
-
- if(s){
- pl.moveTo(s.pos.plus(jo.point(16,0)));
- }else{
- pl.moveTo( new jo.Point(100, 64));
- }
+ game.addObject('player', new Actor({name: 'player', position: new jo.Point(100, 64)}));
+ game.initLevel();
game.device= new jo.Animation([1,1,1], 80,42, jo.files.img.device);
});
@@ -58,13 +48,14 @@ define(['../jo/jo',
}
var p = game.cam.toWorld();
game.map.draw({cam: game.cam, x: p.x, y: p.y, width: jo.screen.width, height:jo.screen.height, grid: false}, new jo.Point(0,0), jo.screen);
-// if(game.level.device ){
-// var fr = 0;
-// if(recording){
-// fr = 2;
-// }
-// game.device.draw({frame: fr}, new jo.Point(32, 32), jo.screen);
-// }
+
+ if(game.device ){
+ var fr = 0;
+ if(recording){
+ fr = 2;
+ }
+ //game.device.draw({frame: fr}, new jo.Point(32, 32), jo.screen);
+ }
if(jo.dev){
caption('Play Mode | FPS: '+parseInt(jo.screen.realFps)+' @ width:'+jo.screen.width+' height:'+jo.screen.height);
@@ -75,8 +66,9 @@ define(['../jo/jo',
game.centerCam(game.getObject('player').pos.clone());
};
game.centerCam = function(p){
- var half = new jo.Point(jo.screen.width / 2, jo.screen.height*0.5);
+ var half = new jo.Point(jo.screen.width *0.5, jo.screen.height*0.5);
game.cam.copy(p.minus(half));
+
var mf = this.map.getFrame();
game.cam.copy(new jo.Point(
@@ -84,106 +76,32 @@ define(['../jo/jo',
Math.min(mf.height - jo.screen.height, Math.max(-64, game.cam.y))
));
};
- game.drawEdit= function(){
- game.map.tileSet.draw({tile: pal}, new jo.Point(jo.screen.width-96, 32), jo.screen);
- };
-
- game.loadLevel = function(level, init){
- var lvl = JSON.parse(level.json, jo.Object.revive);
- game.map = new Map(game.ts, lvl.width, lvl.height, lvl.data);
-
- game.objects = lvl.objects;
-
- game.level = level;
- game.level.lvl = lvl;
- if(init){
- game.initLevel();
- }
-
+ game.initLevel= function(){
+ game.records = [];
+ game.resetRecording();
var s = game.map.find(game.ts.start);
- var pl =game.getObject('player');
+ var pl = game.getObject('player');
+
if(typeof s !== 'undefined'){
pl.moveTo(s.pos.plus(jo.point(16,0)));
}else{
pl.moveTo( new jo.Point(100, 64));
}
- return game.level;
- };
- game.initLevel= function(){
- game.records = [];
- game.enemies = [];
- game.switches = [];
- for(var i in game.objects){
- if(game.level.lvl.objects[i].type === 'record'){
- game.records.push(i);
- }else if(game.level.lvl.objects[i].type === 'enemy'){
- game.enemies.push(i);
- }else if(game.level.lvl.objects[i].type === 'switch'){
- game.switches.push(i);
- }
- }
- game.records = [];
- game.resetRecording();
- };
- game.saveLevel = function(){
- var lvl = {};
- lvl.width = game.map.width;
- lvl.height = game.map.height;
- //
- lvl.data = game.map.data;
- lvl.objects = {};
-
- for(var i in game.objects){
- if( !i.match(/record/)){
- lvl.objects[i] = game.objects[i];
- }
- }
- lvl.json = JSON.stringify(lvl);
- game.records = [];
- game.resetRecording();
- game.loadLevel(lvl);
- return lvl;
-
- };
- game.stopLevel= function(){
- game.loadLevel(game.level, false);
- game.enemies = [];
- game.switches = [];
-
- for(var i in game.records){
- game.addObject('record'+i, new Clone({name: 'record'+i, position: game.records[i][0].pos.clone()}));
- }
- for(var i in game.objects){
- if(game.level.lvl.objects[i].type === 'enemy'){
- game.enemies.push(i);
- }else if(game.level.lvl.objects[i].type === 'switch'){
- game.switches.push(i);
- }
- }
- };
- game.restartLevel = function(){
- game.records = [];
- game.loadLevel(game.level);
- };
- game.restart = function(){
- game.records= [];
- game.loadLevel(levels['start'], true);
};
game.levelDone = function(){
- game.loadLevel(levels[game.level.next], true);
- jo.cookies.setCookie('LD20Balooga03',game.level.next, 60);
- //jo.files.sfx.woo.play();
+ //game.initLevel();
+ alert('Level Done');
};
var recording = false;
var current_rec = 0;
var rec_frame = 0;
+
game.deleteRecords= function(){
- game.records=[];
- game.resetRecording();
-
+ game.records = [];
+ game.resetRecording();
};
game.resetRecording =function(){
recording = false;
@@ -191,37 +109,33 @@ define(['../jo/jo',
rec_frame = 0;
};
game.stopRecording= function(){
- recording=false;
- game.getObject('record'+current_rec).rec=false;
- current_rec+=1;
- game.stopLevel();
- rec_frame=0;
- game.getObject('player').rec=false;
+ recording = false;
+ game.getObject('record'+current_rec).rec = false;
+ current_rec += 1;
+ rec_frame = 0;
+ game.getObject('player').rec = false;
};
game.startRecording= function(){
recording = true;
- game.records[current_rec]= [];
- game.addObject('record'+current_rec, new Clone({name: 'record'+current_rec, position: game.getObject('player').pos.clone()}));
- game.getObject('record'+current_rec).rec=true;
+ game.records[current_rec] = [];
+
+ game.addObject('record' + current_rec, new Clone({
+ name: 'record'+current_rec,
+ position: game.getObject('player').pos.clone()
+ }));
+
+ game.getObject('record' + current_rec).rec = true;
game.getObject('player').rec=true;
};
game.OnUpdate(function(ticks){
- game.map.update(ticks);
- if(jo.input.once('E')){
- jo.edit= !jo.edit;
- game.level.device=true;
- }
- if(jo.edit && jo.dev){
- this.editControls();
- this.controls();
- }else{
- this.controls();
- }
+ game.player = game.getObject('player');
+ game.map.update(ticks);
+ this.controls();
this.handleCollision();
if(recording){
- var p= game.getObject('player');
+ var p = game.player;
game.records[current_rec].push({pos: p.pos.clone(), fr: p.fr});
}
if(recording || current_rec>0){
@@ -236,7 +150,9 @@ define(['../jo/jo',
});
game.controls = function(){
- game.player = game.getObject('player');
+ if(jo.input.once('E')){
+ game.device = true;
+ }
if(jo.input.once('SPACE')){
this.player.jump();
$('#popup').hide();
@@ -252,11 +168,10 @@ define(['../jo/jo',
}else{
this.player.stand();
}
- if(!recording && jo.input.once('SHIFT') && game.level.device){
-
+ if(!recording && jo.input.once('SHIFT') && game.device){
//jo.files.sfx.rrm.play();
game.startRecording();
- }else if(recording && !jo.input.k('SHIFT') && game.level.device){
+ }else if(recording && !jo.input.k('SHIFT') && game.device){
//jo.files.sfx.clkclk.play();
game.stopRecording();
}
@@ -313,12 +228,7 @@ define(['../jo/jo',
actor.pos.x = Math.min(mf.width-actor.width,Math.max(0,actor.pos.x));
actor.pos.y = Math.min(mf.height,Math.max(0,actor.pos.y));
if(actor.pos.y > mf.height-actor.height){
- if(recording){
- game.stopLevel();
- }else{
- game.stopLevel();
- }
-
+ game.initLevel();
}
var tiles = game.tiles = map.getIntersection({x:actor.pos.x, y: actor.pos.y, width: actor.width, height: actor.height});
View
52 static/js/ioclient.js
@@ -6,15 +6,15 @@ define(['jo/jo', 'jo/Point', 'jo/Surface', './Level'], function(jo, Point, Surfa
functions = {},
pending = {count:0};
- function map(obj){
+ function toArray(obj){
var args = [];
for(var i in obj){
args[i] = obj[i];
}
return args;
};
- function makeIdent(name, prefix, args){
- return prefix+name+'('+JSON.stringify(args)+')';
+ function makeIdent(name, context, args){
+ return context+name+'('+JSON.stringify(args)+')';
};
exports.init = function(fn){
@@ -27,22 +27,17 @@ define(['jo/jo', 'jo/Point', 'jo/Surface', './Level'], function(jo, Point, Surfa
socket.emit('handshake', {rediskey: $appdata.rediskey, levelId: levelId}, fn);
socket.on(channel, function(msg){
- var name = msg.name;
- if(msg.prefix){
- name= msg.prefix+msg.name;
- }
- if(msg.type === 'function'&& msg.name&& functions[name]){
- var args = map(msg.args);
- //console.log(msg);
- functions[msg.name].apply(functions[msg.name].self, args);
-
- var ident = makeIdent(msg.name, msg.prefix, args);
+ var name = msg.context+':'+msg.name;
+
+ if(msg.type === 'function' && msg.name && functions[name]){
+ var args = toArray(msg.args);
+ console.log(msg);
+ functions[name].apply(functions[name].self, args);
- if(pending[ident]){
+ if(pending[msg.ident]){
pending.count-=1;
- //console.log('unpending: '+ident);
- pending[ident]=false;
- delete pending[ident];
+ pending[msg.ident] = false;
+ delete pending[msg.ident];
}
if(pending.count==0){
$('#saved').show();
@@ -54,25 +49,24 @@ define(['jo/jo', 'jo/Point', 'jo/Surface', './Level'], function(jo, Point, Surfa
});
};
- exports.sync = function(name, obj, prefix){
- prefix = prefix || '';
+ exports.sync = function(name, obj, context, wait){
+ context = context || '';
var fn = obj[name];
fn.self = obj;
- fn.prefix = prefix;
+ fn.context = context;
+ fn.wait = wait;
- functions[prefix+name] = fn;
+ functions[context+':'+name] = fn;
- obj[name]= function(){
-
-
- var ident = makeIdent(name, prefix, map(arguments));
-
+ obj[name]= function(){
+ var ident = makeIdent(name, context, arguments);
if(! pending[ident]){
- fn.apply(fn.self, arguments);
- //console.log('pending: '+ident);
+ if(!wait){
+ fn.apply(fn.self, arguments);
+ }
pending[ident] = true;
- socket.emit(channel, {type: 'function', name: name, prefix: prefix, args: arguments});
+ socket.emit(channel, {type: 'function', name: name, context: context, args: arguments, ident: ident});
pending.count+=1;
$('#saved').hide();
$('#loading').show();
View
17 static/js/util.js → static/js/menus.js
@@ -2,7 +2,8 @@ $(document).ready(function(){
settings = $('#tools #settings'),
chatbutton = $('#chat-button'),
helpbutton = $('#help-button'),
- playbutton = $('#play-button'),
+ playbutton = $('#play-button'),
+ editbutton = $('#edit-button'),
buttons = $('.button');
buttons.each(function(vent, obj){
@@ -17,6 +18,9 @@ $(document).ready(function(){
o.append('<img src="/img/empty.png" width="32" height="32" alt="'+$(obj).attr('id')+'"/>').append(p);
p = o.find('span');
p.css({left: 8-(p.width()/2)});
+ if(txt =='edit'){
+ editbutton.hide();
+ }
});
chatbutton.click(function(){
@@ -43,10 +47,19 @@ $(document).ready(function(){
$jo.game.runSetup();
$jo.state = 'play';
console.log('go play');
- }else if($jo.state === 'play'){
+ playbutton.hide();
+ editbutton.show();
+ $('#sidebar').fadeOut();
+ }
+ });
+ editbutton.click(function(){
+ if($jo.state === 'play'){
$jo.editor.run();
$jo.state = 'edit';
console.log('go edit');
+ editbutton.hide();
+ playbutton.show();
+ $('#sidebar').fadeIn();
}
});
View
13 static/js/page.js
@@ -0,0 +1,13 @@
+$(document).ready(function(){
+
+ $('form.confirm').submit(function(event){
+ if(confirm('Are you sure?')){
+ return true;
+ }
+ else{
+ event.preventDefault();
+ }
+ });
+
+
+});
View
16 static/js/sidebar.js
@@ -21,8 +21,7 @@ define(['jo/jo'], function(jo){
$('.tool-prop').each(function(ev, obj){
$(obj).hide();
});
- $('#'+$jo.tool+'-prop').show();
-
+ $('#'+$jo.tool+'-prop').show();
});
});
@@ -35,8 +34,8 @@ define(['jo/jo'], function(jo){
});
//entity select
var eselect = $('#add-entity select');
- for(var i in jo.editor.entitylist){
- eselect.append($('<option>').html(jo.editor.entitylist[i]));
+ for(var i in jo.entities){
+ eselect.append($('<option>').html(jo.entities[i].name));
}
//tiles
@@ -78,13 +77,16 @@ define(['jo/jo'], function(jo){
},
actions:{
addEntitySubmit: function(form){
- var ent =form.find('select').val();
+ var ent = form.find('select').val();
alert(ent);
},
mapSettingsSubmit: function(form){
- var w = $('#width').val(), h = $('#height').val();
+ var w = $('#width').val(),
+ h = $('#height').val(),
+ name = $('#name').val();
w = parseInt(w, 10), h = parseInt(h, 10);
- $jo.editor.map.resize(w,h, {index: -1});
+ $jo.editor.map.resize(w,h, {index: -1});
+ $jo.editor.map.rename(name);
}
},
tools:{
View
2  users.js
@@ -64,7 +64,7 @@ UserSchema.virtual('password').set(function(password) {
});
mongoose.model('User', UserSchema);
-User = mongoose.model('User');
+module.exports.User = User = mongoose.model('User');
PendingSchema = new Schema({
'hash': {type: String, 'default': encrypt(makeSalt(), 'well this is fun'), index: {unique: true}},
View
8 views/dashboard.jade
@@ -0,0 +1,8 @@
+h2 Hi #{user.name}
+p
+ a(href='/level/list') all Levels
+p
+ a#create-level(href='/level/create') Create new Level
+
+h2 Your levels:
+ul#level-list!=partial('levellist')
View
13 views/edit/chat.jade
@@ -1,9 +1,4 @@
- <div id="chat" style="display:none;">
- <div id="chat-text">
-
- </div>
- <form action="chat" id="chat-form">
- <input id="chat-input"/>
- <input type="submit" value="send"/>
- </form>
- </div>
+#chat-text
+form#chat-form(action='chat')
+ input#chat-input
+ input(type='submit', value='send')
View
1  views/edit/index.jade
@@ -5,6 +5,7 @@ ul#menu!=partial('menu')
#saved(style='display:none;') saved
ul#sidebar!= partial('sidebar')
#help(style='display:none;')!=partial('help');
+#chat(style='display:none;')!=partial('chat');
canvas#canvas
p unfortunately your browser lacks canvas support! get
View
3  views/edit/menu.jade
@@ -2,4 +2,5 @@ li#home-button(class='button link', name='home')
a(href='/')
li#chat-button(class='button hidden', name='chat')
li#help-button(class='button hidden', name='help')
-li#play-button(class='button hidden', name='play')
+li#play-button(class='button', name='play')
+li#edit-button(class='button', name='edit')
View
2  views/editor-layout.jade
@@ -14,5 +14,5 @@ html
script(type='text/javascript', src= '/js/jquery.js')
// script(type='text/javascript', src= '/js/plugins/jquery.form.js')
script(type='text/javascript', src= '/js/plugins/jquery.cookie.js')
- script(type='text/javascript', src= '/js/util.js')
+ script(type='text/javascript', src= '/js/menus.js')
script!=googleAnalytics
View
8 views/front.jade
@@ -4,12 +4,6 @@ p
p
a.menu(href='/login') Login
p
- a.menu(href='/levels') Start
-p
a.menu(href='/register') Register
p
- // a.menu(href='/feedback') Give Feedback
-p
- // a.menu(href='/credits') Credits
-p
- hr
+ hr
View
2  views/game-layout.jade
@@ -14,5 +14,5 @@ html
script(type='text/javascript', src= '/js/jquery.js')
// script(type='text/javascript', src= '/js/plugins/jquery.form.js')
script(type='text/javascript', src= '/js/plugins/jquery.cookie.js')
- script(type='text/javascript', src= '/js/util.js')
+ script(type='text/javascript', src= '/js/menus.js')
script!=googleAnalytics
View
21 views/layout.jade
@@ -7,12 +7,23 @@ html
link(href='http://fonts.googleapis.com/css?family=Leckerli+One&v2', rel='stylesheet', type='text/css')
link(href='http://fonts.googleapis.com/css?family=Delius', rel='stylesheet', type='text/css')
body
- a(href='/')#head!=title
+ #head
+ a#title(href='/')!=title
+ -if(user)
+ p#user
+ a(href='/profile') profile
+ a(href='/logout') logout
- if(flash.warn)
#warn.flash= flash.warn
+ - if(flash.info)
+ #info.flash= flash.info
+ - if(flash.error)
+ #error.flash= flash.error
+
+
#container!=body
- //- script(type='text/javascript', src= 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')
- script(type='text/javascript', src= 'js/jquery.js')
- script(type='text/javascript', src= 'js/plugins/jquery.form.js')
- script(type='text/javascript', src= 'js/util.js')
+ //- script(type='text/javascript', src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')
+ script(type='text/javascript', src='/js/jquery.js')
+ script(type='text/javascript', src='/js/plugins/jquery.form.js')
+ script(type='text/javascript', src='/js/page.js')
script!=googleAnalytics
View
20 views/levellist.jade
@@ -0,0 +1,20 @@
+li.head
+ .row name
+ .row last update
+ .row creator
+ .row created
+ .row.last action
+- for(lvl in levels)
+ li
+ a.row(href='/level/'+levels[lvl]._id+'/edit')=levels[lvl].name
+ .row.date=levels[lvl].prettyupdate
+ .row.creator=levels[lvl].creatorName
+ .row.date=levels[lvl].prettydate
+ .row.last.tools
+ -if(levels[lvl].owner)
+ form.confirm(action='/level/'+levels[lvl]._id, method='POST')
+ input(type='hidden', name='_method', value='DELETE')
+ input(type='hidden', name='origin', value=origin)
+ input(type='submit', value='remove')
+ form.confirm(action='/level/'+levels[lvl]._id+'/copy', method='get')
+ input(type='submit', value='clone')
View
8 views/list.jade
@@ -1,5 +1,5 @@
p
- a#create-level(href='/create') Create new Level
-- for(lvl in levels)
- p
- a(href='edit/'+levels[lvl]._id)=levels[lvl].name
+ a#create-level(href='/level/create') Create new Level
+ul#level-list!=partial('levellist');
+
+
View
26 views/user/profile.jade
@@ -1,15 +1,25 @@
-form(action='/profile', method='POST')
+p Name: #{user.name}
+p Email: #{user.email}
+
+
+h3 change name
+form#change-name.check-form(action='/user', method='POST')
+ input(type='hidden', name='_method', value='PUT')
p
- label(for='name') Name:
+ input#password(type='text', name'user[name]', value = user.name)
p
- input#name(type='text', name='user[name]', value = user.name)
+ input(type='submit', value='ok')
+
+h3 change password
+form#change-password.check-form(action='/user', method='POST')
+ input(type='hidden', name='_method', value='PUT')
p
- label(for='email') Email:
+ label(for='password') password:
p
- input#email(type='text', name='user[email]', value= user.email)
+ input#password(type='password', name'user[password]')
p
- label(for='password') Password:
+ label(for='repeatpassword') repeat password:
p
- input#password(type='password', name='user[password]')
+ input#repeatpassword(type='password', name'user[repassword]')
p
- input#login(type='submit', value='Submit')
+ input(type='submit', value='ok')
Please sign in to comment.
Something went wrong with that request. Please try again.