Skip to content

Commit

Permalink
Reflector and refractor are drawn anly when wire is installed (#41)
Browse files Browse the repository at this point in the history
Fixed: Issue #40. Drawing model not called when wiremod is missing
Fixed: Pre-defined configurations break registrations
Fixed: Consistency when drawing shadows of various units
Added: Raise error when someone overrides internal addon units
Added: Flag for initialized unit `UNIT_ROW[5]`
Removed: Render mode trans-color from visuals
  • Loading branch information
dvdvideo1234 authored Jul 9, 2024
1 parent d814415 commit 07a2d48
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
73 changes: 36 additions & 37 deletions lua/autorun/laserlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ local gtUNITS = {
-- [2] Extension for folder and variable name indices. Stores which folder are entity specific files located
-- [3] Contains the current model ( last path ) cashed being used for the given entity unit ID
-- [4] Contains the current material ( texture ) cashed being used for the given entity unit ID
-- [5] Whenever the unit is initialized successfully. Must contain nil, true or false
{"gmod_laser" , nil, nil, nil}, -- Laser entity class `PriarySource`
{"gmod_laser_crystal" , "crystal" , "models/props_c17/pottery02a.mdl" , "models/dog/eyeglass" }, -- Laser crystal class `EveryBeam`
{"gmod_laser_reflector", "reflector", "models/madjawa/laser_reflector.mdl" , "debug/env_cubemap_model" }, -- Laser reflectors class `DoBeam`
Expand Down Expand Up @@ -1117,43 +1118,41 @@ function LaserLib.RegisterUnit(uent, mdef, vdef, conv)
error("Class invalid: "..tostring(usrc)) end
local udrr = ucas:gsub(ocas.."%A+", ""); if(udrr == "") then
error("Suffix empty: "..tostring(usrc)) end
local vset = gtUNITS[index] -- Attempt to index class info
if(not vset or (vset and not vset[2])) then -- Empty table
-- Allocate class configuration. Make it accessible to the library
local vidx = tostring(conv or udrr):lower() -- Extract variable suffix
local vset = {ucas, vidx, mdef, vdef}; gtUNITS[index] = vset -- Index variable name
-- Configure arrays and corresponding console variables
local vmod = tostring(mdef or ""):lower()
local vmat = tostring(vdef or ""):lower()
local vaum, vauv = ("mu"..vidx), ("vu"..vidx)
local varm = CreateConVar(DATA.TOOL.."_"..vaum, vmod, DATA.FGSRVCN, "Controls the "..udrr.." model")
local varv = CreateConVar(DATA.TOOL.."_"..vauv, vmat, DATA.FGSRVCN, "Controls the "..udrr.." material")
DATA[vaum:upper()], DATA[vauv:upper()] = varm, varv
-- Configure model visual
local vanm = varm:GetName()
cvars.RemoveChangeCallback(vanm, vanm)
cvars.AddChangeCallback(vanm, function(name, o, n)
local m = tostring(n):Trim()
if(m:sub(1,1) ~= DATA.KEYD) then LaserLib.GetModel(index, m) else
varm:SetString(LaserLib.GetModel(index, varm:GetDefault()))
end -- Update current model at index [4]
end, vanm); LaserLib.GetModel(index, varm:GetString():lower())
-- Configure material visual
local vanv = varv:GetName()
cvars.RemoveChangeCallback(vanv, vanv)
cvars.AddChangeCallback(vanv, function(name, o, n)
local v = tostring(n):Trim()
if(v:sub(1,1) ~= DATA.KEYD) then LaserLib.GetMaterial(index, v) else
varv:SetString(LaserLib.GetMaterial(index, varv:GetDefault()))
end -- Update current material at index [5]
end, vanv); LaserLib.GetMaterial(index, varv:GetString():lower())
-- Return the class extracted from folder
return ucas -- This is passed to `ents.Create`
else -- The class is already present so return it
if(vset[1] ~= ucas) then -- Index taken so raise error
error("Index ["..index.."]["..vset[1].."] exists: "..tostring(usrc)) end
return ucas -- Already cashed value returned
end
local vset = (gtUNITS[index] or {}); if(vset and vset[5]) then
error("Unit present ["..index.."]["..vset[1].."]: "..ucas) end
local uset = vset[1]; if(uset and uset ~= ucas) then
error("Unit mismatch ["..index.."]["..vset[1].."]: "..ucas) end
-- Allocate class configuration. Make it accessible to the library
local vidx = tostring(conv or udrr):lower() -- Extract variable suffix
vset[1], vset[2], vset[3], vset[4], vset[5] = ucas, vidx, mdef, vdef, true
-- Configure arrays and corresponding console variables
local vmod = tostring(mdef or ""):lower()
local vmat = tostring(vdef or ""):lower()
local vaum, vauv = ("mu"..vidx), ("vu"..vidx)
local varm = CreateConVar(DATA.TOOL.."_"..vaum, vmod, DATA.FGSRVCN, "Controls the "..udrr.." model")
local varv = CreateConVar(DATA.TOOL.."_"..vauv, vmat, DATA.FGSRVCN, "Controls the "..udrr.." material")
-- Store convar objects
DATA[vaum:upper()], DATA[vauv:upper()], gtUNITS[index] = varm, varv, vset
-- Configure model visual
local vanm = varm:GetName()
cvars.RemoveChangeCallback(vanm, vanm)
cvars.AddChangeCallback(vanm, function(name, o, n)
local m = tostring(n):Trim()
if(m:sub(1,1) ~= DATA.KEYD) then LaserLib.GetModel(index, m) else
varm:SetString(LaserLib.GetModel(index, varm:GetDefault()))
end -- Update current model at index [4]
end, vanm); LaserLib.GetModel(index, varm:GetString():lower())
-- Configure material visual
local vanv = varv:GetName()
cvars.RemoveChangeCallback(vanv, vanv)
cvars.AddChangeCallback(vanv, function(name, o, n)
local v = tostring(n):Trim()
if(v:sub(1,1) ~= DATA.KEYD) then LaserLib.GetMaterial(index, v) else
varv:SetString(LaserLib.GetMaterial(index, varv:GetDefault()))
end -- Update current material at index [5]
end, vanv); LaserLib.GetMaterial(index, varv:GetString():lower())
-- Return the class extracted from folder
return ucas -- This is passed to `ents.Create`
end

--[[
Expand Down
1 change: 0 additions & 1 deletion lua/entities/gmod_laser/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ end

function ENT:Draw()
self:DrawModel()
self:DrawShadow(false)

if(self:GetOn()) then
local width = self:GetBeamWidth()
Expand Down
4 changes: 4 additions & 0 deletions lua/entities/gmod_laser_reflector/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ end

function ENT:Think()
end

function ENT:Draw()
self:DrawModel()
end
5 changes: 5 additions & 0 deletions lua/entities/gmod_laser_refractor/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ end

function ENT:Think()
end

function ENT:Draw()
self:DrawModel()
self:DrawShadow(false)
end
1 change: 0 additions & 1 deletion lua/entities/gmod_laser_sensor/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ include("shared.lua")

function ENT:Draw()
self:DrawModel()
self:DrawShadow(false)
end

0 comments on commit 07a2d48

Please sign in to comment.