game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
HLTBService Class Reference

Service for fetching game time estimates from HowLongToBeat. More...

#include <hltb_service.h>

Public Types

using InfoCallback = std::function<void(const HowLongToBeatInfo&)>
using SearchCallback = std::function<void(const std::vector<HLTBSearchResult>&)>

Static Public Member Functions

static void batchFetch (std::vector< Game * > &games, const std::function< void(int completed, int total)> &progressCallback=nullptr)
 Fetch HLTB info for multiple games.
static void clearCache ()
 Clear the HLTB cache.
static LRUCache< std::string, HowLongToBeatInfo >::Stats getCacheStats ()
 Get cache statistics.
static HowLongToBeatInfo getGameInfo (const std::string &gameName)
 Get time estimates for a game by name.
static void getGameInfoAsync (const std::string &gameName, const InfoCallback &callback)
 Get game info asynchronously.
static HowLongToBeatInfo getGameInfoById (int hltbId)
 Get time estimates by HLTB game ID.
static std::vector< HLTBSearchResult > search (const std::string &query, int maxResults=10)
 Search for games on HLTB.
static void searchAsync (const std::string &query, const SearchCallback &callback, int maxResults=10)
 Search asynchronously.

Detailed Description

Service for fetching game time estimates from HowLongToBeat.

Usage:

auto info = HLTBService::getGameInfo("The Witcher 3: Wild Hunt");
if (info.found) {
Logger::info("Main story: {} hours", info.mainStoryHours);
}
static HowLongToBeatInfo getGameInfo(const std::string &gameName)
Get time estimates for a game by name.
static void info(const std::string &message, Args &&... args)
Log info message (general information).
Definition logger.h:108

Definition at line 69 of file hltb_service.h.

Member Typedef Documentation

◆ InfoCallback

using HLTBService::InfoCallback = std::function<void(const HowLongToBeatInfo&)>

Definition at line 73 of file hltb_service.h.

◆ SearchCallback

using HLTBService::SearchCallback = std::function<void(const std::vector<HLTBSearchResult>&)>

Definition at line 74 of file hltb_service.h.

Member Function Documentation

◆ batchFetch()

void HLTBService::batchFetch ( std::vector< Game * > & games,
const std::function< void(int completed, int total)> & progressCallback = nullptr )
static

Fetch HLTB info for multiple games.

Parameters
gamesGames to fetch info for (updates in place)
progressCallbackOptional callback for progress updates

Efficiently fetches HLTB data for multiple games, skipping those that already have fresh data.

Definition at line 590 of file hltb_service.cpp.

References getGameInfo().

◆ clearCache()

void HLTBService::clearCache ( )
static

Clear the HLTB cache.

Definition at line 630 of file hltb_service.cpp.

References hltbCache(), and Logger::info().

◆ getCacheStats()

LRUCache< std::string, HowLongToBeatInfo >::Stats HLTBService::getCacheStats ( )
static

Get cache statistics.

Definition at line 636 of file hltb_service.cpp.

References hltbCache().

◆ getGameInfo()

HowLongToBeatInfo HLTBService::getGameInfo ( const std::string & gameName)
static

Get time estimates for a game by name.

Parameters
gameNameGame name to search for
Returns
HowLongToBeatInfo with time estimates

Searches HLTB and returns the best matching result. Results are cached with a 30-day TTL.

Definition at line 437 of file hltb_service.cpp.

References Logger::debug(), HowLongToBeatInfo::found, hltbCache(), Logger::info(), search(), and Logger::warn().

Referenced by batchFetch(), and getGameInfoAsync().

◆ getGameInfoAsync()

void HLTBService::getGameInfoAsync ( const std::string & gameName,
const InfoCallback & callback )
static

Get game info asynchronously.

Parameters
gameNameGame name to search for
callbackFunction called with results

Definition at line 523 of file hltb_service.cpp.

References getGameInfo().

◆ getGameInfoById()

HowLongToBeatInfo HLTBService::getGameInfoById ( int hltbId)
static

Get time estimates by HLTB game ID.

Parameters
hltbIdHowLongToBeat game ID
Returns
HowLongToBeatInfo with time estimates

Definition at line 501 of file hltb_service.cpp.

References HowLongToBeatInfo::found, and Logger::warn().

◆ search()

std::vector< HLTBSearchResult > HLTBService::search ( const std::string & query,
int maxResults = 10 )
static

Search for games on HLTB.

Parameters
querySearch query
maxResultsMaximum results to return
Returns
Vector of search results

Definition at line 387 of file hltb_service.cpp.

References Logger::debug(), ShellUtils::escapeJson(), Logger::info(), and Logger::warn().

Referenced by getGameInfo(), and searchAsync().

◆ searchAsync()

void HLTBService::searchAsync ( const std::string & query,
const SearchCallback & callback,
int maxResults = 10 )
static

Search asynchronously.

Parameters
querySearch query
callbackFunction called with results
maxResultsMaximum results

Definition at line 556 of file hltb_service.cpp.

References search().


The documentation for this class was generated from the following files: