mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-10-15 07:21:58 +00:00
Add info and question icons. Bump version to beta1.7. Add chat badge visibility. Add support for setting inheritance merge strategies.
This commit is contained in:
parent
19c81bb049
commit
cc682230e2
16 changed files with 222 additions and 51 deletions
|
@ -7,6 +7,8 @@
|
|||
import {EventEmitter} from 'utilities/events';
|
||||
import {has, get as getter, array_equals} from 'utilities/object';
|
||||
|
||||
import * as DEFINITIONS from './types';
|
||||
|
||||
|
||||
/**
|
||||
* The SettingsContext class provides a context through which to read
|
||||
|
@ -128,7 +130,7 @@ export default class SettingsContext extends EventEmitter {
|
|||
this.emit(`changed:${key}`, new_value, old_value);
|
||||
}
|
||||
|
||||
if ( new_uses !== old_uses ) {
|
||||
if ( ! array_equals(new_uses, old_uses) ) {
|
||||
this.emit('uses_changed', key, new_uses, old_uses);
|
||||
this.emit(`uses_changed:${key}`, new_uses, old_uses);
|
||||
}
|
||||
|
@ -190,7 +192,7 @@ export default class SettingsContext extends EventEmitter {
|
|||
old_uses = old_meta ? old_meta.uses : null,
|
||||
new_uses = new_meta ? new_meta.uses : null;
|
||||
|
||||
if ( old_uses !== new_uses ) {
|
||||
if ( ! array_equals(new_uses, old_uses) ) {
|
||||
this.emit('uses_changed', key, new_uses, old_uses);
|
||||
this.emit(`uses_changed:${key}`, new_uses, old_uses);
|
||||
}
|
||||
|
@ -216,9 +218,15 @@ export default class SettingsContext extends EventEmitter {
|
|||
visited.push(key);
|
||||
|
||||
const definition = this.manager.definitions.get(key),
|
||||
raw_value = this._getRaw(key),
|
||||
raw_type = definition && definition.type,
|
||||
type = raw_type ? DEFINITIONS[raw_type] : DEFINITIONS.basic;
|
||||
|
||||
if ( ! type )
|
||||
throw new Error(`non-existent setting type "${raw_type}"`);
|
||||
|
||||
const raw_value = this._getRaw(key, type),
|
||||
meta = {
|
||||
uses: raw_value ? raw_value[1].id : null
|
||||
uses: raw_value ? raw_value[1] : null
|
||||
};
|
||||
|
||||
let value = raw_value ? raw_value[0] : undefined;
|
||||
|
@ -250,11 +258,22 @@ export default class SettingsContext extends EventEmitter {
|
|||
}
|
||||
|
||||
|
||||
_getRaw(key) {
|
||||
*profiles() {
|
||||
for(const profile of this.__profiles)
|
||||
yield profile;
|
||||
}
|
||||
|
||||
|
||||
_getRaw(key, type) {
|
||||
if ( ! type )
|
||||
throw new Error(`non-existent `)
|
||||
|
||||
return type.get(key, this.profiles(), this.manager.log);
|
||||
}
|
||||
/* for(const profile of this.__profiles)
|
||||
if ( profile.has(key) )
|
||||
return [profile.get(key), profile]
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
|
81
src/settings/types.js
Normal file
81
src/settings/types.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
'use strict';
|
||||
|
||||
// ============================================================================
|
||||
// Settings Types
|
||||
// ============================================================================
|
||||
|
||||
export const basic = {
|
||||
get(key, profiles) {
|
||||
for(const profile of profiles)
|
||||
if ( profile.has(key) )
|
||||
return [
|
||||
profile.get(key),
|
||||
[profile.id]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const object_merge = {
|
||||
get(key, profiles, log) {
|
||||
const values = [],
|
||||
sources = [];
|
||||
|
||||
for(const profile of profiles)
|
||||
if ( profile.has(key) ) {
|
||||
const val = profile.get(key);
|
||||
if ( typeof val !== 'object' ) {
|
||||
log.warn(`Profile #${profile.id} has an invalid value for "${key}" of type ${typeof val}. Skipping.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
sources.push(profile.id);
|
||||
values.unshift(val);
|
||||
}
|
||||
|
||||
if ( values.length )
|
||||
return [
|
||||
Object.assign({}, ...values),
|
||||
sources
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const array_merge = {
|
||||
get(key, profiles, log) {
|
||||
const values = [],
|
||||
trailing = [],
|
||||
sources = [];
|
||||
|
||||
for(const profile of profiles)
|
||||
if ( profile.has(key) ) {
|
||||
const value = profile.get(key);
|
||||
if ( ! Array.isArray(value) ) {
|
||||
log.warn(`Profile #${profile.id} has an invalid value for "${key}" of type ${typeof value}. Skipping.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
sources.push(profile.id);
|
||||
let is_trailing = false;
|
||||
for(const val of value) {
|
||||
if ( val.t === 'inherit' )
|
||||
is_trailing = true;
|
||||
else if ( is_trailing )
|
||||
trailing.unshift(val.v);
|
||||
else
|
||||
values.push(val.v);
|
||||
}
|
||||
|
||||
// If we didn't run into an inherit, don't inherit.
|
||||
if ( ! is_trailing )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( values.length || trailing.length )
|
||||
return [
|
||||
values.concat(trailing),
|
||||
sources
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue