ah_sce_unpacked/unpacked/Custom_Token Instruction Generator 240522.ttslua

194 lines
5.9 KiB
Plaintext
Raw Normal View History

2024-02-04 10:51:51 -05:00
-- 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")
function onLoad()
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)
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
function generate(_, playerColor)
local idList = {}
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
if obj.type == "Card" then
local cardMetadata = JSON.decode(obj.getGMNotes())
if cardMetadata then
local id = getIdFromData(cardMetadata)
if id then
table.insert(idList, id)
end
end
elseif obj.type == "Deck" then
for _, deepObj in ipairs(obj.getData().ContainedObjects) do
local cardMetadata = JSON.decode(deepObj.GMNotes)
if cardMetadata then
local id = getIdFromData(cardMetadata)
if id then
table.insert(idList, id)
end
end
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
-- construct the string
local description = "++SCED import instructions++\n- add: "
for _, id in ipairs(idList) do
description = description .. id .. ", "
end
-- remove last delimiter (last two characters)
description = description:sub(1, -3)
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 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 Table Global position
---@param rot Table 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)
if filter then filter = 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 filter(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")