diff --git a/src/meson.build b/src/meson.build index 78d6144..f2c7981 100644 --- a/src/meson.build +++ b/src/meson.build @@ -30,6 +30,7 @@ cartridges_sources = [ 'utils/get_cover.py', 'utils/save_games.py', 'utils/save_cover.py', + 'utils/game_data_to_json.py', 'utils/toggle_hidden.py', 'utils/create_dialog.py', 'utils/create_details_window.py' diff --git a/src/utils/game_data_to_json.py b/src/utils/game_data_to_json.py new file mode 100644 index 0000000..f927809 --- /dev/null +++ b/src/utils/game_data_to_json.py @@ -0,0 +1,25 @@ +# game_data_to_json.py +# +# Copyright 2022-2023 kramo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import json +import os + + +def game_data_to_json(data): + return json.dumps(data, indent=4, sort_keys=True) diff --git a/src/utils/save_games.py b/src/utils/save_games.py index 858f08c..fdc6e77 100644 --- a/src/utils/save_games.py +++ b/src/utils/save_games.py @@ -20,6 +20,8 @@ import json import os +from .game_data_to_json import game_data_to_json + def save_games(games): games_dir = os.path.join( @@ -34,5 +36,5 @@ def save_games(games): for game in games: with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file: - open_file.write(json.dumps(games[game], indent=4, sort_keys=True)) + open_file.write(game_data_to_json(games[game])) open_file.close()