dylanpiera / Foundry-Pokemon-Tabletop-United-System

PTU System for FoundryVTT
35 stars 33 forks source link

Fix Fangame Species #485

Closed dylanpiera closed 1 year ago

dylanpiera commented 1 year ago

Currently all fangame species have fully broken links in them.

I decided to try to run the automated importer just for Abilities and already noticed a ton of abilities are incorrect / not present image

For now this fix is paused until someone has time to go through all of these and add the missing entries.

Muhsigbokz commented 1 year ago

Would you like to share how to run the importer you wrote about? Then I would start looking into things.

Muhsigbokz commented 1 year ago

a little progress

The following snippet

//((await getBadlySlugged()).map(x => x.name) //deltaRos = fromUuidSync("Compendium.ptu.species.Item.H7siLUqPoZEiaFIu") await getFixes();

Muhsigbokz commented 1 year ago

Pimped the thing before. This should come in handy in the future

Creates three dicts with potential fixes, what is not found using preexisting slug and what is not found using fresh slugs of item names.

async function getFixes() {
    const nonPtrSources = ["Fangame Insurgence Dex", "Fangame Uranium Dex", "Fangame Sage Dex", ""];

    const itemTypes = ["abilities", "feats", "items", "species", "moves", "capabilities", "effects", "poke-edges"]

    const freshDic = {}
    const oldDic = {}
    for (const cat of itemTypes) {
        freshDic[cat] = {}
        oldDic[cat] = {}
        const items = await game.packs.get(`ptu.${cat}`).getDocuments();
        for (const item of items) {
            const freshSlug = CONFIG.PTU.util.sluggify(item.name)
            freshDic[cat][freshSlug] = item
            oldDic[cat][item.slug] = item
        }
    }

    const changeProposals = {}
    const notInOld = {}
    const notInFresh = {}

    let fixed = 0

    const fanMons = (await game.packs.get(`ptu.species`).getDocuments()).filter(sp => ! nonPtrSources.includes(sp.system?.source?.value))
    for (const mon of fanMons) {
        const prevFixed = fixed;
        const cp = {};
        const cpO = {};
        const cpF = {};
        //abilities
        for (const tier of ["basic", "advanced", "high"]) {
            for (const ab of mon.system.abilities[tier]) {
                if (!ab.uuid) {
                    const oldP = oldDic["abilities"][ab.slug];
                    if (oldP) {
                        if(!cp[`${tier}Abilities`])
                            cp[`${tier}Abilities`] = []
                        cp[`${tier}Abilities`].push(oldP)
                        fixed += 1;
                        continue
                    }
                    if(!cpO[`${tier}Abilities`])
                        cpO[`${tier}Abilities`] = []
                    cpO[`${tier}Abilities`].push(ab.slug)
                    const freshP = freshDic["abilities"][ab.slug];
                    if (freshP) {
                        if(!cp[`${tier}Abilities`])
                            cp[`${tier}Abilities`] = []
                        cp[`${tier}Abilities`].push(freshP)
                        fixed += 1;
                        continue
                    }
                    if(!cpF[`${tier}Abilities`])
                        cpF[`${tier}Abilities`] = []
                    cpF[`${tier}Abilities`].push(ab.slug)
                }
            }
        }
        //moves
        for (const src of ["egg", "level", "machine", "tutor"]) {
            for (const move of mon.system.moves[src]) {
                if (!move.uuid) {
                    const oldP = oldDic["moves"][move.slug];
                    if (oldP) {
                        if(!cp[`${src}Moves`])
                            cp[`${src}Moves`] = []
                        cp[`${src}Moves`].push(oldP)
                        fixed += 1;
                        continue
                    }
                    if(!cpO[`${src}Moves`])
                        cpO[`${src}Moves`] = []
                    cpO[`${src}Moves`].push(move.slug)
                    const freshP = freshDic["moves"][move.slug];
                    if (freshP) {
                        if(!cp[`${src}Moves`])
                            cp[`${src}Moves`] = []
                        cp[`${src}Moves`].push(freshP)
                        fixed += 1;
                        continue
                    }
                    if(!cpF[`${src}Moves`])
                        cpF[`${src}Moves`] = []
                    cpF[`${src}Moves`].push(move.slug)
                }
            }
        }
        // other capabilities
        for (const cap of mon.system.capabilities.other) {
            if (!cap.uuid) {
                if (cap.slug.startsWith("mountable-"))
                    continue
                const oldP = oldDic["capabilities"][cap.slug];
                if (oldP) {
                    if(!cp.capabilities)
                        cp.capabilities = []
                    cp.capabilities.push(oldP)
                    fixed += 1;
                    continue
                }
                if(!cpO.capabilities)
                    cpO.capabilities = []
                cpO.capabilities.push(cap.slug)
                const freshP = freshDic["capabilities"][cap.slug];
                if (freshP) {
                    if(!cp.capabilities)
                        cp.capabilities = []
                    cp.capabilities.push(freshP)
                    fixed += 1;
                    continue
                }
                if(!cpF.capabilities)
                    cpF.capabilities = []
                cpF.capabilities.push(cap.slug)
            }
        }
        // evolutions
        for (const evo of mon.system.evolutions) {
            if (!evo.uuid) {
                const oldP = oldDic["species"][evo.slug];
                if (oldP) {
                    if(!cp.evolutions)
                        cp.evolutions = []
                    cp.evolutions.push(oldP)
                    fixed += 1;
                    continue
                }
                if(!cpO.evolutions)
                    cpO.evolutions = []
                cpO.evolutions.push(evo.slug)
                const freshP = freshDic["species"][evo.slug];
                if (freshP) {
                    if(!cp.evolutions)
                        cp.evolutions = []
                    cp.evolutions.push(freshP)
                    fixed += 1;
                    continue
                }
                if(!cpF.evolutions)
                    cpF.evolutions = []
                cpF.evolutions.push(evo.slug)
            }
        }

        const id = mon.name

        if (Object.keys(cp).length > 0)
            changeProposals[id] = cp
        if (Object.keys(cpO).length > 0)
            notInOld[id] = cpO
        if (Object.keys(cpF).length > 0)
            notInFresh[id] = cpF
    }
    console.warn(notInOld)
    console.error(notInFresh)
    return changeProposals
}

await getFixes();
Muhsigbokz commented 1 year ago

Current (4.0.3) issues not fixable through my script so far <.<

broken_fandex.json broken_ptrdex.json

And here 37 species with 46 errors such that you can map a unlinked item in the species through looking up its slug.

broken_ptrdex_autofixable.json

Muhsigbokz commented 1 year ago

newest version of check for mangled species

async function getFixes() {
    const nonPtrSources = ["Fangame Insurgence Dex", "Fangame Uranium Dex", "Fangame Sage Dex", ""];

    const itemTypes = ["abilities", "feats", "items", "species", "moves", "capabilities", "effects", "poke-edges"]

    const freshDic = {}
    const oldDic = {}
    for (const cat of itemTypes) {
        freshDic[cat] = {}
        oldDic[cat] = {}
        const items = await game.packs.get(`ptu.${cat}`).getDocuments();
        for (const item of items) {
            const freshSlug = CONFIG.PTU.util.sluggify(item.name)
            freshDic[cat][freshSlug] = item
            oldDic[cat][item.slug] = item
        }
    }

    const changeProposals = {}
    const notInOld = {}
    const notInFresh = {}
    const allScrewed = {}

    let fixed = 0

    const fanMons = (await game.packs.get(`ptu.species`).getDocuments())//.filter(sp => nonPtrSources.includes(sp.system?.source?.value))
    for (const mon of fanMons) {
        const prevFixed = fixed;
        const cp = {};
        const cpO = {};
        const cpF = {};
        const screwed = {};
        //abilities
        for (const tier of ["basic", "advanced", "high"]) {
            for (const ab of mon.system.abilities[tier]) {
                if (!ab.uuid) {
                    if(!screwed[`${tier}Abilities`])
                        screwed[`${tier}Abilities`] = []
                    screwed[`${tier}Abilities`].push(ab.slug)
                    const oldP = oldDic["abilities"][ab.slug];
                    if (oldP) {
                        if(!cp[`${tier}Abilities`])
                            cp[`${tier}Abilities`] = []
                        cp[`${tier}Abilities`].push(oldP)
                        fixed += 1;
                        continue
                    }
                    if(!cpO[`${tier}Abilities`])
                        cpO[`${tier}Abilities`] = []
                    cpO[`${tier}Abilities`].push(ab.slug)
                    const freshP = freshDic["abilities"][ab.slug];
                    if (freshP) {
                        if(!cp[`${tier}Abilities`])
                            cp[`${tier}Abilities`] = []
                        cp[`${tier}Abilities`].push(freshP)
                        fixed += 1;
                        continue
                    }
                    if(!cpF[`${tier}Abilities`])
                        cpF[`${tier}Abilities`] = []
                    cpF[`${tier}Abilities`].push(ab.slug)
                }
            }
        }
        //moves
        for (const src of ["egg", "level", "machine", "tutor"]) {
            for (const move of mon.system.moves[src]) {
                if (!move.uuid) {
                    if(!screwed[`${src}Moves`])
                        screwed[`${src}Moves`] = []
                    screwed[`${src}Moves`].push(move.slug)
                    const oldP = oldDic["moves"][move.slug];
                    if (oldP) {
                        if(!cp[`${src}Moves`])
                            cp[`${src}Moves`] = []
                        cp[`${src}Moves`].push(oldP)
                        fixed += 1;
                        continue
                    }
                    if(!cpO[`${src}Moves`])
                        cpO[`${src}Moves`] = []
                    cpO[`${src}Moves`].push(move.slug)
                    const freshP = freshDic["moves"][move.slug];
                    if (freshP) {
                        if(!cp[`${src}Moves`])
                            cp[`${src}Moves`] = []
                        cp[`${src}Moves`].push(freshP)
                        fixed += 1;
                        continue
                    }
                    if(!cpF[`${src}Moves`])
                        cpF[`${src}Moves`] = []
                    cpF[`${src}Moves`].push(move.slug)
                }
            }
        }
        // other capabilities
        for (const cap of mon.system.capabilities.other) {
            if (!cap.uuid) {
                if (cap.slug.startsWith("mountable-"))
                    continue
                if(!screwed.capabilities)
                    screwed.capabilities = []
                screwed.capabilities.push(cap.slug)
                const oldP = oldDic["capabilities"][cap.slug];
                if (oldP) {
                    if(!cp.capabilities)
                        cp.capabilities = []
                    cp.capabilities.push(oldP)
                    fixed += 1;
                    continue
                }
                if(!cpO.capabilities)
                    cpO.capabilities = []
                cpO.capabilities.push(cap.slug)
                const freshP = freshDic["capabilities"][cap.slug];
                if (freshP) {
                    if(!cp.capabilities)
                        cp.capabilities = []
                    cp.capabilities.push(freshP)
                    fixed += 1;
                    continue
                }
                if(!cpF.capabilities)
                    cpF.capabilities = []
                cpF.capabilities.push(cap.slug)
            }
        }
        // evolutions
        for (const evo of mon.system.evolutions) {
            if (!evo.uuid) {
                if(!screwed.evolutions)
                    screwed.evolutions = []
                screwed.evolutions.push(evo.slug)
                const oldP = oldDic["species"][evo.slug];
                if (oldP) {
                    if(!cp.evolutions)
                        cp.evolutions = []
                    cp.evolutions.push(oldP)
                    fixed += 1;
                    continue
                }
                if(!cpO.evolutions)
                    cpO.evolutions = []
                cpO.evolutions.push(evo.slug)
                const freshP = freshDic["species"][evo.slug];
                if (freshP) {
                    if(!cp.evolutions)
                        cp.evolutions = []
                    cp.evolutions.push(freshP)
                    fixed += 1;
                    continue
                }
                if(!cpF.evolutions)
                    cpF.evolutions = []
                cpF.evolutions.push(evo.slug)
            }
        }

        const id = mon.name

        if (Object.keys(screwed).length > 0)
            allScrewed[id] = screwed
        if (Object.keys(cp).length > 0)
            changeProposals[id] = cp
        if (Object.keys(cpO).length > 0)
            notInOld[id] = cpO
        if (Object.keys(cpF).length > 0)
            notInFresh[id] = cpF
    }
    console.log(fixed)
    console.warn(notInOld)
    console.error(notInFresh)
    return allScrewed
}

JSON.stringify(await getFixes());