mclemente / fvtt-module-polyglot

Talk to others using a language you can speak and scrambles text you can't understand.
MIT License
41 stars 48 forks source link

Error for hook 'polyglot.init' integrating. #347

Closed pedroaugustobt closed 10 months ago

pedroaugustobt commented 10 months ago

System Name: TheWitcherTRPG (https://github.com/AnthonyMonette/TheWitcherTRPG/tree/main)

I'm integrating Polyglota for this system and I came across an error. According to all my current attempts and logs, the error is when registering the module or system using the reference listed in its API (polyglot.registerSystem("TheWitcherTRPG", FictionalGameSystemLanguageProvider), polyglot.registerModule("TheWitcherTRPG", FictionalGameSystemLanguageProvider) ). The error in the console is this (ReferenceError: Error thrown in hooked function '' for hook 'polyglot.init'. polyglot is not defined).

Would there be any way to resolve it?

Hooks.once("polyglot.init", (LanguageProvider) => { console.log("Polyglot initialization started.") class FictionalGameSystemLanguageProvider extends LanguageProvider { languages = { common: { label: 'Common', font: 'Thorass', rng: 'default' }, dwarven: { label: 'Dwarven', font: 'Dethek', rng: 'default' }, elder: { label: 'Elder', font: 'Espruar', rng: 'default' }, }

    get originalAlphabets() {
        return {
            "common": "130% Thorass",
            "dwarven": "120% Dethek",
            "elder": "150% Espruar",
        };
    }
    get originalTongues() {
        return {
            "_default": "common",
            "common": "common",
            "dwarven": "dwarven",
            "elder": "elder",
        };
    }

    getUserLanguages(actor) {
        console.log("DataPath called.");
        const dataPath = "actor.system.skills.int";
        let known_languages = new Set();
        let literate_languages = new Set();
        if (getProperty(actor.data, `${dataPath}.eldersp.isProffession`) ||
            getProperty(actor.data, `${dataPath}.eldersp.isPickup`) ||
            getProperty(actor.data, `${dataPath}.eldersp.isLearned`) ||
            getProperty(actor.data, `${dataPath}.eldersp.value`) > 0) {
        known_languages.add("elder");
        }
        if (getProperty(actor.data, `${dataPath}.dwarven.isProffession`) ||
            getProperty(actor.data, `${dataPath}.dwarven.isPickup`) ||
            getProperty(actor.data, `${dataPath}.dwarven.isLearned`) ||
            getProperty(actor.data, `${dataPath}.dwarven.value`) > 0) {
        known_languages.add("dwarven");
        }
        if (getProperty(actor.data, `${dataPath}.commonsp.isProffession`) ||
            getProperty(actor.data, `${dataPath}.commonsp.isPickup`) ||
            getProperty(actor.data, `${dataPath}.commonsp.isLearned`) ||
            getProperty(actor.data, `${dataPath}.commonsp.value`) > 0) {
        known_languages.add("common");
        }
        return [known_languages, literate_languages];
    }
}

console.log("Registering system or module...");
polyglot.registerSystem("TheWitcherTRPG", FictionalGameSystemLanguageProvider)
//polyglot.registerModule("TheWitcherTRPG", FictionalGameSystemLanguageProvider);

})

Used code.

mclemente commented 10 months ago

Replace originalAlphabets and originalTongues for:

languages = {
    "common": {
        label: "Common",
        font: "Thorass",
    },
    "dwarven": {
        label: "Dwarven",
        font: "Dethek",
    },
    "elder": {
        label: "Elder Speech",
        font: "Espruar",
    }
}

And replace:

- polyglot.registerSystem("TheWitcherTRPG", FictionalGameSystemLanguageProvider)
+ game.polyglot.api.registerSystem(FictionalGameSystemLanguageProvider)
pedroaugustobt commented 10 months ago

Thanks, it's working!!!!