Skip to content

Commit c8531a7

Browse files
authored
Some improvements in color core
Do not create new colors where possible
1 parent 9e416c4 commit c8531a7

File tree

1 file changed

+12
-5
lines changed
  • lua/entities/gmod_wire_expression2/core

1 file changed

+12
-5
lines changed

lua/entities/gmod_wire_expression2/core/color.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ e2function void entity:setColor(r,g,b)
3636
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
3737
if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
3838

39-
WireLib.SetColor(this, Color(r, g, b, this:GetColor().a))
39+
local color = this:GetColor()
40+
color.r, color.g, color.b = RGBClamp(r, g, b)
41+
42+
WireLib.SetColor(this, color)
4043
end
4144

4245
e2function void entity:setColor(r,g,b,a)
@@ -50,7 +53,10 @@ e2function void entity:setColor(vector c)
5053
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
5154
if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
5255

53-
WireLib.SetColor(this, Color(c[1], c[2], c[3], this:GetColor().a))
56+
local color = this:GetColor()
57+
color.r, color.g, color.b = RGBClamp(c[1], c[2], c[3])
58+
59+
WireLib.SetColor(this, color)
5460
end
5561

5662
e2function void entity:setColor(vector c, a)
@@ -70,11 +76,12 @@ end
7076
e2function void entity:setAlpha(a)
7177
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
7278
if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
73-
7479
if this:IsPlayer() then return self:throw("You cannot set the alpha of a player!", nil) end
7580

76-
local c = this:GetColor()
77-
WireLib.SetColor(this, Color(c.r, c.g, c.b, a))
81+
local color = this:GetColor()
82+
color.a = Clamp(a, 0, 255)
83+
84+
WireLib.SetColor(this, color)
7885
end
7986

8087
e2function void entity:setRenderMode(mode)

0 commit comments

Comments
 (0)