Exemplo n.º 1
0
bool SavePersistedData(void)
{
	CharacterData *characterData;

	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
	}
	
	if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData));
		return false;
	}

	if(GetSizeOfItemsOwned() > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("Item data is too big to save (%d).", GetSizeOfItemsOwned());
		return false;
	}

	ProfileLogStart("SavePersistedData");
	INFO_LOG("Saving persisted data.");
	DEBUG_VERBOSE_LOG("Saving meta data");
	persist_write_bool(PERSISTED_IS_DATA_SAVED, true);
	persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION);
	persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY);
	
	DEBUG_VERBOSE_LOG("Saving character");
	characterData = GetCharacter();
	persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	
	DEBUG_VERBOSE_LOG("Saving floor");
	persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor());
	
	DEBUG_VERBOSE_LOG("Saving item data");
	persist_write_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned());
	
	DEBUG_VERBOSE_LOG("Saving stat points");
	persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased());

	DEBUG_VERBOSE_LOG("Saving option data");
	persist_write_bool(PERSISTED_VIBRATION, GetVibration());
	persist_write_bool(PERSISTED_FAST_MODE, GetFastMode());
	persist_write_bool(PERSISTED_WORKER_APP, GetWorkerApp());
	persist_write_bool(PERSISTED_WORKER_CAN_LAUNCH, GetWorkerCanLaunch());
	persist_write_bool(PERSISTED_USE_OLD_ASSETS, GetUseOldAssets());

	DEBUG_VERBOSE_LOG("Saving combat data");
	persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle());
	persist_write_int(PERSISTED_MONSTER_TYPE, GetMostRecentMonster());
	persist_write_int(PERSISTED_MONSTER_HEALTH, GetCurrentMonsterHealth());
	INFO_LOG("Done saving persisted data.");
	ProfileLogStop("SavePersistedData");
	
	return true;
}
Exemplo n.º 2
0
bool SavePersistedData(void)
{
	CharacterData *characterData;

	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
	}
	
	if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData));
		return false;
	}

	INFO_LOG("Saving persisted data.");
	persist_write_bool(PERSISTED_IS_DATA_SAVED, true);
	persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION);
	persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY);
	
	characterData = GetCharacter();
	persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	
	persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor());
	
	uint8_t * itemsOwned = malloc(sizeof(uint8_t) * ITEM_TYPE_COUNT);
	GetItemsOwned(itemsOwned);
	persist_write_data(PERSISTED_ITEM_DATA, itemsOwned, sizeof(itemsOwned));
	free(itemsOwned);
	
	persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased());

	persist_write_bool(PERSISTED_VIBRATION, GetVibration());
	persist_write_bool(PERSISTED_FAST_MODE, GetFastMode());
	persist_write_bool(PERSISTED_EASY_MODE, GetEasyMode());

	persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle());
	
	persist_write_data(PERSISTED_MONSTER_TYPE, GetCurMonster(), sizeof(MonsterInfo));
	
	CardSave saves[NB_TYPE_CARDS];
	GetCardSaves(saves);
	persist_write_data(PERSISTED_CARD_DECK, saves, sizeof(saves));
	
	persist_write_int(PERSISTED_ENTRIES_SIZE, GetEntriesSize());
	
	return true;
}