mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-24 19:59:36 +00:00
Move menu constants to menu section
This commit is contained in:
80
dist/birb.js
vendored
80
dist/birb.js
vendored
@@ -6,6 +6,22 @@
|
||||
RIGHT: 1,
|
||||
};
|
||||
|
||||
let debug$1 = location.hostname === "127.0.0.1";
|
||||
|
||||
/**
|
||||
* @returns {boolean} Whether debug mode is enabled
|
||||
*/
|
||||
function isDebug() {
|
||||
return debug$1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} debugMode
|
||||
*/
|
||||
function setDebug(debugMode) {
|
||||
debug$1 = debugMode;
|
||||
}
|
||||
|
||||
/** Indicators for parts of the base bird sprite sheet */
|
||||
const SPRITE = {
|
||||
THEME_HIGHLIGHT: "theme-highlight",
|
||||
@@ -614,6 +630,9 @@
|
||||
onSave();
|
||||
}
|
||||
|
||||
const MENU_ID = "birb-menu";
|
||||
const MENU_EXIT_ID = "birb-menu-exit";
|
||||
|
||||
class MenuItem {
|
||||
/**
|
||||
* @param {string} text
|
||||
@@ -788,24 +807,21 @@
|
||||
|
||||
/**
|
||||
* Add the menu to the page if it doesn't already exist
|
||||
* @param {string} menuId
|
||||
* @param {string} menuExitId
|
||||
* @param {MenuItem[]} menuItems
|
||||
* @param {string} title
|
||||
* @param {boolean} debugMode
|
||||
* @param {(menu: HTMLElement) => void} updateLocationCallback
|
||||
*/
|
||||
function insertMenu(menuId, menuExitId, menuItems, title, debugMode, updateLocationCallback) {
|
||||
if (document.querySelector("#" + menuId)) {
|
||||
function insertMenu(menuItems, title, updateLocationCallback) {
|
||||
if (document.querySelector("#" + MENU_ID)) {
|
||||
return;
|
||||
}
|
||||
let menu = makeElement("birb-window", undefined, menuId);
|
||||
let menu = makeElement("birb-window", undefined, MENU_ID);
|
||||
let header = makeElement("birb-window-header");
|
||||
header.innerHTML = `<div class="birb-window-title">${title}</div>`;
|
||||
let content = makeElement("birb-window-content");
|
||||
const removeCallback = () => removeMenu(menuId, menuExitId);
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || debugMode) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -814,7 +830,7 @@
|
||||
document.body.appendChild(menu);
|
||||
makeDraggable(document.querySelector(".birb-window-header"));
|
||||
|
||||
let menuExit = makeElement("birb-window-exit", undefined, menuExitId);
|
||||
let menuExit = makeElement("birb-window-exit", undefined, MENU_EXIT_ID);
|
||||
onClick(menuExit, removeCallback);
|
||||
document.body.appendChild(menuExit);
|
||||
makeClosable(removeCallback);
|
||||
@@ -824,36 +840,31 @@
|
||||
|
||||
/**
|
||||
* Remove the menu from the page
|
||||
* @param {string} menuId
|
||||
* @param {string} menuExitId
|
||||
*/
|
||||
function removeMenu(menuId, menuExitId) {
|
||||
const menu = document.querySelector("#" + menuId);
|
||||
function removeMenu() {
|
||||
const menu = document.querySelector("#" + MENU_ID);
|
||||
if (menu) {
|
||||
menu.remove();
|
||||
}
|
||||
const exitMenu = document.querySelector("#" + menuExitId);
|
||||
const exitMenu = document.querySelector("#" + MENU_EXIT_ID);
|
||||
if (exitMenu) {
|
||||
exitMenu.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} menuId
|
||||
* @returns {boolean} Whether the menu element is on the page
|
||||
*/
|
||||
function isMenuOpen(menuId) {
|
||||
return document.querySelector("#" + menuId) !== null;
|
||||
function isMenuOpen() {
|
||||
return document.querySelector("#" + MENU_ID) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} menuId
|
||||
* @param {MenuItem[]} menuItems
|
||||
* @param {boolean} debugMode
|
||||
* @param {(menu: HTMLElement) => void} updateLocationCallback
|
||||
*/
|
||||
function switchMenuItems(menuId, menuItems, debugMode, updateLocationCallback) {
|
||||
const menu = document.querySelector("#" + menuId);
|
||||
function switchMenuItems(menuItems, updateLocationCallback) {
|
||||
const menu = document.querySelector("#" + MENU_ID);
|
||||
if (!menu || !(menu instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
@@ -863,9 +874,9 @@
|
||||
return;
|
||||
}
|
||||
content.innerHTML = "";
|
||||
const removeCallback = () => removeMenu(menuId, menuId + "-exit");
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || debugMode) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -892,7 +903,6 @@
|
||||
|
||||
const CONFIG = { ...SHARED_CONFIG, ...isMobile() ? MOBILE_CONFIG : DESKTOP_CONFIG };
|
||||
|
||||
let debugMode = location.hostname === "127.0.0.1";
|
||||
let frozen = false;
|
||||
|
||||
const BIRB_CSS_SCALE = CONFIG.birbCssScale;
|
||||
@@ -1279,8 +1289,6 @@
|
||||
const DECORATIONS_SPRITE_SHEET = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAPNJREFUaIHtmTESgzAMBHWZDC+gp0vP/x9Bn44+L6BRmrhJA4csM05uGzfY1s1JxggzIYQQQgghxEnATnB3zwikAICKiXq4BE/uwaxvn/UPb3BnNwFg27Ky0w6vzRp8S4mkIbQD3wzzFJofdTMkYJgn89czFADGKSSiSgphfFBjTaoIKC4cHWvSxIFMmjiQSYoDLUlxoCVywOwHHWjpROop1IL/vsxty2oYO77M1QggSvcpJAFXE66BPfa+2C4v4j2yi7z7FJKAq6FrwN3TO3MMlAAAKO3F2sVZTiu2N9p9CnUv4FR7PbMG2BQ69SJL/kVA8QauAnHUj36BVwAAAABJRU5ErkJggg==";
|
||||
const FEATHER_SPRITE_SHEET = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAARhJREFUWIXtlbENwjAQRf8hSiZIRQ+9WQNRUFIAKzACBSsAA1Ag1mAABqCCBomG3hQQ9OMEx4ZDNH5SikSJ3/fZ5wCJRCKRSPwZ0RzMWmtLAhGvQyUAi9mXP/aFaGjJRQQiguHihMvcFMJUVUYlAMuHixPGy4en1WmVQqgHYHkuZjiEj6a2/LjtYzTY0eiZbgC37Mxh1UN3sn/dr6cCz/LHB/DJj9s+2oMdbtdz6TtfFwQHcMvOInfmQNjsgchNWLXmdfK6gyioAu/6uKrsm1kWLAciKuCuey5nYuXAh234bdmZ6INIUw4E/Ix49xtjCmXfzLL8nY/ktdgnAKwxxgIoXIyqmAOwvIqfiN0ALNd21HYBO9XXGMAdnZTYyHWzWjQAAAAASUVORK5CYII=";
|
||||
|
||||
const MENU_ID = "birb-menu";
|
||||
const MENU_EXIT_ID = "birb-menu-exit";
|
||||
const FIELD_GUIDE_ID = "birb-field-guide";
|
||||
const FEATHER_ID = "birb-feather";
|
||||
|
||||
@@ -1290,7 +1298,7 @@
|
||||
/** Speed at which the feather falls per tick */
|
||||
const FEATHER_FALL_SPEED = 1;
|
||||
/** Time in milliseconds until the user is considered AFK */
|
||||
const AFK_TIME = debugMode ? 0 : 1000 * 30;
|
||||
const AFK_TIME = isDebug() ? 0 : 1000 * 30;
|
||||
const UPDATE_INTERVAL = 1000 / 60; // 60 FPS
|
||||
// Per-frame chances
|
||||
const HOP_CHANCE = 1 / (60 * 3); // 3 seconds
|
||||
@@ -1479,14 +1487,14 @@
|
||||
}
|
||||
}),
|
||||
new DebugMenuItem("Disable Debug", () => {
|
||||
debugMode = false;
|
||||
setDebug(false);
|
||||
}),
|
||||
new Separator(),
|
||||
new MenuItem("Settings", () => switchMenuItems(MENU_ID, settingsItems, debugMode, updateMenuLocation), false),
|
||||
new MenuItem("Settings", () => switchMenuItems(settingsItems, updateMenuLocation), false),
|
||||
];
|
||||
|
||||
const settingsItems = [
|
||||
new MenuItem("Go Back", () => switchMenuItems(MENU_ID, menuItems, debugMode, updateMenuLocation), false),
|
||||
new MenuItem("Go Back", () => switchMenuItems(menuItems, updateMenuLocation), false),
|
||||
new Separator(),
|
||||
new MenuItem("Toggle Birb Mode", () => {
|
||||
userSettings.birbMode = !userSettings.birbMode;
|
||||
@@ -1691,7 +1699,7 @@
|
||||
onClick(document, (e) => {
|
||||
lastActionTimestamp = Date.now();
|
||||
if (e.target instanceof Node && document.querySelector("#" + MENU_EXIT_ID)?.contains(e.target)) {
|
||||
removeMenu(MENU_ID, MENU_EXIT_ID);
|
||||
removeMenu();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1700,10 +1708,8 @@
|
||||
// Currently being pet, don't open menu
|
||||
return;
|
||||
}
|
||||
insertMenu(MENU_ID, MENU_EXIT_ID, menuItems, `${birdBirb().toLowerCase()}OS`, debugMode, updateMenuLocation);
|
||||
});
|
||||
|
||||
canvas.addEventListener("mouseover", () => {
|
||||
insertMenu(menuItems, `${birdBirb().toLowerCase()}OS`, updateMenuLocation);
|
||||
}); canvas.addEventListener("mouseover", () => {
|
||||
lastActionTimestamp = Date.now();
|
||||
if (currentState === States.IDLE) {
|
||||
petStack.push(Date.now());
|
||||
@@ -1747,7 +1753,7 @@
|
||||
// Won't be restored on fullscreen exit
|
||||
}
|
||||
|
||||
if (currentState === States.IDLE && !frozen && !isMenuOpen(MENU_ID)) {
|
||||
if (currentState === States.IDLE && !frozen && !isMenuOpen()) {
|
||||
if (Math.random() < HOP_CHANCE && currentAnimation !== Animations.HEART) {
|
||||
hop();
|
||||
} else if (Date.now() - lastActionTimestamp > AFK_TIME) {
|
||||
@@ -2459,7 +2465,7 @@
|
||||
}
|
||||
|
||||
function debug() {
|
||||
if (debugMode) {
|
||||
if (isDebug()) {
|
||||
console.debug("Birb: ", ...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
82
dist/birb.user.js
vendored
82
dist/birb.user.js
vendored
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Pocket Bird
|
||||
// @namespace https://idreesinc.com
|
||||
// @version 2025.10.26.101
|
||||
// @version 2025.10.26.163
|
||||
// @description birb
|
||||
// @author Idrees
|
||||
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js
|
||||
@@ -20,6 +20,22 @@
|
||||
RIGHT: 1,
|
||||
};
|
||||
|
||||
let debug$1 = location.hostname === "127.0.0.1";
|
||||
|
||||
/**
|
||||
* @returns {boolean} Whether debug mode is enabled
|
||||
*/
|
||||
function isDebug() {
|
||||
return debug$1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} debugMode
|
||||
*/
|
||||
function setDebug(debugMode) {
|
||||
debug$1 = debugMode;
|
||||
}
|
||||
|
||||
/** Indicators for parts of the base bird sprite sheet */
|
||||
const SPRITE = {
|
||||
THEME_HIGHLIGHT: "theme-highlight",
|
||||
@@ -628,6 +644,9 @@
|
||||
onSave();
|
||||
}
|
||||
|
||||
const MENU_ID = "birb-menu";
|
||||
const MENU_EXIT_ID = "birb-menu-exit";
|
||||
|
||||
class MenuItem {
|
||||
/**
|
||||
* @param {string} text
|
||||
@@ -802,24 +821,21 @@
|
||||
|
||||
/**
|
||||
* Add the menu to the page if it doesn't already exist
|
||||
* @param {string} menuId
|
||||
* @param {string} menuExitId
|
||||
* @param {MenuItem[]} menuItems
|
||||
* @param {string} title
|
||||
* @param {boolean} debugMode
|
||||
* @param {(menu: HTMLElement) => void} updateLocationCallback
|
||||
*/
|
||||
function insertMenu(menuId, menuExitId, menuItems, title, debugMode, updateLocationCallback) {
|
||||
if (document.querySelector("#" + menuId)) {
|
||||
function insertMenu(menuItems, title, updateLocationCallback) {
|
||||
if (document.querySelector("#" + MENU_ID)) {
|
||||
return;
|
||||
}
|
||||
let menu = makeElement("birb-window", undefined, menuId);
|
||||
let menu = makeElement("birb-window", undefined, MENU_ID);
|
||||
let header = makeElement("birb-window-header");
|
||||
header.innerHTML = `<div class="birb-window-title">${title}</div>`;
|
||||
let content = makeElement("birb-window-content");
|
||||
const removeCallback = () => removeMenu(menuId, menuExitId);
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || debugMode) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -828,7 +844,7 @@
|
||||
document.body.appendChild(menu);
|
||||
makeDraggable(document.querySelector(".birb-window-header"));
|
||||
|
||||
let menuExit = makeElement("birb-window-exit", undefined, menuExitId);
|
||||
let menuExit = makeElement("birb-window-exit", undefined, MENU_EXIT_ID);
|
||||
onClick(menuExit, removeCallback);
|
||||
document.body.appendChild(menuExit);
|
||||
makeClosable(removeCallback);
|
||||
@@ -838,36 +854,31 @@
|
||||
|
||||
/**
|
||||
* Remove the menu from the page
|
||||
* @param {string} menuId
|
||||
* @param {string} menuExitId
|
||||
*/
|
||||
function removeMenu(menuId, menuExitId) {
|
||||
const menu = document.querySelector("#" + menuId);
|
||||
function removeMenu() {
|
||||
const menu = document.querySelector("#" + MENU_ID);
|
||||
if (menu) {
|
||||
menu.remove();
|
||||
}
|
||||
const exitMenu = document.querySelector("#" + menuExitId);
|
||||
const exitMenu = document.querySelector("#" + MENU_EXIT_ID);
|
||||
if (exitMenu) {
|
||||
exitMenu.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} menuId
|
||||
* @returns {boolean} Whether the menu element is on the page
|
||||
*/
|
||||
function isMenuOpen(menuId) {
|
||||
return document.querySelector("#" + menuId) !== null;
|
||||
function isMenuOpen() {
|
||||
return document.querySelector("#" + MENU_ID) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} menuId
|
||||
* @param {MenuItem[]} menuItems
|
||||
* @param {boolean} debugMode
|
||||
* @param {(menu: HTMLElement) => void} updateLocationCallback
|
||||
*/
|
||||
function switchMenuItems(menuId, menuItems, debugMode, updateLocationCallback) {
|
||||
const menu = document.querySelector("#" + menuId);
|
||||
function switchMenuItems(menuItems, updateLocationCallback) {
|
||||
const menu = document.querySelector("#" + MENU_ID);
|
||||
if (!menu || !(menu instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
@@ -877,9 +888,9 @@
|
||||
return;
|
||||
}
|
||||
content.innerHTML = "";
|
||||
const removeCallback = () => removeMenu(menuId, menuId + "-exit");
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || debugMode) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -906,7 +917,6 @@
|
||||
|
||||
const CONFIG = { ...SHARED_CONFIG, ...isMobile() ? MOBILE_CONFIG : DESKTOP_CONFIG };
|
||||
|
||||
let debugMode = location.hostname === "127.0.0.1";
|
||||
let frozen = false;
|
||||
|
||||
const BIRB_CSS_SCALE = CONFIG.birbCssScale;
|
||||
@@ -1293,8 +1303,6 @@
|
||||
const DECORATIONS_SPRITE_SHEET = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAPNJREFUaIHtmTESgzAMBHWZDC+gp0vP/x9Bn44+L6BRmrhJA4csM05uGzfY1s1JxggzIYQQQgghxEnATnB3zwikAICKiXq4BE/uwaxvn/UPb3BnNwFg27Ky0w6vzRp8S4mkIbQD3wzzFJofdTMkYJgn89czFADGKSSiSgphfFBjTaoIKC4cHWvSxIFMmjiQSYoDLUlxoCVywOwHHWjpROop1IL/vsxty2oYO77M1QggSvcpJAFXE66BPfa+2C4v4j2yi7z7FJKAq6FrwN3TO3MMlAAAKO3F2sVZTiu2N9p9CnUv4FR7PbMG2BQ69SJL/kVA8QauAnHUj36BVwAAAABJRU5ErkJggg==";
|
||||
const FEATHER_SPRITE_SHEET = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAARhJREFUWIXtlbENwjAQRf8hSiZIRQ+9WQNRUFIAKzACBSsAA1Ag1mAABqCCBomG3hQQ9OMEx4ZDNH5SikSJ3/fZ5wCJRCKRSPwZ0RzMWmtLAhGvQyUAi9mXP/aFaGjJRQQiguHihMvcFMJUVUYlAMuHixPGy4en1WmVQqgHYHkuZjiEj6a2/LjtYzTY0eiZbgC37Mxh1UN3sn/dr6cCz/LHB/DJj9s+2oMdbtdz6TtfFwQHcMvOInfmQNjsgchNWLXmdfK6gyioAu/6uKrsm1kWLAciKuCuey5nYuXAh234bdmZ6INIUw4E/Ix49xtjCmXfzLL8nY/ktdgnAKwxxgIoXIyqmAOwvIqfiN0ALNd21HYBO9XXGMAdnZTYyHWzWjQAAAAASUVORK5CYII=";
|
||||
|
||||
const MENU_ID = "birb-menu";
|
||||
const MENU_EXIT_ID = "birb-menu-exit";
|
||||
const FIELD_GUIDE_ID = "birb-field-guide";
|
||||
const FEATHER_ID = "birb-feather";
|
||||
|
||||
@@ -1304,7 +1312,7 @@
|
||||
/** Speed at which the feather falls per tick */
|
||||
const FEATHER_FALL_SPEED = 1;
|
||||
/** Time in milliseconds until the user is considered AFK */
|
||||
const AFK_TIME = debugMode ? 0 : 1000 * 30;
|
||||
const AFK_TIME = isDebug() ? 0 : 1000 * 30;
|
||||
const UPDATE_INTERVAL = 1000 / 60; // 60 FPS
|
||||
// Per-frame chances
|
||||
const HOP_CHANCE = 1 / (60 * 3); // 3 seconds
|
||||
@@ -1493,14 +1501,14 @@
|
||||
}
|
||||
}),
|
||||
new DebugMenuItem("Disable Debug", () => {
|
||||
debugMode = false;
|
||||
setDebug(false);
|
||||
}),
|
||||
new Separator(),
|
||||
new MenuItem("Settings", () => switchMenuItems(MENU_ID, settingsItems, debugMode, updateMenuLocation), false),
|
||||
new MenuItem("Settings", () => switchMenuItems(settingsItems, updateMenuLocation), false),
|
||||
];
|
||||
|
||||
const settingsItems = [
|
||||
new MenuItem("Go Back", () => switchMenuItems(MENU_ID, menuItems, debugMode, updateMenuLocation), false),
|
||||
new MenuItem("Go Back", () => switchMenuItems(menuItems, updateMenuLocation), false),
|
||||
new Separator(),
|
||||
new MenuItem("Toggle Birb Mode", () => {
|
||||
userSettings.birbMode = !userSettings.birbMode;
|
||||
@@ -1705,7 +1713,7 @@
|
||||
onClick(document, (e) => {
|
||||
lastActionTimestamp = Date.now();
|
||||
if (e.target instanceof Node && document.querySelector("#" + MENU_EXIT_ID)?.contains(e.target)) {
|
||||
removeMenu(MENU_ID, MENU_EXIT_ID);
|
||||
removeMenu();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1714,10 +1722,8 @@
|
||||
// Currently being pet, don't open menu
|
||||
return;
|
||||
}
|
||||
insertMenu(MENU_ID, MENU_EXIT_ID, menuItems, `${birdBirb().toLowerCase()}OS`, debugMode, updateMenuLocation);
|
||||
});
|
||||
|
||||
canvas.addEventListener("mouseover", () => {
|
||||
insertMenu(menuItems, `${birdBirb().toLowerCase()}OS`, updateMenuLocation);
|
||||
}); canvas.addEventListener("mouseover", () => {
|
||||
lastActionTimestamp = Date.now();
|
||||
if (currentState === States.IDLE) {
|
||||
petStack.push(Date.now());
|
||||
@@ -1761,7 +1767,7 @@
|
||||
// Won't be restored on fullscreen exit
|
||||
}
|
||||
|
||||
if (currentState === States.IDLE && !frozen && !isMenuOpen(MENU_ID)) {
|
||||
if (currentState === States.IDLE && !frozen && !isMenuOpen()) {
|
||||
if (Math.random() < HOP_CHANCE && currentAnimation !== Animations.HEART) {
|
||||
hop();
|
||||
} else if (Date.now() - lastActionTimestamp > AFK_TIME) {
|
||||
@@ -2473,7 +2479,7 @@
|
||||
}
|
||||
|
||||
function debug() {
|
||||
if (debugMode) {
|
||||
if (isDebug()) {
|
||||
console.debug("Birb: ", ...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 3,
|
||||
"name": "Pocket Bird",
|
||||
"description": "It's a bird, in your browser. What more could you want?",
|
||||
"version": "2025.10.26.101",
|
||||
"version": "2025.10.26.163",
|
||||
"homepage_url": "https://idreesinc.com",
|
||||
"content_scripts": [
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Directions } from './sharedConstants.js';
|
||||
import { Directions } from './shared.js';
|
||||
import { SPRITE, BirdType } from './sprites.js';
|
||||
import Layer from './layer.js';
|
||||
|
||||
|
||||
61
src/birb.js
61
src/birb.js
@@ -1,19 +1,31 @@
|
||||
import {
|
||||
Directions
|
||||
} from './sharedConstants.js';
|
||||
|
||||
import {
|
||||
SPRITE,
|
||||
SPRITE_SHEET_COLOR_MAP,
|
||||
SPECIES,
|
||||
BirdType
|
||||
} from './sprites.js';
|
||||
|
||||
import Frame from './frame.js';
|
||||
import Layer from './layer.js';
|
||||
import Anim from './anim.js';
|
||||
import { StickyNote, createNewStickyNote, drawStickyNotes } from './stickyNotes.js';
|
||||
import { MenuItem, DebugMenuItem, Separator, insertMenu, removeMenu, isMenuOpen, switchMenuItems } from './menu.js';
|
||||
import {
|
||||
Directions,
|
||||
isDebug,
|
||||
setDebug
|
||||
} from './shared.js';
|
||||
import {
|
||||
SPRITE,
|
||||
SPRITE_SHEET_COLOR_MAP,
|
||||
SPECIES
|
||||
} from './sprites.js';
|
||||
import {
|
||||
StickyNote,
|
||||
createNewStickyNote,
|
||||
drawStickyNotes
|
||||
} from './stickyNotes.js';
|
||||
import {
|
||||
MenuItem,
|
||||
DebugMenuItem,
|
||||
Separator,
|
||||
insertMenu,
|
||||
removeMenu,
|
||||
isMenuOpen,
|
||||
switchMenuItems,
|
||||
MENU_EXIT_ID
|
||||
} from './menu.js';
|
||||
|
||||
// @ts-ignore
|
||||
const SHARED_CONFIG = {
|
||||
@@ -35,7 +47,6 @@ const MOBILE_CONFIG = {
|
||||
|
||||
const CONFIG = { ...SHARED_CONFIG, ...isMobile() ? MOBILE_CONFIG : DESKTOP_CONFIG };
|
||||
|
||||
let debugMode = location.hostname === "127.0.0.1";
|
||||
let frozen = false;
|
||||
|
||||
const BIRB_CSS_SCALE = CONFIG.birbCssScale;
|
||||
@@ -79,8 +90,6 @@ const SPRITE_SHEET = "__SPRITE_SHEET__";
|
||||
const DECORATIONS_SPRITE_SHEET = "__DECORATIONS_SPRITE_SHEET__";
|
||||
const FEATHER_SPRITE_SHEET = "__FEATHER_SPRITE_SHEET__";
|
||||
|
||||
const MENU_ID = "birb-menu";
|
||||
const MENU_EXIT_ID = "birb-menu-exit";
|
||||
const FIELD_GUIDE_ID = "birb-field-guide";
|
||||
const FEATHER_ID = "birb-feather";
|
||||
|
||||
@@ -90,7 +99,7 @@ const HOP_DISTANCE = CONFIG.hopDistance;
|
||||
/** Speed at which the feather falls per tick */
|
||||
const FEATHER_FALL_SPEED = 1;
|
||||
/** Time in milliseconds until the user is considered AFK */
|
||||
const AFK_TIME = debugMode ? 0 : 1000 * 30;
|
||||
const AFK_TIME = isDebug() ? 0 : 1000 * 30;
|
||||
const UPDATE_INTERVAL = 1000 / 60; // 60 FPS
|
||||
// Per-frame chances
|
||||
const HOP_CHANCE = 1 / (60 * 3); // 3 seconds
|
||||
@@ -287,14 +296,14 @@ Promise.all([
|
||||
}
|
||||
}),
|
||||
new DebugMenuItem("Disable Debug", () => {
|
||||
debugMode = false;
|
||||
setDebug(false);
|
||||
}),
|
||||
new Separator(),
|
||||
new MenuItem("Settings", () => switchMenuItems(MENU_ID, settingsItems, debugMode, updateMenuLocation), false),
|
||||
new MenuItem("Settings", () => switchMenuItems(settingsItems, updateMenuLocation), false),
|
||||
];
|
||||
|
||||
const settingsItems = [
|
||||
new MenuItem("Go Back", () => switchMenuItems(MENU_ID, menuItems, debugMode, updateMenuLocation), false),
|
||||
new MenuItem("Go Back", () => switchMenuItems(menuItems, updateMenuLocation), false),
|
||||
new Separator(),
|
||||
new MenuItem("Toggle Birb Mode", () => {
|
||||
userSettings.birbMode = !userSettings.birbMode;
|
||||
@@ -499,7 +508,7 @@ Promise.all([
|
||||
onClick(document, (e) => {
|
||||
lastActionTimestamp = Date.now();
|
||||
if (e.target instanceof Node && document.querySelector("#" + MENU_EXIT_ID)?.contains(e.target)) {
|
||||
removeMenu(MENU_ID, MENU_EXIT_ID);
|
||||
removeMenu();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -508,10 +517,8 @@ Promise.all([
|
||||
// Currently being pet, don't open menu
|
||||
return;
|
||||
}
|
||||
insertMenu(MENU_ID, MENU_EXIT_ID, menuItems, `${birdBirb().toLowerCase()}OS`, debugMode, updateMenuLocation);
|
||||
});
|
||||
|
||||
canvas.addEventListener("mouseover", () => {
|
||||
insertMenu(menuItems, `${birdBirb().toLowerCase()}OS`, updateMenuLocation);
|
||||
}); canvas.addEventListener("mouseover", () => {
|
||||
lastActionTimestamp = Date.now();
|
||||
if (currentState === States.IDLE) {
|
||||
petStack.push(Date.now());
|
||||
@@ -555,7 +562,7 @@ Promise.all([
|
||||
// Won't be restored on fullscreen exit
|
||||
}
|
||||
|
||||
if (currentState === States.IDLE && !frozen && !isMenuOpen(MENU_ID)) {
|
||||
if (currentState === States.IDLE && !frozen && !isMenuOpen()) {
|
||||
if (Math.random() < HOP_CHANCE && currentAnimation !== Animations.HEART) {
|
||||
hop();
|
||||
} else if (Date.now() - lastActionTimestamp > AFK_TIME) {
|
||||
@@ -1299,7 +1306,7 @@ function log() {
|
||||
}
|
||||
|
||||
function debug() {
|
||||
if (debugMode) {
|
||||
if (isDebug()) {
|
||||
console.debug("Birb: ", ...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Directions } from './sharedConstants.js';
|
||||
import { Directions } from './shared.js';
|
||||
import { SPRITE, BirdType } from './sprites.js';
|
||||
import Layer from './layer.js';
|
||||
|
||||
|
||||
43
src/menu.js
43
src/menu.js
@@ -1,3 +1,8 @@
|
||||
import { isDebug } from './shared.js';
|
||||
|
||||
export const MENU_ID = "birb-menu";
|
||||
export const MENU_EXIT_ID = "birb-menu-exit";
|
||||
|
||||
export class MenuItem {
|
||||
/**
|
||||
* @param {string} text
|
||||
@@ -178,24 +183,21 @@ function makeMenuItem(item, removeMenuCallback) {
|
||||
|
||||
/**
|
||||
* Add the menu to the page if it doesn't already exist
|
||||
* @param {string} menuId
|
||||
* @param {string} menuExitId
|
||||
* @param {MenuItem[]} menuItems
|
||||
* @param {string} title
|
||||
* @param {boolean} debugMode
|
||||
* @param {(menu: HTMLElement) => void} updateLocationCallback
|
||||
*/
|
||||
export function insertMenu(menuId, menuExitId, menuItems, title, debugMode, updateLocationCallback) {
|
||||
if (document.querySelector("#" + menuId)) {
|
||||
export function insertMenu(menuItems, title, updateLocationCallback) {
|
||||
if (document.querySelector("#" + MENU_ID)) {
|
||||
return;
|
||||
}
|
||||
let menu = makeElement("birb-window", undefined, menuId);
|
||||
let menu = makeElement("birb-window", undefined, MENU_ID);
|
||||
let header = makeElement("birb-window-header");
|
||||
header.innerHTML = `<div class="birb-window-title">${title}</div>`;
|
||||
let content = makeElement("birb-window-content");
|
||||
const removeCallback = () => removeMenu(menuId, menuExitId);
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || debugMode) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -204,7 +206,7 @@ export function insertMenu(menuId, menuExitId, menuItems, title, debugMode, upda
|
||||
document.body.appendChild(menu);
|
||||
makeDraggable(document.querySelector(".birb-window-header"));
|
||||
|
||||
let menuExit = makeElement("birb-window-exit", undefined, menuExitId);
|
||||
let menuExit = makeElement("birb-window-exit", undefined, MENU_EXIT_ID);
|
||||
onClick(menuExit, removeCallback);
|
||||
document.body.appendChild(menuExit);
|
||||
makeClosable(removeCallback);
|
||||
@@ -214,36 +216,31 @@ export function insertMenu(menuId, menuExitId, menuItems, title, debugMode, upda
|
||||
|
||||
/**
|
||||
* Remove the menu from the page
|
||||
* @param {string} menuId
|
||||
* @param {string} menuExitId
|
||||
*/
|
||||
export function removeMenu(menuId, menuExitId) {
|
||||
const menu = document.querySelector("#" + menuId);
|
||||
export function removeMenu() {
|
||||
const menu = document.querySelector("#" + MENU_ID);
|
||||
if (menu) {
|
||||
menu.remove();
|
||||
}
|
||||
const exitMenu = document.querySelector("#" + menuExitId);
|
||||
const exitMenu = document.querySelector("#" + MENU_EXIT_ID);
|
||||
if (exitMenu) {
|
||||
exitMenu.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} menuId
|
||||
* @returns {boolean} Whether the menu element is on the page
|
||||
*/
|
||||
export function isMenuOpen(menuId) {
|
||||
return document.querySelector("#" + menuId) !== null;
|
||||
export function isMenuOpen() {
|
||||
return document.querySelector("#" + MENU_ID) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} menuId
|
||||
* @param {MenuItem[]} menuItems
|
||||
* @param {boolean} debugMode
|
||||
* @param {(menu: HTMLElement) => void} updateLocationCallback
|
||||
*/
|
||||
export function switchMenuItems(menuId, menuItems, debugMode, updateLocationCallback) {
|
||||
const menu = document.querySelector("#" + menuId);
|
||||
export function switchMenuItems(menuItems, updateLocationCallback) {
|
||||
const menu = document.querySelector("#" + MENU_ID);
|
||||
if (!menu || !(menu instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
@@ -253,9 +250,9 @@ export function switchMenuItems(menuId, menuItems, debugMode, updateLocationCall
|
||||
return;
|
||||
}
|
||||
content.innerHTML = "";
|
||||
const removeCallback = () => removeMenu(menuId, menuId + "-exit");
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || debugMode) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
|
||||
20
src/shared.js
Normal file
20
src/shared.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export const Directions = {
|
||||
LEFT: -1,
|
||||
RIGHT: 1,
|
||||
};
|
||||
|
||||
let debug = location.hostname === "127.0.0.1";
|
||||
|
||||
/**
|
||||
* @returns {boolean} Whether debug mode is enabled
|
||||
*/
|
||||
export function isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} debugMode
|
||||
*/
|
||||
export function setDebug(debugMode) {
|
||||
debug = debugMode;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export const Directions = {
|
||||
LEFT: -1,
|
||||
RIGHT: 1,
|
||||
};
|
||||
Reference in New Issue
Block a user