performance improvement
This commit is contained in:
parent
cbc8425f56
commit
dea47d6b36
@ -224,12 +224,12 @@ function canTouchChaosTokens()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- called by playermats (by the "Draw chaos token" button)
|
-- called by playermats (by the "Draw chaos token" button)
|
||||||
function drawChaosToken(params)
|
function drawChaosToken(param)
|
||||||
if not canTouchChaosTokens() then return end
|
if not canTouchChaosTokens() then return end
|
||||||
|
|
||||||
local mat = params[1]
|
local mat = param[1]
|
||||||
local tokenOffset = params[2]
|
local tokenOffset = param[2]
|
||||||
local isRightClick = params[3]
|
local isRightClick = param[3]
|
||||||
chaosbag = findChaosBag()
|
chaosbag = findChaosBag()
|
||||||
|
|
||||||
-- return token(s) on other playmat first
|
-- return token(s) on other playmat first
|
||||||
@ -275,9 +275,9 @@ end
|
|||||||
|
|
||||||
-- DEPRECATED. Use TokenManager instead.
|
-- DEPRECATED. Use TokenManager instead.
|
||||||
-- Spawns a single token.
|
-- Spawns a single token.
|
||||||
---@param params Table. Array with arguments to the method. 1 = position, 2 = type, 3 = rotation
|
---@param param Table. Array with arguments to the method. 1 = position, 2 = type, 3 = rotation
|
||||||
function spawnToken(params)
|
function spawnToken(param)
|
||||||
return tokenManager.spawnToken(params[1], params[2], params[3])
|
return tokenManager.spawnToken(param[1], param[2], param[3])
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
@ -632,10 +632,18 @@ function onClick_tab(player, contentToShow)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- click function for the items in the download window
|
-- click function for the items in the download window
|
||||||
function onClick_select(player, params)
|
function onClick_select(player, param)
|
||||||
params = JSON.decode(urldecode(params))
|
local parsed = parseKey(param) or {}
|
||||||
local url = SOURCE_REPO .. '/' .. params.url
|
local contentToShow = parsed.contentToShow
|
||||||
requestObj = WebRequest.get(url, function (request) complete_obj_download(request, params) end )
|
local index = parsed.index
|
||||||
|
if not contentToShow or not index then return end
|
||||||
|
startContentDownload(library[contentToShow][index])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- download requested content
|
||||||
|
function startContentDownload(param)
|
||||||
|
local url = SOURCE_REPO .. '/' .. param.url
|
||||||
|
requestObj = WebRequest.get(url, function (request) complete_obj_download(request, param) end )
|
||||||
startLuaCoroutine(Global, 'downloadCoroutine')
|
startLuaCoroutine(Global, 'downloadCoroutine')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -687,17 +695,9 @@ function onMouseEnter_item(player, param)
|
|||||||
UI.hide("previewWindow")
|
UI.hide("previewWindow")
|
||||||
|
|
||||||
-- parse parameters
|
-- parse parameters
|
||||||
local contentToShow, index
|
local parsed = parseKey(param) or {}
|
||||||
for str in string.gmatch(param, "([^_]+)") do
|
local contentToShow = parsed.contentToShow
|
||||||
if not contentToShow then
|
local index = parsed.index
|
||||||
-- grab the first part to know the content type
|
|
||||||
contentToShow = str
|
|
||||||
else
|
|
||||||
-- get the index
|
|
||||||
index = tonumber(str)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not contentToShow or not index then return end
|
if not contentToShow or not index then return end
|
||||||
|
|
||||||
@ -772,6 +772,25 @@ function onMouseEnter_item(player, param)
|
|||||||
UI.show("previewWindow")
|
UI.show("previewWindow")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- parses the identification key (contentToShow_index) and returns the result
|
||||||
|
function parseKey(unparsedStr)
|
||||||
|
local contentToShow, index
|
||||||
|
for str in string.gmatch(unparsedStr, "([^_]+)") do
|
||||||
|
if not contentToShow then
|
||||||
|
-- grab the first part to know the content type
|
||||||
|
contentToShow = str
|
||||||
|
else
|
||||||
|
-- get the index
|
||||||
|
index = tonumber(str)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
contentToShow = contentToShow,
|
||||||
|
index = index
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
-- formats the json response from the webrequest into a key-value lua table
|
-- formats the json response from the webrequest into a key-value lua table
|
||||||
-- strips the prefix from the community content items
|
-- strips the prefix from the community content items
|
||||||
function formatLibrary(json_response)
|
function formatLibrary(json_response)
|
||||||
@ -821,8 +840,7 @@ function update_list(contentToShow)
|
|||||||
fanmadePlayerCards = "Fan-Made Player Cards",
|
fanmadePlayerCards = "Fan-Made Player Cards",
|
||||||
fanmadeScenarios = "Fan-Made Scenarios"
|
fanmadeScenarios = "Fan-Made Scenarios"
|
||||||
}
|
}
|
||||||
local titleText = find_tag_with_id(ui, "title")
|
UI.setValue("previewTitle", cleanName[contentToShow])
|
||||||
titleText.value = "Downloable Content: " .. cleanName[contentToShow]
|
|
||||||
|
|
||||||
-- addition of list items according to library file
|
-- addition of list items according to library file
|
||||||
local update_height = find_tag_with_id(ui, 'ui_update_height')
|
local update_height = find_tag_with_id(ui, 'ui_update_height')
|
||||||
@ -830,13 +848,14 @@ function update_list(contentToShow)
|
|||||||
update_children.children = {}
|
update_children.children = {}
|
||||||
|
|
||||||
for i, v in ipairs(library[contentToShow]) do
|
for i, v in ipairs(library[contentToShow]) do
|
||||||
|
local key = contentToShow .. "_" .. i
|
||||||
table.insert(update_children.children,
|
table.insert(update_children.children,
|
||||||
{
|
{
|
||||||
tag = 'Text',
|
tag = 'Text',
|
||||||
value = v.name,
|
value = v.name,
|
||||||
attributes = {
|
attributes = {
|
||||||
onClick = 'onClick_select(' .. urlencode(JSON.encode(v)) .. ')',
|
onClick = 'onClick_select(' .. key .. ')',
|
||||||
onMouseEnter = "onMouseEnter_item(" .. contentToShow .. "_" .. i .. ")",
|
onMouseEnter = "onMouseEnter_item(" .. key .. ")",
|
||||||
alignment = 'MiddleLeft'
|
alignment = 'MiddleLeft'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -848,7 +867,7 @@ end
|
|||||||
|
|
||||||
-- called after the webrequest of downloading an item
|
-- called after the webrequest of downloading an item
|
||||||
-- deletes the placeholder and spawns the downloaded item
|
-- deletes the placeholder and spawns the downloaded item
|
||||||
function complete_obj_download(request, params)
|
function complete_obj_download(request, param)
|
||||||
assert(request.is_done)
|
assert(request.is_done)
|
||||||
if request.is_error or request.response_code ~= 200 then
|
if request.is_error or request.response_code ~= 200 then
|
||||||
print('error: ' .. request.error)
|
print('error: ' .. request.error)
|
||||||
@ -856,8 +875,8 @@ function complete_obj_download(request, params)
|
|||||||
if pcall(function()
|
if pcall(function()
|
||||||
local replacedObject
|
local replacedObject
|
||||||
pcall(function()
|
pcall(function()
|
||||||
if params.replace then
|
if param.replace then
|
||||||
replacedObject = getObjectFromGUID(params.replace)
|
replacedObject = getObjectFromGUID(param.replace)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if replacedObject then
|
if replacedObject then
|
||||||
@ -886,9 +905,9 @@ function complete_obj_download(request, params)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- the download button on the placeholder objects calls this to directly initiate a download
|
-- the download button on the placeholder objects calls this to directly initiate a download
|
||||||
---@param params Table contains url and guid of replacement object, which happens to match what onClick_select wants
|
---@param param Table contains url and guid of replacement object, which happens to match what onClick_select wants
|
||||||
function placeholder_download(params)
|
function placeholder_download(param)
|
||||||
onClick_select(nil, JSON.encode(params))
|
startContentDownload(param)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- downloading of the library file
|
-- downloading of the library file
|
||||||
@ -922,18 +941,6 @@ function find_tag_with_id(ui, id)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function urlencode(str)
|
|
||||||
local str = string.gsub(str, "([^A-Za-z0-9-_.~])",
|
|
||||||
function (c) return string.format("%%%02X", string.byte(c)) end)
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
function urldecode(str)
|
|
||||||
local str = string.gsub(str, "%%(%x%x)",
|
|
||||||
function (h) return string.char(tonumber(h, 16)) end)
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- Option Panel related functionality
|
-- Option Panel related functionality
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user