feat: 完成自动创建文件部分

This commit is contained in:
2026-01-21 14:53:30 +08:00
parent c8f27cb4c9
commit f8880b7e92
4 changed files with 65 additions and 22 deletions
+30 -8
View File
@@ -14,19 +14,41 @@ offset_bottom = 1167.0
color = Color(0.7058824, 0.6862745, 0, 1) color = Color(0.7058824, 0.6862745, 0, 1)
[node name="IsServerLabel" type="Label" parent="."] [node name="IsServerLabel" type="Label" parent="."]
offset_left = 30.0 offset_left = 58.0
offset_top = 11.0 offset_top = 15.0
offset_right = 227.0 offset_right = 255.0
offset_bottom = 59.0 offset_bottom = 63.0
theme_override_fonts/font = ExtResource("1_uwrxv") theme_override_fonts/font = ExtResource("1_uwrxv")
theme_override_font_sizes/font_size = 20 theme_override_font_sizes/font_size = 20
text = "啊啊啊啊啊:啊啊啊啊" text = "啊啊啊啊啊:啊啊啊啊"
[node name="IPLabel" type="Label" parent="."] [node name="IPLabel" type="Label" parent="."]
offset_left = 1742.0 offset_left = 54.0
offset_top = 14.0 offset_top = 53.0
offset_right = 1844.0 offset_right = 156.0
offset_bottom = 59.0 offset_bottom = 98.0
theme_override_fonts/font = ExtResource("1_uwrxv") theme_override_fonts/font = ExtResource("1_uwrxv")
theme_override_font_sizes/font_size = 24 theme_override_font_sizes/font_size = 24
text = "127.0.0.2" text = "127.0.0.2"
[node name="Player1" type="Node2D" parent="."]
[node name="Username" type="Label" parent="Player1"]
offset_left = 57.0
offset_top = 1003.0
offset_right = 539.0
offset_bottom = 1061.0
theme_override_fonts/font = ExtResource("1_uwrxv")
theme_override_font_sizes/font_size = 35
text = "Player1"
[node name="Player2" type="Node2D" parent="."]
[node name="Username" type="Label" parent="Player2"]
offset_left = 1446.0
offset_top = 15.0
offset_right = 1928.0
offset_bottom = 73.0
theme_override_fonts/font = ExtResource("1_uwrxv")
theme_override_font_sizes/font_size = 35
text = "Player2"
+3
View File
@@ -107,6 +107,9 @@ offset_left = 711.0
offset_top = 913.0 offset_top = 913.0
offset_right = 1738.0 offset_right = 1738.0
offset_bottom = 966.0 offset_bottom = 966.0
theme_override_fonts/font = ExtResource("2_6wm04")
theme_override_font_sizes/font_size = 50
text = "提示:无"
[connection signal="pressed" from="SaveButton" to="." method="_on_save_button_pressed"] [connection signal="pressed" from="SaveButton" to="." method="_on_save_button_pressed"]
[connection signal="pressed" from="DownloadButton" to="." method="_on_download_button_pressed"] [connection signal="pressed" from="DownloadButton" to="." method="_on_download_button_pressed"]
+17 -1
View File
@@ -1,13 +1,27 @@
extends Node extends Node
func _ready() -> void:
print(OS.get_user_data_dir())
func create_file(file_path: String) -> void:
var base_dir = file_path.get_base_dir()
if !DirAccess.dir_exists_absolute(base_dir):
DirAccess.make_dir_recursive_absolute(base_dir)
FileAccess.open(file_path, FileAccess.WRITE)
func download_file(server_path: String, local_path: String) -> void: func download_file(server_path: String, local_path: String) -> void:
var http = HTTPRequest.new() var http = HTTPRequest.new()
http.download_file = local_path add_child(http)
var file_path = "user://downloads_test/" + local_path
if !FileAccess.file_exists(file_path):
create_file(file_path)
http.set_download_file(file_path)
http.request(server_path) http.request(server_path)
func download_from_origin() -> int: func download_from_origin() -> int:
var origin = GameManager.data_origin var origin = GameManager.data_origin
var http = HTTPRequest.new() var http = HTTPRequest.new()
add_child(http)
if origin.substr(0, 4) != "http": if origin.substr(0, 4) != "http":
return 1 return 1
@@ -18,6 +32,8 @@ func download_from_origin() -> int:
if origin[-1] != "/": if origin[-1] != "/":
origin = origin + "/" origin = origin + "/"
download_file(origin + "card/id/Oxygen", "test_Oxygen.json")
return 0 return 0
func load_resource(): func load_resource():
+2
View File
@@ -15,3 +15,5 @@ func init() -> void:
if address.substr(0, GameManager.ip_begin.length()) == GameManager.ip_begin: if address.substr(0, GameManager.ip_begin.length()) == GameManager.ip_begin:
ipaddress = address ipaddress = address
$IPLabel.text = ipaddress $IPLabel.text = ipaddress
$Player1/Username.text = GameManager.username