Skip to content

Commit 6893cb4

Browse files
authored
more models + modelplug cleanup (#2563)
* 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
1 parent 0ed150e commit 6893cb4

File tree

91 files changed

+687
-638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+687
-638
lines changed

lua/autorun/wire_load.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if SERVER then
3636
AddCSLuaFile("wire/default_data_decompressor.lua")
3737
AddCSLuaFile("wire/flir.lua")
3838
AddCSLuaFile("wire/von.lua")
39+
AddCSLuaFile("wire/sh_modelplug.lua")
3940

4041
-- client includes
4142
AddCSLuaFile("wire/client/cl_wirelib.lua")
@@ -84,11 +85,12 @@ if SERVER then
8485
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
8586
resource.AddWorkshop("160250458")
8687
end
87-
resource.AddFile("resource/fonts/alphalcd.ttf")
88-
88+
resource.AddFile("resource/fonts/alphalcd.ttf")
89+
8990
end
9091

9192
-- shared includes
93+
include("wire/sh_modelplug.lua")
9294
include("wire/wireshared.lua")
9395
include("wire/wire_paths.lua")
9496
include("wire/wiregates.lua")
@@ -131,8 +133,6 @@ if CLIENT then
131133
include("wire/client/rendertarget_fix.lua")
132134
include("wire/client/hlzasm/hc_compiler.lua")
133135
include("wire/client/customspawnmenu.lua")
134-
135-
136136
end
137137

138138
-- Load UWSVN, done here so its definitely after Wire is loaded.

lua/entities/gmod_wire_datasocket.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ if CLIENT then
2525
end
2626

2727
function ENT:DrawEntityOutline() end -- never draw outline
28-
28+
2929
function ENT:Initialize()
30+
self:CacheData()
3031
table.insert(sockets, self)
3132
if #sockets == 1 then
3233
hook.Add("HUDPaint", "Wire_DataSocket_DrawLinkHelperLine",DrawLinkHelperLinefunction)
@@ -35,7 +36,7 @@ if CLIENT then
3536

3637
function ENT:OnRemove()
3738
table.RemoveByValue(sockets, self)
38-
if #sockets == 0 then
39+
if #sockets == 0 then
3940
hook.Remove("HUDPaint", "Wire_DataSocket_DrawLinkHelperLine")
4041
end
4142
end
@@ -44,6 +45,7 @@ if CLIENT then
4445
end
4546

4647
function ENT:Initialize()
48+
self:CacheData()
4749
self:PhysicsInit( SOLID_VPHYSICS )
4850
self:SetMoveType( MOVETYPE_VPHYSICS )
4951
self:SetSolid( SOLID_VPHYSICS )

lua/entities/gmod_wire_socket.lua

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,19 @@ ENT.Purpose = "Links with a plug"
55
ENT.Instructions = "Move a plug close to a plug to link them, and data will be transferred through the link."
66
ENT.WireDebugName = "Socket"
77

8-
local PositionOffsets = {
9-
["models/wingf0x/isasocket.mdl"] = Vector(0,0,0),
10-
["models/wingf0x/altisasocket.mdl"] = Vector(0,0,2.6),
11-
["models/wingf0x/ethernetsocket.mdl"] = Vector(0,0,0),
12-
["models/wingf0x/hdmisocket.mdl"] = Vector(0,0,0),
13-
["models/props_lab/tpplugholder_single.mdl"] = Vector(5, 13, 10),
14-
["models/bull/various/usb_socket.mdl"] = Vector(8,0,0),
15-
["models/hammy/pci_slot.mdl"] = Vector(0,0,0),
16-
["models//hammy/pci_slot.mdl"] = Vector(0,0,0), -- For some reason, GetModel on this model has two / on the client... Bug?
17-
}
18-
local AngleOffsets = {
19-
["models/wingf0x/isasocket.mdl"] = Angle(0,0,0),
20-
["models/wingf0x/altisasocket.mdl"] = Angle(0,0,0),
21-
["models/wingf0x/ethernetsocket.mdl"] = Angle(0,0,0),
22-
["models/wingf0x/hdmisocket.mdl"] = Angle(0,0,0),
23-
["models/props_lab/tpplugholder_single.mdl"] = Angle(0,0,0),
24-
["models/bull/various/usb_socket.mdl"] = Angle(0,0,0),
25-
["models/hammy/pci_slot.mdl"] = Angle(0,0,0),
26-
["models//hammy/pci_slot.mdl"] = Angle(0,0,0), -- For some reason, GetModel on this model has two / on the client... Bug?
27-
}
28-
local SocketModels = {
29-
["models/wingf0x/isasocket.mdl"] = "models/wingf0x/isaplug.mdl",
30-
["models/wingf0x/altisasocket.mdl"] = "models/wingf0x/isaplug.mdl",
31-
["models/wingf0x/ethernetsocket.mdl"] = "models/wingf0x/ethernetplug.mdl",
32-
["models/wingf0x/hdmisocket.mdl"] = "models/wingf0x/hdmiplug.mdl",
33-
["models/props_lab/tpplugholder_single.mdl"] = "models/props_lab/tpplug.mdl",
34-
["models/bull/various/usb_socket.mdl"] = "models/bull/various/usb_stick.mdl",
35-
["models/hammy/pci_slot.mdl"] = "models/hammy/pci_card.mdl",
36-
["models//hammy/pci_slot.mdl"] = "models//hammy/pci_card.mdl", -- For some reason, GetModel on this model has two / on the client... Bug?
37-
}
8+
local SocketData = list.Get("Wire_Socket_Models")
9+
10+
hook.Add("ModelPlugLuaRefresh","gmod_wire_socket_updatemodels",function()
11+
SocketData = list.Get("Wire_Socket_Models")
12+
end)
3813

3914
function ENT:GetLinkPos()
40-
return self:LocalToWorld(PositionOffsets[self:GetModel()] or Vector(0,0,0)), self:LocalToWorldAngles(AngleOffsets[self:GetModel()] or Angle(0,0,0))
15+
return self:LocalToWorld(self.SockData.pos or Vector(0,0,0)), self:GetAngles()
4116
end
4217

4318
function ENT:CanLink( Target )
4419
if (Target.Socket and Target.Socket:IsValid()) then return false end
45-
if (SocketModels[self:GetModel()] ~= Target:GetModel()) then return false end
20+
if (self.SockData.plug ~= Target:GetModel()) then return false end
4621
return true
4722
end
4823

@@ -63,7 +38,6 @@ function ENT:GetClosestPlug()
6338
end
6439
end
6540
end
66-
6741
return Closest
6842
end
6943

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

52+
function ENT:CacheData()
53+
self.SockData = SocketData[ self:GetModel() ] or {}
54+
end
7855

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

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

127105
function ENT:Initialize()
106+
self:CacheData()
128107
self:PhysicsInit( SOLID_VPHYSICS )
129108
self:SetMoveType( MOVETYPE_VPHYSICS )
130109
self:SetSolid( SOLID_VPHYSICS )
@@ -249,6 +228,7 @@ function ENT:ResendValues()
249228
end
250229

251230
function ENT:AttachWeld(weld)
231+
self:EmitSound("buttons/lightswitch2.wav", 60)
252232
self.Weld = weld
253233
local plug = self.Plug
254234
weld:CallOnRemove("wire_socket_remove_on_weld",function()
@@ -299,10 +279,9 @@ function ENT:Think()
299279
return true
300280
end
301281

302-
if not IsValid(self.Plug) then -- currently not linked, check for nearby links
282+
if not IsValid(self.Plug) then -- currently not linked, check for nearby links|
303283
local Pos, Ang = self:GetLinkPos()
304284
local Closest = self:GetClosestPlug()
305-
306285
if (Closest and Closest:IsValid() and self:CanLink( Closest ) and not Closest:IsPlayerHolding() and Closest:GetClosestSocket() == self) then
307286
self.Plug = Closest
308287
Closest.Socket = self

0 commit comments

Comments
 (0)