215 lines
6.7 KiB
Plaintext
215 lines
6.7 KiB
Plaintext
|
PLAYAREA = {
|
||
|
position = {-28.40, 4.15, -0.01},
|
||
|
rotation = { x=0, y=90, z=0 },
|
||
|
scale = {37.64, 5.10, 37.46}
|
||
|
}
|
||
|
|
||
|
SET_ASIDE_AREA = {
|
||
|
position = {-6.52, 1.55, 19.39},
|
||
|
rotation = {0, 270.00, 0}
|
||
|
}
|
||
|
|
||
|
CONNECTOR_URL_1 = "https://i.imgur.com/vppt2my.png"
|
||
|
CONNECTOR_URL_2 = "https://i.imgur.com/HyfE8m8.png"
|
||
|
CONNECTOR_URL_3 = "https://i.imgur.com/dHKBLoD.png"
|
||
|
|
||
|
HEART = 1
|
||
|
STAR = 2
|
||
|
DIAMOND = 3
|
||
|
TRIANGLE = 4
|
||
|
CIRCLE = 5
|
||
|
SQUARE = 6
|
||
|
|
||
|
RETURN_TO_DECK_GUIDS = {
|
||
|
"e1b096", "f3d951", "4aa735", "595817", "bbd866", "cc60a6"
|
||
|
}
|
||
|
|
||
|
LOCATIONS = {
|
||
|
{ guid="22f371", symbol=HEART, connections={ DIAMOND, STAR } },
|
||
|
{ guid="3fc05b", symbol=HEART, connections={ DIAMOND, STAR } },
|
||
|
{ guid="c8f441", symbol=TRIANGLE, connections={ STAR } },
|
||
|
{ guid="fefad6", symbol=TRIANGLE, connections={ STAR } },
|
||
|
{ guid="db1ed3", symbol=STAR, connections={ DIAMOND, TRIANGLE, CIRCLE, HEART } },
|
||
|
{ guid="5ef561", symbol=STAR, connections={ DIAMOND, TRIANGLE, CIRCLE, HEART } },
|
||
|
{ guid="941f46", symbol=DIAMOND, connections={ HEART, SQUARE, STAR, CIRCLE } },
|
||
|
{ guid="6ef414", symbol=DIAMOND, connections={ HEART, SQUARE, STAR, CIRCLE } },
|
||
|
{ guid="d71f61", symbol=CIRCLE, connections={ DIAMOND, STAR } },
|
||
|
{ guid="3b4974", symbol=CIRCLE, connections={ DIAMOND, STAR } },
|
||
|
{ guid="f37af1", symbol=CIRCLE, connections={ DIAMOND, STAR } },
|
||
|
{ guid="158c7c", symbol=SQUARE, connections={ DIAMOND } },
|
||
|
{ guid="fab058", symbol=SQUARE, connections={ DIAMOND } },
|
||
|
|
||
|
{ guid="0e6a01", symbol=HEART, connections={ DIAMOND, STAR } },
|
||
|
{ guid="59bf7d", symbol=HEART, connections={ DIAMOND, STAR } },
|
||
|
{ guid="5bc035", symbol=TRIANGLE, connections={ STAR, CIRCLE } },
|
||
|
{ guid="baec21", symbol=TRIANGLE, connections={ STAR, CIRCLE } },
|
||
|
{ guid="b5e340", symbol=STAR, connections={ HEART, TRIANGLE } },
|
||
|
{ guid="07056f", symbol=STAR, connections={ HEART, TRIANGLE } },
|
||
|
{ guid="d15d6f", symbol=DIAMOND, connections={ HEART, SQUARE } },
|
||
|
{ guid="f0b962", symbol=DIAMOND, connections={ HEART, SQUARE } },
|
||
|
{ guid="ae5d5c", symbol=CIRCLE, connections={ SQUARE, TRIANGLE } },
|
||
|
{ guid="fb0083", symbol=CIRCLE, connections={ SQUARE, TRIANGLE } },
|
||
|
{ guid="0261d3", symbol=SQUARE, connections={ DIAMOND, CIRCLE } },
|
||
|
{ guid="80cef8", symbol=SQUARE, connections={ DIAMOND, CIRCLE } }
|
||
|
}
|
||
|
|
||
|
function onLoad()
|
||
|
self.createButton({
|
||
|
label="Set Up",
|
||
|
click_function="setup",
|
||
|
function_owner=self,
|
||
|
position={0,0.1,-0.6},
|
||
|
height=120,
|
||
|
width=500,
|
||
|
scale={x=1.75, y=1.75, z=1.75},
|
||
|
font_size=80
|
||
|
})
|
||
|
|
||
|
self.createButton({
|
||
|
label="Update\nConnections",
|
||
|
click_function="updateConnections",
|
||
|
function_owner=self,
|
||
|
position={0,0.1,0.4},
|
||
|
height=240,
|
||
|
width=500,
|
||
|
scale={x=1.75, y=1.75, z=1.75},
|
||
|
font_size=80
|
||
|
})
|
||
|
|
||
|
playarea = getObjectFromGUID("721ba2")
|
||
|
makeIndexes()
|
||
|
math.randomseed(os.time())
|
||
|
end
|
||
|
|
||
|
function setup()
|
||
|
for i,guid in ipairs(RETURN_TO_DECK_GUIDS) do
|
||
|
local deck = getObjectFromGUID(guid)
|
||
|
if deck == nil then
|
||
|
print("Set up is only required for Return to the Boundary Beyond")
|
||
|
return
|
||
|
end
|
||
|
deck.shuffle()
|
||
|
deck.takeObject({
|
||
|
position = SET_ASIDE_AREA.position,
|
||
|
rotation = SET_ASIDE_AREA.rotation,
|
||
|
smooth = true
|
||
|
})
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function makeIndexes()
|
||
|
guidMap = {}
|
||
|
connMap = {}
|
||
|
for i,v in ipairs(LOCATIONS) do
|
||
|
guidMap[v.guid] = v
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function updateConnections(obj, color, alt_click)
|
||
|
local objs = Physics.cast({
|
||
|
origin = PLAYAREA.position,
|
||
|
direction = { x=0, y=1, z=0 },
|
||
|
type = 3,
|
||
|
size = PLAYAREA.scale,
|
||
|
orientation = PLAYAREA.rotation
|
||
|
})
|
||
|
|
||
|
local cardObjs = {}
|
||
|
local connObjs = {}
|
||
|
for i,v in ipairs(objs) do
|
||
|
local obj = v.hit_object
|
||
|
local guid = obj.getGUID()
|
||
|
if guid ~= nil and obj.tag == "Card" then
|
||
|
local loc = guidMap[guid]
|
||
|
if loc ~= nil and isOnTop(obj) then
|
||
|
cardObjs[guid] = obj
|
||
|
if connObjs[loc.symbol] == nil then
|
||
|
connObjs[loc.symbol] = {}
|
||
|
end
|
||
|
table.insert(connObjs[loc.symbol], obj)
|
||
|
end
|
||
|
elseif obj.tag == "Deck" and not obj.is_face_down then
|
||
|
local cards = obj.getObjects()
|
||
|
local card = cards[#cards]
|
||
|
local loc = guidMap[card.guid]
|
||
|
if loc ~= nil then
|
||
|
cardObjs[card.guid] = obj
|
||
|
if connObjs[loc.symbol] == nil then
|
||
|
connObjs[loc.symbol] = {}
|
||
|
end
|
||
|
table.insert(connObjs[loc.symbol], obj)
|
||
|
end
|
||
|
elseif obj.tag == "Tile" then
|
||
|
local url = obj.getCustomObject().image
|
||
|
if url == CONNECTOR_URL_1 or url == CONNECTOR_URL_2 or url == CONNECTOR_URL_3 then
|
||
|
obj.destruct()
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
local lines = {}
|
||
|
for guid,obj in pairs(cardObjs) do
|
||
|
for j,conn in ipairs(getLocationInfo(obj).connections) do
|
||
|
if connObjs[conn] ~= nil then
|
||
|
for k,target in ipairs(connObjs[conn]) do
|
||
|
drawConnection(obj, target, lines)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
Global.setVectorLines(lines)
|
||
|
end
|
||
|
|
||
|
function isOnTop(card)
|
||
|
local pos = card.getPosition()
|
||
|
local objs = Physics.cast({
|
||
|
origin = pos,
|
||
|
direction = { x=0, y=1, z=0 },
|
||
|
type = 2,
|
||
|
size = { 1, 1, 1 },
|
||
|
orientation = card.getRotation()
|
||
|
})
|
||
|
|
||
|
for i,v in ipairs(objs) do
|
||
|
local obj = v.hit_object
|
||
|
if obj.tag == "Card" and obj.getPosition().y > pos.y then
|
||
|
return false
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
function drawConnection(origin, target, lines)
|
||
|
local originPos = origin.getPosition()
|
||
|
local targetPos = target.getPosition()
|
||
|
table.insert(lines, { points={ originPos, targetPos } })
|
||
|
|
||
|
if not connectsTo(target, origin) then
|
||
|
-- draw one-way arrow
|
||
|
local midpoint = originPos:lerp(targetPos, 0.5)
|
||
|
local direction = (targetPos - originPos):normalize()
|
||
|
local arrow1 = direction:copy():rotateOver('y', 45)
|
||
|
local arrow2 = direction:copy():rotateOver('y', -45)
|
||
|
table.insert(lines, { points={ midpoint-arrow1, midpoint, midpoint-arrow2 } })
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function connectsTo(origin, target)
|
||
|
local symbol = getLocationInfo(target).symbol
|
||
|
for i,conn in ipairs(getLocationInfo(origin).connections) do
|
||
|
if conn == symbol then return true end
|
||
|
end
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
function getLocationInfo(obj)
|
||
|
if obj.tag == "Card" then
|
||
|
return guidMap[obj.getGUID()]
|
||
|
else
|
||
|
local cards = obj.getObjects()
|
||
|
return guidMap[cards[#cards].guid]
|
||
|
end
|
||
|
end
|