Skip to content

Commit

Permalink
more models + modelplug cleanup (#2563)
Browse files Browse the repository at this point in the history
* refactor this terribleness

like actually who wrote this

* add epic led model

* less redundant file-exists checks

* minor syntax error

* cursed model

* more leds!

* I'm a huge fan!

(add computer fan model)

* remove big LED

(this was way too large)

* inductor model :)

* pick one damn it

tabs OR spaces, NOT BOTH!

* unspaghetti this crap

data plug has been missing models for years!

* more antispaghetti shennanigans

* several things

add usb-c plug and socket
fix bugs from unspaghetti commit
plugs play confirmation sound when linked

* shared modelplug

* improve lua autorefresh compatibility

* finally remove redundant angle offset code

* SD card & socket

* microusb :)

* all lint fixes

* more lint fixes
  • Loading branch information
Fasteroid authored Jul 10, 2023
1 parent 0ed150e commit 6893cb4
Show file tree
Hide file tree
Showing 91 changed files with 687 additions and 638 deletions.
8 changes: 4 additions & 4 deletions lua/autorun/wire_load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if SERVER then
AddCSLuaFile("wire/default_data_decompressor.lua")
AddCSLuaFile("wire/flir.lua")
AddCSLuaFile("wire/von.lua")
AddCSLuaFile("wire/sh_modelplug.lua")

-- client includes
AddCSLuaFile("wire/client/cl_wirelib.lua")
Expand Down Expand Up @@ -84,11 +85,12 @@ if SERVER then
if CreateConVar("wire_force_workshop", 1, {FCVAR_ARCHIVE}, "Should Wire force all clients to download the Workshop edition of Wire, for models? (requires restart to disable)"):GetBool() then
resource.AddWorkshop("160250458")
end
resource.AddFile("resource/fonts/alphalcd.ttf")
resource.AddFile("resource/fonts/alphalcd.ttf")

end

-- shared includes
include("wire/sh_modelplug.lua")
include("wire/wireshared.lua")
include("wire/wire_paths.lua")
include("wire/wiregates.lua")
Expand Down Expand Up @@ -131,8 +133,6 @@ if CLIENT then
include("wire/client/rendertarget_fix.lua")
include("wire/client/hlzasm/hc_compiler.lua")
include("wire/client/customspawnmenu.lua")


end

-- Load UWSVN, done here so its definitely after Wire is loaded.
Expand Down
6 changes: 4 additions & 2 deletions lua/entities/gmod_wire_datasocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ if CLIENT then
end

function ENT:DrawEntityOutline() end -- never draw outline

function ENT:Initialize()
self:CacheData()
table.insert(sockets, self)
if #sockets == 1 then
hook.Add("HUDPaint", "Wire_DataSocket_DrawLinkHelperLine",DrawLinkHelperLinefunction)
Expand All @@ -35,7 +36,7 @@ if CLIENT then

function ENT:OnRemove()
table.RemoveByValue(sockets, self)
if #sockets == 0 then
if #sockets == 0 then
hook.Remove("HUDPaint", "Wire_DataSocket_DrawLinkHelperLine")
end
end
Expand All @@ -44,6 +45,7 @@ if CLIENT then
end

function ENT:Initialize()
self:CacheData()
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
Expand Down
49 changes: 14 additions & 35 deletions lua/entities/gmod_wire_socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,19 @@ ENT.Purpose = "Links with a plug"
ENT.Instructions = "Move a plug close to a plug to link them, and data will be transferred through the link."
ENT.WireDebugName = "Socket"

local PositionOffsets = {
["models/wingf0x/isasocket.mdl"] = Vector(0,0,0),
["models/wingf0x/altisasocket.mdl"] = Vector(0,0,2.6),
["models/wingf0x/ethernetsocket.mdl"] = Vector(0,0,0),
["models/wingf0x/hdmisocket.mdl"] = Vector(0,0,0),
["models/props_lab/tpplugholder_single.mdl"] = Vector(5, 13, 10),
["models/bull/various/usb_socket.mdl"] = Vector(8,0,0),
["models/hammy/pci_slot.mdl"] = Vector(0,0,0),
["models//hammy/pci_slot.mdl"] = Vector(0,0,0), -- For some reason, GetModel on this model has two / on the client... Bug?
}
local AngleOffsets = {
["models/wingf0x/isasocket.mdl"] = Angle(0,0,0),
["models/wingf0x/altisasocket.mdl"] = Angle(0,0,0),
["models/wingf0x/ethernetsocket.mdl"] = Angle(0,0,0),
["models/wingf0x/hdmisocket.mdl"] = Angle(0,0,0),
["models/props_lab/tpplugholder_single.mdl"] = Angle(0,0,0),
["models/bull/various/usb_socket.mdl"] = Angle(0,0,0),
["models/hammy/pci_slot.mdl"] = Angle(0,0,0),
["models//hammy/pci_slot.mdl"] = Angle(0,0,0), -- For some reason, GetModel on this model has two / on the client... Bug?
}
local SocketModels = {
["models/wingf0x/isasocket.mdl"] = "models/wingf0x/isaplug.mdl",
["models/wingf0x/altisasocket.mdl"] = "models/wingf0x/isaplug.mdl",
["models/wingf0x/ethernetsocket.mdl"] = "models/wingf0x/ethernetplug.mdl",
["models/wingf0x/hdmisocket.mdl"] = "models/wingf0x/hdmiplug.mdl",
["models/props_lab/tpplugholder_single.mdl"] = "models/props_lab/tpplug.mdl",
["models/bull/various/usb_socket.mdl"] = "models/bull/various/usb_stick.mdl",
["models/hammy/pci_slot.mdl"] = "models/hammy/pci_card.mdl",
["models//hammy/pci_slot.mdl"] = "models//hammy/pci_card.mdl", -- For some reason, GetModel on this model has two / on the client... Bug?
}
local SocketData = list.Get("Wire_Socket_Models")

hook.Add("ModelPlugLuaRefresh","gmod_wire_socket_updatemodels",function()
SocketData = list.Get("Wire_Socket_Models")
end)

function ENT:GetLinkPos()
return self:LocalToWorld(PositionOffsets[self:GetModel()] or Vector(0,0,0)), self:LocalToWorldAngles(AngleOffsets[self:GetModel()] or Angle(0,0,0))
return self:LocalToWorld(self.SockData.pos or Vector(0,0,0)), self:GetAngles()
end

function ENT:CanLink( Target )
if (Target.Socket and Target.Socket:IsValid()) then return false end
if (SocketModels[self:GetModel()] ~= Target:GetModel()) then return false end
if (self.SockData.plug ~= Target:GetModel()) then return false end
return true
end

Expand All @@ -63,7 +38,6 @@ function ENT:GetClosestPlug()
end
end
end

return Closest
end

Expand All @@ -75,6 +49,9 @@ function ENT:SetupDataTables()
self:NetworkVar( "Bool", 0, "Linked" )
end

function ENT:CacheData()
self.SockData = SocketData[ self:GetModel() ] or {}
end

if CLIENT then
local sockets = ents.FindByClass("gmod_wire_socket") or {}
Expand All @@ -100,6 +77,7 @@ if CLIENT then
end

function ENT:Initialize()
self:CacheData()
table.insert(sockets, self)
if #sockets == 1 then
hook.Add("HUDPaint", "Wire_Socket_DrawLinkHelperLine",DrawLinkHelperLinefunction)
Expand All @@ -125,6 +103,7 @@ for k,v in ipairs( LETTERS ) do
end

function ENT:Initialize()
self:CacheData()
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
Expand Down Expand Up @@ -249,6 +228,7 @@ function ENT:ResendValues()
end

function ENT:AttachWeld(weld)
self:EmitSound("buttons/lightswitch2.wav", 60)
self.Weld = weld
local plug = self.Plug
weld:CallOnRemove("wire_socket_remove_on_weld",function()
Expand Down Expand Up @@ -299,10 +279,9 @@ function ENT:Think()
return true
end

if not IsValid(self.Plug) then -- currently not linked, check for nearby links
if not IsValid(self.Plug) then -- currently not linked, check for nearby links|
local Pos, Ang = self:GetLinkPos()
local Closest = self:GetClosestPlug()

if (Closest and Closest:IsValid() and self:CanLink( Closest ) and not Closest:IsPlayerHolding() and Closest:GetClosestSocket() == self) then
self.Plug = Closest
Closest.Socket = self
Expand Down
Loading

0 comments on commit 6893cb4

Please sign in to comment.