-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhighlighter.ttslua
67 lines (60 loc) · 1.84 KB
/
highlighter.ttslua
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
-- Licensed under Creative Commons By 4.0 (https://creativecommons.org/licenses/by/4.0/legalcode)
COLOR = nil
PIECES_NAMES = nil
ID = nil
function onLoad(save_state)
self.addContextMenuItem("Highlight Pieces", highlight_on)
local data = JSON.decode(self.getDescription())
COLOR = Color[data.Color]
PIECES = data.Pieces
end
function highlight_on(...)
self.clearContextMenu()
self.addContextMenuItem("Highlight off", highlight_off)
ID = routineColorChange(Color(0, 0, 0, 0), COLOR, find_objects_by_names(PIECES))
end
function highlight_off(...)
self.clearContextMenu()
self.addContextMenuItem("Highlight Pieces", highlight_on)
Wait.stop(ID)
end
function routineColorChange(from_color, to_color, objects)
local steps = 30
local step_time = 0.05
function change()
function co_change()
local time = os.clock()
for x=1, steps do
local color = from_color:lerp(to_color, (1/steps)*x)
for _, object in ipairs(objects) do
object.highlightOn(color)
end
waitTime(step_time)
end
waitTime(0.1)
for x=1, steps do
local color = to_color:lerp(from_color, (1/steps)*x)
for _, object in ipairs(objects) do
object.highlightOn(color)
end
waitTime(step_time)
end
return 1
end
startLuaCoroutine(self, 'co_change')
end
change()
return Wait.time(change, 4.5, -1)
end
function find_objects_by_names(names)
local objects = {}
for _, o in ipairs(getAllObjects()) do
for _, n in ipairs(names) do
if o.getName() == n then
table.insert(objects, o)
end
end
end
return objects
end
#include util\wait