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 Distribution
py_db_save-1.0.2.tar.gz
(9.9 kB
view details)
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.2.tar.gz.
File metadata
- Download URL: py_db_save-1.0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c04561ef4bd1f0edaeed91cc958edffd7a97037e76382ed3d89f4a1f310cb8d
|
|
| MD5 |
2fba55724018c23a13c7e0be3f9baa11
|
|
| BLAKE2b-256 |
2697c0fd2f2e858b8ec948be8bc49c1ab7ee41edd75bbe20e4a919b95a81eb86
|
File details
Details for the file py_db_save-1.0.2-py3-none-any.whl.
File metadata
- Download URL: py_db_save-1.0.2-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 |
5cb1a28f8bf785acdf11149f6aed59f32865236be08533cf86ee690f3ce8a933
|
|
| MD5 |
bd0671d4087b3a353c1b574e33a65c05
|
|
| BLAKE2b-256 |
72cf258448b157523e17d2bb3002e324a743f8e3023807414089b7bbec0da28d
|