ah_sce_unpacked/unpacked/Custom_Token Instruction Ge...

210 lines
6.3 KiB
Plaintext

-- Bundled by luabundle {"version":"1.6.0"}
local __bundle_require, __bundle_loaded, __bundle_register, __bundle_modules = (function(superRequire)
local loadingPlaceholder = {[{}] = true}
local register
local modules = {}
local require
local loaded = {}
register = function(name, body)
if not modules[name] then
modules[name] = body
end
end
require = function(name)
local loadedModule = loaded[name]
if loadedModule then
if loadedModule == loadingPlaceholder then
return nil
end
else
if not modules[name] then
if not superRequire then
local identifier = type(name) == 'string' and '\"' .. name .. '\"' or tostring(name)
error('Tried to require ' .. identifier .. ', but no such module has been registered')
else
return superRequire(name)
end
end
loaded[name] = loadingPlaceholder
loadedModule = modules[name](require, loaded, register, modules)
loaded[name] = loadedModule
end
return loadedModule
end
return require, loaded, register, modules
end)(nil)
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
require("arkhamdb/InstructionGenerator")
end)
__bundle_register("arkhamdb/InstructionGenerator", function(require, _LOADED, __bundle_register, __bundle_modules)
local searchLib = require("util/SearchLib")
local idList = {}
function onLoad()
-- "generate" button
local buttonParameters = {}
buttonParameters.function_owner = self
buttonParameters.height = 200
buttonParameters.width = 1200
buttonParameters.font_size = 75
buttonParameters.click_function = "generate"
buttonParameters.label = "Generate instructions!"
buttonParameters.position = { 0, 0.06, 1.55 }
self.createButton(buttonParameters)
-- "output" text field
local inputParameters = {}
inputParameters.label = "Click button above"
inputParameters.input_function = "none"
inputParameters.function_owner = self
inputParameters.position = { 0, 0.05, 1.95 }
inputParameters.width = 1200
inputParameters.height = 130
inputParameters.font_size = 107
self.createInput(inputParameters)
end
-- generates a string for the ArkhamDB deck notes that will instruct the deck import to add the specified cards
function generate(_, playerColor)
idList = {}
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
if obj.type == "Card" then
processCard(obj.getGMNotes(), obj.getName(), playerColor)
elseif obj.type == "Deck" then
for _, deepObj in ipairs(obj.getData().ContainedObjects) do
processCard(deepObj.GMNotes, deepObj.Nickname, playerColor)
end
end
end
if #idList == 0 then
broadcastToColor("Didn't find any valid cards.", playerColor, "Red")
return
else
broadcastToColor("Created deck instruction for " .. #idList .. " card(s). Copy it from the input field.", playerColor, "Green")
end
-- sort the idList
table.sort(idList, sortById)
-- construct the string (new line for each instruction)
local description = "++SCED import instructions++"
for _, entry in ipairs(idList) do
description = description .. "\n- add: " .. entry.id .. " (**" .. entry.name .. "**)"
end
self.editInput({index = 0, value = description})
end
-- use the ZoopGuid as fallback if no id present
function getIdFromData(metadata)
if metadata.id then
return metadata.id
elseif metadata.TtsZoopGuid then
return metadata.TtsZoopGuid
end
end
function processCard(notes, name, playerColor)
local id = getIdFromData(JSON.decode(notes) or {})
if id then
table.insert(idList, {id = id, name = name})
else
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
end
end
function sortById(a, b)
local numA = tonumber(a.id)
local numB = tonumber(b.id)
if numA and numB then
return numA < numB
else
return a.name < b.name
end
end
function none() end
end)
__bundle_register("util/SearchLib", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local SearchLib = {}
local filterFunctions = {
isActionToken = function(x) return x.getDescription() == "Action Token" end,
isCard = function(x) return x.type == "Card" end,
isDeck = function(x) return x.type == "Deck" end,
isCardOrDeck = function(x) return x.type == "Card" or x.type == "Deck" end,
isClue = function(x) return x.memo == "clueDoom" and x.is_face_down == false end,
isTileOrToken = function(x) return x.type == "Tile" end
}
-- performs the actual search and returns a filtered list of object references
---@param pos tts__Vector Global position
---@param rot? tts__Vector Global rotation
---@param size table Size
---@param filter? string Name of the filter function
---@param direction? table Direction (positive is up)
---@param maxDistance? number Distance for the cast
local function returnSearchResult(pos, rot, size, filter, direction, maxDistance)
local filterFunc
if filter then
filterFunc = filterFunctions[filter]
end
local searchResult = Physics.cast({
origin = pos,
direction = direction or { 0, 1, 0 },
orientation = rot or { 0, 0, 0 },
type = 3,
size = size,
max_distance = maxDistance or 0
})
-- filtering the result
local objList = {}
for _, v in ipairs(searchResult) do
if not filter or filterFunc(v.hit_object) then
table.insert(objList, v.hit_object)
end
end
return objList
end
-- searches the specified area
SearchLib.inArea = function(pos, rot, size, filter)
return returnSearchResult(pos, rot, size, filter)
end
-- searches the area on an object
SearchLib.onObject = function(obj, filter)
pos = obj.getPosition()
size = obj.getBounds().size:setAt("y", 1)
return returnSearchResult(pos, _, size, filter)
end
-- searches the specified position (a single point)
SearchLib.atPosition = function(pos, filter)
size = { 0.1, 2, 0.1 }
return returnSearchResult(pos, _, size, filter)
end
-- searches below the specified position (downwards until y = 0)
SearchLib.belowPosition = function(pos, filter)
direction = { 0, -1, 0 }
maxDistance = pos.y
return returnSearchResult(pos, _, size, filter, direction, maxDistance)
end
return SearchLib
end
end)
return __bundle_require("__root")