Skip to content

Commit

Permalink
v1.1.0: CLI, Discord SDk, update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
face-hh committed Mar 23, 2024
1 parent f513686 commit c65aa89
Show file tree
Hide file tree
Showing 52 changed files with 959 additions and 820 deletions.
11 changes: 0 additions & 11 deletions Lua/Plugins/test.gd

This file was deleted.

11 changes: 0 additions & 11 deletions Lua/test.gd

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ To extend the functionality of GriddyCode for a specific **file extension**, cre

| Method | Example | Description | Notes |
| -------- | -------- | -------- | -------- |
| `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` |
| `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` |
| `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. |
| `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. |
| `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"]). |
| `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"]). |
| `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. |
| `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. |

*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!*

Expand Down
2 changes: 1 addition & 1 deletion Scenes/comments.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ script = ExtResource("1_8hvfh")
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource("ShaderMaterial_onjnb")
layout_mode = 0
offset_right = 392.0
offset_right = 429.0
offset_bottom = 534.0
color = Color(0, 0, 0, 1)

Expand Down
41 changes: 4 additions & 37 deletions Scenes/editor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ script = ExtResource("2_7x3ll")

[node name="Background" type="ColorRect" parent="."]
unique_name_in_owner = true
visible = false
modulate = Color(1, 1, 1, 0)
offset_right = 1920.0
offset_bottom = 1080.0
offset_left = -368.0
offset_top = -207.0
offset_right = 2263.0
offset_bottom = 1342.0

[node name="FileDialog" type="RichTextLabel" parent="."]
unique_name_in_owner = true
Expand Down Expand Up @@ -136,40 +137,6 @@ script = ExtResource("5_bhd70")
wait_time = 5.0
autostart = true

[node name="Intro" type="Node2D" parent="."]
unique_name_in_owner = true
visible = false

[node name="RichTextLabel" type="RichTextLabel" parent="Intro"]
offset_left = 836.0
offset_top = 112.0
offset_right = 3336.0
offset_bottom = 2112.0
scale = Vector2(0.235, 0.235)
theme_override_font_sizes/normal_font_size = 376
bbcode_enabled = true
text = "Greetings!"

[node name="RichTextLabel2" type="RichTextLabel" parent="Intro"]
offset_left = 841.0
offset_top = 244.0
offset_right = 3341.0
offset_bottom = 2244.0
scale = Vector2(0.235, 0.235)
theme_override_font_sizes/normal_font_size = 146
bbcode_enabled = true
text = "You're currently using [color=#c9daf8]Bussin[/color] [color=#85c6ff]GriddyCode[/color]"

[node name="RichTextLabel3" type="RichTextLabel" parent="Intro"]
offset_left = 841.0
offset_top = 380.0
offset_right = 3341.0
offset_bottom = 2380.0
scale = Vector2(0.235, 0.235)
theme_override_font_sizes/normal_font_size = 106
bbcode_enabled = true
text = "To get started, please choose a file."

[node name="Settings" type="Node2D" parent="."]
unique_name_in_owner = true

Expand Down
50 changes: 50 additions & 0 deletions Scenes/update.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[gd_scene load_steps=3 format=3 uid="uid://bkx02j85qa1rm"]

[ext_resource type="Script" path="res://Scripts/update.gd" id="1_ug1sp"]
[ext_resource type="Script" path="res://Scripts/hyperlink.gd" id="2_w1buf"]

[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ug1sp")

[node name="RichTextLabel" type="RichTextLabel" parent="."]
layout_mode = 0
offset_top = 23.0
offset_right = 256.0
offset_bottom = 63.0
text = "Current version: v1.0.3"

[node name="Button" type="Button" parent="."]
layout_mode = 0
offset_top = 56.0
offset_right = 257.0
offset_bottom = 108.0
text = "💾 Check updates"

[node name="HSeparator" type="HSeparator" parent="."]
layout_mode = 0
offset_top = 7.0
offset_right = 271.0
offset_bottom = 11.0

[node name="RichTextLabel2" type="RichTextLabel" parent="."]
visible = false
layout_mode = 0
offset_left = 294.0
offset_top = 58.0
offset_right = 765.0
offset_bottom = 98.0
bbcode_enabled = true
text = "Nothing new..."
scroll_active = false
script = ExtResource("2_w1buf")

[node name="HTTPRequest" type="HTTPRequest" parent="."]
use_threads = true

[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
30 changes: 25 additions & 5 deletions Scripts/file_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ signal ui_close

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

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

func setup() -> void:
active = true
active = false
change_dir(editor.current_dir)

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

var is_dir = dir.get_directories().find(item) != -1;

if item == "..":
push_color(LuaSingleton.gui.font_color)
add_text("󰕌")
elif dir.get_directories().find(item) != -1:
elif is_dir:
push_color(LuaSingleton.gui.completion_selected_color)
add_text("")
else:
Expand All @@ -80,9 +84,22 @@ func show_item(item: String) -> void:
add_text(data.icon)

pop()
add_text(" " + item + '\n')

if active: %Cam.focus_on(Vector2(gp().x, global_position.y + (selected_index * 30)), zoom)
var filename = item.split(".")[0];

if is_dir: filename = item

if filename.length() > 30:
filename = filename.left(30) + "..." + filename.right(3)

if item == "..":
add_text(" %s\n" % [ item ])
elif is_dir or !item.contains("."):
add_text(" %s\n" % [ filename ] )
else:
add_text(" %s.%s\n" % [ filename, item.split(".")[1] ] )

if active: %Cam.focus_on(Vector2(gp().x, global_position.y + (selected_index * 23)), zoom)

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

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

code.setup_highlighter()
get_tree().create_timer(.1).timeout.connect(func():
code.grab_focus()
)

ui_close.emit()
else:
selected_index = 0;
Expand Down
65 changes: 52 additions & 13 deletions Scripts/file_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,37 @@ const NOTICE = preload("res://Scenes/notice.tscn")
var current_file: String;
var current_dir: String = "/";

var time_start = 0
var time_now = 0

func _ready():
if (OS.get_name() == "Windows"):
if LuaSingleton.discord_sdk:
DiscordSDK.app_id = 1220393467738591242 # Application ID

DiscordSDK.large_image = "griddycode" # Image key from "Art Assets"
DiscordSDK.large_image_text = "https://github.com/face-hh/griddycode"
DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system())

if OS.get_name() == "Windows":
current_dir = "C:/"

var args = OS.get_cmdline_args()
var is_debug = OS.is_debug_build()
var path = OS.get_executable_path().get_base_dir()

if args.size() > 0 and !is_debug:
if args[0] != ".":
current_file = path + "/" + args[0]
current_dir = path

var is_cli = args.size() > 0 and !is_debug

print("INFO: Running inside CLI mode: ", is_cli)

inject_lua()
check_for_reserved()

load_game()
load_game(is_cli)
open_file(current_file)

LuaSingleton.themes = list_themes()
Expand All @@ -27,8 +50,8 @@ func _ready():
file_dialog.setup()

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

func check_for_reserved() -> void:
Expand All @@ -40,7 +63,6 @@ func check_for_reserved() -> void:

func _on_file_dialog_file_selected(path: String) -> void:
open_file(path)
%Intro.hide()

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

func copy_from_res(from: String, to: String) -> void:
var file_from = FileAccess.open(from, FileAccess.READ)
var file_to = FileAccess.open(to, FileAccess.WRITE)
file_to.store_buffer(file_from.get_buffer(file_from.get_length()))
file_to = null
file_from = null

func copy_if_not_exist(user_path: String, res_path: String, file: String) -> void:
if !file.contains("lua"): return

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

if !exists:
DirAccess.copy_absolute(current_path, path)
DirAccess.remove_absolute(path)
copy_from_res(current_path, path)

func warn(notice: String) -> void:
var node = NOTICE.instantiate()
Expand All @@ -76,6 +104,8 @@ func warn(notice: String) -> void:
)

func open_file(path: String) -> void:
LuaSingleton.setup_discord_sdk("Editing " + path.split("/")[-1], "In " + current_dir.split("/")[-1])

var src = Fs._load(path)

Code.text = src
Expand All @@ -100,6 +130,8 @@ func _notification(what):
"settings": LuaSingleton.settings,
"theme": LuaSingleton.theme
}


save_data(save_dict)
Fs.save(current_file, Code.text)

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

save_game.store_line(json_string)

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

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

var node_data = json.get_data()

current_dir = node_data["current_dir"]
current_file = node_data["current_file"]
if !cli:
current_dir = node_data["current_dir"]
current_file = node_data["current_file"]

LuaSingleton.theme = node_data["theme"]

var settings = node_data["settings"];
var settings = node_data["settings"]
var new_settings = []

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

LuaSingleton.settings.remove_at(index)
LuaSingleton.settings.append(dic);
new_settings.append(dic)

LuaSingleton.settings = node_data["settings"]
for setting in LuaSingleton.settings:
if not new_settings.has(setting):
new_settings.append(setting)

LuaSingleton.settings = new_settings
LuaSingleton.on_settings_change.emit()


func _on_auto_save_timer_timeout():
if !current_file: return
if !Code.file_modified: return
Expand Down
Loading

0 comments on commit c65aa89

Please sign in to comment.