mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-22 14:05:39 +00:00
Adding json support and supporting class
On branch feat/godot-configurator Changes to be committed: deleted: tools/configurator/basic new file: tools/configurator/data.json modified: tools/configurator/data_list.json modified: tools/configurator/main.gd modified: tools/configurator/project.godot modified: tools/configurator/res/pixel_ui_theme/RetroDECKTheme.tres new file: tools/configurator/scripts/app_data.gd modified: tools/configurator/scripts/class_functions.gd new file: tools/configurator/scripts/data_handler.gd new file: tools/configurator/scripts/emulator.gd new file: tools/configurator/scripts/emulator_option.gd new file: tools/configurator/scripts/emulator_property.gd new file: tools/configurator/scripts/link.gd new file: tools/configurator/scripts/save_manager.gd
This commit is contained in:
parent
77eb009fff
commit
058fe166c5
|
@ -1,2 +0,0 @@
|
|||
[2024-07-28 11:10:38.087] [INFO] Configurator: check_bios_files
|
||||
[2024-07-28 11:11:04.473] [INFO] Configurator: check_bios_files
|
10
tools/configurator/data.json
Normal file
10
tools/configurator/data.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"item1": {
|
||||
"cost": 50,
|
||||
"description": "an item description"
|
||||
},
|
||||
"item2": {
|
||||
"cost": 1000,
|
||||
"description": "another item description"
|
||||
}
|
||||
}
|
|
@ -1,48 +1,41 @@
|
|||
{
|
||||
"about_links": [
|
||||
{
|
||||
"about_links": {
|
||||
"rd_web": {
|
||||
"name": "Website",
|
||||
"id": "rd_web",
|
||||
"url": "https://retrodeck.net/",
|
||||
"description": "Opens the RetroDECK Website in your default browser"
|
||||
},
|
||||
{
|
||||
"rd_changelog": {
|
||||
"name": "Changelog",
|
||||
"id": "rd_changelog",
|
||||
"url": "https://retrodeck.readthedocs.io/en/latest/wiki_rd_versions/version-history/",
|
||||
"description": "Opens the RetroDECK change log in your default browser"
|
||||
},
|
||||
{
|
||||
"rd_wiki":{
|
||||
"name": "Wiki",
|
||||
"id": "rd_wiki",
|
||||
"url": "https://retrodeck.readthedocs.io/en/latest/",
|
||||
"description": "Opens the RetroDECK Wiki in your default browser"
|
||||
},
|
||||
{
|
||||
"rd_credits": {
|
||||
"name": "Credits",
|
||||
"id": "rd_credits",
|
||||
"url": "https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/",
|
||||
"description": "Opens the RetroDECK Credits in your default browser"
|
||||
},
|
||||
{
|
||||
"rd_donate": {
|
||||
"name": "Donate",
|
||||
"id": "rd_donate",
|
||||
"url": "https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/",
|
||||
"description": "Opens Donations page in your default browser"
|
||||
},
|
||||
{
|
||||
"rd_contactus": {
|
||||
"name": "Contact us",
|
||||
"id": "rd_contactus",
|
||||
"url": "https://github.com/XargonWan/RetroDECK",
|
||||
"description": "Opens the RetroDECK contact us section in your default browser"
|
||||
},
|
||||
{
|
||||
"rd_licenses": {
|
||||
"name": "Licences",
|
||||
"id": "rd_licenses",
|
||||
"url": "https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/",
|
||||
"description": "Opens the RetroDECK licenses in your default browser"
|
||||
}
|
||||
],
|
||||
},
|
||||
"emulators": {
|
||||
"cemu": {
|
||||
"name": "Cemu",
|
||||
|
|
|
@ -16,17 +16,21 @@ var tab_container: TabContainer
|
|||
var anim_logo: AnimatedSprite2D
|
||||
var anim_rekku: AnimatedSprite2D
|
||||
|
||||
var player =[]
|
||||
|
||||
func _ready():
|
||||
_get_nodes()
|
||||
_connect_signals()
|
||||
_play_main_animations()
|
||||
#print(save_manager.data)#["name"]["unlock_goal"])
|
||||
print(save_manager.data["about_links"]["rd_web"]["name"], " ", save_manager.data["about_links"]["rd_web"]["url"])
|
||||
print(save_manager.data["emulators"]["mame"]["name"], " ", save_manager.data["emulators"]["mame"]["description"])
|
||||
|
||||
var emulator_list = class_functions.get_text_file_from_system_path("../../tools/configurator.sh","sed -n '/local emulator_list=(/,/)/{s/.*local emulator_list=\\(.*\\)/\\1/; /)/q; p}' ","emulist")
|
||||
#print (emulator_list)
|
||||
var abxy_button_list = class_functions.get_text_file_from_system_path("/var/config/retrodeck/retrodeck.cfg","sed -n '/\\[abxy_button_swap\\]/,/^$/p' ","normal")
|
||||
#print(abxy_button_list)
|
||||
var file_path = "res://data_list.json"
|
||||
var about_links_dict: Dictionary = class_functions.get_about_links_from_file(file_path)
|
||||
print(about_links_dict)
|
||||
# set current startup tab to match IDE
|
||||
tab_container.current_tab = 3
|
||||
#add_child(class_functions) # Needed for threaded results Not need autoload?
|
||||
|
|
|
@ -20,6 +20,7 @@ config/icon="res://icon.svg"
|
|||
[autoload]
|
||||
|
||||
class_functions="*res://scripts/class_functions.gd"
|
||||
save_manager="*res://scripts/save_manager.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
8
tools/configurator/scripts/app_data.gd
Normal file
8
tools/configurator/scripts/app_data.gd
Normal file
|
@ -0,0 +1,8 @@
|
|||
extends Resource
|
||||
class_name AppData
|
||||
|
||||
#@export var about_links: Dictionary[String, Link] = {}
|
||||
#@export var emulators: Dictionary[String, Emulator] = {}
|
||||
|
||||
@export var about_links: Dictionary = {}
|
||||
@export var emulators: Dictionary = {}
|
|
@ -116,47 +116,3 @@ func _import_data_lists(file_path: String) -> void:
|
|||
print("URL: " + entry["URL"])
|
||||
print("Description: " + entry["Description"])
|
||||
print("---")
|
||||
|
||||
|
||||
func get_about_links_from_file(file_path: String) -> Dictionary:
|
||||
var about_links_dict = {}
|
||||
var file = FileAccess.open(file_path, FileAccess.READ)
|
||||
|
||||
if file:
|
||||
var json_string = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(json_string)
|
||||
print ("RES: %s",parse_result)
|
||||
|
||||
if parse_result == OK:
|
||||
var data = parse_result
|
||||
print (data)
|
||||
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
||||
#continue
|
||||
if parse_result is Dictionary:
|
||||
if parse_result.has("about_links"):
|
||||
var about_links = parse_result["about_links"]
|
||||
about_links_dict = parse_about_links(about_links)
|
||||
else:
|
||||
print("Error: 'about_links' key not found in JSON.")
|
||||
else:
|
||||
print("Error parsing JSON: %s" % json.error_string)
|
||||
else:
|
||||
print("Failed to open file: %s" % file_path)
|
||||
|
||||
print (about_links_dict)
|
||||
return about_links_dict
|
||||
|
||||
func parse_about_links(about_links: Array) -> Dictionary:
|
||||
var about_links_dict = {}
|
||||
|
||||
for link in about_links:
|
||||
about_links_dict[link["id"]] = {
|
||||
"name": link["name"],
|
||||
"url": link["url"],
|
||||
"description": link["description"]
|
||||
}
|
||||
|
||||
return about_links_dict
|
||||
|
|
108
tools/configurator/scripts/data_handler.gd
Normal file
108
tools/configurator/scripts/data_handler.gd
Normal file
|
@ -0,0 +1,108 @@
|
|||
extends Node
|
||||
|
||||
class_name DataHandler
|
||||
|
||||
var data_file_path = "res://data.json"
|
||||
var app_data: AppData
|
||||
|
||||
func _ready():
|
||||
# Load the data when the scene is ready
|
||||
app_data = load_data()
|
||||
|
||||
func load_data() -> AppData:
|
||||
var file = FileAccess.open(data_file_path, FileAccess.READ)
|
||||
if file:
|
||||
var json_data = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parsed_data = json.parse(json_data)
|
||||
if parsed_data.error == OK:
|
||||
var data_dict = parsed_data.result
|
||||
|
||||
var about_links = {}
|
||||
for key in data_dict["about_links"].keys():
|
||||
var link_data = data_dict["about_links"][key]
|
||||
var link = Link.new()
|
||||
link.name = link_data["name"]
|
||||
link.url = link_data["url"]
|
||||
link.description = link_data["description"]
|
||||
about_links[key] = link
|
||||
|
||||
var emulators = {}
|
||||
for key in data_dict["emulators"].keys():
|
||||
var emulator_data = data_dict["emulators"][key]
|
||||
var emulator = Emulator.new()
|
||||
emulator.name = emulator_data["name"]
|
||||
emulator.description = emulator_data["description"]
|
||||
|
||||
emulator.options = []
|
||||
for option_data in emulator_data["options"]:
|
||||
var option = EmulatorOption.new()
|
||||
option.resettable = option_data["resettable"]
|
||||
emulator.options.append(option)
|
||||
|
||||
emulator.properties = []
|
||||
for property_data in emulator_data["properties"]:
|
||||
var property = EmulatorProperty.new()
|
||||
property.standalone = property_data["standalone"]
|
||||
property.abxy_button_status = property_data.get("abxy_button", {}).get("status", false)
|
||||
emulator.properties.append(property)
|
||||
|
||||
emulators[key] = emulator
|
||||
|
||||
var app_data = AppData.new()
|
||||
app_data.about_links = about_links
|
||||
app_data.emulators = emulators
|
||||
|
||||
return app_data
|
||||
else:
|
||||
print("Error parsing JSON")
|
||||
else:
|
||||
print("Error opening file")
|
||||
return null
|
||||
|
||||
func save_data(app_data: AppData):
|
||||
var file = FileAccess.open(data_file_path, FileAccess.WRITE)
|
||||
if file:
|
||||
var data_dict = {}
|
||||
|
||||
var about_links = {}
|
||||
for key in app_data.about_links.keys():
|
||||
var link = app_data.about_links[key]
|
||||
about_links[key] = {
|
||||
"name": link.name,
|
||||
"url": link.url,
|
||||
"description": link.description
|
||||
}
|
||||
|
||||
var emulators = {}
|
||||
for key in app_data.emulators.keys():
|
||||
var emulator = app_data.emulators[key]
|
||||
var options = []
|
||||
for option in emulator.options:
|
||||
options.append({
|
||||
"resettable": option.resettable
|
||||
})
|
||||
|
||||
var properties = []
|
||||
for property in emulator.properties:
|
||||
properties.append({
|
||||
"standalone": property.standalone,
|
||||
"abxy_button": {"status": property.abxy_button_status}
|
||||
})
|
||||
|
||||
emulators[key] = {
|
||||
"name": emulator.name,
|
||||
"description": emulator.description,
|
||||
"options": options,
|
||||
"properties": properties
|
||||
}
|
||||
|
||||
data_dict["about_links"] = about_links
|
||||
data_dict["emulators"] = emulators
|
||||
|
||||
var json = JSON.new()
|
||||
var json_text = json.print(data_dict)
|
||||
file.store_string(json_text)
|
||||
file.close()
|
7
tools/configurator/scripts/emulator.gd
Normal file
7
tools/configurator/scripts/emulator.gd
Normal file
|
@ -0,0 +1,7 @@
|
|||
extends Resource
|
||||
|
||||
class_name Emulator
|
||||
@export var name: String
|
||||
@export var description: String
|
||||
@export var options: Array[EmulatorOption]
|
||||
@export var properties: Array[EmulatorProperty]
|
4
tools/configurator/scripts/emulator_option.gd
Normal file
4
tools/configurator/scripts/emulator_option.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends Resource
|
||||
|
||||
class_name EmulatorOption
|
||||
@export var resettable: bool
|
5
tools/configurator/scripts/emulator_property.gd
Normal file
5
tools/configurator/scripts/emulator_property.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
extends Resource
|
||||
|
||||
class_name EmulatorProperty
|
||||
@export var standalone: bool
|
||||
@export var abxy_button_status: bool = false
|
6
tools/configurator/scripts/link.gd
Normal file
6
tools/configurator/scripts/link.gd
Normal file
|
@ -0,0 +1,6 @@
|
|||
extends Resource
|
||||
|
||||
class_name Link
|
||||
@export var name: String
|
||||
@export var url: String
|
||||
@export var description: String
|
30
tools/configurator/scripts/save_manager.gd
Normal file
30
tools/configurator/scripts/save_manager.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends Node
|
||||
|
||||
var json: JSON = JSON.new()
|
||||
#var path: String = "res://data.json"
|
||||
var path: String = "res://data_list.json"
|
||||
|
||||
var data = {}
|
||||
|
||||
func write_json(content):
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
file.store_string(json.stringify(content))
|
||||
file.close()
|
||||
file = null
|
||||
|
||||
func read_json():
|
||||
var file = FileAccess.open(path, FileAccess.READ)
|
||||
var content = json.parse_string(file.get_as_text())
|
||||
if data is Dictionary:
|
||||
return content
|
||||
else:
|
||||
print ("Error")
|
||||
|
||||
func create_new_json_file():
|
||||
var file = FileAccess.open("res://test.json",FileAccess.READ)
|
||||
var content = json.parse_string(file.get_as_text())
|
||||
data = content
|
||||
write_json(content)
|
||||
|
||||
func _ready ():
|
||||
data = read_json()
|
Loading…
Reference in a new issue