This package adds simple Python decorator methods and functions for reading and writing TOML save files.
This package is being developed to add save functionality to Python games. The package requires the you to install tomli - v2.0.1 (or higher)
To install tomli run:
pip install tomli
To ensure that pip is up to-date run:
pip install --upgrade pip
Using the load_game
decorator...
class Game:
def __init__(self, ...):
self.player = ...
@load_game
def start(self, ...):
# implement the game logic here.
This assigns any saved values to Game
and Game.player
.
Using the save_game
decorator...
class Game:
def __init__(self, ...):
self.player = ...
@save_game
def event(self, ...):
# implement the event logic here.
This saves the Game
and Game.player
attribute values to the save file.
Using the load
method to retrive a single element...
game = Game(...)
hp = load(game, subject='player_data', _kw='health')
# 100
... And to retrieve multiple elements...
game = Game(...)
elements = load(game, subject='player_data', _kw=['health', 'stamina', 'xp'])
# [100, 20, 120]
An example on how the save_file
might look...
[player_data]
name = "John Doe"
health = 100
max_health = 100
level = 1
[game_data]
current_map = 1
current_quest = "A new day"
[controls]
forward = "A"
backwards = "S"
left = "A"
right = "D"
interact = "F"