Skip to content

Commit

Permalink
Resolve #6 by vastly improving loadValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
Murphy Angelo authored and murfalo committed Jul 10, 2016
1 parent aed4051 commit d351b5f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
27 changes: 9 additions & 18 deletions editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,16 @@ Editor::~Editor()
std::string Editor::loadValue(std::string specifier)
{
/* Returns the value assigned to specifier. */
std::string value = "";
// Find the value by determining the string between start and end (Ex: 0hp : <value> : System.Int32;
std::string startDelimiter = " " + specifier + Strings::paddedSeperator;
std::string endDelimiter = Strings::paddedSeperator;

// Create a stringstream and set it's contents to playerData
std::stringstream playerDataStream(*(this->_playerData));
// Find the location of key in playerData
std::size_t first = this->_playerData->find(startDelimiter);
first += startDelimiter.length(); // Move to the position just before value
std::size_t last = this->_playerData->find(endDelimiter, first);

std::string word;

// Search the file up to the specifier
while (playerDataStream >> word)
if (word == specifier) break;

// Find the value
while(playerDataStream >> word && word != Strings::terminator)
{
if (word != Strings::separator && word != Strings::intSpecifier && word != Strings::stringSpecifier)
value = value.empty() ? word : value + " " + word;
}

return value;
return this->_playerData->substr(first, last-first);
}

void Editor::replaceValue(std::string specifier, std::string oldValue, std::string newValue)
Expand Down Expand Up @@ -165,7 +156,7 @@ void Editor::loadCharacterItemBrowser()
int *Editor::equippedStats()
{
int* equippedStats = new int[Items::NUM_STATS];
Items::Equippable currentEquippable(0,0,0,0,0,0);
Items::Equippable currentEquippable;
int itemLevel;
int itemRarityBonus;

Expand Down
3 changes: 2 additions & 1 deletion items.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ namespace Items
/* Item Stats */
struct Equippable
{
Equippable::Equippable(int vitality, int dexterity, int magic, int strength, int tech, int faith) :
Equippable() : vitality(0), dexterity(0), magic(0), strength(0), tech(0), faith(0) {}
Equippable(int vitality, int dexterity, int magic, int strength, int tech, int faith) :
vitality(vitality), dexterity(dexterity), magic(magic), strength(strength), tech(tech), faith(faith) {}
int vitality;
int dexterity;
Expand Down
5 changes: 5 additions & 0 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,11 @@
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<property name="font">
<font>
<family>Tahoma</family>
</font>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
Expand Down
14 changes: 9 additions & 5 deletions strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Strings
static const std::string playerDataSuffix = "/AppData/LocalLow/DefaultCompany/Roguelands/PlayerPrefs.txt";
static const std::string tmpDataSuffix = "/AppData/LocalLow/DefaultCompany/Roguelands/.txt";
static const QString appStyle = "WindowsVista";
static const QString appStyleSheet = "* { font-family: \"Segoe UI\"; font-size: 11px; font-weight: normal }";
static const QString appStyleSheet = "* { font-family: \"Tahoma\"; font-size: 11px; font-weight: normal }";
#elif defined(Q_OS_MAC)
static const std::string playerDataPrefix = "/Users/";
static const std::string playerDataSuffix = "/Library/Application Support/unity.DefaultCompany.Roguelands/PlayerPrefs.txt";
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace Strings
static const std::string allegianceLevelSpecifier = "aq";
static const std::string allegianceSpecifier = "allegiance";
static const std::string combatChipSpecifier = "cc";
static const std::string characterCurrentHealthSpecifier = "health";
static const std::string characterCurrentHealthSpecifier = "hp";
static const std::string characterCurrentManaSpecifier = "mana";

/************ User Interface ************/
Expand Down Expand Up @@ -141,6 +141,8 @@ namespace Strings
static const QString faithEditObjectName = "spinBoxFaiVal";
static const QString characterLevelObjectName = "spinBoxLevelVal";
static const QString allegianceLevelObjectName = "spinBoxAllegianceLevelVal";
static const QString characterHealthObjectName = "spinBoxHealthVal";
static const QString characterManaObjectName = "spinBoxManaVal";


/*** Character Tab ***/
Expand Down Expand Up @@ -198,16 +200,18 @@ namespace Strings
/* Arrays for Iteration */

// Total number of spinBoxes and comboBoxes on the character tab
static const int CHARACTER_TAB_NUM_SPINBOXES = 8;
static const int CHARACTER_TAB_NUM_SPINBOXES = 10;
static const int CHARACTER_TAB_NUM_COMBOBOXES = 7;

// Arrays for use in spinBox iteration
static const QString cSpinBoxObjectNames[CHARACTER_TAB_NUM_SPINBOXES] = { vitalityEditObjectName, dexterityEditObjectName, magicEditObjectName,
strengthEditObjectName, techEditObjectName, faithEditObjectName,
characterLevelObjectName, allegianceLevelObjectName };
characterLevelObjectName, allegianceLevelObjectName,
characterHealthObjectName, characterManaObjectName };
static const std::string cSpinBoxSpecifiers[CHARACTER_TAB_NUM_SPINBOXES] = { vitalitySpecifier, dexteritySpecifier, magicSpecifier,
strengthSpecifier, techSpecifier, faithSpecifier,
characterLevelSpecifier, allegianceLevelSpecifier};
characterLevelSpecifier, allegianceLevelSpecifier,
characterCurrentHealthSpecifier, characterCurrentManaSpecifier};

// Arrays for use in comboBox iteration
static const QString cComboBoxObjectNames[CHARACTER_TAB_NUM_COMBOBOXES] = { difficultyEditObjectName, raceEditObjectName, classEditObjectName,
Expand Down

0 comments on commit d351b5f

Please sign in to comment.