Implement server that listens for connection from fake-editor script

As well as a commit message editor! \o/
This commit is contained in:
Sebastian Morr 2020-09-01 15:14:01 +02:00
parent 80cbff92a1
commit 01cf45dee4
4 changed files with 67 additions and 2 deletions

39
main.gd
View file

@ -8,10 +8,26 @@ var dragged = null
var viewport_size var viewport_size
var server
var client_connection
func _ready(): func _ready():
viewport_size = get_viewport_rect().size viewport_size = get_viewport_rect().size
server = TCP_Server.new()
server.listen(1234)
func _connected(id, proto):
print("!!!")
print(id)
func _player_connected(id):
print("connected")
func _process(delta): func _process(delta):
if server.is_connection_available():
client_connection = server.take_connection()
read_commit_message()
if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7: if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
if Input.is_action_just_pressed("click"): if Input.is_action_just_pressed("click"):
var mindist = 9999999 var mindist = 9999999
@ -30,6 +46,29 @@ func _process(delta):
update_index() update_index()
update_objects() update_objects()
apply_forces() apply_forces()
func read_commit_message():
$CommitMessage.show()
$Terminal/Input.editable = false
var file_path = "/tmp/githydragit/.git/COMMIT_EDITMSG"
var file = File.new()
file.open(file_path, File.READ)
var content = file.get_as_text()
file.close()
$CommitMessage.text = content
func save_commit_message():
var file = File.new()
var file_path = "/tmp/githydragit/.git/COMMIT_EDITMSG"
file.open(file_path, File.WRITE)
var content = $CommitMessage.text
file.store_string(content)
file.close()
print("disconnect")
client_connection.disconnect_from_host()
$Terminal/Input.editable = true
$CommitMessage.text = ""
$CommitMessage.hide()
func update_index(): func update_index():
$Index.text = git("ls-files") $Index.text = git("ls-files")

View file

@ -49,4 +49,25 @@ margin_bottom = 1075.0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="CommitMessage" type="TextEdit" parent="."]
visible = false
margin_left = 889.832
margin_top = 16.4234
margin_right = 1388.83
margin_bottom = 582.423
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="CommitMessage"]
margin_left = 344.277
margin_top = 509.45
margin_right = 493.277
margin_bottom = 558.45
text = "SAVE!"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"] [connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"]
[connection signal="pressed" from="CommitMessage/Button" to="." method="save_commit_message"]

View file

@ -2,5 +2,5 @@
echo Hi, I am commit-hook echo Hi, I am commit-hook
echo $* echo $*
zenity --question nc localhost 1234
echo Goodbye echo Goodbye

View file

@ -1,8 +1,13 @@
extends Node2D extends Node2D
var thread
func send_command(command): func send_command(command):
thread = Thread.new()
thread.start(self, "run_command_in_a_thread", command)
func run_command_in_a_thread(command):
var cwd = run("pwd") var cwd = run("pwd")
var output = [] var output = []
var hacky_command = command var hacky_command = command