feat: 实现了加载本地数据功能
This commit is contained in:
@@ -69,6 +69,10 @@ func download_from_origin() -> int:
|
||||
|
||||
get_uuid()
|
||||
|
||||
DirAccess.remove_absolute("user://download/temp/index.json")
|
||||
DirAccess.remove_absolute("user://download/temp/")
|
||||
|
||||
await download_file(origin + "index", "user://download/%s/index.json" % [uuid])
|
||||
await download_file(origin + "card/list", "user://download/%s/cards/list.json" % [uuid])
|
||||
await download_file(origin + "reaction/list", "user://download/%s/reactions/list.json" % [uuid])
|
||||
await download_file(origin + "matter/list", "user://download/%s/matters/list.json" % [uuid])
|
||||
@@ -80,6 +84,8 @@ func download_from_origin() -> int:
|
||||
|
||||
await download_assets(origin)
|
||||
|
||||
get_sources()
|
||||
|
||||
return 0
|
||||
|
||||
func load_resource():
|
||||
@@ -100,3 +106,18 @@ func load_resource():
|
||||
GameManager.pic_list = asset_list["pics"]
|
||||
GameManager.sound_list = asset_list["sounds"]
|
||||
asset_file.close()
|
||||
|
||||
func get_sources():
|
||||
var dir = DirAccess.open("user://download/")
|
||||
var subdirs: PackedStringArray = dir.get_directories()
|
||||
print(subdirs)
|
||||
for subdir in subdirs:
|
||||
if subdir == "temp":
|
||||
continue
|
||||
var file = FileAccess.open("user://download/%s/index.json" % [subdir], FileAccess.READ)
|
||||
var text = file.get_as_text()
|
||||
var content = JSON.parse_string(text)
|
||||
file.close()
|
||||
var source_name = content["name"]
|
||||
var source_uuid = content["uuid"]
|
||||
GameManager.sources[source_name] = source_uuid
|
||||
|
||||
@@ -3,10 +3,13 @@ extends Node
|
||||
var data_origin: String = ""
|
||||
var ip_begin: String = "192.168."
|
||||
var username: String = "Player1"
|
||||
var source: int = 0
|
||||
|
||||
var card_list: Dictionary = {}
|
||||
var matter_list: Dictionary = {}
|
||||
var reaction_list: Dictionary = {}
|
||||
var match_list: Dictionary = {}
|
||||
var pic_list: Dictionary = {}
|
||||
var sound_list: Dictionary = {}
|
||||
var sound_list: Dictionary = {}
|
||||
|
||||
var sources: Dictionary = {}
|
||||
@@ -1,14 +1,26 @@
|
||||
extends Node2D
|
||||
|
||||
func _ready() -> void:
|
||||
init_sources()
|
||||
init_text()
|
||||
|
||||
func init_text() -> void:
|
||||
$DataSetting/LineEdit.text = GameManager.data_origin
|
||||
$IPBeginSetting/LineEdit.text = GameManager.ip_begin
|
||||
$UsernameSetting/LineEdit.text = GameManager.username
|
||||
$LoadSource/ChooseSource.select(GameManager.source)
|
||||
|
||||
func init_sources() -> void:
|
||||
DownloadManager.get_sources()
|
||||
var options = $LoadSource/ChooseSource
|
||||
for source_name in GameManager.sources:
|
||||
options.add_item(source_name)
|
||||
|
||||
func _on_save_button_pressed() -> void:
|
||||
GameManager.data_origin = $DataSetting/LineEdit.text
|
||||
GameManager.ip_begin = $IPBeginSetting/LineEdit.text
|
||||
GameManager.username = $UsernameSetting/LineEdit.text
|
||||
GameManager.source = $LoadSource/ChooseSource.get_selected()
|
||||
SceneManager.goto_scene("main_menu")
|
||||
|
||||
|
||||
@@ -29,3 +41,9 @@ func _on_download_button_pressed() -> void:
|
||||
DownloadManager.load_resource()
|
||||
$Tips.text = "提示:完成加载"
|
||||
|
||||
|
||||
|
||||
func _on_load_button_pressed() -> void:
|
||||
DownloadManager.uuid = GameManager.sources[$LoadSource/ChooseSource.text]
|
||||
DownloadManager.load_resource()
|
||||
$Tips.text = "提示:完成加载"
|
||||
|
||||
Reference in New Issue
Block a user