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 -14
View File
@@ -1,24 +1,40 @@
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:
var http = HTTPRequest.new()
http.download_file = local_path
http.request(server_path)
var http = HTTPRequest.new()
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)
func download_from_origin() -> int:
var origin = GameManager.data_origin
var http = HTTPRequest.new()
var origin = GameManager.data_origin
var http = HTTPRequest.new()
add_child(http)
if origin.substr(0, 4) != "http":
return 1
if http.request(origin) != OK:
return 2
if origin.substr(0, 4) != "http":
return 1
if http.request(origin) != OK:
return 2
if origin[-1] != "/":
origin = origin + "/"
if origin[-1] != "/":
origin = origin + "/"
return 0
download_file(origin + "card/id/Oxygen", "test_Oxygen.json")
return 0
func load_resource():
pass
pass
+2
View File
@@ -15,3 +15,5 @@ func init() -> void:
if address.substr(0, GameManager.ip_begin.length()) == GameManager.ip_begin:
ipaddress = address
$IPLabel.text = ipaddress
$Player1/Username.text = GameManager.username