Skip to content
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
55 changes: 43 additions & 12 deletions lua/outfitter/cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end

function DisableEverything()
dbg("DisableEverything")
for _, pl in next, player.GetAll() do
for _, pl in player.Iterator() do
if pl.outfitter_nvar then
pl.outfitter_nvar = nil

Expand All @@ -53,11 +53,38 @@ function DisableEverything()
end

function RefreshPlayers()
for _, pl in next, player.GetAll() do
for _, pl in player.Iterator() do
OnPlayerVisible(pl)
end
end

function RefreshDependencies()
local players = {}
for _, pl in player.Iterator() do
local dependency_manifest = pl:OutfitDependencyManifest()
if 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
if pl == LocalPlayer() then
local mdl, download_info, skin, bodygroups = pl:OutfitInfo()
if mdl then
OnChangeOutfit(pl, mdl, download_info, skin, bodygroups, pl:OutfitDependencyManifest())
end
else
pl.outfitter_nvar = nil
OnPlayerVisible(pl)
end
end
co.sleep(.25)
end
end)
end

function EnableEverything()
dbg("EnableEverything")
RefreshPlayers()
Expand All @@ -67,9 +94,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 +106,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 @@ -158,6 +185,7 @@ function ChangeOutfitThreadWorker(pl, hash)
assert(not HBAD(pl, hash))

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

dbg("ChangeOutfit", "BEGIN", pl, mdl or "unset", download_info)
Expand All @@ -174,9 +202,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 Down Expand Up @@ -205,7 +234,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 Down Expand Up @@ -247,9 +276,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 @@ -269,9 +298,11 @@ end
function BroadcastMyOutfit(a)
assert(not a)
local mdl, download_info, s, bg = LocalPlayer():OutfitInfo()
dbg("BroadcastMyOutfit", mdl, download_info, s, bg)
local dependency_manifest = LocalPlayer():OutfitDependencyManifest()
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
29 changes: 27 additions & 2 deletions lua/outfitter/cl_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,27 @@ do
end
end

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

do
local outfitter_mount_children = CreateClientConVar("outfitter_mount_children_test", "0", true)
local outfitter_allow_dependencies = CreateClientConVar("outfitter_allow_dependencies", "1", true)

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

function ShouldMountChildren()
return outfitter_mount_children:GetBool()
return outfitter_allow_dependencies:GetBool()
end

function OutfitMaxSize()
return outfitter_maxsize:GetFloat() * 1000 * 1000
end
end

Expand Down Expand Up @@ -371,6 +388,14 @@ end

--TODO
outfitter_maxsize = CreateClientConVar("outfitter_maxsize", "60", true)
cvars.AddChangeCallback("outfitter_maxsize", function(cvar, old, new)
old = tonumber(old) or 0
new = tonumber(new) or 0

if ShouldMountChildren and ShouldMountChildren() and old > 0 and (new <= 0 or new > old) then
refresh_dependencies()
end
end)

-- Model enforcing

Expand Down
Loading
Loading