Skip to content

Commit

Permalink
Cleanup: Brackets with double quotes to include structures ( like wir…
Browse files Browse the repository at this point in the history
…em… (#445)

* Added: Brackets with double quotes to include structures ( like wiremod )
Converted: Global `constraints` and `serializable` to real globals

* Update: Shove control stricture in the global setup table

* Order by length and reduce spaces
  • Loading branch information
dvdvideo1234 authored Nov 8, 2023
1 parent e4a0d9d commit e7db6e0
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 84 deletions.
4 changes: 2 additions & 2 deletions lua/advdupe2/sh_codec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
local REVISION = 5
AdvDupe2.CodecRevision = REVISION

include "sh_codec_legacy.lua"
AddCSLuaFile "sh_codec_legacy.lua"
include( "sh_codec_legacy.lua" )
AddCSLuaFile( "sh_codec_legacy.lua" )

local pairs = pairs
local type = type
Expand Down
124 changes: 61 additions & 63 deletions lua/advdupe2/sv_clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Version: 1.0
]]

require "duplicator"
require( "duplicator" )

AdvDupe2.duplicator = {}

Expand All @@ -15,27 +15,63 @@ AdvDupe2.JobManager.Queue = {}

local debugConvar = GetConVar("AdvDupe2_DebugInfo")

local constraints = {
Weld = true,
Axis = true,
Ballsocket = true,
Elastic = true,
Hydraulic = true,
Motor = true,
Muscle = true,
Pulley = true,
Rope = true,
Slider = true,
Winch = true
}

local serializable = {
[TYPE_BOOL] = true,
[TYPE_NUMBER] = true,
[TYPE_VECTOR] = true,
[TYPE_ANGLE] = true,
[TYPE_TABLE] = true,
[TYPE_STRING] = true
local gtSetupTable = {
SERIAL = {
[TYPE_BOOL] = true,
[TYPE_ANGLE] = true,
[TYPE_TABLE] = true,
[TYPE_NUMBER] = true,
[TYPE_VECTOR] = true,
[TYPE_STRING] = true
},
CONSTRAINT = {
Weld = true,
Axis = true,
Rope = true,
Motor = true,
Winch = true,
Muscle = true,
Pulley = true,
Slider = true,
Elastic = true,
Hydraulic = true,
Ballsocket = true
},
COMPARE = {
V1 = Vector(1, 1, 1),
A0 = Angle (0, 0, 0),
V0 = Vector(0, 0, 0)
},
POS = {
["pos"] = true,
["Pos"] = true,
["position"] = true,
["Position"] = true
},
ANG = {
["ang"] = true,
["Ang"] = true,
["angle"] = true,
["Angle"] = true
},
MODEL = {
["model"] = true,
["Model"] = true
},
PLAYER = {
["pl"] = true,
["ply"] = true
},
ENT1 = {
["Ent"] = true,
["Ent1"] = true,
},
TVEHICLE = {
["VehicleTable"] = true
},
SPECIAL = {
["Data"] = true
}
}

local function CopyClassArgTable(tab)
Expand All @@ -45,7 +81,7 @@ local function CopyClassArgTable(tab)
done[oldtable] = newtable
for k, v in pairs(oldtable) do
local varType = TypeID(v)
if serializable[varType] then
if gtSetupTable.SERIAL[varType] then
if varType == TYPE_TABLE then
if done[v] then
newtable[k] = done[v]
Expand Down Expand Up @@ -77,44 +113,6 @@ end
Returns a copy of the passed entity's table
---------------------------------------------------------]]

local gtSetupTable = {
POS = {
["pos" ] = true,
["position"] = true,
["Pos" ] = true,
["Position"] = true
},
ANG = {
["ang" ] = true,
["angle" ] = true,
["Ang" ] = true,
["Angle" ] = true
},
MODEL = {
["model" ] = true,
["Model" ] = true
},
PLAYER = {
["pl" ] = true,
["ply" ] = true
},
ENT1 = {
["Ent" ] = true,
["Ent1" ] = true,
},
COMPARE = {
V1 = Vector(1, 1, 1),
A0 = Angle (0, 0, 0),
V0 = Vector(0, 0, 0)
},
TVEHICLE = {
["VehicleTable"] = true
},
SPECIAL = {
["Data"] = true
}
}

function AdvDupe2.duplicator.IsCopyable(Ent)
return not Ent.DoNotDuplicate and duplicator.IsAllowed(Ent:GetClass()) and IsValid(Ent:GetPhysicsObject())
end
Expand Down Expand Up @@ -144,7 +142,7 @@ local function CopyEntTable(Ent, Offset)
not gtSetupTable.ANG[Key] and
not gtSetupTable.MODEL[Key]) then
local varType = TypeID(EntTable[Key])
if serializable[varType] then
if gtSetupTable.SERIAL[varType] then
if varType == TYPE_TABLE then
Tab[Key] = CopyClassArgTable(EntTable[Key])
else
Expand Down Expand Up @@ -1381,7 +1379,7 @@ local function AdvDupe2_Spawn()
v:SetParent(Queue.CreatedEntities[Queue.EntityList[k].BuildDupeInfo.DupeParentID])
if (v.Constraints ~= nil) then
for i, c in pairs(v.Constraints) do
if (c and constraints[c.Type]) then
if (c and gtSetupTable.CONSTRAINT[c.Type]) then
edit = false
break
end
Expand Down
8 changes: 4 additions & 4 deletions lua/autorun/client/advdupe2_cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ if(!file.Exists(AdvDupe2.DataFolder, "DATA"))then
file.CreateDir(AdvDupe2.DataFolder)
end

include "advdupe2/file_browser.lua"
include "advdupe2/sh_codec.lua"
include "advdupe2/cl_file.lua"
include "advdupe2/cl_ghost.lua"
include( "advdupe2/file_browser.lua" )
include( "advdupe2/sh_codec.lua" )
include( "advdupe2/cl_file.lua" )
include( "advdupe2/cl_ghost.lua" )

function AdvDupe2.Notify(msg,typ,dur)
surface.PlaySound(typ == 1 and "buttons/button10.wav" or "ambient/water/drip1.wav")
Expand Down
20 changes: 10 additions & 10 deletions lua/autorun/server/advdupe2_sv_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function AdvDupe2.Notify(ply,msg,typ, showsvr, dur)
end
end

AddCSLuaFile "autorun/client/advdupe2_cl_init.lua"
AddCSLuaFile "advdupe2/file_browser.lua"
AddCSLuaFile "advdupe2/sh_codec.lua"
AddCSLuaFile "advdupe2/cl_file.lua"
AddCSLuaFile "advdupe2/cl_ghost.lua"
AddCSLuaFile( "autorun/client/advdupe2_cl_init.lua" )
AddCSLuaFile( "advdupe2/file_browser.lua" )
AddCSLuaFile( "advdupe2/sh_codec.lua" )
AddCSLuaFile( "advdupe2/cl_file.lua" )
AddCSLuaFile( "advdupe2/cl_ghost.lua" )

util.AddNetworkString("AdvDupe2_ReportClass")
util.AddNetworkString("AdvDupe2_ReportModel")
Expand Down Expand Up @@ -120,9 +120,9 @@ hook.Add("PlayerInitialSpawn","AdvDupe2_AddPlayerTable",function(ply)
ply.AdvDupe2 = {}
end)

include "advdupe2/sv_clipboard.lua"
include "advdupe2/sh_codec.lua"
include "advdupe2/sv_misc.lua"
include "advdupe2/sv_file.lua"
include "advdupe2/sv_ghost.lua"
include( "advdupe2/sv_clipboard.lua" )
include( "advdupe2/sh_codec.lua" )
include( "advdupe2/sv_misc.lua" )
include( "advdupe2/sv_file.lua" )
include( "advdupe2/sv_ghost.lua" )

2 changes: 1 addition & 1 deletion lua/entities/gmod_contr_spawner/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include("shared.lua")
include( "shared.lua" )

function ENT:Draw()
self.BaseClass.Draw(self)
Expand Down
5 changes: 2 additions & 3 deletions lua/entities/gmod_contr_spawner/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
Version: 1.0
]]


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
if(WireLib)then
include('entities/base_wire_entity.lua')
include( "entities/base_wire_entity.lua" )
end
include('shared.lua')

include( "shared.lua" )

function ENT:Initialize()

Expand Down
2 changes: 1 addition & 1 deletion lua/weapons/gmod_tool/stools/advdupe2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TOOL.Category = "Construction"
TOOL.Name = "#Tool.advdupe2.name"
cleanup.Register( "AdvDupe2" )
require "controlpanel"
require( "controlpanel" )

if(SERVER)then
CreateConVar("sbox_maxgmod_contr_spawners",5)
Expand Down

0 comments on commit e7db6e0

Please sign in to comment.