From 84365b6f901a9c0251a9f724a8d9f81a3787e97d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 3 Nov 2024 14:10:07 +0100 Subject: next commit --- Game/Lobby/Server/db | Bin 0 -> 16384 bytes Game/Lobby/Server/index.php | 139 ++++++++++++++++++++++++++++++++++++ Game/Selection/SelectionManager.gd | 6 ++ Game/Selection/selectable_area.gd | 8 ++- Game/States/Build/BuilderElement.gd | 18 +++-- 5 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 Game/Lobby/Server/db create mode 100644 Game/Lobby/Server/index.php create mode 100644 Game/Selection/SelectionManager.gd (limited to 'Game') diff --git a/Game/Lobby/Server/db b/Game/Lobby/Server/db new file mode 100644 index 0000000..9e551a0 Binary files /dev/null and b/Game/Lobby/Server/db differ diff --git a/Game/Lobby/Server/index.php b/Game/Lobby/Server/index.php new file mode 100644 index 0000000..de7d5c0 --- /dev/null +++ b/Game/Lobby/Server/index.php @@ -0,0 +1,139 @@ + PDO::FETCH_ASSOC, +]); + +if (php_sapi_name() == 'cli') { + if ($argv[$argc - 1] == 'init-db') { + $db->query(<<execute(); + } + + return; +} + +$response = []; + +if (isset($_POST['host'])) { + $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); + + if ($ip === false) { + $response = [ + 'success' => false, + 'error' => 'Invalid IP.', + ]; + } + + else { + $port = intval($_POST['port']); + $name = $_POST['name']; + + $success = $db->prepare(<<execute([ + 'id' => md5($name . time()), + 'ip' => $ip, + 'port' => $port, + 'timestamp' => time(), + 'name' => $name, + ]); + + $response = [ + 'success' => $success, + ]; + } +} + +else if (isset($_GET['get-list'])) { + $statement = $db->prepare(<<execute(); + $results = $statement->fetchAll(); + + $list = []; + foreach ($results as $row) { + $list[] = [ + 'id' => $row['id'], + 'name' => $row['name'], + ]; + } + + $response = [ + 'success' => true, + 'data' => $list, + ]; +} + +else if (isset($_GET['join'])) { + $id = $_GET['join']; + + $statement = $db->prepare(<<execute(['id' => $id]); + $result = $statement->fetch(); + + if ($result === false) { + $response = [ + 'success' => false, + 'error' => 'Game not found.' + ]; + http_response_code(404); + } + + else { + $response = [ + 'success' => true, + 'data' => [ + 'ip' => $result['ip'], + 'port' => $result['port'], + ], + ]; + } +} + +else if (isset($_POST['close'])) { + $id = $_POST['close']; + + $success = $db->prepare(<<execute([ + 'id' => $id, + ]); + + $response = [ + 'success' => $success, + ]; +} + +else { + $response = [ + 'success' => false, + 'error' => 'Route not found.' + ]; + http_response_code(404); +} + +header('Content-Type: application/json'); +echo json_encode($response); diff --git a/Game/Selection/SelectionManager.gd b/Game/Selection/SelectionManager.gd new file mode 100644 index 0000000..c58dc69 --- /dev/null +++ b/Game/Selection/SelectionManager.gd @@ -0,0 +1,6 @@ +class_name SelectionManager +extends Node + + +func _ready() -> void: + pass diff --git a/Game/Selection/selectable_area.gd b/Game/Selection/selectable_area.gd index b3336f1..0b3557d 100644 --- a/Game/Selection/selectable_area.gd +++ b/Game/Selection/selectable_area.gd @@ -3,7 +3,9 @@ extends Area2D signal hover_enter signal hover_exit -signal select(event: InputEvent) + +signal select_primary(event: InputEvent) +signal select_secondary(event: InputEvent) #func _on_area_entered(_area: Area2D) -> void: @@ -26,4 +28,6 @@ func _on_mouse_exited() -> void: func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: if event.is_action_pressed("select"): - select.emit(event) + select_primary.emit(event) + if event.is_action_pressed("select_secondary"): + select_secondary.emit(event) diff --git a/Game/States/Build/BuilderElement.gd b/Game/States/Build/BuilderElement.gd index 8c98bdc..cc9c051 100644 --- a/Game/States/Build/BuilderElement.gd +++ b/Game/States/Build/BuilderElement.gd @@ -15,13 +15,17 @@ var collision_areas: Array[Area2D] = [] func _ready(): instance = element.instantiate() - var element_sprite: Sprite2D = instance.get_node("Sprite2D") - $Sprite2D.texture = element_sprite.texture - $Sprite2D.region_enabled = element_sprite.region_enabled - $Sprite2D.region_rect = element_sprite.region_rect - $Sprite2D.scale = element_sprite.scale - $Sprite2D.position = element_sprite.position - $Sprite2D.scale = instance.scale + var element_sprite: AnimatedSprite2D = instance.get_node("AnimatedSprite2D").duplicate() + element_sprite.scale *= instance.scale + element_sprite.position *= instance.scale + add_child(element_sprite) + element_sprite.play() + #$Sprite2D.texture = element_sprite.sprite_frames.get_frame_texture("default", 0) + #$Sprite2D.region_enabled = element_sprite.region_enabled + #$Sprite2D.region_rect = element_sprite.region_rect + #$Sprite2D.scale = element_sprite.scale + #$Sprite2D.position = element_sprite.position + #$Sprite2D.scale = instance.scale var element_collision_shape = instance.get_node("CollisionShape2D").duplicate() as CollisionShape2D collision_shape = element_collision_shape.shape -- cgit v1.2.3