diff --git a/plugins/registry.json b/plugins/registry.json index 7f918c38..c539433d 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -1561,6 +1561,41 @@ "desktopWidget" ], "lastUpdated": "2026-11-24" + }, + { + "id": "ryoku-navbar-pets", + "name": "Navbar Pets", + "version": "0.1.0", + "path": "plugins/ryoku-navbar-pets", + "author": "Manish <159711477+mannish01@users.noreply.github.com>", + "upstream": "https://github.com/mannish01/Ryoku-Navbar-Pets", + "summary": "Original pixel-art pets for the Ryoku bar and desktop: eight species, five skies, treats, ball play and head pats.", + "description": "A native Ryoku companion scene with two hosts: a tiny pixel pet in the bar and a matching desktop tile. Eight original 16x16 species, five QML-painted scenic skies, treat chasing with happy particles, a bouncing ball, head pats, adjustable companions and sprite size, and a calm reduced-motion mode. No network, no external commands, no file writes; only settings are persisted through the host API.", + "tags": [ + "pets", + "pixel-art", + "companion", + "bar-widget", + "desktop-widget", + "fun" + ], + "accent": "#c88a9b", + "surface": "#101010", + "preview": "assets/preview-widget.png", + "screenshots": [ + "assets/preview-widget.png", + "assets/preview-panel.png" + ], + "manifest": "product-manifest.json", + "manifestSha256": "d5eff5c462e3f35c356ba96507b4b87acabf4e0478f0ab2b62e8c55cd5fc906d", + "official": false, + "tagline": "Pixel-art companions that live in your bar and on your desktop.", + "icon": "pets", + "hosts": [ + "topbarGlyph", + "desktopWidget" + ], + "lastUpdated": "2026-11-30" } ] } diff --git a/plugins/ryoku-navbar-pets/LICENSE b/plugins/ryoku-navbar-pets/LICENSE new file mode 100644 index 00000000..c1f7a261 --- /dev/null +++ b/plugins/ryoku-navbar-pets/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Manish + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/ryoku-navbar-pets/README.md b/plugins/ryoku-navbar-pets/README.md new file mode 100644 index 00000000..302e4616 --- /dev/null +++ b/plugins/ryoku-navbar-pets/README.md @@ -0,0 +1,84 @@ +# Navbar Pets for Ryoku + +An original pixel-art companion scene for the **Ryoku** bar and desktop. A tiny +pet sits in the bar; click it to open a full scene with your companions, treat +them, bounce a ball with them, change the sky, or just give them head pats. +Right-click the bar glyph for a quick pat without opening the panel. + +This is a native Ryoku plugin: it uses the shell's `Theme` tokens, the shared +panel surface, `pluginApi.saveSetting` for persistence, and the same two-host +dispatch (`topbarGlyph` + `desktopWidget`) used by Coffee and LeetCode Summary. +It is inspired by the Omarchy Navbar Pets idea, but the artwork, QML, and +simulation here are written from scratch — no upstream sprites or code are used. + +## Features + +- **Eight original species** — cat, dog, panda, fox, rat, frog, bird and dragon, + drawn as 16×16 pixel sprites with a two-frame walk cycle. Pick one species or + run the whole menagerie with `MIXED`. +- **Five scenic skies** — Dawn, Meadow, Dusk, Night and Candy, each a QML-painted + gradient with stars, layered ridges and a ground line. No image files. +- **Treats and chasing** — drop a treat and the matching pet runs toward it, + eats it, and shows a happy face and crumbs. +- **Physics play** — a bouncing ball with gravity and damped bounce; pets hop + when patted. `CALM` reduces motion and slows the simulation for quiet desks. +- **Live controls** — treat, ball on/off, pat all, cycle sky, play ball, change + species, companions (1–4) and sprite pixel size, all from the panel. +- **Two hosts, one state** — the bar glyph and the desktop tile read the same + service instance, so a treat given on the desktop is reflected in the bar. +- **Privacy by default** — no network hosts, no external commands, no file + writes, no compositor socket access. Only settings are persisted, through + the host API. + +## Files + +| file | role | +| --- | --- | +| `service/Main.qml` | headless simulation: pets, ball, treats, particles, settings | +| `content/Pets.js` | original sprite rect definitions and scenery palettes | +| `content/PetSprite.qml` | Canvas renderer for one 16×16 pet | +| `content/Scene.qml` | reusable scenic background + actors | +| `content/Widget.qml` | host dispatcher: glyph on the bar, card on the desktop | +| `content/Glyph.qml` | bar mark, mood dot, click/right-click actions | +| `content/Card.qml` | desktop tile with scene and four quick actions | +| `content/Panel.qml` | full scene panel and all controls | + +## Settings + +| key | type | default | description | +| --- | --- | --- | --- | +| `pet` | choice | `mixed` | species, or `mixed` for one of each | +| `theme` | choice | `dawn` | scenic sky palette | +| `companions` | int | `2` | number of pets, 1–4 | +| `pixelScale` | int | `2` | sprite pixel size, 1–4 | +| `ball` | toggle | `true` | bouncing ball on startup | +| `reducedMotion` | toggle | `false` | calm mode (slower, less motion) | + +Settings can be changed in the panel or under **Ryoku Settings > Add-ons > +Navbar Pets**. + +## Preview + +Desktop tile: + +![Navbar Pets desktop tile](assets/preview-widget.png) + +Bar panel: + +![Navbar Pets panel](assets/preview-panel.png) + +## Build, check, install + +``` +ryoku plugin validate . +ryoku plugin add . --bar --yes +``` + +Then enable the desktop tile under **Ryoku Settings > Add-ons** if you want the +second host. Because this is a QML-only plugin, a shell reload is enough after +changes: `ryoku reload`. + +## Author + +Manish <159711477+mannish01@users.noreply.github.com>: community-made +(`official` is false). Art and code original; MIT licensed. diff --git a/plugins/ryoku-navbar-pets/assets/preview-panel.png b/plugins/ryoku-navbar-pets/assets/preview-panel.png new file mode 100644 index 00000000..0b1e92d0 Binary files /dev/null and b/plugins/ryoku-navbar-pets/assets/preview-panel.png differ diff --git a/plugins/ryoku-navbar-pets/assets/preview-widget.png b/plugins/ryoku-navbar-pets/assets/preview-widget.png new file mode 100644 index 00000000..a41b76a8 Binary files /dev/null and b/plugins/ryoku-navbar-pets/assets/preview-widget.png differ diff --git a/plugins/ryoku-navbar-pets/content/Card.qml b/plugins/ryoku-navbar-pets/content/Card.qml new file mode 100644 index 00000000..df778447 --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/Card.qml @@ -0,0 +1,120 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import Ryoku.PluginKit.Singletons + +// Desktop host: the same scene and the four playful actions, in a small tile. +Item { + id: root + + property var pluginApi + property var screen + property bool active: false + property string density: "compact" + property real s: 1 + property real widthBudget: 320 + property bool open: false + property real reveal: 0 + property bool tabActive: false + signal requestClose() + + readonly property var service: pluginApi ? pluginApi.mainInstance : null + + onActiveChanged: if (root.service) root.service.setHostActive("desktop", root.active) + Component.onCompleted: if (root.service) root.service.setHostActive("desktop", root.active) + + implicitWidth: 320 * root.s + implicitHeight: 224 * root.s + + MouseArea { + id: hover + anchors.fill: parent + hoverEnabled: true + } + + Rectangle { + anchors.fill: parent + color: Theme.cardTop + border.color: hover.containsMouse ? Theme.accent : Theme.hair + border.width: 1 + radius: Theme.radius + } + + Row { + id: header + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 12 * root.s + spacing: 6 * root.s + Text { + anchors.verticalCenter: parent.verticalCenter + text: "NAVBAR PETS" + color: Theme.bright + font.family: Theme.display + font.pixelSize: 13 * root.s + font.bold: true + } + Text { + anchors.verticalCenter: parent.verticalCenter + text: root.service ? root.service.palette.name.toUpperCase() : "" + color: Theme.dim + font.family: Theme.mono + font.pixelSize: 9 * root.s + } + } + + Rectangle { + anchors.top: header.bottom + anchors.topMargin: 8 * root.s + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 12 * root.s + anchors.rightMargin: 12 * root.s + height: 160 * root.s + radius: Theme.radius + clip: true + Scene { + anchors.fill: parent + s: root.s + service: root.service + onSceneClicked: if (root.service) root.service.petAll() + } + } + + Row { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 12 * root.s + spacing: 6 * root.s + component TileButton: Rectangle { + id: btn + property string label: "" + implicitWidth: 62 * root.s + implicitHeight: 22 * root.s + radius: Theme.radius + color: buttonHit.containsMouse ? Qt.rgba(Theme.accent.r, Theme.accent.g, Theme.accent.b, 0.18) : "transparent" + border.color: Theme.border + border.width: 1 + Text { + anchors.centerIn: parent + text: btn.label + color: buttonHit.containsMouse ? Theme.accent : Theme.dim + font.family: Theme.mono + font.pixelSize: 9 * root.s + } + MouseArea { + id: buttonHit + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: root.service && root.service[btn.label === "TREAT" ? "giveTreat" : btn.label === "BALL" ? "toggleBall" : btn.label === "PAT" ? "petAll" : "cycleTheme"]() + } + } + TileButton { label: "TREAT" } + TileButton { label: "BALL" } + TileButton { label: "PAT" } + TileButton { label: "SKY" } + } +} diff --git a/plugins/ryoku-navbar-pets/content/Glyph.qml b/plugins/ryoku-navbar-pets/content/Glyph.qml new file mode 100644 index 00000000..95f3f15a --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/Glyph.qml @@ -0,0 +1,72 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import QtQuick.Controls +import Ryoku.PluginKit.Singletons + +// Bar host view: a tiny pixel pet that follows the chosen species and mood. +// Clicking toggles the scene panel; right-clicking sends a quick head pat. +Item { + id: root + + property var pluginApi + property var screen + property bool active: false + property string density: "glyph" + property real s: 1 + property real widthBudget: 220 + property bool open: false + property real reveal: 0 + property bool tabActive: false + signal requestClose() + + readonly property var service: pluginApi ? pluginApi.mainInstance : null + readonly property string petId: service && service.pets.length + ? service.pets[0].id : (service ? service.pet : "cat") + readonly property string mood: service && service.pets.length ? service.pets[0].mood : "calm" + + onActiveChanged: if (root.service) root.service.setHostActive("bar", root.active) + Component.onCompleted: if (root.service) root.service.setHostActive("bar", root.active) + + implicitWidth: Math.max(22 * root.s, sprite.implicitWidth + 10 * root.s) + implicitHeight: Math.max(20 * root.s, sprite.implicitHeight) + + PetSprite { + id: sprite + anchors.verticalCenter: parent.verticalCenter + pet: root.petId === "mixed" ? "cat" : root.petId + phase: 0 + mood: root.mood + pixelScale: 1 * root.s + } + + Rectangle { + anchors.right: parent.right + anchors.top: parent.top + width: 5 * root.s + height: 5 * root.s + radius: 2.5 * root.s + color: root.mood === "happy" ? "#ff8fa3" : Theme.accent + visible: !!service + } + + MouseArea { + id: hit + anchors.fill: parent + hoverEnabled: true + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: function (mouse) { + if (mouse.button === Qt.RightButton) { + if (root.service) root.service.petAll(); + return; + } + if (!root.pluginApi) return; + if (root.open) root.requestClose(); + else if (root.pluginApi.togglePanel) root.pluginApi.togglePanel(); + } + ToolTip.visible: hit.containsMouse + ToolTip.text: "Navbar Pets · click for the scene, right-click to pet" + ToolTip.delay: 450 + ToolTip.timeout: 3000 + } +} diff --git a/plugins/ryoku-navbar-pets/content/Panel.qml b/plugins/ryoku-navbar-pets/content/Panel.qml new file mode 100644 index 00000000..2461a6d6 --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/Panel.qml @@ -0,0 +1,165 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import Ryoku.PluginKit.Singletons + +// Bar panel: the pixel scene plus the whole pet/theme/play control surface. +// The host supplies pluginApi and sizes the panel to implicitHeight. +Item { + id: root + + property var pluginApi + property string density: "full" + property real s: 1 + property real widthBudget: 320 + property bool active: false + + readonly property var service: pluginApi ? pluginApi.mainInstance : null + + component Pill: Rectangle { + id: pill + property string label: "" + property bool selected: false + property bool compact: false + signal clicked() + implicitWidth: (pill.compact ? 26 : pillLabel.implicitWidth + 18) * root.s + implicitHeight: 26 * root.s + radius: Theme.radius + color: pill.selected ? Theme.accent : (hit.containsMouse ? Qt.rgba(Theme.accent.r, Theme.accent.g, Theme.accent.b, 0.18) : "transparent") + border.color: pill.selected ? Theme.accent : Theme.border + border.width: 1 + Text { + id: pillLabel + anchors.centerIn: parent + text: pill.label + color: pill.selected ? Theme.cardTop : (hit.containsMouse ? Theme.accent : Theme.dim) + font.family: Theme.mono + font.pixelSize: (pill.compact ? 11 : 10) * root.s + } + MouseArea { + id: hit + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: pill.clicked() + } + } + + implicitWidth: root.widthBudget + implicitHeight: 24 * root.s + col.implicitHeight + + Column { + id: col + x: 12 * root.s + y: 12 * root.s + width: root.width - 24 * root.s + spacing: 8 * root.s + + Row { + width: parent.width + spacing: 6 * root.s + Text { + anchors.verticalCenter: parent.verticalCenter + text: "NAVBAR PETS" + color: Theme.bright + font.family: Theme.display + font.pixelSize: 15 * root.s + font.bold: true + } + Item { width: 6 * root.s; height: 1 } + Text { + anchors.verticalCenter: parent.verticalCenter + text: root.service ? root.service.palette.name.toUpperCase() : "" + color: Theme.dim + font.family: Theme.mono + font.pixelSize: 9 * root.s + } + } + + Rectangle { + width: parent.width + height: 160 * root.s + radius: Theme.radius + clip: true + border.color: Theme.hair + border.width: 1 + Scene { + anchors.fill: parent + s: root.s + service: root.service + onSceneClicked: if (root.service) root.service.petAll() + } + } + + Text { + width: parent.width + text: root.service && root.service.lastAction + ? root.service.lastAction + : "Click the scene to pet everyone. Right-click the bar glyph for a quick pat." + color: Theme.dim + font.family: Theme.font + font.pixelSize: 10 * root.s + elide: Text.ElideRight + } + + Row { + width: parent.width + spacing: 6 * root.s + Pill { label: "TREAT"; onClicked: if (root.service) root.service.giveTreat() } + Pill { label: root.service && root.service.ball.active ? "BALL ON" : "BALL OFF" + selected: !!root.service && root.service.ball.active + onClicked: if (root.service) root.service.toggleBall() } + Pill { label: "PAT ALL"; onClicked: if (root.service) root.service.petAll() } + Pill { label: "SKY"; onClicked: if (root.service) root.service.cycleTheme() } + Pill { label: "PLAY"; onClicked: if (root.service) root.service.playBall() } + } + + Text { + text: "COMPANION" + color: Theme.dim + font.family: Theme.mono + font.pixelSize: 8 * root.s + font.letterSpacing: 1.2 + } + + Flow { + width: parent.width + spacing: 5 * root.s + Pill { label: "MIXED"; compact: false; selected: !!root.service && root.service.pet === "mixed" + onClicked: if (root.service) root.service.setPet("mixed") } + Pill { label: "Cat"; selected: !!root.service && root.service.pet === "cat"; onClicked: if (root.service) root.service.setPet("cat") } + Pill { label: "Dog"; selected: !!root.service && root.service.pet === "dog"; onClicked: if (root.service) root.service.setPet("dog") } + Pill { label: "Panda"; selected: !!root.service && root.service.pet === "panda"; onClicked: if (root.service) root.service.setPet("panda") } + Pill { label: "Fox"; selected: !!root.service && root.service.pet === "fox"; onClicked: if (root.service) root.service.setPet("fox") } + Pill { label: "Rat"; selected: !!root.service && root.service.pet === "rat"; onClicked: if (root.service) root.service.setPet("rat") } + Pill { label: "Frog"; selected: !!root.service && root.service.pet === "frog"; onClicked: if (root.service) root.service.setPet("frog") } + Pill { label: "Bird"; selected: !!root.service && root.service.pet === "bird"; onClicked: if (root.service) root.service.setPet("bird") } + Pill { label: "Dragon"; selected: !!root.service && root.service.pet === "dragon"; onClicked: if (root.service) root.service.setPet("dragon") } + } + + Row { + width: parent.width + spacing: 10 * root.s + Text { + anchors.verticalCenter: parent.verticalCenter + text: "PETS " + (root.service ? root.service.companions : 2) + color: Theme.dim + font.family: Theme.mono + font.pixelSize: 9 * root.s + } + Pill { label: "−"; compact: true; onClicked: if (root.service) root.service.setCompanions(root.service.companions - 1) } + Pill { label: "+"; compact: true; onClicked: if (root.service) root.service.setCompanions(root.service.companions + 1) } + Text { + anchors.verticalCenter: parent.verticalCenter + text: "PIXEL " + (root.service ? root.service.pixelScale : 2) + color: Theme.dim + font.family: Theme.mono + font.pixelSize: 9 * root.s + } + Pill { label: "−"; compact: true; onClicked: if (root.service) root.service.setPixelScale(root.service.pixelScale - 1) } + Pill { label: "+"; compact: true; onClicked: if (root.service) root.service.setPixelScale(root.service.pixelScale + 1) } + Pill { label: "CALM"; selected: !!root.service && root.service.reducedMotion + onClicked: if (root.service) root.service.setReducedMotion(!root.service.reducedMotion) } + } + } +} diff --git a/plugins/ryoku-navbar-pets/content/PetSprite.qml b/plugins/ryoku-navbar-pets/content/PetSprite.qml new file mode 100644 index 00000000..2b591fa4 --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/PetSprite.qml @@ -0,0 +1,41 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import "Pets.js" as Pets + +// One original 16x16 pixel pet, drawn from rect definitions in Pets.js. +// Canvas keeps a whole scene cheap: no image assets, no per-pixel rectangles. +Canvas { + id: root + property string pet: "cat" + property int phase: 0 + property real pixelScale: 2 + property string mood: "calm" + + width: 16 * root.pixelScale + height: 16 * root.pixelScale + antialiasing: false + + onPetChanged: root.requestPaint() + onPhaseChanged: root.requestPaint() + onPixelScaleChanged: root.requestPaint() + onMoodChanged: root.requestPaint() + + onPaint: { + var ctx = root.getContext("2d"); + ctx.reset(); + ctx.clearRect(0, 0, root.width, root.height); + var parts = Pets.sprite(root.pet, root.phase); + for (var i = 0; i < parts.length; i++) { + var p = parts[i]; + ctx.fillStyle = p.c; + ctx.fillRect(p.x * root.pixelScale, p.y * root.pixelScale, + p.w * root.pixelScale, p.h * root.pixelScale); + } + if (root.mood === "happy") { + ctx.fillStyle = "#ffd166"; + ctx.fillRect(11 * root.pixelScale, 2 * root.pixelScale, root.pixelScale, root.pixelScale); + ctx.fillRect(13 * root.pixelScale, 4 * root.pixelScale, root.pixelScale, root.pixelScale); + } + } +} diff --git a/plugins/ryoku-navbar-pets/content/Pets.js b/plugins/ryoku-navbar-pets/content/Pets.js new file mode 100644 index 00000000..f3da0354 --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/Pets.js @@ -0,0 +1,140 @@ +// Original pixel-art definitions for Ryoku Navbar Pets. +// Every sprite is a list of rects on a 16x16 grid; no upstream artwork is used. + +var THEMES = [ + { id: "dawn", name: "Dawn", skyTop: "#2b1f3d", skyBottom: "#c86b6b", far: "#6b405c", near: "#3d2b45", ground: "#241c2e", tint: "#f0a6a0" }, + { id: "meadow", name: "Meadow", skyTop: "#123044", skyBottom: "#3f8c8c", far: "#2c6b63", near: "#1d4a46", ground: "#14302f", tint: "#9ad7b2" }, + { id: "dusk", name: "Dusk", skyTop: "#1b1b38", skyBottom: "#70406b", far: "#49345e", near: "#2e2547", ground: "#1d1930", tint: "#c99ad6" }, + { id: "night", name: "Night", skyTop: "#0a1024", skyBottom: "#1c2c4a", far: "#1a2542", near: "#121a30", ground: "#0c1222", tint: "#9fb8ff" }, + { id: "candy", name: "Candy", skyTop: "#3a1f42", skyBottom: "#a85c8c", far: "#7a4275", near: "#502e57", ground: "#33203a", tint: "#ffb3d1" } +]; + +function theme(id) { + for (var i = 0; i < THEMES.length; i++) if (THEMES[i].id === id) return THEMES[i]; + return THEMES[0]; +} + +function rect(x, y, w, h, color) { return { x: x, y: y, w: w, h: h, c: color }; } + +// Shared quadruped builder. `kind` selects ears/tail/markings. +function quad(colors, kind, phase) { + var b = colors.body, l = colors.light, a = colors.accent, d = colors.dark; + var p = []; + // ground shadow + p.push(rect(3, 14, 10, 1, "rgba(0,0,0,0.28)")); + // tail + if (kind === "fox") { + p.push(rect(12, phase ? 5 : 7, 3, 4, l)); + p.push(rect(14, phase ? 4 : 6, 1, 2, a)); + } else if (kind === "dog") { + p.push(rect(12, phase ? 6 : 8, 3, 2, b)); + p.push(rect(14, phase ? 5 : 7, 1, 2, l)); + } else if (kind === "rat") { + p.push(rect(12, 11, 3, 1, a)); + p.push(rect(14, 10, 1, 2, a)); + } else { + p.push(rect(12, phase ? 6 : 8, 2, 2, b)); + p.push(rect(13, phase ? 4 : 6, 1, 2, l)); + } + // legs (two-frame walk cycle) + var legA = phase ? 4 : 5; + var legB = phase ? 9 : 8; + p.push(rect(legA, 12, 2, 2, b)); + p.push(rect(legB, 12, 2, 2, b)); + p.push(rect(legA, 13, 2, 1, d)); + p.push(rect(legB, 13, 2, 1, d)); + // body + belly + p.push(rect(4, 7, 8, 6, b)); + p.push(rect(5, 9, 5, 3, l)); + // head + p.push(rect(2, 4, 7, 6, b)); + // ears / markings + if (kind === "panda") { + p.push(rect(2, 2, 3, 3, d)); + p.push(rect(6, 2, 3, 3, d)); + p.push(rect(3, 5, 2, 2, d)); + p.push(rect(7, 5, 2, 2, d)); + } else if (kind === "dog") { + p.push(rect(1, 4, 2, 4, d)); + p.push(rect(8, 4, 2, 4, d)); + p.push(rect(3, 6, 1, 1, d)); + p.push(rect(7, 6, 1, 1, d)); + } else if (kind === "rat") { + p.push(rect(2, 2, 3, 3, l)); + p.push(rect(6, 2, 3, 3, l)); + p.push(rect(3, 3, 1, 1, a)); + p.push(rect(7, 3, 1, 1, a)); + p.push(rect(3, 6, 1, 1, d)); + p.push(rect(7, 6, 1, 1, d)); + } else if (kind === "frog") { + p.push(rect(2, 3, 2, 2, l)); + p.push(rect(7, 3, 2, 2, l)); + p.push(rect(3, 4, 2, 2, l)); + p.push(rect(7, 4, 2, 2, l)); + p.push(rect(2, 7, 7, 1, d)); + } else { + // cat / fox pointed ears + p.push(rect(2, 2, 2, 3, kind === "fox" ? d : l)); + p.push(rect(7, 2, 2, 3, kind === "fox" ? d : l)); + p.push(rect(3, 3, 1, 1, a)); + p.push(rect(7, 3, 1, 1, a)); + p.push(rect(3, 6, 1, 1, d)); + p.push(rect(7, 6, 1, 1, d)); + } + // face + p.push(rect(4, 7, 3, 1, a)); + p.push(rect(5, 8, 1, 1, d)); + if (kind === "panda") { + p.push(rect(3, 6, 2, 2, d)); + p.push(rect(7, 6, 2, 2, d)); + } + return p; +} + +function bird(colors, phase) { + var b = colors.body, l = colors.light, a = colors.accent, d = colors.dark; + var p = []; + p.push(rect(5, phase ? 12 : 11, 2, 2, d)); + p.push(rect(9, phase ? 11 : 12, 2, 2, d)); + p.push(rect(4, 5, 8, 8, b)); + p.push(rect(5, 7, 5, 4, l)); + p.push(rect(3, phase ? 7 : 6, 3, 5, l)); + p.push(rect(11, phase ? 6 : 7, 2, 4, l)); + p.push(rect(5, 2, 6, 5, b)); + p.push(rect(4, 4, 1, 1, d)); + p.push(rect(10, 4, 1, 1, d)); + p.push(rect(7, 5, 2, 2, a)); + return p; +} + +var SPECIES = [ + { id: "cat", name: "Cat", colors: { body: "#e09a4a", light: "#f6c982", accent: "#e8788e", dark: "#3a2a25" }, kind: "cat" }, + { id: "dog", name: "Dog", colors: { body: "#a9764f", light: "#d7b08a", accent: "#f0a3a3", dark: "#3d2b24" }, kind: "dog" }, + { id: "panda", name: "Panda", colors: { body: "#f2f0ea", light: "#ffffff", accent: "#d97b8c", dark: "#26242b" }, kind: "panda" }, + { id: "fox", name: "Fox", colors: { body: "#d9663f", light: "#f4bc86", accent: "#f2e5cf", dark: "#34251f" }, kind: "fox" }, + { id: "rat", name: "Rat", colors: { body: "#8d94a5", light: "#c8cede", accent: "#e79aa9", dark: "#2d3140" }, kind: "rat" }, + { id: "frog", name: "Frog", colors: { body: "#6dbb6a", light: "#a9df9b", accent: "#f3d36b", dark: "#233d28" }, kind: "frog" }, + { id: "bird", name: "Bird", colors: { body: "#5aa7d6", light: "#9fd4ef", accent: "#f2c14e", dark: "#243c52" }, kind: "bird" }, + { id: "dragon",name: "Dragon",colors: { body: "#9a76d6", light: "#c9aef0", accent: "#f2d36b", dark: "#2f2447" }, kind: "cat" } +]; + +function sprite(id, phase) { + for (var i = 0; i < SPECIES.length; i++) { + if (SPECIES[i].id !== id) continue; + var s = SPECIES[i]; + if (s.id === "bird") return bird(s.colors, phase); + var parts = quad(s.colors, s.kind, phase); + if (s.id === "dragon") { + parts.push(rect(2, 1, 2, 2, s.colors.accent)); + parts.push(rect(7, 1, 2, 2, s.colors.accent)); + parts.push(rect(10, 5, 3, 4, s.colors.light)); + } + return parts; + } + return quad(SPECIES[0].colors, "cat", phase); +} + +function byId(id) { + for (var i = 0; i < SPECIES.length; i++) if (SPECIES[i].id === id) return SPECIES[i]; + return SPECIES[0]; +} diff --git a/plugins/ryoku-navbar-pets/content/Scene.qml b/plugins/ryoku-navbar-pets/content/Scene.qml new file mode 100644 index 00000000..f7a8c0c8 --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/Scene.qml @@ -0,0 +1,142 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import "Pets.js" as Pets + +// The shared pixel scene. Both the bar panel and the desktop tile mount this. +Item { + id: root + property var service + property real s: 1 + property bool interactive: true + signal sceneClicked() + + readonly property var palette: root.service ? root.service.palette : Pets.theme("dawn") + readonly property int scale: root.service ? root.service.pixelScale : 2 + + implicitWidth: 320 * root.s + implicitHeight: 160 * root.s + + Canvas { + id: backdrop + anchors.fill: parent + antialiasing: false + Connections { + target: root + function onPaletteChanged() { backdrop.requestPaint() } + function onSChanged() { backdrop.requestPaint() } + } + onPaint: { + var ctx = backdrop.getContext("2d"); + var w = backdrop.width, h = backdrop.height; + var g = ctx.createLinearGradient(0, 0, 0, h); + g.addColorStop(0, root.palette.skyTop); + g.addColorStop(1, root.palette.skyBottom); + ctx.fillStyle = g; + ctx.fillRect(0, 0, w, h); + + // a few fixed stars/specks for depth + ctx.fillStyle = root.palette.tint; + ctx.globalAlpha = 0.45; + for (var i = 0; i < 18; i++) { + var sx = ((i * 71 + 13) % 310) / 320 * w; + var sy = ((i * 37 + 9) % 70) / 160 * h; + ctx.fillRect(sx, sy, Math.max(1, 1.5 * root.s), Math.max(1, 1.5 * root.s)); + } + ctx.globalAlpha = 1; + + // far ridge + ctx.fillStyle = root.palette.far; + ctx.beginPath(); + ctx.moveTo(0, h * 0.72); + ctx.lineTo(w * 0.18, h * 0.48); + ctx.lineTo(w * 0.34, h * 0.66); + ctx.lineTo(w * 0.55, h * 0.38); + ctx.lineTo(w * 0.78, h * 0.64); + ctx.lineTo(w, h * 0.46); + ctx.lineTo(w, h); + ctx.lineTo(0, h); + ctx.closePath(); + ctx.fill(); + + // near ridge + ctx.fillStyle = root.palette.near; + ctx.beginPath(); + ctx.moveTo(0, h * 0.86); + ctx.lineTo(w * 0.24, h * 0.64); + ctx.lineTo(w * 0.48, h * 0.84); + ctx.lineTo(w * 0.72, h * 0.60); + ctx.lineTo(w, h * 0.80); + ctx.lineTo(w, h); + ctx.lineTo(0, h); + ctx.closePath(); + ctx.fill(); + + ctx.fillStyle = root.palette.ground; + ctx.fillRect(0, h * 0.94, w, h * 0.06); + } + } + + // Bouncing ball. + Rectangle { + visible: !!root.service && root.service.ball.active + x: (root.service ? root.service.ball.x : 0) * root.s + y: (root.service ? root.service.ball.y : 0) * root.s + width: 12 * root.s + height: 12 * root.s + radius: 6 * root.s + color: root.palette.tint + border.color: root.palette.ground + border.width: 1 + } + + // Treats on the ground. + Repeater { + model: root.service ? root.service.treats : [] + delegate: Rectangle { + required property var modelData + x: modelData.x * root.s + y: modelData.y * root.s + width: 7 * root.s + height: 7 * root.s + radius: 1 + color: "#f2c14e" + border.color: "#7a4a24" + border.width: 1 + } + } + + // Pets. + Repeater { + model: root.service ? root.service.pets : [] + delegate: PetSprite { + required property var modelData + x: modelData.x * root.s + y: modelData.y * root.s + pet: modelData.id + phase: modelData.phase + mood: modelData.mood + pixelScale: root.scale * root.s + } + } + + // Hearts and crumbs. + Repeater { + model: root.service ? root.service.particles : [] + delegate: Text { + required property var modelData + x: modelData.x * root.s + y: modelData.y * root.s + text: modelData.kind === "heart" ? "♥" : "•" + color: modelData.kind === "heart" ? "#ff8fa3" : "#f2c14e" + font.pixelSize: 12 * root.s + opacity: Math.min(1, modelData.life / 20) + } + } + + MouseArea { + anchors.fill: parent + enabled: root.interactive + onClicked: root.sceneClicked() + } +} diff --git a/plugins/ryoku-navbar-pets/content/Widget.qml b/plugins/ryoku-navbar-pets/content/Widget.qml new file mode 100644 index 00000000..14e44132 --- /dev/null +++ b/plugins/ryoku-navbar-pets/content/Widget.qml @@ -0,0 +1,55 @@ +pragma ComponentBehavior: Bound + +import QtQuick + +// Both hosts mount this single view. The bar gets Glyph.qml at "glyph"; the +// desktop tile gets Card.qml at "compact". Both share pluginApi.mainInstance. +Item { + id: root + + // Host-set; read only, never assign. + property var pluginApi + property var screen + property bool active: false + property string density: "glyph" + property real s: 1 + property real widthBudget: 220 + property bool open: false + property real reveal: 0 + property bool tabActive: false + signal requestClose() + + readonly property bool isGlyph: density === "glyph" + readonly property var view: isGlyph ? glyphLoader.item : cardLoader.item + + implicitWidth: view ? view.implicitWidth : 20 * root.s + implicitHeight: view ? view.implicitHeight : 20 * root.s + + Loader { + id: glyphLoader + anchors.fill: parent + active: root.isGlyph + sourceComponent: Glyph { + pluginApi: root.pluginApi + active: root.active + open: root.open + onRequestClose: root.requestClose() + density: root.density + s: root.s + widthBudget: root.widthBudget + } + } + + Loader { + id: cardLoader + anchors.fill: parent + active: !root.isGlyph + sourceComponent: Card { + pluginApi: root.pluginApi + active: root.active + density: root.density + s: root.s + widthBudget: root.widthBudget + } + } +} diff --git a/plugins/ryoku-navbar-pets/manifest.json b/plugins/ryoku-navbar-pets/manifest.json new file mode 100644 index 00000000..babe4670 --- /dev/null +++ b/plugins/ryoku-navbar-pets/manifest.json @@ -0,0 +1,118 @@ +{ + "id": "ryoku-navbar-pets", + "name": "Navbar Pets", + "version": "0.1.0", + "author": "Manish <159711477+mannish01@users.noreply.github.com>", + "description": "Original pixel-art companions for the Ryoku bar and desktop: eight hand-built species, five scenic skies, treat chasing, a bouncing ball, head pats and a shared playful state.", + "license": "MIT", + "official": false, + "hosts": [ + "topbarGlyph", + "desktopWidget" + ], + "entryPoints": { + "main": "service/Main.qml", + "content": "content/Widget.qml", + "panel": "content/Panel.qml" + }, + "panel": { + "width": 320 + }, + "files": [ + "content/Pets.js", + "content/PetSprite.qml", + "content/Scene.qml", + "content/Glyph.qml", + "content/Card.qml", + "assets/preview-widget.png", + "assets/preview-panel.png" + ], + "capabilities": { + "densities": [ + "glyph", + "compact" + ] + }, + "defaults": { + "host": "topbarGlyph", + "label": "Navbar Pets", + "desktopWidget": { + "x": 1280, + "y": 120, + "scale": 1, + "locked": false + }, + "icon": "pets" + }, + "dependencies": { + "commands": [] + }, + "metadata": { + "settings": [ + { + "key": "pet", + "type": "choice", + "label": "Companion species", + "group": "Navbar Pets", + "default": "mixed", + "options": [ + { "value": "mixed", "label": "Mixed (one of each)" }, + { "value": "cat", "label": "Cat" }, + { "value": "dog", "label": "Dog" }, + { "value": "panda", "label": "Panda" }, + { "value": "fox", "label": "Fox" }, + { "value": "rat", "label": "Rat" }, + { "value": "frog", "label": "Frog" }, + { "value": "bird", "label": "Bird" }, + { "value": "dragon", "label": "Dragon" } + ] + }, + { + "key": "theme", + "type": "choice", + "label": "Scenic sky", + "group": "Navbar Pets", + "default": "dawn", + "options": [ + { "value": "dawn", "label": "Dawn" }, + { "value": "meadow", "label": "Meadow" }, + { "value": "dusk", "label": "Dusk" }, + { "value": "night", "label": "Night" }, + { "value": "candy", "label": "Candy" } + ] + }, + { + "key": "companions", + "type": "int", + "label": "Number of companions", + "group": "Navbar Pets", + "default": 2, + "min": 1, + "max": 4 + }, + { + "key": "pixelScale", + "type": "int", + "label": "Sprite pixel size", + "group": "Navbar Pets", + "default": 2, + "min": 1, + "max": 4 + }, + { + "key": "ball", + "type": "toggle", + "label": "Bouncing ball", + "group": "Navbar Pets", + "default": true + }, + { + "key": "reducedMotion", + "type": "toggle", + "label": "Calm mode (reduced motion)", + "group": "Navbar Pets", + "default": false + } + ] + } +} diff --git a/plugins/ryoku-navbar-pets/product-manifest.json b/plugins/ryoku-navbar-pets/product-manifest.json new file mode 100644 index 00000000..a9b5fd0b --- /dev/null +++ b/plugins/ryoku-navbar-pets/product-manifest.json @@ -0,0 +1,113 @@ +{ + "schema": 1, + "id": "ryoku-navbar-pets", + "category": "plugins", + "version": "0.1.0", + "destination": "ryoku/plugins/ryoku-navbar-pets", + "files": [ + { + "source": "LICENSE", + "destination": "LICENSE", + "sha256": "cc6fbab09c64ad8762e668ae69c36d8ebee8735c20cbc37d136e20b18aa64269", + "mode": "0644", + "size": 1063, + "install": false + }, + { + "source": "README.md", + "destination": "README.md", + "sha256": "99f6a4035c6d735bd83a8f4ecce450712d407afec241d8b39af7b24bcd08622f", + "mode": "0644", + "size": 3567, + "install": false + }, + { + "source": "assets/preview-panel.png", + "destination": "assets/preview-panel.png", + "sha256": "dac4efbfa67db868ebc1e160ac38feedcb5b634cd21045e80617da61186024bb", + "mode": "0644", + "size": 75916, + "install": false + }, + { + "source": "assets/preview-widget.png", + "destination": "assets/preview-widget.png", + "sha256": "76bce1231b233dd9f39ec42605ae6e25371b3c2a0fec5b6df0f02856473ed805", + "mode": "0644", + "size": 29809, + "install": false + }, + { + "source": "content/Card.qml", + "destination": "content/Card.qml", + "sha256": "c04c575628b6334b7aaecc2f7ce67e10516a4918150edaefca0c163c98650590", + "mode": "0644", + "size": 3729, + "install": true + }, + { + "source": "content/Glyph.qml", + "destination": "content/Glyph.qml", + "sha256": "a851123467e6523a1dc6ce8b222eb9e9e03a756a555ec0773fa2e9370debf22d", + "mode": "0644", + "size": 2391, + "install": true + }, + { + "source": "content/Panel.qml", + "destination": "content/Panel.qml", + "sha256": "c915cb76db42c2237a502d128f781c513653646b355676dfc5a6ee21c92647f2", + "mode": "0644", + "size": 7140, + "install": true + }, + { + "source": "content/PetSprite.qml", + "destination": "content/PetSprite.qml", + "sha256": "6839053bf2e496acab9d44ddbbcf92378720668c80a684aa12134414218034ef", + "mode": "0644", + "size": 1375, + "install": true + }, + { + "source": "content/Pets.js", + "destination": "content/Pets.js", + "sha256": "5b5ff488e5a1b8779de12241c3a68119afb91097621b6f5bb8178c3ea35aeb09", + "mode": "0644", + "size": 5615, + "install": true + }, + { + "source": "content/Scene.qml", + "destination": "content/Scene.qml", + "sha256": "4d3ef041f0bfaf44d79471a5ffc0b37e973bd7a969c7300632af260906ed791a", + "mode": "0644", + "size": 4431, + "install": true + }, + { + "source": "content/Widget.qml", + "destination": "content/Widget.qml", + "sha256": "b7ec32a6bc1153e6c2eabf8d2ffee95e7de1c7afa79b106eaa8cd8a5b460169d", + "mode": "0644", + "size": 1523, + "install": true + }, + { + "source": "manifest.json", + "destination": "manifest.json", + "sha256": "fa877c05accb66874e5c9de9a16be9b784649589b4c8ed6778aca5090a4bd962", + "mode": "0644", + "size": 2982, + "install": true + }, + { + "source": "service/Main.qml", + "destination": "service/Main.qml", + "sha256": "3e7e4153d8c7215d899e8db5a7f9ae0e620949f978b6e8f10f8840c2f6db56d6", + "mode": "0644", + "size": 11079, + "install": true + } + ] +} diff --git a/plugins/ryoku-navbar-pets/service/Main.qml b/plugins/ryoku-navbar-pets/service/Main.qml new file mode 100644 index 00000000..a1e793e6 --- /dev/null +++ b/plugins/ryoku-navbar-pets/service/Main.qml @@ -0,0 +1,277 @@ +pragma ComponentBehavior: Bound + +import QtQuick + +// Headless simulation for the bar pet and its scene. It owns no UI: views only +// read pets/ball/treats/particles and call the action functions. State lives in +// memory; only user choices are persisted through pluginApi.saveSetting. +Item { + id: svc + + property var pluginApi + readonly property var settings: pluginApi ? pluginApi.pluginSettings : null + readonly property bool ready: !!(pluginApi && pluginApi.pluginDir) + + // Local palette/species helpers: the service must not import from a parent + // directory, and the sprite definitions live with the views in Pets.js. + readonly property var palettes: [ + { id: "dawn", name: "Dawn", skyTop: "#2b1f3d", skyBottom: "#c86b6b", far: "#6b405c", near: "#3d2b45", ground: "#241c2e", tint: "#f0a6a0" }, + { id: "meadow", name: "Meadow", skyTop: "#123044", skyBottom: "#3f8c8c", far: "#2c6b63", near: "#1d4a46", ground: "#14302f", tint: "#9ad7b2" }, + { id: "dusk", name: "Dusk", skyTop: "#1b1b38", skyBottom: "#70406b", far: "#49345e", near: "#2e2547", ground: "#1d1930", tint: "#c99ad6" }, + { id: "night", name: "Night", skyTop: "#0a1024", skyBottom: "#1c2c4a", far: "#1a2542", near: "#121a30", ground: "#0c1222", tint: "#9fb8ff" }, + { id: "candy", name: "Candy", skyTop: "#3a1f42", skyBottom: "#a85c8c", far: "#7a4275", near: "#502e57", ground: "#33203a", tint: "#ffb3d1" } + ] + readonly property var speciesIds: ["cat", "dog", "panda", "fox", "rat", "frog", "bird", "dragon"] + + function paletteFor(id) { + for (var i = 0; i < svc.palettes.length; i++) + if (svc.palettes[i].id === id) return svc.palettes[i]; + return svc.palettes[0]; + } + function speciesName(id) { + return String(id).charAt(0).toUpperCase() + String(id).slice(1); + } + + function _str(key, fallback) { + return settings && settings[key] !== undefined && String(settings[key]).length > 0 + ? String(settings[key]) : fallback; + } + function _int(key, fallback) { + if (settings && settings[key] !== undefined) { + var n = Number(settings[key]); + return isFinite(n) ? n : fallback; + } + return fallback; + } + function _bool(key, fallback) { + return settings && settings[key] !== undefined ? !!settings[key] : fallback; + } + function save(key, value) { + if (pluginApi && pluginApi.saveSetting) pluginApi.saveSetting(key, value); + } + + readonly property string pet: svc._str("pet", "mixed") + readonly property string theme: svc._str("theme", "dawn") + readonly property int companions: Math.min(4, Math.max(1, svc._int("companions", 2))) + readonly property bool ballEnabled: svc._bool("ball", true) + readonly property bool reducedMotion: svc._bool("reducedMotion", false) + readonly property int pixelScale: Math.min(4, Math.max(1, svc._int("pixelScale", 2))) + readonly property var palette: svc.paletteFor(svc.theme) + + readonly property real sceneWidth: 320 + readonly property real sceneHeight: 160 + readonly property int spriteSize: 16 * svc.pixelScale + + property var pets: [] + property var treats: [] + property var particles: [] + property var ball: ({ x: 150, y: 40, vx: 1.6, vy: 0.4, active: svc.ballEnabled }) + property var activeHosts: ({}) + property bool hostReported: false + property int treatsGiven: 0 + property int playCount: 0 + property string lastAction: "" + + function rand(a, b) { return a + Math.random() * (b - a); } + function clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); } + + // Views report whether their host is visible. Before the first report the + // simulation runs so a harness or a single host still animates. + function setHostActive(name, active) { + var map = svc.hostReported ? svc.activeHosts : {}; + map[name] = !!active; + svc.activeHosts = map; + svc.hostReported = true; + } + readonly property bool anyHostActive: { + if (!svc.hostReported) return true; + for (var key in svc.activeHosts) if (svc.activeHosts[key]) return true; + return false; + } + + function speciesFor(index) { + if (svc.pet !== "mixed") return svc.pet; + var ids = svc.speciesIds; + return ids[(index * 3 + 1) % ids.length]; + } + + function spawnPet(index) { + return { + id: svc.speciesFor(index), + x: svc.rand(10, svc.sceneWidth - svc.spriteSize - 10), + y: svc.sceneHeight - svc.spriteSize - 4, + vx: svc.rand(-0.55, 0.55), + vy: 0, + phase: 0, + mood: "calm", + hop: 0, + target: -1 + }; + } + + function populate() { + var next = []; + for (var i = 0; i < svc.companions; i++) next.push(svc.spawnPet(i)); + svc.pets = next; + svc.treats = []; + svc.particles = []; + } + + function addParticle(x, y, kind) { + var list = svc.particles.slice(); + list.push({ x: x, y: y, kind: kind, life: 40 }); + if (list.length > 24) list.shift(); + svc.particles = list; + } + + function giveTreat() { + if (!svc.pets.length) return; + var idx = Math.floor(Math.random() * svc.pets.length); + var pet = svc.pets[idx]; + var list = svc.treats.slice(); + list.push({ x: svc.clamp(pet.x + svc.rand(-50, 50), 4, svc.sceneWidth - 12), + y: svc.sceneHeight - svc.spriteSize - 6, index: idx, life: 220 }); + svc.treats = list; + svc.treatsGiven++; + svc.lastAction = "Treat for the " + svc.speciesName(pet.id).toLowerCase() + "!"; + } + + function playBall() { + svc.ball = { x: svc.rand(40, 260), y: 24, vx: svc.rand(-2.2, 2.2), vy: svc.rand(-1, 1), active: true }; + svc.save("ball", true); + svc.playCount++; + svc.lastAction = "Ball is bouncing"; + } + + function toggleBall() { + var next = !svc.ball.active; + svc.setBall(next); + svc.lastAction = next ? "Ball is bouncing" : "Ball parked"; + } + + function petAll() { + var next = svc.pets.map(function (p) { + p.mood = "happy"; + p.hop = 8; + return p; + }); + svc.pets = next; + for (var i = 0; i < next.length; i++) + svc.addParticle(next[i].x + 16, next[i].y + 4, "heart"); + svc.lastAction = "Head pats for everyone"; + } + + function setPet(id) { svc.save("pet", id); svc.populate(); } + function setTheme(id) { svc.save("theme", id); } + function cycleTheme() { + var ids = svc.palettes.map(function (t) { return t.id; }); + var at = ids.indexOf(svc.theme); + svc.save("theme", ids[(at + 1) % ids.length]); + } + function setCompanions(n) { + svc.save("companions", svc.clamp(Math.round(n), 1, 4)); + svc.populate(); + } + function setReducedMotion(on) { svc.save("reducedMotion", !!on); } + function setBall(on) { + var b = svc.ball; + svc.save("ball", !!on); + svc.ball = { x: b.x, y: b.y, vx: b.vx, vy: b.vy, active: !!on }; + } + function setPixelScale(n) { svc.save("pixelScale", svc.clamp(Math.round(n), 1, 4)); } + + function tick() { + if (!svc.pets.length) return; + var step = svc.reducedMotion ? 0.35 : 1; + var nextPets = svc.pets.map(function (p) { return { + id: p.id, x: p.x, y: p.y, vx: p.vx, vy: p.vy, + phase: p.phase, mood: p.mood === "happy" ? "happy" : "calm", + hop: p.hop, target: p.target + }; }); + + var currentBall = svc.ball; + var b = { x: currentBall.x, y: currentBall.y, vx: currentBall.vx, + vy: currentBall.vy, active: currentBall.active }; + if (b.active) { + b.vy += 0.22 * step; + b.x += b.vx * step; + b.y += b.vy * step; + if (b.x < 6 || b.x > svc.sceneWidth - 18) { b.vx *= -0.85; b.x = svc.clamp(b.x, 6, svc.sceneWidth - 18); } + if (b.y > svc.sceneHeight - 12) { b.vy = -Math.abs(b.vy) * 0.78; b.y = svc.sceneHeight - 12; } + b.vx *= 0.995; + } + + var nextTreats = []; + for (var t = 0; t < svc.treats.length; t++) { + var treat = svc.treats[t]; + treat.life -= step; + var target = nextPets[treat.index]; + if (target && treat.life > 0) { + var dx = treat.x - target.x; + var dy = treat.y - target.y; + var dist = Math.sqrt(dx * dx + dy * dy) || 1; + target.target = treat.index; + if (!svc.reducedMotion) { + target.vx += (dx / dist) * 0.16 * step; + if (dy < -8) target.vy -= 0.9 * step; + } + // Treats sit on the ground, so consume on horizontal overlap. + if (Math.abs(dx) < 14) { + target.mood = "happy"; + svc.addParticle(treat.x, treat.y, "crumb"); + svc.lastAction = svc.speciesName(target.id) + " enjoyed the treat"; + continue; + } + } + if (treat.life > 0) nextTreats.push(treat); + } + + for (var i = 0; i < nextPets.length; i++) { + var pet = nextPets[i]; + if (!svc.reducedMotion) { + if (pet.hop > 0) { pet.vy -= 0.6 * step; pet.hop--; } + else pet.vy += 0.5 * step; + pet.x += pet.vx * step; + pet.y += pet.vy * step; + pet.vx *= 0.96; + if (pet.y > svc.sceneHeight - svc.spriteSize - 4) { + pet.y = svc.sceneHeight - svc.spriteSize - 4; + pet.vy = 0; + } + if (pet.y < 8) { pet.y = 8; pet.vy = Math.abs(pet.vy) * 0.5; } + if (pet.x < 2 || pet.x > svc.sceneWidth - svc.spriteSize - 2) { + pet.vx *= -0.8; + pet.x = svc.clamp(pet.x, 2, svc.sceneWidth - svc.spriteSize - 2); + } + if (Math.abs(pet.vx) > 0.12) pet.phase = (pet.phase + 1) % 2; + if (pet.mood === "happy" && Math.random() < 0.02) pet.mood = "calm"; + } + } + + var nextParticles = []; + for (var q = 0; q < svc.particles.length; q++) { + var part = svc.particles[q]; + part.life -= step; + part.y -= 0.35 * step; + if (part.life > 0) nextParticles.push(part); + } + + svc.ball = b; + svc.treats = nextTreats; + svc.particles = nextParticles; + svc.pets = nextPets; + } + + Timer { + running: svc.ready && svc.anyHostActive + interval: svc.reducedMotion ? 240 : 50 + repeat: true + onTriggered: svc.tick() + } + + onReadyChanged: if (svc.ready) svc.populate() + onCompanionsChanged: if (svc.ready && svc.pets.length !== svc.companions) svc.populate() + onPetChanged: if (svc.ready) svc.populate() + onBallEnabledChanged: svc.setBall(svc.ballEnabled) + Component.onCompleted: if (svc.ready) svc.populate() +}