# api
`loreKit.api` (`require("~loreKit.api")`) is loreKit's public surface: define entries (`define`, `get`, `ids`), open and close the reader (`open(id, { style })`, `close`, `current`), the per-player journal (`find`, `markRead`, `journal`, `unread`, `openJournal`, `toggleJournal`, `resetJournal`, `loadJournal` from saveKit), the style list (`STYLES`, `STYLE_INFO`) and events (`on("read"|"found"|"opened"|"closed"|"journal")`). Game code, the Lore component and horrorKit call it.
# loreKit
Version **1.0.6**.
Notes, documents and audio logs that tell your game's story. Put a **Lore** component on a prop and the player can read it: a full-screen **reader** opens in one of **seven styles**, switched by one field. Everything found goes into the player's **journal** with unread markers, saved per player through saveKit. Reading pauses nothing (the world keeps running for everyone), it closes with **Esc**, the pad's **B**, or a big **tap** target, and it is sized for phones and tablets. Ships nine original example entries, two generated voice logs and two generated photos.
## Install
Install `loreKit` from ZeroMind. It needs nothing else and installing it brings no other kit. It works with these when the game links them (`require("~loreKit.links").link("interactKit.api", require("~interactKit.api"))`; `require("~horrorKit.api")` links all three):
| Kit | Used for |
|---|---|
| interactKit | the standard Read prompt on a Lore prop (E / pad X-west / touch button, look-at or proximity) |
| saveKit | saving each player's journal (`Save.set("loreKit", ...)`) |
| soundstage | ducking music and ambience under a tape |
## First example
```lua
local Lore = require("~loreKit.api")
Lore.define({ id = "first_note", style = "note", title = "A torn page", body = "Don't run. It hears the grating." })
-- on a prop, in the editor: add loreKit.Lore, set id = "first_note" (or write title/body there)
-- or from code, on any prop (here a new one):
local prop = entity.spawn("tornPage")
prop.component.add("loreKit.Lore", { id = "first_note" })
Lore.on("read", function(e) if e.first then print("found", e.id) end end)
```
In play, walk up to the prop and press E. Press **J** (or the pad's View/Select, or tap the badge) for the journal.
## Reader styles (`style` = one field)
| Style | What the player sees and hears |
|---|---|
| `note` | handwritten italic on stained, creased paper, slightly askew; paper rustle |
| `memo` | typed office memo: letterhead, FROM / DATE / SUBJ, typewriter face, CONFIDENTIAL stamp |
| `terminal` | CRT terminal; green phosphor text types itself out with a blinking cursor (`variant = "amber"` for amber); beep and keys |
| `tape` | dictaphone deck with spinning reels, timer and progress; plays the entry's `clip` with tape hiss and timed subtitles (from `subtitles`, or made from the body's sentences); music ducks under it |
| `graffiti` | big rough red letters scrawled on a grimy wall |
| `datapad` | sci-fi tablet: bezel, glowing header bar, clean type |
| `photo` | pinned instant photo (`image`) with a handwritten `caption` |
`Lore.open(id, { style = "terminal" })` shows any entry in another style.
## Entries
`{ id, style, title, body, author?, date?, clip?, subtitles? = { { at, text } }, image?, caption?, variant? }`. `clip` is a soundClip ref (or a loreKit clip name), `image` a texture reference (or a loreKit image name).
Examples (original, a half-flooded deep-sea research station): `ring_c_note` (note), `curfew_memo` (memo), `sonar_terminal` (terminal), `tape_varga_14` and `tape_reyne_02` (tape, generated voices), `scrawl_light` (graffiti), `pad_manifest` (datapad), `crew_photo` and `camera_still` (photo, generated images).
## The Lore component
Fields: `id`, `style` (`default` or one of the seven), `title`, `body`, `clip`, `label` ("Read"), `range` (2.2 m), `trigger` (`look` / `proximity`). With interactKit it adds an Interactable beside itself; without it, E or the pad's west button opens it within range. Event `read{id}`. Only the player who used it reads it.
## API (`require("~loreKit.api")`)
| Call | Does |
|---|---|
| `define(entry)`, `get(id)`, `ids()` | the catalogue |
| `open(id, opts?)` | open the reader (finds + marks read + fires `read`). `opts.style`, `opts.source` |
| `close()`, `current()` | close the reader or journal; the open id |
| `find(id)` | add to the journal without opening (true the first time) |
| `markRead(id)`, `isFound(id)`, `isRead(id)` | journal state |
| `journal()`, `unread()` | `{ { id, title, style, read } }` oldest first; unread count |
| `openJournal()`, `toggleJournal()`, `resetJournal()` | the journal screen; a new game |
| `setSubtitles(on)`, `subtitles()` | this player's tape subtitles on or off (default on), for a settings menu; saved in their saveKit profile (`loreKit.settings`) when saveKit is linked; an open tape redraws at once. `open(id, { subtitles = false })` overrides it for one open |
| `STYLES`, `STYLE_INFO`, `VERSION` | |
## Events
| Event | Payload |
|---|---|
| `read` | `{ id, style, title, first, source }` |
| `found` | `{ id, title }` |
| `opened` / `closed` | `{ id }` / `{ id, seconds }` |
| `journal` | `{ open }` (or `{ loaded = true }` after saveKit loads it) |
| `settings` | `{ subtitles }` (and `loaded = true` when a saved choice was applied) |
## Input
| | Keyboard / mouse | Gamepad | Touch |
|---|---|---|---|
| Read | E (interactKit prompt) | X / west | Interact button |
| Close | Esc, Backspace, ✕ button, click outside | B / east | tap ✕ (56 pt tall) or outside |
| Journal | J | View / Select | tap the badge |
## Multiplayer
The reader, journal and badge are local to each player: reading pauses nothing for anyone, and only the player who used a Lore prop sees it. Each player's journal is their own and is saved in their own saveKit profile. Entries defined in code exist on every engine that runs that code.
## Known limits
- Without saveKit the journal lasts the session only.
- Tape subtitles made from the body are timed by sentence length; give `subtitles` for exact timing.
- The badge and journal key are fixed per host (`LoreHost.journalKey`, default J).
## 1.0.1
Escape closes only the open reader or journal; it no longer also opens the engine menu. Declares its dependencies with versions.
## 1.0.2
Installs alone: interactKit, saveKit and soundstage are linked by the game through `loreKit.links` instead of being required by name; `require("~horrorKit.api")` links them.
## 1.0.3
README: the first example spawns the prop it adds Lore to, so it runs as written.
## 1.0.4
The reader test no longer leaves engine errors behind: it removed the reader screen in the same frame it showed it (14 "parent never materialized" errors per run). It now lets each screen settle before closing it. The reader itself is unchanged.
## 1.0.5
The tests remove everything each test left behind and wait for previews a fresh install is drawing, so a passing run leaves no errors. No changes outside the tests.
## 1.0.6
Subtitles can be turned off. `Lore.setSubtitles(false)` hides the tape reader's timed subtitles for this player (a settings menu toggle), `Lore.subtitles()` reads it, and `Lore.open(id, { subtitles = true | false })` overrides it for one open. The choice is saved per player through saveKit (key `loreKit.settings`) when it is linked, an open tape redraws at once, and the `settings` event fires. Default unchanged (on). New test covers it.