-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.lua
120 lines (108 loc) · 3.72 KB
/
code.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--[[ Lua code. See documentation: https://api.tabletopsimulator.com/ --]]
--[[ The onLoad event is called after the game save finishes loading. --]]
gameDeck = {}
dealerQuarter = {}
resetQuarter = {}
clearQuarter = {}
globalCard = nil
hasDealt = false
--fills global containers for scripted objects
function onLoad()
gameDeck = spawnDeck()
dealerQuarter = buttonSpawner(-10, 10, 'dealCards', 'DEAL', 14, 12, 4)
resetQuarter = buttonSpawner(-10.5, 11, 'clearHands', 'RESET', 7, 12.5, -4)
clearQuarter = buttonSpawner(-11, 11, 'clearScriptables', 'CLEAR', 7, 13, 4)
drawQuarter = buttonSpawner(-11.5, 11, 'dealCardToPlayer', 'DRAW', 15, 13.5, -4)
hasDealt = false
print('loaded!')
end
--helper function for 'DEAL' button
function dealCardToPlayer(obj, color)
gameDeck.dealToColor(1, color)
end
--helper function for card removal timer
function destroyThing()
globalCard.destruct()
end
--deals 1 card to all players and removes a card from the deck (after waiting 60 frames)
function dealCards()
globalCard = gameDeck.takeObject({index = 0, position = {-8,1.3,0}, rotation = {180,0,0}})
gameDeck.dealToAll(1)
Wait.frames(destroyThing, 60)
hasDealt = true
end
--spawns the deck object and returns it
function spawnDeck()
local deckHolder = {}
deckHolder.type = 'DeckCustom'
deckHolder.position = {0,1,0}
deckHolder.rotation = {0,180,180}
dealdeck = spawnObject(deckHolder)
customDeck = {}
customDeck.width = 8
customDeck.height = 7
customDeck.face = 'https://raw.githubusercontent.com/reiss-josh/loveletter/master/testdeck.png'
customDeck.back = 'http://i.imgur.com/QFhp7nF.jpg'
customDeck.unique_back = false
customDeck.number = 16
dealdeck.setCustomObject(customDeck)
dealdeck.shuffle()
return dealdeck
end
--empties the hands of all seated players
function clearHands()
player_colors = getSeatedPlayers()
for _, color in ipairs(player_colors) do
handTable = Player[color].getHandObjects()
for _, card in ipairs(handTable) do
card.destruct()
end
end
if (gameDeck != nil) then gameDeck.destruct() end
gameDeck = spawnDeck()
hasDealt = false
end
--destroys all scriptable objects (useful for my uploading / removing buttons)
function clearScriptables()
if (gameDeck != nil) then gameDeck.destruct() end
if (dealerQuarter != nil) then dealerQuarter.destruct() end
if (resetQuarter != nil) then resetQuarter.destruct() end
if (clearQuarter != nil) then clearQuarter.destruct() end
if (drawQuarter != nil) then drawQuarter.destruct() end
end
--spawns a quarter and attaches a button to it
--quarter spawns at {0,y,z}
--button spawns at {xb, yb, zb} with label 'label' and calls function 'func'
function buttonSpawner(y, z, func, label, xb, yb, zb)
local obj = {}
obj.type = 'Quarter'
obj.position = {0, y, z}
obj.rotation = {0, -90, 0}
deal_token = spawnObject(obj)
deal_token.use_gravity = false
deal_token.interactable = false
local button = {}
button.click_function = func
button.label = label
button.function_owner = Global
button.position = {xb, yb, zb}
button.rotation = {0, -90, 0}
button.width = 1000
button.height = 500
button.font_size = 250
deal_token.createButton(button)
return deal_token
end
--updates button visibility (hides 'DEAL' mid-game and hides 'DRAW' before setup)
function onUpdate()
if hasDealt == true then
dealerQuarter.setInvisibleTo(Player.getColors())
drawQuarter.setInvisibleTo(nil)
else
dealerQuarter.setInvisibleTo(nil)
drawQuarter.setInvisibleTo(Player.getColors())
end
end
--[[ Deal Cards. --]]
--front http://i.imgur.com/tysJ4C9.jpg
--back http://i.imgur.com/QFhp7nF.jpg