From fcff613a934418d6c2a0c11c036256dcbfcb5994 Mon Sep 17 00:00:00 2001 From: darknight Date: Sun, 6 Jun 2021 18:54:25 +0200 Subject: [PATCH] bugfix/android-database (#78) Co-authored-by: VAILLANT Jeremy Reviewed-on: https://dev.stilobique.com/Athena/game-source/pulls/78 Co-authored-by: darknight Co-committed-by: darknight --- db/ahog.json | 2 +- export_presets.cfg | 1 - scenes/levels/parts/ListObjects.tscn | 9 +++-- scripts/Database.gd | 52 ++++++++++++++++++++++------ 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/db/ahog.json b/db/ahog.json index a129e4e..85fe443 100644 --- a/db/ahog.json +++ b/db/ahog.json @@ -7,7 +7,7 @@ "props":[ {"name":"langue","type":"1","auto_increment":"0"}, {"name":"gyroscope","type":"0","auto_increment":"0"}, - {"name":"ambiant_sound","type":"0","auto_increment":"0"}, + {"name":"ambient_sound","type":"0","auto_increment":"0"}, {"name":"resolution","type":"3","auto_increment":"0"}, {"name":"fullscreen","type":"0","auto_increment":"0"} ], diff --git a/export_presets.cfg b/export_presets.cfg index 43a80f8..e171987 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -223,7 +223,6 @@ texture_format/etc=false texture_format/etc2=false texture_format/no_bptc_fallbacks=true codesign/enable=false -codesign/identity_type=0 codesign/identity="" codesign/password="" codesign/timestamp=true diff --git a/scenes/levels/parts/ListObjects.tscn b/scenes/levels/parts/ListObjects.tscn index e3134c4..e317d4f 100644 --- a/scenes/levels/parts/ListObjects.tscn +++ b/scenes/levels/parts/ListObjects.tscn @@ -6,7 +6,7 @@ [ext_resource path="res://assets/ui/themes/UI-Button-ItemsList-last-hover.png" type="Texture" id=6] [ext_resource path="res://assets/ui/themes/UI-Button-ItemsList-last.png" type="Texture" id=8] -[sub_resource type="Animation" id=2] +[sub_resource type="Animation" id=1] resource_name = "ObjectFind" tracks/0/type = "bezier" tracks/0/path = NodePath("ListContainer/TextureButtonLast/Label:rect_position:x") @@ -19,8 +19,7 @@ tracks/0/keys = { "times": PoolRealArray( 0, 0.2, 0.4, 0.6, 0.8, 1 ) } -[sub_resource type="Animation" id=1] -resource_name = "ObjectFindAll" +[sub_resource type="Animation" id=2] tracks/0/type = "bezier" tracks/0/path = NodePath("ListContainer/TextureButtonLast:rect_position:x") tracks/0/interp = 1 @@ -102,5 +101,5 @@ margin_bottom = 128.0 texture_normal = ExtResource( 4 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] -anims/ObjectFind = SubResource( 2 ) -anims/ObjectFindAll = SubResource( 1 ) +anims/ObjectFind = SubResource( 1 ) +anims/ObjectFindAll = SubResource( 2 ) diff --git a/scripts/Database.gd b/scripts/Database.gd index b03f191..8276832 100644 --- a/scripts/Database.gd +++ b/scripts/Database.gd @@ -2,14 +2,46 @@ extends Node func initialize(): var database_manager = load(gddb_constants.c_addon_main_path + "core/db_man.gd").new() - var db_id = database_manager.load_database("res://db/ahog.json") - - if db_id == gddb_types.e_db_invalid_file: - print("[global#_initialize_database] Error invalid database file !") - OS.set_exit_code(1) - - if db_id == gddb_types.e_db_invalid_ver: - print("[global#_initialize_database] Error invalid database version !") - OS.set_exit_code(1) - + var db_id = database_manager.load_database(save_database_in()) + + check_invalid_type(db_id) + check_invalid_version(db_id) + return database_manager.get_db_by_id(db_id) + +func check_invalid_type(db_id): + if db_id == gddb_types.e_db_invalid_file: + print("[Database#check_invalid_type] Error invalid database file !") + OS.set_exit_code(1) + +func check_invalid_version(db_id): + if db_id == gddb_types.e_db_invalid_ver: + print("[Database#check_invalid_version] Error invalid database version !") + OS.set_exit_code(1) + +func save_database_in(): + if OS.get_name() == "Android": + copy_database() + return android_path() + else: + return normal_path() + +func android_path(): + return "user://database.json" + +func normal_path(): + return "res://db/ahog.json" + +func copy_database(): + var database_copy = File.new() + + if !database_copy.file_exists(android_path()): + var database_file = File.new() + + database_file.open(normal_path(), File.READ) + database_copy.open(android_path(), File.WRITE) + database_copy.store_string(database_file.get_as_text()) + database_copy.close() + + database_file.close() +