-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththeme.lua
70 lines (59 loc) · 2.39 KB
/
theme.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local DEFAULT_TOKEN_COLORS = {
["background"] = Color3.fromRGB(47, 47, 47),
["iden"] = Color3.fromRGB(234, 234, 234),
["keyword"] = Color3.fromRGB(215, 174, 255),
["builtin"] = Color3.fromRGB(131, 206, 255),
["string"] = Color3.fromRGB(196, 255, 193),
["number"] = Color3.fromRGB(255, 125, 125),
["comment"] = Color3.fromRGB(140, 140, 155),
["operator"] = Color3.fromRGB(255, 239, 148),
["custom"] = Color3.fromRGB(119, 122, 255),
}
local types = loadstring(game:HttpGet("https://raw.githubusercontent.com/hello-n-bye/internal-executor-project/main/types.lua"))()
local Theme = {
tokenColors = {},
tokenRichTextFormatter = {},
}
function Theme.setColors(tokenColors: types.TokenColors)
assert(type(tokenColors) == "table", "Theme.updateColors expects a table")
for tokenName, color in tokenColors do
Theme.tokenColors[tokenName] = color
end
end
function Theme.getColoredRichText(color: Color3, text: string): string
return '<font color="#' .. color:ToHex() .. '">' .. text .. "</font>"
end
function Theme.getColor(tokenName: types.TokenName): Color3
return Theme.tokenColors[tokenName]
end
function Theme.matchStudioSettings(refreshCallback: () -> ()): boolean
local success = pcall(function()
-- When not used in a Studio plugin, this will error
-- and the pcall will just silently return
local studio = settings().Studio
local studioTheme = studio.Theme
local function getTokens()
return {
["background"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptBackground),
["iden"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptText),
["keyword"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptKeyword),
["builtin"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptBuiltInFunction),
["string"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptString),
["number"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptNumber),
["comment"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptComment),
["operator"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptOperator),
["custom"] = studioTheme:GetColor(Enum.StudioStyleGuideColor.ScriptBool),
}
end
Theme.setColors(getTokens())
studio.ThemeChanged:Connect(function()
studioTheme = studio.Theme
Theme.setColors(getTokens())
refreshCallback()
end)
end)
return success
end
-- Initialize
Theme.setColors(DEFAULT_TOKEN_COLORS)
return Theme