Browse Source

fixes #720 and fixed a bug in the new clone method

tags/v0.2.1^2
big bad waffle 5 years ago
parent
commit
098031b9d5
14 changed files with 1708 additions and 4367 deletions
  1. +8
    -1
      helpers/passives/client/js/client.js
  2. +52
    -29
      helpers/passives/client/js/generator.js
  3. +10
    -3
      helpers/passives/client/ui/templates/menu/menu.js
  4. +1
    -1
      helpers/passives/client/ui/templates/menu/styles.css
  5. +1
    -1
      helpers/passives/client/ui/templates/menu/styles.less
  6. +1
    -0
      helpers/passives/client/ui/templates/menu/template.html
  7. +14
    -13
      helpers/passives/server/index.js
  8. +9
    -0
      helpers/passives/server/persist.js
  9. +1
    -1
      helpers/passives/server/saves/tree.json
  10. +10
    -1
      src/client/ui/templates/passives/passives.js
  11. +1
    -2220
      src/client/ui/templates/passives/temp.js
  12. +3
    -3
      src/server/components/passives.js
  13. +1596
    -2093
      src/server/config/passiveTree.js
  14. +1
    -1
      src/server/misc/clone.js

+ 8
- 1
helpers/passives/client/js/client.js View File

@@ -7,7 +7,7 @@ define([
socket: null,

init: function (onReady) {
var tType = 'websocket';
let tType = 'websocket';
this.socket = io({
transports: [tType]
});
@@ -30,6 +30,13 @@ define([
}, callback);
},

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

getFileList: function (callback) {
this.socket.emit('request', {
action: 'getFileList'


+ 52
- 29
helpers/passives/client/js/generator.js View File

@@ -21,10 +21,10 @@ define([
},

findNode: function (x, y) {
var res = this.nodes.find(n => ((n.pos.x == x) && (n.pos.y == y)));
let res = this.nodes.find(n => ((n.pos.x == x) && (n.pos.y == y)));
if (!res) {
res = this.nodes.find(function (n) {
return ((n.size > 0) && (Math.abs(n.pos.x - x) <= 1) && (Math.abs(n.pos.y - y) <= 1))
return ((n.size > 0) && (Math.abs(n.pos.x - x) <= 1) && (Math.abs(n.pos.y - y) <= 1));
});
}

@@ -32,21 +32,20 @@ define([
},

callAction: function (action, options = {}) {
var node = options.node || this.findNode(options.x, options.y);
let node = options.node || this.findNode(options.x, options.y);

options.node = node;
return !this.actions[action].call(this, options);
},

getSelected: function (single) {
var selected = this.nodes.filter(n => n.selected);
let selected = this.nodes.filter(n => n.selected);
if ((single) && (selected.length != 1))
return null;

if (single)
return selected[0];
else
return selected;
return selected;
},

serialize: function () {
@@ -65,6 +64,30 @@ define([
});
},

getData: function () {
return {
nodes: this.nodes.map(function (n) {
let res = {
id: n.id,
pos: n.pos
};

['size', 'color', 'stats', 'spiritStart'].forEach(function (s) {
if (n[s] !== undefined)
res[s] = n[s];
});

return res;
}),
links: this.links.map(function (l) {
return {
from: l.from.id,
to: l.to.id
};
})
};
},

getNextId: function () {
for (var i = 0; i < this.nodes.length; i++) {
if (!this.nodes.some(n => (n.id == i)))
@@ -143,13 +166,13 @@ define([
},

connectNode: function (options) {
var node = options.node;
let node = options.node;
if (!node) {
this.callAction('selectNode');
return true;
}

var singleSelected = this.getSelected(true);
let singleSelected = this.getSelected(true);

if ((singleSelected) && (input.isKeyDown('ctrl'))) {
if (options.shiftDown) {
@@ -180,12 +203,12 @@ define([
} else {
return this.callAction('selectNode', {
node: node
})
});
}
},

moveNode: function (options) {
var selected = this.getSelected();
let selected = this.getSelected();
if (!selected.length)
return true;

@@ -193,14 +216,14 @@ define([
return;

selected.sort(function (a, b) {
var distanceA = Math.abs(a.pos.x - options.x) + Math.abs(a.pos.y - options.y);
var distanceB = Math.abs(b.pos.x - options.x) + Math.abs(b.pos.y - options.y);
let distanceA = Math.abs(a.pos.x - options.x) + Math.abs(a.pos.y - options.y);
let distanceB = Math.abs(b.pos.x - options.x) + Math.abs(b.pos.y - options.y);

return (distanceA > distanceB) ? 1 : -1;
});

var deltaX = selected[0].pos.x - options.x;
var deltaY = selected[0].pos.y - options.y;
let deltaX = selected[0].pos.x - options.x;
let deltaY = selected[0].pos.y - options.y;

selected.forEach(function (s) {
s.pos.x -= deltaX;
@@ -209,7 +232,7 @@ define([
},

deleteNode: function (options) {
var selected = this.getSelected();
let selected = this.getSelected();
selected.forEach(function (s) {
this.nodes.spliceWhere(n => (n == s));
this.links.spliceWhere(n => ((n.from == s) || (n.to == s)));
@@ -221,7 +244,7 @@ define([
},

recolorNode: function () {
var selected = this.getSelected(true);
let selected = this.getSelected(true);
if (!selected)
return true;

@@ -229,7 +252,7 @@ define([
},

resizeNode: function () {
var selected = this.getSelected(true);
let selected = this.getSelected(true);
if (!selected)
return true;

@@ -242,15 +265,15 @@ define([
if (!input.isKeyDown('ctrl'))
this.nodes.forEach(n => (n.selected = false));

var lowX = Math.min(from.x, to.x);
var lowY = Math.min(from.y, to.y);
let lowX = Math.min(from.x, to.x);
let lowY = Math.min(from.y, to.y);

var highX = Math.max(from.x, to.x);
var highY = Math.max(from.y, to.y);
let highX = Math.max(from.x, to.x);
let highY = Math.max(from.y, to.y);

for (var i = lowX; i <= highX; i++) {
for (var j = lowY; j <= highY; j++) {
var node = this.findNode(i, j);
for (let i = lowX; i <= highX; i++) {
for (let j = lowY; j <= highY; j++) {
let node = this.findNode(i, j);
if (!node)
continue;
node.selected = true;
@@ -261,13 +284,13 @@ define([
},

onMouseMove: function (e) {
var hoverNode = this.findNode(e.x, e.y);
let hoverNode = this.findNode(e.x, e.y);
if (hoverNode) {
var text = '';
var stats = hoverNode.stats || {};
for (var s in stats) {
let text = '';
let stats = hoverNode.stats || {};
for (let s in stats)
text += s + ': ' + stats[s] + '<br />';
}
text = text.substr(0, text.length - 6);

if (text.length > 0)


+ 10
- 3
helpers/passives/client/ui/templates/menu/menu.js View File

@@ -4,14 +4,16 @@ define([
'ui/factory',
'js/generator',
'js/renderer',
'js/constants'
'js/constants',
'js/client'
], function (
template,
styles,
uiFactory,
generator,
renderer,
constants
constants,
client
) {
return {
tpl: template,
@@ -27,6 +29,7 @@ define([
this.on('.btnSave', 'click', this.actions.onSave.bind(this));
this.on('.btnExport', 'click', this.actions.onExport.bind(this));
this.on('.btnImport', 'click', this.actions.onImport.bind(this));
this.on('.btnPersist', 'click', this.actions.onPersist.bind(this));
},

actions: {
@@ -50,7 +53,11 @@ define([

onImport: function () {
uiFactory.build('import');
},

onPersist: function () {
client.persist(generator.getData());
}
}
}
};
});

+ 1
- 1
helpers/passives/client/ui/templates/menu/styles.css View File

@@ -1 +1 @@
.q0{color:#f2f5f5}.q1{color:#4ac441}.q2{color:#3fa7dd}.q3{color:#a24eff}.q4{color:#ff6942}.color-red{color:#d43346 !important}.color-redA{color:#ff4252 !important}.color-blueA{color:#48edff !important}.color-blueB{color:#3fa7dd !important}.color-greenB{color:#4ac441 !important}.color-yellowB{color:#faac45 !important}.color-green{color:#80f643 !important}.color-brownC{color:#b15a30 !important}.color-brownD{color:#763b3b !important}.color-grayA{color:#f2f5f5 !important}.color-grayB{color:#c0c3cf !important}.color-grayC{color:#929398 !important}.color-grayD{color:#69696e !important}.color-pinkB{color:#de43ae !important}.uiMenu{position:absolute;right:10px;bottom:10px;padding:10px;width:120px;background-color:#373041;text-align:center}.uiMenu .heading{color:#f2f5f5;margin-bottom:15px}.uiMenu input{border:none;outline:none;width:calc(100% - 10px);height:20px;padding:5px;display:box}.uiMenu .btn{float:left;width:100%;color:#f2f5f5;background-color:#3fa7dd;padding:5px;box-sizing:border-box;cursor:pointer}.uiMenu .btn:not(:last-child){margin-bottom:15px}.uiMenu .btn:hover{background-color:#51fc9a;color:#3c3f4c}.uiMenu .btn:nth-child(3){clear:both}
.q0{color:#f2f5f5}.q1{color:#4ac441}.q2{color:#3fa7dd}.q3{color:#a24eff}.q4{color:#ff6942}.color-red{color:#d43346 !important}.color-redA{color:#ff4252 !important}.color-blueA{color:#48edff !important}.color-blueB{color:#3fa7dd !important}.color-greenB{color:#4ac441 !important}.color-yellowB{color:#faac45 !important}.color-green{color:#80f643 !important}.color-brownC{color:#b15a30 !important}.color-brownD{color:#763b3b !important}.color-grayA{color:#f2f5f5 !important}.color-grayB{color:#c0c3cf !important}.color-grayC{color:#929398 !important}.color-grayD{color:#69696e !important}.color-pinkB{color:#de43ae !important}.uiMenu{position:absolute;right:10px;bottom:10px;padding:10px;width:120px;background-color:#373041;text-align:center}.uiMenu .heading{color:#f2f5f5;margin-bottom:15px}.uiMenu input{border:none;outline:none;width:calc(100% - 10px);height:20px;padding:5px;display:box}.uiMenu .btn{float:left;width:100%;color:#f2f5f5;background-color:#3fa7dd;padding:5px;box-sizing:border-box;cursor:pointer}.uiMenu .btn:not(:last-child){margin-bottom:15px}.uiMenu .btn:hover{background-color:#51fc9a;color:#3c3f4c}.uiMenu .btn:nth-child(3),.uiMenu .btn:nth-child(5){clear:both}

+ 1
- 1
helpers/passives/client/ui/templates/menu/styles.less View File

@@ -41,7 +41,7 @@
color: @blackB;
}

&:nth-child(3) {
&:nth-child(3), &:nth-child(5) {
clear: both;
}
}


+ 1
- 0
helpers/passives/client/ui/templates/menu/template.html View File

@@ -7,6 +7,7 @@
<div class="btn btnSave">Save</div>
<div class="btn btnExport">Export</div>
<div class="btn btnImport">Import</div>
<div class="btn btnPersist">Persist</div>
<div class="btn btnNew">New</div>
</div>
</div>

+ 14
- 13
helpers/passives/server/index.js View File

@@ -1,10 +1,10 @@
var fs = require('fs');
let fs = require('fs');

var mod = {
let mod = {
init: function (callback) {
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
let app = require('express')();
let server = require('http').createServer(app);
let io = require('socket.io')(server);

app.use(function (req, res, next) {
if (req.url.indexOf('/server') != 0)
@@ -13,7 +13,7 @@ var mod = {
next();
});

var lessMiddleware = require('less-middleware');
let lessMiddleware = require('less-middleware');
app.use(lessMiddleware('../', {
force: true,
render: {
@@ -26,9 +26,9 @@ var mod = {

io.on('connection', this.listeners.onConnection.bind(this));

var port = process.env.PORT || 5000;
let port = process.env.PORT || 5000;
server.listen(port, function () {
var message = 'Server: Ready';
let message = 'Server: Ready';
console.log(message);
});
},
@@ -40,14 +40,15 @@ var mod = {

onRequest: function (socket, msg, callback) {
if (msg.action == 'load') {
var res = JSON.parse(fs.readFileSync('saves/' + msg.fileName + '.json'));
let res = JSON.parse(fs.readFileSync('saves/' + msg.fileName + '.json'));
callback(res);
} else if (msg.action == 'save')
fs.writeFileSync('saves/' + msg.fileName + '.json', msg.data);
else if (msg.action == 'getFileList') {
callback(fs.readdirSync('saves/').map(l => (l.split('.')[0])));
return;
}
} else if (msg.action == 'persist')
require('./persist')(msg.data);

if (callback)
callback();
@@ -59,13 +60,13 @@ var mod = {
},

default: function (req, res, next) {
var root = req.url.split('/')[1];
var file = req.params[0];
let root = req.url.split('/')[1];
let file = req.params[0];

file = file.replace('/' + root + '/', '');

res.sendFile(file, {
'root': '../' + root
root: '../' + root
});
}
}


+ 9
- 0
helpers/passives/server/persist.js View File

@@ -0,0 +1,9 @@
const fs = require('fs');

module.exports = function (data) {
const serverString = `module.exports = ${JSON.stringify(data, null, '\t')};`;
fs.writeFileSync('../../../src/server/config/passiveTree.js', serverString);

const clientString = `define([], function() { return ${JSON.stringify(data)}; });`;
fs.writeFileSync('../../../src/client/ui/templates/passives/temp.js', clientString);
};

+ 1
- 1
helpers/passives/server/saves/tree.json
File diff suppressed because it is too large
View File


+ 10
- 1
src/client/ui/templates/passives/passives.js View File

@@ -52,7 +52,16 @@ define([
input.init(this.el);

this.data.nodes = temp.nodes;
this.data.links = temp.links;
this.data.links = temp.links.map(function (l) {
return {
from: {
id: l.from
},
to: {
id: l.to
}
};
});

//We need to be able to determine the size of elements
this.el.css({


+ 1
- 2220
src/client/ui/templates/passives/temp.js
File diff suppressed because it is too large
View File


+ 3
- 3
src/server/components/passives.js View File

@@ -71,12 +71,12 @@ module.exports = {
return;

let linked = passiveTree.links.some(function (l) {
if ((l.from.id !== node.id) && (l.to.id !== node.id))
if ((l.from !== node.id) && (l.to !== node.id))
return false;

return (
(this.selected.indexOf(l.from.id) > -1) ||
(this.selected.indexOf(l.to.id) > -1)
(this.selected.indexOf(l.from) > -1) ||
(this.selected.indexOf(l.to) > -1)
);
}, this);
if (!linked)


+ 1596
- 2093
src/server/config/passiveTree.js
File diff suppressed because it is too large
View File


+ 1
- 1
src/server/misc/clone.js View File

@@ -15,7 +15,7 @@ let cloneRecursive = function (o, newO) {
return newO;
}

if (!newO)
if (!newO)
newO = {};
for (let i in o) {
if (o.hasOwnProperty(i))


Loading…
Cancel
Save