Skip to content

Commit

Permalink
Add support for the ARS system
Browse files Browse the repository at this point in the history
  • Loading branch information
mclemente committed Sep 7, 2024
1 parent 0336635 commit 3ae33ff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/module/providers/_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { default as GenericLanguageProvider } from "./templates/Generic.js";

export { default as a5eLanguageProvider } from "./a5e.js";
export { default as ariaLanguageProvider } from "./aria.js";
export { default as arsLanguageProvider } from "./ars.js";
export { default as coc7LanguageProvider } from "./coc7.js";
export { default as cyberpunkRedLanguageProvider } from "./cyberpunk-red-core.js";
export { default as d35eLanguageProvider } from "./d35e.js";
Expand Down
48 changes: 48 additions & 0 deletions src/module/providers/ars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import LanguageProvider from "./templates/Base.js";

export default class arsLanguageProvider extends LanguageProvider {
get settings() {
return {
LanguageRegex: {
type: String,
default: game.i18n.localize("POLYGLOT.Generic.Language"),
}
};
}

async getLanguages() {
this.languages = {};
if (this.replaceLanguages) return;
if (game.modules.get("osric-compendium")?.active) {
const langs = {};
const osricPack = game.packs.get("osric-compendium.items");
const osricItemList = await osricPack.getIndex();
const languagesSetting = game.settings.get("polyglot", "Languages");
let myRegex = new RegExp(`(?:Language:|${game.settings.get("polyglot", "LanguageRegex")}:)\\s*(.+)`, "i");
for (let item of osricItemList) {
if (myRegex.test(item.name)) {
let label = item.name.match(myRegex)[1].trim();
let key = label.toLowerCase();
if (!label) continue;
langs[key] = {
label,
font: languagesSetting[key]?.font || this.languages[key]?.font || this.defaultFont,
rng: languagesSetting[key]?.rng ?? "default",
};
}
}
this.languages = langs;
}
}

getUserLanguages(actor) {
let knownLanguages = new Set();
let literateLanguages = new Set();
let myRegex = new RegExp(`(?:Language:|${game.settings.get("polyglot", "LanguageRegex")}:)\\s*(.+)`, "i");
for (let item of actor.items) {
// adding only the descriptive language name, not "Language: XYZ"
if (myRegex.test(item.name)) knownLanguages.add(item.name.match(myRegex)[1].trim().toLowerCase());
}
return [knownLanguages, literateLanguages];
}
}

0 comments on commit 3ae33ff

Please sign in to comment.