Насрал типами, но еще не до конца
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
--@name koptilnya/libs/constants
|
||||
|
||||
NULL_ENTITY = entity(0)
|
||||
CURRENT_PLAYER = player()
|
||||
OWNER = owner()
|
||||
IS_ME = CURRENT_PLAYER == OWNER
|
||||
TICK_INTERVAL = game.getTickInterval()
|
||||
RAD_TO_RPM = 9.5493
|
||||
RPM_TO_RAD = 0.10472
|
||||
UNITS_PER_METER = 39.37
|
||||
UNITS_TO_METERS = 0.01905
|
||||
KG_TO_N = 9.80665
|
||||
KG_TO_KN = 0.00980665
|
||||
_G.NULL_ENTITY = entity(0)
|
||||
_G.CURRENT_PLAYER = player()
|
||||
_G.OWNER = owner()
|
||||
_G.IS_ME = CURRENT_PLAYER == OWNER
|
||||
_G.TICK_INTERVAL = game.getTickInterval()
|
||||
_G.RAD_TO_RPM = 9.5493
|
||||
_G.RPM_TO_RAD = 0.10472
|
||||
_G.UNITS_PER_METER = 39.37
|
||||
_G.UNITS_TO_METERS = 0.01905
|
||||
_G.KG_TO_N = 9.80665
|
||||
_G.KG_TO_KN = 0.00980665
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
-- @name koptilnya/libs/utils
|
||||
function checkVarClass(var, class, message)
|
||||
if type(var) ~= "table" or var["class"] == nil or not var:isInstanceOf(class) then
|
||||
throw(message == nil and "Wrong variable class." or message, 1, true)
|
||||
end
|
||||
if type(var) ~= 'table' or var['class'] == nil or not var:isInstanceOf(class) then
|
||||
throw(message == nil and 'Wrong variable class.' or message, 1, true)
|
||||
end
|
||||
end
|
||||
|
||||
function accessorFunc(tbl, varName, name, defaultValue)
|
||||
tbl[varName] = defaultValue
|
||||
tbl["get" .. name] = function(self)
|
||||
return self[varName]
|
||||
end
|
||||
tbl["set" .. name] = function(self, value)
|
||||
self[varName] = value
|
||||
end
|
||||
tbl[varName] = defaultValue
|
||||
tbl['get' .. name] = function(self)
|
||||
return self[varName]
|
||||
end
|
||||
tbl['set' .. name] = function(self, value)
|
||||
self[varName] = value
|
||||
end
|
||||
end
|
||||
|
||||
function rotateAround(entity, pivot, angles)
|
||||
local pos = entity:getPos()
|
||||
local localPivotPos = entity:worldToLocal(pivot)
|
||||
local pos = entity:getPos()
|
||||
local localPivotPos = entity:worldToLocal(pivot)
|
||||
|
||||
entity:setAngles(angles)
|
||||
pos = pos + (pivot - entity:localToWorld(localPivotPos))
|
||||
entity:setPos(pos)
|
||||
entity:setAngles(angles)
|
||||
pos = pos + (pivot - entity:localToWorld(localPivotPos))
|
||||
entity:setPos(pos)
|
||||
end
|
||||
|
||||
function tobase(number, base)
|
||||
local ret = ""
|
||||
local ret = ''
|
||||
|
||||
if base < 2 or base > 36 or number == 0 then
|
||||
return "0"
|
||||
end
|
||||
if base < 2 or base > 36 or number == 0 then
|
||||
return '0'
|
||||
end
|
||||
|
||||
if base == 10 then
|
||||
return tostring(number)
|
||||
end
|
||||
if base == 10 then
|
||||
return tostring(number)
|
||||
end
|
||||
|
||||
local chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
local loops = 0
|
||||
while number > 0 do
|
||||
loops = loops + 1
|
||||
number, d = math.floor(number / base), (number % base) + 1
|
||||
ret = string.sub(chars, d, d) .. ret
|
||||
if (loops > 32000) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return ret
|
||||
local chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
local loops = 0
|
||||
while number > 0 do
|
||||
loops = loops + 1
|
||||
number, d = math.floor(number / base), (number % base) + 1
|
||||
ret = string.sub(chars, d, d) .. ret
|
||||
if loops > 32000 then
|
||||
break
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function bytesToHex(bytes)
|
||||
local hex = "0x"
|
||||
local hex = '0x'
|
||||
|
||||
for _, v in pairs(bytes) do
|
||||
hex = hex .. bit.tohex(v, 2)
|
||||
end
|
||||
for _, v in pairs(bytes) do
|
||||
hex = hex .. bit.tohex(v, 2)
|
||||
end
|
||||
|
||||
return hex
|
||||
return hex
|
||||
end
|
||||
|
||||
function byteTable(str, start, length)
|
||||
local result = {}
|
||||
local result = {}
|
||||
|
||||
for i = 1, length do
|
||||
result[i] = string.byte(str, i + start - 1)
|
||||
end
|
||||
for i = 1, length do
|
||||
result[i] = string.byte(str, i + start - 1)
|
||||
end
|
||||
|
||||
return result
|
||||
return result
|
||||
end
|
||||
|
||||
function isURL(str)
|
||||
local _1, _2, prefix = str:find("^(%w-):")
|
||||
local _1, _2, prefix = str:find('^(%w-):')
|
||||
|
||||
return prefix == "http" or prefix == "https" or prefix == "data"
|
||||
return prefix == 'http' or prefix == 'https' or prefix == 'data'
|
||||
end
|
||||
|
||||
function debounce(func, delay)
|
||||
local lastCall = 0
|
||||
return function(...)
|
||||
local now = timer.systime()
|
||||
if now - lastCall >= delay then
|
||||
lastCall = now
|
||||
return func(...)
|
||||
end
|
||||
end
|
||||
end
|
||||
local lastCall = 0
|
||||
return function(...)
|
||||
local now = timer.systime()
|
||||
if now - lastCall >= delay then
|
||||
lastCall = now
|
||||
return func(...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user