From 17a498a532ef53afd4e80b6c0d4a41e5ea87c92d Mon Sep 17 00:00:00 2001 From: CapsAdmin Date: Sun, 4 Apr 2021 17:16:49 +0200 Subject: [PATCH] don't auto indent net. library --- lint.lua | 9 - lua/autorun/netstream.lua | 40 +- lua/autorun/pac_version.lua | 4 +- lua/pac3/core/client/base_part.lua | 12 +- lua/pac3/core/client/parts/effect.lua | 2 +- lua/pac3/core/client/parts/event.lua | 2 +- lua/pac3/core/client/parts/legacy/ogg.lua | 116 +- lua/pac3/core/client/parts/movement.lua | 12 +- lua/pac3/core/client/parts/projectile.lua | 6 +- lua/pac3/core/client/test.lua | 4 +- lua/pac3/core/server/effects.lua | 2 +- lua/pac3/core/server/event.lua | 36 +- lua/pac3/core/server/net_messages.lua | 12 +- lua/pac3/core/server/test_suite_backdoor.lua | 4 +- lua/pac3/core/shared/entity_mutator.lua | 42 +- lua/pac3/core/shared/footsteps_fix.lua | 8 +- lua/pac3/editor/client/asset_browser.lua | 1392 +++++++++--------- lua/pac3/editor/client/init.lua | 8 +- lua/pac3/editor/client/wear.lua | 28 +- lua/pac3/editor/server/bans.lua | 8 +- lua/pac3/editor/server/init.lua | 18 +- lua/pac3/editor/server/spawnmenu.lua | 2 +- lua/pac3/editor/server/wear.lua | 24 +- lua/pac3/extra/client/contraption.lua | 2 +- lua/pac3/extra/server/contraption.lua | 8 +- lua/pac3/extra/shared/modifiers.lua | 4 +- lua/pac3/extra/shared/modifiers/model.lua | 4 +- lua/pac3/extra/shared/modifiers/size.lua | 6 +- lua/pac3/extra/shared/projectiles.lua | 508 +++---- 29 files changed, 1157 insertions(+), 1166 deletions(-) diff --git a/lint.lua b/lint.lua index f4bfb34e..14a559e8 100644 --- a/lint.lua +++ b/lint.lua @@ -55,15 +55,6 @@ local config = { cam_Start3D2D = {to = "cam_End3D2D"}, cam_Start = {to = "cam_End"}, - Start = { - to = { - SendToServer = true, - Send = true, - Broadcast = true, - End = true, - } - }, - SetPropertyGroup = "toggle", } } diff --git a/lua/autorun/netstream.lua b/lua/autorun/netstream.lua index aeb89935..e1d48894 100644 --- a/lua/autorun/netstream.lua +++ b/lua/autorun/netstream.lua @@ -23,12 +23,12 @@ function net.Stream.ReadStream:Request() -- print("Requesting",self.identifier,false,false,#self.chunks) net.Start("NetStreamRequest") - net.WriteUInt(self.identifier, 32) - net.WriteBit(false) - net.WriteBit(false) - net.WriteUInt(#self.chunks, 32) + net.WriteUInt(self.identifier, 32) + net.WriteBit(false) + net.WriteBit(false) + net.WriteUInt(#self.chunks, 32) - if CLIENT then + if CLIENT then net.SendToServer() else net.Send(self.player) @@ -78,11 +78,11 @@ function net.Stream.ReadStream:Remove() end net.Start("NetStreamRequest") - net.WriteUInt(self.identifier, 32) - net.WriteBit(false) - net.WriteBit(true) + net.WriteUInt(self.identifier, 32) + net.WriteBit(false) + net.WriteBit(true) - if CLIENT then + if CLIENT then net.SendToServer() else net.Send(self.player) @@ -123,12 +123,12 @@ function net.Stream.WriteStream:Write(ply) if chunk then self.clients[ply].progress = progress net.Start("NetStreamDownload") - net.WriteUInt(#chunk.data, 32) - net.WriteUInt(progress, 32) - net.WriteString(chunk.crc) - net.WriteData(chunk.data, #chunk.data) + net.WriteUInt(#chunk.data, 32) + net.WriteUInt(progress, 32) + net.WriteString(chunk.crc) + net.WriteData(chunk.data, #chunk.data) - if CLIENT then + if CLIENT then net.SendToServer() else net.Send(ply) @@ -169,10 +169,10 @@ function net.Stream.WriteStream:Remove() end net.Start("NetStreamDownload") - net.WriteUInt(0, 32) - net.WriteUInt(self.identifier, 32) + net.WriteUInt(0, 32) + net.WriteUInt(self.identifier, 32) - if SERVER then + if SERVER then net.Send(sendTo) else net.SendToServer() @@ -358,10 +358,10 @@ function net.ReadStream(ply, callback) if #queue > 1 then timer.Create("NetStreamKeepAlive" .. identifier, net.Stream.Timeout / 2, 0, function() net.Start("NetStreamRequest") - net.WriteUInt(identifier, 32) - net.WriteBit(true) + net.WriteUInt(identifier, 32) + net.WriteBit(true) - if CLIENT then + if CLIENT then net.SendToServer() else net.Send(ply) diff --git a/lua/autorun/pac_version.lua b/lua/autorun/pac_version.lua index deaf4f43..4cecfd12 100644 --- a/lua/autorun/pac_version.lua +++ b/lua/autorun/pac_version.lua @@ -69,7 +69,7 @@ if SERVER then local verbose = args[1] == "1" info = PAC_VERSION() net.Start("pac_version") - net.WriteTable(info) + net.WriteTable(info) net.Broadcast() dump(info, verbose) end) @@ -81,7 +81,7 @@ if SERVER then if self == ply and not cmd:IsForced() then hook.Remove("SetupMove", id) net.Start("pac_version") - net.WriteTable(info) + net.WriteTable(info) net.Send(ply) end end) diff --git a/lua/pac3/core/client/base_part.lua b/lua/pac3/core/client/base_part.lua index 14bea3b0..e9ca6224 100644 --- a/lua/pac3/core/client/base_part.lua +++ b/lua/pac3/core/client/base_part.lua @@ -130,12 +130,12 @@ function PART:SetBlendMode(str) if src_color and dst_color then self.blend_override = { - src_color, - dst_color, - src_alpha, - dst_alpha, - tbl[5], - } + src_color, + dst_color, + src_alpha, + dst_alpha, + tbl[5], + } else self.blend_override = nil end diff --git a/lua/pac3/core/client/parts/effect.lua b/lua/pac3/core/client/parts/effect.lua index 67547520..ab1fbb3a 100644 --- a/lua/pac3/core/client/parts/effect.lua +++ b/lua/pac3/core/client/parts/effect.lua @@ -86,7 +86,7 @@ local function pac_request_precache(name) already[name] = true PrecacheParticleSystem(name) net.Start("pac_request_precache") - net.WriteString(name) + net.WriteString(name) net.SendToServer() end diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 6af49f2f..070a1622 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -1059,7 +1059,7 @@ do if val then net.Start("pac.AllowPlayerButtons") - net.WriteUInt(val, 8) + net.WriteUInt(val, 8) net.SendToServer() end diff --git a/lua/pac3/core/client/parts/legacy/ogg.lua b/lua/pac3/core/client/parts/legacy/ogg.lua index 209d77b6..48bfaec6 100644 --- a/lua/pac3/core/client/parts/legacy/ogg.lua +++ b/lua/pac3/core/client/parts/legacy/ogg.lua @@ -219,69 +219,69 @@ function PART:PlaySound(_, additiveVolumeFraction) stream:Resume() else stream:Start() - end - - self.last_stream = stream end - function PART:StopSound() - for key, stream in pairs(self.streams) do - if not stream:IsValid() then - self.streams[key] = nil + self.last_stream = stream +end - goto CONTINUE +function PART:StopSound() + for key, stream in pairs(self.streams) do + if not stream:IsValid() then + self.streams[key] = nil + + goto CONTINUE + end + + if not self.StopOnHide then + if self.PauseOnHide then + stream:Pause() + else + stream:Stop() end - - if not self.StopOnHide then - if self.PauseOnHide then - stream:Pause() - else - stream:Stop() - end - end - - ::CONTINUE:: - end - end - - function PART:OnShow(from_rendering) - if not from_rendering then - self:PlaySound() - end - end - - function PART:OnHide() - self:StopSound() - end - - function PART:OnRemove() - for key, stream in pairs(self.streams) do - if not stream:IsValid() then - self.streams[key] = nil - - goto CONTINUE - end - - stream:Remove() - - ::CONTINUE:: - end - end - - function PART:SetDoppler(num) - for key, stream in pairs(self.streams) do - if not stream:IsValid() then - self.streams[key] = nil - - goto CONTINUE - end - - stream:EnableDoppler(num) - - ::CONTINUE:: end - self.Doppler = num + ::CONTINUE:: + end +end + +function PART:OnShow(from_rendering) + if not from_rendering then + self:PlaySound() + end +end + +function PART:OnHide() + self:StopSound() +end + +function PART:OnRemove() + for key, stream in pairs(self.streams) do + if not stream:IsValid() then + self.streams[key] = nil + + goto CONTINUE + end + + stream:Remove() + + ::CONTINUE:: + end +end + +function PART:SetDoppler(num) + for key, stream in pairs(self.streams) do + if not stream:IsValid() then + self.streams[key] = nil + + goto CONTINUE + end + + stream:EnableDoppler(num) + + ::CONTINUE:: end - pac.RegisterPart(PART) + self.Doppler = num +end + +pac.RegisterPart(PART) diff --git a/lua/pac3/core/client/parts/movement.lua b/lua/pac3/core/client/parts/movement.lua index a98e0680..0ed4bdc4 100644 --- a/lua/pac3/core/client/parts/movement.lua +++ b/lua/pac3/core/client/parts/movement.lua @@ -19,8 +19,8 @@ local function ADD(PART, name, default, ...) ply.pac_movement = ply.pac_movement or table.Copy(pac_movement_default) ply.pac_movement[name] = val net.Start("pac_modify_movement") - net.WriteString(name) - net.WriteType(val) + net.WriteString(name) + net.WriteType(val) net.SendToServer() end end @@ -99,10 +99,10 @@ function PART:OnHide() if ent == pac.LocalPlayer then net.Start("pac_modify_movement") - net.WriteString("disable") - net.SendToServer() - ent.pac_movement = nil -end + net.WriteString("disable") + net.SendToServer() + ent.pac_movement = nil + end end pac.RegisterPart(PART) diff --git a/lua/pac3/core/client/parts/projectile.lua b/lua/pac3/core/client/parts/projectile.lua index 49c45c15..a03fccbc 100644 --- a/lua/pac3/core/client/parts/projectile.lua +++ b/lua/pac3/core/client/parts/projectile.lua @@ -154,9 +154,9 @@ function PART:Shoot(pos, ang) end net.Start("pac_projectile") - net.WriteVector(pos) - net.WriteAngle(ang) - net.WriteTable(tbl) + net.WriteVector(pos) + net.WriteAngle(ang) + net.WriteTable(tbl) net.SendToServer() else self.projectiles = self.projectiles or {} diff --git a/lua/pac3/core/client/test.lua b/lua/pac3/core/client/test.lua index 998ee65e..6727f4f6 100644 --- a/lua/pac3/core/client/test.lua +++ b/lua/pac3/core/client/test.lua @@ -268,8 +268,8 @@ function run_lua_on_server(code, cb) local id = util.CRC(code .. tostring(cb)) lua_server_run_callbacks[id] = cb net.Start("pac3_test_sutie_backdoor") - net.WriteString(id) - net.WriteString(code) + net.WriteString(id) + net.WriteString(code) net.SendToServer() end diff --git a/lua/pac3/core/server/effects.lua b/lua/pac3/core/server/effects.lua index debfe3e8..708df88e 100644 --- a/lua/pac3/core/server/effects.lua +++ b/lua/pac3/core/server/effects.lua @@ -29,7 +29,7 @@ util.AddNetworkString("pac_request_precache") function pac.PrecacheEffect(name) PrecacheParticleSystem(name) net.Start("pac_effect_precached") - net.WriteString(name) + net.WriteString(name) net.Broadcast() end diff --git a/lua/pac3/core/server/event.lua b/lua/pac3/core/server/event.lua index 77dbeb7f..e69c13db 100644 --- a/lua/pac3/core/server/event.lua +++ b/lua/pac3/core/server/event.lua @@ -14,9 +14,9 @@ concommand.Add("pac_event", function(ply, _, args) end net.Start("pac_event", true) - net.WriteEntity(ply) - net.WriteString(event) - net.WriteInt(extra, 8) + net.WriteEntity(ply) + net.WriteString(event) + net.WriteInt(extra, 8) net.Broadcast() end) @@ -28,14 +28,14 @@ concommand.Add("+pac_event", function(ply, _, args) ply.pac_event_toggles = ply.pac_event_toggles or {} ply.pac_event_toggles[event] = true net.Start("pac_event", true) - net.WriteEntity(ply) - net.WriteString(event) - net.WriteInt(1, 8) + net.WriteEntity(ply) + net.WriteString(event) + net.WriteInt(1, 8) net.Broadcast() else net.Start("pac_event", true) - net.WriteEntity(ply) - net.WriteString(args[1] .. "_on") + net.WriteEntity(ply) + net.WriteString(args[1] .. "_on") net.Broadcast() end end) @@ -48,14 +48,14 @@ concommand.Add("-pac_event", function(ply, _, args) ply.pac_event_toggles = ply.pac_event_toggles or {} ply.pac_event_toggles[event] = false net.Start("pac_event", true) - net.WriteEntity(ply) - net.WriteString(event) - net.WriteInt(0, 8) + net.WriteEntity(ply) + net.WriteString(event) + net.WriteInt(0, 8) net.Broadcast() else net.Start("pac_event", true) - net.WriteEntity(ply) - net.WriteString(args[1] .. "_off") + net.WriteEntity(ply) + net.WriteString(args[1] .. "_off") net.Broadcast() end end) @@ -63,10 +63,10 @@ end) -- proxy concommand.Add("pac_proxy", function(ply, _, args) net.Start("pac_proxy", true) - net.WriteEntity(ply) - net.WriteString(args[1]) - net.WriteFloat(tonumber(args[2]) or 0) - net.WriteFloat(tonumber(args[3]) or 0) - net.WriteFloat(tonumber(args[4]) or 0) + net.WriteEntity(ply) + net.WriteString(args[1]) + net.WriteFloat(tonumber(args[2]) or 0) + net.WriteFloat(tonumber(args[3]) or 0) + net.WriteFloat(tonumber(args[4]) or 0) net.Broadcast() end) diff --git a/lua/pac3/core/server/net_messages.lua b/lua/pac3/core/server/net_messages.lua index a4af99cc..e68804e2 100644 --- a/lua/pac3/core/server/net_messages.lua +++ b/lua/pac3/core/server/net_messages.lua @@ -2,10 +2,10 @@ util.AddNetworkString("pac.TogglePartDrawing") function pac.TogglePartDrawing(ent, b, who) --serverside interface to clientside function of the same name net.Start("pac.TogglePartDrawing") - net.WriteEntity(ent) - net.WriteBit(b) + net.WriteEntity(ent) + net.WriteBit(b) - if not who then + if not who then net.Broadcast() else net.Send(who) @@ -25,9 +25,9 @@ do -- button event local function broadcast_key(ply, key, down) if ply.pac_broadcast_buttons and ply.pac_broadcast_buttons[key] then net.Start("pac.BroadcastPlayerButton") - net.WriteEntity(ply) - net.WriteUInt(key, 8) - net.WriteBool(down) + net.WriteEntity(ply) + net.WriteUInt(key, 8) + net.WriteBool(down) net.Broadcast() end end diff --git a/lua/pac3/core/server/test_suite_backdoor.lua b/lua/pac3/core/server/test_suite_backdoor.lua index e97ab63e..8a42d1cb 100644 --- a/lua/pac3/core/server/test_suite_backdoor.lua +++ b/lua/pac3/core/server/test_suite_backdoor.lua @@ -13,7 +13,7 @@ net.Receive("pac3_test_sutie_backdoor", function(len, ply) local func = CompileString(lua_code, "pac3_test_sutie_backdoor") local res = {func()} net.Start("pac3_test_sutie_backdoor_receive_results") - net.WriteString(id) - net.WriteTable(res) + net.WriteString(id) + net.WriteTable(res) net.Send(ply) end) diff --git a/lua/pac3/core/shared/entity_mutator.lua b/lua/pac3/core/shared/entity_mutator.lua index ef9181c3..8c93c164 100644 --- a/lua/pac3/core/shared/entity_mutator.lua +++ b/lua/pac3/core/shared/entity_mutator.lua @@ -115,21 +115,21 @@ function emut.MutateEntity(ply, class_name, ent, ...) if CLIENT then if ply == LocalPlayer() and not suppress_send_to_server then net.Start("pac_entity_mutator") - net.WriteString(class_name) - net.WriteEntity(ent) - net.WriteBool(false) - mutator:WriteArguments(...) + net.WriteString(class_name) + net.WriteEntity(ent) + net.WriteBool(false) + mutator:WriteArguments(...) net.SendToServer(ply) end end if SERVER then net.Start("pac_entity_mutator") - net.WriteEntity(ply) - net.WriteString(class_name) - net.WriteEntity(ent) - net.WriteBool(false) - mutator:WriteArguments(...) + net.WriteEntity(ply) + net.WriteString(class_name) + net.WriteEntity(ent) + net.WriteBool(false) + mutator:WriteArguments(...) net.Broadcast(ply) end @@ -162,19 +162,19 @@ function emut.RestoreMutations(ply, class_name, ent) if CLIENT then if ply == LocalPlayer() and not suppress_send_to_server then net.Start("pac_entity_mutator") - net.WriteString(class_name) - net.WriteEntity(ent) - net.WriteBool(true) + net.WriteString(class_name) + net.WriteEntity(ent) + net.WriteBool(true) net.SendToServer(ply) end end if SERVER then net.Start("pac_entity_mutator") - net.WriteEntity(ply) - net.WriteString(class_name) - net.WriteEntity(ent) - net.WriteBool(true) + net.WriteEntity(ply) + net.WriteString(class_name) + net.WriteEntity(ent) + net.WriteBool(true) net.Broadcast() -- we also include the player who made the mutations, in case the server wants the arguments to be something else end @@ -313,11 +313,11 @@ if SERVER then function emut.ReplicateMutatorsForPlayer(ply) for _, mutator in ipairs(emut.GetAllMutators()) do net.Start("pac_entity_mutator") - net.WriteEntity(mutator.Owner) - net.WriteString(mutator.ClassName) - net.WriteEntity(mutator.Entity) - net.WriteBool(false) - mutator:WriteArguments(unpack(mutator.current_state)) + net.WriteEntity(mutator.Owner) + net.WriteString(mutator.ClassName) + net.WriteEntity(mutator.Entity) + net.WriteBool(false) + mutator:WriteArguments(unpack(mutator.current_state)) net.Send(ply) end end diff --git a/lua/pac3/core/shared/footsteps_fix.lua b/lua/pac3/core/shared/footsteps_fix.lua index f4ac94c3..4cce96b0 100644 --- a/lua/pac3/core/shared/footsteps_fix.lua +++ b/lua/pac3/core/shared/footsteps_fix.lua @@ -4,10 +4,10 @@ if game.SinglePlayer() then hook.Add("PlayerFootstep", "footstep_fix", function(ply, pos, _, snd, vol) net.Start("pac_footstep") - net.WriteEntity(ply) - net.WriteVector(pos) - net.WriteString(snd) - net.WriteFloat(vol) + net.WriteEntity(ply) + net.WriteVector(pos) + net.WriteString(snd) + net.WriteFloat(vol) net.Broadcast() end) end diff --git a/lua/pac3/editor/client/asset_browser.lua b/lua/pac3/editor/client/asset_browser.lua index f2a98019..9bdde66d 100644 --- a/lua/pac3/editor/client/asset_browser.lua +++ b/lua/pac3/editor/client/asset_browser.lua @@ -834,271 +834,271 @@ function pace.AssetBrowser(callback, browse_types_str, part_key) if code == MOUSE_RIGHT then play:Start() - else - pace.model_browser_callback(sound, "GAME") - end + else + pace.model_browser_callback(sound, "GAME") end - local label = line.Columns[1] - label:SetTextInset(play:GetWide() + 5, 0) - play.DoClick = function() - if - timer.Exists("pac_asset_browser_play") and - self:GetLines()[self:GetSelectedLine()] == line - then - play:Stop() - return - end - - self:ClearSelection() - self:SelectItem(line) - play:Start() - end - line.play = play + end + local label = line.Columns[1] + label:SetTextInset(play:GetWide() + 5, 0) + play.DoClick = function() + if + timer.Exists("pac_asset_browser_play") and + self:GetLines()[self:GetSelectedLine()] == line + then + play:Stop() + return end - function sound_name_list:AddSound(name) - AddGeneric(self, name) - end + self:ClearSelection() + self:SelectItem(line) + play:Start() + end + line.play = play + end - function sound_list:AddSound(path, pathid) - local sound_path = path:match("sound/(.+)") - AddGeneric(self, sound_path, file.Size(path, pathid)) - end + function sound_name_list:AddSound(name) + AddGeneric(self, name) + end - local select_me + function sound_list:AddSound(path, pathid) + local sound_path = path:match("sound/(.+)") + AddGeneric(self, sound_path, file.Size(path, pathid)) + end - if texture_view or material_view then - local node = root_node:AddNode("materials", "icon16/folder_database.png") - node.dir = "materials" - local viewPanel = vgui.Create("pac_AssetBrowser_ContentContainer", frame.PropPanel) - viewPanel:DockMargin(5, 0, 0, 0) - viewPanel:SetVisible(false) - viewPanel:SetZoomControls(zoom_controls) - node.propPanel = viewPanel + local select_me - for list_name, materials in pairs(pace.Materials) do - local list = node:AddNode(list_name) - list.dir = "materials" - list.propPanel = viewPanel - list.OnNodeSelected = function() - if viewPanel and viewPanel.currentNode and viewPanel.currentNode == list then return end - viewPanel:Clear(true) - viewPanel.currentNode = list + if texture_view or material_view then + local node = root_node:AddNode("materials", "icon16/folder_database.png") + node.dir = "materials" + local viewPanel = vgui.Create("pac_AssetBrowser_ContentContainer", frame.PropPanel) + viewPanel:DockMargin(5, 0, 0, 0) + viewPanel:SetVisible(false) + viewPanel:SetZoomControls(zoom_controls) + node.propPanel = viewPanel - if material_view then - for _, material_name in ipairs(materials) do - local path = "materials/" .. material_name .. ".vmt" + for list_name, materials in pairs(pace.Materials) do + local list = node:AddNode(list_name) + list.dir = "materials" + list.propPanel = viewPanel + list.OnNodeSelected = function() + if viewPanel and viewPanel.currentNode and viewPanel.currentNode == list then return end + viewPanel:Clear(true) + viewPanel.currentNode = list - if file_Exists(path, "GAME") then - create_material_icon(path, viewPanel) - end - end - end + if material_view then + for _, material_name in ipairs(materials) do + local path = "materials/" .. material_name .. ".vmt" - if texture_view then - local done = {} - local textures = {} - - for _, material_name in ipairs(materials) do - for k, v in pairs(get_material_keyvalues(material_name)) do - if type(v) == "ITexture" then - local name = v:GetName() - - if not done[name] then - done[name] = true - table.insert(textures, "materials/" .. name .. ".vtf") - end - end - end - end - - for _, path in ipairs(textures) do - viewPanel:Add(create_texture_icon(path)) - end - end - - tree:OnNodeSelected(list) - viewPanel.currentNode = list - end - - if - #browse_types == 1 and - list_name == "materials" and - (texture_view or material_view) - then - select_me = list - end - end - end - - if table.HasValue(browse_types, "models") then - local spawnlists = root_node:AddNode("spawnlists") - spawnlists.info = {} - spawnlists.info.id = 0 - spawnlists.dir = "models" - local has_game = {} - has_game[""] = true - - for k, v in pairs(engine.GetGames()) do - if v.mounted then - has_game[v.folder] = true - end - end - - local function fillNavBar(propTable, parentNode) - for k, v in table_sortedpairs(propTable, function(a, b) - return a.key < b.key - end) do - if v.parentid == parentNode.info.id and has_game[v.needsapp] then - local node = parentNode:AddNode(v.name, v.icon) - node:SetExpanded(true) - node.info = v - node.dir = "models" - node.propPanel = vgui.Create( - vgui.GetControlTable("ContentContainer") and - "ContentContainer" or - "pac_AssetBrowser_ContentContainer", - frame.PropPanel - ) - node.propPanel:DockMargin(5, 0, 0, 0) - node.propPanel:SetVisible(false) - parentNode.propPanel = node.propPanel - node.OnNodeSelected = function() - if not node.setup then - node.setup = true - - for i, object in table_sortedpairs(v.contents, function(a, b) - return a.key < b.key - end) do - if object.type == "model" then - node.propPanel:Add(create_model_icon(object.model)) - elseif object.type == "header" then - if not object.text or type(object.text) ~= "string" then return end - local label = vgui.Create("ContentHeader", node.propPanel) - label:SetText(object.text) - node.propPanel:Add(label) - end - end - end - - tree:OnNodeSelected(node) - end - - if #browse_types == 1 and v.name == "Construction Props" then - select_me = node - end - - fillNavBar(propTable, node) + if file_Exists(path, "GAME") then + create_material_icon(path, viewPanel) end end end - fillNavBar(spawnmenu.GetPropTable(), spawnlists) + if texture_view then + local done = {} + local textures = {} + + for _, material_name in ipairs(materials) do + for k, v in pairs(get_material_keyvalues(material_name)) do + if type(v) == "ITexture" then + local name = v:GetName() + + if not done[name] then + done[name] = true + table.insert(textures, "materials/" .. name .. ".vtf") + end + end + end + end + + for _, path in ipairs(textures) do + viewPanel:Add(create_texture_icon(path)) + end + end + + tree:OnNodeSelected(list) + viewPanel.currentNode = list end - if sound_view then - local node = root_node:AddNode("game sounds", "icon16/sound.png") + if + #browse_types == 1 and + list_name == "materials" and + (texture_view or material_view) + then + select_me = list + end + end + end + + if table.HasValue(browse_types, "models") then + local spawnlists = root_node:AddNode("spawnlists") + spawnlists.info = {} + spawnlists.info.id = 0 + spawnlists.dir = "models" + local has_game = {} + has_game[""] = true + + for k, v in pairs(engine.GetGames()) do + if v.mounted then + has_game[v.folder] = true + end + end + + local function fillNavBar(propTable, parentNode) + for k, v in table_sortedpairs(propTable, function(a, b) + return a.key < b.key + end) do + if v.parentid == parentNode.info.id and has_game[v.needsapp] then + local node = parentNode:AddNode(v.name, v.icon) + node:SetExpanded(true) + node.info = v + node.dir = "models" + node.propPanel = vgui.Create( + vgui.GetControlTable("ContentContainer") and + "ContentContainer" or + "pac_AssetBrowser_ContentContainer", + frame.PropPanel + ) + node.propPanel:DockMargin(5, 0, 0, 0) + node.propPanel:SetVisible(false) + parentNode.propPanel = node.propPanel + node.OnNodeSelected = function() + if not node.setup then + node.setup = true + + for i, object in table_sortedpairs(v.contents, function(a, b) + return a.key < b.key + end) do + if object.type == "model" then + node.propPanel:Add(create_model_icon(object.model)) + elseif object.type == "header" then + if not object.text or type(object.text) ~= "string" then return end + local label = vgui.Create("ContentHeader", node.propPanel) + label:SetText(object.text) + node.propPanel:Add(label) + end + end + end + + tree:OnNodeSelected(node) + end + + if #browse_types == 1 and v.name == "Construction Props" then + select_me = node + end + + fillNavBar(propTable, node) + end + end + end + + fillNavBar(spawnmenu.GetPropTable(), spawnlists) + end + + if sound_view then + local node = root_node:AddNode("game sounds", "icon16/sound.png") + node.dir = "sound names" + node.propPanel = sound_name_list + node.OnNodeSelected = function() + local categories = {} + + for _, sound_name in ipairs(sound.GetTable()) do + local category = sound_name:match("^(.-)%.") or + sound_name:match("^(.-)_") or + sound_name:match("^(.-)%u") + + if not category or category == nil then + category = "misc" + end + + categories[category] = categories[category] or {} + table.insert(categories[category], sound_name) + end + + local sorted = {} + + for name, sounds in pairs(categories) do + table.sort(sounds, function(a, b) + return a < b + end) + + table.insert(sorted, {name = name, sounds = sounds}) + end + + table.sort(sorted, function(a, b) + return a.name < b.name + end) + + for _, data in ipairs(sorted) do + local category_name, sounds = data.name, data.sounds + local node = node:AddNode(category_name, "icon16/sound.png") node.dir = "sound names" node.propPanel = sound_name_list node.OnNodeSelected = function() - local categories = {} + sound_name_list:Clear() - for _, sound_name in ipairs(sound.GetTable()) do - local category = sound_name:match("^(.-)%.") or - sound_name:match("^(.-)_") or - sound_name:match("^(.-)%u") - - if not category or category == nil then - category = "misc" - end - - categories[category] = categories[category] or {} - table.insert(categories[category], sound_name) + for _, sound_name in ipairs(sounds) do + sound_name_list:AddSound(sound_name) end - local sorted = {} - - for name, sounds in pairs(categories) do - table.sort(sounds, function(a, b) - return a < b - end) - - table.insert(sorted, {name = name, sounds = sounds}) - end - - table.sort(sorted, function(a, b) - return a.name < b.name - end) - - for _, data in ipairs(sorted) do - local category_name, sounds = data.name, data.sounds - local node = node:AddNode(category_name, "icon16/sound.png") - node.dir = "sound names" - node.propPanel = sound_name_list - node.OnNodeSelected = function() - sound_name_list:Clear() - - for _, sound_name in ipairs(sounds) do - sound_name_list:AddSound(sound_name) - end - - tree:OnNodeSelected(node) - end - end + tree:OnNodeSelected(node) end end + end + end - do -- mounted + do -- mounted local function addBrowseContent(viewPanel, node, name, icon, path, pathid) - local function on_select(self, node) - if viewPanel and viewPanel.currentNode and viewPanel.currentNode == node then return end - node.dir = self.dir - sound_list:Clear() - viewPanel:Clear(true) - viewPanel.currentNode = node - local searchString = node:GetFolder() + local function on_select(self, node) + if viewPanel and viewPanel.currentNode and viewPanel.currentNode == node then return end + node.dir = self.dir + sound_list:Clear() + viewPanel:Clear(true) + viewPanel.currentNode = node + local searchString = node:GetFolder() - if searchString == "" and #browse_types == 1 then - local count = 0 + if searchString == "" and #browse_types == 1 then + local count = 0 - local function find_recursive(path, pathid) - if count >= 500 then return end - local files_, folders_ = file.Find(path .. "/*", pathid) + local function find_recursive(path, pathid) + if count >= 500 then return end + local files_, folders_ = file.Find(path .. "/*", pathid) - if files_ then - for i, v in ipairs(files_) do - count = count + 1 - local path = path .. "/" .. v - path = path:gsub("^.-(" .. browse_types[1] .. "/.+)$", "%1") + if files_ then + for i, v in ipairs(files_) do + count = count + 1 + local path = path .. "/" .. v + path = path:gsub("^.-(" .. browse_types[1] .. "/.+)$", "%1") - if browse_types[1] == "models" then - if not IsUselessModel(path) then - viewPanel:Add(create_model_icon(path, pathid)) - end - elseif browse_types[1] == "materials" then - if path:find("%.vmt$") then - if material_view then - create_material_icon(path, viewPanel) - end - elseif texture_view then - viewPanel:Add(create_texture_icon(path, pathid)) - end - elseif browse_types[1] == "sound" then - sound_list:AddSound(path, pathid) + if browse_types[1] == "models" then + if not IsUselessModel(path) then + viewPanel:Add(create_model_icon(path, pathid)) + end + elseif browse_types[1] == "materials" then + if path:find("%.vmt$") then + if material_view then + create_material_icon(path, viewPanel) end + elseif texture_view then + viewPanel:Add(create_texture_icon(path, pathid)) end - - for i, v in ipairs(folders_) do - find_recursive(path .. "/" .. v, pathid) - end + elseif browse_types[1] == "sound" then + sound_list:AddSound(path, pathid) end end - find_recursive(path .. browse_types[1], node:GetPathID()) - else - local files, folders = file.Find(searchString .. "/*", node:GetPathID()) + for i, v in ipairs(folders_) do + find_recursive(path .. "/" .. v, pathid) + end + end + end - if files then + find_recursive(path .. browse_types[1], node:GetPathID()) + else + local files, folders = file.Find(searchString .. "/*", node:GetPathID()) + + if files then --[[ for _, dir in pairs(folders) do @@ -1126,496 +1126,496 @@ function pace.AssetBrowser(callback, browse_types_str, part_key) end ]] if self.dir == "models" then - for k, v in pairs(files) do - local path = node:GetFolder() .. "/" .. v + for k, v in pairs(files) do + local path = node:GetFolder() .. "/" .. v - if not path:StartWith("models/pac3_cache/") then - if not IsUselessModel(path) then - viewPanel:Add(create_model_icon(path, pathid)) - end - end - end - elseif self.dir == "materials" then - for k, v in pairs(files) do - local path = node:GetFolder() .. "/" .. v - - if v:find("%.vmt$") then - if material_view then - create_material_icon(path, viewPanel) - end - elseif texture_view then - viewPanel:Add(create_texture_icon(path, pathid)) - end - end - elseif self.dir == "sound" then - for k, v in pairs(files) do - local path = node:GetFolder() .. "/" .. v - sound_list:AddSound(path, pathid) + if not path:StartWith("models/pac3_cache/") then + if not IsUselessModel(path) then + viewPanel:Add(create_model_icon(path, pathid)) end end end - end + elseif self.dir == "materials" then + for k, v in pairs(files) do + local path = node:GetFolder() .. "/" .. v - if self.dir == "sound" then - node.propPanel = sound_list - else - node.propPanel = viewPanel - end - - tree:OnNodeSelected(node) - viewPanel.currentNode = node - end - - node = node:AddNode(name, icon) - node:SetFolder("") - node:SetPathID(pathid) - node.viewPanel = viewPanel - - for _, dir in ipairs(browse_types) do - local files, folders = file.Find(path .. dir .. "/*", pathid) - - if files and (files[1] or folders[1]) then - local parent = node - local node = node:AddFolder(dir, path .. dir, pathid, false) - node.dir = dir - node.OnNodeSelected = on_select - - if - not select_me and - #browse_types == 1 and - name == "all" and - browse_types[1] == dir and - dir ~= "models" - then - select_me = node - end - - if - not select_me and - #browse_types == 3 and - name == "all" and - dir == "materials" - then - select_me = node - end - end - end - - node.OnNodeSelected = on_select - end - - local viewPanel = vgui.Create("pac_AssetBrowser_ContentContainer", frame.PropPanel) - viewPanel:DockMargin(5, 0, 0, 0) - viewPanel:SetVisible(false) - viewPanel:SetZoomControls(zoom_controls) - - do - local special = { - { - title = "all", - folder = "GAME", - icon = "games/16/all.png", - }, - { - title = "downloaded", - folder = "DOWNLOAD", - icon = "materials/icon16/server_go.png", - }, - { - title = "workshop", - folder = "WORKSHOP", - icon = "materials/icon16/plugin.png", - }, - { - title = "thirdparty", - folder = "THIRDPARTY", - icon = "materials/icon16/folder_brick.png", - }, - { - title = "mod", - folder = "MOD", - icon = "materials/icon16/folder_brick.png", - }, - } - - for _, info in ipairs(special) do - addBrowseContent( - viewPanel, - root_node, - info.title, - info.icon, - "", - info.folder - ) - end - end - - do - local games = engine.GetGames() - table.insert( - games, - { - title = "Garry's Mod", - folder = "garrysmod", - mounted = true, - } - ) - - for _, game in table_sortedpairs(games, function(a, b) - return a.val.title < b.val.title - end) do - if game.mounted then - addBrowseContent( - viewPanel, - root_node, - game.title, - "games/16/" .. (game.icon or game.folder) .. ".png", - "", - game.folder - ) - end - end - end - - local node = root_node:AddNode("addons") - - for _, addon in table_sortedpairs(engine.GetAddons(), function(a, b) - return a.val.title < b.val.title - end) do - if addon.file:StartWith("addons/") then - local _, dirs = file.Find("*", addon.title) - - if - table.HasValue(dirs, "materials") or - table.HasValue(dirs, "models") or - table.HasValue(dirs, "sound") - then - addBrowseContent( - viewPanel, - node, - addon.title, - "icon16/bricks.png", - "", - addon.title - ) - end - end - end - - local _, folders = file.Find("addons/*", "MOD") - - for _, path in ipairs(folders) do - if - file.IsDir("addons/" .. path .. "/materials", "MOD") or - file.IsDir("addons/" .. path .. "/sound", "MOD") or - file.IsDir("addons/" .. path .. "/models", "MOD") - then - addBrowseContent( - viewPanel, - node, - path, - "icon16/folder.png", - "addons/" .. path .. "/", - "MOD" - ) - end - end - end - - local model_view = vgui.Create("pac_AssetBrowser_ContentContainer", frame.PropPanel) - model_view:DockMargin(5, 0, 0, 0) - model_view:SetVisible(false) - model_view:SetZoomControls(zoom_controls) - local search = vgui.Create("DTextEntry", left_panel) - search:Dock(TOP) - search:SetTooltip("Press enter to search") - search.propPanel = model_view - search.model_view = model_view - search.delay_functions = {} - - file_menu:AddOption(L("build search cache"), function() - search:StartSearch("", "models/", {}, "GAME", function(path, pathid) - end) - - search:StartSearch("", "sound/", {}, "GAME", function(path, pathid) - end) - - search:StartSearch("", "materials/", {}, "GAME", function(path, pathid) - end) - end) - - local cancel = vgui.Create("DImageButton", search) - cancel:SetImage(pace.MiscIcons.clear) - cancel:SetSize(16, 16) - cancel.DoClick = function() - search:Cancel() - end - cancel:SetVisible(false) - - do - local old = search.OnGetFocus - - function search:OnGetFocus() - if self:GetValue() == self.default_text then - self:SetValue("") - end - - old(self) - end - end - - do - local old = search.OnLoseFocus - - function search:OnLoseFocus() - if self:GetValue() == "" then - self:SetValue(self.default_text) - end - - old(self) - end - end - - local function find(path, pathid) - local key = path .. pathid - if pac.asset_browser_cache[key] then return unpack(pac.asset_browser_cache[key]) end - local files, folders = file.Find(path, pathid) - pac.asset_browser_cache[key] = {files, folders} - return files, folders - end - - function search:PerformLayout() - cancel:SetPos(self:GetWide() - 16 - 2, 2) - end - - function search:StartSearch(search_text, folder, extensions, pathid, cb) - cancel:SetVisible(true) - local files, folders = find(folder .. "*", pathid) - self.searched = true - - if files then - update_title(table.Count(self.delay_functions) .. " directories left - " .. folder .. "*") - - for k, v in ipairs(files) do - local file = folder .. v - - for _, ext in ipairs(extensions) do - if v:EndsWith(ext) and file:find(search_text, nil, true) then - local func = function() - return cb(file, pathid) + if v:find("%.vmt$") then + if material_view then + create_material_icon(path, viewPanel) + end + elseif texture_view then + viewPanel:Add(create_texture_icon(path, pathid)) end - self.delay_functions[func] = func - - break end - end - end - - for k, v in ipairs(folders) do - if v ~= "pac3_cache" then - local func = function() - self:StartSearch(search_text, folder .. v .. "/", extensions, pathid, cb) + elseif self.dir == "sound" then + for k, v in pairs(files) do + local path = node:GetFolder() .. "/" .. v + sound_list:AddSound(path, pathid) end - self.delay_functions[func] = func end end end - end - function search:Stop() - cancel:SetVisible(false) - self.delay_functions = {} - self.searched = false - end - - function search:Cancel(why) - self:Stop() - - if why then - update_title("search canceled: " .. why) + if self.dir == "sound" then + node.propPanel = sound_list else - update_title("search canceled") + node.propPanel = viewPanel + end + + tree:OnNodeSelected(node) + viewPanel.currentNode = node + end + + node = node:AddNode(name, icon) + node:SetFolder("") + node:SetPathID(pathid) + node.viewPanel = viewPanel + + for _, dir in ipairs(browse_types) do + local files, folders = file.Find(path .. dir .. "/*", pathid) + + if files and (files[1] or folders[1]) then + local parent = node + local node = node:AddFolder(dir, path .. dir, pathid, false) + node.dir = dir + node.OnNodeSelected = on_select + + if + not select_me and + #browse_types == 1 and + name == "all" and + browse_types[1] == dir and + dir ~= "models" + then + select_me = node + end + + if + not select_me and + #browse_types == 3 and + name == "all" and + dir == "materials" + then + select_me = node + end end end - function search:Think() - if input.IsKeyDown(KEY_ESCAPE) then - self:Cancel() + node.OnNodeSelected = on_select + end + + local viewPanel = vgui.Create("pac_AssetBrowser_ContentContainer", frame.PropPanel) + viewPanel:DockMargin(5, 0, 0, 0) + viewPanel:SetVisible(false) + viewPanel:SetZoomControls(zoom_controls) + + do + local special = { + { + title = "all", + folder = "GAME", + icon = "games/16/all.png", + }, + { + title = "downloaded", + folder = "DOWNLOAD", + icon = "materials/icon16/server_go.png", + }, + { + title = "workshop", + folder = "WORKSHOP", + icon = "materials/icon16/plugin.png", + }, + { + title = "thirdparty", + folder = "THIRDPARTY", + icon = "materials/icon16/folder_brick.png", + }, + { + title = "mod", + folder = "MOD", + icon = "materials/icon16/folder_brick.png", + }, + } + + for _, info in ipairs(special) do + addBrowseContent( + viewPanel, + root_node, + info.title, + info.icon, + "", + info.folder + ) + end + end + + do + local games = engine.GetGames() + table.insert( + games, + { + title = "Garry's Mod", + folder = "garrysmod", + mounted = true, + } + ) + + for _, game in table_sortedpairs(games, function(a, b) + return a.val.title < b.val.title + end) do + if game.mounted then + addBrowseContent( + viewPanel, + root_node, + game.title, + "games/16/" .. (game.icon or game.folder) .. ".png", + "", + game.folder + ) + end + end + end + + local node = root_node:AddNode("addons") + + for _, addon in table_sortedpairs(engine.GetAddons(), function(a, b) + return a.val.title < b.val.title + end) do + if addon.file:StartWith("addons/") then + local _, dirs = file.Find("*", addon.title) + + if + table.HasValue(dirs, "materials") or + table.HasValue(dirs, "models") or + table.HasValue(dirs, "sound") + then + addBrowseContent( + viewPanel, + node, + addon.title, + "icon16/bricks.png", + "", + addon.title + ) + end + end + end + + local _, folders = file.Find("addons/*", "MOD") + + for _, path in ipairs(folders) do + if + file.IsDir("addons/" .. path .. "/materials", "MOD") or + file.IsDir("addons/" .. path .. "/sound", "MOD") or + file.IsDir("addons/" .. path .. "/models", "MOD") + then + addBrowseContent( + viewPanel, + node, + path, + "icon16/folder.png", + "addons/" .. path .. "/", + "MOD" + ) + end + end + end + + local model_view = vgui.Create("pac_AssetBrowser_ContentContainer", frame.PropPanel) + model_view:DockMargin(5, 0, 0, 0) + model_view:SetVisible(false) + model_view:SetZoomControls(zoom_controls) + local search = vgui.Create("DTextEntry", left_panel) + search:Dock(TOP) + search:SetTooltip("Press enter to search") + search.propPanel = model_view + search.model_view = model_view + search.delay_functions = {} + + file_menu:AddOption(L("build search cache"), function() + search:StartSearch("", "models/", {}, "GAME", function(path, pathid) + end) + + search:StartSearch("", "sound/", {}, "GAME", function(path, pathid) + end) + + search:StartSearch("", "materials/", {}, "GAME", function(path, pathid) + end) + end) + + local cancel = vgui.Create("DImageButton", search) + cancel:SetImage(pace.MiscIcons.clear) + cancel:SetSize(16, 16) + cancel.DoClick = function() + search:Cancel() + end + cancel:SetVisible(false) + + do + local old = search.OnGetFocus + + function search:OnGetFocus() + if self:GetValue() == self.default_text then + self:SetValue("") + end + + old(self) + end + end + + do + local old = search.OnLoseFocus + + function search:OnLoseFocus() + if self:GetValue() == "" then + self:SetValue(self.default_text) + end + + old(self) + end + end + + local function find(path, pathid) + local key = path .. pathid + if pac.asset_browser_cache[key] then return unpack(pac.asset_browser_cache[key]) end + local files, folders = file.Find(path, pathid) + pac.asset_browser_cache[key] = {files, folders} + return files, folders + end + + function search:PerformLayout() + cancel:SetPos(self:GetWide() - 16 - 2, 2) + end + + function search:StartSearch(search_text, folder, extensions, pathid, cb) + cancel:SetVisible(true) + local files, folders = find(folder .. "*", pathid) + self.searched = true + + if files then + update_title(table.Count(self.delay_functions) .. " directories left - " .. folder .. "*") + + for k, v in ipairs(files) do + local file = folder .. v + + for _, ext in ipairs(extensions) do + if v:EndsWith(ext) and file:find(search_text, nil, true) then + local func = function() + return cb(file, pathid) + end + self.delay_functions[func] = func + + break + end + end + end + + for k, v in ipairs(folders) do + if v ~= "pac3_cache" then + local func = function() + self:StartSearch(search_text, folder .. v .. "/", extensions, pathid, cb) + end + self.delay_functions[func] = func + end + end + end + end + + function search:Stop() + cancel:SetVisible(false) + self.delay_functions = {} + self.searched = false + end + + function search:Cancel(why) + self:Stop() + + if why then + update_title("search canceled: " .. why) + else + update_title("search canceled") + end + end + + function search:Think() + if input.IsKeyDown(KEY_ESCAPE) then + self:Cancel() + return + end + + if input.IsControlDown() and input.IsKeyDown(KEY_F) then + self:RequestFocus() + end + + local i = 0 + + for key, func in pairs(self.delay_functions) do + i = i + 1 + local ok, reason = func() + + if ok == false then + self:Cancel(reason) + return + end + + self.delay_functions[func] = nil + if i > 50 then break end + end + + if i == 0 and self.searched then + self:Stop() + update_title() + file.Write("pac3_cache/pac_asset_browser_index.txt", util.TableToJSON(pac.asset_browser_cache)) + end + + if frame.dir then + if not self:IsEnabled() then + self:SetEnabled(true) + end + + local change = false + + if self:GetValue() == "" or self:GetValue() == self.default_text then + change = true + end + + local pathid = frame.pathid or "GAME" + + if pathid == "GAME" then + pathid = "all" + end + + self.default_text = L("search " .. pathid .. "/" .. frame.dir .. "/*") + + if change then + self:SetValue(self.default_text) + end + else + self:SetValue("") + + if self:IsEnabled() then + self:SetEnabled(false) + end + end + end + + function search:OnEnter() + if self:GetValue() == "" then return end + local count = 0 + local pathid = frame.pathid or "GAME" + local dir = frame.dir + + if dir == "models" then + self.propPanel = self.model_view + self.propPanel:Clear() + + self:StartSearch(self:GetValue(), "models/", {".mdl"}, pathid, function(path, pathid) + if count >= 500 then return false, "too many results (" .. count .. ")" end + count = count + 1 + + if not IsUselessModel(path) then + self.propPanel:Add(create_model_icon(path, pathid)) + end + end) + elseif dir == "sound" then + self.propPanel = sound_list + self.propPanel:Clear() + + self:StartSearch(self:GetValue(), "sound/", {".wav", ".mp3", ".ogg"}, pathid, function(path, pathid) + if count >= 1500 then return false, "too many results (" .. count .. ")" end + count = count + 1 + sound_list:AddSound(path, pathid) + end) + elseif dir == "materials" then + self.propPanel = self.model_view + self.propPanel:Clear() + + self:StartSearch(self:GetValue(), "materials/", {".vmt", ".vtf", ".png"}, pathid, function(path, pathid) + if count >= 750 then return false, "too many results (" .. count .. ")" end + + if path:EndsWith(".vmt") then + if material_view then + count = count + 1 + create_material_icon(path, self.propPanel) + end + elseif texture_view then + self.propPanel:Add(create_texture_icon(path, pathid)) + count = count + 1 + end + end) + elseif dir == "sound names" then + self.propPanel = sound_name_list + self.propPanel:Clear() + local search_text = self:GetValue() + + for _, name in ipairs(sound.GetTable()) do + if count >= 1500 then + update_title("too many results (" .. count .. ")") return end - if input.IsControlDown() and input.IsKeyDown(KEY_F) then - self:RequestFocus() + if name:find(search_text, nil, true) then + count = count + 1 + sound_name_list:AddSound(name) end - - local i = 0 - - for key, func in pairs(self.delay_functions) do - i = i + 1 - local ok, reason = func() - - if ok == false then - self:Cancel(reason) - return - end - - self.delay_functions[func] = nil - if i > 50 then break end - end - - if i == 0 and self.searched then - self:Stop() - update_title() - file.Write("pac3_cache/pac_asset_browser_index.txt", util.TableToJSON(pac.asset_browser_cache)) - end - - if frame.dir then - if not self:IsEnabled() then - self:SetEnabled(true) - end - - local change = false - - if self:GetValue() == "" or self:GetValue() == self.default_text then - change = true - end - - local pathid = frame.pathid or "GAME" - - if pathid == "GAME" then - pathid = "all" - end - - self.default_text = L("search " .. pathid .. "/" .. frame.dir .. "/*") - - if change then - self:SetValue(self.default_text) - end - else - self:SetValue("") - - if self:IsEnabled() then - self:SetEnabled(false) - end - end - end - - function search:OnEnter() - if self:GetValue() == "" then return end - local count = 0 - local pathid = frame.pathid or "GAME" - local dir = frame.dir - - if dir == "models" then - self.propPanel = self.model_view - self.propPanel:Clear() - - self:StartSearch(self:GetValue(), "models/", {".mdl"}, pathid, function(path, pathid) - if count >= 500 then return false, "too many results (" .. count .. ")" end - count = count + 1 - - if not IsUselessModel(path) then - self.propPanel:Add(create_model_icon(path, pathid)) - end - end) - elseif dir == "sound" then - self.propPanel = sound_list - self.propPanel:Clear() - - self:StartSearch(self:GetValue(), "sound/", {".wav", ".mp3", ".ogg"}, pathid, function(path, pathid) - if count >= 1500 then return false, "too many results (" .. count .. ")" end - count = count + 1 - sound_list:AddSound(path, pathid) - end) - elseif dir == "materials" then - self.propPanel = self.model_view - self.propPanel:Clear() - - self:StartSearch(self:GetValue(), "materials/", {".vmt", ".vtf", ".png"}, pathid, function(path, pathid) - if count >= 750 then return false, "too many results (" .. count .. ")" end - - if path:EndsWith(".vmt") then - if material_view then - count = count + 1 - create_material_icon(path, self.propPanel) - end - elseif texture_view then - self.propPanel:Add(create_texture_icon(path, pathid)) - count = count + 1 - end - end) - elseif dir == "sound names" then - self.propPanel = sound_name_list - self.propPanel:Clear() - local search_text = self:GetValue() - - for _, name in ipairs(sound.GetTable()) do - if count >= 1500 then - update_title("too many results (" .. count .. ")") - return - end - - if name:find(search_text, nil, true) then - count = count + 1 - sound_name_list:AddSound(name) - end - end - end - - self.dir = dir - self.pathid = pathid - tree:OnNodeSelected(self) - end - - file_menu:AddSpacer() - file_menu:AddOption(L("exit"), function() - frame:Remove() - end):SetImage(pace.MiscIcons.exit) - - if select_me then - select_me:GetParentNode():SetExpanded(true) - select_me:SetExpanded(true) - tree:SetSelectedItem(select_me) - end - - frame:MakePopup() - end - - if pace.model_browser and pace.model_browser:IsValid() then - local visible = pace.model_browser:IsVisible() - pace.model_browser:Remove() - - if visible then - pace.AssetBrowser(function(...) - print(...) - return false - end) end end - concommand.Add("pac_asset_browser", function(_, _, args) - pace.AssetBrowser(function(path) - SetClipboardText(path) - update_title("copied " .. path .. " to clipboard!") - return false - end, args[1] and table.concat(args, ";")) + self.dir = dir + self.pathid = pathid + tree:OnNodeSelected(self) + end - pace.model_browser:SetSize(ScrW() / 1.25, ScrH() / 1.25) - pace.model_browser:Center() + file_menu:AddSpacer() + file_menu:AddOption(L("exit"), function() + frame:Remove() + end):SetImage(pace.MiscIcons.exit) + + if select_me then + select_me:GetParentNode():SetExpanded(true) + select_me:SetExpanded(true) + tree:SetSelectedItem(select_me) + end + + frame:MakePopup() +end + +if pace.model_browser and pace.model_browser:IsValid() then + local visible = pace.model_browser:IsVisible() + pace.model_browser:Remove() + + if visible then + pace.AssetBrowser(function(...) + print(...) + return false end) + end +end - list.Set( - "DesktopWindows", - "PACAssetBrowser", - { - title = "Asset Browser", - icon = "icon16/images.png", - width = 960, - height = 700, - onewindow = true, - init = function(icn, pnl) - pnl:Remove() - RunConsoleCommand("pac_asset_browser") - end, - } - ) +concommand.Add("pac_asset_browser", function(_, _, args) + pace.AssetBrowser(function(path) + SetClipboardText(path) + update_title("copied " .. path .. " to clipboard!") + return false + end, args[1] and table.concat(args, ";")) + + pace.model_browser:SetSize(ScrW() / 1.25, ScrH() / 1.25) + pace.model_browser:Center() +end) + +list.Set( + "DesktopWindows", + "PACAssetBrowser", + { + title = "Asset Browser", + icon = "icon16/images.png", + width = 960, + height = 700, + onewindow = true, + init = function(icn, pnl) + pnl:Remove() + RunConsoleCommand("pac_asset_browser") + end, + } +) diff --git a/lua/pac3/editor/client/init.lua b/lua/pac3/editor/client/init.lua index 71d7b062..2c707d58 100644 --- a/lua/pac3/editor/client/init.lua +++ b/lua/pac3/editor/client/init.lua @@ -269,7 +269,7 @@ end do function pace.SetInPAC3Editor(b) net.Start("pac_in_editor") - net.WriteBit(b) + net.WriteBit(b) net.SendToServer() end @@ -360,9 +360,9 @@ do if lastViewPos == pos and lastViewAngle == ang and lastTargetPos == target_pos then return end lastViewPos, lastViewAngle, lastTargetPos = pos, ang, target_pos net.Start("pac_in_editor_posang", true) - net.WriteVector(pos) - net.WriteAngle(ang) - net.WriteVector(target_pos) + net.WriteVector(pos) + net.WriteAngle(ang) + net.WriteVector(target_pos) net.SendToServer() end) end diff --git a/lua/pac3/editor/client/wear.lua b/lua/pac3/editor/client/wear.lua index 7108ef33..5e330cfc 100644 --- a/lua/pac3/editor/client/wear.lua +++ b/lua/pac3/editor/client/wear.lua @@ -37,11 +37,11 @@ do -- to server net.Receive("pac_update_playerfilter", function() local filter = assemblePlayerFilter() net.Start("pac_update_playerfilter") - net.WriteUInt(#filter, 8) + net.WriteUInt(#filter, 8) - for i, id in ipairs(filter) do - net.WriteString(id) - end + for i, id in ipairs(filter) do + net.WriteString(id) + end net.SendToServer() end) @@ -83,12 +83,12 @@ do -- to server data.owner = part:GetPlayerOwner() data.wear_filter = assemblePlayerFilter() net.Start("pac_submit") - local bytes, err = net_write_table(data) + local bytes, err = net_write_table(data) - if not bytes then - pace.Notify(false, "unable to transfer data to server: " .. tostring(err or "too big"), part:GetName()) - return false - end + if not bytes then + pace.Notify(false, "unable to transfer data to server: " .. tostring(err or "too big"), part:GetName()) + return false + end net.SendToServer() pac.Message(("Transmitting outfit %q to server (%s)"):format(part.Name or part.ClassName or "", string.NiceSize(bytes))) @@ -107,12 +107,12 @@ do -- to server 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) - return false - end + if ret == nil then + pace.Notify(false, "unable to transfer data to server: " .. tostring(err or "too big"), name) + return false + end net.SendToServer() return true diff --git a/lua/pac3/editor/server/bans.lua b/lua/pac3/editor/server/bans.lua index 1f427640..6d887fd6 100644 --- a/lua/pac3/editor/server/bans.lua +++ b/lua/pac3/editor/server/bans.lua @@ -29,8 +29,8 @@ function pace.Ban(ply) timer.Simple(1, function() -- made it a timer because the ConCommand don't run fast enough. - Bizzclaw net.Start("pac_submit_acknowledged") - net.WriteBool(false) - net.WriteString("You have been banned from using pac!") + net.WriteBool(false) + net.WriteString("You have been banned from using pac!") net.Send(ply) local bans = get_bans() @@ -48,8 +48,8 @@ end function pace.Unban(ply) net.Start("pac_submit_acknowledged") - net.WriteBool(true) - net.WriteString("You are now permitted to use pac!") + net.WriteBool(true) + net.WriteString("You are now permitted to use pac!") net.Send(ply) local bans = get_bans() diff --git a/lua/pac3/editor/server/init.lua b/lua/pac3/editor/server/init.lua index a1585150..7992c6d9 100644 --- a/lua/pac3/editor/server/init.lua +++ b/lua/pac3/editor/server/init.lua @@ -48,13 +48,13 @@ do local ang = net.ReadAngle() local part_pos = net.ReadVector() net.Start("pac_in_editor_posang", true) - net.WriteEntity(ply) - net.WriteVector(pos) - net.WriteAngle(ang) - net.WriteVector(part_pos) - net.SendPVS(ply:GetPos()) - end) - end + net.WriteEntity(ply) + net.WriteVector(pos) + net.WriteAngle(ang) + net.WriteVector(part_pos) + net.SendPVS(ply:GetPos()) + end) +end - CreateConVar("has_pac3_editor", "1", {FCVAR_NOTIFY}) - resource.AddSingleFile("materials/icon64/pac3.png") +CreateConVar("has_pac3_editor", "1", {FCVAR_NOTIFY}) +resource.AddSingleFile("materials/icon64/pac3.png") diff --git a/lua/pac3/editor/server/spawnmenu.lua b/lua/pac3/editor/server/spawnmenu.lua index eecf0226..152b6bd7 100644 --- a/lua/pac3/editor/server/spawnmenu.lua +++ b/lua/pac3/editor/server/spawnmenu.lua @@ -8,7 +8,7 @@ function pace.SpawnPart(ply, model) if model then if IsValid(ply) and ply:GetNWBool("in pac3 editor") then net.Start("pac_spawn_part") - net.WriteString(model) + net.WriteString(model) net.Send(ply) return false end diff --git a/lua/pac3/editor/server/wear.lua b/lua/pac3/editor/server/wear.lua index 7ceb4387..092e45a0 100644 --- a/lua/pac3/editor/server/wear.lua +++ b/lua/pac3/editor/server/wear.lua @@ -311,17 +311,17 @@ function pace.SubmitPart(data, filter) if ret == nil then net.Start("pac_submit") - local bytes, err = net_write_table(data) + local bytes, err = net_write_table(data) - if not bytes then - ErrorNoHalt( - "[PAC3] Outfit broadcast failed for " .. tostring(data.owner) .. ": " .. tostring(err) .. "\n" - ) + if not bytes then + ErrorNoHalt( + "[PAC3] Outfit broadcast failed for " .. tostring(data.owner) .. ": " .. tostring(err) .. "\n" + ) - if data.owner and data.owner:IsValid() then - data.owner:ChatPrint("[PAC3] ERROR: Could not broadcast your outfit: " .. tostring(err)) - end - else + if data.owner and data.owner:IsValid() then + data.owner:ChatPrint("[PAC3] ERROR: Could not broadcast your outfit: " .. tostring(err)) + end + else net.Send(players) end end @@ -355,9 +355,9 @@ function pace.SubmitPartNotify(data) end net.Start("pac_submit_acknowledged") - net.WriteBool(allowed) - net.WriteString(reason or "") - net.WriteString(data.part.self.Name or "no name") + net.WriteBool(allowed) + net.WriteString(reason or "") + net.WriteString(data.part.self.Name or "no name") net.Send(data.owner) hook.Run( "PACSubmitAcknowledged", diff --git a/lua/pac3/extra/client/contraption.lua b/lua/pac3/extra/client/contraption.lua index 31c9b901..1d1b019d 100644 --- a/lua/pac3/extra/client/contraption.lua +++ b/lua/pac3/extra/client/contraption.lua @@ -3,7 +3,7 @@ local L = pace.LanguageString pace.AddTool(L("spawn as props"), function(part) local data = pacx.PartToContraptionData(part) net.Start("pac_to_contraption") - net.WriteTable(data) + net.WriteTable(data) net.SendToServer() end) diff --git a/lua/pac3/extra/server/contraption.lua b/lua/pac3/extra/server/contraption.lua index 6fd93799..1f4e767f 100644 --- a/lua/pac3/extra/server/contraption.lua +++ b/lua/pac3/extra/server/contraption.lua @@ -56,8 +56,8 @@ end) pace.PCallNetReceive(net.Receive, "pac_to_contraption", function(len, ply) if not pac_to_contraption_allow:GetBool() then net.Start("pac_submit_acknowledged") - net.WriteBool(false) - net.WriteString("This server does not allow spawning PAC contraptions.") + net.WriteBool(false) + net.WriteString("This server does not allow spawning PAC contraptions.") net.Send(ply) return end @@ -80,8 +80,8 @@ pace.PCallNetReceive(net.Receive, "pac_to_contraption", function(len, ply) if count > max then net.Start("pac_submit_acknowledged") - net.WriteBool(false) - net.WriteString("You can only spawn ", max, " props at a time!") + net.WriteBool(false) + net.WriteString("You can only spawn ", max, " props at a time!") net.Send(ply) pac.Message( ply, diff --git a/lua/pac3/extra/shared/modifiers.lua b/lua/pac3/extra/shared/modifiers.lua index a2fb59af..8e0d7f9e 100644 --- a/lua/pac3/extra/shared/modifiers.lua +++ b/lua/pac3/extra/shared/modifiers.lua @@ -19,8 +19,8 @@ function pacx.AddServerModifier(id, change_callback) if SERVER then -- https://github.com/Facepunch/garrysmod-issues/issues/3740 net.Start("pacx_modifiers_change") - net.WriteString(id) - net.WriteBool(enable) + net.WriteString(id) + net.WriteBool(enable) net.Broadcast() end end, id .. "_change") diff --git a/lua/pac3/extra/shared/modifiers/model.lua b/lua/pac3/extra/shared/modifiers/model.lua index a543a293..48332b1c 100644 --- a/lua/pac3/extra/shared/modifiers/model.lua +++ b/lua/pac3/extra/shared/modifiers/model.lua @@ -14,8 +14,8 @@ end) function pacx.SetModelOnServer(ent, path) path = path or "" net.Start("pacx_setmodel") - net.WriteEntity(ent) - net.WriteString(path) + net.WriteEntity(ent) + net.WriteString(path) net.SendToServer() end diff --git a/lua/pac3/extra/shared/modifiers/size.lua b/lua/pac3/extra/shared/modifiers/size.lua index 5f5e9801..90252e45 100644 --- a/lua/pac3/extra/shared/modifiers/size.lua +++ b/lua/pac3/extra/shared/modifiers/size.lua @@ -47,9 +47,9 @@ end function pacx.SetEntitySizeOnServer(ent, multiplier, other) net.Start("pacx_size") - net.WriteEntity(ent) - net.WriteDouble(multiplier or 1) - write_other(other) + net.WriteEntity(ent) + net.WriteDouble(multiplier or 1) + write_other(other) net.SendToServer() end diff --git a/lua/pac3/extra/shared/projectiles.lua b/lua/pac3/extra/shared/projectiles.lua index d0f3939f..7ae1e97d 100644 --- a/lua/pac3/extra/shared/projectiles.lua +++ b/lua/pac3/extra/shared/projectiles.lua @@ -246,294 +246,294 @@ do -- projectile entity if not self.part_data then return end if not self.projectile_owner:IsValid() then return end net.Start("pac_projectile_collide_event", true) - net.WriteEntity(self) - net.WriteTable({}) -- nothing for now + net.WriteEntity(self) + net.WriteTable({}) -- nothing for now net.SendPVS(data.HitPos) - local ply = self.projectile_owner + local ply = self.projectile_owner - if self.part_data.Bounce ~= 0 then - phys:SetVelocity( - data.OurOldVelocity - 2 * (data.HitNormal:Dot(data.OurOldVelocity) * data.HitNormal) * self.part_data.Bounce - ) - end + if self.part_data.Bounce ~= 0 then + phys:SetVelocity( + data.OurOldVelocity - 2 * (data.HitNormal:Dot(data.OurOldVelocity) * data.HitNormal) * self.part_data.Bounce + ) + end - if self.part_data.Sticky and (self.part_data.Bounce == 0 or not data.HitEntity:IsWorld()) then - phys:SetVelocity(Vector(0, 0, 0)) - phys:Sleep() - phys:EnableMotion(false) - phys:EnableCollisions(false) + if self.part_data.Sticky and (self.part_data.Bounce == 0 or not data.HitEntity:IsWorld()) then + phys:SetVelocity(Vector(0, 0, 0)) + phys:Sleep() + phys:EnableMotion(false) + phys:EnableCollisions(false) - timer.Simple(0, function() - if self:IsValid() then - self:SetCollisionGroup(COLLISION_GROUP_DEBRIS) - end - end) + timer.Simple(0, function() + if self:IsValid() then + self:SetCollisionGroup(COLLISION_GROUP_DEBRIS) + end + end) - if not data.HitEntity:IsWorld() then - if data.HitEntity:GetBoneCount() then - local closest = {} + if not data.HitEntity:IsWorld() then + if data.HitEntity:GetBoneCount() then + local closest = {} - for id = 1, data.HitEntity:GetBoneCount() do - local pos = data.HitEntity:GetBonePosition(id) + for id = 1, data.HitEntity:GetBoneCount() do + local pos = data.HitEntity:GetBonePosition(id) - if pos then - table.insert( - closest, - { - dist = pos:Distance(data.HitPos), - id = id, - pos = pos, - } - ) - end - end - - if closest[1] then - table.sort(closest, function(a, b) - return a.dist < b.dist - end) - - self:FollowBone(data.HitEntity, closest[1].id) - self:SetLocalPos( - util.TraceLine({start = data.HitPos, endpos = closest[1].pos}).HitPos - closest[1].pos + if pos then + table.insert( + closest, + { + dist = pos:Distance(data.HitPos), + id = id, + pos = pos, + } ) - else - self:SetPos(data.HitPos) - self:SetParent(data.HitEntity) end + end + + if closest[1] then + table.sort(closest, function(a, b) + return a.dist < b.dist + end) + + self:FollowBone(data.HitEntity, closest[1].id) + self:SetLocalPos( + util.TraceLine({start = data.HitPos, endpos = closest[1].pos}).HitPos - closest[1].pos + ) else self:SetPos(data.HitPos) self:SetParent(data.HitEntity) end + else + self:SetPos(data.HitPos) + self:SetParent(data.HitEntity) end - - self:SetOldVelocity(data.OurOldVelocity) end - if self.part_data.BulletImpact then - self:FireBullets( - { - Attacker = ply, - Damage = 0, - Force = 0, - Num = 1, - Src = data.HitPos - data.HitNormal, - Dir = data.HitNormal, - Distance = 10, - } - ) - end + self:SetOldVelocity(data.OurOldVelocity) + end - if - self.part_data.DamageType:sub(0, 9) == "dissolve_" and - damage_types[self.part_data.DamageType] - then - if data.HitEntity:IsPlayer() then - local info = DamageInfo() - info:SetAttacker(ply) - info:SetInflictor(self) + if self.part_data.BulletImpact then + self:FireBullets( + { + Attacker = ply, + Damage = 0, + Force = 0, + Num = 1, + Src = data.HitPos - data.HitNormal, + Dir = data.HitNormal, + Distance = 10, + } + ) + end + + if + self.part_data.DamageType:sub(0, 9) == "dissolve_" and + damage_types[self.part_data.DamageType] + then + if data.HitEntity:IsPlayer() then + local info = DamageInfo() + info:SetAttacker(ply) + info:SetInflictor(self) + info:SetDamageForce(data.OurOldVelocity) + info:SetDamagePosition(data.HitPos) + info:SetDamage(100000) + info:SetDamageType(damage_types.dissolve) + data.HitEntity:TakeDamageInfo(info) + else + local can = hook.Run("CanProperty", ply, "remover", data.HitEntity) + + if can ~= false then + dissolve(data.HitEntity, ply, damage_types[self.part_data.DamageType]) + end + end + end + + local damage_radius = math.Clamp(self.part_data.DamageRadius, 0, 300) + + if self.part_data.Damage > 0 then + if self.part_data.DamageType == "heal" then + if damage_radius > 0 then + for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do + if ent ~= ply or self.part_data.CollideWithOwner then + ent:SetHealth(math.min(ent:Health() + self.part_data.Damage, ent:GetMaxHealth())) + end + end + else + data.HitEntity:SetHealth(math.min(data.HitEntity:Health() + self.part_data.Damage, data.HitEntity:GetMaxHealth())) + end + elseif self.part_data.DamageType == "armor" then + if damage_radius > 0 then + for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do + if ent.SetArmor and ent.Armor then + if ent ~= ply or self.part_data.CollideWithOwner then + ent:SetArmor(math.min( + ent:Armor() + self.part_data.Damage, + ent.GetMaxArmor and ent:GetMaxArmor() or 100 + )) + end + end + end + elseif data.HitEntity.SetArmor and data.HitEntity.Armor then + data.HitEntity:SetArmor(math.min( + data.HitEntity:Armor() + self.part_data.Damage, + data.HitEntity.GetMaxArmor and + data.HitEntity:GetMaxArmor() or + 100 + )) + end + else + local info = DamageInfo() + info:SetAttacker(ply) + info:SetInflictor(self) + + if self.part_data.DamageType == "fire" then + local ent = data.HitEntity + + if damage_radius > 0 then + -- this should also use blast damage to find which entities it can damage + for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do + if + ent ~= self and + ent:IsSolid() and + hook.Run("CanProperty", ply, "ignite", ent) ~= false and + (ent ~= ply or self.part_data.CollideWithOwner) + then + ent:Ignite(math.min(self.part_data.Damage, 5)) + end + end + elseif ent:IsSolid() and hook.Run("CanProperty", ply, "ignite", ent) ~= false then + ent:Ignite(math.min(self.part_data.Damage, 5)) + end + elseif self.part_data.DamageType == "explosion" then + info:SetDamageType(damage_types.blast) + info:SetDamage(math.Clamp(self.part_data.Damage, 0, 100000)) + util.BlastDamageInfo(info, data.HitPos, damage_radius) + else info:SetDamageForce(data.OurOldVelocity) info:SetDamagePosition(data.HitPos) - info:SetDamage(100000) - info:SetDamageType(damage_types.dissolve) - data.HitEntity:TakeDamageInfo(info) - else - local can = hook.Run("CanProperty", ply, "remover", data.HitEntity) + info:SetDamage(math.min(self.part_data.Damage, 100000)) + info:SetDamageType(damage_types[self.part_data.DamageType] or damage_types.generic) - if can ~= false then - dissolve(data.HitEntity, ply, damage_types[self.part_data.DamageType]) - end - end - end - - local damage_radius = math.Clamp(self.part_data.DamageRadius, 0, 300) - - if self.part_data.Damage > 0 then - if self.part_data.DamageType == "heal" then if damage_radius > 0 then for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do if ent ~= ply or self.part_data.CollideWithOwner then - ent:SetHealth(math.min(ent:Health() + self.part_data.Damage, ent:GetMaxHealth())) + ent:TakeDamageInfo(info) end end else - data.HitEntity:SetHealth(math.min(data.HitEntity:Health() + self.part_data.Damage, data.HitEntity:GetMaxHealth())) - end - elseif self.part_data.DamageType == "armor" then - if damage_radius > 0 then - for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do - if ent.SetArmor and ent.Armor then - if ent ~= ply or self.part_data.CollideWithOwner then - ent:SetArmor(math.min( - ent:Armor() + self.part_data.Damage, - ent.GetMaxArmor and ent:GetMaxArmor() or 100 - )) - end - end - end - elseif data.HitEntity.SetArmor and data.HitEntity.Armor then - data.HitEntity:SetArmor(math.min( - data.HitEntity:Armor() + self.part_data.Damage, - data.HitEntity.GetMaxArmor and - data.HitEntity:GetMaxArmor() or - 100 - )) - end - else - local info = DamageInfo() - info:SetAttacker(ply) - info:SetInflictor(self) - - if self.part_data.DamageType == "fire" then - local ent = data.HitEntity - - if damage_radius > 0 then - -- this should also use blast damage to find which entities it can damage - for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do - if - ent ~= self and - ent:IsSolid() and - hook.Run("CanProperty", ply, "ignite", ent) ~= false and - (ent ~= ply or self.part_data.CollideWithOwner) - then - ent:Ignite(math.min(self.part_data.Damage, 5)) - end - end - elseif ent:IsSolid() and hook.Run("CanProperty", ply, "ignite", ent) ~= false then - ent:Ignite(math.min(self.part_data.Damage, 5)) - end - elseif self.part_data.DamageType == "explosion" then - info:SetDamageType(damage_types.blast) - info:SetDamage(math.Clamp(self.part_data.Damage, 0, 100000)) - util.BlastDamageInfo(info, data.HitPos, damage_radius) - else - info:SetDamageForce(data.OurOldVelocity) - info:SetDamagePosition(data.HitPos) - info:SetDamage(math.min(self.part_data.Damage, 100000)) - info:SetDamageType(damage_types[self.part_data.DamageType] or damage_types.generic) - - if damage_radius > 0 then - for _, ent in ipairs(ents.FindInSphere(data.HitPos, damage_radius)) do - if ent ~= ply or self.part_data.CollideWithOwner then - ent:TakeDamageInfo(info) - end - end - else - data.HitEntity:TakeDamageInfo(info) - end + data.HitEntity:TakeDamageInfo(info) end end end - - if self.part_data.RemoveOnCollide then - timer.Simple(0, function() - SafeRemoveEntity(self) - end) - end end - function ENT:OnRemove() - if IsValid(self.pac_projectile_owner) then - local ply = self.pac_projectile_owner - ply.pac_projectiles = ply.pac_projectiles or {} - ply.pac_projectiles[self] = nil - end + if self.part_data.RemoveOnCollide then + timer.Simple(0, function() + SafeRemoveEntity(self) + end) end end - scripted_ents.Register(ENT, ENT.ClassName) - end - - if SERVER then - for key, ent in pairs(ents.FindByClass("pac_projectile")) do - ent:Remove() - end - - util.AddNetworkString("pac_projectile") - util.AddNetworkString("pac_projectile_attach") - util.AddNetworkString("pac_projectile_remove_all") - - net.Receive("pac_projectile_remove_all", function(len, ply) - ply.pac_projectiles = ply.pac_projectiles or {} - - for k, v in pairs(ply.pac_projectiles) do - SafeRemoveEntity(v) - end - - ply.pac_projectiles = {} - end) - - net.Receive("pac_projectile", function(len, ply) - if not enable:GetBool() then return end - pace.suppress_prop_spawn = true - - if hook.Run("PlayerSpawnProp", ply, "models/props_junk/popcan01a.mdl") == false then - pace.suppress_prop_spawn = nil - return - end - - pace.suppress_prop_spawn = nil - local pos = net.ReadVector() - local ang = net.ReadAngle() - local part = net.ReadTable() - local radius_limit = 2000 - - if pos:Distance(ply:EyePos()) > radius_limit * ply:GetModelScale() then - local ok = false - - for _, ent in ipairs(ents.FindInSphere(pos, radius_limit)) do - if - (ent.CPPIGetOwner and ent:CPPIGetOwner() == ply) or - ent.projectile_owner == ply or - ent:GetOwner() == ply - then - ok = true - - break - end - end - - if not ok then - pos = ply:EyePos() - end - end - - local function spawn() - if not ply:IsValid() then return end + function ENT:OnRemove() + if IsValid(self.pac_projectile_owner) then + local ply = self.pac_projectile_owner ply.pac_projectiles = ply.pac_projectiles or {} - if part.Maximum > 0 and table.Count(ply.pac_projectiles) >= part.Maximum then return end - local ent = ents.Create("pac_projectile") - SafeRemoveEntityDelayed(ent, math.Clamp(part.LifeTime, 0, 10)) - ent:SetModel("models/props_junk/popcan01a.mdl") - ent:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE_DEBRIS) - ent:SetPos(pos) - ent:SetAngles(ang) - ent:Spawn() - - if not part.CollideWithOwner then - ent:SetOwner(ply) - end - - ent:SetData(ply, pos, ang, part) - ent:SetPhysicsAttacker(ply) - - if ent.CPPISetOwner then - ent:CPPISetOwner(ply) - end - - net.Start("pac_projectile_attach") - net.WriteEntity(ply) - net.WriteInt(ent:EntIndex(), 16) - net.WriteString(part.UniqueID) - net.Broadcast() - ply.pac_projectiles[ent] = ent - ent.pac_projectile_owner = ply + ply.pac_projectiles[self] = nil end - - if part.Delay == 0 then - spawn() - else - timer.Simple(part.Delay, spawn) - end - end) + end end + + scripted_ents.Register(ENT, ENT.ClassName) +end + +if SERVER then + for key, ent in pairs(ents.FindByClass("pac_projectile")) do + ent:Remove() + end + + util.AddNetworkString("pac_projectile") + util.AddNetworkString("pac_projectile_attach") + util.AddNetworkString("pac_projectile_remove_all") + + net.Receive("pac_projectile_remove_all", function(len, ply) + ply.pac_projectiles = ply.pac_projectiles or {} + + for k, v in pairs(ply.pac_projectiles) do + SafeRemoveEntity(v) + end + + ply.pac_projectiles = {} + end) + + net.Receive("pac_projectile", function(len, ply) + if not enable:GetBool() then return end + pace.suppress_prop_spawn = true + + if hook.Run("PlayerSpawnProp", ply, "models/props_junk/popcan01a.mdl") == false then + pace.suppress_prop_spawn = nil + return + end + + pace.suppress_prop_spawn = nil + local pos = net.ReadVector() + local ang = net.ReadAngle() + local part = net.ReadTable() + local radius_limit = 2000 + + if pos:Distance(ply:EyePos()) > radius_limit * ply:GetModelScale() then + local ok = false + + for _, ent in ipairs(ents.FindInSphere(pos, radius_limit)) do + if + (ent.CPPIGetOwner and ent:CPPIGetOwner() == ply) or + ent.projectile_owner == ply or + ent:GetOwner() == ply + then + ok = true + + break + end + end + + if not ok then + pos = ply:EyePos() + end + end + + local function spawn() + if not ply:IsValid() then return end + ply.pac_projectiles = ply.pac_projectiles or {} + if part.Maximum > 0 and table.Count(ply.pac_projectiles) >= part.Maximum then return end + local ent = ents.Create("pac_projectile") + SafeRemoveEntityDelayed(ent, math.Clamp(part.LifeTime, 0, 10)) + ent:SetModel("models/props_junk/popcan01a.mdl") + ent:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE_DEBRIS) + ent:SetPos(pos) + ent:SetAngles(ang) + ent:Spawn() + + if not part.CollideWithOwner then + ent:SetOwner(ply) + end + + ent:SetData(ply, pos, ang, part) + ent:SetPhysicsAttacker(ply) + + if ent.CPPISetOwner then + ent:CPPISetOwner(ply) + end + + net.Start("pac_projectile_attach") + net.WriteEntity(ply) + net.WriteInt(ent:EntIndex(), 16) + net.WriteString(part.UniqueID) + net.Broadcast() + ply.pac_projectiles[ent] = ent + ent.pac_projectile_owner = ply + end + + if part.Delay == 0 then + spawn() + else + timer.Simple(part.Delay, spawn) + end + end) +end