chatplugin
Lines a seat says, on four channels, and the panel that shows and takes them.
Putting it in a scene
List it before ui, which draws what chat shows. The scene's sim hands the chat and chatbox kinds from #plugins/chat/chat.sim.ts a way to mail other truths and a way to find a player's party (see Rules). The scene has one { "is": "chat" } actor, and the hub has one too. A scene whose talk includes party or whisper must list chatbox.channels in its security, so each seat is sent only its own party and whisper lines.
"plugins": ["loader", "scenemanager", "player", "chat", "ui", "render2d"],
"security": { "chatbox": { "channels": "me" } },
"prefabs": {
"player": { "seat": 0, "masks": [], "account": "", "name": "" },
"chat": {
"who": { "kind": "player", "seat": "seat", "account": "account", "name": "name" },
"talk": ["zone", "party", "whisper", "global"],
"length": 120,
"keep": 40,
"rate": { "gap": 30, "burst": 4 },
"hub": "hub",
"scenes": ["town", "forest"],
"page": { "lines": 8, "height": 18, "tab": 70, "label": [0, 170], "entry": [60, 170] },
"channels": { "zone": { "seq": 0, "lines": {} }, "global": { "seq": 0, "lines": {} } },
"n": 0,
"next": {}
},
"chatbox": { "channels": { "party": { "seq": 0, "lines": {} }, "whisper": { "seq": 0, "lines": {} } } }
}
Channels
| Channel | Who reads a line |
|---|---|
zone | Every seat in the truth the speaker is in. |
whisper | One account, named when the line is said. The line is also echoed to the speaker with a to: { account, name }, drawn as →name: text. |
party | Every member account of the speaker's party, wherever they are. A speaker in no party is heard by nobody. |
global | Every live copy of each scene in the chat row's scenes. |
A line is { from, account, text, n }: the speaker's name and account, what was said, and the chat row's step it arrived on. Each channel keeps its last keep lines in a ring { seq, lines: { <seq>: line } }. Adding a line adds one key and deletes the key keep behind it, so each say sends one line and never the whole ring.
The zone and global rings are on the chat row. The party and whisper rings are on a chatbox row of the reading account, spawned the first time a line reaches that account in this truth and ended once no row of the account is here. Its owner is the account's row, so with the security listing above every other seat is sent the chatbox without its lines.
Properties
Read from the chat prefab.
| Field | Meaning |
|---|---|
who | { kind, seat, account, name }: the kind whose row stands for a seat, and the names of three of its fields. seat holds the truth's seat number the row's seat speaks from (a player row keeps the number its arrive act was handed), and account and name hold what a line is attributed to. A seat with no such row says nothing. |
talk | The channels this scene allows, from zone, whisper, party and global. A line on any other is dropped, so leaving one out turns it off. The tabs are in this order, and the first is open at first. |
length | The most characters in a line. A longer line, or a blank one, is dropped. |
keep | Lines kept in each ring. |
rate | { gap, burst }: a seat may say burst lines at once, then one every gap steps of the chat row. |
hub | The name of the hub's truth, where party and global lines are relayed. |
scenes | The scenes a global line reaches. |
channels | The empty rings for zone and global. A chatbox's prefab holds the rings for party and whisper. |
n, next | The row's own step count, and per seat the step it may next say a line. Both start as shown. |
page | Where the page draws, in pixels (below). |
.page
| Key | Meaning |
|---|---|
lines | How many of the open channel's last lines are shown, the oldest at the top. |
height | Pixels between lines. |
tab | Pixels between channel tabs, across. |
label | [x, y] of the label saying where a line goes: [zone], or [name] for a whisper. |
entry | [x, y] of the text entry. |
Panels and styles
The panels and styles are in ui's prefab.
| Panel | Contents and styles |
|---|---|
chat.tabs | A button per channel of talk, labelled with its name, in the style chat.tab, and chat.tab.on for the open one. Each is a button options object without its label. A tap opens that channel. |
chat.log | The lines, as from: text, or →name: text for a whisper the seat sent, in the style chat.<channel>. A tap on a line opens the whisper channel to its speaker, or to whoever a whisper the seat sent went to. |
chat.entry | The label in the style chat.label, and the text entry in the style chat.entry, which is ui's entry with the row's length as its max. A line sent with Enter goes to the chat row as say on the open channel. A whisper goes with the account and name it is for, and a whisper with nobody to go to is not sent. |
Methods
Acts
Sent at the chat row by a seat. All are open.
say( channel, text, to?, toName? )
Says a line. to is the account and toName the name a whisper goes to, and both are required for a whisper. The line is dropped unless the channel is in talk, the text is a non-blank string of at most length characters, the seat has a speaker row, and the seat is within its rate.
relay( channel, from, account, text )
Mail between truths: the hub's chat row passes a party line to every member account of the speaker's party, and a global line to every live copy of each scene in scenes. Not for a seat to send.
hear( channel, from, account, text, reader )
Mail between truths: adds a line. A zone or global line goes to the chat row, and a party or whisper line to the chatbox of reader, when that account has a row here. Not for a seat to send.
Rules
From #plugins/chat/chat.sim.ts.
chat( post, members ) : { chat, chatbox }
Builds the two kinds for the game's sim. post(w, to, kind, act, ...args) calls an act on the first row of kind in the truth to names, which is a truth name, { account } or { scene }. members(w, account) returns every account of that account's party; party's own members does this.
On the page
Through plugins.chat.
whisper( account, name )
Opens the whisper channel to that account. The next line the player sends from the entry goes to them. Another plugin's page half calls it when the player picks someone, as party does through its mod.
Mods
- partychat gives party a
whispermod, the fileplugins/chat/chat.party.ts. A tap on a party member's name opens the whisper channel to them. The scene names it withworld.party.mods.whisperset to"chat".