mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 19:59:38 +00:00
Add user settings
This commit is contained in:
45
birb.js
45
birb.js
@@ -35,6 +35,17 @@ const MENU_EXIT_ID = "birb-menu-exit";
|
|||||||
const FIELD_GUIDE_ID = "birb-field-guide";
|
const FIELD_GUIDE_ID = "birb-field-guide";
|
||||||
const FEATHER_ID = "birb-feather";
|
const FEATHER_ID = "birb-feather";
|
||||||
|
|
||||||
|
|
||||||
|
const DEFAULT_SETTINGS = {
|
||||||
|
birbMode: false
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
||||||
|
*/
|
||||||
|
|
||||||
|
let userSettings = {};
|
||||||
|
|
||||||
const styles = `
|
const styles = `
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Monocraft;
|
font-family: Monocraft;
|
||||||
@@ -845,11 +856,11 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
new MenuItem("Pet Birb", pet),
|
new MenuItem(`Pet ${birdBirb()}`, pet),
|
||||||
new MenuItem("Field Guide", insertFieldGuide),
|
new MenuItem("Field Guide", insertFieldGuide),
|
||||||
// new MenuItem("Decorations", insertDecoration),
|
// new MenuItem("Decorations", insertDecoration),
|
||||||
new DebugMenuItem("Applications", () => switchMenuItems(otherItems), false),
|
new DebugMenuItem("Applications", () => switchMenuItems(otherItems), false),
|
||||||
new MenuItem("Hide Birb", hideBirb),
|
new MenuItem(`Hide ${birdBirb()}`, hideBirb),
|
||||||
new DebugMenuItem("Reset Data", resetSaveData),
|
new DebugMenuItem("Reset Data", resetSaveData),
|
||||||
new DebugMenuItem("Unlock All", () => {
|
new DebugMenuItem("Unlock All", () => {
|
||||||
for (let type in species) {
|
for (let type in species) {
|
||||||
@@ -952,7 +963,11 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
} else {
|
} else {
|
||||||
log("Not a UserScript");
|
log("Not a UserScript");
|
||||||
}
|
}
|
||||||
log("Loaded data: " + JSON.stringify(saveData));
|
debug("Loaded data: " + JSON.stringify(saveData));
|
||||||
|
if (!saveData.settings) {
|
||||||
|
log("No user settings found in save data, starting fresh");
|
||||||
|
}
|
||||||
|
userSettings = saveData.settings ?? {};
|
||||||
unlockedSpecies = saveData.unlockedSpecies ?? [DEFAULT_BIRD];
|
unlockedSpecies = saveData.unlockedSpecies ?? [DEFAULT_BIRD];
|
||||||
currentSpecies = saveData.currentSpecies ?? DEFAULT_BIRD;
|
currentSpecies = saveData.currentSpecies ?? DEFAULT_BIRD;
|
||||||
switchSpecies(currentSpecies);
|
switchSpecies(currentSpecies);
|
||||||
@@ -962,6 +977,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
let saveData = {
|
let saveData = {
|
||||||
unlockedSpecies: unlockedSpecies,
|
unlockedSpecies: unlockedSpecies,
|
||||||
currentSpecies: currentSpecies,
|
currentSpecies: currentSpecies,
|
||||||
|
settings: userSettings
|
||||||
};
|
};
|
||||||
if (isUserScript()) {
|
if (isUserScript()) {
|
||||||
log("Saving data to UserScript storage");
|
log("Saving data to UserScript storage");
|
||||||
@@ -989,6 +1005,21 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user settings merged with default settings
|
||||||
|
* @returns {Settings} The merged settings
|
||||||
|
*/
|
||||||
|
function settings() {
|
||||||
|
return { ...DEFAULT_SETTINGS, ...userSettings };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bird or birb, you decide
|
||||||
|
*/
|
||||||
|
function birdBirb() {
|
||||||
|
return settings().birbMode ? "Birb" : "Bird";
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (window !== window.top) {
|
if (window !== window.top) {
|
||||||
// Skip installation if within an iframe
|
// Skip installation if within an iframe
|
||||||
@@ -1446,7 +1477,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
let menu = makeElement("birb-window", undefined, MENU_ID);
|
let menu = makeElement("birb-window", undefined, MENU_ID);
|
||||||
let header = makeElement("birb-window-header");
|
let header = makeElement("birb-window-header");
|
||||||
header.innerHTML = '<div class="birb-window-title">birbOS</div>';
|
header.innerHTML = `<div class="birb-window-title">${birdBirb().toLowerCase()}OS</div>`;
|
||||||
let content = makeElement("birb-window-content");
|
let content = makeElement("birb-window-content");
|
||||||
for (const item of menuItems) {
|
for (const item of menuItems) {
|
||||||
if (!item.isDebug || debugMode) {
|
if (!item.isDebug || debugMode) {
|
||||||
@@ -1856,6 +1887,12 @@ function log() {
|
|||||||
console.log("Birb: ", ...arguments);
|
console.log("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debug() {
|
||||||
|
if (debugMode) {
|
||||||
|
console.debug("Birb: ", ...arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
console.error("Birb: ", ...arguments);
|
console.error("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
45
dist/birb.js
vendored
45
dist/birb.js
vendored
@@ -35,6 +35,17 @@ const MENU_EXIT_ID = "birb-menu-exit";
|
|||||||
const FIELD_GUIDE_ID = "birb-field-guide";
|
const FIELD_GUIDE_ID = "birb-field-guide";
|
||||||
const FEATHER_ID = "birb-feather";
|
const FEATHER_ID = "birb-feather";
|
||||||
|
|
||||||
|
|
||||||
|
const DEFAULT_SETTINGS = {
|
||||||
|
birbMode: false
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
||||||
|
*/
|
||||||
|
|
||||||
|
let userSettings = {};
|
||||||
|
|
||||||
const styles = `
|
const styles = `
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Monocraft;
|
font-family: Monocraft;
|
||||||
@@ -845,11 +856,11 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
new MenuItem("Pet Birb", pet),
|
new MenuItem(`Pet ${birdBirb()}`, pet),
|
||||||
new MenuItem("Field Guide", insertFieldGuide),
|
new MenuItem("Field Guide", insertFieldGuide),
|
||||||
// new MenuItem("Decorations", insertDecoration),
|
// new MenuItem("Decorations", insertDecoration),
|
||||||
new DebugMenuItem("Applications", () => switchMenuItems(otherItems), false),
|
new DebugMenuItem("Applications", () => switchMenuItems(otherItems), false),
|
||||||
new MenuItem("Hide Birb", hideBirb),
|
new MenuItem(`Hide ${birdBirb()}`, hideBirb),
|
||||||
new DebugMenuItem("Reset Data", resetSaveData),
|
new DebugMenuItem("Reset Data", resetSaveData),
|
||||||
new DebugMenuItem("Unlock All", () => {
|
new DebugMenuItem("Unlock All", () => {
|
||||||
for (let type in species) {
|
for (let type in species) {
|
||||||
@@ -952,7 +963,11 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
} else {
|
} else {
|
||||||
log("Not a UserScript");
|
log("Not a UserScript");
|
||||||
}
|
}
|
||||||
log("Loaded data: " + JSON.stringify(saveData));
|
debug("Loaded data: " + JSON.stringify(saveData));
|
||||||
|
if (!saveData.settings) {
|
||||||
|
log("No user settings found in save data, starting fresh");
|
||||||
|
}
|
||||||
|
userSettings = saveData.settings ?? {};
|
||||||
unlockedSpecies = saveData.unlockedSpecies ?? [DEFAULT_BIRD];
|
unlockedSpecies = saveData.unlockedSpecies ?? [DEFAULT_BIRD];
|
||||||
currentSpecies = saveData.currentSpecies ?? DEFAULT_BIRD;
|
currentSpecies = saveData.currentSpecies ?? DEFAULT_BIRD;
|
||||||
switchSpecies(currentSpecies);
|
switchSpecies(currentSpecies);
|
||||||
@@ -962,6 +977,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
let saveData = {
|
let saveData = {
|
||||||
unlockedSpecies: unlockedSpecies,
|
unlockedSpecies: unlockedSpecies,
|
||||||
currentSpecies: currentSpecies,
|
currentSpecies: currentSpecies,
|
||||||
|
settings: userSettings
|
||||||
};
|
};
|
||||||
if (isUserScript()) {
|
if (isUserScript()) {
|
||||||
log("Saving data to UserScript storage");
|
log("Saving data to UserScript storage");
|
||||||
@@ -989,6 +1005,21 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user settings merged with default settings
|
||||||
|
* @returns {Settings} The merged settings
|
||||||
|
*/
|
||||||
|
function settings() {
|
||||||
|
return { ...DEFAULT_SETTINGS, ...userSettings };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bird or birb, you decide
|
||||||
|
*/
|
||||||
|
function birdBirb() {
|
||||||
|
return settings().birbMode ? "Birb" : "Bird";
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (window !== window.top) {
|
if (window !== window.top) {
|
||||||
// Skip installation if within an iframe
|
// Skip installation if within an iframe
|
||||||
@@ -1446,7 +1477,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
let menu = makeElement("birb-window", undefined, MENU_ID);
|
let menu = makeElement("birb-window", undefined, MENU_ID);
|
||||||
let header = makeElement("birb-window-header");
|
let header = makeElement("birb-window-header");
|
||||||
header.innerHTML = '<div class="birb-window-title">birbOS</div>';
|
header.innerHTML = `<div class="birb-window-title">${birdBirb().toLowerCase()}OS</div>`;
|
||||||
let content = makeElement("birb-window-content");
|
let content = makeElement("birb-window-content");
|
||||||
for (const item of menuItems) {
|
for (const item of menuItems) {
|
||||||
if (!item.isDebug || debugMode) {
|
if (!item.isDebug || debugMode) {
|
||||||
@@ -1856,6 +1887,12 @@ function log() {
|
|||||||
console.log("Birb: ", ...arguments);
|
console.log("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debug() {
|
||||||
|
if (debugMode) {
|
||||||
|
console.debug("Birb: ", ...arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
console.error("Birb: ", ...arguments);
|
console.error("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
45
dist/birb.user.js
vendored
45
dist/birb.user.js
vendored
@@ -48,6 +48,17 @@ const MENU_EXIT_ID = "birb-menu-exit";
|
|||||||
const FIELD_GUIDE_ID = "birb-field-guide";
|
const FIELD_GUIDE_ID = "birb-field-guide";
|
||||||
const FEATHER_ID = "birb-feather";
|
const FEATHER_ID = "birb-feather";
|
||||||
|
|
||||||
|
|
||||||
|
const DEFAULT_SETTINGS = {
|
||||||
|
birbMode: false
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
||||||
|
*/
|
||||||
|
|
||||||
|
let userSettings = {};
|
||||||
|
|
||||||
const styles = `
|
const styles = `
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Monocraft;
|
font-family: Monocraft;
|
||||||
@@ -858,11 +869,11 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
new MenuItem("Pet Birb", pet),
|
new MenuItem(`Pet ${birdBirb()}`, pet),
|
||||||
new MenuItem("Field Guide", insertFieldGuide),
|
new MenuItem("Field Guide", insertFieldGuide),
|
||||||
// new MenuItem("Decorations", insertDecoration),
|
// new MenuItem("Decorations", insertDecoration),
|
||||||
new DebugMenuItem("Applications", () => switchMenuItems(otherItems), false),
|
new DebugMenuItem("Applications", () => switchMenuItems(otherItems), false),
|
||||||
new MenuItem("Hide Birb", hideBirb),
|
new MenuItem(`Hide ${birdBirb()}`, hideBirb),
|
||||||
new DebugMenuItem("Reset Data", resetSaveData),
|
new DebugMenuItem("Reset Data", resetSaveData),
|
||||||
new DebugMenuItem("Unlock All", () => {
|
new DebugMenuItem("Unlock All", () => {
|
||||||
for (let type in species) {
|
for (let type in species) {
|
||||||
@@ -965,7 +976,11 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
} else {
|
} else {
|
||||||
log("Not a UserScript");
|
log("Not a UserScript");
|
||||||
}
|
}
|
||||||
log("Loaded data: " + JSON.stringify(saveData));
|
debug("Loaded data: " + JSON.stringify(saveData));
|
||||||
|
if (!saveData.settings) {
|
||||||
|
log("No user settings found in save data, starting fresh");
|
||||||
|
}
|
||||||
|
userSettings = saveData.settings ?? {};
|
||||||
unlockedSpecies = saveData.unlockedSpecies ?? [DEFAULT_BIRD];
|
unlockedSpecies = saveData.unlockedSpecies ?? [DEFAULT_BIRD];
|
||||||
currentSpecies = saveData.currentSpecies ?? DEFAULT_BIRD;
|
currentSpecies = saveData.currentSpecies ?? DEFAULT_BIRD;
|
||||||
switchSpecies(currentSpecies);
|
switchSpecies(currentSpecies);
|
||||||
@@ -975,6 +990,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
let saveData = {
|
let saveData = {
|
||||||
unlockedSpecies: unlockedSpecies,
|
unlockedSpecies: unlockedSpecies,
|
||||||
currentSpecies: currentSpecies,
|
currentSpecies: currentSpecies,
|
||||||
|
settings: userSettings
|
||||||
};
|
};
|
||||||
if (isUserScript()) {
|
if (isUserScript()) {
|
||||||
log("Saving data to UserScript storage");
|
log("Saving data to UserScript storage");
|
||||||
@@ -1002,6 +1018,21 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user settings merged with default settings
|
||||||
|
* @returns {Settings} The merged settings
|
||||||
|
*/
|
||||||
|
function settings() {
|
||||||
|
return { ...DEFAULT_SETTINGS, ...userSettings };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bird or birb, you decide
|
||||||
|
*/
|
||||||
|
function birdBirb() {
|
||||||
|
return settings().birbMode ? "Birb" : "Bird";
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (window !== window.top) {
|
if (window !== window.top) {
|
||||||
// Skip installation if within an iframe
|
// Skip installation if within an iframe
|
||||||
@@ -1459,7 +1490,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
let menu = makeElement("birb-window", undefined, MENU_ID);
|
let menu = makeElement("birb-window", undefined, MENU_ID);
|
||||||
let header = makeElement("birb-window-header");
|
let header = makeElement("birb-window-header");
|
||||||
header.innerHTML = '<div class="birb-window-title">birbOS</div>';
|
header.innerHTML = `<div class="birb-window-title">${birdBirb().toLowerCase()}OS</div>`;
|
||||||
let content = makeElement("birb-window-content");
|
let content = makeElement("birb-window-content");
|
||||||
for (const item of menuItems) {
|
for (const item of menuItems) {
|
||||||
if (!item.isDebug || debugMode) {
|
if (!item.isDebug || debugMode) {
|
||||||
@@ -1869,6 +1900,12 @@ function log() {
|
|||||||
console.log("Birb: ", ...arguments);
|
console.log("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debug() {
|
||||||
|
if (debugMode) {
|
||||||
|
console.debug("Birb: ", ...arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
console.error("Birb: ", ...arguments);
|
console.error("Birb: ", ...arguments);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user