mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update
This commit is contained in:
42
druid/druid.script
Normal file
42
druid/druid.script
Normal file
@@ -0,0 +1,42 @@
|
||||
-- Place this script nearby with the gui component to able make requests
|
||||
-- To the go namespace from GUI with events systems (cross context)
|
||||
|
||||
local defer = require("event.defer")
|
||||
|
||||
---Usage: defer.push("druid.get_atlas_path", {
|
||||
--- texture_name = gui.get_texture(self.node),
|
||||
--- sender = msg.url(),
|
||||
---}, callback, [context])
|
||||
---Pass texture name to get atlas info and sender url to check if the request is valid
|
||||
local MESSAGE_GET_ATLAS_PATH = "druid.get_atlas_path"
|
||||
|
||||
---@class druid.get_atlas_path_request
|
||||
---@field texture_name hash
|
||||
---@field sender hash
|
||||
|
||||
---@param request druid.get_atlas_path_request
|
||||
---@return string?
|
||||
local function get_atlas_path(self, request)
|
||||
local my_url = msg.url()
|
||||
my_url.fragment = nil
|
||||
|
||||
local copy_url = msg.url(request.sender)
|
||||
copy_url.fragment = nil
|
||||
|
||||
-- This check should works well
|
||||
if my_url ~= copy_url then
|
||||
return nil
|
||||
end
|
||||
|
||||
return go.get(request.sender, "textures", { key = request.texture_name })
|
||||
end
|
||||
|
||||
|
||||
function init(self)
|
||||
defer.subscribe(MESSAGE_GET_ATLAS_PATH, get_atlas_path, self)
|
||||
end
|
||||
|
||||
|
||||
function final(self)
|
||||
defer.unsubscribe(MESSAGE_GET_ATLAS_PATH, get_atlas_path, self)
|
||||
end
|
Reference in New Issue
Block a user