mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-13 19:04:54 +01:00
Implement server that listens for connection from fake-editor script
As well as a commit message editor! \o/
This commit is contained in:
parent
80cbff92a1
commit
01cf45dee4
4 changed files with 67 additions and 2 deletions
39
main.gd
39
main.gd
|
@ -8,10 +8,26 @@ var dragged = null
|
|||
|
||||
var viewport_size
|
||||
|
||||
var server
|
||||
var client_connection
|
||||
|
||||
func _ready():
|
||||
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):
|
||||
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 Input.is_action_just_pressed("click"):
|
||||
var mindist = 9999999
|
||||
|
@ -30,6 +46,29 @@ func _process(delta):
|
|||
update_index()
|
||||
update_objects()
|
||||
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():
|
||||
$Index.text = git("ls-files")
|
||||
|
|
21
main.tscn
21
main.tscn
|
@ -49,4 +49,25 @@ margin_bottom = 1075.0
|
|||
__meta__ = {
|
||||
"_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="pressed" from="CommitMessage/Button" to="." method="save_commit_message"]
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
echo Hi, I am commit-hook
|
||||
echo $*
|
||||
zenity --question
|
||||
nc localhost 1234
|
||||
echo Goodbye
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
extends Node2D
|
||||
|
||||
var thread
|
||||
|
||||
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 output = []
|
||||
|
||||
var hacky_command = command
|
||||
|
|
Loading…
Reference in a new issue