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

Complete representation of a game in the library. More...

#include <game.h>

Collaboration diagram for Game:

Public Member Functions

 Game ()
 Default constructor.
void deserializeMetadata (const std::string &json)
 Deserialize metadata from JSON.
void deserializeRunnerConfig (const std::string &json)
 Deserialize runner configuration from JSON.
double getAverageSessionDuration () const
 Get average session duration for this game.
double getCompletionPercentage (int targetStyle=0) const
 Get completion percentage based on HLTB estimate.
std::string getCompletionStatusName () const
 Get human-readable completion status name.
const std::string & getDescriptionLower () const
 Get lowercase description (cached for performance).
const std::string & getDeveloperLower () const
 Get lowercase developer (cached for performance).
std::string getFormattedInstallSize () const
 Format install size as human-readable string.
std::string getFormattedPlayTime () const
 Format total play time as human-readable string.
std::string getImagePath (ImageType type) const
 Get path for a specific image type.
const std::string & getNameLower () const
 Get lowercase name (cached for performance).
std::string getPlatformName () const
 Get human-readable platform name.
const std::string & getPublisherLower () const
 Get lowercase publisher (cached for performance).
double getRemainingPlaytime (int targetStyle=0) const
 Get estimated remaining playtime based on HLTB data.
std::string getRunnerName () const
 Get human-readable runner name.
std::string getSourceName () const
 Get human-readable source name.
std::string getStatusName () const
 Get human-readable status name.
void invalidateCache () const
 Invalidate lowercase caches (call when name/metadata changes).
bool isInstalled () const
 Check if game is currently installed.
bool isRunning () const
 Check if game is currently running.
std::string serializeMetadata () const
 Serialize metadata to JSON.
std::string serializeRunnerConfig () const
 Serialize runner configuration to JSON.
void syncPlatformFromRunner ()
 Sync the deprecated platform field from the current runner and source.

Public Attributes

std::string activeTemplateName
 Currently active template name (empty = using runnerConfig directly).
bool cacheInitialized_ = false
 True if caches have been computed.
std::vector< std::string > collections
 Collections this game belongs to.
CompletionStatus completionStatus = CompletionStatus::NotPlayed
 User's completion status.
std::map< std::string, GameRunnerConfig > configTemplates
 Named configuration templates (presets) that can be switched between Key is template name (e.g., "Performance", "Quality", "Compatibility").
std::string descriptionLowerCache_
 Cached lowercase description for case-insensitive search (computed on first access).
std::string developerLowerCache_
 Cached lowercase developer for case-insensitive search (computed on first access).
HowLongToBeatInfo hltbInfo
 Time-to-beat estimates.
std::string id
 Unique identifier (auto-generated or user-specified).
std::string installPath
 Installation directory path.
uint64_t installSizeBytes
 Installation size in bytes.
bool isFavorite
 Is this marked as a favorite game?
GameMetadata metadata
 Descriptive information and media.
std::string name
 Display name shown in UI.
std::string nameLowerCache_
 Cached lowercase name for case-insensitive search (computed on first access).
GamePlatform platform
std::string publisherLowerCache_
 Cached lowercase publisher for case-insensitive search (computed on first access).
std::vector< PlaySession > recentSessions
 Recent play sessions (last 20 kept in memory).
GameRunner runner
 Runner/compatibility layer to use (Native, Proton, Wine, etc.).
GameRunnerConfig runnerConfig
 How to launch and run the game.
GameSource source
 Where the game was acquired from (Steam, GOG, Local, etc.).
GameStatistics statistics
 Play statistics and usage tracking.
GameStatus status
 Current installation and execution status.
std::string userNotes
 User's personal notes about the game.

Detailed Description

Complete representation of a game in the library.

The Game class stores all information about a game, including:

  • Core identifying information (id, name, platform)
  • How to run the game (runnerConfig)
  • Descriptive metadata (cover art, description, genres)
  • Usage statistics (play time, launch count)
  • User organization (favorites, collections)
  • Installation details (path, size, status)

Data Persistence

Games are persisted in the SQLite-backed GameLibrary. Per-field JSON serialization is used for nested structs (runner config, metadata).

Thread Safety

This class is NOT thread-safe. External synchronization is required if a Game object is accessed from multiple threads.

Definition at line 766 of file game.h.

Constructor & Destructor Documentation

◆ Game()

Game::Game ( )
inline

Default constructor.

Creates a new Game with default values:

  • Source: Local
  • Platform: Native (deprecated)
  • Runner: Native
  • Status: NotInstalled
  • Not a favorite
  • Zero install size

Definition at line 852 of file game.h.

References installSizeBytes, isFavorite, runner, source, and status.

Member Function Documentation

◆ deserializeMetadata()

void Game::deserializeMetadata ( const std::string & json)

Deserialize metadata from JSON.

Parameters
jsonJSON string to parse

Definition at line 888 of file game.cpp.

References DLCInfo::appId, DLCInfo::installed, metadata, DLCInfo::name, DLCInfo::sizeBytes, and Logger::warn().

◆ deserializeRunnerConfig()

void Game::deserializeRunnerConfig ( const std::string & json)

Deserialize runner configuration from JSON.

Parameters
jsonJSON string to parse

Definition at line 724 of file game.cpp.

References runnerConfig, and Logger::warn().

◆ getAverageSessionDuration()

double Game::getAverageSessionDuration ( ) const

Get average session duration for this game.

Returns
Average session length in seconds

Definition at line 367 of file game.cpp.

References recentSessions.

◆ getCompletionPercentage()

double Game::getCompletionPercentage ( int targetStyle = 0) const

Get completion percentage based on HLTB estimate.

Parameters
targetStyleTarget playstyle (0=main, 1=main+extras, 2=completionist)
Returns
Percentage 0-100+ (can exceed 100 if played longer than estimate)

Definition at line 338 of file game.cpp.

References hltbInfo, and statistics.

◆ getCompletionStatusName()

std::string Game::getCompletionStatusName ( ) const

Get human-readable completion status name.

Returns
Status name (e.g., "Not Played", "Playing", "Beaten")

Definition at line 286 of file game.cpp.

References Abandoned, Beaten, Completed, completionStatus, NotPlayed, OnHold, Played, and Playing.

◆ getDescriptionLower()

const std::string & Game::getDescriptionLower ( ) const

Get lowercase description (cached for performance).

Returns
Lowercase version of description text

Definition at line 208 of file game.cpp.

References cacheInitialized_, descriptionLowerCache_, and getNameLower().

◆ getDeveloperLower()

const std::string & Game::getDeveloperLower ( ) const

Get lowercase developer (cached for performance).

Returns
Lowercase version of developer name

Definition at line 190 of file game.cpp.

References cacheInitialized_, developerLowerCache_, and getNameLower().

◆ getFormattedInstallSize()

std::string Game::getFormattedInstallSize ( ) const

Format install size as human-readable string.

Returns
Formatted size (e.g., "1.5 GB", "250 MB", "45.2 KB")

Definition at line 144 of file game.cpp.

References installSizeBytes.

◆ getFormattedPlayTime()

std::string Game::getFormattedPlayTime ( ) const

Format total play time as human-readable string.

Returns
Formatted play time (e.g., "42h 30m", "2h 15m", "45m")

Definition at line 114 of file game.cpp.

References statistics.

Referenced by DetailsPanelManager::Impl::update().

◆ getImagePath()

std::string Game::getImagePath ( ImageType type) const

Get path for a specific image type.

Parameters
typeType of image
Returns
Path to image file (empty string if not available)

Returns the path for the requested image type, checking both new imagePaths and legacy coverArtPath/bannerPath fields for backwards compatibility.

Definition at line 221 of file game.cpp.

References Capsule, Header, HeroImage, Icon, Logo, metadata, and VerticalCover.

Referenced by GameThumbnailCache::findBestImage(), and DetailsPanelManager::Impl::update().

◆ getNameLower()

const std::string & Game::getNameLower ( ) const

Get lowercase name (cached for performance).

Returns
Lowercase version of game name

This method computes lowercase strings on first access and caches them to avoid 15M+ string transformations per second during search/filtering.

Definition at line 176 of file game.cpp.

References cacheInitialized_, descriptionLowerCache_, developerLowerCache_, metadata, name, nameLowerCache_, publisherLowerCache_, and toLower().

Referenced by getDescriptionLower(), getDeveloperLower(), and getPublisherLower().

◆ getPlatformName()

std::string Game::getPlatformName ( ) const

Get human-readable platform name.

Returns
Platform name as string (e.g., "Native Linux", "Wine", "Proton")
Deprecated
Use getSourceName() and getRunnerName() instead

Definition at line 68 of file game.cpp.

References DOSBox, Epic, GOG, Native, Proton, RetroArch, ScummVM, Steam, and Wine.

◆ getPublisherLower()

const std::string & Game::getPublisherLower ( ) const

Get lowercase publisher (cached for performance).

Returns
Lowercase version of publisher name

Definition at line 199 of file game.cpp.

References cacheInitialized_, getNameLower(), and publisherLowerCache_.

◆ getRemainingPlaytime()

double Game::getRemainingPlaytime ( int targetStyle = 0) const

Get estimated remaining playtime based on HLTB data.

Parameters
targetStyleTarget playstyle (0=main, 1=main+extras, 2=completionist)
Returns
Remaining hours (negative if exceeded estimate), or -1 if no data

Definition at line 309 of file game.cpp.

References hltbInfo, and statistics.

◆ getRunnerName()

std::string Game::getRunnerName ( ) const

Get human-readable runner name.

Returns
Runner name as string (e.g., "Native", "Proton", "Wine")

Definition at line 49 of file game.cpp.

References DOSBox, Native, Proton, runner, ScummVM, and Wine.

Referenced by DetailsPanelManager::Impl::update().

◆ getSourceName()

std::string Game::getSourceName ( ) const

Get human-readable source name.

Returns
Source name as string (e.g., "Steam", "GOG", "Local")

Definition at line 25 of file game.cpp.

References Epic, Flatpak, GOG, Itch, Local, Lutris, source, Steam, and Unknown.

Referenced by DetailsPanelManager::Impl::update().

◆ getStatusName()

std::string Game::getStatusName ( ) const

Get human-readable status name.

Returns
Status name as string (e.g., "Installed", "Running", "Not Installed")

Definition at line 95 of file game.cpp.

References Installed, Installing, NotInstalled, Running, status, and Updating.

◆ invalidateCache()

void Game::invalidateCache ( ) const
inline

Invalidate lowercase caches (call when name/metadata changes).

Call this method after modifying name, developer, publisher, or description to ensure cached lowercase versions are recomputed on next access.

Definition at line 1027 of file game.h.

References cacheInitialized_.

◆ isInstalled()

bool Game::isInstalled ( ) const
inline

Check if game is currently installed.

Returns
True if status is Installed or Running

For Steam games, the steamInstalled metadata flag takes precedence since it's synced from Steam's actual state.

Definition at line 944 of file game.h.

References Installed, metadata, Running, source, status, and Steam.

Referenced by GameActionFactory::addLaunchActions(), GameActionFactory::addOpenFolderAction(), GameActionFactory::addSteamActions(), DetailsPanelManager::Impl::update(), and DetailsPanelManager::Impl::updateLaunchButton().

◆ isRunning()

bool Game::isRunning ( ) const
inline

Check if game is currently running.

Returns
True if status is Running

Definition at line 959 of file game.h.

References Running, and status.

◆ serializeMetadata()

std::string Game::serializeMetadata ( ) const

Serialize metadata to JSON.

Returns
JSON string containing metadata

Definition at line 817 of file game.cpp.

References metadata.

◆ serializeRunnerConfig()

std::string Game::serializeRunnerConfig ( ) const

Serialize runner configuration to JSON.

Returns
JSON string containing runner config

Definition at line 647 of file game.cpp.

References runnerConfig.

Referenced by GameDatabase::insertGame().

◆ syncPlatformFromRunner()

void Game::syncPlatformFromRunner ( )
inline

Sync the deprecated platform field from the current runner and source.

Call this after setting runner/source to keep platform consistent. This exists for backward compatibility with code that still reads platform.

Definition at line 912 of file game.h.

References DOSBox, Native, Proton, runner, ScummVM, source, Steam, and Wine.

Referenced by ScannedGame::toGame(), and SteamGame::toGame().

Member Data Documentation

◆ activeTemplateName

std::string Game::activeTemplateName

Currently active template name (empty = using runnerConfig directly).

Definition at line 797 of file game.h.

Referenced by GameDatabase::insertGame(), and DetailsPanelManager::Impl::update().

◆ cacheInitialized_

bool Game::cacheInitialized_ = false
mutable

True if caches have been computed.

Definition at line 835 of file game.h.

Referenced by getDescriptionLower(), getDeveloperLower(), getNameLower(), getPublisherLower(), and invalidateCache().

◆ collections

◆ completionStatus

User's completion status.

Definition at line 810 of file game.h.

Referenced by getCompletionStatusName(), and DetailsPanelManager::Impl::update().

◆ configTemplates

std::map<std::string, GameRunnerConfig> Game::configTemplates

Named configuration templates (presets) that can be switched between Key is template name (e.g., "Performance", "Quality", "Compatibility").

Definition at line 794 of file game.h.

Referenced by GameDatabase::insertGame(), and DetailsPanelManager::Impl::update().

◆ descriptionLowerCache_

std::string Game::descriptionLowerCache_
mutable

Cached lowercase description for case-insensitive search (computed on first access).

Definition at line 833 of file game.h.

Referenced by getDescriptionLower(), and getNameLower().

◆ developerLowerCache_

std::string Game::developerLowerCache_
mutable

Cached lowercase developer for case-insensitive search (computed on first access).

Definition at line 829 of file game.h.

Referenced by getDeveloperLower(), and getNameLower().

◆ hltbInfo

HowLongToBeatInfo Game::hltbInfo

Time-to-beat estimates.

Definition at line 812 of file game.h.

Referenced by getCompletionPercentage(), getRemainingPlaytime(), and DetailsPanelManager::Impl::update().

◆ id

◆ installPath

std::string Game::installPath

◆ installSizeBytes

uint64_t Game::installSizeBytes

◆ isFavorite

bool Game::isFavorite

◆ metadata

◆ name

◆ nameLowerCache_

std::string Game::nameLowerCache_
mutable

Cached lowercase name for case-insensitive search (computed on first access).

Definition at line 827 of file game.h.

Referenced by getNameLower().

◆ platform

GamePlatform Game::platform
Deprecated
Platform/runner type for execution (use source + runner)

Definition at line 776 of file game.h.

Referenced by core::GameLibraryController::Impl::passesFilter().

◆ publisherLowerCache_

std::string Game::publisherLowerCache_
mutable

Cached lowercase publisher for case-insensitive search (computed on first access).

Definition at line 831 of file game.h.

Referenced by getNameLower(), and getPublisherLower().

◆ recentSessions

std::vector<PlaySession> Game::recentSessions

Recent play sessions (last 20 kept in memory).

Definition at line 811 of file game.h.

Referenced by getAverageSessionDuration(), and DetailsPanelManager::Impl::update().

◆ runner

◆ runnerConfig

◆ source

◆ statistics

◆ status

◆ userNotes

std::string Game::userNotes

User's personal notes about the game.

Definition at line 813 of file game.h.

Referenced by DetailsPanelManager::Impl::eventFilter(), and DetailsPanelManager::Impl::update().


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