Persistent Coins (#1405)
On Coin Insert, a file Save/Coin.ini is created if it does not exist, which stores the number of coins currrently in m_iCoins. Whenever m_iCoins is update, the Coin.ini is updated. On boot, Coin.ini is read and m_iCoins is set to that value. If coins in coin.ini file is greater then MAX_NUM_CREDITS then reset the value to 0.
This commit is contained in:
committed by
Colby Klein
parent
4b3507f195
commit
8f332653e1
@@ -4,10 +4,12 @@
|
||||
#include "RageLog.h"
|
||||
#include "IniFile.h"
|
||||
#include "GameConstantsAndTypes.h"
|
||||
#include "GameState.h"
|
||||
#include "SongManager.h"
|
||||
#include "RageFile.h"
|
||||
#include "XmlFile.h"
|
||||
#include "XmlFileUtil.h"
|
||||
#include "SpecialFiles.h"
|
||||
#include <ctime>
|
||||
|
||||
Bookkeeper* BOOKKEEPER = NULL; // global and accessible from anywhere in our program
|
||||
@@ -120,6 +122,17 @@ void Bookkeeper::ReadFromDisk()
|
||||
if( !XmlFileUtil::LoadFromFileShowErrors(xml, COINS_DAT) )
|
||||
return;
|
||||
|
||||
int numCoins = 0;
|
||||
ReadCoinsFile(numCoins);
|
||||
|
||||
if ( numCoins < 0 )
|
||||
numCoins = 0;
|
||||
else if ( numCoins / PREFSMAN->m_iCoinsPerCredit > MAX_NUM_CREDITS )
|
||||
numCoins = 0;
|
||||
|
||||
LOG->Trace("Number of Coins to Load on boot: %i", numCoins);
|
||||
GAMESTATE->m_iCoins.Set(numCoins);
|
||||
|
||||
LoadFromNode( &xml );
|
||||
}
|
||||
|
||||
@@ -145,6 +158,20 @@ void Bookkeeper::CoinInserted()
|
||||
++m_mapCoinsForHour[d];
|
||||
}
|
||||
|
||||
void Bookkeeper::WriteCoinsFile( int coins )
|
||||
{
|
||||
IniFile ini;
|
||||
ini.SetValue( "Bookkeeping", "Coins", coins);
|
||||
ini.WriteFile( SpecialFiles::COINS_INI );
|
||||
}
|
||||
|
||||
void Bookkeeper::ReadCoinsFile( int &coins )
|
||||
{
|
||||
IniFile ini;
|
||||
ini.ReadFile( SpecialFiles::COINS_INI );
|
||||
ini.GetValue( "Bookkeeping", "Coins", coins);
|
||||
}
|
||||
|
||||
// Return the number of coins between [beginning,ending).
|
||||
int Bookkeeper::GetNumCoinsInRange( map<Date,int>::const_iterator begin, map<Date,int>::const_iterator end ) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user