{"size": 1855, "ext": "js", "max_stars_repo_path": "module/utils/cache-helper.js", "max_stars_repo_name": "Theik/Foundry-Pokemon-Tabletop-United-System", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "module/utils/cache-helper.js", "max_issues_repo_name": "Theik/Foundry-Pokemon-Tabletop-United-System", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "module/utils/cache-helper.js", "max_forks_repo_name": "Theik/Foundry-Pokemon-Tabletop-United-System", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 40.3260869565, "max_line_length": 94, "alphanum_fraction": 0.6070080863}
export async function GetOrCreateCachedItem(key, getFn) {
    let result;
    if(game.ptu.cache[key]) result = game.ptu.cache[key];
    else {
        await new Promise(r => setTimeout(r, 100));
        if(game.ptu.cache[key]) result = game.ptu.cache[key];
        else {
            result = await getFn();
            game.ptu.cache[key] = duplicate(result);
        }
    }
    return result;
}

export function GetOrCacheAbilities() { 
    return GetOrCreateCachedItem("abilities", async () => {
        let abilities = await game.packs.get("ptu.abilities").getContent();
        if(game.settings.get("ptu", "uraniumData") || game.settings.get("ptu", "sageData")) {
            let fgc = await game.packs.get("ptu.fan-game-content").getContent();
            Array.prototype.push.apply(abilities, fgc.filter(x => x.type == "ability"));
        }
        return abilities;
    });
}

export function GetOrCacheMoves() { 
    return GetOrCreateCachedItem("moves", async () => {
        let moves = await game.packs.get("ptu.moves").getContent();
        if(game.settings.get("ptu", "uraniumData") || game.settings.get("ptu", "sageData")) {
            let fgc = await game.packs.get("ptu.fan-game-content").getContent();
            Array.prototype.push.apply(moves, fgc.filter(x => x.type == "move"));
        }
        return moves;
    });
}

export function GetOrCacheCapabilities() { 
    return GetOrCreateCachedItem("capabilities", async () => {
        let capabilities = await game.packs.get("ptu.capabilities").getContent();
        if(game.settings.get("ptu", "uraniumData") || game.settings.get("ptu", "sageData")) {
            let fgc = await game.packs.get("ptu.fan-game-content").getContent();
            Array.prototype.push.apply(capabilities, fgc.filter(x => x.type == "capability"));
        }
        return capabilities;
    });
}