coastline 0.0.4
Loading...
Searching...
No Matches
coastline::GameText Class Reference

Read the strings of a language and of en-us, each a JSON object of strings by key, from strings/LANGUAGE.json and strings/en-us.json under assets, for the race and the menus. More...

#include <stringresources.h>

Public Member Functions

 GameText (const std::filesystem::path &assets, std::string language)
 Load strings and register the exclusive active catalogue with SDL.
 ~GameText ()
 Unregister the active catalogue and invalidate references to its strings.
 GameText (const GameText &)=delete
 Prevent copying the registered catalogue.
GameText & operator= (const GameText &)=delete
 Prevent assignment of the registered catalogue.
const std::string & Language () const
bool Empty () const
const std::string * Find (std::string_view key) const
std::string_view Resolve (std::string_view key)

Static Public Member Functions

static GameText * Active ()

Detailed Description

Read the strings of a language and of en-us, each a JSON object of strings by key, from strings/LANGUAGE.json and strings/en-us.json under assets, for the race and the menus.

A key the language lacks takes its en-us string.

Constructor & Destructor Documentation

◆ GameText() [1/2]

coastline::GameText::GameText ( const std::filesystem::path & assets,
std::string language )

Load strings and register the exclusive active catalogue with SDL.

Parameters
assetsThe prepared asset directory with strings/LANGUAGE.json and strings/en-us.json.
languageThe requested language; missing keys use en-us strings.

◆ ~GameText()

coastline::GameText::~GameText ( )

Unregister the active catalogue and invalidate references to its strings.

◆ GameText() [2/2]

coastline::GameText::GameText ( const GameText & )
delete

Prevent copying the registered catalogue.

Member Function Documentation

◆ operator=()

GameText & coastline::GameText::operator= ( const GameText & )
delete

Prevent assignment of the registered catalogue.

◆ Active()

GameText * coastline::GameText::Active ( )
static
Returns
The active text catalogue, or null outside its lifetime.

◆ Language()

const std::string & coastline::GameText::Language ( ) const
inline
Returns
The selected language.

◆ Empty()

bool coastline::GameText::Empty ( ) const
inline
Returns
Whether the catalogue is empty.

◆ Find()

const std::string * coastline::GameText::Find ( std::string_view key) const
Parameters
keyThe catalogue key to query without logging a missing translation.
Returns
The stored string, valid for the catalogue's lifetime, or null when unavailable.

◆ Resolve()

std::string_view coastline::GameText::Resolve ( std::string_view key)
Parameters
keyThe catalogue key, whose storage must outlast a returned fallback view.
Returns
The stored string or key, logging a missing key once per catalogue.

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