mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
Enhance draggable module with environment checks
Updated UserInputService initialization and added checks for non-Roblox environments and GuiObject types.
This commit is contained in:
parent
870d07a469
commit
a94aee800f
1 changed files with 14 additions and 1 deletions
|
|
@ -1,11 +1,23 @@
|
||||||
local UserInputService = game:GetService("UserInputService") or nil
|
local UserInputService = game and game:GetService("UserInputService") or nil
|
||||||
|
|
||||||
|
-- Factory: inject Vide functions to avoid cyclic requires
|
||||||
return function(action, cleanup)
|
return function(action, cleanup)
|
||||||
return function(opts)
|
return function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local axis = opts.axis or "both" -- "x" | "y" | "both"
|
local axis = opts.axis or "both" -- "x" | "y" | "both"
|
||||||
|
|
||||||
return action(function(gui)
|
return action(function(gui)
|
||||||
|
-- Non-Roblox / unit-test environment: allow requiring this module without crashing.
|
||||||
|
-- Draggable behaviour is disabled when UserInputService is unavailable.
|
||||||
|
if not UserInputService then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Optional hardening: ignore non-GuiObject targets
|
||||||
|
if typeof(gui) ~= "Instance" or not gui:IsA("GuiObject") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local dragging = false
|
local dragging = false
|
||||||
local dragInput
|
local dragInput
|
||||||
local dragStart
|
local dragStart
|
||||||
|
|
@ -46,6 +58,7 @@ return function(action, cleanup)
|
||||||
if input.UserInputState == Enum.UserInputState.End then
|
if input.UserInputState == Enum.UserInputState.End then
|
||||||
dragging = false
|
dragging = false
|
||||||
if changedConn then changedConn:Disconnect() end
|
if changedConn then changedConn:Disconnect() end
|
||||||
|
|
||||||
if opts.onDragEnd then
|
if opts.onDragEnd then
|
||||||
opts.onDragEnd(gui.Position)
|
opts.onDragEnd(gui.Position)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue