moving short supply function directly to card
This commit is contained in:
parent
1fd6f8bd48
commit
0b6eb32f75
@ -33,8 +33,8 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScriptState": "",
|
||||
"LuaScript_path": "AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
"Nickname": "Short Supply",
|
||||
|
57
objects/AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua
Normal file
57
objects/AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua
Normal file
@ -0,0 +1,57 @@
|
||||
local MAT_GUIDS = { "8b081b", "bd0ff4", "383d8b", "0840d5" }
|
||||
|
||||
function onLoad()
|
||||
self.addContextMenuItem("Discard 10 cards", shortSupply)
|
||||
end
|
||||
|
||||
-- called by context menu entry
|
||||
function shortSupply(color)
|
||||
local cardPos = self.getPosition()
|
||||
local playerNumber = getPlayernumber(cardPos)
|
||||
local mat = getObjectFromGUID(MAT_GUIDS[playerNumber])
|
||||
if mat == nil then return end
|
||||
|
||||
-- get draw deck and discard pile
|
||||
mat.call("getDrawDiscardDecks")
|
||||
local drawDeck = mat.getVar("drawDeck")
|
||||
local discardPos = mat.getTable("DISCARD_PILE_POSITION")
|
||||
if discardPos == nil then
|
||||
broadcastToAll("Couldn't retrieve discard position from playermat!", "Red")
|
||||
return
|
||||
end
|
||||
|
||||
if drawDeck == nil then
|
||||
broadcastToColor("Deck not found!", color, "Yellow")
|
||||
return
|
||||
elseif drawDeck.tag ~= "Deck" then
|
||||
broadcastToColor("Deck only contains a single card!", color, "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
-- discard cards
|
||||
discardPos.y = 0.5
|
||||
for i = 1, 10 do
|
||||
discardPos.y = discardPos.y + 0.05 * i
|
||||
drawDeck.takeObject({
|
||||
flip = true,
|
||||
position = discardPos
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- helper to find playernumber based on position
|
||||
function getPlayernumber(cardPos)
|
||||
if cardPos.x < -42 then
|
||||
if cardPos.z > 0 then
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
end
|
||||
else
|
||||
if cardPos.z > 0 then
|
||||
return 3
|
||||
else
|
||||
return 4
|
||||
end
|
||||
end
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
MAT_GUIDS = { "8b081b", "bd0ff4", "383d8b", "0840d5" }
|
||||
|
||||
local BUTTON_PARAMETERS = {}
|
||||
BUTTON_PARAMETERS.function_owner = self
|
||||
local buttonParamaters = {}
|
||||
buttonParamaters.function_owner = self
|
||||
|
||||
-- saving "playerColor" and "des"
|
||||
function onSave() return JSON.encode({ playerColor, des}) end
|
||||
@ -13,41 +13,41 @@ function onLoad(saved_data)
|
||||
des = loaded_data[2] or false
|
||||
|
||||
-- index 0: button as hand size label
|
||||
BUTTON_PARAMETERS.hover_color = "White"
|
||||
BUTTON_PARAMETERS.click_function = "none"
|
||||
BUTTON_PARAMETERS.position = { 0, 0.1, -0.4 }
|
||||
BUTTON_PARAMETERS.height = 0
|
||||
BUTTON_PARAMETERS.width = 0
|
||||
BUTTON_PARAMETERS.font_size = 500
|
||||
BUTTON_PARAMETERS.font_color = "White"
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.hover_color = "White"
|
||||
buttonParamaters.click_function = "none"
|
||||
buttonParamaters.position = { 0, 0.11, -0.4 }
|
||||
buttonParamaters.height = 0
|
||||
buttonParamaters.width = 0
|
||||
buttonParamaters.font_size = 500
|
||||
buttonParamaters.font_color = "White"
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- index 1: button to toggle "des"
|
||||
BUTTON_PARAMETERS.label = "DES: " .. (des and "✓" or "✗")
|
||||
BUTTON_PARAMETERS.click_function = "toggleDES"
|
||||
BUTTON_PARAMETERS.position = { 0.475, 0.1, 0.25 }
|
||||
BUTTON_PARAMETERS.height = 175
|
||||
BUTTON_PARAMETERS.width = 440
|
||||
BUTTON_PARAMETERS.font_size = 90
|
||||
BUTTON_PARAMETERS.font_color = "Black"
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.label = "DES: " .. (des and "✓" or "✗")
|
||||
buttonParamaters.click_function = "toggleDES"
|
||||
buttonParamaters.position = { 0.475, 0.11, 0.25 }
|
||||
buttonParamaters.height = 175
|
||||
buttonParamaters.width = 440
|
||||
buttonParamaters.font_size = 90
|
||||
buttonParamaters.font_color = "Black"
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- index 2: button to discard a card
|
||||
BUTTON_PARAMETERS.label = "discard random card"
|
||||
BUTTON_PARAMETERS.click_function = "discardRandom"
|
||||
BUTTON_PARAMETERS.position = { 0, 0.1, 0.7 }
|
||||
BUTTON_PARAMETERS.width = 900
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.label = "discard random card"
|
||||
buttonParamaters.click_function = "discardRandom"
|
||||
buttonParamaters.position = { 0, 0.11, 0.7 }
|
||||
buttonParamaters.width = 900
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- index 3: button to select color
|
||||
BUTTON_PARAMETERS.label = playerColor
|
||||
BUTTON_PARAMETERS.color = playerColor
|
||||
BUTTON_PARAMETERS.hover_color = playerColor
|
||||
BUTTON_PARAMETERS.click_function = "changeColor"
|
||||
BUTTON_PARAMETERS.tooltip = "change color"
|
||||
BUTTON_PARAMETERS.position = { -0.475, 0.1, 0.25 }
|
||||
BUTTON_PARAMETERS.width = 440
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.label = playerColor
|
||||
buttonParamaters.color = playerColor
|
||||
buttonParamaters.hover_color = playerColor
|
||||
buttonParamaters.click_function = "changeColor"
|
||||
buttonParamaters.tooltip = "change color"
|
||||
buttonParamaters.position = { -0.475, 0.11, 0.25 }
|
||||
buttonParamaters.width = 440
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- start loop to update card count
|
||||
loopId = Wait.time(||updateValue(), 1, -1)
|
||||
@ -71,14 +71,6 @@ function onLoad(saved_data)
|
||||
end
|
||||
|
||||
function onObjectHover(hover_color, obj)
|
||||
-- error handling
|
||||
if obj == nil then return end
|
||||
|
||||
-- add context menu to "short supply"
|
||||
if obj.getName() == "Short Supply" then
|
||||
obj.addContextMenuItem("Discard 10 (" .. playerColor .. ")", shortSupply)
|
||||
end
|
||||
|
||||
-- only continue if correct player hovers over "self"
|
||||
if obj ~= self or hover_color ~= playerColor then return end
|
||||
|
||||
@ -151,11 +143,11 @@ function changeColor(_, _, isRightClick, color)
|
||||
end
|
||||
|
||||
-- update "change color" button (note: remove and create instantly updates hover_color)
|
||||
BUTTON_PARAMETERS.label = playerColor
|
||||
BUTTON_PARAMETERS.color = playerColor
|
||||
BUTTON_PARAMETERS.hover_color = playerColor
|
||||
buttonParamaters.label = playerColor
|
||||
buttonParamaters.color = playerColor
|
||||
buttonParamaters.hover_color = playerColor
|
||||
self.removeButton(3)
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
self.createButton(buttonParamaters)
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
@ -184,38 +176,6 @@ function discardRandom()
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
-- discards the top 10 cards of your deck
|
||||
---------------------------------------------------------
|
||||
function shortSupply(color)
|
||||
local mat = getPlayermat(playerColor)
|
||||
if mat == nil then return end
|
||||
|
||||
-- get draw deck and discard pile
|
||||
mat.call("getDrawDiscardDecks")
|
||||
drawDeck = mat.getVar("drawDeck")
|
||||
local discardPos = mat.getTable("DISCARD_PILE_POSITION")
|
||||
if discardPos == nil then
|
||||
broadcastToAll("Couldn't retrieve discard position from playermat!", "Red")
|
||||
return
|
||||
end
|
||||
|
||||
if drawDeck == nil then
|
||||
broadcastToColor("Deck not found!", color, "Yellow")
|
||||
return
|
||||
elseif drawDeck.tag ~= "Deck" then
|
||||
broadcastToColor("Deck only contains a single card!", color, "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
-- discard cards
|
||||
discardPos[2] = 0.5
|
||||
for i = 1, 10 do
|
||||
discardPos[2] = discardPos[2] + 0.05 * i
|
||||
drawDeck.takeObject({ flip = true; position = discardPos })
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
-- helper functions
|
||||
---------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user