-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_factory.ttslua
73 lines (68 loc) · 2.22 KB
/
task_factory.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
68
69
70
71
72
73
require("it_moves/random_tasks") -- provides "tasks"
function onload(save_state)
unused_tasks = tasks
task_end_of_deck = {
name = "Deck exhausted",
difficulty = 99,
state_0 = [[If you still need tasks,
you'll have to write them up yourself.]]
}
spawn_offset_from_button = vector(-6.5, 8, 4)
self.createButton(
{
click_function = "pressed",
label = "task factory",
function_owner = self,
position = {0, 1, 1},
rotation = {0, 180, 0},
width = 3300,
height = 600,
font_size = 500
}
)
end
function pressed(clicked_object, player)
my_position = self.getPosition()
spawning_zone = my_position + spawn_offset_from_button
unused_tasks = tasks_spawn_taskcard(unused_tasks, spawning_zone)
end
function tasks_spawn_taskcard(tasks_table, pos_vector)
-- consumes a table of task-specifications and pops
-- a task from it. produces the table without the
-- task, and as a side-effect spawns a notecard
-- representing the task in the gameworld.
if #tasks_table == 0 then
task_to_spawn = task_end_of_deck
else
task_to_spawn = table.remove(unused_tasks, math.random( #unused_tasks ))
end
printToAll("spawning task " .. task_to_spawn["name"])
task_spawn_task_card(task_to_spawn, pos_vector)
return unused_tasks
end
function task_spawn_task_card(task, pos_vector)
-- consumes a task-specification and a world-location, and spawns
-- a Notecard representing the task at the world-location. returns
-- nothing.
local callback = function(obj)
task_card_write_info(obj, task)
end
spawnObject(
{
type = "Notecard",
position = pos_vector,
sound = true,
scale = Vector(1.5,1.5,1.5),
callback_function = callback
}
)
return
end
function task_card_write_info(notecard, task)
-- consumes a notecard object-reference and a task-spec and writes
-- the task-spec onto the notecard. return nothing.
notecard.setName(task["name"])
notecard.setGMNotes(tostring(task["difficulty"]))
notecard.setDescription(tostring(task["state_0"]))
return
end