-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent_hands.ttslua
54 lines (50 loc) · 1.68 KB
/
current_hands.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
function onUpdate()
updateDescription()
end
function updateDescription()
-- consumes nothing, and updates my description to reflect the
-- hands of seated players.
local seated_player_colors = getSeatedPlayers()
if #seated_player_colors < 1 then return end
local hands_string = format_player_colors(seated_player_colors)
return self.setDescription(hands_string)
end
function format_player_colors(player_colors)
-- consumes a list of player-colors (strings), and produces a string describing them.
local str = ""
if #player_colors == 0 then
return str .. "none"
else
for _, player_color in ipairs(player_colors) do
if player_color ~= "Black" then
player = Player[player_color]
str = str .. format_player(player)
end
end
return str
end
end
function format_player(player)
-- consumes a player and produces a string describing its state
local fstring = "%s :: handsize = %i :: hand = %s \n"
colour = player.color
handcount = player.getHandCount()
if handcount > 0 then
hand_contents = player.getHandObjects(1)
hand_contents_str = format_hand(hand_contents)
else
hand_contents_str = "None"
end
return string.format(fstring, colour, #hand_contents, hand_contents_str)
end
function format_hand(hand_objects)
-- consumes a table of objects and produces a string of
-- the GMNote-stored names of the objects
local str = ""
local fstring = "%s/"
for _, object in ipairs(hand_objects) do
local object_name = object.getGMNotes()
str = str .. string.format(fstring, object_name)
end
return str
end