-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup Store code #7424
base: master
Are you sure you want to change the base?
Cleanup Store code #7424
Conversation
I think I'll submit a PR separately that changes the variable names found in stores.cpp so this PR is much easier to review. |
I think you should, this one already has conflicts despite being the latest |
34b6132
to
705e5f6
Compare
Do your self a favor and merge master rather then rebase on it with the commits you have. |
95cd85b
to
3e5daee
Compare
a69ea18
to
1243405
Compare
for (int i = 0; i < giNumberOfSmithPremiumItems; ++i) { | ||
LoadAndValidateItemData(file, Blacksmith.items[i]); | ||
} | ||
|
||
// Remove any empty/null items from the vector after loading | ||
Blacksmith.items.erase(std::remove_if(Blacksmith.items.begin(), Blacksmith.items.end(), [](const Item &item) { | ||
return item._itype == ItemType::None; | ||
}), | ||
Blacksmith.items.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there potentially be items that where not nulled and which where previously truncated by PremiumItemCount
? Maybe we should just load the given number and then fast forward the point (giNumberOfSmithPremiumItems - PremiumItemCount) * sizeof(Item)
@@ -6,69 +6,95 @@ using namespace devilution; | |||
|
|||
namespace { | |||
|
|||
TEST(Stores, AddStoreHoldRepair_magic) | |||
// Helper function to reset the playerItems vector before each test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use doc blocks for function comments:
/**
* @brief Helper function to reset the playerItems vector before each test.
*/
// Call the filtering function to remove non-repairable items | ||
Test_FilterRepairableItems(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests that the Test_FilterRepairableItems()
function works, but we would want to know if the game code works, not if the tests work...
void InitStores(); | ||
|
||
/** Spawns items sold by vendors, including premium items sold by Griswold and Wirt. */ | ||
/* Spawns items sold by vendors, including premium items sold by Griswold and Wirt. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use short form doc block for single line function comments.
/* Spawns items sold by vendors, including premium items sold by Griswold and Wirt. */ | |
/** Spawns items sold by vendors, including premium items sold by Griswold and Wirt. */ |
|
||
/** Clears premium items sold by Griswold and Wirt. */ | ||
/* Clears premium items sold by Griswold and Wirt. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Clears premium items sold by Griswold and Wirt. */ | |
/** Clears premium items sold by Griswold and Wirt. */ |
Item *itemPtr; // Pointer to the original item | ||
ItemLocation location; // Location in the player's inventory (Inventory, Belt, or Body) | ||
int index; // Index in the corresponding array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use doc blocks instead of inline comments so that the documentation is picked up properly by tools.
} | ||
|
||
void SpawnHealer(int lvl) | ||
{ | ||
constexpr size_t PinnedItemCount = 2; | ||
constexpr std::array<_item_indexes, PinnedItemCount + 1> PinnedItemTypes = { IDI_HEAL, IDI_FULLHEAL, IDI_RESURRECT }; | ||
const auto itemCount = static_cast<size_t>(RandomIntBetween(10, gbIsHellfire ? 19 : 17)); | ||
const size_t itemCount = static_cast<size_t>(RandomIntBetween(10, gbIsHellfire ? NumHealerItemsHf : NumHealerItems)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can omit size_t here since there is a cast where the type is explicit.
} | ||
|
||
SortVendor(WitchItems + PinnedItemCount); | ||
// Sort the vendor's inventory, keeping pinned items in place |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a comment on SortVendor()
|
||
if (CurrentItemIndex == 0) { | ||
HasScrollbar = false; | ||
// FIXME: Put in anonymous namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to address the FIXME
parts of the code before we merge it.
const std::string SmithMenuHeader = "Welcome to the\n\nBlacksmith's shop"; | ||
|
||
const StoreMenuOption SmithMenuOptions[] = { | ||
{ TalkID::Gossip, fmt::format("Talk to {:s}", Blacksmith.name) }, | ||
{ TalkID::BasicBuy, "Buy basic items" }, | ||
{ TalkID::Buy, "Buy premium items" }, | ||
{ TalkID::Sell, "Sell items" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these string needs to be exposed for translation, since they are mostly static global you should wrap them in the fake translation function N_()
, if you don't they will all be stripped from the language next time someone want to update a translation.
|
||
const std::string HealerMenuHeader = "Welcome to the\n\nHealer's home"; | ||
|
||
const StoreMenuOption HealerMenuOptions[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having each store statically hard coded doesn't feel like a good direction. It would probably be better to populate a single structure with the relevant store, that would also make it feasible to make custom stores at runtime in mods.
This would also let you avoid the issue of having to wrap static strings in the fake translation function since you can perform the translation where the string is defined.
|
||
void SetActiveStore(TalkID talkId) | ||
{ | ||
OldActiveStore = ActiveStore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old as in Previous?
if (itemCount <= ItemLineSpace) | ||
return false; | ||
|
||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (itemCount <= ItemLineSpace) | |
return false; | |
return true; | |
return itemCount > ItemLineSpace; |
{ | ||
int itemCount = GetItemCount(ActiveStore); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int itemCount = GetItemCount(ActiveStore); | |
const int itemCount = GetItemCount(ActiveStore); |
No description provided.