Last active
August 13, 2017 10:29
-
-
Save cauerego/8fb42f15c5719575643d9334fce04bbf to your computer and use it in GitHub Desktop.
tabletop kanagawa revised to work a bit better with the new tts version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guids = { | |
start_button = 'ef8989', | |
lesson_deck = '7c44e3', | |
starting_tile_bag = '931537', | |
zone_lessons_1 = 'd6b214', | |
zone_lessons_2 = '8bd9fb', | |
zone_lessons_3 = '72c9f5', | |
zone_column_1 = 'be1644', | |
zone_column_2 = '31425c', | |
zone_column_3 = 'a37574', | |
zone_column_4 = 'accef5', | |
zone_mat_6c5ef8 = '7b0067', -- bottom right | |
zone_mat_d5c0a4 = 'b58660', -- bottom left | |
zone_mat_bde7bd = 'b6a062', -- top right | |
zone_mat_a18219 = '346685', -- top left | |
} | |
starting_positions = { | |
Teal = {40, 1.4, 27.3}, | |
Yellow = {-11.7, 1.4, 26.4}, | |
White = {12.6, 1.4, -24.7}, | |
Pink = {-35.8, 1.4, -24.6}, | |
} | |
lesson_positions = { | |
row1 = { | |
{-6.2, 1.6, 2.4, true}, | |
{-2, 1.6, 2.4, true}, | |
{2, 1.7, 2.4 , false}, | |
{6.1, 1.5, 2.4, true}, | |
}, | |
row2 = { | |
{-6.2, 1.4, -1.3, true}, | |
{-2, 1.6, -1.3, false}, | |
{2, 1.7, -1.3, true}, | |
{6.1, 1.5, -1.3, true}, | |
}, | |
row3 = { | |
{-6.2, 1.6, -5.1, false}, | |
{-2, 1.6, -5.1, true}, | |
{2, 1.7, -5.1, true}, | |
{6.1, 1.5, -5.1, false}, | |
}, | |
} | |
function onload () | |
getObject('start_button').createButton({ | |
click_function = 'clickLearn', | |
label = 'Learn', | |
function_owner = nil, | |
position = { 0, 0.3, 0}, | |
rotation = {0, 180, 0}, | |
width = 1200, | |
height = 800, | |
font_size = 400 | |
}) | |
end | |
function clickLearn() | |
startLuaCoroutine(Global, 'learnLessons') | |
end | |
function learnLessons() | |
local lessons = getObject('lesson_deck') | |
if lessons.getQuantity() == 72 then | |
-- Intitial setup | |
local bag = getObject('starting_tile_bag') | |
local tile | |
bag.shuffle() | |
wait(0.1) | |
bag.shuffle() | |
bigShuffle(lessons) | |
-- deal starting tiles | |
for _, colour in pairs(getAllowedSeatedPlayers()) do | |
tile = bag.takeObject({ | |
position = starting_positions[colour], | |
rotation = {0, (colour == 'Teal' or colour == 'Yellow') and 0 or 180, 0} | |
}) | |
tile.lock() | |
end | |
wait(0.5) | |
if bag.getQuantity() == 0 then | |
bag.destruct() | |
end | |
end | |
learnNextRow() | |
return 1 | |
end | |
function learnNextRow() | |
for row_number = 1, 3, 1 do | |
if #findElementsInZone('Card', 'lessons_' .. row_number) == 0 then | |
dealLessonsToRow(row_number) | |
break | |
end | |
end | |
end | |
function dealLessonsToRow(row_number) | |
local lessons = getObject('lesson_deck') | |
local positions = lesson_positions['row' .. row_number] | |
for i in ipairs(getAllowedSeatedPlayers()) do | |
if row_number == 1 or #findElementsInZone('Card', 'column_' .. i) > 0 then | |
lessons.takeObject({ | |
position = positions[i], | |
flip = positions[i][4], | |
}) | |
end | |
end | |
end | |
function addLessonToBoard(card, board) | |
local lesson_counts = countLessonsOnBoard(board) | |
local card_position = board.getPosition() | |
local card_rotation = board.getRotation() | |
local type = determineCardTypeByRotation(card, board) | |
local x_offset_per_lesson | |
lesson_counts[type] = lesson_counts[type] + 1 | |
-- A quick hack for top and bottom player mats | |
local orientation_factor = -1 | |
if card_rotation.y > 90 and card_rotation.y < 270 then | |
orientation_factor = 1 | |
end | |
if type == 'print' then | |
-- "print" row | |
card_position.z = card_position.z + (1.65 * orientation_factor) | |
card_rotation.z = 356 | |
x_offset_per_lesson = 2 | |
else | |
-- "studio" row | |
card_position.z = card_position.z - (1.65 * orientation_factor) | |
card_rotation.z = 5 | |
card_rotation.y = card_rotation.y + 180 | |
x_offset_per_lesson = 1 | |
end | |
card_position.x = card_position.x | |
- (13 * orientation_factor) | |
+ (lesson_counts[type] * x_offset_per_lesson * orientation_factor) | |
card_position.y = card_position.y + 0.2 | |
card.lock() | |
card.setRotation(card_rotation) | |
card.setPosition(card_position) | |
end | |
function onBoardCollision(table) | |
local card = table.object | |
local guid = card.getGUID() | |
-- as to adjust cards layed on board's right most part only | |
local cardPositionOnBoard_x = card.getPosition().x - table.board.getPosition().x | |
if card.tag != 'Card' or cardPositionOnBoard_x < 10 then | |
return | |
end | |
addLessonToBoard(card, table.board) | |
end | |
function determineCardTypeByRotation(card, board) | |
local rotation_difference = card.getRotation().y - board.getRotation().y | |
rotation_difference = math.abs(math.abs((rotation_difference + 180) % 360) - 180) | |
if rotation_difference < 90 then | |
return 'print' | |
else | |
return 'studio' | |
end | |
end | |
function countLessonsOnBoard(board) | |
local lessons = findElementsInZone('Card', 'mat_' .. board.getGUID()) | |
local lesson_counts = { | |
print = 0, | |
studio = 0, | |
} | |
local lesson_type | |
for _, lesson in pairs(lessons) do | |
if lesson.getLock() then | |
lesson_type = determineCardTypeByRotation(lesson, board) | |
lesson_counts[lesson_type] = lesson_counts[lesson_type] + 1 | |
end | |
end | |
return lesson_counts | |
end | |
function bigShuffle(deck) | |
for j = 1,48 do | |
if j % 2 then | |
deck.shuffle() | |
else | |
deck.cut() | |
end | |
coroutine.yield(0) | |
coroutine.yield(0) | |
end | |
end | |
function findObjectInZone(tag, zoneName) | |
local found = findElementsInZone(tag, zoneName) | |
if #found == 1 then | |
return found[1] | |
else | |
return nil | |
end | |
end | |
function findElementsInZone(tag, zoneName) | |
local zone = getObject('zone_' .. zoneName) | |
if not zone then | |
displayError('Zone not found: ' .. zoneName) | |
end | |
local objectsInZone = zone.getObjects() | |
local found = {} | |
for _, object in ipairs(objectsInZone) do | |
if object.tag == tag then | |
table.insert(found, object) | |
end | |
end | |
return found | |
end | |
function getObject(name) | |
local guid = guids[name] | |
if not guid then | |
displayError('Error finding "'.. name ..'"') | |
return nil | |
end | |
return getObjectFromGUID(guid) | |
end | |
function wait(time) | |
if not time then | |
time = 0.1 | |
end | |
local start = os.time() | |
repeat coroutine.yield(0) until os.time() > start + time | |
end | |
function getPlayerCount() | |
local players = getAllowedSeatedPlayers() | |
return #players | |
end | |
function getAllowedSeatedPlayers() | |
-- return {'White', 'Pink', 'Yellow', 'Teal'} | |
return getSeatedPlayers() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment