Skip to content

Commit e2ce294

Browse files
committed
Add Color3.fromHex as deprecated and fix #108
1 parent 6ddf182 commit e2ce294

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

server/rbx/datatypes.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,22 @@
450450
"ReturnType": {
451451
"Name": "Color3"
452452
}
453+
},
454+
{
455+
"MemberType": "Function",
456+
"Name": "fromHex",
457+
"Deprecated": true,
458+
"Parameters": [
459+
{
460+
"Name": "hex",
461+
"Type": {
462+
"Name": "string"
463+
}
464+
}
465+
],
466+
"ReturnType": {
467+
"Name": "Color3"
468+
}
453469
}
454470
],
455471
"Name": "Color3"

server/script/core/color-picker.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ local function hsvToRgb(h, s, v, a)
3131
return r, g, b
3232
end
3333

34+
local function hex2rgb(hex)
35+
hex = hex:gsub("#","")
36+
return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
37+
end
38+
3439
local function rgbToHsv(r, g, b, a)
3540
local max, min = math.max(r, g, b), math.min(r, g, b)
3641
local h, s, v
@@ -114,6 +119,21 @@ local function documentColor(uri)
114119
end
115120
end
116121
break
122+
elseif def.special == "Color3.fromHex" then
123+
if source.args and #source.args == 1 and source.args[1].type == "string" then
124+
local hex = source.args[1][1]
125+
local r, g, b = hex2rgb(hex)
126+
results[#results+1] = {
127+
range = files.range(uri, source.start, source.finish),
128+
color = {
129+
red = r / 255,
130+
green = g / 255,
131+
blue = b / 255,
132+
alpha = 1
133+
}
134+
}
135+
end
136+
break
117137
end
118138
end
119139
end

server/script/library/rbxlibs.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ local SPECIAL_FUNCTIONS = {
3535
["Color3.new"] = "Color3.new",
3636
["Color3.fromRGB"] = "Color3.fromRGB",
3737
["Color3.fromHSV"] = "Color3.fromHSV",
38+
["Color3.fromHex"] = "Color3.fromHex",
3839
["EnumItem.IsA"] = "EnumItem.IsA",
3940
["BrickColor.new"] = "BrickColor.new"
4041
}

0 commit comments

Comments
 (0)