updated more code
This commit is contained in:
parent
05e375074a
commit
2006ec85ec
@ -76,19 +76,6 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
||||
return
|
||||
end
|
||||
|
||||
-- initialize list of objects to move (and store local position + rotation)
|
||||
local additionalObjects = {}
|
||||
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
|
||||
if not obj.locked then
|
||||
local data = {
|
||||
object = obj,
|
||||
localPos = hoveredObject.positionToLocal(obj.getPosition()),
|
||||
localRot = obj.getRotation() - cardRot
|
||||
}
|
||||
table.insert(additionalObjects, data)
|
||||
end
|
||||
end
|
||||
|
||||
-- get the rotation of the owning playermat (or Mythos)
|
||||
local cardOwner = guidReferenceApi.getOwnerOfObject(hoveredObject)
|
||||
local ownerRotation = Vector(0, 270, 0)
|
||||
@ -101,17 +88,7 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
||||
local newCardRot = cardRot:setAt("y", matRotation.y + cardRot.y - ownerRotation.y)
|
||||
|
||||
-- move the main card to threat area
|
||||
hoveredObject.setRotation(newCardRot)
|
||||
hoveredObject.setPosition(threatAreaPos)
|
||||
|
||||
-- move tokens/tiles (to new global position)
|
||||
for _, data in ipairs(additionalObjects) do
|
||||
data.object.setPosition(hoveredObject.positionToWorld(data.localPos))
|
||||
|
||||
local newRot = data.localRot + Vector(0, newCardRot.y, 0)
|
||||
newRot.y = roundToMultiple(newRot.y, 45)
|
||||
data.object.setRotation(newRot)
|
||||
end
|
||||
GlobalApi.moveCardWithTokens(hoveredObject, threatAreaPos, newCardRot)
|
||||
|
||||
-- contruct feedback message (hide name when face-down + enabled setting)
|
||||
local cardName = hoveredObject.getName()
|
||||
|
@ -180,9 +180,10 @@ function getRandomSeed()
|
||||
return math.random(999)
|
||||
end
|
||||
|
||||
function onObjectDrop(playerColor, object)
|
||||
if object.type ~= "Card" then return end
|
||||
handleCardDropping({ player = Player[playerColor], card = object })
|
||||
function onObjectDrop(_, object)
|
||||
if object.type == "Card" or object.type == "Deck" then
|
||||
moveCardWithTokens({ card = object })
|
||||
end
|
||||
end
|
||||
|
||||
-- Event hook for any object search. When chaos tokens are manipulated while the chaos bag
|
||||
@ -214,7 +215,7 @@ function tryObjectEnterContainer(container, object)
|
||||
if object.hasTag("Minicard") and container.hasTag("Minicard") then
|
||||
return false
|
||||
elseif object.type == "Card" then
|
||||
handleCardResting({ card = object })
|
||||
finishCardMoving(object)
|
||||
end
|
||||
|
||||
playAreaApi.tryObjectEnterContainer(container, object)
|
||||
@ -2841,23 +2842,36 @@ function tableContains(thisTable, thisElement)
|
||||
return false
|
||||
end
|
||||
|
||||
function handleCardDropping(params)
|
||||
function moveCardWithTokens(params)
|
||||
local card = params.card
|
||||
local player = params.player
|
||||
local position = params.position
|
||||
local rotation = params.rotation
|
||||
|
||||
-- store local position/rotation of tokens
|
||||
cardTokens[card] = {}
|
||||
local cardRot = card.getRotation()
|
||||
for _, token in ipairs(searchLib.onObject(card, "isTileOrToken", 0.95)) do
|
||||
cardTokens[card].token = token
|
||||
cardTokens[card].localPos = card.positionToLocal(token.getPosition())
|
||||
cardTokens[card].localRot = token.getRotation() - cardRot
|
||||
if not token.locked then
|
||||
cardTokens[card].token = token
|
||||
cardTokens[card].localPos = card.positionToLocal(token.getPosition())
|
||||
cardTokens[card].localRot = token.getRotation() - cardRot
|
||||
end
|
||||
end
|
||||
|
||||
if position then
|
||||
card.setPositionSmooth(position)
|
||||
end
|
||||
|
||||
if rotation then
|
||||
card.setRotationSmooth(rotation)
|
||||
end
|
||||
|
||||
-- wait for the card to finish moving
|
||||
Wait.condition(
|
||||
function() handleCardResting({ card = card }) end,
|
||||
function() finishCardMoving(card) end,
|
||||
function()
|
||||
if card ~= nil and player ~= nil and player.seated then
|
||||
return card.resting and not tableContains(player.getHoldingObjects(), card)
|
||||
if card ~= nil then
|
||||
return card.resting and card.isSmoothMoving()
|
||||
else
|
||||
return true
|
||||
end
|
||||
@ -2865,8 +2879,7 @@ function handleCardDropping(params)
|
||||
)
|
||||
end
|
||||
|
||||
function handleCardResting(params)
|
||||
local card = params.card
|
||||
function finishCardMoving(card)
|
||||
if card == nil or cardTokens[card] == nil or #cardTokens[card] == 0 then return end
|
||||
|
||||
local cardRot = card.getRotation()
|
||||
|
@ -60,6 +60,14 @@ do
|
||||
Global.call("removeTokensFromObject", { object = object, owner = owner })
|
||||
end
|
||||
|
||||
-- moves a card with tokens on it
|
||||
---@param card tts__Object Card that should get moved
|
||||
---@param position? tts__Vector Target position
|
||||
---@param rotation? tts__Vector Target rotation
|
||||
function GlobalApi.moveCardWithTokens(card, position, rotation)
|
||||
Global.call("moveCardWithTokens", { card = card, position = position, rotation = rotation })
|
||||
end
|
||||
|
||||
-- loads saved options
|
||||
---@param options table Set a new state for the option table
|
||||
function GlobalApi.loadOptionPanelSettings(options)
|
||||
|
@ -360,23 +360,7 @@ function discardOrMove(_, playerColor, isRightClick)
|
||||
|
||||
for _, obj in ipairs(searchResult) do
|
||||
if obj.type == "Card" or obj.type == "Deck" then
|
||||
-- initialize list of objects to move (and store local position + rotation)
|
||||
local additionalObjects = {}
|
||||
for _, tokenOnCard in ipairs(searchLib.onObject(obj, "isTileOrToken")) do
|
||||
if not tokenOnCard.locked then
|
||||
local data = {
|
||||
object = tokenOnCard,
|
||||
localPos = obj.positionToLocal(tokenOnCard.getPosition()),
|
||||
}
|
||||
table.insert(additionalObjects, data)
|
||||
end
|
||||
end
|
||||
|
||||
obj.setPosition(threatAreaPos)
|
||||
-- move tokens/tiles (to new global position)
|
||||
for _, data in ipairs(additionalObjects) do
|
||||
data.object.setPosition(obj.positionToWorld(data.localPos))
|
||||
end
|
||||
GlobalApi.moveCardWithTokens(obj, threatAreaPos)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user