feat(resource/zoneCreator): change output format in dialog

This commit is contained in:
DokaDoka
2022-09-15 00:00:53 +10:00
parent 863ac03ca3
commit 6fb18c740a
2 changed files with 28 additions and 21 deletions

View File

@@ -3,6 +3,7 @@ local controlsActive = false
local zoneType, step, xCoord, yCoord, zCoord, heading, height, width, length local zoneType, step, xCoord, yCoord, zCoord, heading, height, width, length
local steps = {{0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 25, 50, 100}, {0.25, 0.5, 1, 2.5, 5, 15, 30, 45, 60, 90, 180}} local steps = {{0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 25, 50, 100}, {0.25, 0.5, 1, 2.5, 5, 15, 30, 45, 60, 90, 180}}
local points = {} local points = {}
local format = 'array'
local function firstToUpper(str) local function firstToUpper(str)
return (str:gsub("^%l", string.upper)) return (str:gsub("^%l", string.upper))
@@ -42,18 +43,26 @@ local function round(number)
return number >= 0 and math.floor(number + 0.5) or math.ceil(number - 0.5) return number >= 0 and math.floor(number + 0.5) or math.ceil(number - 0.5)
end end
local function closeCreator(cancel) local function closeCreator(cancel)
if not cancel then if not cancel then
if zoneType == 'poly' then if zoneType == 'poly' then
points[#points + 1] = vec(xCoord, yCoord) points[#points + 1] = vec(xCoord, yCoord)
end end
local name = lib.inputDialog(('Name your %s Zone'):format(firstToUpper(zoneType)), {'Name'})?[1] local input = lib.inputDialog(('Name your %s Zone'):format(firstToUpper(zoneType)), {
{ type = 'input', label = 'Name', placeholder = 'none' },
{ type = 'select', label = 'Format', default = format, options = {
{ value = 'function', label = 'Function' },
{ value = 'array', label = 'Array' },
}}
}) or {}
format = input[2]
TriggerServerEvent('ox_lib:saveZone', { TriggerServerEvent('ox_lib:saveZone', {
zoneType = zoneType, zoneType = zoneType,
name = name, name = input[1] or 'none',
format = format,
xCoord = xCoord, xCoord = xCoord,
yCoord = yCoord, yCoord = yCoord,
zCoord = zCoord, zCoord = zCoord,

View File

@@ -1,7 +1,5 @@
local printFunction = false
--[[ --[[
-- printFunction = true -- function
local poly = lib.zones.poly({ local poly = lib.zones.poly({
name = poly, name = poly,
points = { points = {
@@ -13,7 +11,7 @@ local poly = lib.zones.poly({
}, },
thickness = 2, thickness = 2,
}) })
-- printFunction = false -- array
{ {
name = poly, name = poly,
points = { points = {
@@ -35,19 +33,19 @@ local parse = {
end end
local pattern local pattern
if printFunction then if data.format == 'function' then
pattern = { pattern = {
'local poly = lib.zones.poly({\n', 'local poly = lib.zones.poly({\n',
('\tname = "%s",\n'):format(data.name or 'none'), ('\tname = "%s",\n'):format(data.name),
'\tpoints = {\n', '\tpoints = {\n',
('%s\t},\n'):format(table.concat(points)), ('%s\t},\n'):format(table.concat(points)),
('\tthickness = %s,\n'):format(data.height), ('\tthickness = %s,\n'):format(data.height),
'})\n', '})\n',
} }
else elseif data.format == 'array' then
pattern = { pattern = {
'{\n', '{\n',
('\tname = "%s",\n'):format(data.name or 'none'), ('\tname = "%s",\n'):format(data.name),
'\tpoints = {\n', '\tpoints = {\n',
('%s\t},\n'):format(table.concat(points)), ('%s\t},\n'):format(table.concat(points)),
('\tthickness = %s,\n'):format(data.height), ('\tthickness = %s,\n'):format(data.height),
@@ -59,19 +57,19 @@ local parse = {
end, end,
box = function(data) box = function(data)
local pattern local pattern
if printFunction then if data.format == 'function' then
pattern = { pattern = {
'local box = lib.zones.box({\n', 'local box = lib.zones.box({\n',
('\tname = "%s",\n'):format(data.name or 'none'), ('\tname = "%s",\n'):format(data.name),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord), ('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height), ('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height),
('\trotation = %s,\n'):format(data.heading), ('\trotation = %s,\n'):format(data.heading),
'})\n', '})\n',
} }
else elseif data.format == 'array' then
pattern = { pattern = {
'{\n', '{\n',
('\tname = "%s",\n'):format(data.name or 'none'), ('\tname = "%s",\n'):format(data.name),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord), ('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height), ('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height),
('\trotation = %s,\n'):format(data.heading), ('\trotation = %s,\n'):format(data.heading),
@@ -83,20 +81,20 @@ local parse = {
end, end,
sphere = function(data) sphere = function(data)
local pattern local pattern
if printFunction then if data.format == 'function' then
pattern = { pattern = {
'local sphere = lib.zones.sphere({\n', 'local sphere = lib.zones.sphere({\n',
('\tname = "%s",\n'):format(data.name or 'none'), ('\tname = "%s",\n'):format(data.name),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord), ('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tradius = %s,\n'):format(data.heading), ('\tradius = %s,\n'):format(data.height),
'})\n', '})\n',
} }
else elseif data.format == 'array' then
pattern = { pattern = {
'{\n', '{\n',
('\tname = "%s",\n'):format(data.name or 'none'), ('\tname = "%s",\n'):format(data.name),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord), ('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tradius = %s,\n'):format(data.heading), ('\tradius = %s,\n'):format(data.height),
'},\n', '},\n',
} }
end end