stmm-games-doc  0.32.0
Classes | Public Types | Public Member Functions | List of all members
stmg::Variable Class Reference

Classes

class  Value
 The formatted representation of a variable's value. More...
 
struct  VariableType
 The variable type. More...
 

Public Types

enum  VARIABLE_TIME_BASE { VARIABLE_TIME_BASE_MILLISEC = 1, VARIABLE_TIME_BASE_SEC = 2, VARIABLE_TIME_BASE_MIN = 3 }
 
enum  VARIABLE_FORMAT { VARIABLE_FORMAT_NUMBER = 1, VARIABLE_FORMAT_MILL = 2, VARIABLE_FORMAT_MIN_SEC = 5, VARIABLE_FORMAT_MIN_SEC_MILLISEC = 6 }
 

Public Member Functions

 Variable (const VariableType *p0VarType, Game *p0Game) noexcept
 Constructor. More...
 
Value getValue () const noexcept
 Get the value. More...
 
int32_t get () const noexcept
 Get the value as a number. More...
 
void set (int32_t nValue) noexcept
 Set the value. More...
 
void inc (int32_t nInc) noexcept
 Add a value to the current value. More...
 
bool isChanged () const noexcept
 Tells whether the variable changed in the current game tick. More...
 
const VariableTypegetType () const noexcept
 Returns the type of the variable. More...
 
std::string toFormattedString () const noexcept
 The value as a string. More...
 

Member Enumeration Documentation

◆ VARIABLE_FORMAT

Enumerator
VARIABLE_FORMAT_NUMBER 

'131234 -> 131234'

VARIABLE_FORMAT_MILL 

131234 -> 131'234

VARIABLE_FORMAT_MIN_SEC 

'131 -> 2:11'

VARIABLE_FORMAT_MIN_SEC_MILLISEC 

'131234 -> 2:11.234'

◆ VARIABLE_TIME_BASE

Enumerator
VARIABLE_TIME_BASE_MILLISEC 

'milliseconds(131234) = 131234 (131234 = 2:11.234 = 2 * 60 + 11 * 1000 + 234)'

VARIABLE_TIME_BASE_SEC 

'seconds(131234) = 131 (131234 = 2:11.234 -> 2:11 = 2 * 60 + 11)'

VARIABLE_TIME_BASE_MIN 

'minutes(131234) = 2 (131234 = 2:11.234 -> 2)'

Constructor & Destructor Documentation

◆ Variable()

stmg::Variable::Variable ( const VariableType p0VarType,
Game p0Game 
)
noexcept

Constructor.

Using this instance while the variable type or the game are deleted is undefined behavior.

Parameters
p0VarTypeThe type. Cannot be null. Must outlive the instance (usage).
p0GameThe game. Cannot be null. Must outlive the instance (usage).

Member Function Documentation

◆ get()

int32_t stmg::Variable::get ( ) const
noexcept

Get the value as a number.

Returns
The value without format information.

◆ getType()

const VariableType& stmg::Variable::getType ( ) const
inlinenoexcept

Returns the type of the variable.

Returns
The type.

◆ getValue()

Value stmg::Variable::getValue ( ) const
noexcept

Get the value.

Returns
The value with format information.

◆ inc()

void stmg::Variable::inc ( int32_t  nInc)
noexcept

Add a value to the current value.

Doesn't check for overflows.

Parameters
nIncThe to be added value.

◆ isChanged()

bool stmg::Variable::isChanged ( ) const
noexcept

Tells whether the variable changed in the current game tick.

◆ set()

void stmg::Variable::set ( int32_t  nValue)
noexcept

Set the value.

If the variable is read-only, has no effect.

Parameters
nValueThe new value.

◆ toFormattedString()

std::string stmg::Variable::toFormattedString ( ) const
noexcept

The value as a string.

Returns
The string representation of the value.