94 lines
2.1 KiB
Plaintext
94 lines
2.1 KiB
Plaintext
-- @include /koptilnya/libs/table.txt
|
|
-- @shared
|
|
|
|
require("/koptilnya/libs/table.txt")
|
|
|
|
if not PERMA then
|
|
PERMA = {}
|
|
|
|
if CLIENT then
|
|
PERMA.list = {}
|
|
end
|
|
end
|
|
|
|
if CLIENT then
|
|
function PERMA.add(permission)
|
|
if not table.hasValue(PERMA.list, permission) then
|
|
table.insert(PERMA.list, permission)
|
|
end
|
|
end
|
|
|
|
function PERMA.addTable(permissions)
|
|
for _, v in ipairs(permissions) do
|
|
PERMA.add(v)
|
|
end
|
|
end
|
|
|
|
function PERMA.remove(permission)
|
|
table.removeByValue(PERMA.list, permission)
|
|
end
|
|
|
|
function PERMA.removeTable(permissions)
|
|
for _, v in ipairs(permissions) do
|
|
PERMA.remove(v)
|
|
end
|
|
end
|
|
|
|
function PERMA.clear()
|
|
PERMA.list = {}
|
|
end
|
|
|
|
function PERMA.check(permission)
|
|
return hasPermission(permission)
|
|
end
|
|
|
|
function PERMA.checkTable(permissions)
|
|
local prohibited = table.filter(PERMA.list, function(permission)
|
|
return not hasPermission(permission)
|
|
end)
|
|
|
|
return #prohibited == 0, prohibited
|
|
end
|
|
|
|
function PERMA:build(description)
|
|
description = description or ""
|
|
|
|
local hasAccess, prohibited = PERMA.checkTable(PERMA.list)
|
|
|
|
local function onPermissionsGained()
|
|
PERMA:onPermissionsGained()
|
|
|
|
net.start("onPermissionsGained")
|
|
net.send()
|
|
|
|
hook.remove("permissionrequest", "PERMA_permissionrequest")
|
|
end
|
|
|
|
if not hasAccess then
|
|
setupPermissionRequest(prohibited, description, true)
|
|
|
|
hook.add("permissionrequest", "PERMA_permissionrequest", function()
|
|
if permissionRequestSatisfied() then
|
|
onPermissionsGained()
|
|
end
|
|
end)
|
|
else
|
|
onPermissionsGained()
|
|
end
|
|
end
|
|
|
|
-- STUB
|
|
|
|
function PERMA:onPermissionsGained()
|
|
end
|
|
else
|
|
net.receive("onPermissionsGained", function(len, ply)
|
|
PERMA:onPermissionsGained(ply)
|
|
end)
|
|
|
|
-- STUB
|
|
|
|
function PERMA:onPermissionsGained(ply)
|
|
end
|
|
end
|