updated drop down menu
This commit is contained in:
parent
af5ce39132
commit
b7cde57aba
@ -1,32 +1,31 @@
|
|||||||
-- this script is shared between the lvl 0 and lvl 3 versions of Scroll of Secrets
|
|
||||||
local mythosAreaApi = require("core/MythosAreaApi")
|
local mythosAreaApi = require("core/MythosAreaApi")
|
||||||
local playmatApi = require("playermat/PlaymatApi")
|
local playmatApi = require("playermat/PlaymatApi")
|
||||||
|
|
||||||
-- get class via metadata and create context menu accordingly
|
|
||||||
function onLoad()
|
function onLoad()
|
||||||
|
-- get class via metadata and proceed menu accordingly:
|
||||||
|
-- lvl 0: draw 1 card from the bottom
|
||||||
|
-- seeker lvl 3: draw 3 cards from the bottom
|
||||||
|
local buttonLabel = "Draw bottom card"
|
||||||
|
local amount = 1
|
||||||
local notes = JSON.decode(self.getGMNotes())
|
local notes = JSON.decode(self.getGMNotes())
|
||||||
if notes then
|
if notes.id == "05188" or notes.id == "05188-t" then
|
||||||
createContextMenu(notes.id)
|
|
||||||
else
|
|
||||||
print("Missing metadata for Scroll of Secrets!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function createContextMenu(id)
|
|
||||||
if id == "05116" or id == "05116-t" then
|
|
||||||
-- lvl 0: draw 1 card from the bottom
|
|
||||||
self.addContextMenuItem("Draw bottom card", function(playerColor) contextFunc(playerColor, 1) end)
|
|
||||||
elseif id == "05188" or id == "05188-t" then
|
|
||||||
-- seeker lvl 3: draw 3 cards from the bottom
|
|
||||||
self.addContextMenuItem("Draw bottom card(s)", function(playerColor) contextFunc(playerColor, 3) end)
|
|
||||||
elseif id == "05189" or id == "05189-t" then
|
|
||||||
-- mystic lvl 3: draw 1 card from the bottom
|
-- mystic lvl 3: draw 1 card from the bottom
|
||||||
self.addContextMenuItem("Draw bottom card", function(playerColor) contextFunc(playerColor, 1) end)
|
buttonLabel = buttonLabel .. "(s)"
|
||||||
|
amount = 3
|
||||||
end
|
end
|
||||||
|
self.addContextMenuItem(buttonLabel, function(playerColor) contextFunc(playerColor, amount) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function contextFunc(playerColor, amount)
|
function contextFunc(playerColor, amount)
|
||||||
local options = { "Encounter Deck" }
|
deckData = {}
|
||||||
|
local options = {}
|
||||||
|
|
||||||
|
-- check for encounter deck
|
||||||
|
local encounterDeck = mythosAreaApi.getEncounterDeck()
|
||||||
|
if encounterDeck then
|
||||||
|
table.insert(options, "Encounter Deck")
|
||||||
|
deckData["Encounter Deck"] = { draw = encounterDeck }
|
||||||
|
end
|
||||||
|
|
||||||
-- check for players with a deck and only display them as option
|
-- check for players with a deck and only display them as option
|
||||||
for _, color in ipairs(Player.getAvailableColors()) do
|
for _, color in ipairs(Player.getAvailableColors()) do
|
||||||
@ -34,28 +33,37 @@ function contextFunc(playerColor, amount)
|
|||||||
local deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
|
local deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
|
||||||
|
|
||||||
if deckAreaObjects.draw or deckAreaObjects.topCard then
|
if deckAreaObjects.draw or deckAreaObjects.topCard then
|
||||||
table.insert(options, color)
|
local playerName = Player[color].steam_name
|
||||||
|
local invName = playmatApi.getInvestigatorName(matColor)
|
||||||
|
|
||||||
|
-- figure out a proper display name for the drop down menu
|
||||||
|
local displayName
|
||||||
|
if playerName then
|
||||||
|
displayName = playerName
|
||||||
|
elseif invName ~= "" then
|
||||||
|
displayName = invName
|
||||||
|
else
|
||||||
|
displayName = color
|
||||||
|
end
|
||||||
|
|
||||||
|
-- recreate table in this script to have access
|
||||||
|
deckData[displayName] = {
|
||||||
|
draw = deckAreaObjects.draw,
|
||||||
|
topCard = deckAreaObjects.topCard
|
||||||
|
}
|
||||||
|
table.insert(options, displayName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- show the target selection dialog
|
-- show the target selection dialog
|
||||||
Player[playerColor].showOptionsDialog("Select target deck", options, _, function(owner) drawCardsFromBottom(playerColor, owner, amount) end)
|
Player[playerColor].showOptionsDialog("Select target deck", options, _,
|
||||||
|
function(owner) drawCardsFromBottom(playerColor, owner, amount) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawCardsFromBottom(playerColor, owner, amount)
|
function drawCardsFromBottom(playerColor, owner, amount)
|
||||||
-- variable initialization
|
local deckAreaObjects = deckData[owner]
|
||||||
local deck = nil
|
local deck = deckAreaObjects.draw
|
||||||
local deckSize = 1
|
local deckSize = 1
|
||||||
local deckAreaObjects = {}
|
|
||||||
|
|
||||||
-- get the respective deck
|
|
||||||
if owner == "Encounter Deck" then
|
|
||||||
deck = mythosAreaApi.getEncounterDeck()
|
|
||||||
else
|
|
||||||
local matColor = playmatApi.getMatColor(owner)
|
|
||||||
deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
|
|
||||||
deck = deckAreaObjects.draw
|
|
||||||
end
|
|
||||||
|
|
||||||
-- error handling
|
-- error handling
|
||||||
if not deck then
|
if not deck then
|
||||||
|
@ -2,6 +2,7 @@ do
|
|||||||
local PlaymatApi = {}
|
local PlaymatApi = {}
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||||
local searchLib = require("util/SearchLib")
|
local searchLib = require("util/SearchLib")
|
||||||
|
local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 }
|
||||||
|
|
||||||
-- Convenience function to look up a mat's object by color, or get all mats.
|
-- Convenience function to look up a mat's object by color, or get all mats.
|
||||||
---@param matColor string Color of the playmat - White, Orange, Green, Red or All
|
---@param matColor string Color of the playmat - White, Orange, Green, Red or All
|
||||||
@ -274,7 +275,6 @@ do
|
|||||||
|
|
||||||
-- Returns a list of mat colors that have an investigator placed
|
-- Returns a list of mat colors that have an investigator placed
|
||||||
PlaymatApi.getUsedMatColors = function()
|
PlaymatApi.getUsedMatColors = function()
|
||||||
local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 }
|
|
||||||
local usedColors = {}
|
local usedColors = {}
|
||||||
for matColor, mat in pairs(getMatForColor("All")) do
|
for matColor, mat in pairs(getMatForColor("All")) do
|
||||||
local searchPos = mat.positionToWorld(localInvestigatorPosition)
|
local searchPos = mat.positionToWorld(localInvestigatorPosition)
|
||||||
@ -286,6 +286,19 @@ do
|
|||||||
return usedColors
|
return usedColors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns investigator name
|
||||||
|
---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
|
||||||
|
PlaymatApi.getInvestigatorName = function(matColor)
|
||||||
|
for _, mat in pairs(getMatForColor(matColor)) do
|
||||||
|
local searchPos = mat.positionToWorld(localInvestigatorPosition)
|
||||||
|
local searchResult = searchLib.atPosition(searchPos, "isCardOrDeck")
|
||||||
|
if #searchResult == 1 then
|
||||||
|
return searchResult[1].getName()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
-- Resets the specified skill tracker to "1, 1, 1, 1"
|
-- Resets the specified skill tracker to "1, 1, 1, 1"
|
||||||
---@param matColor string Color of the playmat - White, Orange, Green, Red or All
|
---@param matColor string Color of the playmat - White, Orange, Green, Red or All
|
||||||
PlaymatApi.resetSkillTracker = function(matColor)
|
PlaymatApi.resetSkillTracker = function(matColor)
|
||||||
|
Loading…
Reference in New Issue
Block a user