Skip to content

Commit

Permalink
chore(jobsystem): item filter
Browse files Browse the repository at this point in the history
  • Loading branch information
polisek committed Feb 26, 2024
1 parent 1aae055 commit 140326b
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions client/creation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local function IsBlacklistedString(text)
return false
end


for _, v in pairs(items) do
if not IsBlacklistedString(v.name) then
table.insert(item_select, {
Expand Down Expand Up @@ -243,33 +244,62 @@ local function openCraftingTable(id)
description = "Create new item for this crafting table.",
icon = 'circle',
onSelect = function()
local FilterData = {
useFilter = false,
filteredData = {}
}
:: BackToFilter ::
local showedItems = {}
if FilterData.useFilter then
for _, filterWorld in pairs(FilterData.filteredData) do
for _, item in pairs(item_select) do
if string.find(string.lower(item.label), string.lower(filterWorld)) then
table.insert(showedItems, item)
end
end
end
else
showedItems = item_select
FilterData.filteredData = {}
end
local input = lib.inputDialog('Select item and ingedience', {
{ type = 'select', label = "Main item", description = "This is the item you want to crafting.",required = true, options = item_select, clearable = true },
{ type = 'multi-select', label = "Ingedience", description = "Required",required = true, options = item_select, clearable = true },
{ type = 'textarea', label = "Filter - Filled search / Unfilled saves", description = "Write the labels of the items you want to filter. Separate them with ,",required = false, placeholder = "Meat, Fish, Bone", clearable = true },
{ type = 'select', label = "Main item", description = "This is the item you want to crafting.",required = true, options = showedItems, clearable = true },
{ type = 'multi-select', label = "Ingedience", description = "Required",required = true, options = showedItems, clearable = true },
})
if input then

local defineIngedience = {}
for _, selectedIngedience in pairs(input[2]) do
table.insert(defineIngedience, {
itemName = selectedIngedience,
if tostring(input[1]) ~= "" then
local searched_value = tostring(input[1])
FilterData.useFilter = true
for word in searched_value:gmatch("[^,%s]+") do
table.insert(FilterData.filteredData, word)
end
goto BackToFilter
end
if input[1] == "" then
if input then

local defineIngedience = {}
for _, selectedIngedience in pairs(input[3]) do
table.insert(defineIngedience, {
itemName = selectedIngedience,
itemCount = 1,
})
end

local newTable = {
itemName = input[2],
itemCount = 1,
ingedience = defineIngedience
}
table.insert(selectedJob.craftings[id].items, newTable)
TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob)
lib.notify({
title="New recipe created",
description="Congrats! New recepie has been created.",
type="success"
})
openCraftingTable(cached.crafting_table_id)
end

local newTable = {
itemName = input[1],
itemCount = 1,
ingedience = defineIngedience
}
table.insert(selectedJob.craftings[id].items, newTable)
TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob)
lib.notify({
title="New recipe created",
description="Congrats! New recepie has been created.",
type="success"
})
openCraftingTable(cached.crafting_table_id)
end
end,
})
Expand Down

0 comments on commit 140326b

Please sign in to comment.