Skip to content

Commit

Permalink
Fix saving Font Settings
Browse files Browse the repository at this point in the history
Fix #343
  • Loading branch information
mclemente committed Jan 1, 2024
1 parent 68d1bd4 commit aa6a1e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
21 changes: 7 additions & 14 deletions src/module/forms/FontSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PolyglotFontSettings extends FormApplication {
const fonts = game.settings.get("polyglot", "Alphabets");
this.fonts = {};

for (let key of Object.keys(fonts)) {
for (let key in fonts) {
this.fonts[key] = {
label: key,
family: fonts[key].fontFamily,
Expand Down Expand Up @@ -90,25 +90,18 @@ export class PolyglotFontSettings extends FormApplication {

async _updateObject() {
const customFontSizes = {};
let changes = false;
for (const [key, font] of Object.entries(this.fonts)) {
customFontSizes[key] = font.size;
game.polyglot.languageProvider.fonts[key].alphabeticOnly = font.alphabeticOnly;
game.polyglot.languageProvider.fonts[key].logographical = font.logographical;
}
let current = game.settings.get("polyglot", "Alphabets");
if (!foundry.utils.isEmpty(foundry.utils.diffObject(current, game.polyglot.languageProvider.fonts))) {
await game.settings.set("polyglot", "Alphabets", game.polyglot.languageProvider.fonts);
changes = true;
}
await game.settings.set("polyglot", "Alphabets", game.polyglot.languageProvider.fonts);
current = game.settings.get("polyglot", "CustomFontSizes");
if (!foundry.utils.isEmpty(foundry.utils.diffObject(current, customFontSizes))) {
game.polyglot.CustomFontSizes = customFontSizes;
await game.settings.set("polyglot", "CustomFontSizes", game.polyglot.CustomFontSizes);
changes = true;
}
if (changes) {
SettingsConfig.reloadConfirm({ world: true });
}
game.polyglot.CustomFontSizes = customFontSizes;
await game.settings.set("polyglot", "CustomFontSizes", game.polyglot.CustomFontSizes);
const changes = !foundry.utils.isEmpty(foundry.utils.diffObject(current, game.polyglot.languageProvider.fonts))
|| !foundry.utils.isEmpty(foundry.utils.diffObject(current, customFontSizes));
if (changes) SettingsConfig.reloadConfirm({ world: true });
}
}
34 changes: 15 additions & 19 deletions src/module/providers/templates/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@ export default class LanguageProvider {

const setupSteps = async () => {
await this.getLanguages();
const enableAllFonts = game.settings.get("polyglot", "enableAllFonts");
if (enableAllFonts) {
for (let font in game.settings.get("core", "fonts")) {
const fontSize = game.polyglot.CustomFontSizes[font] ?? "100";
this.addFont(font, fontSize);
}
}
this.loadFonts();
this.loadLanguages();
this.loadCustomFonts();
Expand Down Expand Up @@ -379,6 +372,20 @@ export default class LanguageProvider {
this.fonts = new LanguageProvider().fonts;
const enableAllFonts = game.settings.get("polyglot", "enableAllFonts");
const fonts = game.settings.get("polyglot", "Alphabets");

if (enableAllFonts) {
for (let font in game.settings.get("core", "fonts")) {
if (fonts[font]) {
this.fonts[font] = fonts[font];
} else {
const fontSize = game.polyglot.CustomFontSizes[font] ?? "100";
this.addFont(font, fontSize);
}
}
}
for (let font in fonts) {
if (!this.fonts[font]) this.fonts[font] = fonts[font];
}
for (let font in this.fonts) {
if (game.polyglot.CustomFontSizes[font]) {
this.fonts[font].fontSize = game.polyglot.CustomFontSizes[font];
Expand All @@ -388,12 +395,6 @@ export default class LanguageProvider {
this.fonts[font].logographical = fonts[font].logographical;
}
}
if (enableAllFonts) {
for (let font in game.settings.get("core", "fonts")) {
const fontSize = game.polyglot.CustomFontSizes[font] ?? 100;
this.addFont(font, fontSize);
}
}
}

/**
Expand Down Expand Up @@ -464,17 +465,12 @@ export default class LanguageProvider {
* @see loadFonts
*/
addFont(fontFamily, fontSize = 100, options = {}) {
const key = fontFamily;
const defaultOptions = {
alphabeticOnly: false,
logographical: false,
// replace: {},
};

const font = { ...defaultOptions, ...options, fontSize,
fontFamily};

this.fonts[key] = font;
this.fonts[fontFamily] = { ...defaultOptions, ...options, fontSize, fontFamily };
}

/**
Expand Down

0 comments on commit aa6a1e1

Please sign in to comment.