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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_db_save-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_db_save-1.0.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7a3c150e1c7a65dbbe1f3d8ff3884a2ba3e840992b538df0212b266bb1b4f65
|
|
| MD5 |
e934ba9f12f8d14c6f337c746c4f54fe
|
|
| BLAKE2b-256 |
109e958cacbd6fea016fcdc96d4b2c5478eba9dcacb6031e2d83553b7750ce04
|