Move game data JSON formatter to re-usable location

This commit is contained in:
Bananaman
2023-03-24 21:21:24 +01:00
parent 4e7e21ff6c
commit eda22c7ea7
3 changed files with 29 additions and 1 deletions

View File

@@ -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'

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
# 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)

View File

@@ -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()