-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.lua
69 lines (50 loc) · 1.73 KB
/
node.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local Node = {}
function Node:new(nodeData)
local node = {}
local position = nodeData.position or {x=0,y=0}
node.x = position.x
node.y = position.y
node.id = nodeData.referenceId
node.maxLevel = nodeData.maxLevel
node.passiveId = nodeData.internalIdentifier
local c = nodeData.connections or {}
node.connections = {}
for _, v in pairs(c) do
table.insert(node.connections, v.referenceId)
end
local img = GetImage(node.passiveId)
node.width = img:getWidth()
node.height = img:getHeight()
setmetatable(node, self)
self.__index = self
return node
end
function Node:draw()
local img = GetImage(self.passiveId)
love.graphics.draw(img, self.x - self.width / 2, self.y - self.height / 2)
local r = math.max(self.width, self.height) / 2
love.graphics.setColor(0, 0, 0)
love.graphics.circle("fill", self.x - r + 3, self.y - r + 7, 8)
love.graphics.setColor(1, 1, 0, 0.2)
love.graphics.circle("line", self.x - r + 3, self.y - r + 7, 8)
love.graphics.setColor(1, 1, 1)
love.graphics.print(self.maxLevel, self.x - r, self.y - r)
end
function Node:mousepressed(x, y)
if (x > self.x - self.width / 2 and x < self.x + self.width / 2 and y > self.y - self.height / 2 and y < self.y + self.height / 2) then
if (SelectedNode1 == self) then
SelectedNode1 = nil
SelectedNode2 = nil
return true
end
if (SelectedNode1 ~= nil and (love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift"))) then
SelectedNode2 = self
return true
end
SelectedNode1 = self
SelectedNode2 = nil
return true
end
return false
end
return Node