mirror of
https://github.com/rm-code/Graphoon.git
synced 2024-11-16 18:24:22 +00:00
Add optional name parameter for Nodes
This parameter can be accessed via the getName getter. If no value is passed to the constructor the name variable will default to the id.
This commit is contained in:
parent
35868a4360
commit
59a055da99
@ -70,9 +70,9 @@ function Graph.new()
|
||||
-- @param x - The x-coordinate at which to place the new node.
|
||||
-- @param y - The y-coordinate at which to place the new node.
|
||||
--
|
||||
function self:addNode( id, x, y )
|
||||
function self:addNode( id, name, x, y )
|
||||
assert( not nodes[id], "Node IDs must be unique." );
|
||||
nodes[id] = Node.new( id, x, y );
|
||||
nodes[id] = Node.new( id, name, x, y );
|
||||
end
|
||||
|
||||
---
|
||||
|
@ -12,9 +12,10 @@ local DEFAULT_MASS = 0.05;
|
||||
---
|
||||
-- @param id - A unique id which will be used to reference this node.
|
||||
--
|
||||
function Node.new( id, x, y )
|
||||
function Node.new( id, name, x, y )
|
||||
local self = {};
|
||||
|
||||
local name = name or id;
|
||||
local px, py = x or 0, y or 0;
|
||||
local ax, ay = 0, 0;
|
||||
local vx, vy = 0, 0;
|
||||
@ -79,6 +80,10 @@ function Node.new( id, x, y )
|
||||
return id;
|
||||
end
|
||||
|
||||
function self:getName()
|
||||
return name;
|
||||
end
|
||||
|
||||
function self:getX()
|
||||
return px;
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user