mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-26 04:07:24 +00:00
Remove duplicate function
This commit is contained in:
22
README.md
22
README.md
@@ -5,24 +5,4 @@ This project is still being worked on, but if you wish to help me beta test it,
|
|||||||
1. Install [Tampermonkey](https://www.tampermonkey.net/) on your web browser
|
1. Install [Tampermonkey](https://www.tampermonkey.net/) on your web browser
|
||||||
2. Enable the Tampermonkey extension and give it the permissions requested
|
2. Enable the Tampermonkey extension and give it the permissions requested
|
||||||
3. Install my Pocket Bird script by going to this link and clicking install: [https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js](https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js)
|
3. Install my Pocket Bird script by going to this link and clicking install: [https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js](https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js)
|
||||||
4. Now any websites you visit will have a little bird hopping around!
|
4. Now any websites you visit will have a little bird hopping around!
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
This project uses Rollup to bundle the source files.
|
|
||||||
|
|
||||||
### Building
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Development Mode
|
|
||||||
|
|
||||||
Watch for changes and rebuild automatically:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
The source files are in the `src/` directory. The main entry point is `src/birb.js`, which bundles all the other modules together.
|
|
||||||
71
dist/birb.js
vendored
71
dist/birb.js
vendored
@@ -82,7 +82,7 @@
|
|||||||
let elementToMove = parent ? element.parentElement : element;
|
let elementToMove = parent ? element.parentElement : element;
|
||||||
|
|
||||||
if (!elementToMove) {
|
if (!elementToMove) {
|
||||||
console.error("Birb: Parent element not found");
|
error("Birb: Parent element not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +171,22 @@
|
|||||||
console.error("Birb: ", ...arguments);
|
console.error("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a layer from a sprite sheet array
|
||||||
|
* @param {string[][]} spriteSheet The sprite sheet pixel array
|
||||||
|
* @param {number} spriteIndex The sprite index
|
||||||
|
* @param {number} width The width of each sprite
|
||||||
|
* @returns {string[][]}
|
||||||
|
*/
|
||||||
|
function getLayer(spriteSheet, spriteIndex, width) {
|
||||||
|
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
||||||
|
const layer = [];
|
||||||
|
for (let y = 0; y < width; y++) {
|
||||||
|
layer.push(spriteSheet[y].slice(spriteIndex * width, (spriteIndex + 1) * width));
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
/** Indicators for parts of the base bird sprite sheet */
|
/** Indicators for parts of the base bird sprite sheet */
|
||||||
const SPRITE = {
|
const SPRITE = {
|
||||||
THEME_HIGHLIGHT: "theme-highlight",
|
THEME_HIGHLIGHT: "theme-highlight",
|
||||||
@@ -529,16 +545,16 @@
|
|||||||
|
|
||||||
// Build layers from sprite sheet
|
// Build layers from sprite sheet
|
||||||
this.layers = {
|
this.layers = {
|
||||||
base: new Layer(this.getLayer(spriteSheet, 0)),
|
base: new Layer(getLayer(spriteSheet, 0, this.spriteWidth)),
|
||||||
down: new Layer(this.getLayer(spriteSheet, 1)),
|
down: new Layer(getLayer(spriteSheet, 1, this.spriteWidth)),
|
||||||
heartOne: new Layer(this.getLayer(spriteSheet, 2)),
|
heartOne: new Layer(getLayer(spriteSheet, 2, this.spriteWidth)),
|
||||||
heartTwo: new Layer(this.getLayer(spriteSheet, 3)),
|
heartTwo: new Layer(getLayer(spriteSheet, 3, this.spriteWidth)),
|
||||||
heartThree: new Layer(this.getLayer(spriteSheet, 4)),
|
heartThree: new Layer(getLayer(spriteSheet, 4, this.spriteWidth)),
|
||||||
tuftBase: new Layer(this.getLayer(spriteSheet, 5), "tuft"),
|
tuftBase: new Layer(getLayer(spriteSheet, 5, this.spriteWidth), "tuft"),
|
||||||
tuftDown: new Layer(this.getLayer(spriteSheet, 6), "tuft"),
|
tuftDown: new Layer(getLayer(spriteSheet, 6, this.spriteWidth), "tuft"),
|
||||||
wingsUp: new Layer(this.getLayer(spriteSheet, 7)),
|
wingsUp: new Layer(getLayer(spriteSheet, 7, this.spriteWidth)),
|
||||||
wingsDown: new Layer(this.getLayer(spriteSheet, 8)),
|
wingsDown: new Layer(getLayer(spriteSheet, 8, this.spriteWidth)),
|
||||||
happyEye: new Layer(this.getLayer(spriteSheet, 9)),
|
happyEye: new Layer(getLayer(spriteSheet, 9, this.spriteWidth)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build frames from layers
|
// Build frames from layers
|
||||||
@@ -618,21 +634,6 @@
|
|||||||
return anim.draw(this.ctx, this.direction, this.animStart, this.canvasPixelSize, species);
|
return anim.draw(this.ctx, this.direction, this.animStart, this.canvasPixelSize, species);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a layer from the sprite sheet array
|
|
||||||
* @param {string[][]} array
|
|
||||||
* @param {number} sprite
|
|
||||||
* @returns {string[][]}
|
|
||||||
*/
|
|
||||||
getLayer(array, sprite) {
|
|
||||||
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
|
||||||
const layer = [];
|
|
||||||
for (let y = 0; y < this.spriteWidth; y++) {
|
|
||||||
layer.push(array[y].slice(sprite * this.spriteWidth, (sprite + 1) * this.spriteWidth));
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {AnimationType} The current animation key
|
* @returns {AnimationType} The current animation key
|
||||||
*/
|
*/
|
||||||
@@ -1053,7 +1054,7 @@
|
|||||||
}
|
}
|
||||||
const content = menu.querySelector(".birb-window-content");
|
const content = menu.querySelector(".birb-window-content");
|
||||||
if (!content) {
|
if (!content) {
|
||||||
console.error("Birb: Content not found");
|
error("Birb: Content not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
content.innerHTML = "";
|
content.innerHTML = "";
|
||||||
@@ -2169,21 +2170,6 @@
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string[][]} array
|
|
||||||
* @param {number} sprite
|
|
||||||
* @param {number} [width]
|
|
||||||
* @returns {string[][]}
|
|
||||||
*/
|
|
||||||
function getLayer(array, sprite, width = SPRITE_WIDTH) {
|
|
||||||
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
|
||||||
const layer = [];
|
|
||||||
for (let y = 0; y < width; y++) {
|
|
||||||
layer.push(array[y].slice(sprite * width, (sprite + 1) * width));
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the birds location from the start to the target location on a parabolic path
|
* Update the birds location from the start to the target location on a parabolic path
|
||||||
* @param {number} speed The speed of the bird along the path
|
* @param {number} speed The speed of the bird along the path
|
||||||
@@ -2241,7 +2227,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function focusOnGround() {
|
function focusOnGround() {
|
||||||
console.log("Focusing on ground");
|
|
||||||
focusedElement = null;
|
focusedElement = null;
|
||||||
focusedBounds = { left: 0, right: window.innerWidth, top: getSafeWindowHeight() };
|
focusedBounds = { left: 0, right: window.innerWidth, top: getSafeWindowHeight() };
|
||||||
flyTo(Math.random() * window.innerWidth, 0);
|
flyTo(Math.random() * window.innerWidth, 0);
|
||||||
|
|||||||
73
dist/birb.user.js
vendored
73
dist/birb.user.js
vendored
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Pocket Bird
|
// @name Pocket Bird
|
||||||
// @namespace https://idreesinc.com
|
// @namespace https://idreesinc.com
|
||||||
// @version 2025.10.26.388
|
// @version 2025.10.26.402
|
||||||
// @description birb
|
// @description birb
|
||||||
// @author Idrees
|
// @author Idrees
|
||||||
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js
|
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
let elementToMove = parent ? element.parentElement : element;
|
let elementToMove = parent ? element.parentElement : element;
|
||||||
|
|
||||||
if (!elementToMove) {
|
if (!elementToMove) {
|
||||||
console.error("Birb: Parent element not found");
|
error("Birb: Parent element not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +185,22 @@
|
|||||||
console.error("Birb: ", ...arguments);
|
console.error("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a layer from a sprite sheet array
|
||||||
|
* @param {string[][]} spriteSheet The sprite sheet pixel array
|
||||||
|
* @param {number} spriteIndex The sprite index
|
||||||
|
* @param {number} width The width of each sprite
|
||||||
|
* @returns {string[][]}
|
||||||
|
*/
|
||||||
|
function getLayer(spriteSheet, spriteIndex, width) {
|
||||||
|
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
||||||
|
const layer = [];
|
||||||
|
for (let y = 0; y < width; y++) {
|
||||||
|
layer.push(spriteSheet[y].slice(spriteIndex * width, (spriteIndex + 1) * width));
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
/** Indicators for parts of the base bird sprite sheet */
|
/** Indicators for parts of the base bird sprite sheet */
|
||||||
const SPRITE = {
|
const SPRITE = {
|
||||||
THEME_HIGHLIGHT: "theme-highlight",
|
THEME_HIGHLIGHT: "theme-highlight",
|
||||||
@@ -543,16 +559,16 @@
|
|||||||
|
|
||||||
// Build layers from sprite sheet
|
// Build layers from sprite sheet
|
||||||
this.layers = {
|
this.layers = {
|
||||||
base: new Layer(this.getLayer(spriteSheet, 0)),
|
base: new Layer(getLayer(spriteSheet, 0, this.spriteWidth)),
|
||||||
down: new Layer(this.getLayer(spriteSheet, 1)),
|
down: new Layer(getLayer(spriteSheet, 1, this.spriteWidth)),
|
||||||
heartOne: new Layer(this.getLayer(spriteSheet, 2)),
|
heartOne: new Layer(getLayer(spriteSheet, 2, this.spriteWidth)),
|
||||||
heartTwo: new Layer(this.getLayer(spriteSheet, 3)),
|
heartTwo: new Layer(getLayer(spriteSheet, 3, this.spriteWidth)),
|
||||||
heartThree: new Layer(this.getLayer(spriteSheet, 4)),
|
heartThree: new Layer(getLayer(spriteSheet, 4, this.spriteWidth)),
|
||||||
tuftBase: new Layer(this.getLayer(spriteSheet, 5), "tuft"),
|
tuftBase: new Layer(getLayer(spriteSheet, 5, this.spriteWidth), "tuft"),
|
||||||
tuftDown: new Layer(this.getLayer(spriteSheet, 6), "tuft"),
|
tuftDown: new Layer(getLayer(spriteSheet, 6, this.spriteWidth), "tuft"),
|
||||||
wingsUp: new Layer(this.getLayer(spriteSheet, 7)),
|
wingsUp: new Layer(getLayer(spriteSheet, 7, this.spriteWidth)),
|
||||||
wingsDown: new Layer(this.getLayer(spriteSheet, 8)),
|
wingsDown: new Layer(getLayer(spriteSheet, 8, this.spriteWidth)),
|
||||||
happyEye: new Layer(this.getLayer(spriteSheet, 9)),
|
happyEye: new Layer(getLayer(spriteSheet, 9, this.spriteWidth)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build frames from layers
|
// Build frames from layers
|
||||||
@@ -632,21 +648,6 @@
|
|||||||
return anim.draw(this.ctx, this.direction, this.animStart, this.canvasPixelSize, species);
|
return anim.draw(this.ctx, this.direction, this.animStart, this.canvasPixelSize, species);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a layer from the sprite sheet array
|
|
||||||
* @param {string[][]} array
|
|
||||||
* @param {number} sprite
|
|
||||||
* @returns {string[][]}
|
|
||||||
*/
|
|
||||||
getLayer(array, sprite) {
|
|
||||||
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
|
||||||
const layer = [];
|
|
||||||
for (let y = 0; y < this.spriteWidth; y++) {
|
|
||||||
layer.push(array[y].slice(sprite * this.spriteWidth, (sprite + 1) * this.spriteWidth));
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {AnimationType} The current animation key
|
* @returns {AnimationType} The current animation key
|
||||||
*/
|
*/
|
||||||
@@ -1067,7 +1068,7 @@
|
|||||||
}
|
}
|
||||||
const content = menu.querySelector(".birb-window-content");
|
const content = menu.querySelector(".birb-window-content");
|
||||||
if (!content) {
|
if (!content) {
|
||||||
console.error("Birb: Content not found");
|
error("Birb: Content not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
content.innerHTML = "";
|
content.innerHTML = "";
|
||||||
@@ -2183,21 +2184,6 @@
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string[][]} array
|
|
||||||
* @param {number} sprite
|
|
||||||
* @param {number} [width]
|
|
||||||
* @returns {string[][]}
|
|
||||||
*/
|
|
||||||
function getLayer(array, sprite, width = SPRITE_WIDTH) {
|
|
||||||
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
|
||||||
const layer = [];
|
|
||||||
for (let y = 0; y < width; y++) {
|
|
||||||
layer.push(array[y].slice(sprite * width, (sprite + 1) * width));
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the birds location from the start to the target location on a parabolic path
|
* Update the birds location from the start to the target location on a parabolic path
|
||||||
* @param {number} speed The speed of the bird along the path
|
* @param {number} speed The speed of the bird along the path
|
||||||
@@ -2255,7 +2241,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function focusOnGround() {
|
function focusOnGround() {
|
||||||
console.log("Focusing on ground");
|
|
||||||
focusedElement = null;
|
focusedElement = null;
|
||||||
focusedBounds = { left: 0, right: window.innerWidth, top: getSafeWindowHeight() };
|
focusedBounds = { left: 0, right: window.innerWidth, top: getSafeWindowHeight() };
|
||||||
flyTo(Math.random() * window.innerWidth, 0);
|
flyTo(Math.random() * window.innerWidth, 0);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "Pocket Bird",
|
"name": "Pocket Bird",
|
||||||
"description": "It's a bird, in your browser. What more could you want?",
|
"description": "It's a bird, in your browser. What more could you want?",
|
||||||
"version": "2025.10.26.388",
|
"version": "2025.10.26.402",
|
||||||
"homepage_url": "https://idreesinc.com",
|
"homepage_url": "https://idreesinc.com",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import {
|
|||||||
isMobile,
|
isMobile,
|
||||||
log,
|
log,
|
||||||
debug,
|
debug,
|
||||||
error
|
error,
|
||||||
|
getLayer
|
||||||
} from './shared.js';
|
} from './shared.js';
|
||||||
import {
|
import {
|
||||||
SPRITE,
|
SPRITE,
|
||||||
@@ -802,21 +803,6 @@ Promise.all([
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string[][]} array
|
|
||||||
* @param {number} sprite
|
|
||||||
* @param {number} [width]
|
|
||||||
* @returns {string[][]}
|
|
||||||
*/
|
|
||||||
function getLayer(array, sprite, width = SPRITE_WIDTH) {
|
|
||||||
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
|
||||||
const layer = [];
|
|
||||||
for (let y = 0; y < width; y++) {
|
|
||||||
layer.push(array[y].slice(sprite * width, (sprite + 1) * width));
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the birds location from the start to the target location on a parabolic path
|
* Update the birds location from the start to the target location on a parabolic path
|
||||||
* @param {number} speed The speed of the bird along the path
|
* @param {number} speed The speed of the bird along the path
|
||||||
@@ -874,7 +860,6 @@ Promise.all([
|
|||||||
}
|
}
|
||||||
|
|
||||||
function focusOnGround() {
|
function focusOnGround() {
|
||||||
console.log("Focusing on ground");
|
|
||||||
focusedElement = null;
|
focusedElement = null;
|
||||||
focusedBounds = { left: 0, right: window.innerWidth, top: getSafeWindowHeight() };
|
focusedBounds = { left: 0, right: window.innerWidth, top: getSafeWindowHeight() };
|
||||||
flyTo(Math.random() * window.innerWidth, 0);
|
flyTo(Math.random() * window.innerWidth, 0);
|
||||||
|
|||||||
37
src/birb.js
37
src/birb.js
@@ -1,4 +1,4 @@
|
|||||||
import { Directions } from './shared.js';
|
import { Directions, getLayer } from './shared.js';
|
||||||
import Layer from './layer.js';
|
import Layer from './layer.js';
|
||||||
import Frame from './frame.js';
|
import Frame from './frame.js';
|
||||||
import Anim from './anim.js';
|
import Anim from './anim.js';
|
||||||
@@ -41,16 +41,16 @@ export class Birb {
|
|||||||
|
|
||||||
// Build layers from sprite sheet
|
// Build layers from sprite sheet
|
||||||
this.layers = {
|
this.layers = {
|
||||||
base: new Layer(this.getLayer(spriteSheet, 0)),
|
base: new Layer(getLayer(spriteSheet, 0, this.spriteWidth)),
|
||||||
down: new Layer(this.getLayer(spriteSheet, 1)),
|
down: new Layer(getLayer(spriteSheet, 1, this.spriteWidth)),
|
||||||
heartOne: new Layer(this.getLayer(spriteSheet, 2)),
|
heartOne: new Layer(getLayer(spriteSheet, 2, this.spriteWidth)),
|
||||||
heartTwo: new Layer(this.getLayer(spriteSheet, 3)),
|
heartTwo: new Layer(getLayer(spriteSheet, 3, this.spriteWidth)),
|
||||||
heartThree: new Layer(this.getLayer(spriteSheet, 4)),
|
heartThree: new Layer(getLayer(spriteSheet, 4, this.spriteWidth)),
|
||||||
tuftBase: new Layer(this.getLayer(spriteSheet, 5), "tuft"),
|
tuftBase: new Layer(getLayer(spriteSheet, 5, this.spriteWidth), "tuft"),
|
||||||
tuftDown: new Layer(this.getLayer(spriteSheet, 6), "tuft"),
|
tuftDown: new Layer(getLayer(spriteSheet, 6, this.spriteWidth), "tuft"),
|
||||||
wingsUp: new Layer(this.getLayer(spriteSheet, 7)),
|
wingsUp: new Layer(getLayer(spriteSheet, 7, this.spriteWidth)),
|
||||||
wingsDown: new Layer(this.getLayer(spriteSheet, 8)),
|
wingsDown: new Layer(getLayer(spriteSheet, 8, this.spriteWidth)),
|
||||||
happyEye: new Layer(this.getLayer(spriteSheet, 9)),
|
happyEye: new Layer(getLayer(spriteSheet, 9, this.spriteWidth)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build frames from layers
|
// Build frames from layers
|
||||||
@@ -130,21 +130,6 @@ export class Birb {
|
|||||||
return anim.draw(this.ctx, this.direction, this.animStart, this.canvasPixelSize, species);
|
return anim.draw(this.ctx, this.direction, this.animStart, this.canvasPixelSize, species);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a layer from the sprite sheet array
|
|
||||||
* @param {string[][]} array
|
|
||||||
* @param {number} sprite
|
|
||||||
* @returns {string[][]}
|
|
||||||
*/
|
|
||||||
getLayer(array, sprite) {
|
|
||||||
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
|
||||||
const layer = [];
|
|
||||||
for (let y = 0; y < this.spriteWidth; y++) {
|
|
||||||
layer.push(array[y].slice(sprite * this.spriteWidth, (sprite + 1) * this.spriteWidth));
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {AnimationType} The current animation key
|
* @returns {AnimationType} The current animation key
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import {
|
|||||||
makeElement,
|
makeElement,
|
||||||
onClick,
|
onClick,
|
||||||
makeDraggable,
|
makeDraggable,
|
||||||
makeClosable
|
makeClosable,
|
||||||
|
error
|
||||||
} from './shared.js';
|
} from './shared.js';
|
||||||
|
|
||||||
export const MENU_ID = "birb-menu";
|
export const MENU_ID = "birb-menu";
|
||||||
@@ -124,7 +125,7 @@ export function switchMenuItems(menuItems, updateLocationCallback) {
|
|||||||
}
|
}
|
||||||
const content = menu.querySelector(".birb-window-content");
|
const content = menu.querySelector(".birb-window-content");
|
||||||
if (!content) {
|
if (!content) {
|
||||||
console.error("Birb: Content not found");
|
error("Birb: Content not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
content.innerHTML = "";
|
content.innerHTML = "";
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export function makeDraggable(element, parent = true, callback = () => { }) {
|
|||||||
let elementToMove = parent ? element.parentElement : element;
|
let elementToMove = parent ? element.parentElement : element;
|
||||||
|
|
||||||
if (!elementToMove) {
|
if (!elementToMove) {
|
||||||
console.error("Birb: Parent element not found");
|
error("Birb: Parent element not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,4 +166,20 @@ export function debug() {
|
|||||||
|
|
||||||
export function error() {
|
export function error() {
|
||||||
console.error("Birb: ", ...arguments);
|
console.error("Birb: ", ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a layer from a sprite sheet array
|
||||||
|
* @param {string[][]} spriteSheet The sprite sheet pixel array
|
||||||
|
* @param {number} spriteIndex The sprite index
|
||||||
|
* @param {number} width The width of each sprite
|
||||||
|
* @returns {string[][]}
|
||||||
|
*/
|
||||||
|
export function getLayer(spriteSheet, spriteIndex, width) {
|
||||||
|
// From an array of a horizontal sprite sheet, get the layer for a specific sprite
|
||||||
|
const layer = [];
|
||||||
|
for (let y = 0; y < width; y++) {
|
||||||
|
layer.push(spriteSheet[y].slice(spriteIndex * width, (spriteIndex + 1) * width));
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user