Klaleus/defold-checkpoint/checkpoint
Checkpoint is a library for reading from and writing to files in a Defold game engine project.
- Codeberg: Klaleus/defold-checkpoint — pinned to
a5cf87e- This repo publishes no releases or tags. Add a commit archive URL — for the pinned commit,
https://codeberg.org/Klaleus/defold-checkpoint/archive/a5cf87e1dce8d8980f641301e33843747986ff81.zip— togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as checkpoint from "checkpoint.checkpoint"
- This repo publishes no releases or tags. Add a commit archive URL — for the pinned commit,
Functions
read<T = unknown>(path: string): LuaMultiReturn<[ T | false, string | undefined ]>
Loads a saved file. A path ending in .json is read as text and decoded with
json.decode; anything else is loaded with sys.load. On success the loaded
value is returned alone, so the error slot is absent; on any failure — the file
missing, unreadable, or holding invalid content — the first value is false and
the second is the error string. Name the saved shape through the type parameter
to avoid casting at the call site.
Parameters
path:string— Path relative toproject_save_path.
Returns
LuaMultiReturn<[ T | false, string | undefined ]>— The loaded value, orfalseand the error that stopped it.
write(path: string, data: unknown): LuaMultiReturn<[ boolean, string | undefined ]>
Saves a value, creating any missing directories along the path first. A path
ending in .json is encoded with json.encode and written as text and flushed
immediately; anything else is written with sys.save. Creating the directories
goes through lfs, so the project needs britzl/defold-lfs as a dependency;
this corpus does not type it.
Parameters
path:string— Path relative toproject_save_path.data:unknown— The value to save.
Returns
LuaMultiReturn<[ boolean, string | undefined ]>—true, orfalseand the error that stopped it.
exists(path: string): boolean
Whether a saved file exists. Returns a real boolean rather than the underlying
file attributes, so it reads directly as a condition. Goes through lfs, so the
project needs britzl/defold-lfs as a dependency.
Parameters
path:string— Path relative toproject_save_path.
Returns
boolean
list(): string[]
Every saved file, found by walking the save directory breadth-first. Directories
are descended into rather than listed. Goes through lfs, so the project needs
britzl/defold-lfs as a dependency.
Returns
string[]— The file paths, relative toproject_save_path.
Variables
project_title: string
The project.title from game.project, read once when the module loads. It is
the name the save directory is derived from.
project_save_path: string
The absolute path of the project's save directory, resolved once when the
module loads. Every path the other members take is relative to it, and list
returns paths relative to it. Ends with a separator, e.g.
/home/klaleus/.local/share/defold-checkpoint/.