start moving towards collections

This commit is contained in:
Zack Rauen 2019-06-06 00:28:43 -04:00
parent 671ea2a24d
commit c14d21eab4
22 changed files with 228 additions and 130 deletions

View File

@ -81,6 +81,10 @@
order: 3;
}
.bd-settings-title.bd-settings-group-title {
margin-bottom: 10px;
}

View File

@ -105,12 +105,12 @@ __webpack_require__.r(__webpack_exports__);
return "24Hour";
}
get group() {
get category() {
return "general";
}
get id() {
return "bda-gs-6";
return "twentyFourHour";
}
enabled() {
@ -230,10 +230,10 @@ const normalizedPrefix = "da";
const randClass = new RegExp(`^(?!${normalizedPrefix}-)((?:[A-Za-z]|[0-9]|-)+)-(?:[A-Za-z]|[0-9]|-|_){6}$`);
/* harmony default export */ __webpack_exports__["default"] = (new class ClassNormalizer extends _structs_builtin__WEBPACK_IMPORTED_MODULE_0__["default"] {
get id() {
return "fork-ps-4";
return "classNormalizer";
}
get group() {
get category() {
return "general";
}
@ -375,7 +375,7 @@ const MessageContent = modules__WEBPACK_IMPORTED_MODULE_1__["WebpackModules"].ge
return "ColoredText";
}
get group() {
get category() {
return "appearance";
}
@ -440,12 +440,12 @@ __webpack_require__.r(__webpack_exports__);
return "DarkMode";
}
get group() {
get category() {
return "appearance";
}
get id() {
return "bda-gs-5";
return "darkMode";
}
enabled() {
@ -480,16 +480,16 @@ __webpack_require__.r(__webpack_exports__);
return "DeveloperMode";
}
get group() {
get category() {
return "developer";
}
get id() {
return "bda-gs-8";
return "developerMode";
}
get selectorModeID() {
return "fork-dm-1";
return "copySelector";
}
get selectorMode() {
@ -616,16 +616,16 @@ __webpack_require__.r(__webpack_exports__);
return "EmoteAutocapitalize";
}
get category() {
get collection() {
return "emotes";
}
get group() {
return "preferences";
get category() {
return "general";
}
get id() {
return "bda-es-4";
return "autoCaps";
}
enabled() {
@ -721,20 +721,20 @@ const makeEmote = (emote, url, options = {}) => {
return "EmoteMenu";
}
get category() {
get collection() {
return "emotes";
}
get group() {
return "preferences";
get category() {
return "general";
}
get id() {
return "bda-es-0";
return "emoteMenu";
}
get hideEmojisID() {
return "bda-es-9";
return "hideEmojiMenu";
}
get hideEmojis() {
@ -947,12 +947,12 @@ const bdEmoteSettingIDs = {
return "Emotes";
}
get category() {
get collection() {
return "emotes";
}
get group() {
return "preferences";
get category() {
return "general";
}
get id() {
@ -1239,16 +1239,16 @@ __webpack_require__.r(__webpack_exports__);
return "MinimalMode";
}
get group() {
get category() {
return "appearance";
}
get id() {
return "bda-gs-2";
return "minimalMode";
}
get hideChannelsID() {
return "bda-gs-3";
return "hideChannels";
}
get hideChannels() {
@ -1307,12 +1307,12 @@ __webpack_require__.r(__webpack_exports__);
return "PublicServers";
}
get group() {
get category() {
return "general";
}
get id() {
return "bda-gs-1";
return "publicServers";
}
enabled() {
@ -1401,12 +1401,12 @@ __webpack_require__.r(__webpack_exports__);
return "VoiceDisconnect";
}
get group() {
get category() {
return "general";
}
get id() {
return "bda-dc-0";
return "voiceDisconnect";
}
constructor() {
@ -1446,12 +1446,12 @@ __webpack_require__.r(__webpack_exports__);
return "VoiceMode";
}
get group() {
get category() {
return "appearance";
}
get id() {
return "bda-gs-4";
return "voiceMode";
}
enabled() {
@ -1572,11 +1572,12 @@ __webpack_require__.r(__webpack_exports__);
/*!**************************!*\
!*** ./src/data/data.js ***!
\**************************/
/*! exports provided: State, SettingsInfo, SettingsCookie, Config, PluginCookie, ThemeCookie, Themes, Plugins, Emotes, EmoteBlacklist, EmoteInfo, EmoteModifiers, EmoteOverrides */
/*! exports provided: Collections, State, SettingsInfo, SettingsCookie, Config, PluginCookie, ThemeCookie, Themes, Plugins, Emotes, EmoteBlacklist, EmoteInfo, EmoteModifiers, EmoteOverrides */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Collections", function() { return Collections; });
/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./state */ "./src/data/state.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "State", function() { return _state__WEBPACK_IMPORTED_MODULE_0__["default"]; });
@ -1616,6 +1617,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _emotes_overrides__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./emotes/overrides */ "./src/data/emotes/overrides.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EmoteOverrides", function() { return _emotes_overrides__WEBPACK_IMPORTED_MODULE_12__["default"]; });
/* harmony import */ var _settings_config__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./settings/config */ "./src/data/settings/config.js");
/* harmony import */ var _emotes_config__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./emotes/config */ "./src/data/emotes/config.js");
@ -1631,6 +1634,9 @@ __webpack_require__.r(__webpack_exports__);
const Collections = [_settings_config__WEBPACK_IMPORTED_MODULE_13__["default"], _emotes_config__WEBPACK_IMPORTED_MODULE_14__["default"]];
/***/ }),
/***/ "./src/data/emotes/blacklist.js":
@ -1657,8 +1663,8 @@ __webpack_require__.r(__webpack_exports__);
__webpack_require__.r(__webpack_exports__);
/* harmony default export */ __webpack_exports__["default"] = ([{
type: "category",
id: "preferences",
name: "Preferences",
id: "general",
name: "General",
collapsible: true,
settings: [{
type: "switch",
@ -2136,6 +2142,12 @@ __webpack_require__.r(__webpack_exports__);
name: "General",
collapsible: true,
settings: [{
type: "switch",
id: "emotes",
name: "Emote System",
note: "Enables BD's emote system",
value: true
}, {
type: "switch",
id: "publicServers",
name: "Public Servers",
@ -3856,6 +3868,8 @@ __webpack_require__.r(__webpack_exports__);
this.renderer = new ui__WEBPACK_IMPORTED_MODULE_6__["SettingsPanel"]({
onChange: this.updateSettings.bind(this)
});
this.updateSettings = this.updateSettings.bind(this);
console.log(data__WEBPACK_IMPORTED_MODULE_0__["Collections"]);
}
initialize() {
@ -3905,11 +3919,11 @@ __webpack_require__.r(__webpack_exports__);
Object.assign(state, config);
}
buildSettingsPanel(config, state, onChange) {
buildSettingsPanel(title, config, state, onChange) {
config.forEach(section => {
section.settings.forEach(item => item.value = state[section.id][item.id]);
});
return this.renderer.getSettingsPanel(config, onChange);
return this.renderer.getSettingsPanel(title, config, onChange);
}
async patchSections() {
@ -3917,26 +3931,35 @@ __webpack_require__.r(__webpack_exports__);
_utilities__WEBPACK_IMPORTED_MODULE_7__["default"].monkeyPatch(UserSettings.prototype, "generateSections", {
after: data => {
// console.log(data); /* eslint-disable-line no-console */
data.returnValue.splice(23, 0, {
let location = data.returnValue.findIndex(s => s.section.toLowerCase() == "linux") + 1;
const insert = section => {
data.returnValue.splice(location, 0, section);
location++;
};
console.log(data);
/* eslint-disable-line no-console */
insert({
section: "DIVIDER"
});
data.returnValue.splice(24, 0, {
insert({
section: "HEADER",
label: "BandagedBD"
}); // data.returnValue.splice(25, 0, {section: "BBD Settings", label: "Settings", element: () => this.renderer.core2});
}); // insert({section: "BBD Settings", label: "Settings", element: () => this.renderer.core2});
data.returnValue.splice(25, 0, {
insert({
section: "BBD Settings",
label: "Settings",
element: () => this.buildSettingsPanel(_data_settings_config__WEBPACK_IMPORTED_MODULE_10__["default"], _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"], this.updateSettings)
element: () => this.buildSettingsPanel("Settings", _data_settings_config__WEBPACK_IMPORTED_MODULE_10__["default"], _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"], this.updateSettings.bind(this, _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"]))
});
data.returnValue.splice(26, 0, {
if (_data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"].general.emotes) insert({
section: "BBD Emotes",
label: "Emotes",
element: () => this.buildSettingsPanel(_data_emotes_config__WEBPACK_IMPORTED_MODULE_8__["default"], _data_emotes_state__WEBPACK_IMPORTED_MODULE_9__["default"], this.updateSettings)
element: () => this.buildSettingsPanel("Emote Settings", _data_emotes_config__WEBPACK_IMPORTED_MODULE_8__["default"], _data_emotes_state__WEBPACK_IMPORTED_MODULE_9__["default"], this.updateSettings.bind(this, _data_emotes_state__WEBPACK_IMPORTED_MODULE_9__["default"]))
});
data.returnValue.splice(27, 0, {
insert({
section: "BBD Test",
label: "Test Tab",
onClick: function () {
@ -3945,12 +3968,16 @@ __webpack_require__.r(__webpack_exports__);
});
}
});
data.returnValue.splice(28, 0, {
insert({
section: "CUSTOM",
element: () => this.renderer.attribution
});
}
});
this.forceUpdate();
}
forceUpdate() {
const viewClass = _webpackmodules__WEBPACK_IMPORTED_MODULE_5__["default"].getByProps("standardSidebarView").standardSidebarView.split(" ")[0];
const node = document.querySelector(`.${viewClass}`);
_utilities__WEBPACK_IMPORTED_MODULE_7__["default"].getInternalInstance(node).return.return.return.return.return.return.stateNode.forceUpdate();
@ -3976,16 +4003,33 @@ __webpack_require__.r(__webpack_exports__);
return _datastore__WEBPACK_IMPORTED_MODULE_1__["default"].getSettingGroup("settings");
}
updateSettings(id, enabled) {
if (arguments.length == 3) {
_data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"][arguments[0]][arguments[1]] = arguments[2];
_emitter__WEBPACK_IMPORTED_MODULE_4__["default"].dispatch("setting-updated", arguments[0], arguments[1], arguments[2]);
console.log(_data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"]);
return;
}
onSettingChange(collection, category, id, enabled) {
collection[category][id] = enabled;
_emitter__WEBPACK_IMPORTED_MODULE_4__["default"].dispatch("setting-updated", category, id, enabled); // console.log(collection);
_emitter__WEBPACK_IMPORTED_MODULE_4__["default"].dispatch("setting-updated", "Modules", id, enabled);
data__WEBPACK_IMPORTED_MODULE_0__["SettingsCookie"][id] = enabled; // if (id == "bda-es-4") {
if (id == "emotes") this.forceUpdate();
}
getSetting(category, id) {
if (arguments.length == 2) return _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"][category][id];
const collection = arguments[0] == "emotes" ? _data_emotes_state__WEBPACK_IMPORTED_MODULE_9__["default"] : _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"];
return collection && collection[arguments[1]][arguments[2]];
}
get(category, id) {
if (arguments.length == 2) return _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"][category][id];
const collection = arguments[0] == "emotes" ? _data_emotes_state__WEBPACK_IMPORTED_MODULE_9__["default"] : _data_settings_state__WEBPACK_IMPORTED_MODULE_11__["default"];
return collection && collection[arguments[1]][arguments[2]];
}
updateSettings(collection, category, id, enabled) {
// console.log("Updating ", collection);
// console.log(category, id, enabled);
collection[category][id] = enabled;
_emitter__WEBPACK_IMPORTED_MODULE_4__["default"].dispatch("setting-updated", category, id, enabled); // console.log(collection);
if (id == "emotes") this.forceUpdate(); // SettingsCookie[id] = enabled;
// if (id == "bda-es-4") {
// if (enabled) EmoteModule.autoCapitalize();
// else EmoteModule.disableAutoCapitalize();
// }
@ -4003,9 +4047,8 @@ __webpack_require__.r(__webpack_exports__);
if (id == "fork-wp-1") {
_pluginapi__WEBPACK_IMPORTED_MODULE_3__["default"].setWindowPreference("transparent", enabled);
if (enabled) _pluginapi__WEBPACK_IMPORTED_MODULE_3__["default"].setWindowPreference("backgroundColor", null);else _pluginapi__WEBPACK_IMPORTED_MODULE_3__["default"].setWindowPreference("backgroundColor", "#2f3136");
}
} // this.saveSettings();
this.saveSettings();
}
initializeSettings() {
@ -5189,11 +5232,11 @@ class BuiltinModule {
return "Unnamed Builtin";
}
get category() {
get collection() {
return "settings";
}
get group() {
get category() {
return "general";
}
@ -5202,10 +5245,10 @@ class BuiltinModule {
}
async initialize() {
const state = this.category == "settings" ? _data_settings_state__WEBPACK_IMPORTED_MODULE_1__["default"] : _data_emotes_state__WEBPACK_IMPORTED_MODULE_2__["default"];
if (state[this.group][this.id]) await this.enable();
_modules_emitter__WEBPACK_IMPORTED_MODULE_4__["default"].on("setting-updated", (group, id, enabled) => {
if (group !== this.group || id !== this.id) return;
const state = this.collection == "settings" ? _data_settings_state__WEBPACK_IMPORTED_MODULE_1__["default"] : _data_emotes_state__WEBPACK_IMPORTED_MODULE_2__["default"];
if (state[this.category][this.id]) await this.enable();
_modules_emitter__WEBPACK_IMPORTED_MODULE_4__["default"].on("setting-updated", (category, id, enabled) => {
if (category !== this.category || id !== this.id) return;
if (enabled) this.enable();else this.disable();
});
}
@ -6691,7 +6734,8 @@ class Group extends modules__WEBPACK_IMPORTED_MODULE_0__["React"].Component {
text: this.props.name,
collapsible: this.props.collapsible,
onClick: () => this.toggleCollapse(),
button: this.props.button
button: this.props.button,
isGroup: true
}), modules__WEBPACK_IMPORTED_MODULE_0__["React"].createElement("div", {
className: "bd-settings-container",
ref: this.container
@ -6731,6 +6775,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _ui__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../ui */ "./src/ui/ui.js");
/* harmony import */ var _data_settings_config__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../data/settings/config */ "./src/data/settings/config.js");
/* harmony import */ var _data_settings_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../data/settings/state */ "./src/data/settings/state.js");
/* harmony import */ var _title__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./title */ "./src/ui/settings/title.jsx");
// import Sidebar from "./sidebar";
// import Scroller from "../scroller";
@ -6749,6 +6794,7 @@ __webpack_require__.r(__webpack_exports__);
class V2_SettingsPanel {
constructor({
onChange
@ -6785,12 +6831,14 @@ class V2_SettingsPanel {
}, []);
}
getSettingsPanel(groups, onChange) {
return groups.map(section => {
getSettingsPanel(title, groups, onChange) {
return [modules__WEBPACK_IMPORTED_MODULE_1__["React"].createElement(_title__WEBPACK_IMPORTED_MODULE_6__["default"], {
text: title
}), groups.map(section => {
return modules__WEBPACK_IMPORTED_MODULE_1__["React"].createElement(_settings_group__WEBPACK_IMPORTED_MODULE_2__["default"], Object.assign({}, section, {
onChange
}));
});
})];
}
get core3() {
@ -7022,6 +7070,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var modules__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! modules */ "./src/modules/modules.js");
const className = "bd-settings-title h2-2gWE-o title-3sZWYQ size16-14cGz5 height20-mO2eIN weightSemiBold-NJexzi defaultColor-1_ajX0 defaultMarginh2-2LTaUL marginBottom20-32qID7";
const className2 = "bd-settings-title bd-settings-group-title h5-18_1nd title-3sZWYQ size12-3R0845 height16-2Lv3qA weightSemiBold-NJexzi da-h5 da-title da-size12 da-height16 da-weightSemiBold marginBottom4-2qk4Hy da-marginBottom4 marginTop8-1DLZ1n da-marginTop8";
class SettingsTitle extends modules__WEBPACK_IMPORTED_MODULE_0__["React"].Component {
constructor(props) {
super(props);
@ -7029,7 +7078,8 @@ class SettingsTitle extends modules__WEBPACK_IMPORTED_MODULE_0__["React"].Compon
render() {
const titleClass = this.props.className ? `${className} ${this.props.className}` : className;
const baseClass = this.props.isGroup ? className2 : className;
const titleClass = this.props.className ? `${baseClass} ${this.props.className}` : baseClass;
return modules__WEBPACK_IMPORTED_MODULE_0__["React"].createElement("h2", {
className: titleClass,
onClick: () => {

View File

@ -3,8 +3,8 @@ import {Utilities, DiscordModules} from "modules";
export default new class TwentyFourHour extends Builtin {
get name() {return "24Hour";}
get group() {return "general";}
get id() {return "bda-gs-6";}
get category() {return "general";}
get id() {return "twentyFourHour";}
enabled() {
this.inject24Hour();

View File

@ -5,8 +5,8 @@ const normalizedPrefix = "da";
const randClass = new RegExp(`^(?!${normalizedPrefix}-)((?:[A-Za-z]|[0-9]|-)+)-(?:[A-Za-z]|[0-9]|-|_){6}$`);
export default new class ClassNormalizer extends Builtin {
get id() {return "fork-ps-4";}
get group() {return "general";}
get id() {return "classNormalizer";}
get category() {return "general";}
get name() {return "ClassNormalizer";}
enabled() {

View File

@ -5,7 +5,7 @@ const MessageContent = WebpackModules.getModule(m => m.defaultProps && m.default
export default new class ColoredText extends Builtin {
get name() {return "ColoredText";}
get group() {return "appearance";}
get category() {return "appearance";}
get id() {return "coloredText";}
enabled() {

View File

@ -2,8 +2,8 @@ import Builtin from "../structs/builtin";
export default new class DarkMode extends Builtin {
get name() {return "DarkMode";}
get group() {return "appearance";}
get id() {return "bda-gs-5";}
get category() {return "appearance";}
get id() {return "darkMode";}
enabled() {
$("#app-mount").addClass("bda-dark").addClass("bd-dark");

View File

@ -4,9 +4,9 @@ import {DiscordModules} from "modules";
export default new class DeveloperMode extends Builtin {
get name() {return "DeveloperMode";}
get group() {return "developer";}
get id() {return "bda-gs-8";}
get selectorModeID() {return "fork-dm-1";}
get category() {return "developer";}
get id() {return "developerMode";}
get selectorModeID() {return "copySelector";}
get selectorMode() {return SettingsCookie[this.selectorModeID];}
constructor() {

View File

@ -5,9 +5,9 @@ import {Utilities} from "modules";
export default new class EmoteAutocaps extends Builtin {
get name() {return "EmoteAutocapitalize";}
get category() {return "emotes";}
get group() {return "preferences";}
get id() {return "bda-es-4";}
get collection() {return "emotes";}
get category() {return "general";}
get id() {return "autoCaps";}
enabled() {
$("body").off(".bdac");

View File

@ -40,10 +40,10 @@ const makeEmote = (emote, url, options = {}) => {
export default new class EmoteMenu extends Builtin {
get name() {return "EmoteMenu";}
get category() {return "emotes";}
get group() {return "preferences";}
get id() {return "bda-es-0";}
get hideEmojisID() {return "bda-es-9";}
get collection() {return "emotes";}
get category() {return "general";}
get id() {return "emoteMenu";}
get hideEmojisID() {return "hideEmojiMenu";}
get hideEmojis() {return SettingsCookie[this.hideEmojisID];}
constructor() {

View File

@ -15,8 +15,8 @@ const bdEmoteSettingIDs = {
export default new class EmoteModule extends Builtin {
get name() {return "Emotes";}
get category() {return "emotes";}
get group() {return "preferences";}
get collection() {return "emotes";}
get category() {return "general";}
get id() {return "";}
get categories() { return Object.keys(bdEmoteSettingIDs).filter(k => SettingsCookie[bdEmoteSettingIDs[k]]); }

View File

@ -3,9 +3,9 @@ import {SettingsCookie} from "data";
export default new class MinimalMode extends Builtin {
get name() {return "MinimalMode";}
get group() {return "appearance";}
get id() {return "bda-gs-2";}
get hideChannelsID() {return "bda-gs-3";}
get category() {return "appearance";}
get id() {return "minimalMode";}
get hideChannelsID() {return "hideChannels";}
get hideChannels() {return SettingsCookie[this.hideChannelsID];}
constructor() {

View File

@ -5,8 +5,8 @@ import {PublicServers as PSComponents} from "ui";
export default new class PublicServers extends Builtin {
get name() {return "PublicServers";}
get group() {return "general";}
get id() {return "bda-gs-1";}
get category() {return "general";}
get id() {return "publicServers";}
enabled() {
const wrapper = BDV2.guildClasses.wrapper.split(" ")[0];

View File

@ -3,8 +3,8 @@ import {DiscordModules} from "modules";
export default new class DarkMode extends Builtin {
get name() {return "VoiceDisconnect";}
get group() {return "general";}
get id() {return "bda-dc-0";}
get category() {return "general";}
get id() {return "voiceDisconnect";}
constructor() {
super();

View File

@ -2,8 +2,8 @@ import Builtin from "../structs/builtin";
export default new class VoiceMode extends Builtin {
get name() {return "VoiceMode";}
get group() {return "appearance";}
get id() {return "bda-gs-4";}
get category() {return "appearance";}
get id() {return "voiceMode";}
enabled() {
$(".scroller.guild-channels ul").first().css("display", "none");

View File

@ -12,4 +12,9 @@ import EmoteInfo from "./emotes/info";
import EmoteModifiers from "./emotes/modifiers";
import EmoteOverrides from "./emotes/overrides";
import SettingsCollection from "./settings/config";
import EmoteCollection from "./emotes/config";
export const Collections = [SettingsCollection, EmoteCollection];
export {State, SettingsInfo, SettingsCookie, Config, PluginCookie, ThemeCookie, Themes, Plugins, Emotes, EmoteBlacklist, EmoteInfo, EmoteModifiers, EmoteOverrides};

View File

@ -1,8 +1,8 @@
export default [
{
type: "category",
id: "preferences",
name: "Preferences",
id: "general",
name: "General",
collapsible: true,
settings: [
{

View File

@ -5,6 +5,13 @@ export default [
name: "General",
collapsible: true,
settings: [
{
type: "switch",
id: "emotes",
name: "Emote System",
note: "Enables BD's emote system",
value: true
},
{
type: "switch",
id: "publicServers",

View File

@ -1,4 +1,4 @@
import {SettingsCookie} from "data";
import {SettingsCookie, Collections} from "data";
import DataStore from "./datastore";
import ContentManager from "./contentmanager";
import BdApi from "./pluginapi";
@ -21,6 +21,8 @@ export default new class SettingsManager {
constructor() {
this.renderer = new SettingsRenderer({onChange: this.updateSettings.bind(this)});
this.updateSettings = this.updateSettings.bind(this);
console.log(Collections);
}
initialize() {
@ -63,25 +65,34 @@ export default new class SettingsManager {
Object.assign(state, config);
}
buildSettingsPanel(config, state, onChange) {
buildSettingsPanel(title, config, state, onChange) {
config.forEach(section => {
section.settings.forEach(item => item.value = state[section.id][item.id]);
});
return this.renderer.getSettingsPanel(config, onChange);
return this.renderer.getSettingsPanel(title, config, onChange);
}
async patchSections() {
const UserSettings = await this.getUserSettings(); // data.returnValue.type;
Utilities.monkeyPatch(UserSettings.prototype, "generateSections", {after: (data) => {
// console.log(data); /* eslint-disable-line no-console */
data.returnValue.splice(23, 0, {section: "DIVIDER"});
data.returnValue.splice(24, 0, {section: "HEADER", label: "BandagedBD"});
// data.returnValue.splice(25, 0, {section: "BBD Settings", label: "Settings", element: () => this.renderer.core2});
data.returnValue.splice(25, 0, {section: "BBD Settings", label: "Settings", element: () => this.buildSettingsPanel(TheSettings, SettingsState, this.updateSettings)});
data.returnValue.splice(26, 0, {section: "BBD Emotes", label: "Emotes", element: () => this.buildSettingsPanel(EmoteSettings, EmoteState, this.updateSettings)});
data.returnValue.splice(27, 0, {section: "BBD Test", label: "Test Tab", onClick: function() {Toasts.success("This can just be a click listener!", {forceShow: true});}});
data.returnValue.splice(28, 0, {section: "CUSTOM", element: () => this.renderer.attribution});
let location = data.returnValue.findIndex(s => s.section.toLowerCase() == "linux") + 1;
const insert = (section) => {
data.returnValue.splice(location, 0, section);
location++;
};
console.log(data); /* eslint-disable-line no-console */
insert({section: "DIVIDER"});
insert({section: "HEADER", label: "BandagedBD"});
// insert({section: "BBD Settings", label: "Settings", element: () => this.renderer.core2});
insert({section: "BBD Settings", label: "Settings", element: () => this.buildSettingsPanel("Settings", TheSettings, SettingsState, this.updateSettings.bind(this, SettingsState))});
if (SettingsState.general.emotes) insert({section: "BBD Emotes", label: "Emotes", element: () => this.buildSettingsPanel("Emote Settings", EmoteSettings, EmoteState, this.updateSettings.bind(this, EmoteState))});
insert({section: "BBD Test", label: "Test Tab", onClick: function() {Toasts.success("This can just be a click listener!", {forceShow: true});}});
insert({section: "CUSTOM", element: () => this.renderer.attribution});
}});
this.forceUpdate();
}
forceUpdate() {
const viewClass = WebpackModules.getByProps("standardSidebarView").standardSidebarView.split(" ")[0];
const node = document.querySelector(`.${viewClass}`);
Utilities.getInternalInstance(node).return.return.return.return.return.return.stateNode.forceUpdate();
@ -105,15 +116,33 @@ export default new class SettingsManager {
return DataStore.getSettingGroup("settings");
}
updateSettings(id, enabled) {
if (arguments.length == 3) {
SettingsState[arguments[0]][arguments[1]] = arguments[2];
Events.dispatch("setting-updated", arguments[0], arguments[1], arguments[2]);
console.log(SettingsState);
return;
}
Events.dispatch("setting-updated", "Modules", id, enabled);
SettingsCookie[id] = enabled;
onSettingChange(collection, category, id, enabled) {
collection[category][id] = enabled;
Events.dispatch("setting-updated", category, id, enabled);
// console.log(collection);
if (id == "emotes") this.forceUpdate();
}
getSetting(category, id) {
if (arguments.length == 2) return SettingsState[category][id];
const collection = arguments[0] == "emotes" ? EmoteState : SettingsState;
return collection && collection[arguments[1]][arguments[2]];
}
get(category, id) {
if (arguments.length == 2) return SettingsState[category][id];
const collection = arguments[0] == "emotes" ? EmoteState : SettingsState;
return collection && collection[arguments[1]][arguments[2]];
}
updateSettings(collection, category, id, enabled) {
// console.log("Updating ", collection);
// console.log(category, id, enabled);
collection[category][id] = enabled;
Events.dispatch("setting-updated", category, id, enabled);
// console.log(collection);
if (id == "emotes") this.forceUpdate();
// SettingsCookie[id] = enabled;
// if (id == "bda-es-4") {
@ -138,7 +167,7 @@ export default new class SettingsManager {
else BdApi.setWindowPreference("backgroundColor", "#2f3136");
}
this.saveSettings();
// this.saveSettings();
}
initializeSettings() {

View File

@ -17,15 +17,15 @@ export function onSettingChange(category, identifier, onEnable, onDisable) {
export default class BuiltinModule {
get name() {return "Unnamed Builtin";}
get category() {return "settings";}
get group() {return "general";}
get collection() {return "settings";}
get category() {return "general";}
get id() {return "None";}
async initialize() {
const state = this.category == "settings" ? SettingState : EmoteState;
if (state[this.group][this.id]) await this.enable();
Events.on("setting-updated", (group, id, enabled) => {
if (group !== this.group || id !== this.id) return;
const state = this.collection == "settings" ? SettingState : EmoteState;
if (state[this.category][this.id]) await this.enable();
Events.on("setting-updated", (category, id, enabled) => {
if (category !== this.category || id !== this.id) return;
if (enabled) this.enable();
else this.disable();
});

View File

@ -47,7 +47,7 @@ export default class Group extends React.Component {
const groupClass = `${baseClassName} ${collapseClass}`;
return <div className={groupClass}>
<Title text={this.props.name} collapsible={this.props.collapsible} onClick={() => this.toggleCollapse()} button={this.props.button} />
<Title text={this.props.name} collapsible={this.props.collapsible} onClick={() => this.toggleCollapse()} button={this.props.button} isGroup={true} />
<div className="bd-settings-container" ref={this.container}>
{settings.filter(s => !s.hidden).map((setting) => {
// console.log(setting);

View File

@ -17,6 +17,7 @@ import SettingsGroup2 from "../settings/group";
import {Toasts} from "../ui";
import Settings from "../../data/settings/config";
import State from "../../data/settings/state";
import SettingsTitle from "./title";
export default class V2_SettingsPanel {
@ -48,10 +49,10 @@ export default class V2_SettingsPanel {
getSettingsPanel(groups, onChange) {
return groups.map(section => {
getSettingsPanel(title, groups, onChange) {
return [React.createElement(SettingsTitle, {text: title}), groups.map(section => {
return React.createElement(SettingsGroup2, Object.assign({}, section, {onChange}));
});
})];
}
get core3() {

View File

@ -1,6 +1,7 @@
import {React} from "modules";
const className = "bd-settings-title h2-2gWE-o title-3sZWYQ size16-14cGz5 height20-mO2eIN weightSemiBold-NJexzi defaultColor-1_ajX0 defaultMarginh2-2LTaUL marginBottom20-32qID7";
const className2 = "bd-settings-title bd-settings-group-title h5-18_1nd title-3sZWYQ size12-3R0845 height16-2Lv3qA weightSemiBold-NJexzi da-h5 da-title da-size12 da-height16 da-weightSemiBold marginBottom4-2qk4Hy da-marginBottom4 marginTop8-1DLZ1n da-marginTop8";
export default class SettingsTitle extends React.Component {
constructor(props) {
@ -8,7 +9,8 @@ export default class SettingsTitle extends React.Component {
}
//h2-2gWE-o title-3sZWYQ size16-14cGz5 height20-mO2eIN weightSemiBold-NJexzi da-h2 da-title da-size16 da-height20 da-weightSemiBold defaultColor-1_ajX0 da-defaultColor marginTop60-3PGbtK da-marginTop60 marginBottom20-32qID7 da-marginBottom20
render() {
const titleClass = this.props.className ? `${className} ${this.props.className}` : className;
const baseClass = this.props.isGroup ? className2 : className;
const titleClass = this.props.className ? `${baseClass} ${this.props.className}` : baseClass;
return <h2 className={titleClass} onClick={() => {this.props.onClick && this.props.onClick();}}>
{this.props.text}
{this.props.button && <button className="bd-title-button" onClick={this.props.button.onClick}>{this.props.button.title}</button>}