From ec1a98b83a2fc3358ddb010b4956b3f75c05bbed Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 6 Dec 2021 08:39:08 +1100 Subject: [PATCH] feat(keys): implement a DisableControlAction wrapper --- fxmanifest.lua | 2 +- imports/controls/client.lua | 54 +++++++++++++++++++++++++++++++++++++ init.lua | 13 ++------- 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 imports/controls/client.lua diff --git a/fxmanifest.lua b/fxmanifest.lua index b53a402..6b1c7b4 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -23,7 +23,7 @@ game 'gta5' --[[ Resource Information ]]-- name 'pe-lualib' author 'Linden' -version '1.0.2' +version '1.0.3' repository 'https://github.com/project-error/pe-lualib' description 'A library of shared functions to utilise in other resources.' diff --git a/imports/controls/client.lua b/imports/controls/client.lua new file mode 100644 index 0000000..6ba5fb6 --- /dev/null +++ b/imports/controls/client.lua @@ -0,0 +1,54 @@ +--- Call on frame to disable all stored keys. +--- ``` +--- DisableControlActions() +--- ``` +local DisableControlActions = {} + +---@param ... number +function DisableControlActions:Add(...) + local keys = type(...) == 'table' and ... or {...} + for i=1, #keys do + local key = keys[i] + if self[key] then + self[key] += 1 + else + self[key] = 1 + end + end +end + +---@param ... number +function DisableControlActions:Remove(...) + local keys = type(...) == 'table' and ... or {...} + for i=1, #keys do + local key = keys[i] + local exists = self[key] + if exists and exists > 1 then + self[key] -= 1 + else + self[key] = nil + end + end +end + +---@param ... number +function DisableControlActions:Clear(...) + local keys = type(...) == 'table' and ... or {...} + for i=1, #keys do + self[keys[i]] = nil + end +end + +local Keys = {} +local DisableControlAction = DisableControlAction +local pairs = pairs + +return setmetatable(DisableControlActions, { + __index = Keys, + __newindex = Keys, + __call = function() + for k in pairs(Keys) do + DisableControlAction(0, k, true) + end + end +}) \ No newline at end of file diff --git a/init.lua b/init.lua index dc39f30..8a2d75d 100644 --- a/init.lua +++ b/init.lua @@ -32,16 +32,7 @@ local function loadFile(self, file) error(('\n^1Error importing module (%s): %s^0'):format(dir, err), 3) else rawset(self, file, chunk()) - return setmetatable(self[file], { - __index = { - name = file, - resource = LIBRARY - }, - - __newindex = function() - error('Cannot add indexes to imports') - end - }) + return self[file] end else error(('\n^3Unable to import module (%s)^0'):format(dir), 3) end end @@ -84,7 +75,7 @@ setmetatable(lib, { _ENV.lib = lib --- Dream of a world where this PR gets accepted. ---- ```lua +--- ``` --- SetInterval(callback: function, timer: number) --- ``` SetInterval = setmetatable({currentId = 0}, {