-
Notifications
You must be signed in to change notification settings - Fork 0
/
total_difficulty_on_board_counter.ttslua
56 lines (48 loc) · 1.7 KB
/
total_difficulty_on_board_counter.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
function onLoad()
board_scripting_zone_GUID = "057141"
difficulty_counter_GUID = "28fdfb"
board_scripting_zone = getObjectFromGUID(board_scripting_zone_GUID)
difficulty_counter = getObjectFromGUID(difficulty_counter_GUID)
difficulty_on_board = 0
end
function onUpdate()
difficulty_on_board = get_difficulty_in_zone(board_scripting_zone)
difficulty_counter.setValue(difficulty_on_board)
end
function get_difficulty_in_zone(zone)
-- consumes a scripting zone reference and produces the total difficulty of all
-- currently active tasks in the zone.
active_taskcards = scripting_zone_get_all_taskcards(zone)
return taskcards_get_total_difficulty(active_taskcards)
end
function taskcards_get_total_difficulty(taskcards)
-- consumes a table of taskcards and produces their total difficulty
total = 0
for _, card in ipairs(taskcards) do
total = total + task_card_get_value(card)
end
return total
end
function scripting_zone_get_all_taskcards(zone)
-- consumes a scripting zone and gets all the task cards within it.
all_objects = zone.getObjects()
task_cards = objects_get_taskcards(all_objects)
return task_cards
end
function objects_get_taskcards(t)
-- consumes a table of objects and produces a table of its members That
-- are task cards.
local out = {}
-- printToAll(tostring(table == nil))
-- printToAll(tostring(pairs(table)))
for _, object in pairs(t) do
if Global.call("is_taskcard_p",object) then
table.insert(out, object)
end
end
return out
end
function task_card_get_value(card)
-- consumes a task-card and produces its value on completion
return tonumber(card.getGMNotes())
end