@@ -4,4 +4,4 @@ storage.db | |||||
*.sublime-workspace | *.sublime-workspace | ||||
*.css | *.css | ||||
!helpers/item-tooltip/styles.css | !helpers/item-tooltip/styles.css | ||||
!helpers/passives/styles.css | |||||
!helpers/passives/*.css |
@@ -15,14 +15,16 @@ define([ | |||||
this.socket.on('connect', this.onConnected.bind(this, onReady)); | this.socket.on('connect', this.onConnected.bind(this, onReady)); | ||||
}, | }, | ||||
load: function (callback) { | |||||
load: function (fileName, callback) { | |||||
this.socket.emit('request', { | this.socket.emit('request', { | ||||
fileName: fileName, | |||||
action: 'load' | action: 'load' | ||||
}, callback); | }, callback); | ||||
}, | }, | ||||
save: function (data, callback) { | |||||
save: function (fileName, data, callback) { | |||||
this.socket.emit('request', { | this.socket.emit('request', { | ||||
fileName: fileName, | |||||
action: 'save', | action: 'save', | ||||
data: data | data: data | ||||
}, callback); | }, callback); | ||||
@@ -15,11 +15,6 @@ define([ | |||||
init: function () { | init: function () { | ||||
events.on('onAreaSelect', this.events.onAreaSelect.bind(this)); | events.on('onAreaSelect', this.events.onAreaSelect.bind(this)); | ||||
/*this.actions.addNode.call(this, { | |||||
x: 100, | |||||
y: 100 | |||||
});*/ | |||||
}, | }, | ||||
findNode: function (x, y) { | findNode: function (x, y) { | ||||
@@ -51,11 +46,15 @@ define([ | |||||
return selected; | return selected; | ||||
}, | }, | ||||
serialize: function () { | |||||
return JSON.stringify({ | |||||
nodes: this.nodes, | |||||
links: this.links | |||||
}); | |||||
}, | |||||
actions: { | actions: { | ||||
load: function () { | |||||
client.load(this.actions.onLoad.bind(this)); | |||||
}, | |||||
onLoad: function (data) { | |||||
load: function (data) { | |||||
this.nodes = data.nodes; | this.nodes = data.nodes; | ||||
this.links = data.links.map(function (l) { | this.links = data.links.map(function (l) { | ||||
l.from = this.nodes.find(n => (n.id == l.from.id)); | l.from = this.nodes.find(n => (n.id == l.from.id)); | ||||
@@ -65,15 +64,6 @@ define([ | |||||
}, this); | }, this); | ||||
}, | }, | ||||
save: function () { | |||||
var res = JSON.stringify({ | |||||
nodes: this.nodes, | |||||
links: this.links | |||||
}); | |||||
client.save(res); | |||||
}, | |||||
selectNode: function (options) { | selectNode: function (options) { | ||||
if ( | if ( | ||||
( | ( | ||||
@@ -37,7 +37,7 @@ define([ | |||||
events.on('onMouseWheel', this.events.onMouseWheel.bind(this)); | events.on('onMouseWheel', this.events.onMouseWheel.bind(this)); | ||||
events.on('onKeyDown', this.events.onKeyDown.bind(this)); | events.on('onKeyDown', this.events.onKeyDown.bind(this)); | ||||
uiFactory.build('nodeInfo'); | |||||
uiFactory.build('loadSave'); | |||||
renderer.center(generator.nodes[0]); | renderer.center(generator.nodes[0]); | ||||
this.render(); | this.render(); | ||||
@@ -102,9 +102,7 @@ define([ | |||||
onKeyDown: function (key) { | onKeyDown: function (key) { | ||||
var action = ({ | var action = ({ | ||||
d: 'deleteNode', | |||||
l: 'load', | |||||
s: 'save' | |||||
d: 'deleteNode' | |||||
})[key]; | })[key]; | ||||
if (!action) | if (!action) | ||||
return; | return; | ||||
@@ -4,7 +4,6 @@ define([ | |||||
) { | ) { | ||||
return { | return { | ||||
id: 0, | |||||
color: 0, | color: 0, | ||||
size: 0, | size: 0, | ||||
pos: { | pos: { | ||||
@@ -14,7 +13,7 @@ define([ | |||||
build: function (options) { | build: function (options) { | ||||
var res = $.extend(true, {}, this, { | var res = $.extend(true, {}, this, { | ||||
id: this.id++, | |||||
id: options.id, | |||||
pos: { | pos: { | ||||
x: options.x, | x: options.x, | ||||
y: options.y | y: options.y | ||||
@@ -0,0 +1,33 @@ | |||||
define([ | |||||
'html!./template', | |||||
'css!./styles', | |||||
'js/generator', | |||||
'js/client' | |||||
], function ( | |||||
template, | |||||
styles, | |||||
generator, | |||||
client | |||||
) { | |||||
return { | |||||
tpl: template, | |||||
postRender: function () { | |||||
this.on('.btnLoad', 'click', this.events.onLoad.bind(this)); | |||||
this.on('.btnSave', 'click', this.events.onSave.bind(this)); | |||||
}, | |||||
events: { | |||||
onLoad: function () { | |||||
var fileName = this.val('.fileName'); | |||||
client.load(fileName, generator.actions.load.bind(generator)); | |||||
}, | |||||
onSave: function () { | |||||
var fileName = this.val('.fileName'); | |||||
var data = generator.serialize(); | |||||
client.save(fileName, data, generator.actions.load.bind(generator)); | |||||
} | |||||
} | |||||
} | |||||
}); |
@@ -0,0 +1,10 @@ | |||||
<div class="uiLoadSave"> | |||||
<div class="heading"> | |||||
<div class="heading-text">Load/Save</div> | |||||
</div> | |||||
<div class="content"> | |||||
<input type="text" class="fileName"> | |||||
<div class="btn btnLoad">Load</div> | |||||
<div class="btn btnSave">Save</div> | |||||
</div> | |||||
</div> |
@@ -1,13 +0,0 @@ | |||||
define([ | |||||
'html!./template' | |||||
], function ( | |||||
template | |||||
) { | |||||
return { | |||||
tpl: template, | |||||
postRender: function () { | |||||
} | |||||
} | |||||
}); |
@@ -1,8 +0,0 @@ | |||||
<div class="uiInventory"> | |||||
<div class="heading"> | |||||
<div class="heading-text">Node Info</div> | |||||
</div> | |||||
<div class="content"> | |||||
</div> | |||||
</div> |
@@ -32,10 +32,10 @@ var mod = { | |||||
onRequest: function (socket, msg, callback) { | onRequest: function (socket, msg, callback) { | ||||
if (msg.action == 'load') { | if (msg.action == 'load') { | ||||
var res = JSON.parse(fs.readFileSync('save.json')); | |||||
var res = JSON.parse(fs.readFileSync(msg.fileName + '.json')); | |||||
callback(res); | callback(res); | ||||
} else if (msg.action == 'save') | } else if (msg.action == 'save') | ||||
fs.writeFileSync('save.json', msg.data); | |||||
fs.writeFileSync(msg.fileName + '.json', msg.data); | |||||
if (callback) | if (callback) | ||||
callback(); | callback(); | ||||