Add parameter for specifying node names

This commit is contained in:
Robert Machmer 2015-12-21 00:32:17 +01:00
parent 9723b80c98
commit b5649d3fd4
2 changed files with 7 additions and 3 deletions

View File

@ -72,9 +72,9 @@ function Graph.new()
-- @param anchor - Wether the node should be locked in place or not (optional). -- @param anchor - Wether the node should be locked in place or not (optional).
-- @param ... - Additional parameters (useful when a custom Node class is used). -- @param ... - Additional parameters (useful when a custom Node class is used).
-- --
function self:addNode( id, x, y, anchor, ... ) function self:addNode( id, name, x, y, anchor, ... )
assert( not nodes[id], "Node IDs must be unique." ); assert( not nodes[id], "Node IDs must be unique." );
nodes[id] = Node.new( id, x, y, anchor, ... ); nodes[id] = Node.new( id, name, x, y, anchor, ... );
return nodes[id]; return nodes[id];
end end

View File

@ -17,7 +17,7 @@ local DEFAULT_MASS = 3;
-- @param y - The y coordinate the Node should be spawned at (optional). -- @param y - The y coordinate the Node should be spawned at (optional).
-- @param anchor - Wether the node should be locked in place or not (optional). -- @param anchor - Wether the node should be locked in place or not (optional).
-- --
function Node.new( id, x, y, anchor ) function Node.new( id, name, x, y, anchor )
local self = {}; local self = {};
local px, py = x or 0, y or 0; local px, py = x or 0, y or 0;
@ -143,6 +143,10 @@ function Node.new( id, x, y, anchor )
return mass; return mass;
end end
function self:getName()
return name;
end
return self; return self;
end end