Skip to content

This package adds simple Python decorator methods and functions for reading and writing TOML save files.

License

Notifications You must be signed in to change notification settings

OBMAKF-DEV/toml-save-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toml-save-tools

This package adds simple Python decorator methods and functions for reading and writing TOML save files.

About

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

How to use

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]

The Save File

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"

About

This package adds simple Python decorator methods and functions for reading and writing TOML save files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages