datapack to_json

This commit is contained in:
Chris Bell 2025-10-21 18:37:33 -05:00
parent 248345e064
commit 410c532475
2 changed files with 29 additions and 5 deletions

View File

@ -37,8 +37,27 @@ func to_dict() -> Dictionary:
# TODO: Implement this
func from_dict(dict: Dictionary) -> DatapackModel:
static func from_dict(dict: Dictionary) -> DatapackModel:
var dp: DatapackModel = DatapackModel.new()
dp.guid = dict["guid"]
dp.name = dict.get("name", "")
dp.version = dict.get("version", "")
dp.author = dict.get("author", "")
dp.license = dict.get("license", "")
dp.description = dict.get("description", "")
dp.icon = dict.get("icon", "")
dp.session_zero_version = dict.get("session_zero_version", "")
if dict.has("guid"):
dp.guid = Guid.from_string(dict["guid"])
else:
return null
dp.dependencies.clear()
if dict.has("dependencies"):
var deps_arr: Array = dict["dependencies"]
for d_dict in deps_arr:
var dependency: DatapackDependency = DatapackDependency.from_dict(d_dict)
dp.dependencies.append(dependency)
return dp

View File

@ -14,6 +14,11 @@ func to_dict() -> Dictionary:
}
func from_dict(dict: Dictionary) -> DatapackDependency:
# TODO
return null
static func from_dict(dict: Dictionary) -> DatapackDependency:
var dd := DatapackDependency.new()
dd.id = dict.get("id", "")
dd.name = dict.get("name", "")
dd.version = dict.get("version", "")
return dd