Browse Source

Revert "update"

This reverts commit c5767edee15ffb530792a8e2568301f7d92ac9ac.
galo 1 year ago
parent
commit
21bbb6f4e0
5 changed files with 174 additions and 0 deletions
  1. 5 0
      Camera2D.gd
  2. 29 0
      Databasebckp.gd
  3. 71 0
      Helloworld.gd
  4. 25 0
      PowerMenu.gd
  5. 44 0
      PowerMenu.tscn

+ 5 - 0
Camera2D.gd

@@ -0,0 +1,5 @@
+extends Camera2D
+
+func _physics_process(delta):
+	zoom.x += 0.001 * delta
+	zoom.y += 0.001 * delta

+ 29 - 0
Databasebckp.gd

@@ -0,0 +1,29 @@
+extends Node
+
+# CRUD
+
+var crud = {}
+
+func Create(key,value):
+	if crud.has(key):
+		print('key already exist')
+		return
+	crud[key] = value
+
+func Read(key):
+	if not crud.has(key):
+		print('key doesent exist')
+		return
+	return crud[key]
+
+func Update(key,value):
+	if not crud.has(key):
+		print('key doesent exist')
+		return
+	crud[key] = value
+
+func delete(key):
+	if not crud.has(key):
+		print('key doesent exist')
+		return
+	crud.erase(key)

+ 71 - 0
Helloworld.gd

@@ -0,0 +1,71 @@
+extends Node
+
+var database := PostgreSQLClient.new()
+
+const USER = "samuel"
+const PASSWORD = "123123"
+const HOST = "localhost"
+const PORT = 5432 # Default postgres port
+const DATABASE = "samuel" # Database name
+
+
+func _init() -> void:
+	var _error := database.connect("connection_established", self, "_executer")
+	_error = database.connect("authentication_error", self, "_authentication_error")
+	_error = database.connect("connection_closed", self, "_close")
+	
+	#Connection to the database
+	_error = database.connect_to_host("postgresql://%s:%s@%s:%d/%s" % [USER, PASSWORD, HOST, PORT, DATABASE])
+	print('trying to connect')
+	print(_error)
+
+func _physics_process(_delta: float) -> void:
+	database.poll()
+
+
+func _authentication_error(error_object: Dictionary) -> void:
+	prints("Error connection to database:", error_object["message"])
+
+
+func _executer() -> void:
+	print(database.parameter_status)
+	
+	var datas := database.execute("""
+	select * from niggers;
+	""")
+	
+#	var datas := database.execute("""
+#		BEGIN;
+#		/*Helloworld*/
+#		SELECT concat('Hello', 'World');
+#		COMMIT;
+#	""")
+	
+	
+	#The datas variable contains an array of PostgreSQLQueryResult object.
+	for data in datas:
+		#Specifies the number of fields in a row (can be zero).
+		print(data.number_of_fields_in_a_row)
+
+		# This is usually a single word that identifies which SQL command was completed.
+		# note: the "BEGIN" and "COMMIT" commands return empty values
+		print(data.command_tag)
+
+		print(data.row_description)
+
+		print(data.data_row)
+			
+		prints("Notice:", data.notice)
+	
+	if not database.error_object.empty():
+		prints("Error:", database.error_object)
+
+	database.close()
+
+
+func _close(clean_closure := true) -> void:
+	prints("DB CLOSE,", "Clean closure:", clean_closure)
+
+
+func _exit_tree() -> void:
+	database.close()

+ 25 - 0
PowerMenu.gd

@@ -0,0 +1,25 @@
+extends CanvasLayer
+
+var idbuffer = []
+
+func showmenu(powers = ['power1','power2','power3'], id = 0):
+	idbuffer = id
+	$CenterContainer.show()
+	for i in $CenterContainer/VBoxContainer.get_child_count():
+		$CenterContainer/VBoxContainer.get_child(i).text  = powers[i]
+
+func _on_Button_button_down():
+	senddatatoserver(0)
+	pass # Replace with function body.
+
+func _on_Button2_button_down():
+	senddatatoserver(1)
+	pass # Replace with function body.
+
+func _on_Button3_button_down():
+	senddatatoserver(2)
+	pass # Replace with function body.
+
+func senddatatoserver(arg = ''):
+	get_parent().players_choice_is(arg, idbuffer)
+	$CenterContainer.hide()

+ 44 - 0
PowerMenu.tscn

@@ -0,0 +1,44 @@
+[gd_scene load_steps=2 format=2]
+
+[ext_resource path="res://PowerMenu.gd" type="Script" id=1]
+
+[node name="PowerMenu" type="CanvasLayer"]
+script = ExtResource( 1 )
+
+[node name="CenterContainer" type="CenterContainer" parent="."]
+visible = false
+anchor_right = 1.0
+anchor_bottom = 1.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
+margin_left = 293.0
+margin_top = 146.0
+margin_right = 346.0
+margin_bottom = 214.0
+alignment = 1
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="Button1" type="Button" parent="CenterContainer/VBoxContainer"]
+margin_right = 53.0
+margin_bottom = 20.0
+text = "option"
+
+[node name="Button2" type="Button" parent="CenterContainer/VBoxContainer"]
+margin_top = 24.0
+margin_right = 53.0
+margin_bottom = 44.0
+text = "option"
+
+[node name="Button3" type="Button" parent="CenterContainer/VBoxContainer"]
+margin_top = 48.0
+margin_right = 53.0
+margin_bottom = 68.0
+text = "option"
+[connection signal="button_down" from="CenterContainer/VBoxContainer/Button1" to="." method="_on_Button_button_down"]
+[connection signal="button_down" from="CenterContainer/VBoxContainer/Button2" to="." method="_on_Button2_button_down"]
+[connection signal="button_down" from="CenterContainer/VBoxContainer/Button3" to="." method="_on_Button3_button_down"]