Comunicacion entre el juego y la api(en local)
This commit is contained in:
parent
cdcd56c794
commit
4b68f652fe
|
|
@ -192,4 +192,4 @@ Game={
|
|||
"hide_selection": false,
|
||||
"select_mode": 0
|
||||
}
|
||||
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@21272/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@54/@VBoxContainer@55/@EditorMainScreen@102/MainScreen/@CanvasItemEditor@11482/@VSplitContainer@11134/@HSplitContainer@11136/@HSplitContainer@11138/@Control@11139/@SubViewportContainer@11140/@SubViewport@11141/Configuration/VBoxContainer/levels_menu")])
|
||||
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@21272/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@54/@VBoxContainer@55/@EditorMainScreen@102/MainScreen/@CanvasItemEditor@11482/@VSplitContainer@11134/@HSplitContainer@11136/@HSplitContainer@11138/@Control@11139/@SubViewportContainer@11140/@SubViewport@11141/Node2D")])
|
||||
|
|
|
|||
|
|
@ -192,4 +192,4 @@ Game={
|
|||
"hide_selection": false,
|
||||
"select_mode": 0
|
||||
}
|
||||
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@21272/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@54/@VBoxContainer@55/@EditorMainScreen@102/MainScreen/@CanvasItemEditor@11482/@VSplitContainer@11134/@HSplitContainer@11136/@HSplitContainer@11138/@Control@11139/@SubViewportContainer@11140/@SubViewport@11141/Configuration/VBoxContainer/levels_menu")])
|
||||
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@21272/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@54/@VBoxContainer@55/@EditorMainScreen@102/MainScreen/@CanvasItemEditor@11482/@VSplitContainer@11134/@HSplitContainer@11136/@HSplitContainer@11138/@Control@11139/@SubViewportContainer@11140/@SubViewport@11141/Node2D")])
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
[folding]
|
||||
|
||||
sections_unfolded=PackedStringArray()
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
Button
|
||||
Label
|
||||
VBoxContainer
|
||||
PopupPanel
|
||||
MenuButton
|
||||
ColorPickerButton
|
||||
VBoxContainer
|
||||
Control
|
||||
HBoxContainer
|
||||
AudioStreamPlayer
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
dock_3_selected_tab_idx=0
|
||||
dock_4_selected_tab_idx=0
|
||||
dock_5_selected_tab_idx=0
|
||||
dock_5_selected_tab_idx=1
|
||||
dock_floating={}
|
||||
dock_filesystem_h_split_offset=240
|
||||
dock_filesystem_v_split_offset=0
|
||||
dock_filesystem_display_mode=0
|
||||
dock_filesystem_file_sort=0
|
||||
dock_filesystem_file_list_display_mode=1
|
||||
dock_filesystem_selected_paths=PackedStringArray("res://scenes/Configuration.tscn")
|
||||
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scenes/")
|
||||
dock_filesystem_selected_paths=PackedStringArray("res://scenes/Game.tscn")
|
||||
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scripts/", "res://scenes/")
|
||||
dock_node_current_tab=0
|
||||
dock_history_include_scene=true
|
||||
dock_history_include_global=true
|
||||
|
|
@ -28,8 +28,8 @@ dock_5="Inspector,Node,History"
|
|||
|
||||
[EditorNode]
|
||||
|
||||
open_scenes=PackedStringArray("res://scenes/Game.tscn", "res://scripts/screen_manager.tscn", "res://scenes/Configuration.tscn")
|
||||
current_scene="res://scenes/Configuration.tscn"
|
||||
open_scenes=PackedStringArray("res://scenes/Game.tscn", "res://scenes/Configuration.tscn")
|
||||
current_scene="res://scenes/Game.tscn"
|
||||
center_split_offset=0
|
||||
selected_default_debugger_tab_idx=0
|
||||
selected_main_editor_idx=2
|
||||
|
|
@ -44,12 +44,12 @@ size=Vector2i(1024, 1000)
|
|||
|
||||
[ScriptEditor]
|
||||
|
||||
open_scripts=["res://scripts/animal_tile.gd", "res://scenes/configuration.gd", "res://scripts/game_data.gd", "res://scripts/image_loader.gd", "res://scripts/node_2d.gd", "res://scripts/screen_manager.gd"]
|
||||
selected_script="res://scenes/configuration.gd"
|
||||
open_scripts=["res://scripts/animal_tile.gd", "res://scripts/configuration.gd", "res://scripts/game_data.gd", "res://scripts/image_loader.gd", "res://scripts/node_2d.gd", "res://scripts/screen_manager.gd"]
|
||||
selected_script="res://scripts/game_data.gd"
|
||||
open_help=[]
|
||||
script_split_offset=200
|
||||
list_split_offset=0
|
||||
zoom_factor=1.0
|
||||
zoom_factor=1.07143
|
||||
|
||||
[GameView]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fc8a56933c4b1c8d796fdb8f7a9f9475
|
||||
::res://::1744315176
|
||||
export_presets.cfg::TextFile/TextFile::-1::1744298367::0::1::::<><><>0<>0<><>::
|
||||
::res://::1744408654
|
||||
export_presets.cfg::TextFile::-1::1744399092::0::1::::<><><>0<>0<><>::
|
||||
icon.svg::CompressedTexture2D/CompressedTexture2D::4846091670585274137::1744195706::1744195716::1::::<><><>0<>0<>a6ef899d0bda3cdd63eaa6b079d03aca<>res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex::
|
||||
::res://audios/::1744295153
|
||||
instrucciones.mp3::AudioStreamMP3/AudioStreamMP3::7110748935779360531::1744295152::1744295153::1::::<><><>0<>0<>907b78c75c0c4deb72d14e7a74dd7acf<>res://.godot/imported/instrucciones.mp3-3e910247f8d0baa2378a660539fef5b4.mp3str::
|
||||
|
|
@ -60,10 +60,14 @@ vaca_color.png::CompressedTexture2D/CompressedTexture2D::1639453517109408540::17
|
|||
vaca_sombra.png::CompressedTexture2D/CompressedTexture2D::4137840386567035395::1744226338::1744226677::1::::<><><>0<>0<>8b8f93705ab813c8fda24891062e2b93<>res://.godot/imported/vaca_sombra.png-87bf77b3bedacf2de6553221767d8158.ctex::
|
||||
zorro_color.png::CompressedTexture2D/CompressedTexture2D::1666546973926131984::1744220372::1744222652::1::::<><><>0<>0<>507db7ef7a8e54c877af1f7c2e943778<>res://.godot/imported/zorro_color.png-9357deebbe773a59422357e0f482914f.ctex::
|
||||
zorro_sombra.png::CompressedTexture2D/CompressedTexture2D::6252548807644359177::1744226356::1744226677::1::::<><><>0<>0<>dd376ca5b7be9cc4c9ab8247eb78f99a<>res://.godot/imported/zorro_sombra.png-a7d9fb62668d52352c13e90c900ac2bc.ctex::
|
||||
::res://scenes/::1744307544
|
||||
Game.tscn::PackedScene::7300647384769136354::1744307544::0::1::::<><><>0<>0<><>::uid://3qvb4d882mqd::::res://scripts/node_2d.gd<>uid://c8kq84p5btav8::::res://audios/instrucciones.mp3<>uid://bkwdw0l43i15v::::res://images/menu_logo.png
|
||||
::res://scripts/::1744307516
|
||||
animal_tile.gd::GDScript::4714635075097887840::1744307516::0::1::::AnimalTile<>Node2D<><>0<>0<><>::
|
||||
game_data.gd::GDScript/GDScript::1767393862001390866::1744292186::0::1::::GameData<>Node<><>0<>0<><>::
|
||||
::res://scenes/::1744404395
|
||||
Configuration.tscn::PackedScene::6729908559101085089::1744403417::0::1::::<><><>0<>0<><>::uid://ctge47k34s7yi::::res://scripts/configuration.gd
|
||||
Game.tscn::PackedScene::7300647384769136354::1744404395::0::1::::<><><>0<>0<><>::uid://3qvb4d882mqd::::res://scripts/node_2d.gd<>uid://c8kq84p5btav8::::res://audios/instrucciones.mp3<>uid://bkwdw0l43i15v::::res://images/menu_logo.png
|
||||
::res://scripts/::1744404395
|
||||
animal_tile.gd::GDScript::4714635075097887840::1744403019::0::1::::AnimalTile<>Node2D<><>0<>0<><>::
|
||||
configuration.gd::GDScript::6119112016534423576::1744402008::0::1::::<>Control<><>0<>0<><>::
|
||||
game_data.gd::GDScript::1767393862001390866::1744404395::0::1::::<>Node<><>0<>0<><>::
|
||||
image_loader.gd::GDScript/GDScript::4945911806681378795::1744289398::0::1::::ImageLoader<>Node<><>0<>0<><>::
|
||||
node_2d.gd::GDScript/GDScript::1999596037927974939::1744304959::0::1::::<>Node2D<><>0<>0<><>::
|
||||
node_2d.gd::GDScript::1999596037927974939::1744403411::0::1::::<>Node2D<><>0<>0<><>::
|
||||
screen_manager.gd::GDScript/GDScript::6637911554621855883::1744315379::0::1::::<>Node<><>0<>0<><>::
|
||||
screen_manager.tscn::PackedScene::1657251017967126927::1744396137::0::1::::<><><>0<>0<><>::
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
res://scenes/Game.tscn
|
||||
res://scripts/screen_manager.gd
|
||||
res://scenes/configuration.gd
|
||||
res://scenes/Configuration.tscn
|
||||
res://scripts/game_data.gd
|
||||
res://scripts/node_2d.gd
|
||||
res://scripts/screen_manager.tscn
|
||||
res://scripts/configuration.gd
|
||||
res://scenes/Configuration.tscn
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ last_selected_language="GDScript"
|
|||
|
||||
[recent_files]
|
||||
|
||||
scripts=["res://scenes/configuration.gd", "res://scripts/screen_manager.gd", "res://scripts/game_data.gd", "res://image_loader.gd", "res://export_presets.cfg", "res://number_title.gd", "res://node_2d.gd"]
|
||||
scenes=["res://scenes/Game.tscn"]
|
||||
scripts=["Object", "res://scenes/configuration.gd", "res://scripts/screen_manager.gd", "res://scripts/game_data.gd", "res://image_loader.gd", "res://export_presets.cfg", "res://number_title.gd", "res://node_2d.gd"]
|
||||
scenes=["res://scenes/Configuration.tscn", "res://scenes/Game.tscn"]
|
||||
|
||||
[export_options]
|
||||
|
||||
|
|
|
|||
|
|
@ -192,4 +192,4 @@ Game={
|
|||
"hide_selection": false,
|
||||
"select_mode": 0
|
||||
}
|
||||
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@21272/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@54/@VBoxContainer@55/@EditorMainScreen@102/MainScreen/@CanvasItemEditor@11482/@VSplitContainer@11134/@HSplitContainer@11136/@HSplitContainer@11138/@Control@11139/@SubViewportContainer@11140/@SubViewport@11141/Configuration/VBoxContainer/levels_menu")])
|
||||
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@21272/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@54/@VBoxContainer@55/@EditorMainScreen@102/MainScreen/@CanvasItemEditor@11482/@VSplitContainer@11134/@HSplitContainer@11136/@HSplitContainer@11138/@Control@11139/@SubViewportContainer@11140/@SubViewport@11141/ScreenManager")])
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ state={
|
|||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 33,
|
||||
"column": 0,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 61,
|
||||
"scroll_position": 48.0,
|
||||
"row": 89,
|
||||
"scroll_position": 71.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ state={
|
|||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 32,
|
||||
"scroll_position": 19.0,
|
||||
"scroll_position": 10.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
|
@ -45,11 +45,11 @@ state={
|
|||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 32,
|
||||
"column": 0,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 36,
|
||||
"scroll_position": 16.0,
|
||||
"row": 182,
|
||||
"scroll_position": 0.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
|
@ -59,11 +59,11 @@ state={
|
|||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 23,
|
||||
"column": 28,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 18,
|
||||
"scroll_position": 0.0,
|
||||
"scroll_position": 140.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
|
@ -82,15 +82,15 @@ state={
|
|||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
||||
[res://scenes/configuration.gd]
|
||||
[res://scripts/configuration.gd]
|
||||
|
||||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 12,
|
||||
"column": 30,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 13,
|
||||
"row": 44,
|
||||
"scroll_position": 0.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,3 +1,3 @@
|
|||
res://scenes/Game.tscn::470d2ca5918c266d5f5ad41f90064b19::1744318189::res://.godot/exported/133200997/export-ff8ceb9b2bd5b48777d3d52e811276ab-Game.scn
|
||||
res://scenes/Configuration.tscn::34869c88940d35a567f149b338aa43c1::1744318190::res://.godot/exported/133200997/export-9342d86e93843c4fab70a2c0224d3fd3-Configuration.scn
|
||||
res://scripts/screen_manager.tscn::9988fbb1a6b9e1613010f5ccda4bc922::1744318189::res://.godot/exported/133200997/export-d70c5745a12c569d3ecc03f08fad1e89-screen_manager.scn
|
||||
res://scenes/Game.tscn::470d2ca5918c266d5f5ad41f90064b19::1744399048::res://.godot/exported/133200997/export-ff8ceb9b2bd5b48777d3d52e811276ab-Game.scn
|
||||
res://scenes/Configuration.tscn::c438d452251509b6acf75454df33bea5::1744399048::res://.godot/exported/133200997/export-9342d86e93843c4fab70a2c0224d3fd3-Configuration.scn
|
||||
res://scripts/screen_manager.tscn::9988fbb1a6b9e1613010f5ccda4bc922::1744396137::res://.godot/exported/133200997/export-d70c5745a12c569d3ecc03f08fad1e89-screen_manager.scn
|
||||
|
|
|
|||
|
|
@ -8,14 +8,6 @@ list=[{
|
|||
"path": "res://scripts/animal_tile.gd"
|
||||
}, {
|
||||
"base": &"Node",
|
||||
"class": &"GameData",
|
||||
"icon": "",
|
||||
"is_abstract": false,
|
||||
"is_tool": false,
|
||||
"language": &"GDScript",
|
||||
"path": "res://scripts/game_data.gd"
|
||||
}, {
|
||||
"base": &"Node",
|
||||
"class": &"ImageLoader",
|
||||
"icon": "",
|
||||
"is_abstract": false,
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -18,6 +18,7 @@ config/icon="res://icon.svg"
|
|||
[autoload]
|
||||
|
||||
ScreenManager="*res://scripts/screen_manager.gd"
|
||||
GameData="*res://scripts/game_data.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c25au08um2kxt"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ctge47k34s7yi" path="res://scenes/configuration.gd" id="1_d6xro"]
|
||||
[ext_resource type="Script" uid="uid://ctge47k34s7yi" path="res://scripts/configuration.gd" id="1_d6xro"]
|
||||
|
||||
[node name="Configuration" type="Control"]
|
||||
layout_mode = 3
|
||||
|
|
@ -18,7 +18,7 @@ offset_bottom = 731.0
|
|||
layout_mode = 2
|
||||
text = "Selecciona un jugador"
|
||||
|
||||
[node name="MenuButton" type="MenuButton" parent="VBoxContainer"]
|
||||
[node name="residents_menu" type="MenuButton" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Residentes"
|
||||
flat = false
|
||||
|
|
|
|||
|
|
@ -70,3 +70,25 @@ layout_mode = 2
|
|||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
columns = 5
|
||||
|
||||
[node name="WinPopup" type="PopupPanel" parent="."]
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="WinPopup"]
|
||||
offset_left = 4.0
|
||||
offset_top = 4.0
|
||||
offset_right = 96.0
|
||||
offset_bottom = 96.0
|
||||
|
||||
[node name="victory_label" type="Label" parent="WinPopup/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="duration_label" type="Label" parent="WinPopup/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="fail_count_label" type="Label" parent="WinPopup/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="exit_endgame_button" type="Button" parent="WinPopup/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[connection signal="pressed" from="WinPopup/VBoxContainer/exit_endgame_button" to="." method="_on_exit_button_pressed"]
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func check_drop_on_board():
|
|||
|
||||
var tiles_container = get_tree().get_root().get_node("Node2D/HBoxContainer/VBoxContainer/TilesContainer")
|
||||
if tiles_container.get_child_count() <= 1:
|
||||
tiles_container.get_parent().call_deferred("check_win")
|
||||
get_tree().get_root().get_node("Node2D").check_win()
|
||||
placed_on_board = true
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,25 @@
|
|||
extends Control
|
||||
|
||||
@onready var levels_menu = $VBoxContainer/levels_menu
|
||||
@onready var residents_menu = $VBoxContainer/residents_menu
|
||||
|
||||
var level = -1
|
||||
var id_player = -1
|
||||
|
||||
func _ready():
|
||||
RenderingServer.set_default_clear_color(Color.SKY_BLUE)
|
||||
levels_menu.get_popup().connect("id_pressed", self._on_level_selected)
|
||||
|
||||
await get_tree().process_frame #Esperar a que se cree HTTPRequest en GameData
|
||||
var residents = await GameData.get_residents_loaded()
|
||||
|
||||
if residents_menu.item_count < residents.size():
|
||||
for resident in residents:
|
||||
var full_name = "%s %s" % [resident.nombre, resident.apellido]
|
||||
var id = int(resident.id)
|
||||
residents_menu.get_popup().add_item(full_name, id)
|
||||
residents_menu.get_popup().connect("id_pressed", self._on_player_selected)
|
||||
|
||||
func _on_level_selected(id):
|
||||
match id:
|
||||
0:
|
||||
|
|
@ -17,6 +29,9 @@ func _on_level_selected(id):
|
|||
2:
|
||||
level = 3
|
||||
|
||||
func _on_player_selected(id):
|
||||
id_player = id
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
var bg_color = $VBoxContainer/bg_color_picker.color
|
||||
var tiles_lines_color = $VBoxContainer/tiles_lines_color_picker.color
|
||||
|
|
@ -29,4 +44,8 @@ func _on_button_pressed() -> void:
|
|||
game_scene.table_lines_color = table_lines_color
|
||||
game_scene.difficulty = level
|
||||
|
||||
if id_player != -1:
|
||||
GameData.start_game(id_player, level)
|
||||
else:
|
||||
print("Selecciona un jugador") #Cambiar a popup
|
||||
ScreenManager.change_scene(game_scene, self)
|
||||
|
|
@ -1,23 +1,160 @@
|
|||
class_name GameData
|
||||
extends Node
|
||||
#Este script se encarga de comunicarse con la api
|
||||
# Este script se encarga de comunicarse con la API
|
||||
|
||||
#Señales para saber cuando se recibe los datos
|
||||
signal residents_received(residents)
|
||||
signal games_received(games)
|
||||
|
||||
var all_residents = []
|
||||
var all_games = []
|
||||
|
||||
static var resident_playing = " "
|
||||
static var start_time: int = 0
|
||||
static var end_time: int = 0
|
||||
static var fail_count: int = 0
|
||||
var resident_playing = " "
|
||||
var start_time: int = 0
|
||||
var end_time: int = 0
|
||||
var fail_count: int = 0
|
||||
var level_game = -1
|
||||
|
||||
static func start_game():
|
||||
### Metodo para inicar partida
|
||||
func start_game(resident, level):
|
||||
resident_playing = resident
|
||||
level_game = level
|
||||
start_time = Time.get_unix_time_from_system()
|
||||
fail_count = 0
|
||||
|
||||
static func end_game():
|
||||
### Metodo para finalizar partida
|
||||
func end_game():
|
||||
end_time = Time.get_unix_time_from_system()
|
||||
|
||||
static func add_fail():
|
||||
### Metodo para añadir fallos
|
||||
func add_fail():
|
||||
fail_count += 1
|
||||
|
||||
static func get_duration() -> int:
|
||||
### Metodo para calcular la duracion entre el incio y el final de la partida (en segundos)
|
||||
func get_duration() -> int:
|
||||
return end_time - start_time
|
||||
|
||||
#--------------------------------------GET RESIDENTES-----------------------------------------------
|
||||
|
||||
### Metodo para hacer un get a la api de todos los residentes
|
||||
func get_residents():
|
||||
var http_request = HTTPRequest.new()
|
||||
get_tree().root.add_child(http_request)
|
||||
|
||||
var status = http_request.connect(
|
||||
"request_completed",
|
||||
Callable(self, "_on_request_get_residents").bind(http_request)
|
||||
)
|
||||
|
||||
var url = "http://localhost:8080/resi/resident"
|
||||
var headers = ["User-Agent: Godot"]
|
||||
var error = http_request.request(url, headers)
|
||||
|
||||
if error != OK:
|
||||
print("Error al hacer GET:", error)
|
||||
|
||||
### Metodo para parsear json de residentes y que emite una señal cuando lo tenga
|
||||
func _on_request_get_residents(result, response_code, headers, body, request_node):
|
||||
print("Código de respuesta:", response_code)
|
||||
|
||||
if response_code == 200:
|
||||
var response_text = body.get_string_from_utf8()
|
||||
var parsed = JSON.parse_string(response_text)
|
||||
|
||||
if parsed != null:
|
||||
all_residents = parsed
|
||||
print("Residentes obtenidos:", all_residents)
|
||||
|
||||
# Emitir la señal para notificar a quien esté conectado
|
||||
emit_signal("residents_received", all_residents)
|
||||
else:
|
||||
print("Error al parsear JSON")
|
||||
else:
|
||||
print("Error del servidor o conexión:", response_code)
|
||||
|
||||
request_node.queue_free() # Liberar para evitar error 31
|
||||
|
||||
### Metodo que espera a la señal de que se han obtenido y parseado los residentes y los devuelve.
|
||||
func get_residents_loaded() -> Array:
|
||||
get_residents()
|
||||
var result = await self.residents_received
|
||||
return result
|
||||
|
||||
|
||||
# ----------------------------- GET JUEGOS --------------------------------------------
|
||||
func get_games():
|
||||
var http_request = HTTPRequest.new()
|
||||
get_tree().root.add_child(http_request)
|
||||
|
||||
var status = http_request.connect(
|
||||
"request_completed",
|
||||
Callable(self, "_on_request_get_games").bind(http_request)
|
||||
)
|
||||
|
||||
var url = "http://localhost:8080/resi/juegos"
|
||||
var headers = ["User-Agent: Godot"]
|
||||
var error = http_request.request(url, headers)
|
||||
|
||||
if error != OK:
|
||||
print("Error al hacer GET en juegos:", error)
|
||||
|
||||
### Metodo para parsear json de residentes y que emite una señal cuando lo tenga
|
||||
func _on_request_get_games(result, response_code, headers, body, request_node):
|
||||
print("Código de respuesta en juegos:", response_code)
|
||||
|
||||
if response_code == 200:
|
||||
var response_text = body.get_string_from_utf8()
|
||||
var parsed = JSON.parse_string(response_text)
|
||||
|
||||
if parsed != null:
|
||||
all_games = parsed
|
||||
print("Juegos obtenidos:", all_games)
|
||||
|
||||
# Emitir la señal para notificar a quien esté conectado
|
||||
emit_signal("games_received", all_games)
|
||||
else:
|
||||
print("Error al parsear JSON de juegos")
|
||||
else:
|
||||
print("Error del servidor o conexión en juegos:", response_code)
|
||||
|
||||
request_node.queue_free() # Liberar para evitar error 31
|
||||
|
||||
### Metodo que espera a la señal de que se han obtenido y parseado los residentes y los devuelve.
|
||||
func get_games_loaded() -> Array:
|
||||
get_games()
|
||||
var result = await self.games_received
|
||||
return result
|
||||
|
||||
|
||||
|
||||
# ------------------------------- POST PARTIDA ------------------------------------
|
||||
|
||||
func send_game_data():
|
||||
var games = await get_games_loaded()
|
||||
var game_id = 0;
|
||||
for game in games:
|
||||
if game.nombre == "Emparejar las sombras":
|
||||
game_id = game.id
|
||||
|
||||
var http_request = HTTPRequest.new()
|
||||
get_tree().root.add_child(http_request)
|
||||
|
||||
print(game_id)
|
||||
print(resident_playing)
|
||||
var data = {
|
||||
"idJuego": game_id,
|
||||
"idResidente": resident_playing,
|
||||
"fallos": fail_count,
|
||||
"duracion": get_duration()
|
||||
}
|
||||
|
||||
var json_body = JSON.stringify(data)
|
||||
var headers = ["Content-Type: application/json"]
|
||||
var url = "http://localhost:8080/resi/juegos/stats/add"
|
||||
|
||||
http_request.connect("request_completed", Callable(self, "_on_game_data_sent").bind(http_request))
|
||||
var error = http_request.request(url, headers, HTTPClient.METHOD_POST, json_body)
|
||||
|
||||
if error != OK:
|
||||
print("Error al enviar los datos:", error)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -188,11 +188,22 @@ func check_win():
|
|||
var all_matched = true
|
||||
for child in game_board.get_node("GridContainer").get_children():
|
||||
if child is AnimalTile and child.correct_slot == null:
|
||||
print("Porque")
|
||||
all_matched = false
|
||||
break
|
||||
|
||||
if all_matched:
|
||||
GameData.end_game()
|
||||
print("✅ ¡Has ganado!")
|
||||
print("🕐 Tiempo total: ", GameData.get_duration(), " segundos")
|
||||
print("❌ Fallos totales: ", GameData.fail_count)
|
||||
GameData.send_game_data()
|
||||
var popup = $WinPopup
|
||||
popup.get_node("VBoxContainer/victory_label").text = "✅ ¡Has ganado!"
|
||||
popup.get_node("VBoxContainer/duration_label").text = "🕐 Tiempo total: %s segundos" % GameData.get_duration()
|
||||
popup.get_node("VBoxContainer/fail_count_label").text = "❌ Fallos totales: %s" % GameData.fail_count
|
||||
popup.popup_centered()
|
||||
|
||||
func _on_exit_button_pressed() -> void:
|
||||
ScreenManager.go_back_to_previous_scene()
|
||||
|
||||
|
||||
func _on_exit_endgame_button_pressed() -> void:
|
||||
pass # Replace with function body.
|
||||
|
|
|
|||
Loading…
Reference in New Issue