From ff0cb39365d9ba7219be49e18f17c3afa25a226d Mon Sep 17 00:00:00 2001 From: Harkirat Singh Date: Tue, 15 Mar 2016 16:16:49 +0530 Subject: [PATCH 1/7] Fixes #64 --- html/css/main.css | 1 + 1 file changed, 1 insertion(+) diff --git a/html/css/main.css b/html/css/main.css index 49dc47d..e62d941 100644 --- a/html/css/main.css +++ b/html/css/main.css @@ -304,6 +304,7 @@ a { height:100%; text-align:center; z-index: 1000; + overflow: scroll; } #settings > div { From 4d537cd245896c0b75801dd006a0d8346855b7ea Mon Sep 17 00:00:00 2001 From: Harkirat Singh Date: Thu, 17 Mar 2016 15:07:13 +0530 Subject: [PATCH 2/7] Added Undo Functionality --- html/index.html | 1 + html/js/guiutils/MultiAction.js | 21 +++++++++++++---- html/js/structure.js | 2 +- html/js/tree/Change.js | 39 +++++++++++++++++++++++++++++++ html/js/tree/Node.js | 41 +++++++++++++++++++++++++++++---- html/js/tree/Tree.js | 19 +++++++++++---- 6 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 html/js/tree/Change.js diff --git a/html/index.html b/html/index.html index 0df2f02..583049b 100644 --- a/html/index.html +++ b/html/index.html @@ -101,6 +101,7 @@

Settings

+ diff --git a/html/js/guiutils/MultiAction.js b/html/js/guiutils/MultiAction.js index 8639ecc..1e9e6f3 100644 --- a/html/js/guiutils/MultiAction.js +++ b/html/js/guiutils/MultiAction.js @@ -52,6 +52,7 @@ GTE.TREE = (function(parentModule) { MultiAction.prototype.onClick = function() { switch (GTE.MODE) { case GTE.MODES.ADD: + var nodes = []; // Find the smallest number S and largest number L of children // for the nodes in the line var smallestAndLargest = this.findSmallestAndLargest(); @@ -59,16 +60,23 @@ GTE.TREE = (function(parentModule) { if (smallestAndLargest.smallest < smallestAndLargest.largest) { for (var i = 0; i < this.nodesInLine.length; i++) { while (this.nodesInLine[i].children.length < smallestAndLargest.largest) { - this.nodesInLine[i].onClick(); + nodes = nodes.concat(this.nodesInLine[i].onClick(true)); } } + var change = new GTE.TREE.Change(GTE.MODE); + change.nodes = nodes; + GTE.TREE.CHANGES.push(change); } // If L = 0, add two children to each node on the multiaction line, else // If S = L, add one child to each node on the multiaction line. else if (smallestAndLargest.largest === 0 || smallestAndLargest.smallest === smallestAndLargest.largest) { for (var j = 0; j < this.nodesInLine.length; j++) { - this.nodesInLine[j].onClick(); + nodes = nodes.concat(this.nodesInLine[j].onClick(true)); } + + var change = new GTE.TREE.Change(GTE.MODE); + change.nodes = nodes; + GTE.TREE.CHANGES.push(change); } break; case GTE.MODES.DELETE: @@ -77,18 +85,23 @@ GTE.TREE = (function(parentModule) { // of the tree (i.e. even if some nodes are leaves already, // do not delete them). otherwise (that is, ALL nodes in the // multiaction line are leaves), delete all these leaves. + var allLeaves = true; + var nodes = []; for (var k = 0; k < this.nodesInLine.length; k++) { if (this.nodesInLine[k].children.length > 0) { allLeaves = false; - this.nodesInLine[k].onClick(); + nodes = nodes.concat(this.nodesInLine[k].onClick(true)); } } if (allLeaves) { for (k = 0; k < this.nodesInLine.length; k++) { - this.nodesInLine[k].onClick(); + nodes = nodes.concat(this.nodesInLine[k].onClick(true)); } } + var change = new GTE.TREE.Change(GTE.MODE); + change.nodes = nodes; + GTE.TREE.CHANGES.push(change); break; case GTE.MODES.PLAYER_ASSIGNMENT: // set all nodes on the multiaction line to belong to the diff --git a/html/js/structure.js b/html/js/structure.js index 5c8f4e3..1f993cc 100644 --- a/html/js/structure.js +++ b/html/js/structure.js @@ -7,7 +7,7 @@ var GTE = (function () { GTE.UI = {}; GTE.TREE = {}; GTE.TREE.UTILS = {}; - + GTE.TREE.CHANGES = []; GTE.ORIENTATIONS = { VERTICAL: 0, HORIZONTAL: 1 diff --git a/html/js/tree/Change.js b/html/js/tree/Change.js new file mode 100644 index 0000000..78eee85 --- /dev/null +++ b/html/js/tree/Change.js @@ -0,0 +1,39 @@ +GTE.TREE = (function (parentModule) { + "use strict"; + + /** + * Creates a new instance of change Class. + * @class + * @param {Node} parent Parent node. If null, this is root. + * @param {Player} player Node's player + */ + function Change(mode) { + this.mode = mode; + this.nodes = []; + } + + Change.prototype.undo = function () { + if(this.mode==0) + this.deleteNodes(); + if(this.mode==1) + this.addNodes(); + + }; + + Change.prototype.deleteNodes = function() { + for(var i=0;i 0) { + var change = GTE.TREE.CHANGES.pop(); + change.undo(); + } + }; + // Add class to parent module parentModule.Tree = Tree; From ca2016117b1bd23a27d26a50f4bf06736d9a1cda Mon Sep 17 00:00:00 2001 From: Harkirat Singh Date: Thu, 17 Mar 2016 15:29:56 +0530 Subject: [PATCH 3/7] Added button for undo option --- html/css/font.css | 3 +++ html/index.html | 3 +++ html/js/guiutils/Tools.js | 6 ++++++ html/js/main.js | 5 +++++ html/js/tree/Tree.js | 6 ------ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/html/css/font.css b/html/css/font.css index dfe9888..85b34d9 100755 --- a/html/css/font.css +++ b/html/css/font.css @@ -59,3 +59,6 @@ .icon-cog:before { content: "\e900"; } +.icon-undo:before { + content: "\f0e2"; +} diff --git a/html/index.html b/html/index.html index 583049b..22a370a 100644 --- a/html/index.html +++ b/html/index.html @@ -42,6 +42,9 @@
  • +
      +
    • +
    diff --git a/html/js/guiutils/Tools.js b/html/js/guiutils/Tools.js index 760e868..d1b88ed 100644 --- a/html/js/guiutils/Tools.js +++ b/html/js/guiutils/Tools.js @@ -253,6 +253,12 @@ GTE.UI = (function (parentModule) { playerButton.style.color = colour; }; + Tools.prototype.undo = function() { + if(GTE.TREE.CHANGES.length > 0) { + var change = GTE.TREE.CHANGES.pop(); + change.undo(); + } + }; // Add class to parent module parentModule.Tools = Tools; diff --git a/html/js/main.js b/html/js/main.js index a3d5464..b507aae 100644 --- a/html/js/main.js +++ b/html/js/main.js @@ -129,6 +129,11 @@ return false; }); + document.getElementById("button-undo").addEventListener("click", function(){ + GTE.tools.undo(); + return false; + }); + document.getElementById("form-settings").addEventListener("submit", function(e){ e.preventDefault(); // Save settings diff --git a/html/js/tree/Tree.js b/html/js/tree/Tree.js index 4eda876..32ce1f0 100644 --- a/html/js/tree/Tree.js +++ b/html/js/tree/Tree.js @@ -1321,12 +1321,6 @@ GTE.TREE = (function (parentModule) { } }; - Tree.prototype.undo = function() { - if(GTE.TREE.CHANGES.length > 0) { - var change = GTE.TREE.CHANGES.pop(); - change.undo(); - } - }; // Add class to parent module parentModule.Tree = Tree; From f68390a67f21b50adc3441cc4e6710467352a689 Mon Sep 17 00:00:00 2001 From: Harkirat Singh Date: Thu, 17 Mar 2016 16:58:18 +0530 Subject: [PATCH 4/7] Added Undo Option After Selecting a Player --- html/js/guiutils/MultiAction.js | 6 +++++- html/js/tree/Change.js | 15 +++++++++++++-- html/js/tree/Node.js | 28 ++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/html/js/guiutils/MultiAction.js b/html/js/guiutils/MultiAction.js index 1e9e6f3..0011198 100644 --- a/html/js/guiutils/MultiAction.js +++ b/html/js/guiutils/MultiAction.js @@ -104,11 +104,15 @@ GTE.TREE = (function(parentModule) { GTE.TREE.CHANGES.push(change); break; case GTE.MODES.PLAYER_ASSIGNMENT: + var nodes = []; // set all nodes on the multiaction line to belong to the // current player (which may be chance) for (var l = 0; l < this.nodesInLine.length; l++) { - this.nodesInLine[l].onClick(); + nodes = nodes.concat(this.nodesInLine[l].onClick(true)); } + var change = new GTE.TREE.Change(GTE.MODE); + change.nodes = nodes; + GTE.TREE.CHANGES.push(change); break; case GTE.MODES.MERGE: // note that this mode button only works if every node belongs diff --git a/html/js/tree/Change.js b/html/js/tree/Change.js index 78eee85..8611770 100644 --- a/html/js/tree/Change.js +++ b/html/js/tree/Change.js @@ -17,7 +17,8 @@ GTE.TREE = (function (parentModule) { this.deleteNodes(); if(this.mode==1) this.addNodes(); - + if(this.mode==2) + this.assignPlayer(); }; Change.prototype.deleteNodes = function() { @@ -28,7 +29,17 @@ GTE.TREE = (function (parentModule) { Change.prototype.addNodes = function() { for(var i=0;i Date: Thu, 17 Mar 2016 17:13:09 +0530 Subject: [PATCH 5/7] Documentation --- html/js/guiutils/MultiAction.js | 6 ++++++ html/js/guiutils/Tools.js | 4 +++- html/js/tree/Change.js | 25 ++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/html/js/guiutils/MultiAction.js b/html/js/guiutils/MultiAction.js index 0011198..f2c0723 100644 --- a/html/js/guiutils/MultiAction.js +++ b/html/js/guiutils/MultiAction.js @@ -52,6 +52,8 @@ GTE.TREE = (function(parentModule) { MultiAction.prototype.onClick = function() { switch (GTE.MODE) { case GTE.MODES.ADD: + + // nodes array to store the nodes being affected by this change var nodes = []; // Find the smallest number S and largest number L of children // for the nodes in the line @@ -87,6 +89,8 @@ GTE.TREE = (function(parentModule) { // multiaction line are leaves), delete all these leaves. var allLeaves = true; + + // nodes array to store the nodes being affected by this change var nodes = []; for (var k = 0; k < this.nodesInLine.length; k++) { if (this.nodesInLine[k].children.length > 0) { @@ -104,6 +108,8 @@ GTE.TREE = (function(parentModule) { GTE.TREE.CHANGES.push(change); break; case GTE.MODES.PLAYER_ASSIGNMENT: + + // nodes array to store the nodes being affected by this change var nodes = []; // set all nodes on the multiaction line to belong to the // current player (which may be chance) diff --git a/html/js/guiutils/Tools.js b/html/js/guiutils/Tools.js index d1b88ed..2cf1180 100644 --- a/html/js/guiutils/Tools.js +++ b/html/js/guiutils/Tools.js @@ -252,7 +252,9 @@ GTE.UI = (function (parentModule) { var playerButton = document.getElementById("button-player-" + playerId); playerButton.style.color = colour; }; - + /** + * Undo the previous move + */ Tools.prototype.undo = function() { if(GTE.TREE.CHANGES.length > 0) { var change = GTE.TREE.CHANGES.pop(); diff --git a/html/js/tree/Change.js b/html/js/tree/Change.js index 8611770..7c8439a 100644 --- a/html/js/tree/Change.js +++ b/html/js/tree/Change.js @@ -4,35 +4,50 @@ GTE.TREE = (function (parentModule) { /** * Creates a new instance of change Class. * @class - * @param {Node} parent Parent node. If null, this is root. - * @param {Player} player Node's player + * @param {mode} Represents the mode of the Change. + * 0 : Addition of nodes + * 1 : Deletion of nodes + * 2 : Player Assignment */ function Change(mode) { this.mode = mode; this.nodes = []; } + /** + * Calls the corresponding function to revert to previous state + * according to the mode of the change. + */ Change.prototype.undo = function () { - if(this.mode==0) + if(this.mode == 0) this.deleteNodes(); - if(this.mode==1) + if(this.mode == 1) this.addNodes(); - if(this.mode==2) + if(this.mode == 2) this.assignPlayer(); }; + /** + * Deletes the nodes that were added in the previous move + */ Change.prototype.deleteNodes = function() { for(var i=0;i Date: Thu, 17 Mar 2016 17:29:11 +0530 Subject: [PATCH 6/7] Assigned color to leaf node in case of undo --- html/js/tree/Node.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/html/js/tree/Node.js b/html/js/tree/Node.js index a94cbb4..2fd84e7 100644 --- a/html/js/tree/Node.js +++ b/html/js/tree/Node.js @@ -177,6 +177,7 @@ GTE.TREE = (function (parentModule) { nodes.push(this.delete()); } else { nodes = (GTE.tree.deleteChildrenOf(this)); + nodes.push({node : this, player : this.player}); this.deassignPlayer(); } // Tell the tree to redraw itself @@ -366,10 +367,15 @@ GTE.TREE = (function (parentModule) { if (iset !== null) { this.iset.addNode(this); } - if(reachedBy !== null) + if(reachedBy !== null) { this.reachedBy = reachedBy; - if(player==null) + } + if(player==null) { this.deassignPlayer(); + } + else { + this.assignPlayer(player); + } this.deleted = false; GTE.tree.positionsUpdated = false; }; From 69fad32c23537dfa5c6439375c3ff356afc107da Mon Sep 17 00:00:00 2001 From: Harkirat Singh Date: Thu, 17 Mar 2016 19:02:52 +0530 Subject: [PATCH 7/7] Fixed Indentation --- html/js/tree/Change.js | 20 ++++++++++++-------- html/js/tree/Node.js | 10 +++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/html/js/tree/Change.js b/html/js/tree/Change.js index 7c8439a..09b58e2 100644 --- a/html/js/tree/Change.js +++ b/html/js/tree/Change.js @@ -19,11 +19,11 @@ GTE.TREE = (function (parentModule) { * according to the mode of the change. */ Change.prototype.undo = function () { - if(this.mode == 0) + if(this.mode === GTE.MODES.ADD) this.deleteNodes(); - if(this.mode == 1) + if(this.mode === GTE.MODES.DELETE) this.addNodes(); - if(this.mode == 2) + if(this.mode === GTE.MODES.PLAYER_ASSIGNMENT) this.assignPlayer(); }; @@ -31,8 +31,9 @@ GTE.TREE = (function (parentModule) { * Deletes the nodes that were added in the previous move */ Change.prototype.deleteNodes = function() { - for(var i=0;i