wip web import export

This commit is contained in:
erkkon 2023-07-31 22:04:28 +02:00
parent e6248e90ce
commit c6fa75f456
2 changed files with 17 additions and 4 deletions

View file

@ -9,8 +9,11 @@ func _ready():
load_all_data()
func save_data(key, value, file_directory = file_path) :
func save_all_data_to_file_web():
var json = JSON.stringify(game_data)
JavaScriptBridge.download_buffer(json.to_utf8_buffer(),"open_aim_trainer.json")
func save_data(key, value, file_directory = file_path) :
game_data[key] = value
var json = JSON.stringify(game_data)
var file = FileAccess.open(file_directory, FileAccess.WRITE)
@ -34,7 +37,7 @@ func load_all_data(file_directory = file_path):
var result = {}
var file = FileAccess.open(file_directory, FileAccess.READ)
if file:
game_data = json.parse(file.get_as_text())
json.parse(file.get_as_text())
file.close()
else:
print("File not found.")

View file

@ -6,8 +6,13 @@ signal refresh_crosshair
@onready var file_export = $ScrollContainer/MarginContainer/HBoxContainer/VBoxContainer/ExportFileDialog
@onready var file_import = $ScrollContainer/MarginContainer/HBoxContainer/VBoxContainer/ImportFileDialog
var fileImportCallback = JavaScriptBridge.create_callback(Callable(self, "file_parser"))
# Called when the node enters the scene tree for the first time.
func _ready():
if OS.has_feature("web"):
var window = JavaScriptBridge.get_interface("window")
window.getFile(fileImportCallback)
file_export.visible = false
file_import.visible = false
loadSaved()
@ -127,10 +132,14 @@ func open_file_dialog():
"""
func file_parser(args):
var json = JSON.new()
json.parse(args[0])
print(json.result)
func _on_export_pressed():
if OS.has_feature("web"):
pass
DataManager.save_all_data_to_file_web()
else:
file_export.current_dir = "/"
file_export.visible = true
@ -139,7 +148,8 @@ func _on_export_pressed():
func _on_import_pressed():
if OS.has_feature("web"):
open_file_dialog()
var window = JavaScriptBridge.get_interface("window")
window.input.click()
else:
file_import.current_dir = "/"
file_import.visible = true