-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconsole.gd
More file actions
59 lines (51 loc) · 1.63 KB
/
console.gd
File metadata and controls
59 lines (51 loc) · 1.63 KB
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
extends Window
var Server_PID: int
var Server_Log
var CommandExecutorFile = OS.get_data_dir() + "/bootfy/dungeonfy/dfysp-main/plugins/CommandExecutor/commands.txt"
var log_file: FileAccess = null
var last_read_pos: int = 0
func _ready() -> void:
print("PID: " + str(Server_PID))
open_log_file(Server_Log)
var contents = read_all_log()
$UI/TextEdit.text += contents
func _process(_delta: float) -> void:
var new_lines = read_new_log_lines()
if new_lines != "":
$UI/TextEdit.text += new_lines
$UI/TextEdit.scroll_vertical = $UI/TextEdit.get_line_count()
func open_log_file(log_path: String) -> void:
if FileAccess.file_exists(log_path):
log_file = FileAccess.open(log_path, FileAccess.READ)
if log_file:
last_read_pos = 0
else:
print("Log file not found:", log_path)
func read_all_log() -> String:
if not log_file:
return ""
log_file.seek(0)
var file_len = log_file.get_length()
var all_data = log_file.get_buffer(file_len).get_string_from_utf8()
last_read_pos = file_len
return all_data
func read_new_log_lines() -> String:
if not log_file:
return ""
var file_len = log_file.get_length()
if file_len < last_read_pos:
last_read_pos = 0
log_file.seek(last_read_pos)
var new_data = log_file.get_buffer(file_len - last_read_pos).get_string_from_utf8()
last_read_pos = log_file.get_position()
return new_data
func _on_line_edit_submit(new_text: String ) -> void:
print(CommandExecutorFile)
var file := FileAccess.open(CommandExecutorFile, FileAccess.WRITE)
if file:
file.store_string(new_text + "\n")
file.close()
print("Command: ", new_text)
else:
print("Failed to open command file!")
$UI/LineEdit.text = ""