Skip to main content

Pythonのゲーム向けセーブデータ管理ライブラリ

Project description

py_save

ゲーム向け SQLite セーブデータ管理ライブラリ。
標準ライブラリのみで動く SaveManager と、pygame 連携の PygameSaveManager を提供します。

インストール

pip install py_save

クイックスタート

from py_save import SaveManager

mgr = SaveManager("saves/")

# 作成
mgr.create(1, {"player": "Alice", "level": 1, "hp": 100})

# 読み込み
data = mgr.load(1)

# 全体保存
data["level"] = 2
mgr.save(1, data, play_time=3600)

# 部分更新
mgr.update(1, {"hp": 80})

# 消去
mgr.delete(1)

pygame 連携

import pygame
from py_save import PygameSaveManager

mgr = PygameSaveManager("saves/", autosave_sec=300)

# オートセーブ用データ取得関数を登録
mgr.set_data_getter(lambda: {
    "player": player.name,
    "hp":     player.hp,
    "pos":    [player.x, player.y],
})

# ゲームループ
while running:
    for event in pygame.event.get():
        # F5 クイックセーブ / F9 クイックロード
        result = mgr.handle_keydown(
            event,
            quicksave_key=pygame.K_F5,
            quickload_key=pygame.K_F9,
        )

    # オートセーブチェック(毎フレーム)
    mgr.tick()

    # セーブ画面にスロット一覧を描画
    mgr.render_slot_list(screen, font, selected_slot=current_slot)

API 一覧

SaveManager

メソッド 説明
create(slot, data, play_time, overwrite) スロット新規作成
load(slot) データ読み込み(メタキー _* 付き)
save(slot, data, play_time) 全体を上書き保存
update(slot, fields, play_time) 指定フィールドのみ部分更新
delete(slot) スロット消去
exists(slot) スロット存在確認
list() 全スロットのメタ情報一覧
copy(src, dst) スロットのコピー
restore_backup(slot) バックアップから復元

PygameSaveManager(SaveManager を継承)

メソッド 説明
set_data_getter(fn) オートセーブ用データ取得関数を登録
tick() ゲームループで毎フレーム呼ぶ。オートセーブを自動実行
handle_keydown(event, ...) F5/F9 などのキーでクイックセーブ/ロード
save_with_time(slot, data) プレイ時間を自動計算して保存
session_time() 現セッションの経過秒数
total_play_time(slot) 累計プレイ時間(秒)
format_play_time(sec) "HH:MM:SS" 形式に変換
render_slot_list(surface, font, ...) スロット一覧を pygame に描画

例外

例外 発生条件
SlotNotFoundError 存在しないスロットへのアクセス
SlotAlreadyExistsError overwrite=False で既存スロットに create

CLI ツール

py_save list               # スロット一覧
py_save show 1             # スロット1の中身を表示
py_save delete autosave    # autosave スロットを削除
py_save --dir path/to/saves list   # フォルダ指定

ライセンス

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_db_save-1.0.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_db_save-1.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file py_db_save-1.0.1.tar.gz.

File metadata

  • Download URL: py_db_save-1.0.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for py_db_save-1.0.1.tar.gz
Algorithm Hash digest
SHA256 58b20e81cde592e8052f5ce1f02f29ea200fce7e1cbedb9c08d9f458a02d9ffa
MD5 4a7f97818bb322620be266a3c735b598
BLAKE2b-256 84b287eb15d87dc90b045f58dbb5528ee250956d6a988b951fe56503c85a3980

See more details on using hashes here.

File details

Details for the file py_db_save-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_db_save-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for py_db_save-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7db6a8f00e00b301c87ef05be6a8c93031ae44b8b85bae0735b37f29f5f9c60
MD5 5addbb30a2933e6d0ac30015c46b5319
BLAKE2b-256 d472f56f9f745986909cb4a6254b63e4158c1b96b641d096af84a37c88072e0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page