Browse Source

load save box

tags/v0.2.0^2
Big Bad Waffle 6 years ago
parent
commit
7efa9a5036
11 changed files with 61 additions and 1347 deletions
  1. +1
    -1
      .gitignore
  2. +4
    -2
      helpers/passives/client/js/client.js
  3. +8
    -18
      helpers/passives/client/js/generator.js
  4. +2
    -4
      helpers/passives/client/js/main.js
  5. +1
    -2
      helpers/passives/client/js/tplNode.js
  6. +33
    -0
      helpers/passives/client/ui/templates/loadSave/loadSave.js
  7. +10
    -0
      helpers/passives/client/ui/templates/loadSave/template.html
  8. +0
    -13
      helpers/passives/client/ui/templates/nodeInfo/nodeInfo.js
  9. +0
    -8
      helpers/passives/client/ui/templates/nodeInfo/template.html
  10. +2
    -2
      helpers/passives/server/index.js
  11. +0
    -1297
      helpers/passives/server/save.json

+ 1
- 1
.gitignore View File

@@ -4,4 +4,4 @@ storage.db
*.sublime-workspace
*.css
!helpers/item-tooltip/styles.css
!helpers/passives/styles.css
!helpers/passives/*.css

+ 4
- 2
helpers/passives/client/js/client.js View File

@@ -15,14 +15,16 @@ define([
this.socket.on('connect', this.onConnected.bind(this, onReady));
},

load: function (callback) {
load: function (fileName, callback) {
this.socket.emit('request', {
fileName: fileName,
action: 'load'
}, callback);
},

save: function (data, callback) {
save: function (fileName, data, callback) {
this.socket.emit('request', {
fileName: fileName,
action: 'save',
data: data
}, callback);


+ 8
- 18
helpers/passives/client/js/generator.js View File

@@ -15,11 +15,6 @@ define([

init: function () {
events.on('onAreaSelect', this.events.onAreaSelect.bind(this));

/*this.actions.addNode.call(this, {
x: 100,
y: 100
});*/
},

findNode: function (x, y) {
@@ -51,11 +46,15 @@ define([
return selected;
},

serialize: function () {
return JSON.stringify({
nodes: this.nodes,
links: this.links
});
},

actions: {
load: function () {
client.load(this.actions.onLoad.bind(this));
},
onLoad: function (data) {
load: function (data) {
this.nodes = data.nodes;
this.links = data.links.map(function (l) {
l.from = this.nodes.find(n => (n.id == l.from.id));
@@ -65,15 +64,6 @@ define([
}, this);
},

save: function () {
var res = JSON.stringify({
nodes: this.nodes,
links: this.links
});

client.save(res);
},

selectNode: function (options) {
if (
(


+ 2
- 4
helpers/passives/client/js/main.js View File

@@ -37,7 +37,7 @@ define([
events.on('onMouseWheel', this.events.onMouseWheel.bind(this));
events.on('onKeyDown', this.events.onKeyDown.bind(this));

uiFactory.build('nodeInfo');
uiFactory.build('loadSave');

renderer.center(generator.nodes[0]);
this.render();
@@ -102,9 +102,7 @@ define([

onKeyDown: function (key) {
var action = ({
d: 'deleteNode',
l: 'load',
s: 'save'
d: 'deleteNode'
})[key];
if (!action)
return;


+ 1
- 2
helpers/passives/client/js/tplNode.js View File

@@ -4,7 +4,6 @@ define([

) {
return {
id: 0,
color: 0,
size: 0,
pos: {
@@ -14,7 +13,7 @@ define([

build: function (options) {
var res = $.extend(true, {}, this, {
id: this.id++,
id: options.id,
pos: {
x: options.x,
y: options.y


+ 33
- 0
helpers/passives/client/ui/templates/loadSave/loadSave.js View File

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

+ 10
- 0
helpers/passives/client/ui/templates/loadSave/template.html View File

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

+ 0
- 13
helpers/passives/client/ui/templates/nodeInfo/nodeInfo.js View File

@@ -1,13 +0,0 @@
define([
'html!./template'
], function (
template
) {
return {
tpl: template,

postRender: function () {

}
}
});

+ 0
- 8
helpers/passives/client/ui/templates/nodeInfo/template.html View File

@@ -1,8 +0,0 @@
<div class="uiInventory">
<div class="heading">
<div class="heading-text">Node Info</div>
</div>
<div class="content">
</div>
</div>

+ 2
- 2
helpers/passives/server/index.js View File

@@ -32,10 +32,10 @@ var mod = {

onRequest: function (socket, msg, callback) {
if (msg.action == 'load') {
var res = JSON.parse(fs.readFileSync('save.json'));
var res = JSON.parse(fs.readFileSync(msg.fileName + '.json'));
callback(res);
} else if (msg.action == 'save')
fs.writeFileSync('save.json', msg.data);
fs.writeFileSync(msg.fileName + '.json', msg.data);

if (callback)
callback();


+ 0
- 1297
helpers/passives/server/save.json
File diff suppressed because it is too large
View File


Loading…
Cancel
Save