170 lines
3.7 KiB
Plaintext
170 lines
3.7 KiB
Plaintext
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by Whimsical.
|
|
--- DateTime: 2021-08-05 6:14 p.m.
|
|
---
|
|
|
|
|
|
local tags = {
|
|
bag = "chaosBag",
|
|
provider = "token_list_provider",
|
|
tokens = "token_image_provider"
|
|
}
|
|
|
|
---@class ChaosToken
|
|
---@field name string
|
|
---@field image string
|
|
local _ = {}
|
|
|
|
---@type table<string|number, ChaosToken>
|
|
local sources
|
|
|
|
---@type table<string, any[]>
|
|
local tokens
|
|
|
|
---@param source TTSObject
|
|
local LoadSource = function (source)
|
|
tokens = source:getTable("chaos_tokens")
|
|
end
|
|
|
|
---@param token ChaosToken
|
|
---@param position Vector
|
|
---@param chaosBag TTSObject
|
|
---@return number
|
|
local SpawnToken = function(token, position, chaosBag)
|
|
spawnObject {
|
|
type = "Custom_Tile",
|
|
position = position,
|
|
scale = { 0.81, 1.0, 0.81 },
|
|
rotation = { 0, 270, 0 },
|
|
---@param object TTSObject
|
|
callback_function = function(object, _, _)
|
|
object:setName(token.name)
|
|
chaosBag:putObject(object)
|
|
end
|
|
}:setCustomObject {
|
|
image = token.image,
|
|
type = 2,
|
|
thickness = 0.1
|
|
}
|
|
end
|
|
|
|
---@param chaosBag TTSObject
|
|
local emptyBag = function(chaosBag)
|
|
local object = chaosBag:getObjects()
|
|
local pos = self:getPosition()
|
|
pos.y = pos.y+1
|
|
|
|
for _, object in ipairs(object) do
|
|
chaosBag:takeObject {
|
|
guid = object.guid,
|
|
position = pos,
|
|
---@param item TTSObject
|
|
callback_function = function (item) item:destruct() end
|
|
}
|
|
end
|
|
end
|
|
|
|
---@param difficulty string
|
|
local clickFun= function (difficulty)
|
|
local chaosBag = getObjectsWithTag(tags.bag)[1]
|
|
|
|
emptyBag(chaosBag)
|
|
|
|
local loading = tokens[difficulty]
|
|
local pos = self:getPosition()
|
|
|
|
for _, token_id in ipairs(loading) do
|
|
if type(token_id)=="string" then token_id = token_id:lower() end
|
|
|
|
local token = sources[token_id]
|
|
|
|
if (token==nil) then
|
|
error("Could not find token \"" .. token_id .. "\".")
|
|
return
|
|
end
|
|
|
|
SpawnToken(token, pos, chaosBag)
|
|
end
|
|
end
|
|
|
|
|
|
---@param difficulty string
|
|
local MakeClickFun = function(difficulty)
|
|
return function ()
|
|
clickFun(difficulty)
|
|
end
|
|
end
|
|
|
|
---@param label string
|
|
---@param z_offset number|nil
|
|
local makeButton = function(label , z_offset)
|
|
z_offset = z_offset or -0.15
|
|
|
|
_G[label:lower() .. "Click"] = MakeClickFun(label)
|
|
|
|
self:createButton({
|
|
label = label,
|
|
function_owner = self,
|
|
click_function = label:lower() .. "Click",
|
|
position = {0, 0.1, z_offset},
|
|
rotation = {0, 0, 0},
|
|
scale = {0.47, 1, 0.47},
|
|
height = 200,
|
|
width = 1150,
|
|
font_size = 100,
|
|
color = {0.87, 0.8, 0.70},
|
|
font_color = {0, 0, 0}
|
|
})
|
|
return z_offset + 0.20
|
|
end
|
|
|
|
---@param source TTSObject
|
|
local CreateButtons= function(source)
|
|
self:clearButtons()
|
|
|
|
local z_offset
|
|
for difficulty,_ in pairs(tokens) do
|
|
z_offset = makeButton(difficulty, z_offset)
|
|
end
|
|
end
|
|
|
|
|
|
function LoadTokens()
|
|
---@type TTSObject[]
|
|
local image_sources = getObjectsWithTag(tags.tokens)
|
|
|
|
if (#image_sources<=0) then
|
|
error("Cannot find images_sources")
|
|
return
|
|
end
|
|
|
|
sources = image_sources[1]:getTable("sources")
|
|
|
|
if (tokens~=nil) then CreateButtons() return end
|
|
|
|
local source = getObjectsWithTag(tags.provider)
|
|
|
|
if (#source<=0) then return end
|
|
|
|
LoadSource(source[1])
|
|
|
|
CreateButtons()
|
|
end
|
|
|
|
function onload()
|
|
Timer.create {
|
|
identifier = self:getGUID(),
|
|
function_name = "LoadTokens"
|
|
}
|
|
end
|
|
|
|
---@param provider TTSObject
|
|
function onObjectSpawn(provider)
|
|
if (not provider:hasTag(tags.provider)) then return end
|
|
|
|
LoadSource(provider)
|
|
|
|
CreateButtons()
|
|
end
|