Add toggle to enable/disable sound

This commit is contained in:
Idrees Hassan
2026-01-04 18:02:47 -05:00
parent 0cc06a8856
commit e5956426d5
9 changed files with 90 additions and 42 deletions

View File

@@ -61,7 +61,8 @@ import {
* @typedef {typeof DEFAULT_SETTINGS} Settings
*/
const DEFAULT_SETTINGS = {
birbMode: false
birbMode: false,
soundEnabled: true
};
// Rendering constants
@@ -177,7 +178,11 @@ function startApplication(birbPixels, featherPixels) {
const settingsItems = [
new MenuItem("Go Back", () => switchMenuItems(menuItems, updateMenuLocation), false),
new Separator(),
new MenuItem("Toggle Birb Mode", () => {
new MenuItem(() => `${userSettings.soundEnabled ? "Disable" : "Enable"} Sound`, () => {
userSettings.soundEnabled = !userSettings.soundEnabled;
save();
}),
new MenuItem(() => `Toggle ${birdBirb(true)} Mode`, () => {
userSettings.birbMode = !userSettings.birbMode;
save();
const message = makeElement("birb-message-content");
@@ -296,8 +301,8 @@ function startApplication(birbPixels, featherPixels) {
/**
* Bird or birb, you decide
*/
function birdBirb() {
return settings().birbMode ? "Birb" : "Bird";
function birdBirb(invert = false) {
return settings().birbMode !== invert ? "Birb" : "Bird";
}
function init() {
@@ -900,7 +905,9 @@ function startApplication(birbPixels, featherPixels) {
function pet() {
if (currentState === States.IDLE && birb.getCurrentAnimation() !== Animations.HEART) {
birdsong.chirp();
if (settings().soundEnabled) {
birdsong.chirp();
}
birb.setAnimation(Animations.HEART);
lastPetTimestamp = Date.now();
}

View File

@@ -12,7 +12,7 @@ export const MENU_EXIT_ID = "birb-menu-exit";
export class MenuItem {
/**
* @param {string} text
* @param {string|(() => string)} text
* @param {() => void} action
* @param {boolean} [removeMenu]
*/
@@ -61,7 +61,7 @@ function makeMenuItem(item, removeMenuCallback) {
if (item instanceof Separator) {
return makeElement("birb-window-separator");
}
let menuItem = makeElement("birb-menu-item", item.text);
let menuItem = makeElement("birb-menu-item", typeof item.text === "function" ? item.text() : item.text);
onClick(menuItem, () => {
if (item.removeMenu) {
removeMenuCallback();

View File

@@ -198,6 +198,7 @@
.birb-menu-item {
width: calc(100% - var(--birb-double-border-size));
white-space: nowrap;
font-size: 14px;
padding-top: 4px;
padding-bottom: 4px;