mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 19:59:38 +00:00
Prevent flying to the same element and reduce chirp volume
This commit is contained in:
48
dist/obsidian/main.js
vendored
48
dist/obsidian/main.js
vendored
@@ -1,7 +1,7 @@
|
||||
const { Plugin, Notice } = require('obsidian');
|
||||
module.exports = class PocketBird extends Plugin {
|
||||
onload() {
|
||||
console.log("Loading Pocket Bird version 2026.3.19...");
|
||||
console.log("Loading Pocket Bird version 2026.3.20...");
|
||||
const OBSIDIAN_PLUGIN = this;
|
||||
(function () {
|
||||
'use strict';
|
||||
@@ -483,7 +483,7 @@ module.exports = class PocketBird extends Plugin {
|
||||
"face": "#39333e",
|
||||
"wing": "#312c35",
|
||||
"wing-edge": "#171617",
|
||||
"underbelly": "#ff82ba",
|
||||
"underbelly": "#ff7eb8",
|
||||
"belly": "#ff6eaf",
|
||||
"foot": "#2e2c2e",
|
||||
"theme-highlight": "#ff82ba"
|
||||
@@ -1364,7 +1364,7 @@ module.exports = class PocketBird extends Plugin {
|
||||
3500 + Math.random() * 600 * count,
|
||||
2100 + Math.random() * 200 * count,
|
||||
1600 + Math.random() * 400 * count];
|
||||
const VOLUMES = [0.0001, 0.2, 0.2, 0.0001];
|
||||
const VOLUMES = [0.00005, 0.165, 0.165, 0.0001];
|
||||
|
||||
const oscillator = this.audioContext.createOscillator();
|
||||
oscillator.type = "sine";
|
||||
@@ -2458,7 +2458,7 @@ module.exports = class PocketBird extends Plugin {
|
||||
}),
|
||||
new Separator(),
|
||||
new MenuItem(() => `Source Code ${isPetBoostActive() ? " ❤" : ""}`, () => { window.open("https://github.com/IdreesInc/Pocket-Bird"); }),
|
||||
new MenuItem("2026.3.19", () => { alert("Thank you for using Pocket Bird! You are on version: 2026.3.19"); }, false),
|
||||
new MenuItem("2026.3.20", () => { alert("Thank you for using Pocket Bird! You are on version: 2026.3.20"); }, false),
|
||||
];
|
||||
|
||||
/** @type {Birb} */
|
||||
@@ -2648,7 +2648,7 @@ module.exports = class PocketBird extends Plugin {
|
||||
|
||||
setInterval(update, UPDATE_INTERVAL);
|
||||
|
||||
focusOnElement(true);
|
||||
flyToElement(true);
|
||||
// TODO: Remove
|
||||
insertFieldGuide();
|
||||
}
|
||||
@@ -2669,11 +2669,11 @@ module.exports = class PocketBird extends Plugin {
|
||||
// Idle for a while, do something
|
||||
if (focusedElement === null) {
|
||||
// Fly to an element
|
||||
focusOnElement();
|
||||
flyToElement();
|
||||
lastActionTimestamp = Date.now();
|
||||
} else if (Math.random() < FOCUS_SWITCH_CHANCE) {
|
||||
// Fly to another element if idle for a longer while
|
||||
focusOnElement();
|
||||
flyToElement();
|
||||
lastActionTimestamp = Date.now();
|
||||
}
|
||||
}
|
||||
@@ -2709,7 +2709,7 @@ module.exports = class PocketBird extends Plugin {
|
||||
// Update the bird's position
|
||||
if (currentState === States.IDLE) {
|
||||
if (focusedElement && !isWithinHorizontalBounds()) {
|
||||
flySomewhere();
|
||||
flyToElement();
|
||||
}
|
||||
birdY = getFocusedY();
|
||||
} else if (currentState === States.FLYING) {
|
||||
@@ -2725,7 +2725,7 @@ module.exports = class PocketBird extends Plugin {
|
||||
startY += targetY - oldTargetY;
|
||||
if (targetY < 0 || targetY > getWindowHeight()) {
|
||||
// Fly to another element or the ground if the focused element moves out of bounds
|
||||
flySomewhere();
|
||||
flyToElement();
|
||||
}
|
||||
|
||||
if (birb.draw(SPECIES[currentSpecies], currentHat)) {
|
||||
@@ -3244,26 +3244,6 @@ module.exports = class PocketBird extends Plugin {
|
||||
return getWindowHeight() - focusedBounds.top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fly to either an element or the ground
|
||||
*/
|
||||
function flySomewhere() {
|
||||
// On mobile, always prefer to focus on an element
|
||||
// If not mobile, 50% chance to focus on ground
|
||||
// if ((!isMobile() && coinFlip()) || !focusOnElement()) {
|
||||
// focusOnGround();
|
||||
// }
|
||||
if (!focusOnElement()) {
|
||||
focusOnGround();
|
||||
}
|
||||
}
|
||||
|
||||
function focusOnGround() {
|
||||
focusedElement = null;
|
||||
updateFocusedElementBounds();
|
||||
flyTo(Math.random() * window.innerWidth, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {HTMLElement|null} The random element, or null if no valid element was found
|
||||
*/
|
||||
@@ -3295,20 +3275,20 @@ module.exports = class PocketBird extends Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus on an element within the viewport
|
||||
* Fly to an element within the viewport
|
||||
* @param {boolean} [teleport] Whether to teleport to the element instead of flying
|
||||
* @returns Whether an element to focus on was found
|
||||
* @returns Whether an element to fly to was found (null if flying to the ground)
|
||||
*/
|
||||
function focusOnElement(teleport = false) {
|
||||
function flyToElement(teleport = false) {
|
||||
if (frozen) {
|
||||
return false;
|
||||
}
|
||||
const previousElement = focusedElement;
|
||||
focusedElement = getRandomValidElement();
|
||||
log("Focusing on element: ", focusedElement);
|
||||
updateFocusedElementBounds();
|
||||
if (teleport) {
|
||||
teleportTo(getFocusedElementRandomX(), getFocusedY());
|
||||
} else {
|
||||
} else if (focusedElement !== previousElement) {
|
||||
flyTo(getFocusedElementRandomX(), getFocusedY());
|
||||
}
|
||||
return focusedElement !== null;
|
||||
|
||||
2
dist/obsidian/manifest.json
vendored
2
dist/obsidian/manifest.json
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "pocket-bird",
|
||||
"name": "Pocket Bird",
|
||||
"version": "2026.3.19",
|
||||
"version": "2026.3.20",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Add a pet bird to fly around your notes and keep you company!",
|
||||
"author": "Idrees Hassan",
|
||||
|
||||
Reference in New Issue
Block a user