Skip to content

fix outfit filters not working #1369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions lua/pac3/editor/client/wear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
end

net.SendToServer()
pac.Message(('Transmitting outfit %q to server (%s)'):format(part.Name or part.ClassName or '<unknown>', string.NiceSize(bytes)))
pac.Message(("Transmitting outfit %q to server (%s)"):format(part.Name or part.ClassName or "<unknown>", string.NiceSize(bytes)))

pace.ExtendWearTracker(8)

Expand All @@ -127,9 +127,9 @@
end

net.Start("pac_submit")
local ret,err = net_write_table(data)
local ret, err = net_write_table(data)
if ret == nil then
pace.Notify(false, "unable to transfer data to server: "..tostring(err or "too big"), name)
pace.Notify(false, "unable to transfer data to server: " .. tostring(err or "too big"), name)
return false
end
net.SendToServer()
Expand Down Expand Up @@ -182,11 +182,11 @@
end

if owner == pac.LocalPlayer then
pace.CallHook("OnWoreOutfit", part)
pac.CallHook("OnWoreOutfit", part)
end

part:CallRecursive('OnWorn')
part:CallRecursive('PostApplyFixes')
part:CallRecursive("OnWorn")
part:CallRecursive("PostApplyFixes")

if part.UpdateOwnerName then
part:UpdateOwnerName(true)
Expand Down Expand Up @@ -229,7 +229,7 @@
elseif T == "string" then
return pace.RemovePartFromServer(data.owner, data.part, data)
else
ErrorNoHalt("PAC: Unhandled "..T..'!?\n')
ErrorNoHalt("PAC: Unhandled " .. T .. "!?\n")
end
end

Expand All @@ -246,7 +246,7 @@
local data = buffer:readTable()

if type(data.owner) ~= "Player" or not data.owner:IsValid() then
pac.Message("received message from server but owner is not valid!? typeof " .. type(data.owner) .. ' || ', data.owner)
pac.Message("received message from server but owner is not valid!? typeof " .. type(data.owner) .. " || ", data.owner)
return
end

Expand All @@ -262,9 +262,9 @@
name = name or "???"

if allowed == true then
pac.Message(string.format('Your part %q has been applied', name))
pac.Message(string.format("Your part %q has been applied", name))
else
chat.AddText(Color(255, 255, 0), "[PAC3] ", Color(255, 0, 0), string.format('The server rejected applying your part (%q) - %s', name, reason))
chat.AddText(Color(255, 255, 0), "[PAC3] ", Color(255, 0, 0), string.format("The server rejected applying your part (%q) - %s", name, reason))
end
end

Expand Down Expand Up @@ -296,7 +296,8 @@

else
--prompt
local backup_files, directories = file.Find( "pac3/__backup/*.txt", "DATA", "datedesc")

Check warning on line 299 in lua/pac3/editor/client/wear.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: directories
local latest_outfit = cookie.GetString( "pac_last_loaded_outfit", "" )
if not backup_files then
local pnl = Derma_Query("Do you want to load your autoload outfit?", "PAC3 autoload (pac_prompt_for_autoload)",
"load pac3/autoload.txt : " .. string.NiceSize(file.Size("pac3/autoload.txt", "DATA")), function()
Expand All @@ -320,7 +321,6 @@
else
if backup_files[1] then
local latest_autosave = "pac3/__backup/" .. backup_files[1]
local latest_outfit = cookie.GetString( "pac_last_loaded_outfit", "" )
local pnl = Derma_Query("Do you want to load an outfit?", "PAC3 autoload (pac_prompt_for_autoload)",
"load pac3/autoload.txt : " .. string.NiceSize(file.Size("pac3/autoload.txt", "DATA")), function()
pac.Message("Wearing autoload...")
Expand Down Expand Up @@ -400,11 +400,9 @@

frames = frames + 1

if frames > 400 then
if not xpcall(Initialize, ErrorNoHalt) then
pac.RemoveHook("Think", "request_outfits")
pace.NeverLoaded = true
end
if frames > 400 and not xpcall(Initialize, ErrorNoHalt) then
pac.RemoveHook("Think", "request_outfits")
pace.NeverLoaded = true
end
end)

Expand Down
96 changes: 64 additions & 32 deletions lua/pac3/editor/client/wear_filter.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
local list_form = include("panels/list.lua")
local L = pace.LanguageString

local cache = {}
local path = "pac3_config/"

-- old path migration
pac.AddHook("PrePACEditorOpen", "wear_filter_config_migration", function()
if file.IsDir("pac/config", "DATA") and cookie.GetString("pac3_config_migration_dismissed", "0") == "0" then
Derma_Query(
L "Do you want to migrate the old pac/config folder to pac3_config?",
L "Old Config Folder Detected",
L "Yes",
function()
local files, _ = file.Find("pac/config/*.json", "DATA")
for i = 1, #files do
local f = files[i]
local content = file.Read("pac/config/" .. f, "DATA")
file.Write(path .. f, content)
file.Delete("pac/config/" .. f, "DATA")
end
file.Delete("pac/config", "DATA")
file.Delete("pac", "DATA")
end,
L "No",
function()
cookie.Set("pac3_config_migration_dismissed", "1")
end
)
end
end)

local function store_config(id, tbl)
file.CreateDir("pac/config")
file.Write("pac/config/"..id..".json", util.TableToJSON(tbl))
cache[id] = tbl
end
local cache = setmetatable({}, {__index = function(self, key)
local val = util.JSONToTable(file.Read(path .. key .. ".json", "DATA") or "{}") or {}
self[key] = val
return self
end})

local function read_config(id)
local tbl = util.JSONToTable(file.Read("pac/config/"..id..".json", "DATA") or "{}") or {}
local function store_config(id, tbl)
if not file.IsDir(path, "DATA") then
file.CreateDir(path)
end
file.Write(path .. id .. ".json", util.TableToJSON(tbl))
cache[id] = tbl
return tbl
end

local function get_config_value(id, key)
Expand Down Expand Up @@ -83,7 +111,7 @@ do
end
end

table.insert(ent.pac_ignored_callbacks, {callback = callback, index = index})
table.insert(ent.pac_ignored_callbacks, { callback = callback, index = index })
end

function pac.CleanupEntityIgnoreBound(ent)
Expand Down Expand Up @@ -194,7 +222,7 @@ local function generic_form(help)
local pnl = vgui.Create("DListLayout")

local label = pnl:Add("DLabel")
label:DockMargin(0,5,0,5)
label:DockMargin(0, 5, 0, 5)
label:SetWrap(true)
label:SetDark(true)
label:SetAutoStretchVertical(true)
Expand All @@ -207,18 +235,18 @@ local function player_list_form(name, id, help)
local pnl = vgui.Create("DListLayout")

local label = pnl:Add("DLabel")
label:DockMargin(0,5,0,5)
label:DockMargin(0, 5, 0, 5)
label:SetWrap(true)
label:SetDark(true)
label:SetAutoStretchVertical(true)
label:SetText(help)

list_form(pnl, name, {
empty_message = L"No players online.",
empty_message = L "No players online.",

name_left = "players",
populate_left = function()
local blacklist = read_config(id)
local blacklist = cache[id]

local tbl = {}
for _, ply in ipairs(player.GetHumans()) do
Expand All @@ -233,7 +261,7 @@ local function player_list_form(name, id, help)
return tbl
end,
store_left = function(kv)
local tbl = read_config(id)
local tbl = cache[id]
tbl[jsonid(kv.value)] = kv.name
store_config(id, tbl)

Expand All @@ -245,7 +273,7 @@ local function player_list_form(name, id, help)
name_right = name,
populate_right = function()
local tbl = {}
for id, nick in pairs(read_config(id)) do
for id, nick in pairs(cache[id]) do
local ply = pac.ReverseHash(id:sub(2), "Player")
if ply == pac.LocalPlayer then continue end

Expand All @@ -264,7 +292,7 @@ local function player_list_form(name, id, help)
return tbl
end,
store_right = function(kv)
local tbl = read_config(id)
local tbl = cache[id]
tbl[kv.value] = nil
store_config(id, tbl)

Expand Down Expand Up @@ -294,7 +322,7 @@ do
for _, ply in ipairs(player.GetHumans()) do
if ply == pac.LocalPlayer then continue end

local icon = menu:AddOption(L"wear only for " .. ply:Nick(), function()
local icon = menu:AddOption(L "wear only for " .. ply:Nick(), function()
pace.WearParts(ply)
end)
icon:SetImage(pace.MiscIcons.wear)
Expand All @@ -307,11 +335,11 @@ function pace.FillWearSettings(pnl)
list:Dock(FILL)

do
local cat = list:Add(L"wear filter")
cat.Header:SetSize(40,40)
local cat = list:Add(L "wear filter")
cat.Header:SetSize(40, 40)
cat.Header:SetFont("DermaLarge")
local list = vgui.Create("DListLayout")
list:DockPadding(20,20,20,20)
list:DockPadding(20, 20, 20, 20)
cat:SetContents(list)

local mode = vgui.Create("DComboBox", list)
Expand All @@ -327,13 +355,15 @@ function pace.FillWearSettings(pnl)
end

if value == "steam friends" then
mode.form = generic_form(L"Only your steam friends can see your worn outfit.")
mode.form = generic_form(L "Only your steam friends can see your worn outfit.")
elseif value == "whitelist" then
mode.form = player_list_form(L"whitelist", "wear_whitelist", L"Only the players in the whitelist can see your worn outfit.")
mode.form = player_list_form(L "whitelist", "wear_whitelist",
L "Only the players in the whitelist can see your worn outfit.")
elseif value == "blacklist" then
mode.form = player_list_form( L"blacklist", "wear_blacklist", L"The players in the blacklist cannot see your worn outfit.")
mode.form = player_list_form(L "blacklist", "wear_blacklist",
L "The players in the blacklist cannot see your worn outfit.")
elseif value == "disabled" then
mode.form = generic_form(L"Everyone can see your worn outfit.")
mode.form = generic_form(L "Everyone can see your worn outfit.")
end

GetConVar("pace_wear_filter_mode"):SetString(value:gsub(" ", "_"))
Expand All @@ -347,11 +377,11 @@ function pace.FillWearSettings(pnl)
end

do
local cat = list:Add(L"outfit filter")
cat.Header:SetSize(40,40)
local cat = list:Add(L "outfit filter")
cat.Header:SetSize(40, 40)
cat.Header:SetFont("DermaLarge")
local list = vgui.Create("DListLayout")
list:DockPadding(20,20,20,20)
list:DockPadding(20, 20, 20, 20)
cat:SetContents(list)

local mode = vgui.Create("DComboBox", list)
Expand All @@ -367,13 +397,15 @@ function pace.FillWearSettings(pnl)
end

if value == "steam friends" then
mode.form = generic_form(L"You will only see outfits from your steam friends.")
mode.form = generic_form(L "You will only see outfits from your steam friends.")
elseif value == "whitelist" then
mode.form = player_list_form(L"whitelist", "outfit_whitelist", L"You will only see outfits from the players in the whitelist.")
mode.form = player_list_form(L "whitelist", "outfit_whitelist",
L "You will only see outfits from the players in the whitelist.")
elseif value == "blacklist" then
mode.form = player_list_form(L"blacklist", "outfit_blacklist", L"You will see outfits from everyone except the players in the blacklist.")
mode.form = player_list_form(L "blacklist", "outfit_blacklist",
L "You will see outfits from everyone except the players in the blacklist.")
elseif value == "disabled" then
mode.form = generic_form(L"You will see everyone's outfits.")
mode.form = generic_form(L "You will see everyone's outfits.")
end

GetConVar("pace_outfit_filter_mode"):SetString(value:gsub(" ", "_"))
Expand Down
Loading