diff --git a/App/Resources/Skins/abacus/hit.png b/App/Resources/Retired/abacus/hit.png similarity index 100% rename from App/Resources/Skins/abacus/hit.png rename to App/Resources/Retired/abacus/hit.png diff --git a/App/Resources/Skins/abacus/idle.png b/App/Resources/Retired/abacus/idle.png similarity index 100% rename from App/Resources/Skins/abacus/idle.png rename to App/Resources/Retired/abacus/idle.png diff --git a/App/Resources/Skins/abacus/impact.png b/App/Resources/Retired/abacus/impact.png similarity index 100% rename from App/Resources/Skins/abacus/impact.png rename to App/Resources/Retired/abacus/impact.png diff --git a/App/Resources/Skins/abacus/mallet.png b/App/Resources/Retired/abacus/mallet.png similarity index 100% rename from App/Resources/Skins/abacus/mallet.png rename to App/Resources/Retired/abacus/mallet.png diff --git a/App/Resources/Retired/abacus/skin.json b/App/Resources/Retired/abacus/skin.json new file mode 100644 index 0000000..7c547b2 --- /dev/null +++ b/App/Resources/Retired/abacus/skin.json @@ -0,0 +1 @@ +{ "name": "Abacus", "names": { "zh-Hans": "算盘" }, "strike": [0.5, 0.325], "voice": "bead", "glow": "#F0BA44" } diff --git a/App/Resources/Skins/crt-terminal/hit.png b/App/Resources/Retired/crt-terminal/hit.png similarity index 100% rename from App/Resources/Skins/crt-terminal/hit.png rename to App/Resources/Retired/crt-terminal/hit.png diff --git a/App/Resources/Skins/crt-terminal/idle.png b/App/Resources/Retired/crt-terminal/idle.png similarity index 100% rename from App/Resources/Skins/crt-terminal/idle.png rename to App/Resources/Retired/crt-terminal/idle.png diff --git a/App/Resources/Skins/crt-terminal/impact.png b/App/Resources/Retired/crt-terminal/impact.png similarity index 100% rename from App/Resources/Skins/crt-terminal/impact.png rename to App/Resources/Retired/crt-terminal/impact.png diff --git a/App/Resources/Skins/crt-terminal/mallet.png b/App/Resources/Retired/crt-terminal/mallet.png similarity index 100% rename from App/Resources/Skins/crt-terminal/mallet.png rename to App/Resources/Retired/crt-terminal/mallet.png diff --git a/App/Resources/Retired/crt-terminal/skin.json b/App/Resources/Retired/crt-terminal/skin.json new file mode 100644 index 0000000..387847f --- /dev/null +++ b/App/Resources/Retired/crt-terminal/skin.json @@ -0,0 +1 @@ +{ "name": "CRT Terminal", "names": { "zh-Hans": "CRT 终端" }, "strike": [0.52, 0.395], "voice": "crt" } diff --git a/App/Resources/Skins/mug/idle.png b/App/Resources/Retired/mug/idle.png similarity index 100% rename from App/Resources/Skins/mug/idle.png rename to App/Resources/Retired/mug/idle.png diff --git a/App/Resources/Skins/mug/impact.png b/App/Resources/Retired/mug/impact.png similarity index 100% rename from App/Resources/Skins/mug/impact.png rename to App/Resources/Retired/mug/impact.png diff --git a/App/Resources/Skins/mug/mallet.png b/App/Resources/Retired/mug/mallet.png similarity index 100% rename from App/Resources/Skins/mug/mallet.png rename to App/Resources/Retired/mug/mallet.png diff --git a/App/Resources/Retired/mug/skin.json b/App/Resources/Retired/mug/skin.json new file mode 100644 index 0000000..7ea0b25 --- /dev/null +++ b/App/Resources/Retired/mug/skin.json @@ -0,0 +1 @@ +{ "name": "Mug", "names": { "zh-Hans": "马克杯" }, "strike": [0.56, 0.36], "voice": "ceramic", "glow": "#F6BE3D" } diff --git a/App/Resources/Skins/piston/hit.png b/App/Resources/Retired/piston/hit.png similarity index 100% rename from App/Resources/Skins/piston/hit.png rename to App/Resources/Retired/piston/hit.png diff --git a/App/Resources/Skins/piston/idle.png b/App/Resources/Retired/piston/idle.png similarity index 100% rename from App/Resources/Skins/piston/idle.png rename to App/Resources/Retired/piston/idle.png diff --git a/App/Resources/Skins/piston/impact.png b/App/Resources/Retired/piston/impact.png similarity index 100% rename from App/Resources/Skins/piston/impact.png rename to App/Resources/Retired/piston/impact.png diff --git a/App/Resources/Skins/piston/mallet.png b/App/Resources/Retired/piston/mallet.png similarity index 100% rename from App/Resources/Skins/piston/mallet.png rename to App/Resources/Retired/piston/mallet.png diff --git a/App/Resources/Retired/piston/skin.json b/App/Resources/Retired/piston/skin.json new file mode 100644 index 0000000..24366e5 --- /dev/null +++ b/App/Resources/Retired/piston/skin.json @@ -0,0 +1 @@ +{ "name": "Piston", "names": { "zh-Hans": "活塞" }, "strike": [0.52, 0.39], "voice": "piston" } diff --git a/App/Resources/Skins/seal/idle.png b/App/Resources/Retired/seal/idle.png similarity index 100% rename from App/Resources/Skins/seal/idle.png rename to App/Resources/Retired/seal/idle.png diff --git a/App/Resources/Skins/seal/impact.png b/App/Resources/Retired/seal/impact.png similarity index 100% rename from App/Resources/Skins/seal/impact.png rename to App/Resources/Retired/seal/impact.png diff --git a/App/Resources/Skins/seal/mallet.png b/App/Resources/Retired/seal/mallet.png similarity index 100% rename from App/Resources/Skins/seal/mallet.png rename to App/Resources/Retired/seal/mallet.png diff --git a/App/Resources/Retired/seal/skin.json b/App/Resources/Retired/seal/skin.json new file mode 100644 index 0000000..6330e44 --- /dev/null +++ b/App/Resources/Retired/seal/skin.json @@ -0,0 +1 @@ +{ "name": "Seal", "names": { "zh-Hans": "印章" }, "strike": [0.55, 0.39], "voice": "stamp", "glow": "#F95240" } diff --git a/App/Resources/Skins/space-key/hit.png b/App/Resources/Retired/space-key/hit.png similarity index 100% rename from App/Resources/Skins/space-key/hit.png rename to App/Resources/Retired/space-key/hit.png diff --git a/App/Resources/Skins/space-key/idle.png b/App/Resources/Retired/space-key/idle.png similarity index 100% rename from App/Resources/Skins/space-key/idle.png rename to App/Resources/Retired/space-key/idle.png diff --git a/App/Resources/Skins/space-key/impact.png b/App/Resources/Retired/space-key/impact.png similarity index 100% rename from App/Resources/Skins/space-key/impact.png rename to App/Resources/Retired/space-key/impact.png diff --git a/App/Resources/Skins/space-key/mallet.png b/App/Resources/Retired/space-key/mallet.png similarity index 100% rename from App/Resources/Skins/space-key/mallet.png rename to App/Resources/Retired/space-key/mallet.png diff --git a/App/Resources/Retired/space-key/skin.json b/App/Resources/Retired/space-key/skin.json new file mode 100644 index 0000000..2c05ae0 --- /dev/null +++ b/App/Resources/Retired/space-key/skin.json @@ -0,0 +1 @@ +{ "name": "Space Key", "names": { "zh-Hans": "空格键" }, "strike": [0.52, 0.515], "voice": "key" } diff --git a/App/Resources/Skins/abacus/skin.json b/App/Resources/Skins/abacus/skin.json deleted file mode 100644 index 1d600d3..0000000 --- a/App/Resources/Skins/abacus/skin.json +++ /dev/null @@ -1 +0,0 @@ -{ "name": "Abacus", "strike": [0.5, 0.325], "voice": "bead", "glow": "#F0BA44" } diff --git a/App/Resources/Skins/crt-terminal/skin.json b/App/Resources/Skins/crt-terminal/skin.json deleted file mode 100644 index 2de4b3e..0000000 --- a/App/Resources/Skins/crt-terminal/skin.json +++ /dev/null @@ -1 +0,0 @@ -{ "name": "CRT Terminal", "strike": [0.52, 0.395], "voice": "crt" } diff --git a/App/Resources/Skins/mug/skin.json b/App/Resources/Skins/mug/skin.json deleted file mode 100644 index 12b0602..0000000 --- a/App/Resources/Skins/mug/skin.json +++ /dev/null @@ -1 +0,0 @@ -{ "name": "Mug", "strike": [0.56, 0.36], "voice": "ceramic", "glow": "#F6BE3D" } diff --git a/App/Resources/Skins/piston/skin.json b/App/Resources/Skins/piston/skin.json deleted file mode 100644 index da19000..0000000 --- a/App/Resources/Skins/piston/skin.json +++ /dev/null @@ -1 +0,0 @@ -{ "name": "Piston", "strike": [0.52, 0.39], "voice": "piston" } diff --git a/App/Resources/Skins/seal/skin.json b/App/Resources/Skins/seal/skin.json deleted file mode 100644 index cc09c2b..0000000 --- a/App/Resources/Skins/seal/skin.json +++ /dev/null @@ -1 +0,0 @@ -{ "name": "Seal", "strike": [0.55, 0.39], "voice": "stamp", "glow": "#F95240" } diff --git a/App/Resources/Skins/space-key/skin.json b/App/Resources/Skins/space-key/skin.json deleted file mode 100644 index c3f65a2..0000000 --- a/App/Resources/Skins/space-key/skin.json +++ /dev/null @@ -1 +0,0 @@ -{ "name": "Space Key", "strike": [0.52, 0.515], "voice": "key" } diff --git a/App/Resources/zh-Hans.lproj/Localizable.strings b/App/Resources/zh-Hans.lproj/Localizable.strings index 0b3a10b..2fe3ddf 100644 --- a/App/Resources/zh-Hans.lproj/Localizable.strings +++ b/App/Resources/zh-Hans.lproj/Localizable.strings @@ -4,20 +4,6 @@ /* Menu bar and right-click menu */ "Knock" = "敲一下"; "Auto-Knock" = "自动敲击"; -"Pace" = "节奏"; -"With the breath · every 6 s" = "随息 · 每 6 秒"; -"Slow · every 2 s" = "慢 · 每 2 秒"; -"Moderate · every 1 s" = "中 · 每 1 秒"; -"Every %.1f s" = "每 %.1f 秒"; -"Fast · every 0.5 s" = "快 · 每 0.5 秒"; -"Knock as You Type" = "打字时跟着敲"; -"Placement" = "位置"; -"Above windows" = "浮在窗口上方"; -"On the desktop" = "放在桌面上"; -"Heard, not seen" = "只闻其声"; -"Skin" = "皮肤"; -"Add Skins…" = "添加皮肤…"; -"Open Skins Folder" = "打开皮肤文件夹"; "Settings…" = "设置…"; "Quit Plinth" = "退出 Plinth"; "Plinth" = "Plinth"; @@ -31,8 +17,7 @@ "Sound" = "声音"; "The longer the quiet before a knock, the longer it rings." = "敲之前静得越久,余音越长。"; "While You Work" = "做事时"; -"Each key you press, in any app, knocks once. Plinth never learns which key, and needs no permission." = "在任何 App 里每按一个键,就敲一下。Plinth 从不知道按的是哪个键,也不需要任何权限。"; -"While another app listens to a microphone, as in a call, only a knock by hand sounds. Plinth never listens itself." = "别的 App 在用麦克风时(比如开会),只有亲手敲才会响。Plinth 自己从不收音。"; +"Plinth never learns which key you press, never listens to a microphone itself, and needs no permission." = "Plinth 从不知道你按的是哪个键,自己从不收音,也不需要任何权限。"; "The Fish" = "木鱼"; "Volume" = "音量"; "Knock as you type" = "打字时跟着敲"; @@ -41,14 +26,17 @@ "Record Key" = "录制按键"; "Press a key…" = "请按一个键…"; "Clear" = "清除"; -"Space" = "空格"; -"A key, a foot pedal or a Stream Deck button can be the mallet: press it in any app and the fish is knocked by hand. An F-key can stand alone; any other key needs two modifiers, one of them ⌘ or ⌃, so ⌘C, ⌃C and the like keep working." = "一个键、一只脚踏板或一颗 Stream Deck 按键,都可以当作木槌:在任何 App 里按下它,就如亲手敲一下。F 键可以单独用;其他键要配两个修饰键,其中一个是 ⌘ 或 ⌃,这样 ⌘C、⌃C 这类快捷键照常可用。"; -"After half an hour of typing with no three-minute rest, the fish falls quiet for three seconds, then knocks once with a held mallet. Typed knocks and auto-knock stay quiet for three breaths, about 15 seconds. Nothing is counted or kept." = "连着打字半小时,中间没歇过三分钟,木鱼先静三秒,再独敲一下,压槌稍驻。打字敲击和自动敲击再静三息,约 15 秒。不计数,也不记录。"; +/* The space bar, as a mallet key. Not "Space", which is the room the knock rings in. */ +"Space (key)" = "空格"; +"An F-key can stand alone. Any other key needs two modifiers, one of them ⌘ or ⌃." = "F 键可以单独用。其他键要配两个修饰键,其中一个是 ⌘ 或 ⌃。"; "Knock on its own" = "让它自己敲"; -"Every" = "每隔"; -"%.1f s" = "%.1f 秒"; +"Pace" = "节奏"; "Stop after 108 knocks, one turn of a mala" = "敲满 108 下就停,正好念珠一圈"; "Size" = "大小"; +"Placement" = "位置"; +"Above windows" = "浮在窗口上方"; +"On the desktop" = "放在桌面上"; +"Heard, not seen" = "只闻其声"; "Small" = "小"; "Medium" = "中"; "Large" = "大"; @@ -56,11 +44,15 @@ /* Settings: Skins */ "Skins" = "皮肤"; +/* The iPhone's palette button. */ +"Skin" = "皮肤"; "Built In" = "内置"; "Your Skins" = "你的皮肤"; "No skins of your own yet." = "还没有你自己的皮肤。"; "Click a skin to wear it. One of your own can be a single image or a folder of frames; right-click it to export a .plinthskin to share." = "点一下就换上。自己的皮肤可以是一张图片,也可以是一组帧图的文件夹;右键点它,可以导出成 .plinthskin 分享给别人。"; "How to Make a Skin" = "怎样做皮肤"; +"Add Skins…" = "添加皮肤…"; +"Open Skins Folder" = "打开皮肤文件夹"; "Choose images, skin folders that contain idle.png, or .plinthskin files" = "选择图片、包含 idle.png 的皮肤文件夹,或 .plinthskin 文件"; /* Settings: Why a Fish */ @@ -69,9 +61,9 @@ /* Incense */ "Light Incense" = "点一炷香"; -"Half a stick · 25 minutes" = "半炷香 · 25 分钟"; -"One stick · 45 minutes" = "一炷香 · 45 分钟"; -"Long incense · 60 minutes" = "长香 · 60 分钟"; +"Half a stick" = "半炷香"; +"One stick" = "一炷香"; +"Long incense" = "长香"; "Put Out the Incense" = "熄香"; "Incense" = "香"; diff --git a/App/Resources/zh-Hans.lproj/Skins.strings b/App/Resources/zh-Hans.lproj/Skins.strings index 011250a..f226022 100644 --- a/App/Resources/zh-Hans.lproj/Skins.strings +++ b/App/Resources/zh-Hans.lproj/Skins.strings @@ -8,17 +8,11 @@ "pixel-fish" = "像素鱼"; "red-lacquer" = "朱漆"; "singing-bowl" = "铜磬"; -"space-key" = "空格键"; "bamboo-block" = "竹节"; "moss-stone" = "苔石"; -"piston" = "活塞"; -"crt-terminal" = "CRT 终端"; -"abacus" = "算盘"; "cloud-gong" = "云板"; "porcelain-fish" = "青花瓷鱼"; "bianzhong" = "编钟"; -"seal" = "印章"; "stone-chime" = "石磬"; "fish-board" = "鱼板"; -"mug" = "马克杯"; "temple-fish" = "古木鱼"; diff --git a/CREDITS.md b/CREDITS.md index ae693d2..03b1d3c 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -2,7 +2,7 @@ - **Code** is released under the [MIT License](LICENSE). - **Updates** use [Sparkle](https://sparkle-project.org), under the [MIT License](https://github.com/sparkle-project/Sparkle/blob/2.x/LICENSE), embedded in the app as `Sparkle.framework`. -- **Sprite artwork** (`App/Resources/Skins`, `mallet.png`, `impact.png`, `censer.png`) was AI-generated for this project, with the edits and effects below. It is dedicated to the public domain under [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/). +- **Sprite artwork** (`App/Resources/Skins`, `App/Resources/Retired`, `mallet.png`, `impact.png`, `censer.png`) was AI-generated for this project, with the edits and effects below. It is dedicated to the public domain under [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/). - **Sprite effects and derived frames** are also CC0. The singing bowl's ripple is drawn with [`tools/draw_ripple.py`](tools/draw_ripple.py); the space key, bamboo block, moss stone, piston, CRT, abacus, cloud gong, bianzhong, stone chime, and temple fish pulses are drawn with [`tools/draw_skin_impacts.py`](tools/draw_skin_impacts.py). The pressed key, compressed piston, flicked abacus bead, swung cloud gong and bianzhong, and rocked stone chime frames are derived from their idle artwork, keeping their bases still. The seal's mallet head is its generated rosewood head recoloured to boxwood. The CRT's prompt and waveform are drawn over the same screen artwork, leaving its casing unchanged. The disk image's background (`App/DMGBackground.png`), with its ensō and seal, is drawn with [`tools/draw_dmg_background.py`](tools/draw_dmg_background.py). The app icon (`App/AppIcon.png`, and the iPhone app's in `iOS/Plinth/Assets.xcassets`) is the ink fish's idle artwork on the same rice paper, drawn with [`tools/draw_app_icon.py`](tools/draw_app_icon.py). - **Knock sounds** are synthesized by the app as each knock is made (`Sources/PlinthCore/KnockSynth.swift`), not recorded. That synthesis is part of the MIT code. - **Zen quotes** in `Sources/PlinthCore/Zen.swift` are quoted in the original Chinese from texts in the public domain: the Diamond Sutra, the Vimalakirti Sutra, the Platform Sutra, the Chan records (《景德传灯录》, 《碧岩录》, 《无门关》, 《五灯会元》), the Imperial Edition of Baizhang's Pure Rules, and poems by Wang Wei and Li Ao. The disk image's 「放下着」 is Zhaozhou's, from the same Chan records. Each line was checked against its source, the Buddhist texts against the [CBETA](https://cbetaonline.dila.edu.tw/) canon. diff --git a/README.md b/README.md index 94f79b7..64f6a08 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ English · [简体中文](README.zh-Hans.md) · [plinth.fish](https://plinth.fis A small wooden fish that lives on your Mac's desktop. Click it and it goes *tok*, nothing more. Knocking earns no merit (功德). -![Under 「并无功德」 ("No merit at all"), Plinth's twenty-one built-in skins, each on its pedestal with its mallet raised: an ink-wash fish, the neon wooden fish, a cartoon fish, a jade fish, a pixel-art fish, a red lacquer fish, a singing bowl, a space key, a bamboo block, a moss stone, a piston, a CRT terminal, an abacus, a cloud gong, a blue-and-white porcelain fish, a bianzhong bell, a seal, a stone chime, a fish board, a mug, and an old temple fish](docs/skins.png) +![Under 「并无功德」 ("No merit at all"), Plinth's fifteen built-in skins, each on its pedestal with its mallet raised: an ink-wash fish, the neon wooden fish, a cartoon fish, a jade fish, a pixel-art fish, a red lacquer fish, a singing bowl, a bamboo block, a moss stone, a cloud gong, a blue-and-white porcelain fish, a bianzhong bell, a stone chime, a fish board, and an old temple fish](docs/skins.png) The wooden fish (*muyu*) is a hollow temple block that Buddhist monks strike to keep time while chanting. Baizhang's monastic rules say why it is a fish: 「鱼昼夜常醒,刻木象形击之,所以警昏惰也。」 The fish is awake day and night, so wood is carved in its shape and struck, to rouse the drowsy and the slack. Plinth puts one, brushed in ink, on a small pedestal next to your windows. @@ -46,17 +46,17 @@ Your own skins go too; copy them out first if you want to keep them. ## The Fish -Click the fish to knock, and drag it to move it. Right-click the fish, or click its icon in the menu bar, for the menu and **Settings…**. The menu bar icon wears the same skin as the fish. +Click the fish to knock, and drag it to move it. Right-click the fish, or click its icon in the menu bar, for the menu and **Settings…**. The menu holds only what the fish can be asked to do: knock, knock on its own, light incense. How it knocks, where it sits, and what it wears are in Settings. The menu bar icon wears the same skin as the fish. - **A living knock.** Each knock is synthesized as the mallet falls. No two are alike: a firmer press lands harder and brighter, a knock off the top sounds more of the shell, and the wood and the hall follow the hour and the season. The 4 a.m. morning board has a shorter, clearer contact; late at night the shell's highs and the attack soften, with a little more of the low hollow body. The longer the silence before a knock, the longer it rings. After a long quiet, a knock by hand rests the mallet on the wood briefly, then lifts it slowly (压槌), leaving the sound to fade. It sounds from where the fish sits across your displays, in a **Space** you choose in Settings, from a meditation room to a great hall; on headphones you can hear where. A run of knocks rings on together. On a Force Touch trackpad, you feel the mallet land. -- **Auto-Knock.** Knocks on its own every 0.4 to 8 seconds—including **With the breath · every 6 s**, **Slow · every 2 s**, **Moderate · every 1 s**, and **Fast · every 0.5 s** in the menu—in the **Rhythm** you pick: **Steady**, **Quickening**, or **Natural** (each gap a little long or short, like a hand keeping time). **Quickening** (起板) has fifteen knocks: three slow, firm knocks, then an accelerating, progressively lighter roll; half a beat's pause before the firm fifteenth knock, a held mallet, and a rest before the next round. It can stop after 108 knocks, one turn of a mala: the last three knocks slow down (煞板) and the 108th rings out in full, with the mallet resting on the wood before rising slowly into silence. An hour after the screens go to sleep, auto-knock rests too, so the Mac can sleep. -- **Light Incense.** Choose **Half a stick · 25 minutes**, **One stick · 45 minutes**, or **Long incense · 60 minutes**. These are approximate incense periods, not exact timers: each stick's burning time varies naturally by up to ±2%, chosen once when lit. A stick stands in an ash bowl beside the fish. Lighting it sounds one full knock with a held mallet (止静); typed knocks keep quiet for three breaths, about 15 seconds. Auto-knock rests throughout the sitting and the three closing knocks (开静), keeping its setting and its place in the round, and resumes once the call is over and the spent stick has gone. No clock, no count. **Put Out the Incense** ends it early without a signal and lets auto-knock resume if it was enabled. -- **Knock as You Type.** Optional. Each key you press, in any app, knocks once. As keys hurry together, the knocks gradually grow softer and warmer, with less force and fewer sharp highs; a pause lets them open again and ring longer. Plinth only asks macOS how long ago a key last went down—the same counter that idle timers use—and never learns which key, so it needs no Accessibility or Input Monitoring permission. +- **Auto-Knock.** Knocks on its own at the **Pace** you set in Settings, from a knock every 0.4 seconds to one every 8; toward the tortoise, at one knock to each breath out, it keeps time with your own breath. Settings shows no seconds: the fish is knocking as you set it, and the ear sets the pace. It knocks in the **Rhythm** you pick: **Steady**, **Quickening**, or **Natural** (each gap a little long or short, like a hand keeping time). **Quickening** (起板) has fifteen knocks: three slow, firm knocks, then an accelerating, progressively lighter roll; half a beat's pause before the firm fifteenth knock, a held mallet, and a rest before the next round. It can stop after 108 knocks, one turn of a mala: the last three knocks slow down (煞板) and the 108th rings out in full, with the mallet resting on the wood before rising slowly into silence. An hour after the screens go to sleep, auto-knock rests too, so the Mac can sleep. +- **Light Incense.** Choose **Half a stick**, **One stick**, or **Long incense**: about 25, 45, and 60 minutes. These are approximate incense periods, not exact timers, and the menu names no minutes: each stick's burning time varies naturally by up to ±2%, chosen once when lit. A stick stands in an ash bowl beside the fish. Lighting it sounds one full knock with a held mallet (止静); typed knocks keep quiet for three breaths, about 15 seconds. Auto-knock rests throughout the sitting and the three closing knocks (开静), keeping its setting and its place in the round, and resumes once the call is over and the spent stick has gone. No clock, no count. **Put Out the Incense** ends it early without a signal and lets auto-knock resume if it was enabled. +- **Knock as You Type.** Optional, in Settings. Each key you press, in any app, knocks once. As keys hurry together, the knocks gradually grow softer and warmer, with less force and fewer sharp highs; a pause lets them open again and ring longer. Plinth only asks macOS how long ago a key last went down—the same counter that idle timers use—and never learns which key, so it needs no Accessibility or Input Monitoring permission. - **Knock after long typing.** Optional, in Settings. After half an hour of typing with no three-minute rest, the fish falls quiet for three seconds, knocks once with a held mallet, and lets it ring as the mallet rises slowly. Typed knocks and auto-knock stay quiet for three more breaths, about 15 seconds. Nothing is counted or kept. - **Mallet key.** Optional, in Settings. Map a key on a one-key keypad, a foot pedal, or a Stream Deck button to the mallet: press it in any app and it knocks by hand, without moving the mouse or needing any permission. An F-key can be the mallet alone; any other key needs two modifiers, one of them ⌘ or ⌃, so everyday shortcuts such as ⌘C and ⌃C keep working. - **Quiet in calls.** While another app listens to a microphone, typed knocks, auto-knocks, the incense, and knocks from scripts and Shortcuts still swing the mallet but make no sound; only a knock by hand sounds. Plinth asks macOS which apps are reading a microphone and never opens one itself, so this needs no microphone permission. On by default (macOS 14.2 or later). -- **A few words.** On the first knock by hand each day (a temple's day, beginning at 4 a.m.), the fish has a few things to say in the original Chinese, from Bodhidharma's *no merit* to Vimalakirti's silence, and says each of them once. The seventh is from Sengcan's *Xinxin Ming*: 「至道无难,唯嫌拣择。但莫憎爱,洞然明白。」 "The supreme Way is not difficult; it only shuns picking and choosing. Just do not hate or love, and it is wide open and clear." The fourteenth first shows Manjusri's question about entering nonduality; the question and its source then fade, leaving the empty bubble for a moment before it too disappears. Silence is not written out. After that, it only knocks. In Settings, **Why a Fish** sets Baizhang's line on why the block is a fish as an ink-wash hanging scroll; click the painted fish there and it knocks too. -- **Placement.** Plinth has no Dock icon. The fish comes in three sizes, Small, Medium, or Large (150, 210, or 300 points). Keep it **Above windows**, rest it **On the desktop**, or choose **Heard, not seen**: the fish leaves the screen and its knock blends more into the surrounding hall, with less direct sound from a single point. Your chosen **Space** stays the same. The menu bar icon stays, and it keeps its words until it is seen again. +- **A few words.** On the first knock by hand each day (a temple's day, beginning at 4 a.m.), the fish has a few things to say in the original Chinese, from Bodhidharma's *no merit* to Vimalakirti's silence, and says each of them once, on a slip of rice paper under the fish, in the ink and the Song face of the scroll in Settings. The seventh is from Sengcan's *Xinxin Ming*: 「至道无难,唯嫌拣择。但莫憎爱,洞然明白。」 "The supreme Way is not difficult; it only shuns picking and choosing. Just do not hate or love, and it is wide open and clear." The fourteenth first shows Manjusri's question about entering nonduality; the question and its source then fade, leaving the slip empty for a moment before it too disappears. Silence is not written out. After that, it only knocks. In Settings, **Why a Fish** sets Baizhang's line on why the block is a fish as an ink-wash hanging scroll; click the painted fish there and it knocks too. +- **Placement.** Plinth has no Dock icon. Size and placement are in Settings. The fish comes in three sizes, Small, Medium, or Large (150, 210, or 300 points). Keep it **Above windows**, rest it **On the desktop**, or choose **Heard, not seen**: the fish leaves the screen and its knock blends more into the surrounding hall, with less direct sound from a single point. Your chosen **Space** stays the same. The menu bar icon stays, and it keeps its words until it is seen again. When Dongshan came to see that the insentient preach the Dharma, he wrote: 「也大奇!也大奇!无情说法不思议,若将耳听终难会,眼处闻声方得知。」 "How marvelous! How marvelous! The insentient preach the Dharma, past all thinking. Listen with the ears and you will never get it; hear the sound with the eyes, and you will know." *Heard, not seen* leaves the fish to the ears alone. @@ -68,7 +68,7 @@ Scripts and other apps can knock too. `open -g plinth://knock` knocks once (`-g` make test; open -g plinth://call ``` -A call is three knocks, as when a stick of incense goes out: the first gentle, the second even, the third firm, holding the mallet on the wood before lifting it slowly. The last gap opens half a beat longer than the first. Auto-knock and typed knocks keep quiet for it, and the three come after a short quiet, so you hear them over whatever the fish was doing. A knock by hand ends a call early, and so does a key or a click anywhere once its first knock has sounded: you are back. If Plinth isn't running, either URL opens it, and the fish knocks once it is on screen. +A call is three knocks, as when a stick of incense goes out: the first gentle, the second even, the third firm, and it leaves the mallet lying on the wood. The last gap opens half a beat longer than the first. Auto-knock and typed knocks keep quiet for it, and the three come after a short quiet, so you hear them over whatever the fish was doing. A knock by hand ends a call early, and so does a key or a click anywhere once its first knock has sounded: you are back, and the mallet lifts. A call no one answers leaves the mallet where it lay, on the fish and on its icon in the menu bar, so that you can see it called when you come back; the next knock, whoever makes it, lifts it. Nothing is counted: after three calls it lies as it does after one. In a meeting the call makes no sound, though the mallet still falls three times; then a key or a click is no answer, since there was nothing to hear, and the mallet waits on the wood for you to look. If Plinth isn't running, either URL opens it, and the fish knocks once it is on screen. In the *Gateless Gate*, Master Ruiyan called to himself every day, 「主人公」 ("Master!"), and answered himself, 「诺」 ("Yes?"). Then: "Wide awake! Yes. Some other day, don't let anyone fool you! Yes, yes." The fish only calls; answering is up to you. @@ -103,7 +103,7 @@ In Shortcuts, Plinth adds a **Knock** action. Shortcuts runs it only in a signed ## Skins -Twenty-one skins ship with Plinth, each with its own mallet and synthesized voice. The fish starts in ink, as on its icon; the neon wooden fish and the rest are under **Skin** in the menu. The abacus keeps no count, the seal leaves a 空 (empty) where it lands, and the mug splashes without spilling. +Fifteen skins ship with Plinth: the fish, and what a hall is called by, each with its own mallet and synthesized voice. The fish starts in ink, as on its icon; the neon wooden fish and the rest are in **Settings → Skins**. The space key, piston, CRT terminal, abacus, seal, and mug shipped too, once, and have moved to the [community gallery](https://github.com/rubycatco/plinth-skins); a fish that was wearing one when it updated keeps it, in its own skins folder. There the abacus still keeps no count, the seal leaves a 空 (empty) where it lands, and the mug splashes without spilling. A skin of your own is a single image, or a folder with an `idle.png` and, optionally, blink and hit frames, its own mallet and burst, and a `skin.json` for its name, where the mallet lands, and which knock it makes: @@ -114,7 +114,7 @@ my-skin/ └── skin.json { "name": "My Skin", "strike": [0.6, 0.3], "voice": "jade" } ``` -Put skins in `~/Library/Application Support/Plinth/Skins/`, or use **Skin → Add Skins…**. To share a skin, send it as a `.plinthskin` file, which installs with a double-click or a drop on the fish. More skins, made by other people, are in the [community gallery](https://github.com/rubycatco/plinth-skins) (**Skin → Browse More Skins…**). Plinth picks up changes while it runs. +Put skins in `~/Library/Application Support/Plinth/Skins/`, or use **Settings → Skins → Add Skins…**. To share a skin, send it as a `.plinthskin` file, which installs with a double-click or a drop on the fish. More skins are in the [community gallery](https://github.com/rubycatco/plinth-skins) (**Settings → Skins → Browse More Skins…**). Plinth picks up changes while it runs. The [skin format](docs/SKINS.md) has the full specification: every file and key, the twenty-one knock voices, how the mallet and burst are positioned, animation timing, and the built-in skins. diff --git a/README.zh-Hans.md b/README.zh-Hans.md index 10c5915..38457d0 100644 --- a/README.zh-Hans.md +++ b/README.zh-Hans.md @@ -6,7 +6,7 @@ 一条住在 Mac 桌面上的小木鱼。点它一下,笃的一声,仅此而已,敲了也不积功德。 -![「并无功德」四字之下,Plinth 自带的二十一款皮肤,各自立在底座上,木槌悬在上方:水墨鱼、霓虹木鱼、卡通鱼、玉鱼、像素鱼、朱漆、铜磬、空格键、竹节、苔石、活塞、CRT 终端、算盘、云板、青花瓷鱼、编钟、印章、石磬、鱼板、马克杯、古木鱼](docs/skins.png) +![「并无功德」四字之下,Plinth 自带的十五款皮肤,各自立在底座上,木槌悬在上方:水墨鱼、霓虹木鱼、卡通鱼、玉鱼、像素鱼、朱漆、铜磬、竹节、苔石、云板、青花瓷鱼、编钟、石磬、鱼板、古木鱼](docs/skins.png) 寺院诵经时用木鱼打拍子。至于为什么刻成鱼的样子,《敕修百丈清规》里有一句:「鱼昼夜常醒,刻木象形击之,所以警昏惰也。」Plinth 用水墨画一条这样的木鱼,放在小小的底座上,摆在你的窗口旁边。 @@ -46,17 +46,17 @@ rm -rf /Applications/Plinth.app \ ## 木鱼 -点木鱼就是敲,拖动可以换位置。右键点木鱼,或者点菜单栏上的图标,会打开菜单与**设置…**。菜单栏图标和桌面上的木鱼用的是同一款皮肤。 +点木鱼就是敲,拖动可以换位置。右键点木鱼,或者点菜单栏上的图标,会打开菜单与**设置…**。菜单里只有木鱼能做的事:敲一下、自动敲击、点一炷香;怎么敲、摆在哪儿、穿什么,都在设置里。菜单栏图标和桌面上的木鱼用的是同一款皮肤。 - **每一声都不一样。** 敲击声在木槌落下的瞬间实时合成:按得重就敲得重、声音更亮,敲偏了听到更多外壳的声音;木头与殿堂的声响还会随晨昏与四时变化。凌晨四点早板,触壳短促清越;深夜晚板,壳面高频与起音锐度收敛,腹腔低鸣稍增,温润内敛。敲前静得越久,余音越长;久静后亲手一敲,木槌在鱼上略作停驻,再徐徐抬起(压槌),任余音自行消歇。声音从木鱼所在的屏幕方位传来,回荡的**空间**由你选,从禅房到大殿;戴耳机能听出它在哪儿。连着敲,余音会叠在一起。用压感触控板时,指尖能感到木槌落下。 -- **自动敲击。** 每 0.4 到 8 秒一下——菜单里可以直接选**随息 · 每 6 秒**、**慢 · 每 2 秒**、**中 · 每 1 秒**或**快 · 每 0.5 秒**——敲法可选**匀速**、**起板**或**随性**(像人手打拍子,间隔稍长或稍短)。**起板**十五槌一轮:起首三慢槌沉稳,入催板渐快而渐轻,密而不噪;第十五槌前微顿半拍,重落定拍、压槌稍驻,再入下一轮休止。可以选敲满 108 下就停,正好念珠一圈:最后三下渐慢收板(煞板),第 108 下压槌稍驻、缓缓归位,余音放尽,归于止静。屏幕睡下一小时后,自动敲击也会歇下,好让 Mac 睡。 -- **点一炷香。** 可选**半炷香 · 25 分钟**、**一炷香 · 45 分钟**或**长香 · 60 分钟**。这是约略的香期,不是精确计时:每炷点燃时定下一次约 ±2% 的自然浮动。香立在木鱼旁的香碗里:点香时满余音敲一下,压槌止静;打字伴敲先静三息,约 15 秒。坐香及香尽开静三声期间,自动敲击止息,保留开关和轮次,待开静结束、残香撤去再续。不显示时间,也不计数。选**熄香**可提前结束,不另敲一声;原先开启的自动敲击随即恢复。 -- **打字时跟着敲。** 可选。在任何 App 里每按一个键敲一下;急键连绵时,力度和高频渐次收敛,手下越急,声音越温润安静,停顿后再舒展开来,余音也更长。Plinth 只向 macOS 询问上一次按键是多久以前(和系统判断闲置时间用的是同一个计数),始终不知道按的是哪个键,所以不需要辅助功能或输入监控权限。 +- **自动敲击。** **节奏**在设置里调,从每 0.4 秒一下到每 8 秒一下;往乌龟那头拉,拉到一呼一敲,就可以随息。设置里不显示秒数:调的时候木鱼正敲着,快慢由耳朵定。敲法可选**匀速**、**起板**或**随性**(像人手打拍子,间隔稍长或稍短)。**起板**十五槌一轮:起首三慢槌沉稳,入催板渐快而渐轻,密而不噪;第十五槌前微顿半拍,重落定拍、压槌稍驻,再入下一轮休止。可以选敲满 108 下就停,正好念珠一圈:最后三下渐慢收板(煞板),第 108 下压槌稍驻、缓缓归位,余音放尽,归于止静。屏幕睡下一小时后,自动敲击也会歇下,好让 Mac 睡。 +- **点一炷香。** 可选**半炷香**、**一炷香**或**长香**,约 25、45、60 分钟。这是约略的香期,不是精确计时,菜单里也不写分钟:每炷点燃时定下一次约 ±2% 的自然浮动。香立在木鱼旁的香碗里:点香时满余音敲一下,压槌止静;打字伴敲先静三息,约 15 秒。坐香及香尽开静三声期间,自动敲击止息,保留开关和轮次,待开静结束、残香撤去再续。不显示时间,也不计数。选**熄香**可提前结束,不另敲一声;原先开启的自动敲击随即恢复。 +- **打字时跟着敲。** 可选,在设置里开启。在任何 App 里每按一个键敲一下;急键连绵时,力度和高频渐次收敛,手下越急,声音越温润安静,停顿后再舒展开来,余音也更长。Plinth 只向 macOS 询问上一次按键是多久以前(和系统判断闲置时间用的是同一个计数),始终不知道按的是哪个键,所以不需要辅助功能或输入监控权限。 - **打字久了,敲一下。** 可选,在设置里开启。连着打字半小时、中间没歇过三分钟,木鱼先静三秒,独敲一记警策,压槌按驻、徐徐抬起,余音放尽;打字敲击和自动敲击再静三息,约 15 秒。不计数,也不记录。 - **木槌键。** 可选,在设置里录制。把单键小键盘、脚踏开关或 Stream Deck 按键直接化作木槌:在任何 App 里按下它,就如亲手敲一下,不用移鼠标,也不需要任何权限。F 键可以单独当木槌;其他键要配两个修饰键,其中一个是 ⌘ 或 ⌃,这样 ⌘C、⌃C 这类常用快捷键照常可用。 - **开会时不出声。** 别的 App 在用麦克风时,打字敲、自动敲、点香,以及脚本和快捷指令的敲击,木槌照样落下,但没有声音;只有亲手敲才会响。Plinth 只是问 macOS 哪些 App 在读麦克风,自己从不打开麦克风,所以不需要麦克风权限。默认开启(需 macOS 14.2 或更新版本)。 -- **几句话。** 每天(按寺院早板,从凌晨四点算起)亲手敲下的第一声,木鱼有一句话要说,从达摩的「并无功德」到维摩诘的一默,每句只说一次,都用原文。第七句是僧璨《信心铭》:「至道无难,唯嫌拣择。但莫憎爱,洞然明白。」第十四句先浮现「文殊师利问:何等是菩萨入不二法门?」,片刻后问句与出处隐去,空的气泡再停一停,随即消散,不用文字解释沉默。往后就只是敲。设置的**为何是鱼**一页把《百丈清规》那句话写成一幅水墨挂轴,点一下画里的水墨鱼也会响。 -- **位置。** 不占程序坞。木鱼有小、中、大三档(150、210、300 pt),可以**浮在窗口上方**,可以**放在桌面上**,也可以选**只闻其声**:不现身,干声的单点感减弱,更多融入周匝余响,所选的**空间**不变。菜单栏图标仍在,那几句话也留到现身时再说。 +- **几句话。** 每天(按寺院早板,从凌晨四点算起)亲手敲下的第一声,木鱼有一句话要说,从达摩的「并无功德」到维摩诘的一默,每句只说一次,都用原文,写在木鱼下方一张小纸条上,纸、墨和宋体都与设置里那幅挂轴相同。第七句是僧璨《信心铭》:「至道无难,唯嫌拣择。但莫憎爱,洞然明白。」第十四句先浮现「文殊师利问:何等是菩萨入不二法门?」,片刻后问句与出处隐去,空的纸条再停一停,随即消散,不用文字解释沉默。往后就只是敲。设置的**为何是鱼**一页把《百丈清规》那句话写成一幅水墨挂轴,点一下画里的水墨鱼也会响。 +- **位置。** 不占程序坞。大小和位置都在设置里选:木鱼有小、中、大三档(150、210、300 pt),可以**浮在窗口上方**,可以**放在桌面上**,也可以选**只闻其声**:不现身,干声的单点感减弱,更多融入周匝余响,所选的**空间**不变。菜单栏图标仍在,那几句话也留到现身时再说。 洞山良价悟无情说法,述偈云:「也大奇!也大奇!无情说法不思议,若将耳听终难会,眼处闻声方得知。」选「只闻其声」,木鱼就只剩耳朵听得见的那一声。 @@ -68,7 +68,7 @@ rm -rf /Applications/Plinth.app \ make test; open -g plinth://call ``` -唤你,是敲三下,和一炷香燃尽时一样:初槌轻叩,破静而不惊定;二槌中平,摄心回神;三槌沉实,压槌稍驻,再徐徐抬起。二、三声之间比一、二声多展半拍。这时自动敲击和打字敲击都静下来,静一会儿再敲这三下,所以不管木鱼刚才在做什么,你都听得出来。亲手敲一下,唤声就停了;第一声响过之后,随手按个键、点一下鼠标,也算应了「诺」,余下的唤声便不再敲。Plinth 没在运行时,这两个 URL 都会把它打开,木鱼出现后再敲。 +唤你,是敲三下,和一炷香燃尽时一样:初槌轻叩,破静而不惊定;二槌中平,摄心回神;三槌沉实,落下便压在鱼上,不抬。二、三声之间比一、二声多展半拍。这时自动敲击和打字敲击都静下来,静一会儿再敲这三下,所以不管木鱼刚才在做什么,你都听得出来。亲手敲一下,唤声就停了;第一声响过之后,随手按个键、点一下鼠标,也算应了「诺」,余下的唤声便不再敲,木槌徐徐抬起。没人应,木槌就一直压在鱼上,菜单栏的图标也是这个姿态,你回来一眼便知它唤过;等下一声敲击,不论是谁敲的,木槌才从鱼上抬起。不计数:唤过三回和唤过一回,看起来一样。开会时唤声不出声,木槌照样落三下;这时按键和点击不算应,没听见的唤声无从应起,木槌就压着,等你会后来看。Plinth 没在运行时,这两个 URL 都会把它打开,木鱼出现后再敲。 《无门关》里,瑞岩彦和尚每日自唤「主人公」,复自应「诺」,乃云:「惺惺着!喏。他时异日,莫受人瞒!喏喏。」木鱼唤的那一声,应不应在你。 @@ -103,7 +103,7 @@ make test; open -g plinth://call ## 皮肤 -自带二十一款皮肤,各有自己的木槌和合成音色。默认是水墨鱼,和图标上的一样;霓虹木鱼和其余皮肤在菜单的**皮肤**里。算盘从不计数,印章落下留一个「空」字,马克杯溅起咖啡,杯里的一滴不少。 +自带十五款皮肤:鱼,和堂上敲的法器,各有自己的木槌和合成音色。默认是水墨鱼,和图标上的一样;霓虹木鱼和其余皮肤在**设置 → 皮肤**里。空格键、活塞、CRT 终端、算盘、印章和马克杯原先也是自带的,如今搬去了[社区画廊](https://github.com/rubycatco/plinth-skins);升级前正穿着其中一款的木鱼,那一款会留在它自己的皮肤文件夹里。在画廊里,算盘照旧从不计数,印章落下留一个「空」字,马克杯溅起咖啡,杯里的一滴不少。 自己的皮肤可以是单独一张图片,也可以是一个文件夹:里面有 `idle.png`,还可以放眨眼和被敲中的画面、自己的木槌和敲击效果,以及一个 `skin.json`,写上名字、木槌落在哪里、用哪种敲击声: @@ -114,7 +114,7 @@ my-skin/ └── skin.json { "name": "我的皮肤", "strike": [0.6, 0.3], "voice": "jade" } ``` -皮肤放在 `~/Library/Application Support/Plinth/Skins/`,也可以用 **皮肤 → 添加皮肤…** 添加。分享皮肤时,发一个 `.plinthskin` 文件就行:双击它,或者把它拖到木鱼上,就装好了。别人做的更多皮肤在[社区画廊](https://github.com/rubycatco/plinth-skins)里(**皮肤 → 浏览更多皮肤…**)。App 运行时,这里的改动会自动生效。完整规格见[皮肤格式](docs/SKINS.zh-Hans.md)。 +皮肤放在 `~/Library/Application Support/Plinth/Skins/`,也可以用 **设置 → 皮肤 → 添加皮肤…** 添加。分享皮肤时,发一个 `.plinthskin` 文件就行:双击它,或者把它拖到木鱼上,就装好了。更多皮肤在[社区画廊](https://github.com/rubycatco/plinth-skins)里(**设置 → 皮肤 → 浏览更多皮肤…**)。App 运行时,这里的改动会自动生效。完整规格见[皮肤格式](docs/SKINS.zh-Hans.md)。 ## 从源码构建 diff --git a/Sources/Plinth/Fish.swift b/Sources/Plinth/Fish.swift index d2ecaa6..d3bea8f 100644 --- a/Sources/Plinth/Fish.swift +++ b/Sources/Plinth/Fish.swift @@ -92,6 +92,12 @@ final class Fish { /// The mallet's latest swing; each new one swings it again. private(set) var swing = Swing() + /// The mallet lies on the wood, left there by a call no one answered, + /// until the next knock lifts it. Nothing is counted: after three calls + /// it lies as it does after one. + private(set) var malletRests = false { + didSet { if malletRests != oldValue { drawMenuIcon() } } + } /// A swing by hand still in the air, until the mallet lands. @ObservationIgnored private var handSwing: (serial: Int, task: Task)? /// A typed key's short swing still in the air, cancelled if a knock by hand @@ -115,10 +121,12 @@ final class Fish { private(set) var incense: Incense? @ObservationIgnored private var incenseTask: Task? /// The fish calling you back, while it sounds, and when its first knock - /// landed, from which a key or click anywhere ends the call. See `call()`. + /// landed, from which a key or click anywhere ends the call, if the call + /// could be heard. See `call()`. @ObservationIgnored private var callTask: Task? @ObservationIgnored private var callSwing: Task? @ObservationIgnored private var callLanded = Double.infinity + @ObservationIgnored private var callHeard = false /// When the last key went down, and when the stretch of typing it belongs /// to began, on a clock that keeps going while the Mac sleeps, since a /// night's sleep is a rest. Kept only for the bell, never stored. @@ -200,7 +208,9 @@ final class Fish { } } private(set) var pack = SkinOption.inkFish.pack - /// The worn skin, small enough for the menu bar. + /// The worn skin, small enough for the menu bar, and its mallet with it + /// while it lies on the wood, so a call that went unanswered shows even + /// when the fish itself is unseen, or under a window. private(set) var menuIcon = SkinOption.inkFish.pack.idle.menuBarIcon() /// The skins in `skinsDirectory`. private(set) var skins: [SkinOption] = [] @@ -253,7 +263,15 @@ final class Fish { placement = Placement(rawValue: d.string(forKey: "placement") ?? "") ?? .floating launchAtLogin = SMAppService.mainApp.status == .enabled // A skin is stored only once one is chosen; until then, the ink fish. - skin = d.string(forKey: "skin") ?? SkinOption.inkFish.id + // One that has moved to the gallery since it was chosen comes along, + // into the fish's own skins. Stored by hand: nothing is observed yet. + var worn = d.string(forKey: "skin") ?? SkinOption.inkFish.id + if let kept = SkinOption.handOver(worn, from: Bundle.main.url(forResource: "Retired", withExtension: nil), + to: Self.skinsDirectory) { + worn = kept + d.set(kept, forKey: "skin") + } + skin = worn refreshSkins() loadSkin() watchSkins() @@ -286,7 +304,8 @@ final class Fish { /// to 1 at its right. A `preview`, to hear a setting, always sounds and is /// never answered. A `full` knock rings as fully as after a long quiet, /// however lately the fish was knocked. `closing` rests the mallet on the - /// wood at a ritual's close; `settling` softens hurried typing. + /// wood at a ritual's close; `settling` softens hurried typing. Any knock + /// lifts a mallet that a call left on the wood. func knock(byHand: Bool = true, quick: Bool = false, at x: Double? = nil, preview: Bool = false, full: Bool = false, closing: Bool = false, settling: Float = 0) { // While the fish calls you back, other knocks keep quiet, so the call @@ -298,10 +317,18 @@ final class Fish { strike(byHand: byHand, quick: quick, at: x, preview: preview, full: full, closing: closing, settling: settling) } + /// Whether a knock would be heard now: not with the volume all the way + /// down, and only one by hand, or to hear a setting, while another app + /// listens to a microphone. + private func sounds(byHand: Bool, preview: Bool = false) -> Bool { + volume > 0 && (byHand || preview || !quietWhileMicInUse || !Microphone.inUseByOthers()) + } + + /// `holds` leaves the mallet on the wood once it has landed. @discardableResult private func strike(byHand: Bool, quick: Bool = false, at x: Double? = nil, preview: Bool = false, full: Bool = false, closing: Bool = false, settling: Float = 0, - force: Float? = nil, automatic: Bool = false) -> Task { + force: Float? = nil, automatic: Bool = false, holds: Bool = false) -> Task { if byHand { quickSwing?.cancel() quickSwing = nil @@ -309,9 +336,10 @@ final class Fish { let delay = quick ? Swing.quickImpactDelay : Swing.impactDelay let silence = ProcessInfo.processInfo.systemUptime + delay - lastImpact let lingers = !quick && !preview && (closing || (byHand && (full || KnockSound.bloom(afterSilence: silence) > 0.9))) - swing = Swing(serial: swing.serial + 1, quick: quick, lingers: lingers) + swing = Swing(serial: swing.serial + 1, quick: quick, lingers: lingers, holds: holds, rises: malletRests) + malletRests = false let serial = swing.serial - let audible = volume > 0 && (byHand || preview || !quietWhileMicInUse || !Microphone.inUseByOthers()) + let audible = sounds(byHand: byHand, preview: preview) // Wake the audio while the mallet is in the air, so the first knock // after a quiet lands with the mallet rather than a moment after it. if audible { sound.warm(for: delay) } @@ -336,6 +364,8 @@ final class Fish { bloom = full ? 1 : KnockSound.bloom(afterSilence: now - lastImpact) lastImpact = now impacts += 1 + // Unless another swing has begun since, this one's mallet stays down. + if holds && swing.serial == serial { malletRests = true } if audible { sound.play(samples, volume: Float(volume), bloom: Float(bloom), unseen: placement == .unseen) } @@ -390,6 +420,14 @@ final class Fish { swing = Swing(serial: swing.serial + 1, calledOff: true) } + /// Lift a mallet that a call left on the wood, or is about to, without a + /// knock: you are here. + private func liftMallet() { + guard swing.holds else { return } + swing = Swing(serial: swing.serial + 1, calledOff: true, rises: malletRests) + malletRests = false + } + /// One knock to hear a setting just changed: the volume, the room, or a skin. func preview() { if spaceChange != nil { @@ -401,10 +439,11 @@ final class Fish { /// Knock the ink fish painted on the About scroll: always the ink voice, /// heard through paper, whatever the fish on the desktop wears, and that - /// fish's mallet stays still. Like a preview, it always sounds, and a call - /// ends: you are here. + /// fish's mallet stays still, unless a call left it on the wood. Like a + /// preview, it always sounds, and a call ends: you are here. func knockPainting() { endCall() + liftMallet() guard volume > 0 else { return } sound.warm(for: 0) let knock = sound.synthesize(force: 0.58 + .random(in: -0.07...0.07), place: .random(in: -0.2...0.2), voice: "ink") @@ -584,13 +623,17 @@ final class Fish { private func loadSkin() { pack = (allSkins.first { $0.id == skin } ?? SkinOption.inkFish).pack - menuIcon = pack.idle.menuBarIcon() + drawMenuIcon() sound.use(voice: pack.voice, space: Float(space)) skinFileWatcher?.cancel() let isOwn = skins.contains { $0.id == skin } skinFileWatcher = isOwn ? watch(Self.skinsDirectory.appending(path: skin), [.write, .extend, .delete, .rename]) : nil } + private func drawMenuIcon() { + menuIcon = malletRests ? pack.menuBarIcon(malletDown: true) : pack.idle.menuBarIcon() + } + func show(_ quote: Quote, for seconds: Double = 8) { noticeTask?.cancel() notice = Notice(quote: quote) @@ -650,6 +693,7 @@ final class Fish { incenseTask = nil incense = nil endCall() + liftMallet() restartAuto() } @@ -660,29 +704,45 @@ final class Fish { /// while one sounds is the same call. Like auto-knock, it is never answered. /// Once the first knock has sounded, a key or a click anywhere means you /// are back, and the rest of the call keeps quiet. One from before it, - /// such as the key that started a build, doesn't count. + /// such as the key that started a build, doesn't count. Nor does any, if + /// the call can't be heard, as while a microphone is in use: a key + /// pressed in a meeting is no answer to a call that made no sound. + /// + /// The last knock leaves the mallet on the wood. A call no one answers + /// leaves it there, for whoever comes back to see, until the next knock + /// of any kind lifts it; answered by a key or a click, it lifts at once. func call() { guard callTask == nil else { return } pauseAccompaniment() callLanded = .infinity + callHeard = false callTask = Task { [weak self] in for (index, stroke) in Self.callStrokes.enumerated() { try? await Task.sleep(for: .seconds(stroke.gap)) guard let self, !Task.isCancelled else { return } - let answered = max(TypingWatcher.lastEvent(.keyDown), TypingWatcher.lastEvent(.leftMouseDown)) - if answered > callLanded { return endCall() } - callSwing = strike(byHand: false, full: true, closing: index == 2, force: stroke.force) + if answeredFromAfar() { return endCall() } + let last = index == Self.callStrokes.count - 1 + callSwing = strike(byHand: false, full: true, closing: last, force: stroke.force, holds: last) if callLanded == .infinity { callLanded = ProcessInfo.processInfo.systemUptime + Swing.impactDelay + // Heard or not is settled once, as the first knock is made. + callHeard = sounds(byHand: false) } } try? await Task.sleep(for: .seconds(Self.callRest)) guard let self, !Task.isCancelled else { return } + if answeredFromAfar() { liftMallet() } endCall() } } - /// End a call before its last knock: you are here. + /// Whether a key or a click anywhere has answered the call: one since its + /// first knock landed, if that knock could be heard. + private func answeredFromAfar() -> Bool { + callHeard && max(TypingWatcher.lastEvent(.keyDown), TypingWatcher.lastEvent(.leftMouseDown)) > callLanded + } + + /// End a call, answered or run its length. The mallet is left as it is. private func endCall() { guard let callTask else { return } callTask.cancel() @@ -690,6 +750,7 @@ final class Fish { callSwing?.cancel() callSwing = nil callLanded = .infinity + callHeard = false restartAuto() } @@ -705,8 +766,9 @@ final class Fish { // back. When it went down, not when the watcher noticed: for the bell // alone it looks only about once a second, and a key from before the // knock may be noticed after it. - if callTask != nil, TypingWatcher.lastEvent(.keyDown) > callLanded { + if callTask != nil, callHeard, TypingWatcher.lastEvent(.keyDown) > callLanded { endCall() + liftMallet() } let now = Double(clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)) / 1e9 let settling = knockAsYouType ? typingCadence.press(after: now - lastTyped) : 0 diff --git a/Sources/Plinth/FishView.swift b/Sources/Plinth/FishView.swift index 93b00f1..a31adb1 100644 --- a/Sources/Plinth/FishView.swift +++ b/Sources/Plinth/FishView.swift @@ -87,36 +87,48 @@ struct FishView: View { @ViewBuilder private var caption: some View { if let notice = fish.notice { QuoteView(quote: notice.quote) - // Both the question and its source fade; the bubble keeps + // Both the question and its source fade; the slip keeps // their space, but VoiceOver has no hidden words to read. .opacity(notice.silent ? 0 : 1) .accessibilityHidden(notice.silent) - .bubble() + .slip() } } } +/// The fish's line, in the ink and the Song face of the scroll in Settings > +/// Why a Fish, which is also the face the iPhone writes it in. struct QuoteView: View { let quote: Quote var body: some View { VStack(spacing: 3) { Text(quote.text) - .font(.system(size: 12, design: .serif)) + .font(.custom("Songti SC", size: 13)) + .foregroundStyle(Paper.ink.opacity(0.88)) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) Text("— \(quote.source)") - .font(.system(size: 10, design: .serif)) - .foregroundStyle(.secondary) + .font(.custom("Songti SC", size: 10)) + .foregroundStyle(Paper.ink.opacity(0.5)) } } } +/// The rice paper and ink the fish's words are written in, here and on the +/// scroll. Paper stays paper in Dark Mode too; ink needs a light ground. +enum Paper { + static let paper = Color(red: 0.953, green: 0.933, blue: 0.890) + static let ink = Color(red: 0.16, green: 0.15, blue: 0.14) +} + private extension View { - func bubble() -> some View { + /// A slip of the scroll's paper under the fish, with the words on it. + func slip() -> some View { padding(.horizontal, 10) .padding(.vertical, 5) - .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 9)) + .background(Paper.paper, in: RoundedRectangle(cornerRadius: 3)) + .overlay(RoundedRectangle(cornerRadius: 3).strokeBorder(Paper.ink.opacity(0.08), lineWidth: 0.5)) // Rises a little into place as it appears, and sinks as it goes. .transition(.opacity.combined(with: .offset(y: 4)).combined(with: .scale(scale: 0.97, anchor: .top))) } @@ -131,66 +143,18 @@ struct MenuBarIcon: View { } } -/// The skins that ship with the app, then any in the skins folder, each -/// beside a small picture of itself. Choosing one knocks once in its voice. -struct SkinPicker: View { - @Environment(Fish.self) private var fish - - var body: some View { - let wear = Binding(get: { fish.skin }, set: { fish.skin = $0; fish.preview() }) - Picker("Skin", selection: wear) { - ForEach(SkinOption.builtIn) { item($0) } - if !fish.skins.isEmpty { - Divider() - ForEach(fish.skins) { item($0) } - } - } - .pickerStyle(.inline) - // The menu it sits in already says Skin. - .labelsHidden() - } - - private func item(_ option: SkinOption) -> some View { - Label { - Text(option.title) - } icon: { - Image(nsImage: option.pack.idle.thumbnail(side: 16)) - } - .labelStyle(.titleAndIcon) - .tag(option.id) - } -} - -/// Shared by the menu bar item and the fish's right-click menu. +/// Shared by the menu bar item and the fish's right-click menu. It holds +/// what the fish can be asked to do; how it knocks, where it sits and what +/// it wears are in Settings. struct FishMenu: View { @Environment(Fish.self) private var fish @Environment(\.openSettings) private var openSettings - /// The paces the menu offers; Settings can set any other. - private static let paces = [6.0, 2.0, 1.0, 0.5] - var body: some View { @Bindable var fish = fish Button("Knock") { fish.knock() } Divider() Toggle("Auto-Knock", isOn: $fish.autoKnock) - Picker("Pace", selection: $fish.interval) { - // About one breath out: a knock to each, to follow the breath by. - Text("With the breath · every 6 s").tag(6.0) - Text("Slow · every 2 s").tag(2.0) - Text("Moderate · every 1 s").tag(1.0) - Text("Fast · every 0.5 s").tag(0.5) - // A pace set in Settings, so the menu still shows what is chosen. - if !Self.paces.contains(fish.interval) { - Divider() - Text("Every \(fish.interval, specifier: "%.1f") s").tag(fish.interval) - } - } - Picker("Rhythm", selection: $fish.rhythm) { - ForEach(Rhythm.allCases) { Text($0.title).tag($0) } - } - Divider() - Toggle("Knock as You Type", isOn: $fish.knockAsYouType) if fish.incense == nil { Menu("Light Incense") { ForEach(IncenseLength.allCases) { length in @@ -201,17 +165,6 @@ struct FishMenu: View { Button("Put Out the Incense") { fish.putOutIncense() } } Divider() - Picker("Placement", selection: $fish.placement) { - ForEach(Placement.allCases) { Text($0.title).tag($0) } - } - Menu("Skin") { - SkinPicker() - Divider() - Button("Add Skins…") { fish.addSkins() } - Button("Open Skins Folder") { NSWorkspace.shared.open(Fish.skinsDirectory) } - Button("Browse More Skins…") { NSWorkspace.shared.open(Fish.moreSkins) } - } - Divider() let updates = Updates.shared if updates.available { Button(updates.waiting ? "Update Available…" : "Check for Updates…") { updates.check() } diff --git a/Sources/Plinth/MalletKey.swift b/Sources/Plinth/MalletKey.swift index 1a22c70..f47d556 100644 --- a/Sources/Plinth/MalletKey.swift +++ b/Sources/Plinth/MalletKey.swift @@ -17,7 +17,7 @@ struct MalletKey: Equatable { kVK_F16: 16, kVK_F17: 17, kVK_F18: 18, kVK_F19: 19, kVK_F20: 20, ] private static let named: [Int: String] = [ - kVK_Space: String(localized: "Space"), kVK_Return: "↩", kVK_Tab: "⇥", kVK_Delete: "⌫", kVK_ForwardDelete: "⌦", + kVK_Space: String(localized: "Space (key)", defaultValue: "Space"), kVK_Return: "↩", kVK_Tab: "⇥", kVK_Delete: "⌫", kVK_ForwardDelete: "⌦", kVK_LeftArrow: "←", kVK_RightArrow: "→", kVK_UpArrow: "↑", kVK_DownArrow: "↓", kVK_Home: "↖", kVK_End: "↘", kVK_PageUp: "⇞", kVK_PageDown: "⇟", kVK_Escape: "⎋", kVK_ANSI_KeypadEnter: "⌤", diff --git a/Sources/Plinth/SettingsView.swift b/Sources/Plinth/SettingsView.swift index 424f81c..40c9e9b 100644 --- a/Sources/Plinth/SettingsView.swift +++ b/Sources/Plinth/SettingsView.swift @@ -62,23 +62,19 @@ private struct KnockingSettings: View { Toggle("Knock on its own", isOn: $fish.autoKnock.animation(.snappy)) // Only what applies: the pace and rhythm appear once it knocks. if fish.autoKnock { - LabeledContent("Every") { - HStack { - // Even steps in proportion, not in seconds: from 0.4 s to 0.8 s - // is as far as from 4 s to 8 s, a slow breath. Tenths of a second. - Slider(value: Binding(get: { log(fish.interval) }, set: { - let seconds = (exp($0) * 10).rounded() / 10 - if seconds != fish.interval { fish.interval = seconds } - }), in: log(0.4)...log(8)) { - EmptyView() - } minimumValueLabel: { - Image(systemName: "hare").foregroundStyle(.secondary) - } maximumValueLabel: { - Image(systemName: "tortoise").foregroundStyle(.secondary) - } - Text("\(fish.interval, specifier: "%.1f") s") - .monospacedDigit() - .frame(width: 44, alignment: .trailing) + LabeledContent("Pace") { + // Even steps in proportion, not in seconds: from 0.4 s to 0.8 s + // is as far as from 4 s to 8 s, a slow breath. Tenths of a second. + // No seconds are shown: the fish is knocking, and the ear sets the pace. + Slider(value: Binding(get: { log(fish.interval) }, set: { + let seconds = (exp($0) * 10).rounded() / 10 + if seconds != fish.interval { fish.interval = seconds } + }), in: log(0.4)...log(8)) { + EmptyView() + } minimumValueLabel: { + Image(systemName: "hare").foregroundStyle(.secondary) + } maximumValueLabel: { + Image(systemName: "tortoise").foregroundStyle(.secondary) } } Picker("Rhythm", selection: $fish.rhythm) { @@ -103,18 +99,9 @@ private struct KnockingSettings: View { } header: { Text("While You Work") } footer: { - VStack(alignment: .leading, spacing: 6) { - Text("Each key you press, in any app, knocks once. Plinth never learns which key, and needs no permission.") - .settingsFootnote() - Text("After half an hour of typing with no three-minute rest, the fish falls quiet for three seconds, then knocks once with a held mallet. Typed knocks and auto-knock stay quiet for three breaths, about 15 seconds. Nothing is counted or kept.") - .settingsFootnote() - if Microphone.canTell { - Text("While another app listens to a microphone, as in a call, only a knock by hand sounds. Plinth never listens itself.") - .settingsFootnote() - } - Text("A key, a foot pedal or a Stream Deck button can be the mallet: press it in any app and the fish is knocked by hand. An F-key can stand alone; any other key needs two modifiers, one of them ⌘ or ⌃, so ⌘C, ⌃C and the like keep working.") - .settingsFootnote() - } + // What the fish does is in its README. Here, only what it never does. + Text("Plinth never learns which key you press, never listens to a microphone itself, and needs no permission.") + .settingsFootnote() } Section("The Fish") { Picker("Size", selection: $fish.size) { @@ -153,6 +140,8 @@ private struct MalletKeyField: View { Text("Record Key") } } + // The rule a refused key broke, for whoever wonders at the beep. + .help("An F-key can stand alone. Any other key needs two modifiers, one of them ⌘ or ⌃.") if fish.malletKey != nil && monitor == nil { Button { _ = fish.useMalletKey(nil) @@ -318,8 +307,8 @@ private enum VolumeEnd { /// that explains it written top to bottom, right to left, with its source /// and a seal. It stays paper in Dark Mode too; ink needs a light ground. private struct AboutSettings: View { - static let paper = Color(red: 0.953, green: 0.933, blue: 0.890) - static let ink = Color(red: 0.16, green: 0.15, blue: 0.14) + static let paper = Paper.paper + static let ink = Paper.ink static let cinnabar = Color(red: 0.70, green: 0.20, blue: 0.15) @Environment(Fish.self) private var fish diff --git a/Sources/Plinth/Sprites.swift b/Sources/Plinth/Sprites.swift index 1fbb928..4b2f2c9 100644 --- a/Sources/Plinth/Sprites.swift +++ b/Sources/Plinth/Sprites.swift @@ -23,6 +23,37 @@ extension NSImage { } } +extension SkinPack { + /// The figure with its mallet lying on it, as `SpriteFish` draws a mallet + /// a call left on the wood, small enough for the menu bar. The two share + /// the icon's square, so the figure is a little smaller than it is alone. + func menuBarIcon(malletDown: Bool, side: CGFloat = 18) -> NSImage { + guard malletDown, let figure = idle.cgImage(forProposedRect: nil, context: nil, hints: nil), + let stick = (mallet ?? Sprite.mallet).cgImage(forProposedRect: nil, context: nil, hints: nil) else { + return idle.menuBarIcon(side: side) + } + // One frame, and room past its right edge for the mallet's grip. + let frame = CGFloat(figure.width), size = frame * Sprite.malletSize + guard let ctx = CGContext(data: nil, width: Int(frame * 1.25), height: Int(frame), bitsPerComponent: 8, bytesPerRow: 0, + space: CGColorSpaceCreateDeviceRGB(), + bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { + return idle.menuBarIcon(side: side) + } + ctx.interpolationQuality = .high + ctx.draw(figure, in: CGRect(x: 0, y: 0, width: frame, height: frame)) + // The grip, from the frame's lower left: up and to the right of the + // strike point, with the head on it. + let reach = (Sprite.malletGrip.x - Sprite.malletHead.x) * size + let a = Sprite.strikeDegrees * .pi / 180 + let grip = CGPoint(x: strike.x * frame + reach * cos(a), y: (1 - strike.y) * frame + reach * sin(a)) + ctx.translateBy(x: grip.x, y: grip.y) + ctx.rotate(by: a) + ctx.draw(stick, in: CGRect(x: -Sprite.malletGrip.x * size, y: -(1 - Sprite.malletGrip.y) * size, width: size, height: size)) + guard let both = ctx.makeImage() else { return idle.menuBarIcon(side: side) } + return NSImage(cgImage: both, size: .zero).menuBarIcon(side: side) + } +} + extension NSImage { private static var thumbnailsKey: UInt8 = 0 diff --git a/Sources/PlinthCore/Ritual.swift b/Sources/PlinthCore/Ritual.swift index 876c7d1..9ed20f3 100644 --- a/Sources/PlinthCore/Ritual.swift +++ b/Sources/PlinthCore/Ritual.swift @@ -57,16 +57,18 @@ public enum IncenseLength: Int, CaseIterable, Identifiable { public var id: Self { self } public var title: String { switch self { - case .half: String(localized: "Half a stick · 25 minutes") - case .one: String(localized: "One stick · 45 minutes") - case .long: String(localized: "Long incense · 60 minutes") + case .half: String(localized: "Half a stick") + case .one: String(localized: "One stick") + case .long: String(localized: "Long incense") } } } /// One swing of the mallet. `quick` is the short swing for a typed key; /// `calledOff` takes a swing still in the air back up without landing; -/// `lingers` rests on the wood before lifting slowly (压槌). +/// `lingers` rests on the wood before lifting slowly (压槌). One that `holds` +/// lands and stays on the wood, as after a call no one answered, and the +/// swing after it `rises` from there. public struct Swing: Equatable { /// Time from the start of the swing until the mallet meets the wood, and /// how much of it the small lift before the swing takes. @@ -79,12 +81,17 @@ public struct Swing: Equatable { public var quick = false public var calledOff = false public var lingers = false + public var holds = false + public var rises = false - public init(serial: Int = 0, quick: Bool = false, calledOff: Bool = false, lingers: Bool = false) { + public init(serial: Int = 0, quick: Bool = false, calledOff: Bool = false, lingers: Bool = false, + holds: Bool = false, rises: Bool = false) { self.serial = serial self.quick = quick self.calledOff = calledOff self.lingers = lingers + self.holds = holds + self.rises = rises } /// How hard the mallet lands when nothing tells how firmly the hand diff --git a/Sources/PlinthCore/Skin.swift b/Sources/PlinthCore/Skin.swift index 98a53ec..923577d 100644 --- a/Sources/PlinthCore/Skin.swift +++ b/Sources/PlinthCore/Skin.swift @@ -51,8 +51,11 @@ public struct Skin { } /// The skin at `url`, decoding each frame with `image`, which gives nil - /// for a file that is missing or isn't an image. - public static func load(_ url: URL?, image: (URL) -> Image?) -> Skin? { + /// for a file that is missing or isn't an image. Its name is the one + /// `skin.json` gives for `language`, the one the app is showing, if it + /// gives one. + public static func load(_ url: URL?, language: String? = Bundle.main.preferredLocalizations.first, + image: (URL) -> Image?) -> Skin? { guard let url else { return nil } if let single = image(url) { return Skin(idle: single) } func frame(_ name: String) -> Image? { image(url.appending(path: "\(name).png")) } @@ -68,7 +71,7 @@ public struct Skin { mallet: frame("mallet"), impact: frame("impact")) if let data = try? Data(contentsOf: url.appending(path: "skin.json")), let meta = try? JSONDecoder().decode(SkinMeta.self, from: data) { - skin.name = meta.name + skin.name = language.flatMap { meta.names?[$0] } ?? meta.name skin.voice = meta.voice if let s = meta.strike, s.count == 2 { skin.strike = CGPoint(x: s[0], y: s[1]) } skin.glow = meta.glow.flatMap(SkinGlow.init(hex:)) @@ -81,6 +84,8 @@ public struct Skin { /// What `skin.json` may say. private struct SkinMeta: Decodable { var name: String? + /// The name in other languages, keyed as an app's localizations are: "zh-Hans". + var names: [String: String]? var strike: [Double]? var voice: String? var glow: String? diff --git a/Sources/PlinthCore/Sprites.swift b/Sources/PlinthCore/Sprites.swift index f10e019..d84d82d 100644 --- a/Sources/PlinthCore/Sprites.swift +++ b/Sources/PlinthCore/Sprites.swift @@ -70,6 +70,26 @@ public struct SkinOption: Identifiable { private static func title(_ folder: String, _ english: String) -> String { Bundle.main.localizedString(forKey: folder, value: english, table: "Skins") } + + /// A skin that once shipped with the app and has since moved to the + /// gallery stays with a fish that wears it. If `id` is such a skin, one + /// kept in `retired`, it is copied into `skins`, the fish's own skins + /// folder, unless one of its name is there already, and its id there is + /// returned. Nil for any other skin, and nothing is copied. + public static func handOver(_ id: String, from retired: URL?, to skins: URL) -> String? { + let prefix = "builtin/" + guard let retired, id.hasPrefix(prefix) else { return nil } + let name = String(id.dropFirst(prefix.count)) + // A folder of this name, directly in `retired`: an id is not a path. + guard !name.isEmpty, !name.contains("/"), !name.hasPrefix(".") else { return nil } + let kept = retired.appending(path: name) + guard FileManager.default.fileExists(atPath: kept.appending(path: "idle.png").path) else { return nil } + let own = skins.appending(path: name) + if !FileManager.default.fileExists(atPath: own.path) { + guard (try? FileManager.default.copyItem(at: kept, to: own)) != nil else { return nil } + } + return name + } } extension CGImage { @@ -96,16 +116,16 @@ extension CGImage { } /// Shared sprites, and where the mallet's head and grip sit in its image. -enum Sprite { - static let mallet = load("mallet") +public enum Sprite { + public static let mallet = load("mallet") static let impact = load("impact") - static let malletHead = UnitPoint(x: 0.169, y: 0.505) - static let malletGrip = UnitPoint(x: 0.964, y: 0.505) + public static let malletHead = UnitPoint(x: 0.169, y: 0.505) + public static let malletGrip = UnitPoint(x: 0.964, y: 0.505) /// Mallet image size as a fraction of the frame. - static let malletSize = 0.6 + public static let malletSize = 0.6 /// At impact the handle rises this far above horizontal toward the grip; /// at rest the mallet is lifted the skin's `raise` further around the grip. - static let strikeDegrees = 15.0 + public static let strikeDegrees = 15.0 private static func load(_ name: String) -> SkinImage { Bundle.main.url(forResource: name, withExtension: "png").flatMap(picture) ?? SkinImage() @@ -198,24 +218,37 @@ public struct SpriteFish: View { let quick = swing.quick // With Reduce Motion the mallet settles back without bouncing. let rebound: Spring = reduceMotion ? .smooth : .bouncy + // A mallet left on the wood lifts only partway before it swings again. + let top = swing.rises ? hit + pack.raise * 0.6 : rest + 7 return Image(sprite: pack.mallet ?? Sprite.mallet) .resizable() .frame(width: size, height: size) - .keyframeAnimator(initialValue: rest, trigger: swing) { content, angle in + // A track that ends stays where it ended, and the next starts from + // the value given here: from the wood, after a swing that held. + .keyframeAnimator(initialValue: swing.rises ? hit : rest, trigger: swing) { content, angle in content.rotationEffect(.degrees(angle), anchor: Sprite.malletGrip) } keyframes: { _ in KeyframeTrack { if swing.calledOff { - // Pulled back mid-swing: up to rest, without a sound. - SpringKeyframe(rest, duration: 0.35, spring: .smooth) + if swing.rises { + // Lifted off the wood it was left on, as slowly as 压槌 lifts. + LinearKeyframe(rest, duration: 0.85, timingCurve: .easeInOut) + } else { + // Pulled back mid-swing: up to rest, without a sound. + SpringKeyframe(rest, duration: 0.35, spring: .smooth) + } } else { // A small lift that eases to a stop, the swing that // gathers speed into the wood, then the rebound. - LinearKeyframe(quick ? hit : rest + 7, duration: quick ? Swing.quickImpactDelay / 2 : Swing.liftDuration, + LinearKeyframe(quick ? hit : top, duration: quick ? Swing.quickImpactDelay / 2 : Swing.liftDuration, timingCurve: .easeOut) LinearKeyframe(hit, duration: quick ? Swing.quickImpactDelay / 2 : Swing.impactDelay - Swing.liftDuration, timingCurve: .easeIn) - if swing.lingers { + if swing.holds { + // Left on the wood: nothing moves, and nothing + // runs, until the next swing lifts it. + LinearKeyframe(hit, duration: 0.01) + } else if swing.lingers { // 压槌: rest on the wood, then lift without a bounce. // A new swing can interrupt this quiet at any time. LinearKeyframe(hit, duration: 0.42) diff --git a/Sources/PlinthCore/Zen.swift b/Sources/PlinthCore/Zen.swift index b6551a8..a931887 100644 --- a/Sources/PlinthCore/Zen.swift +++ b/Sources/PlinthCore/Zen.swift @@ -4,7 +4,7 @@ public struct Quote: Identifiable, Equatable { public let id = UUID() public let text: String public let source: String - /// The words leave an empty bubble before it, too, goes away. + /// The words leave the slip they were on empty before it, too, goes away. public var leavesSilence = false public init(text: String, source: String, leavesSilence: Bool = false) { diff --git a/Tests/PlinthTests/CallTests.swift b/Tests/PlinthTests/CallTests.swift new file mode 100644 index 0000000..2c67e63 --- /dev/null +++ b/Tests/PlinthTests/CallTests.swift @@ -0,0 +1,43 @@ +import XCTest +@testable import Plinth +import PlinthCore + +final class CallTests: XCTestCase { + /// A call no one answers leaves the mallet on the wood, and the next + /// knock of any kind lifts it. Silent, so no key or click answers it. + @MainActor + func testACallNoOneAnswersLeavesTheMalletOnTheWood() async throws { + _ = NSApplication.shared + let fish = Fish.shared + let saved = (fish.volume, fish.autoKnock, fish.knockAsYouType, fish.bell) + fish.volume = 0 + fish.autoKnock = false + fish.knockAsYouType = false + fish.bell = false + defer { (fish.volume, fish.autoKnock, fish.knockAsYouType, fish.bell) = saved } + + fish.call() + let knocks = Fish.callStrokes.reduce(0) { $0 + $1.gap } + // Between the second knock and the third, the mallet is up. + try await Task.sleep(for: .seconds(knocks - 1)) + XCTAssertFalse(fish.malletRests) + XCTAssertFalse(fish.swing.holds) + try await Task.sleep(for: .seconds(1 + Swing.impactDelay + 0.3)) + XCTAssertTrue(fish.malletRests, "The call's last knock leaves the mallet on the wood") + // Once the call is over it is still there. + try await Task.sleep(for: .seconds(Fish.callRest + 0.3)) + XCTAssertTrue(fish.malletRests, "A call no one answered leaves it there") + + // A knock that isn't by hand lifts it too, and rises from the wood. + fish.knock(byHand: false) + XCTAssertFalse(fish.malletRests) + XCTAssertTrue(fish.swing.rises) + XCTAssertFalse(fish.swing.holds) + try await Task.sleep(for: .seconds(Swing.impactDelay + 0.2)) + XCTAssertFalse(fish.malletRests) + // And the knock after that starts from where a mallet usually hangs. + fish.knock(byHand: false) + XCTAssertFalse(fish.swing.rises) + try await Task.sleep(for: .seconds(Swing.impactDelay + 0.2)) + } +} diff --git a/Tests/PlinthTests/SkinArchiveTests.swift b/Tests/PlinthTests/SkinArchiveTests.swift index 76e3993..9eeffb8 100644 --- a/Tests/PlinthTests/SkinArchiveTests.swift +++ b/Tests/PlinthTests/SkinArchiveTests.swift @@ -15,14 +15,17 @@ final class SkinArchiveTests: XCTestCase { try? FileManager.default.removeItem(at: scratch) } - /// Every built-in skin comes back byte for byte from the archive that - /// Export as .plinthskin writes. + /// Every built-in skin, and every one that has moved to the gallery, + /// comes back byte for byte from the archive that Export as .plinthskin writes. func testUnpacksWhatExportWrites() throws { - let skins = URL(filePath: #filePath).deletingLastPathComponent().appending(path: "../../App/Resources/Skins").standardized - let names = try FileManager.default.contentsOfDirectory(atPath: skins.path).filter { !$0.hasPrefix(".") } - XCTAssertEqual(names.count, 21) - for name in names { - let skin = skins.appending(path: name) + let resources = URL(filePath: #filePath).deletingLastPathComponent().appending(path: "../../App/Resources").standardized + let skins = try ["Skins", "Retired"].flatMap { folder in + try FileManager.default.contentsOfDirectory(atPath: resources.appending(path: folder).path) + .filter { !$0.hasPrefix(".") }.map { resources.appending(path: "\(folder)/\($0)") } + } + XCTAssertEqual(skins.count, 15 + 6) + for skin in skins { + let name = skin.lastPathComponent let archive = scratch.appending(path: "\(name).plinthskin") XCTAssertTrue(SkinArchive.pack(skin, to: archive)) let folder = try SkinArchive.unpack(archive, into: scratch.appending(path: "unpacked-\(name)")) diff --git a/Tests/PlinthTests/SkinTests.swift b/Tests/PlinthTests/SkinTests.swift new file mode 100644 index 0000000..c3faf06 --- /dev/null +++ b/Tests/PlinthTests/SkinTests.swift @@ -0,0 +1,79 @@ +import Foundation +import PlinthCore +import XCTest + +final class SkinTests: XCTestCase { + private var scratch: URL! + + override func setUpWithError() throws { + scratch = FileManager.default.temporaryDirectory.appending(path: "PlinthSkinTests-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: scratch, withIntermediateDirectories: true) + } + + override func tearDownWithError() throws { + try FileManager.default.removeItem(at: scratch) + } + + /// A folder with an idle.png (not a real image; nothing here decodes it) and a skin.json. + private func folder(_ path: String, json: String = "{}", marker: String = "idle") throws -> URL { + let url = scratch.appending(path: path) + try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true) + try Data(marker.utf8).write(to: url.appending(path: "idle.png")) + try Data(json.utf8).write(to: url.appending(path: "skin.json")) + return url + } + + /// Frames that "decode" to their file's name, if the file is there. + private func frame(_ url: URL) -> String? { + var isFolder: ObjCBool = false + guard FileManager.default.fileExists(atPath: url.path, isDirectory: &isFolder), !isFolder.boolValue else { return nil } + return url.lastPathComponent + } + + func testASkinIsNamedInTheLanguageShown() throws { + let mug = try folder("mug", json: #"{ "name": "Mug", "names": { "zh-Hans": "马克杯" }, "voice": "ceramic" }"#) + XCTAssertEqual(Skin.load(mug, language: "zh-Hans", image: frame)?.name, "马克杯") + XCTAssertEqual(Skin.load(mug, language: "en", image: frame)?.name, "Mug") + XCTAssertEqual(Skin.load(mug, language: "fr", image: frame)?.name, "Mug") + XCTAssertEqual(Skin.load(mug, language: nil, image: frame)?.name, "Mug") + XCTAssertEqual(Skin.load(mug, language: "zh-Hans", image: frame)?.voice, "ceramic") + // Without `names`, as every skin made before it: the one name. + let plain = try folder("plain", json: #"{ "name": "Plain" }"#) + XCTAssertEqual(Skin.load(plain, language: "zh-Hans", image: frame)?.name, "Plain") + } + + func testASkinThatMovedToTheGalleryStaysWithAFishThatWearsIt() throws { + let retired = scratch.appending(path: "Retired"), skins = scratch.appending(path: "Skins") + _ = try folder("Retired/mug", json: #"{ "name": "Mug" }"#) + try FileManager.default.createDirectory(at: skins, withIntermediateDirectories: true) + + XCTAssertEqual(SkinOption.handOver("builtin/mug", from: retired, to: skins), "mug") + XCTAssertEqual(try String(contentsOf: skins.appending(path: "mug/skin.json"), encoding: .utf8), #"{ "name": "Mug" }"#) + XCTAssertTrue(FileManager.default.fileExists(atPath: skins.appending(path: "mug/idle.png").path)) + // The app's copy is left where it was. + XCTAssertTrue(FileManager.default.fileExists(atPath: retired.appending(path: "mug/idle.png").path)) + } + + func testAHandoverLeavesASkinOfTheSameNameAlone() throws { + let retired = scratch.appending(path: "Retired"), skins = scratch.appending(path: "Skins") + _ = try folder("Retired/mug") + _ = try folder("Skins/mug", marker: "theirs") + + XCTAssertEqual(SkinOption.handOver("builtin/mug", from: retired, to: skins), "mug") + XCTAssertEqual(try String(contentsOf: skins.appending(path: "mug/idle.png"), encoding: .utf8), "theirs") + } + + func testOnlyASkinThatMovedIsHandedOver() throws { + let retired = scratch.appending(path: "Retired"), skins = scratch.appending(path: "Skins") + _ = try folder("Retired/mug") + _ = try folder("Elsewhere/secret") + try FileManager.default.createDirectory(at: skins, withIntermediateDirectories: true) + + // The wooden fish, a skin that still ships, one of the fish's own, and ids that aren't a folder's name. + for id in ["", "builtin/ink-fish", "mug", "mug.png", "builtin/", "builtin/../Elsewhere/secret", "builtin/.", "builtin/mug/idle.png"] { + XCTAssertNil(SkinOption.handOver(id, from: retired, to: skins), id) + } + XCTAssertNil(SkinOption.handOver("builtin/mug", from: nil, to: skins)) + XCTAssertEqual(try FileManager.default.contentsOfDirectory(atPath: skins.path), []) + } +} diff --git a/docs/SKINS.md b/docs/SKINS.md index 4d2cb5b..6544c00 100644 --- a/docs/SKINS.md +++ b/docs/SKINS.md @@ -12,9 +12,9 @@ Plinth reads your skins from: ~/Library/Application Support/Plinth/Skins/ ``` -Plinth creates the folder on first launch. **Skin → Open Skins Folder** opens it, and **Skin → Add Skins…** copies images, folders or `.plinthskin` files into it. Dropping one on the fish, or opening a `.plinthskin` file, does the same. Copying replaces any skin of the same name that is already there. +Plinth creates the folder on first launch. **Settings → Skins → Open Skins Folder** opens it, and **Add Skins…** beside it copies images, folders or `.plinthskin` files into it. Dropping one on the fish, or opening a `.plinthskin` file, does the same. Copying replaces any skin of the same name that is already there. -Each entry in the folder is one skin, either a single image or a folder. Plinth lists them after the twenty-one built-in skins, sorted by file name. Entries it can't read, such as a folder without `idle.png` or a stray `.DS_Store`, are skipped without a message. +Each entry in the folder is one skin, either a single image or a folder. Plinth lists them after the fifteen built-in skins, sorted by file name. Entries it can't read, such as a folder without `idle.png` or a stray `.DS_Store`, are skipped without a message. A skin's identity is its file or folder name. Plinth remembers the skin you wear by that name, so renaming a skin you're wearing switches you back to the ink fish. @@ -34,7 +34,7 @@ Finder's **Compress** works too; rename the `.zip` to `.plinthskin`. ## Single-image skins -Any image file macOS can open (PNG, JPEG, HEIC, TIFF, and so on) is a skin on its own. It has an idle frame only: no blink, no hit, the shared mallet and burst, the default strike point, and the wooden knock. Its name in the menus is the file name without the extension. +Any image file macOS can open (PNG, JPEG, HEIC, TIFF, and so on) is a skin on its own. It has an idle frame only: no blink, no hit, the shared mallet and burst, the default strike point, and the wooden knock. Its name in Settings is the file name without the extension. ## Folder skins @@ -76,7 +76,8 @@ Folder skins read PNG files only, by these exact lowercase names. A folder witho | Key | Type | Default | Meaning | | --- | --- | --- | --- | -| `name` | string | file name | The skin's name in the menus and in Settings. | +| `name` | string | file name | The skin's name in Settings. | +| `names` | object of strings | none | The name in other languages, keyed by language code as an app's localizations are: `{ "zh-Hans": "我的皮肤" }`. Plinth shows the one for the language it is running in, and `name` when there is none. | | `strike` | array of two numbers | `[0.6, 0.3]` | Where the centre of the mallet's head lands, as fractions of the frame's width and height, measured from the top-left corner. Keep both within 0 to 1. | | `voice` | string | `"wood"` | Which knock the skin makes. See [Voices](#voices). | | `glow` | string | none | The colour of the pedestal's neon, as `#RRGGBB`, for a skin whose base lights up. The incense censer beside the fish catches it on its near side. Leave it out when the base has no light. | @@ -137,7 +138,9 @@ Without `mallet.png`, a skin uses the shared [`App/Resources/mallet.png`](../App At the moment of impact the handle rises 15° above horizontal toward the grip. At rest, the mallet is raised a further 25°, or `raise` degrees when `skin.json` sets it. A knock from typing skips the small lift before the swing. -The mallet rests on the wood for 0.42 seconds, then lifts over 0.85 seconds without bouncing (压槌) on: the 108th auto-knock with **Stop after 108**; a rested knock by hand (more than 90% bloom); the third call knock; the fifteenth **Quickening** knock; the incense's opening knock; and the long-typing bell. Ordinary and typed knocks keep their rebound. A new knock interrupts the hold; a drag before impact still cancels the swing. This uses the same mallet and strike point, with no extra skin files or keys, and remains bounce-free with Reduce Motion. +The mallet rests on the wood for 0.42 seconds, then lifts over 0.85 seconds without bouncing (压槌) on: the 108th auto-knock with **Stop after 108**; a rested knock by hand (more than 90% bloom); the fifteenth **Quickening** knock; the incense's opening knock; and the long-typing bell. Ordinary and typed knocks keep their rebound. A new knock interrupts the hold; a drag before impact still cancels the swing. This uses the same mallet and strike point, with no extra skin files or keys, and remains bounce-free with Reduce Motion. + +The third call knock doesn't lift at all: it leaves the mallet lying on the wood. A key or a click that answers the call lifts it over the same 0.85 seconds. If no one answers, it lies there until the next knock of any kind, which lifts it only 60% of the way to rest before it swings. Meanwhile the menu bar icon shows the mallet lying on the figure, placed by the same `strike`, so the figure in it is a little smaller. A skin needs nothing more for any of this. Lighting incense hushes typed knocks for about 15 seconds and pauses auto-knock until the closing call is over and the spent stick has gone, or until the incense is put out early. A pause preserves auto-knock's enabled setting and its round; cancelled swings do not count as landings. The long-typing bell waits three quiet seconds before its held knock, followed by about 15 quiet seconds. Hand knocks and settings previews remain available. @@ -174,29 +177,25 @@ The built-in skins live in [`App/Resources/Skins`](../App/Resources/Skins), one | Folder | Name | 中文名 | Voice | Strike | Hit frame | Mallet | Burst | | --- | --- | --- | --- | --- | --- | --- | --- | | `ink-fish` | Ink Fish | 水墨鱼 | `ink` | 0.625, 0.289 | no | own | own | -| `abacus` | Abacus | 算盘 | `bead` | 0.5, 0.325 | yes | own | own | | `bamboo-block` | Bamboo Block | 竹节 | `bamboo` | 0.52, 0.485 | no | own | own | | `bianzhong` | Bianzhong | 编钟 | `bell` | 0.56, 0.66 | yes | own | own | | `cartoon-fish` | Cartoon Fish | 卡通鱼 | `cartoon` | 0.625, 0.296 | no | own | own | | `cloud-gong` | Cloud Gong | 云板 | `plate` | 0.56, 0.6 | yes | own | own | -| `crt-terminal` | CRT Terminal | CRT 终端 | `crt` | 0.52, 0.395 | yes | own | own | | `fish-board` | Fish Board | 鱼板 | `board` | 0.56, 0.69 | no | own | shared | | `jade-fish` | Jade Fish | 玉鱼 | `jade` | 0.625, 0.304 | no | own | own | | `moss-stone` | Moss Stone | 苔石 | `stone` | 0.52, 0.375 | no | own | own | -| `mug` | Mug | 马克杯 | `ceramic` | 0.56, 0.36 | no | own | own | -| `piston` | Piston | 活塞 | `piston` | 0.52, 0.39 | yes | own | own | | `pixel-fish` | Pixel Fish | 像素鱼 | `pixel` | 0.625, 0.326 | no | own | own | | `porcelain-fish` | Porcelain Fish | 青花瓷鱼 | `porcelain` | 0.625, 0.31 | no | own | own | | `red-lacquer` | Red Lacquer | 朱漆 | `lacquer` | 0.625, 0.306 | no | own | own | -| `seal` | Seal | 印章 | `stamp` | 0.55, 0.39 | no | own | own | | `singing-bowl` | Singing Bowl | 铜磬 | `bowl` | 0.625, 0.39 | no | own | own | -| `space-key` | Space Key | 空格键 | `key` | 0.52, 0.515 | yes | own | own | | `stone-chime` | Stone Chime | 石磬 | `chime` | 0.52, 0.65 | yes | own | own | | `temple-fish` | Temple Fish | 古木鱼 | `temple` | 0.58, 0.298 | no | own | own | | `wooden-fish` | Wooden Fish | 木鱼 | `wood` | 0.625, 0.316 | no | shared | shared | None of the built-in skins has blink frames. To add a built-in skin, add its folder here and its Chinese name to `Skins.strings`. If its art is new, credit it in [CREDITS.md](../CREDITS.md). +Six skins that once shipped with Plinth (Abacus, CRT Terminal, Mug, Piston, Seal and Space Key) are now in the [community gallery](https://github.com/rubycatco/plinth-skins). The app still carries them, in [`App/Resources/Retired`](../App/Resources/Retired), only so that a fish wearing one when it updates keeps it: on launch, Plinth copies that one skin into the skins folder, unless a skin of its name is already there, and wears it from there. Their Chinese names are in their `skin.json`, under `names`. + ## Checklist - [ ] `idle.png` exists, is square, and has a transparent background. diff --git a/docs/SKINS.zh-Hans.md b/docs/SKINS.zh-Hans.md index 6d655aa..6dd1862 100644 --- a/docs/SKINS.zh-Hans.md +++ b/docs/SKINS.zh-Hans.md @@ -12,9 +12,9 @@ Plinth 从这里读取你的皮肤: ~/Library/Application Support/Plinth/Skins/ ``` -第一次启动时 Plinth 会创建这个文件夹。菜单 **皮肤 → 打开皮肤文件夹** 可以打开它,**皮肤 → 添加皮肤…** 会把选中的图片、文件夹或 `.plinthskin` 文件复制进去,把它们拖到木鱼上、或者打开 `.plinthskin` 文件也一样,遇到同名的皮肤会直接替换。 +第一次启动时 Plinth 会创建这个文件夹。**设置 → 皮肤 → 打开皮肤文件夹** 可以打开它,旁边的 **添加皮肤…** 会把选中的图片、文件夹或 `.plinthskin` 文件复制进去,把它们拖到木鱼上、或者打开 `.plinthskin` 文件也一样,遇到同名的皮肤会直接替换。 -文件夹里的每一项就是一款皮肤,可以是单张图片,也可以是一个文件夹。它们按文件名排序,列在二十一款内置皮肤之后。读不了的项会被跳过,也不提示,比如没有 `idle.png` 的文件夹,或者混进来的 `.DS_Store`。 +文件夹里的每一项就是一款皮肤,可以是单张图片,也可以是一个文件夹。它们按文件名排序,列在十五款内置皮肤之后。读不了的项会被跳过,也不提示,比如没有 `idle.png` 的文件夹,或者混进来的 `.DS_Store`。 皮肤靠文件名或文件夹名识别。Plinth 按这个名字记住你正在用的皮肤,所以给正在用的皮肤改名,木鱼会换回默认的水墨鱼。 @@ -34,7 +34,7 @@ ditto -c -k --keepParent my-skin my-skin.plinthskin ## 单张图片皮肤 -macOS 能打开的图片(PNG、JPEG、HEIC、TIFF 等)单独放进来就是一款皮肤。它只有静止画面:没有眨眼和被敲中的画面,用共用的木槌和敲击效果、默认落点和木鱼的敲击声。菜单里显示的名字是去掉扩展名的文件名。 +macOS 能打开的图片(PNG、JPEG、HEIC、TIFF 等)单独放进来就是一款皮肤。它只有静止画面:没有眨眼和被敲中的画面,用共用的木槌和敲击效果、默认落点和木鱼的敲击声。设置里显示的名字是去掉扩展名的文件名。 ## 文件夹皮肤 @@ -76,7 +76,8 @@ my-skin/ | 键 | 类型 | 默认值 | 含义 | | --- | --- | --- | --- | -| `name` | 字符串 | 文件名 | 菜单和设置里显示的皮肤名字。 | +| `name` | 字符串 | 文件名 | 设置里显示的皮肤名字。 | +| `names` | 字符串组成的对象 | 无 | 其他语言里的名字,以语言代码为键,和 App 的本地化写法相同:`{ "zh-Hans": "我的皮肤" }`。Plinth 显示当前界面语言对应的那一个,没有就用 `name`。 | | `strike` | 两个数字组成的数组 | `[0.6, 0.3]` | 槌头中心落在哪里,用画面宽和高的比例表示,从左上角算起。两个值都应在 0 到 1 之间。 | | `voice` | 字符串 | `"wood"` | 这款皮肤的敲击声,见[敲击声](#敲击声)。 | | `glow` | 字符串 | 无 | 底座霓虹灯的颜色,写成 `#RRGGBB`,给底座会发光的皮肤用。木鱼旁的香炉靠近底座的一侧会映上这道光。底座不发光就不要写。 | @@ -137,7 +138,9 @@ Plinth 不带任何声音文件。换上皮肤时,它按 `voice` 指定的音 落下的那一刻,槌柄朝握柄一侧比水平高 15°;静止时再抬高 25°;`skin.json` 写了 `raise` 时,按它的度数抬。打字触发的敲击没有挥下前的那一下小抬。 -以下敲击会在落点压槌 0.42 秒,再用 0.85 秒徐徐抬起,不回弹:开启「敲满 108 下就停」时的第 108 下、久静后亲手的一敲(余音展开超过 90%)、开静第三声、起板第十五槌、点香止静一声,以及久打字后的警策一击。普通敲击和打字敲击仍照常回弹。新的一敲会打断停驻;落槌前拖动仍会取消敲击。沿用原来的木槌和落点,不需要增加皮肤文件或键,开启「减弱动态效果」时也不会弹跳。 +以下敲击会在落点压槌 0.42 秒,再用 0.85 秒徐徐抬起,不回弹:开启「敲满 108 下就停」时的第 108 下、久静后亲手的一敲(余音展开超过 90%)、起板第十五槌、点香止静一声,以及久打字后的警策一击。普通敲击和打字敲击仍照常回弹。新的一敲会打断停驻;落槌前拖动仍会取消敲击。沿用原来的木槌和落点,不需要增加皮肤文件或键,开启「减弱动态效果」时也不会弹跳。 + +开静第三声落下后不抬,木槌就压在鱼上。有人按键或点击应了,木槌同样用 0.85 秒徐徐抬起。没人应,它一直压着,直到下一声敲击,不论是谁敲的:那一挥只抬到静止高度的 60% 便落下。这期间菜单栏图标也画出压在物体上的木槌,位置同样按 `strike` 算,所以图标里的物体会略小一些。这些都不需要皮肤另加文件或键。 点香后打字伴敲先静约 15 秒;自动敲击则暂停至香尽开静结束、残香撤去,或提前熄香。暂停保留自动敲击的开关与轮次;落槌前取消的一挥不计作敲击。久打字后的警策先静三秒,压槌一击后再静约 15 秒。亲手敲击与设置试听仍然可用。 @@ -174,29 +177,25 @@ Plinth 会监视皮肤文件夹。添加、删除或重命名皮肤,大约半 | 文件夹 | 英文名 | 中文名 | 音色 | 落点 | 被敲中画面 | 木槌 | 敲击效果 | | --- | --- | --- | --- | --- | --- | --- | --- | | `ink-fish` | Ink Fish | 水墨鱼 | `ink` | 0.625, 0.289 | 无 | 自带 | 自带 | -| `abacus` | Abacus | 算盘 | `bead` | 0.5, 0.325 | 有 | 自带 | 自带 | | `bamboo-block` | Bamboo Block | 竹节 | `bamboo` | 0.52, 0.485 | 无 | 自带 | 自带 | | `bianzhong` | Bianzhong | 编钟 | `bell` | 0.56, 0.66 | 有 | 自带 | 自带 | | `cartoon-fish` | Cartoon Fish | 卡通鱼 | `cartoon` | 0.625, 0.296 | 无 | 自带 | 自带 | | `cloud-gong` | Cloud Gong | 云板 | `plate` | 0.56, 0.6 | 有 | 自带 | 自带 | -| `crt-terminal` | CRT Terminal | CRT 终端 | `crt` | 0.52, 0.395 | 有 | 自带 | 自带 | | `fish-board` | Fish Board | 鱼板 | `board` | 0.56, 0.69 | 无 | 自带 | 共用 | | `jade-fish` | Jade Fish | 玉鱼 | `jade` | 0.625, 0.304 | 无 | 自带 | 自带 | | `moss-stone` | Moss Stone | 苔石 | `stone` | 0.52, 0.375 | 无 | 自带 | 自带 | -| `mug` | Mug | 马克杯 | `ceramic` | 0.56, 0.36 | 无 | 自带 | 自带 | -| `piston` | Piston | 活塞 | `piston` | 0.52, 0.39 | 有 | 自带 | 自带 | | `pixel-fish` | Pixel Fish | 像素鱼 | `pixel` | 0.625, 0.326 | 无 | 自带 | 自带 | | `porcelain-fish` | Porcelain Fish | 青花瓷鱼 | `porcelain` | 0.625, 0.31 | 无 | 自带 | 自带 | | `red-lacquer` | Red Lacquer | 朱漆 | `lacquer` | 0.625, 0.306 | 无 | 自带 | 自带 | -| `seal` | Seal | 印章 | `stamp` | 0.55, 0.39 | 无 | 自带 | 自带 | | `singing-bowl` | Singing Bowl | 铜磬 | `bowl` | 0.625, 0.39 | 无 | 自带 | 自带 | -| `space-key` | Space Key | 空格键 | `key` | 0.52, 0.515 | 有 | 自带 | 自带 | | `stone-chime` | Stone Chime | 石磬 | `chime` | 0.52, 0.65 | 有 | 自带 | 自带 | | `temple-fish` | Temple Fish | 古木鱼 | `temple` | 0.58, 0.298 | 无 | 自带 | 自带 | | `wooden-fish` | Wooden Fish | 木鱼 | `wood` | 0.625, 0.316 | 无 | 共用 | 共用 | 内置皮肤都没有眨眼画面。要新增一款内置皮肤,把它的文件夹放进上面的目录,再把中文名加进 `Skins.strings`。如果用了新的美术素材,在 [CREDITS.md](../CREDITS.md) 里注明。 +算盘、CRT 终端、马克杯、活塞、印章和空格键这六款原先也是内置的,现在在[社区画廊](https://github.com/rubycatco/plinth-skins)里。App 里还留着它们,放在 [`App/Resources/Retired`](../App/Resources/Retired),格式相同,只为一件事:升级时正穿着其中一款的木鱼不必换掉。启动时,Plinth 把那一款复制进皮肤文件夹(已有同名皮肤就不复制),之后从那里读取。它们的中文名写在各自 `skin.json` 的 `names` 里。 + ## 检查清单 - [ ] 有 `idle.png`,正方形,背景透明。 diff --git a/docs/skins.png b/docs/skins.png index 7ca8cef..a4b92a6 100644 Binary files a/docs/skins.png and b/docs/skins.png differ diff --git a/tools/draw_skin_impacts.py b/tools/draw_skin_impacts.py index 8dec390..9a0c204 100644 --- a/tools/draw_skin_impacts.py +++ b/tools/draw_skin_impacts.py @@ -9,6 +9,9 @@ The images are original and released under CC0 (the code itself is MIT). Usage: python draw_skin_impacts.py + +Draws those of its skins that are in the directory: App/Resources/Skins for +the ones that ship, App/Resources/Retired for the ones now in the gallery. """ import sys from pathlib import Path @@ -33,6 +36,8 @@ ("stone-chime", (206, 238, 224)), ("temple-fish", (236, 200, 140)), ]: + if not (Path(sys.argv[1]) / name).is_dir(): + continue if name in ("space-key", "abacus"): # A rounded square, flattened to sit on the top of the keycap. r = (dx ** 4 + (dy / 0.60) ** 4) ** 0.25 diff --git a/tools/draw_skins_sheet.py b/tools/draw_skins_sheet.py index 67e26bc..9ad9c9e 100644 --- a/tools/draw_skins_sheet.py +++ b/tools/draw_skins_sheet.py @@ -1,4 +1,5 @@ -"""Draw docs/skins.png, the README's picture of every built-in skin. +"""Draw docs/skins.png, the README's picture of every built-in skin: those of +the show-off video's cast that still ship with the app. Bodhidharma's answer from the show-off video, 并无功德, sits above the skins, each resting on its pedestal with its mallet raised and its name below. The skins are drawn @@ -14,7 +15,8 @@ import showoff_video as v W, COLS, CELL, TOP, BOTTOM = 1800, 5, 360, 300, 40 -ROWS = -(-v.N // COLS) +BUILT_IN = [k for k in range(v.N) if v.SHIPS[k]] +ROWS = -(-len(BUILT_IN) // COLS) H = TOP + ROWS * CELL + BOTTOM SIDE = 250 @@ -57,9 +59,9 @@ def sheet(): d = ImageDraw.Draw(img) centered(d, (W / 2, 125), "并无功德", v.font("serifb", 84), (240, 234, 222)) centered(d, (W / 2, 218), "“No merit at all.” — Bodhidharma, to Emperor Wu", v.font("serif", 26), (150, 146, 140)) - for k in range(v.N): - r, c = divmod(k, COLS) - row = min(COLS, v.N - r * COLS) # a short last row is centred + for i, k in enumerate(BUILT_IN): + r, c = divmod(i, COLS) + row = min(COLS, len(BUILT_IN) - r * COLS) # a short last row is centred left = (W - row * CELL) // 2 + c * CELL img.alpha_composite(cell(k), (left, TOP + r * CELL)) mask = Image.new("L", (W, H)) diff --git a/tools/showoff_video.py b/tools/showoff_video.py index e85972c..80e9556 100644 --- a/tools/showoff_video.py +++ b/tools/showoff_video.py @@ -1,11 +1,14 @@ -"""Render Plinth's show-off video: every built-in skin knocked in turn, then all -twenty-one played as a drum kit. +"""Render Plinth's show-off video: every skin knocked in turn, then all +twenty-one played as a drum kit. Its cast is the skins that shipped with +Plinth when it was made; six have since moved to the gallery, and are drawn +from App/Resources/Retired. Frames are drawn with PIL from the skins' own sprites, with the mallet swing, give and burst timed like Sprites.swift. The soundtrack is the skins' real knocks, synthesized by knock_synth.py, a numpy port of KnockSynth.swift. -Needs numpy, scipy, pillow, ffmpeg and the Noto Serif/Sans CJK fonts. +Needs numpy, scipy, pillow, ffmpeg and the Noto Serif/Sans CJK fonts (the +.ttc files, in /usr/share/fonts/opentype/noto or the folder PLINTH_FONTS names). Usage: python showoff_video.py [--vertical] python showoff_video.py [--vertical] --stills ... @@ -74,8 +77,10 @@ def load(path): HIT = -15.0 # the mallet's angle as it lands PACKS = [] -for name, folder, zh, voice, col, cap in SKINS: - d = f"{RES}/Skins/{folder}" +# Whether each skin still ships with the app, or has moved to the gallery. +SHIPS = [(RES / "Skins" / folder).is_dir() for _, folder, *_ in SKINS] +for (name, folder, zh, voice, col, cap), ships in zip(SKINS, SHIPS): + d = f"{RES}/{'Skins' if ships else 'Retired'}/{folder}" meta = json.load(open(f"{d}/skin.json")) PACKS.append(dict(idle=load(f"{d}/idle.png"), hit=load(f"{d}/hit.png"), mallet=load(f"{d}/mallet.png") or load(f"{RES}/mallet.png"), @@ -83,7 +88,7 @@ def load(path): screen=load(f"{d}/impact.png") is None, strike=meta["strike"], rest=HIT + meta.get("raise", 25))) -FONT = "/usr/share/fonts/opentype/noto/" +FONT = os.environ.get("PLINTH_FONTS", "/usr/share/fonts/opentype/noto").rstrip("/") + "/" @lru_cache(None) def font(kind, size): f = {"serif": "NotoSerifCJK-Regular.ttc", "serifb": "NotoSerifCJK-Bold.ttc",