save-system-patterns
БесплатноБез исполняемых скриптовНе проверенSave system code patterns: a core save manager, a save data model, slot metadata for load screens, and settings persistence kept separate from game saves. Use…
от HermeticOrmus★ 83 звезды на GitHubОб этом скилле
Save System Patterns
Core Save Manager
# Save system with versioning, atomic writes, and migration
class_name SaveManager extends Node
const SAVE_DIR := "user://"
const SAVE_VERSION := 2 # Increment when save schema changes
func save_game(slot: int, data: Dictionary) -> Error:
var path := _get_save_path(slot)
var tmp_path := path + ".tmp"
# Add metadata
data["version"] = SAVE_VERSION
data["timestamp"] = Time.get_unix_time_from_system()
var file := FileAccess.open(tmp_path, FileAccess.WRITE)
if not file:
return FileAccess.get_open_error()
file.store_string(JSON.stringify(data, "\t"))
file.close()
# Backup existing save before replacing
if FileAccess.file_exists(path):
DirAccess.copy_absolute(path, path + ".bak")
# Atomic rename: if crash happens before this, .tmp exists but save is intact
var dir := DirAccess.open(SAVE_DIR)
return dir.rename(tmp_path.get_file(), path.get_file())
func load_game(slot: int) -> Dictionary:
var path := _get_save_path(slot)
if not FileAccess.file_exists(path):
return {}
var file := FileAccess.open(path, FileAccess.READ)
if not file:
return {}
var parsed := JSON.parse_string(file.get_as_text())
if not parsed is Dictionary:
push_error("Save file corrupt at slot %d, trying backup" % slot)
return _load_backup(slot)
return _migrate(parsed)
func _migrate(data: Dictionary) -> Dictionary:
var version: int = data.get("version", 0)
if version < 1:
data = _migrate_v0_to_v1(data)
if version < 2:
data = _migrate_v1_to_v2(data)
return data
func _migrate_v0_to_v1(data: Dictionary) -> Dictionary:
# Example: v0 stored health as "hp", v1 uses "health"
if "hp" in data:
data["health"] = data["hp"]
data.erase("hp")
data["version"] = 1
return data
func _migrate_v1_to_v2(data: Dictionary) -> Dictionary:
# Example: v1 had no settings section
if "settings" not in data:
data["settings"] = {"volume_master": 1.0, "fullscreen": false}
data["version"] = 2
return data
func _load_backup(slot: int) -> Dictionary:
var backup_path := _get_save_path(slot) + ".bak"
if not FileAccess.file_exists(backup_path):
return {}
var file := FileAccess.open(backup_path, FileAccess.READ)
if not file:
return {}
var parsed := JSON.parse_string(file.get_as_text())
return parsed if parsed is Dictionary else {}
func _get_save_path(slot: int) -> String:
return "user://save_%d.json" % slot
func delete_save(slot: int) -> void:
var path := _get_save_path(slot)
if FileAccess.file_exists(path):
DirAccess.remove_absolute(path)
if FileAccess.file_exists(path + ".bak"):
DirAccess.remove_absolute(path + ".bak")
Save Data Model
# Typed save data container - serialize/deserialize explicitly
class_name PlayerSaveData extends RefCounted
var health: float = 100.0
var max_health: float = 100.0
var position: Vector2 = Vector2.ZERO
var current_level: StringName = &"level_01"
var inventory: Array[StringName] = []
var flags: Dictionary = {} # quest flags, doors opened, etc.
var playtime: float = 0.0
func to_dict() -> Dictionary:
return {
"health": health,
"max_health": max_health,
"position": {"x": position.x, "y": position.y},
"current_level": str(current_level),
"inventory": inventory.map(func(s): return str(s)),
"flags": flags,
"playtime": playtime,
}
static func from_dict(d: Dictionary) -> PlayerSaveData:
var data := PlayerSaveData.new()
data.health = float(d.get("health", 100.0))
data.max_health = float(d.get("max_health", 100.0))
var pos: Dictionary = d.get("position", {})
data.position = Vector2(float(pos.get("x", 0.0)), float(pos.get("y", 0.0)))
data.current_level = StringName(d.get("current_level", "level_01"))
data.inventory = Array(d.get("inventory", [])).map(func(s): return StringName(s))
data.flags = d.get("flags", {})
data.playtime = float(d.get("playtime", 0.0))
return data
Save Slot Metadata (for UI)
# Lightweight slot summary for save/load screen - no full deserialization needed
class_name SaveSlotMeta extends RefCounted
var slot: int
var exists: bool = false
var level_name: String = ""
var playtime_seconds: float = 0.0
var timestamp: float = 0.0
func get_playtime_display() -> String:
var hours := int(playtime_seconds) / 3600
var minutes := (int(playtime_seconds) % 3600) / 60
return "%02d:%02d" % [hours, minutes]
func get_date_display() -> String:
return Time.get_datetime_string_from_unix_time(int(timestamp)).substr(0, 10)
static func read(slot: int) -> SaveSlotMeta:
var meta := SaveSlotMeta.new()
meta.slot = slot
var path := "user://save_%d.json" % slot
if not FileAccess.file_exists(path):
return meta # exists = false
Установить save-system-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл save-system-patterns?
Save system code patterns: a core save manager, a save data model, slot metadata for load screens, and settings persistence kept separate from game saves. Use when implementing saving and loading in a game.
Как установить скилл save-system-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл save-system-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic