game/data.py

33 lines
1011 B
Python

# -*- coding: utf-8 -*-
#
# Copyright © 2024 Simon Forman
#
# This file is part of game
#
# game 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.
#
# game 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 game. If not see <http://www.gnu.org/licenses/>.
#
'''
I could use SQLite for a data file format, or just pickle.
'''
from pickle import load as pload, dump
def save(fn, game_state):
with open(fn, 'wb') as f:
dump(game_state, f, protocol=0)
def load(fn):
with open(fn, 'rb') as f:
return pload(f)