commit 1cf3019178b43d512df108b5b8db3bfefa7e47ed Author: istamarahsan Date: Sat Jan 11 10:07:37 2025 +0700 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/export_presets.cfg b/export_presets.cfg new file mode 100644 index 0000000..a745b73 --- /dev/null +++ b/export_presets.cfg @@ -0,0 +1,132 @@ +[preset.0] + +name="Windows Desktop" +platform="Windows Desktop" +runnable=false +advanced_options=false +dedicated_server=false +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="C:/Users/ahsan/OneDrive/Desktop/build.exe" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false +script_export_mode=2 + +[preset.0.options] + +custom_template/debug="" +custom_template/release="" +debug/export_console_wrapper=1 +binary_format/embed_pck=false +texture_format/s3tc_bptc=true +texture_format/etc2_astc=false +binary_format/architecture="x86_64" +codesign/enable=false +codesign/timestamp=true +codesign/timestamp_server_url="" +codesign/digest_algorithm=1 +codesign/description="" +codesign/custom_options=PackedStringArray() +application/modify_resources=true +application/icon="" +application/console_wrapper_icon="" +application/icon_interpolation=4 +application/file_version="" +application/product_version="" +application/company_name="" +application/product_name="" +application/file_description="" +application/copyright="" +application/trademarks="" +application/export_angle=0 +application/export_d3d12=0 +application/d3d12_agility_sdk_multiarch=true +ssh_remote_deploy/enabled=false +ssh_remote_deploy/host="user@host_ip" +ssh_remote_deploy/port="22" +ssh_remote_deploy/extra_args_ssh="" +ssh_remote_deploy/extra_args_scp="" +ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' +$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' +$trigger = New-ScheduledTaskTrigger -Once -At 00:00 +$settings = New-ScheduledTaskSettingsSet +$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings +Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true +Start-ScheduledTask -TaskName godot_remote_debug +while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" +ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue +Remove-Item -Recurse -Force '{temp_dir}'" + +[preset.1] + +name="Windows Server" +platform="Windows Desktop" +runnable=false +advanced_options=false +dedicated_server=true +custom_features="" +export_filter="customized" +customized_files={ +"res://": "strip" +} +include_filter="" +exclude_filter="" +export_path="C:/Users/ahsan/OneDrive/Desktop/server.exe" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false +script_export_mode=2 + +[preset.1.options] + +custom_template/debug="" +custom_template/release="" +debug/export_console_wrapper=1 +binary_format/embed_pck=false +texture_format/s3tc_bptc=true +texture_format/etc2_astc=false +binary_format/architecture="x86_64" +codesign/enable=false +codesign/timestamp=true +codesign/timestamp_server_url="" +codesign/digest_algorithm=1 +codesign/description="" +codesign/custom_options=PackedStringArray() +application/modify_resources=true +application/icon="" +application/console_wrapper_icon="" +application/icon_interpolation=4 +application/file_version="" +application/product_version="" +application/company_name="" +application/product_name="" +application/file_description="" +application/copyright="" +application/trademarks="" +application/export_angle=0 +application/export_d3d12=0 +application/d3d12_agility_sdk_multiarch=true +ssh_remote_deploy/enabled=false +ssh_remote_deploy/host="user@host_ip" +ssh_remote_deploy/port="22" +ssh_remote_deploy/extra_args_ssh="" +ssh_remote_deploy/extra_args_scp="" +ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' +$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' +$trigger = New-ScheduledTaskTrigger -Once -At 00:00 +$settings = New-ScheduledTaskSettingsSet +$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings +Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true +Start-ScheduledTask -TaskName godot_remote_debug +while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" +ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue +Remove-Item -Recurse -Force '{temp_dir}'" diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..9c2a61f --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dbla0xaub2d6" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/main.gd b/main.gd new file mode 100644 index 0000000..621d8f4 --- /dev/null +++ b/main.gd @@ -0,0 +1,76 @@ +extends Node + +const PORT = 25565 +const MAX_CONNECTIONS = 20 + +var counter = 0 + +@onready var before_connect_container = get_node("BeforeConnect") as Container +@onready var host_text_edit = get_node("%HostTextEdit") as TextEdit +@onready var connect_button = get_node("%ConnectButton") as Button + +@onready var after_connect_container = get_node("%AfterConnect") as Container +@onready var counter_label = get_node("%CounterLabel") as Label +@onready var decrement_button = get_node("%DecrementButton") as Button +@onready var increment_button = get_node("%IncrementButton") as Button + +func _ready() -> void: + if OS.has_feature("dedicated_server"): + print("Starting dedicated server") + var peer = ENetMultiplayerPeer.new() + var err = peer.create_server(PORT, MAX_CONNECTIONS) + if err: + print(err) + multiplayer.multiplayer_peer = peer + multiplayer.peer_connected.connect(_on_player_connected) + else: + print("Game starting") + #multiplayer.peer_disconnected.connect(_on_player_disconnected) + multiplayer.connected_to_server.connect(_on_connected_ok) + #multiplayer.connection_failed.connect(_on_connected_fail) + #multiplayer.server_disconnected.connect(_on_server_disconnected) + + increment_button.button_up.connect(func(): _increment.rpc()) + decrement_button.button_up.connect(func(): _decrement.rpc()) + connect_button.button_up.connect(_on_connect_pressed) + +@rpc("any_peer", "call_local") +func _increment(): + counter += 1 + counter_label.text = str(counter) + +@rpc("any_peer", "call_local") +func _decrement(): + counter -= 1 + counter_label.text = str(counter) + +@rpc("authority", "call_remote") +func _set_counter(value: int): + counter = value + counter_label.text = str(counter) + +func _on_connect_pressed(): + var peer = ENetMultiplayerPeer.new() + var parsed: PackedStringArray = host_text_edit.text.split(":") + print("Connecting to ", parsed[0]) + peer.create_client(parsed[0] if not parsed[0].is_empty() else "localhost", int(parsed[1]) if parsed.size() > 1 else PORT) + multiplayer.multiplayer_peer = peer + +func _on_player_connected(id: int): + if multiplayer.get_unique_id() == 1: + _set_counter.rpc_id(id, counter) + +func _on_player_disconnected(): + pass + +func _on_connected_ok(): + $AfterConnect.visible = true + $BeforeConnect.visible = false + counter_label.text = str(counter) + +func _on_connected_fail(): + pass + +func _on_server_disconnected(): + pass + diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..d49cabf --- /dev/null +++ b/main.tscn @@ -0,0 +1,80 @@ +[gd_scene load_steps=2 format=3 uid="uid://c7gn46af6whf8"] + +[ext_resource type="Script" path="res://main.gd" id="1_e0ud3"] + +[node name="Main" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_e0ud3") + +[node name="BeforeConnect" type="VBoxContainer" parent="."] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -187.5 +offset_top = -88.0 +offset_right = 187.5 +offset_bottom = 88.0 +grow_horizontal = 2 +grow_vertical = 2 +alignment = 1 + +[node name="HostTextEdit" type="TextEdit" parent="BeforeConnect"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +placeholder_text = "192.168.*.*" + +[node name="ConnectButton" type="Button" parent="BeforeConnect"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 64) +layout_mode = 2 +text = "Connect" + +[node name="AfterConnect" type="VBoxContainer" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -187.5 +offset_top = -88.5 +offset_right = 187.5 +offset_bottom = 88.5 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="CounterLabel" type="Label" parent="AfterConnect"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +theme_override_font_sizes/font_size = 64 +text = "1" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Actions" type="HBoxContainer" parent="AfterConnect"] +layout_mode = 2 + +[node name="DecrementButton" type="Button" parent="AfterConnect/Actions"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +text = "-" + +[node name="IncrementButton" type="Button" parent="AfterConnect/Actions"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +text = "+" diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..0bfa3d6 --- /dev/null +++ b/project.godot @@ -0,0 +1,20 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="tcg" +run/main_scene="res://main.tscn" +config/features=PackedStringArray("4.3", "Mobile") +config/icon="res://icon.svg" + +[rendering] + +renderer/rendering_method="mobile"