Skip to content
Closed
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
50 changes: 36 additions & 14 deletions lua/outfitter/cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ function RefreshPlayers()
end
end

function RefreshDependencies()
local players = {}
for _, pl in next, player.GetAll() do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for _, pl in next, player.GetAll() do
for _, pl in player.Iterator() do

local _, _, _, _, dependency_manifest = pl:OutfitInfo()
if pl ~= LocalPlayer() and dependency_manifest and #dependency_manifest.dependencies > 0 then
players[#players + 1] = pl
end
end

return co(function()
for _, pl in next, players do
if pl:IsValid() then
pl.outfitter_nvar = nil
OnPlayerVisible(pl)
end
co.sleep(.25)
end
end)
end

function EnableEverything()
dbg("EnableEverything")
RefreshPlayers()
Expand All @@ -67,9 +87,9 @@ local Player = FindMetaTable "Player"

------- player outfit changing --------

function Player.SetWantOutfit(pl, mdl, download_info, skin, bodygroups)
function Player.SetWantOutfit(pl, mdl, download_info, skin, bodygroups, dependency_manifest)
dbg("SetWantOutfit", pl, not mdl and "unset" or ('%q'):format(tostring(mdl)),
not download_info and "-" or ('%q'):format(tostring(download_info)))
not download_info and "-" or ('%q'):format(tostring(download_info)), DependencyManifestID(dependency_manifest))

assert(pl and pl:IsValid())
pl:GetModel()
Expand All @@ -79,7 +99,7 @@ function Player.SetWantOutfit(pl, mdl, download_info, skin, bodygroups)

mdl = mdl or false

pl:OutfitSetInfo(mdl, download_info, skin, bodygroups)
pl:OutfitSetInfo(mdl, download_info, skin, bodygroups, dependency_manifest)

local thread = pl.outfitter_co_thread

Expand Down Expand Up @@ -157,7 +177,7 @@ function ChangeOutfitThreadWorker(pl, hash)
assert(pl:OutfitCheckHash(hash))
assert(not HBAD(pl, hash))

local mdl, download_info, skin, bodygroups = pl:OutfitInfo()
local mdl, download_info, skin, bodygroups, dependency_manifest = pl:OutfitInfo()
mdl = mdl or false

dbg("ChangeOutfit", "BEGIN", pl, mdl or "unset", download_info)
Expand All @@ -174,9 +194,10 @@ function ChangeOutfitThreadWorker(pl, hash)
if tonumber(download_info) then
-- The model may have been mounted before its required items.
if ShouldMountChildren() then
local ok, err = coMountWSChildren(download_info)
local ok, err, err2 = coMountWSChildren(download_info, dependency_manifest)
if not ok then
dbg("ChangeOutfit", download_info, "child mount fail", err)
dbg("ChangeOutfit", download_info, "child mount fail", err, err2)
coUIDependencyFailureMsg(pl, download_info, err, err2)
end
end

Expand All @@ -189,7 +210,7 @@ function ChangeOutfitThreadWorker(pl, hash)
if HBAD(pl, hash) then return false, "outdated" end
end

local ret = hook.Run("CanOutfit", pl, pl:OutfitInfo())
local ret = hook.Run("CanOutfit", pl, mdl, download_info, skin, bodygroups)
if ret == false then
return false, "canoutfit"
end
Expand All @@ -205,7 +226,7 @@ function ChangeOutfitThreadWorker(pl, hash)
end

------------ TIME PASSES ONLY HERE -------------
local ok, err = AcquireAssets(download_info, pl, mdl)
local ok, err = AcquireAssets(download_info, pl, mdl, dependency_manifest)
if not ok then
dbg("DoChangeOutfit", "NeedWS failed", err, "continuing...", pl, mdl, download_info)
if err == 'oversize' then
Expand All @@ -231,7 +252,7 @@ function ChangeOutfitThreadWorker(pl, hash)
end

-- 5. Check CanOutfit
local ret = hook.Run("CanOutfit", pl, pl:OutfitInfo())
local ret = hook.Run("CanOutfit", pl, mdl, download_info, skin, bodygroups)
if ret == false then
return false, "canoutfit"
end
Expand All @@ -247,9 +268,9 @@ function ChangeOutfitThreadWorker(pl, hash)
return true
end

function AcquireAssets(download_info, pl, mdl)
function AcquireAssets(download_info, pl, mdl, dependency_manifest)
if download_info and tonumber(download_info) then
return NeedWS(download_info, pl, mdl)
return NeedWS(download_info, pl, mdl, dependency_manifest)
end
if IsHTTPURL(download_info) then
if AllowedHTTPURL(download_info) then
Expand All @@ -268,10 +289,11 @@ end

function BroadcastMyOutfit(a)
assert(not a)
local mdl, download_info, s, bg = LocalPlayer():OutfitInfo()
dbg("BroadcastMyOutfit", mdl, download_info, s, bg)
local mdl, download_info, s, bg, dependency_manifest = LocalPlayer():OutfitInfo()
if not ShouldMountChildren() then dependency_manifest = nil end
dbg("BroadcastMyOutfit", mdl, download_info, s, bg, DependencyManifestID(dependency_manifest))

NetworkOutfit(mdl, download_info)
NetworkOutfit(mdl, download_info, dependency_manifest)

return mdl, download_info
end
Expand Down
27 changes: 27 additions & 0 deletions lua/outfitter/cl_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,36 @@ end

do
local outfitter_mount_children = CreateClientConVar("outfitter_mount_children_test", "0", true)
outfitter_dependency_maxsize = CreateClientConVar("outfitter_dependency_maxsize", "60", true)

local function refresh_dependencies()
timer.Create(Tag .. "_dependency_refresh", .5, 1, function()
if RefreshDependencies then RefreshDependencies() end
end)
end

cvars.AddChangeCallback("outfitter_mount_children_test", function(cvar, old, new)
if tonumber(old) == 0 and tonumber(new) ~= 0 then
refresh_dependencies()
end
end)

cvars.AddChangeCallback("outfitter_dependency_maxsize", function(cvar, old, new)
old = tonumber(old) or 0
new = tonumber(new) or 0

if outfitter_mount_children:GetBool() and old > 0 and (new <= 0 or new > old) then
refresh_dependencies()
end
end)

function ShouldMountChildren()
return outfitter_mount_children:GetBool()
end

function DependencyMaxSize()
return outfitter_dependency_maxsize:GetFloat() * 1000 * 1000
end
end

--TODO
Expand Down
Loading