/tg/ Station 13 - Modules - Types — Var Details - Proc Details

graffiti_library

One account's graffiti library: up to GRAFFITI_LIBRARY_CAP pieces and the Unfinished slot, kept in one JSON file under SSgraffiti.library_root. Get it with graffiti_library().

Every change is written through and undone when the write fails, so the library holds what its file doesn't only while a change the server made waits for the write pacing (save()). A write the file holds stands even when its backup couldn't be refreshed after it, which the next save does. It unloads as its owner disconnects, or, while an editor session, a paint job or a held write still needs it, once they end (graffiti_library_unload()).

Vars

ckeyThe account's ckey.
next_idThe number in the next new piece's id, "g[next_id]".
piecesPiece id -> list("piece" = canonical piece, "created", "updated", "thumb" = its flattened art), oldest first. Entries are replaced, never changed.
revealedWhat unfinished_entry() last flattened of a stopped paint job: list(piece, progress, the art revealed). The slot's piece is replaced, never changed, so a piece and a progress always reveal the same art.
revisionIts state's number, from SSgraffiti.library_revision and new with each change, so a window that shows it knows to send it again.
storeThe library's file.
unfinishedThe last interrupted or unsaved piece, list("piece", "resume", "created", "thumb"), or null.
unwrittensnapshot() of the library as its file holds it, while changes wait for write_timer.
write_timerThe timer that writes the changes held back by the write pacing, while one is pending.

Procs

NewLoads an account's library from its file.
delete_pieceDeletes a saved piece.
discard_unfinishedEmpties the Unfinished slot.
entriesReturns the saved pieces as the spraycan's Custom Graffiti tab lists them, newest first.
entry_dataReturns one piece as the Custom Graffiti tab lists it.
export_textReturns a saved piece as the text Export writes.
import_pieceImports a piece as a new piece. It must pass graffiti_validate_piece() as given, its format and version included.
keep_unfinishedMoves the Unfinished piece into the library as a new piece.
pieceReturns a saved piece.
putStores a canonical piece in pieces without writing the file.
rename_pieceRenames a saved piece and sets its description, as the Custom Graffiti tab edits them. Its art stays as it is.
saveWrites the library to its file, or deletes the file once the library holds no pieces and no Unfinished piece, and paces the account's next write by how long this one took (graffiti_library_paced()).
save_pieceSaves a piece into the library, as a new piece or over one it holds.
set_unfinishedPuts a piece in the Unfinished slot, replacing what it held.
snapshotReturns the library's state, for save() to put back when a change can't be written.
unfinished_entryReturns the Unfinished slot as the Custom Graffiti tab shows it.
write_heldWrites the changes the write pacing held back, as write_timer fires, then unloads the library if its owner disconnected meanwhile (graffiti_library_unload()). A library no longer loaded, as after an admin purge, writes nothing.

Var Details

ckey

The account's ckey.

next_id

The number in the next new piece's id, "g[next_id]".

pieces

Piece id -> list("piece" = canonical piece, "created", "updated", "thumb" = its flattened art), oldest first. Entries are replaced, never changed.

revealed

What unfinished_entry() last flattened of a stopped paint job: list(piece, progress, the art revealed). The slot's piece is replaced, never changed, so a piece and a progress always reveal the same art.

revision

Its state's number, from SSgraffiti.library_revision and new with each change, so a window that shows it knows to send it again.

store

The library's file.

unfinished

The last interrupted or unsaved piece, list("piece", "resume", "created", "thumb"), or null.

unwritten

snapshot() of the library as its file holds it, while changes wait for write_timer.

write_timer

The timer that writes the changes held back by the write pacing, while one is pending.

Proc Details

New

Loads an account's library from its file.

Every stored piece is validated again, and one that fails is dropped with a log line, as are pieces past GRAFFITI_LIBRARY_CAP. When the file can't be read at all, such as one over GRAFFITI_LIBRARY_MAX_BYTES, the library starts empty and its store refuses every write, so the file stays for an admin to look at.

Arguments:

delete_piece

Deletes a saved piece.

Arguments:

Returns:

discard_unfinished

Empties the Unfinished slot.

Arguments:

Returns:

entries

Returns the saved pieces as the spraycan's Custom Graffiti tab lists them, newest first.

Returns:

entry_data

Returns one piece as the Custom Graffiti tab lists it.

Arguments:

Returns:

export_text

Returns a saved piece as the text Export writes.

Arguments:

Returns:

import_piece

Imports a piece as a new piece. It must pass graffiti_validate_piece() as given, its format and version included.

Arguments:

Returns:

keep_unfinished

Moves the Unfinished piece into the library as a new piece.

Returns:

piece

Returns a saved piece.

Arguments:

Returns:

put

Stores a canonical piece in pieces without writing the file.

Arguments:

Returns:

rename_piece

Renames a saved piece and sets its description, as the Custom Graffiti tab edits them. Its art stays as it is.

Arguments:

Returns:

save

Writes the library to its file, or deletes the file once the library holds no pieces and no Unfinished piece, and paces the account's next write by how long this one took (graffiti_library_paced()).

A change the server makes is never refused for the pacing: while the account's last write still paces the next, it is held back, and write_timer writes it once the pacing allows, with whatever else changed meanwhile. Any write takes the changes held so far with it.

Arguments:

Returns:

save_piece

Saves a piece into the library, as a new piece or over one it holds.

Arguments:

Returns:

set_unfinished

Puts a piece in the Unfinished slot, replacing what it held.

Arguments:

Returns:

snapshot

Returns the library's state, for save() to put back when a change can't be written.

Returns:

unfinished_entry

Returns the Unfinished slot as the Custom Graffiti tab shows it.

Returns:

write_held

Writes the changes the write pacing held back, as write_timer fires, then unloads the library if its owner disconnected meanwhile (graffiti_library_unload()). A library no longer loaded, as after an admin purge, writes nothing.