Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

75 linhas
1.6 KiB

  1. define([
  2. 'js/system/browserStorage'
  3. ], function (
  4. browserStorage
  5. ) {
  6. const config = {
  7. showNames: true,
  8. showQuests: 'on',
  9. showEvents: true,
  10. playAudio: true,
  11. qualityIndicators: 'off',
  12. unusableIndicators: 'off',
  13. rememberChatChannel: true,
  14. soundVolume: 100,
  15. musicVolume: 100,
  16. partyView: 'full',
  17. damageNumbers: 'element'
  18. };
  19. const valueChains = {
  20. partyView: ['full', 'compact', 'minimal'],
  21. showQuests: ['on', 'minimal', 'off'],
  22. qualityIndicators: ['border', 'bottom', 'background', 'off'],
  23. unusableIndicators: ['off', 'border', 'top', 'background'],
  24. damageNumbers: ['element', 'white', 'off']
  25. };
  26. const getNextValue = key => {
  27. const currentValue = config[key];
  28. const chain = valueChains[key];
  29. const currentIndex = chain.indexOf(currentValue);
  30. const nextValue = chain[(currentIndex + 1) % chain.length];
  31. return nextValue;
  32. };
  33. const getKeyName = key => {
  34. return `opt_${key.toLowerCase()}`;
  35. };
  36. config.set = (key, value) => {
  37. config[key] = value;
  38. browserStorage.set(getKeyName(key), config[key]);
  39. };
  40. config.toggle = key => {
  41. if (valueChains[key])
  42. config[key] = getNextValue(key);
  43. else
  44. config[key] = !config[key];
  45. browserStorage.set(getKeyName(key), config[key]);
  46. };
  47. const loadValue = key => {
  48. const currentValue = browserStorage.get(getKeyName(key));
  49. if (currentValue === '{unset}')
  50. return;
  51. if (['true', 'false'].includes(currentValue))
  52. config[key] = currentValue === 'true';
  53. else if (~~currentValue === parseInt(currentValue))
  54. config[key] = ~~currentValue;
  55. else
  56. config[key] = currentValue;
  57. };
  58. Object.keys(config).forEach(key => loadValue(key) );
  59. return config;
  60. });