Add comparison function for OverworldItem class
- Introduced CompareOverworldItems function to compare two vectors of OverworldItem objects for equality based on their properties (x, y, id). - Included necessary header for algorithm functions to support the new comparison logic.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#ifndef YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
|
#ifndef YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
|
||||||
#define YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
|
#define YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -65,6 +66,25 @@ class OverworldItem : public GameEntity {
|
|||||||
bool deleted = false;
|
bool deleted = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool CompareOverworldItems(const std::vector<OverworldItem>& items1,
|
||||||
|
const std::vector<OverworldItem>& items2) {
|
||||||
|
if (items1.size() != items2.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto is_same_item = [](const OverworldItem& a, const OverworldItem& b) {
|
||||||
|
return a.x_ == b.x_ && a.y_ == b.y_ && a.id_ == b.id_;
|
||||||
|
};
|
||||||
|
|
||||||
|
return std::all_of(items1.begin(), items1.end(),
|
||||||
|
[&](const OverworldItem& it) {
|
||||||
|
return std::any_of(items2.begin(), items2.end(),
|
||||||
|
[&](const OverworldItem& other) {
|
||||||
|
return is_same_item(it, other);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<std::string> kSecretItemNames = {
|
const std::vector<std::string> kSecretItemNames = {
|
||||||
"Nothing", // 0
|
"Nothing", // 0
|
||||||
"Green Rupee", // 1
|
"Green Rupee", // 1
|
||||||
|
|||||||
Reference in New Issue
Block a user