This commit is contained in:
Nikita Kruglickiy
2021-11-29 22:17:45 +03:00
parent 8d7d399af5
commit b5c524705b
14 changed files with 325 additions and 256 deletions

View File

@@ -1,5 +1,6 @@
NULL_ENTITY = entity(0)
CURRENT_PLAYER = player()
OWNER = owner()
IS_ME = CURRENT_PLAYER == OWNER
TICK_INTERVAL = game.getTickInterval()
RAD_TO_RPM = 9.5493

93
koptilnya/libs/perma.txt Normal file
View File

@@ -0,0 +1,93 @@
-- @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

View File

@@ -1,60 +0,0 @@
-- @shared
local PERMISSIONS_BUILDER = PERMISSIONS_BUILDER or {}
if CLIENT then
PERMISSIONS_BUILDER.list = PERMISSIONS_BUILDER.list or {}
local function onPermissionsGained()
PERMISSIONS_BUILDER:onPermissionsGained()
net.start("onPermissionsGained")
net.send()
end
function PERMISSIONS_BUILDER:add(permission)
if not table.hasValue(self.list, permission) then
table.insert(self.list, permission)
end
end
function PERMISSIONS_BUILDER:build(description)
description = description or ""
local allPermissionsGained = true
for k, v in pairs(self.list) do
if not hasPermission(v) then
allPermissionsGained = false
break
end
end
if allPermissionsGained then
onPermissionsGained()
else
setupPermissionRequest(self.list, description, true)
hook.add("permissionrequest", "PERMISSIONS_BUILDER_permissionrequest", function()
if permissionRequestSatisfied() then
onPermissionsGained()
end
end)
end
end
-- STUB
function PERMISSIONS_BUILDER:onPermissionsGained()
end
else
net.receive("onPermissionsGained", function(len, ply)
PERMISSIONS_BUILDER:onPermissionsGained(ply)
end)
-- STUB
function PERMISSIONS_BUILDER:onPermissionsGained(ply)
end
end
return PERMISSIONS_BUILDER

View File

@@ -1,12 +1,19 @@
-- @name koptilnya/libs/workers
WORKERS = {}
WORKERS_QUOTA = 0.4
WORKERS_QUOTA = 0.7
local function canProcess()
local exp1 = (math.max(chip():getQuotaAverage(), chip():getQuotaUsed()) + (chip():getQuotaUsed() - math.max(chip():getQuotaAverage(), chip():getQuotaUsed())) * 0.01) / chip():getQuotaMax() < WORKERS_QUOTA
local exp2 = math.max(quotaTotalAverage(), quotaTotalUsed()) < quotaMax() * WORKERS_QUOTA
return exp1 and exp2
end
local function execWorker(worker)
local status
while math.max(quotaAverage(), quotaUsed()) < quotaMax() * WORKERS_QUOTA do
while canProcess() do
status = worker()
if status == 1 or status == 2 then