Skip to content

Commit fb68c21

Browse files
committed
Created plugin
1 parent 63651c5 commit fb68c21

7 files changed

Lines changed: 289 additions & 1 deletion

File tree

Plugin/Configuration.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"PluginId": "Rawblocky-ThemeScript"
3+
}

Plugin/ThemeIcons.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"LightButton": {
3+
"Light": "rbxassetid://75314633328651",
4+
"Dark": "rbxassetid://106473256205258"
5+
},
6+
"DarkButton": {
7+
"Light": "rbxassetid://117012220513934",
8+
"Dark": "rbxassetid://128985095942465"
9+
}
10+
}

Plugin/init.server.luau

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
--[[
2+
Script Name: ThemeScriptExecutor
3+
Purpose: Execute module scripts based on the current theme.
4+
Created by Rawblocky
5+
--]]
6+
7+
-- ==========================
8+
--> SERVICES
9+
-- ==========================
10+
local ChangeHistoryService = game:GetService("ChangeHistoryService")
11+
local RunService = game:GetService("RunService")
12+
local ScriptEditorService = game:GetService("ScriptEditorService")
13+
local PluginGuiService = game:GetService("PluginGuiService")
14+
-- <-
15+
16+
-- ==========================
17+
--> MODULES
18+
-- ==========================
19+
local Configuration = require(script.Configuration)
20+
local ThemeIcons = require(script.ThemeIcons)
21+
-- <-
22+
23+
-- ==========================
24+
--> VARIABLES
25+
-- ==========================
26+
local pluginId = Configuration.PluginId
27+
28+
local defaultSource = 'return function(isInitialLaunch: boolean)\n\tprint("%s")\nend'
29+
local modes = {
30+
Light = {
31+
source = string.format(defaultSource, "Good morning!"),
32+
scriptName = "🌞 Light",
33+
},
34+
Dark = {
35+
source = string.format(defaultSource, "Good evening!"),
36+
scriptName = "🌚 Dark",
37+
},
38+
}
39+
-- <-
40+
41+
if not RunService:IsEdit() then
42+
-- This plugin should only run in edit mode
43+
return
44+
end
45+
46+
--> Wait for script permissions
47+
local function checkForScriptPermissions()
48+
return pcall(function()
49+
local temporaryScript = Instance.new("Script")
50+
temporaryScript.Parent = PluginGuiService
51+
temporaryScript:Destroy()
52+
end)
53+
end
54+
55+
local hasScriptPermissions, _ = checkForScriptPermissions()
56+
if not hasScriptPermissions then
57+
warn(
58+
"ThemeScriptExecutor: Script permissions are required to run this plugin. Restart Studio after giving permissions."
59+
)
60+
return
61+
end
62+
-- <-
63+
64+
--> Save/Load functions
65+
local settingCache = {}
66+
local function getSetting(settingName: string)
67+
if settingCache[settingName] ~= nil then
68+
return settingCache[settingName]
69+
end
70+
local setting = plugin:GetSetting(pluginId .. "-" .. settingName)
71+
settingCache[settingName] = setting
72+
return setting
73+
end
74+
local function setSetting(settingName: string, ...)
75+
plugin:SetSetting(pluginId .. "-" .. settingName, ...)
76+
settingCache[settingName] = ...
77+
end
78+
-- <-
79+
80+
local function getTheme()
81+
return tostring(settings().Studio.Theme)
82+
end
83+
84+
local function getButtonImage(buttonName: string)
85+
return ThemeIcons[buttonName][getTheme()]
86+
end
87+
88+
local toolbar = plugin:CreateToolbar("ThemeScriptExecutor")
89+
local scripts = {}
90+
local pluginButtons = {}
91+
local isInitialLaunch = true
92+
93+
local moduleScriptContainer = Instance.new("Folder")
94+
moduleScriptContainer.Archivable = false
95+
moduleScriptContainer.Name = pluginId
96+
moduleScriptContainer.Parent = PluginGuiService
97+
98+
local function themeChanged()
99+
for mode, button in pluginButtons do
100+
button.Icon = getButtonImage(mode .. "Button")
101+
end
102+
103+
local currentTheme = getTheme()
104+
local ranScript
105+
for mode, moduleScript in scripts do
106+
if mode == currentTheme then
107+
ranScript = moduleScript
108+
break
109+
end
110+
end
111+
if not ranScript then
112+
return
113+
end
114+
115+
-- Clone the script because the script could've been edited and
116+
-- the original function was cached
117+
local ranScriptClone = ranScript:Clone()
118+
task.spawn(require(ranScriptClone), isInitialLaunch)
119+
if isInitialLaunch then
120+
isInitialLaunch = false
121+
end
122+
ChangeHistoryService:SetWaypoint("Executed theme script")
123+
end
124+
for mode, data in modes do
125+
local moduleScript = Instance.new("ModuleScript")
126+
moduleScript.Name = data.scriptName
127+
moduleScript.Source = getSetting(mode) or data.source
128+
moduleScript.Parent = moduleScriptContainer
129+
scripts[mode] = moduleScript
130+
131+
local pluginButton = toolbar:CreateButton(
132+
mode,
133+
string.format("Edit '%s' theme module", data.scriptName),
134+
getButtonImage(mode .. "Button")
135+
)
136+
pluginButtons[mode] = pluginButton
137+
pluginButton.ClickableWhenViewportHidden = true
138+
139+
pluginButton.Click:Connect(function()
140+
plugin:OpenScript(moduleScript)
141+
end)
142+
end
143+
144+
ScriptEditorService.TextDocumentDidChange:Connect(function(document: ScriptDocument, changes: table)
145+
local changedScript = document:GetScript()
146+
local mode
147+
for mode2, moduleScript in scripts do
148+
if moduleScript == changedScript then
149+
mode = mode2
150+
break
151+
end
152+
end
153+
if not mode then
154+
return
155+
end
156+
local newText = document:GetText()
157+
setSetting(mode, newText)
158+
end)
159+
160+
settings().Studio.ThemeChanged:Connect(themeChanged)
161+
themeChanged()

Plugin/temp.luau

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
return function(isInitialLaunch: boolean)
2+
local json =
3+
[[{"Background Color":[239,241,245],"Selection Color":[76,79,105],"Selection Background Color":[204,207,215],"Error Color":[210,15,57],"Warning Color":[254,100,11],"Find Selection Background Color":[230,173,189],"Matching Word Background Color":[204,207,215],"Whitespace Color":[136,57,239],"Current Line Highlight Color":[239,241,245],"Ruler Color":[172,176,190],"Bracket Color":[76,79,105],"Text Color":[230,69,83],"Operator Color":[23,146,153],"Number Color":[254,100,11],"String Color":[64,160,43],"Comment Color":[156,160,176],"Bool Color":[210,15,57],"\"nil\" Color":[210,15,57],"Function Name Color":[30,102,245],"\"function\" Color":[136,57,239],"\"local\" Color":[136,57,239],"\"self\" Color":[136,57,239],"Keyword Color":[136,57,239],"Built-in Function Color":[30,102,245],"\"TODO\" Color":[136,57,239],"Method Color":[30,102,245]}]]
4+
local theme = game.HttpService:JSONDecode(json)
5+
local studio = settings().Studio
6+
for name, color in pairs(theme) do
7+
color = Color3.fromRGB(color[1], color[2], color[3])
8+
local success = pcall(function()
9+
studio[name] = color
10+
end)
11+
if not success then
12+
warn(("%s is not a valid theme color"):format(name))
13+
end
14+
end
15+
print("Successfully changed your Script Editor theme!")
16+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
return function(isInitialLaunch: boolean)
2+
local json = [[{
3+
"Property Color": [205, 214, 244],
4+
"Luau Keyword Color": [205, 214, 244],
5+
6+
"Background Color": [30, 30, 46],
7+
"Selection Color": [205, 214, 244],
8+
"Selection Background Color": [59, 61, 79],
9+
"Error Color": [243, 139, 168],
10+
"Warning Color": [250, 179, 135],
11+
"Find Selection Background Color": [94, 63, 83],
12+
"Matching Word Background Color": [59, 61, 79],
13+
"Whitespace Color": [203, 166, 247],
14+
"Current Line Highlight Color": [30, 30, 46],
15+
"Ruler Color": [88, 91, 112],
16+
"Bracket Color": [243, 139, 168],
17+
"Text Color": [205, 214, 244],
18+
"Operator Color": [148, 226, 213],
19+
"Number Color": [250, 179, 135],
20+
"String Color": [166, 227, 161],
21+
"Comment Color": [108, 112, 134],
22+
"Bool Color": [243, 139, 168],
23+
"\"nil\" Color": [243, 139, 168],
24+
"Function Name Color": [137, 180, 250],
25+
"\"function\" Color": [203, 166, 247],
26+
"\"local\" Color": [203, 166, 247],
27+
"\"self\" Color": [203, 166, 247],
28+
"Keyword Color": [203, 166, 247],
29+
"Built-in Function Color": [137, 180, 250],
30+
"\"TODO\" Color": [203, 166, 247],
31+
"Method Color": [137, 180, 250]
32+
}]]
33+
local theme = game.HttpService:JSONDecode(json)
34+
local studio = settings().Studio
35+
for name, color in pairs(theme) do
36+
color = Color3.fromRGB(color[1], color[2], color[3])
37+
local success = pcall(function()
38+
studio[name] = color
39+
end)
40+
if not success then
41+
warn(("%s is not a valid theme color"):format(name))
42+
end
43+
end
44+
if isInitialLaunch then
45+
print("Script Editor theme set to Catppuccin Mocha!")
46+
else
47+
print("Theme changed; changed script editor theme to Catppuccin Mocha!")
48+
end
49+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
return function(isInitialLaunch: boolean)
2+
local json = [[{
3+
"Property Color": [76, 79, 105],
4+
"Luau Keyword Color": [76, 79, 105],
5+
6+
"Background Color": [239, 241, 245],
7+
"Selection Color": [76, 79, 105],
8+
"Selection Background Color": [204, 207, 215],
9+
"Error Color": [210, 15, 57],
10+
"Warning Color": [254, 100, 11],
11+
"Find Selection Background Color": [230, 173, 189],
12+
"Matching Word Background Color": [204, 207, 215],
13+
"Whitespace Color": [136, 57, 239],
14+
"Current Line Highlight Color": [239, 241, 245],
15+
"Ruler Color": [172, 176, 190],
16+
"Bracket Color": [210, 15, 57],
17+
"Text Color": [76, 79, 105],
18+
"Operator Color": [23, 146, 153],
19+
"Number Color": [254, 100, 11],
20+
"String Color": [64, 160, 43],
21+
"Comment Color": [156, 160, 176],
22+
"Bool Color": [254, 100, 11],
23+
"\"nil\" Color": [210, 15, 57],
24+
"Function Name Color": [30, 102, 245],
25+
"\"function\" Color": [136, 57, 239],
26+
"\"local\" Color": [136, 57, 239],
27+
"\"self\" Color": [136, 57, 239],
28+
"Keyword Color": [136, 57, 239],
29+
"Built-in Function Color": [30, 102, 245],
30+
"\"TODO\" Color": [136, 57, 239],
31+
"Method Color": [30, 102, 245]
32+
}]]
33+
local theme = game.HttpService:JSONDecode(json)
34+
local studio = settings().Studio
35+
for name, color in pairs(theme) do
36+
color = Color3.fromRGB(color[1], color[2], color[3])
37+
local success = pcall(function()
38+
studio[name] = color
39+
end)
40+
if not success then
41+
warn(("%s is not a valid theme color"):format(name))
42+
end
43+
end
44+
if isInitialLaunch then
45+
print("Script Editor theme set to Catppuccin Latte!")
46+
else
47+
print("Theme changed; changed script editor theme to Catppuccin Latte!")
48+
end
49+
end

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rojo build --output "$env:localappdata\Roblox\Plugins\Rawblocky-SubwaySurfers.rbxmx"
1+
rojo build --output "$env:localappdata\Roblox\Plugins\Rawblocky-ThemeScriptExecutor.rbxmx"

0 commit comments

Comments
 (0)