Skip to content

Commit c65aa89

Browse files
committed
v1.1.0: CLI, Discord SDk, update checker
1 parent f513686 commit c65aa89

52 files changed

Lines changed: 959 additions & 820 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lua/Plugins/test.gd

Lines changed: 0 additions & 11 deletions
This file was deleted.

Lua/test.gd

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ To extend the functionality of GriddyCode for a specific **file extension**, cre
5959

6060
| Method | Example | Description | Notes |
6161
| -------- | -------- | -------- | -------- |
62-
| `highlight(keyword: String, color: String)` | `highlight("const", "reserved")` | Tells GriddyCode to highlight a certain keyword with a preset of colors. | Available colors: `reserved`, `string`, `binary`, `symbol`, `variable`, `operator`, `comments`, `error`, `function`, `member` |
62+
| `highlight(keyword: String, color: String)` | `highlight("const", "reserved")` | Tells GriddyCode to highlight a certain keyword with a preset of colors. | Available colors: `reserved`, `annotation`, `string`, `binary`, `symbol`, `variable`, `operator`, `comments`, `error`, `function`, `member` |
6363
| `highlight_region(start: String, end: String, color: String, line_only: bool = false)` | `highlight("/*", "*/", "comments", false)` | Tells GriddyCode to highlight a region with a preset of colors. | The `start` must be a symbol. Due to Godot's limited functionality, you can't use RegEx. |
6464
| `add_comment(comment: String)` | `add_comment("What is blud doing 🗣️🗣️🗣️")` | Adds a comment to be randomly chosen in the `CTRL` + `L` menu. | The username, profile picture, date, and likes are chosen by GriddyCode. |
65-
| `detect_functions(content: String) -> Array[String]` | `detect_functions("const test = 3; function main() {}; async init() => { main() }")` | Called by GriddyCode upon input. Results are showed in the autocomplete feature. | This must be provided by the Lua script. It must return an array of strings (i.e. ["main", "init"]). |
66-
| `detect_variables(content: String) -> Array[String]` | `detect_variables("const test = 3;")` | Called by GriddyCode upon input. Results are showed in the autocomplete feature. | This must be provided by the Lua script. It must return an array of strings (i.e. ["test"]). |
65+
| `detect_functions(content: String, line: int, column: int) -> Array[String]` | `detect_functions("const test = 3; function main() {}; async init() => { main() }")` | Called by GriddyCode upon input. Results are showed in the autocomplete feature. | This must be provided by the Lua script. It must return an array of strings (i.e. ["main", "init"]). "line" and "column" are the position of the cursor when the autocomplete was requested. |
66+
| `detect_variables(content: String, line: int, column: int) -> Array[String]` | `detect_variables("const test = 3;")` | Called by GriddyCode upon input. Results are showed in the autocomplete feature. | This must be provided by the Lua script. It must return an array of strings (i.e. ["test"]). "line" and "column" are the position of the cursor when the autocomplete was requested. |
6767

6868
*Note: to provide reserved variables/functions (i.e. `Math`/`parseInt()` in JS) you can have them already set up in the array you return. GriddyCode will handle the rest!*
6969

Scenes/comments.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ script = ExtResource("1_8hvfh")
2222
[node name="ColorRect" type="ColorRect" parent="."]
2323
material = SubResource("ShaderMaterial_onjnb")
2424
layout_mode = 0
25-
offset_right = 392.0
25+
offset_right = 429.0
2626
offset_bottom = 534.0
2727
color = Color(0, 0, 0, 1)
2828

Scenes/editor.tscn

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ script = ExtResource("2_7x3ll")
101101

102102
[node name="Background" type="ColorRect" parent="."]
103103
unique_name_in_owner = true
104-
visible = false
105104
modulate = Color(1, 1, 1, 0)
106-
offset_right = 1920.0
107-
offset_bottom = 1080.0
105+
offset_left = -368.0
106+
offset_top = -207.0
107+
offset_right = 2263.0
108+
offset_bottom = 1342.0
108109

109110
[node name="FileDialog" type="RichTextLabel" parent="."]
110111
unique_name_in_owner = true
@@ -136,40 +137,6 @@ script = ExtResource("5_bhd70")
136137
wait_time = 5.0
137138
autostart = true
138139

139-
[node name="Intro" type="Node2D" parent="."]
140-
unique_name_in_owner = true
141-
visible = false
142-
143-
[node name="RichTextLabel" type="RichTextLabel" parent="Intro"]
144-
offset_left = 836.0
145-
offset_top = 112.0
146-
offset_right = 3336.0
147-
offset_bottom = 2112.0
148-
scale = Vector2(0.235, 0.235)
149-
theme_override_font_sizes/normal_font_size = 376
150-
bbcode_enabled = true
151-
text = "Greetings!"
152-
153-
[node name="RichTextLabel2" type="RichTextLabel" parent="Intro"]
154-
offset_left = 841.0
155-
offset_top = 244.0
156-
offset_right = 3341.0
157-
offset_bottom = 2244.0
158-
scale = Vector2(0.235, 0.235)
159-
theme_override_font_sizes/normal_font_size = 146
160-
bbcode_enabled = true
161-
text = "You're currently using [color=#c9daf8]Bussin[/color] [color=#85c6ff]GriddyCode[/color]"
162-
163-
[node name="RichTextLabel3" type="RichTextLabel" parent="Intro"]
164-
offset_left = 841.0
165-
offset_top = 380.0
166-
offset_right = 3341.0
167-
offset_bottom = 2380.0
168-
scale = Vector2(0.235, 0.235)
169-
theme_override_font_sizes/normal_font_size = 106
170-
bbcode_enabled = true
171-
text = "To get started, please choose a file."
172-
173140
[node name="Settings" type="Node2D" parent="."]
174141
unique_name_in_owner = true
175142

Scenes/update.tscn

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://bkx02j85qa1rm"]
2+
3+
[ext_resource type="Script" path="res://Scripts/update.gd" id="1_ug1sp"]
4+
[ext_resource type="Script" path="res://Scripts/hyperlink.gd" id="2_w1buf"]
5+
6+
[node name="Control" type="Control"]
7+
layout_mode = 3
8+
anchors_preset = 15
9+
anchor_right = 1.0
10+
anchor_bottom = 1.0
11+
grow_horizontal = 2
12+
grow_vertical = 2
13+
script = ExtResource("1_ug1sp")
14+
15+
[node name="RichTextLabel" type="RichTextLabel" parent="."]
16+
layout_mode = 0
17+
offset_top = 23.0
18+
offset_right = 256.0
19+
offset_bottom = 63.0
20+
text = "Current version: v1.0.3"
21+
22+
[node name="Button" type="Button" parent="."]
23+
layout_mode = 0
24+
offset_top = 56.0
25+
offset_right = 257.0
26+
offset_bottom = 108.0
27+
text = "💾 Check updates"
28+
29+
[node name="HSeparator" type="HSeparator" parent="."]
30+
layout_mode = 0
31+
offset_top = 7.0
32+
offset_right = 271.0
33+
offset_bottom = 11.0
34+
35+
[node name="RichTextLabel2" type="RichTextLabel" parent="."]
36+
visible = false
37+
layout_mode = 0
38+
offset_left = 294.0
39+
offset_top = 58.0
40+
offset_right = 765.0
41+
offset_bottom = 98.0
42+
bbcode_enabled = true
43+
text = "Nothing new..."
44+
scroll_active = false
45+
script = ExtResource("2_w1buf")
46+
47+
[node name="HTTPRequest" type="HTTPRequest" parent="."]
48+
use_threads = true
49+
50+
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]

Scripts/file_dialog.gd

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ signal ui_close
1717

1818
func change_dir(path) -> void:
1919
if !dir: dir = DirAccess.open(path)
20+
#dir.include_hidden = true
21+
# WARNING: this will heavily affect performance if de-commented
2022

2123
dirs = [".."];
2224
dirs.append_array(dir.get_directories())
@@ -30,7 +32,7 @@ func change_dir(path) -> void:
3032
%Cam.focus_on(gp(), zoom)
3133

3234
func setup() -> void:
33-
active = true
35+
active = false
3436
change_dir(editor.current_dir)
3537

3638
update_ui()
@@ -66,10 +68,12 @@ func show_item(item: String) -> void:
6668
else:
6769
push_bgcolor(Color(0, 0, 0, 0)) # Reset background color if not selected
6870

71+
var is_dir = dir.get_directories().find(item) != -1;
72+
6973
if item == "..":
7074
push_color(LuaSingleton.gui.font_color)
7175
add_text("󰕌")
72-
elif dir.get_directories().find(item) != -1:
76+
elif is_dir:
7377
push_color(LuaSingleton.gui.completion_selected_color)
7478
add_text("")
7579
else:
@@ -80,9 +84,22 @@ func show_item(item: String) -> void:
8084
add_text(data.icon)
8185

8286
pop()
83-
add_text(" " + item + '\n')
8487

85-
if active: %Cam.focus_on(Vector2(gp().x, global_position.y + (selected_index * 30)), zoom)
88+
var filename = item.split(".")[0];
89+
90+
if is_dir: filename = item
91+
92+
if filename.length() > 30:
93+
filename = filename.left(30) + "..." + filename.right(3)
94+
95+
if item == "..":
96+
add_text(" %s\n" % [ item ])
97+
elif is_dir or !item.contains("."):
98+
add_text(" %s\n" % [ filename ] )
99+
else:
100+
add_text(" %s.%s\n" % [ filename, item.split(".")[1] ] )
101+
102+
if active: %Cam.focus_on(Vector2(gp().x, global_position.y + (selected_index * 23)), zoom)
86103

87104
# i gave up at that point, sorry for what you're about to witness
88105
func is_selected(item: String) -> bool:
@@ -105,10 +122,13 @@ func handle_enter_key() -> void:
105122
editor.current_dir = dir.get_current_dir();
106123
editor.open_file(editor.current_dir + "/" + item)
107124

108-
%Intro.hide()
109125
LuaSingleton.setup_extension(item.split(".")[-1])
110126

111127
code.setup_highlighter()
128+
get_tree().create_timer(.1).timeout.connect(func():
129+
code.grab_focus()
130+
)
131+
112132
ui_close.emit()
113133
else:
114134
selected_index = 0;

Scripts/file_manager.gd

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,37 @@ const NOTICE = preload("res://Scenes/notice.tscn")
99
var current_file: String;
1010
var current_dir: String = "/";
1111

12+
var time_start = 0
13+
var time_now = 0
14+
1215
func _ready():
13-
if (OS.get_name() == "Windows"):
16+
if LuaSingleton.discord_sdk:
17+
DiscordSDK.app_id = 1220393467738591242 # Application ID
18+
19+
DiscordSDK.large_image = "griddycode" # Image key from "Art Assets"
20+
DiscordSDK.large_image_text = "https://github.com/face-hh/griddycode"
21+
DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system())
22+
23+
if OS.get_name() == "Windows":
1424
current_dir = "C:/"
1525

26+
var args = OS.get_cmdline_args()
27+
var is_debug = OS.is_debug_build()
28+
var path = OS.get_executable_path().get_base_dir()
29+
30+
if args.size() > 0 and !is_debug:
31+
if args[0] != ".":
32+
current_file = path + "/" + args[0]
33+
current_dir = path
34+
35+
var is_cli = args.size() > 0 and !is_debug
36+
37+
print("INFO: Running inside CLI mode: ", is_cli)
38+
1639
inject_lua()
1740
check_for_reserved()
1841

19-
load_game()
42+
load_game(is_cli)
2043
open_file(current_file)
2144

2245
LuaSingleton.themes = list_themes()
@@ -27,8 +50,8 @@ func _ready():
2750
file_dialog.setup()
2851

2952
if !current_file:
53+
LuaSingleton.setup_discord_sdk("Idle", "")
3054
Code.toggle(%FileDialog)
31-
%Intro.show()
3255
warn("Welcome to [color=#c9daf8]Bussin[/color] [color=#85c6ff]GriddyCode[/color]! Please select a file, then press CTRL + I to get started! :D")
3356

3457
func check_for_reserved() -> void:
@@ -40,7 +63,6 @@ func check_for_reserved() -> void:
4063

4164
func _on_file_dialog_file_selected(path: String) -> void:
4265
open_file(path)
43-
%Intro.hide()
4466

4567
func inject_lua() -> void:
4668
DirAccess.make_dir_absolute("user://themes")
@@ -54,15 +76,21 @@ func inject_lua() -> void:
5476
for plugin in plugins:
5577
copy_if_not_exist("langs", "Plugins", plugin)
5678

79+
func copy_from_res(from: String, to: String) -> void:
80+
var file_from = FileAccess.open(from, FileAccess.READ)
81+
var file_to = FileAccess.open(to, FileAccess.WRITE)
82+
file_to.store_buffer(file_from.get_buffer(file_from.get_length()))
83+
file_to = null
84+
file_from = null
85+
5786
func copy_if_not_exist(user_path: String, res_path: String, file: String) -> void:
5887
if !file.contains("lua"): return
5988

6089
var path = "user://" + user_path + "/" + file;
6190
var current_path = "res://Lua/" + res_path + "/" + file;
62-
var exists = FileAccess.file_exists(path);
6391

64-
if !exists:
65-
DirAccess.copy_absolute(current_path, path)
92+
DirAccess.remove_absolute(path)
93+
copy_from_res(current_path, path)
6694

6795
func warn(notice: String) -> void:
6896
var node = NOTICE.instantiate()
@@ -76,6 +104,8 @@ func warn(notice: String) -> void:
76104
)
77105

78106
func open_file(path: String) -> void:
107+
LuaSingleton.setup_discord_sdk("Editing " + path.split("/")[-1], "In " + current_dir.split("/")[-1])
108+
79109
var src = Fs._load(path)
80110

81111
Code.text = src
@@ -100,6 +130,8 @@ func _notification(what):
100130
"settings": LuaSingleton.settings,
101131
"theme": LuaSingleton.theme
102132
}
133+
134+
103135
save_data(save_dict)
104136
Fs.save(current_file, Code.text)
105137

@@ -115,7 +147,7 @@ func save_data(dict: Dictionary):
115147

116148
save_game.store_line(json_string)
117149

118-
func load_game():
150+
func load_game(cli: bool = false):
119151
if not FileAccess.file_exists("user://data.save"):
120152
return # Error! We don't have a save to load.
121153

@@ -132,11 +164,14 @@ func load_game():
132164

133165
var node_data = json.get_data()
134166

135-
current_dir = node_data["current_dir"]
136-
current_file = node_data["current_file"]
167+
if !cli:
168+
current_dir = node_data["current_dir"]
169+
current_file = node_data["current_file"]
170+
137171
LuaSingleton.theme = node_data["theme"]
138172

139-
var settings = node_data["settings"];
173+
var settings = node_data["settings"]
174+
var new_settings = []
140175

141176
for dic: Dictionary in settings:
142177
LuaSingleton.handle_internal_setting_change(dic.property, dic.value)
@@ -148,12 +183,16 @@ func load_game():
148183
return
149184

150185
LuaSingleton.settings.remove_at(index)
151-
LuaSingleton.settings.append(dic);
186+
new_settings.append(dic)
152187

153-
LuaSingleton.settings = node_data["settings"]
188+
for setting in LuaSingleton.settings:
189+
if not new_settings.has(setting):
190+
new_settings.append(setting)
154191

192+
LuaSingleton.settings = new_settings
155193
LuaSingleton.on_settings_change.emit()
156194

195+
157196
func _on_auto_save_timer_timeout():
158197
if !current_file: return
159198
if !Code.file_modified: return

0 commit comments

Comments
 (0)