From 155dc617f83212c80835c9ee6d770c62eb322f41 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Thu, 21 Apr 2022 15:18:50 +1000 Subject: [PATCH] refactor(points): support single argument for lib.points.new --- imports/points/client.lua | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/imports/points/client.lua b/imports/points/client.lua index 0aa9856..3951753 100644 --- a/imports/points/client.lua +++ b/imports/points/client.lua @@ -55,18 +55,30 @@ CreateThread(function() end) return { - new = function(coords, distance, data) + new = function(...) + local args = {...} local id = #points + 1 + local self - local self = { - id = id, - coords = coords, - distance = distance, - remove = removePoint, - } + -- Support sending a single argument containing point data + if type(args[1]) == 'table' then + self = args[1] + self.id = id + self.remove = removePoint + else + -- Backwards compatibility for original implementation (args: coords, distance, data) + self = { + id = id, + coords = args[1], + remove = removePoint, + } + end - if data then - for k, v in pairs(data) do + + self.distance = self.distance or args[2] + + if args[3] then + for k, v in pairs(args[3]) do self[k] = v end end