Skip to content

Commit 695238f

Browse files
committed
The big funny
1 parent 59e40d6 commit 695238f

File tree

11 files changed

+196
-190
lines changed

11 files changed

+196
-190
lines changed

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ set(CMAKE_CXX_STANDARD 20)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
55
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
set(GEODE_DISABLE_PRECOMPILED_HEADERS ON)
67

7-
project(SearchHistory VERSION 1.1.1)
8+
project(SearchHistory VERSION 1.1.2)
89

910
add_library(${PROJECT_NAME} SHARED
10-
src/main.cpp
11+
src/classes/SearchHistoryNode.cpp
12+
src/classes/SearchHistoryPopup.cpp
13+
src/hooks/LevelSearchLayer.cpp
1114
src/SearchHistory.cpp
12-
src/SearchHistoryNode.cpp
13-
src/SearchHistoryPopup.cpp
1415
)
1516

1617
if (NOT DEFINED ENV{GEODE_SDK})

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Search History Changelog
2+
## v1.1.2 (2025-04-01)
3+
- Internal code changes (April Fools' Day)
4+
25
## v1.1.1 (2024-11-15)
36
- Ported to Geode v4.0.0-beta.1
47

mod.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
{
2-
"geode": "4.0.0-beta.1",
2+
"geode": "4.3.1",
33
"gd": {
44
"android": "2.2074",
55
"win": "2.2074",
66
"mac": "2.2074"
77
},
8-
"version": "v1.1.1",
8+
"version": "v1.1.2",
99
"id": "hiimjustin000.search_history",
1010
"name": "Search History",
1111
"developer": "hiimjustin000",
1212
"description": "A mod that allows you to view your search history.",
13-
"dependencies": [
14-
{
15-
"id": "geode.node-ids",
16-
"version": ">=v1.12.0",
17-
"importance": "required"
18-
}
19-
],
13+
"dependencies": {
14+
"geode.node-ids": ">=v1.9.0"
15+
},
2016
"resources": {
2117
"sprites": [
2218
"resources/*.png"
@@ -50,7 +46,7 @@
5046
"links": {
5147
"community": "https://discord.gg/QVKmbvBXA7",
5248
"source": "https://github.com/hiimjustin000/SearchHistory",
53-
"homepage": "https://www.hiimjustin000.com"
49+
"homepage": "https://www.hiimjasmine00.com"
5450
},
5551
"tags": [
5652
"enhancement",

src/SearchHistory.cpp

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#include "SearchHistory.hpp"
2+
#include <Geode/binding/GJSearchObject.hpp>
3+
#include <Geode/loader/Mod.hpp>
4+
#include <Geode/utils/ranges.hpp>
25

36
using namespace geode::prelude;
47

58
void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
69
auto history = Mod::get()->getSavedValue<std::vector<SearchHistoryObject>>("search-history");
710

8-
auto difficultyStrings = search->m_difficulty != "-" ? string::split(search->m_difficulty, ",") : std::vector<std::string>();
9-
std::vector<int> difficulties;
10-
for (auto const& str : difficultyStrings) {
11-
difficulties.push_back(std::stoi(str));
12-
}
11+
auto difficulties = ranges::reduce<std::vector<int>>(
12+
search->m_difficulty != "-" ? string::split(search->m_difficulty, ",") : std::vector<std::string>(),
13+
[](std::vector<int>& vec, const std::string& str) {
14+
if (auto num = numFromString<int>(str)) vec.push_back(num.unwrap());
15+
});
1316

14-
auto lengthStrings = search->m_length != "-" ? string::split(search->m_length, ",") : std::vector<std::string>();
15-
std::vector<int> lengths;
16-
for (auto const& str : lengthStrings) {
17-
lengths.push_back(std::stoi(str));
18-
}
17+
auto lengths = ranges::reduce<std::vector<int>>(
18+
search->m_length != "-" ? string::split(search->m_length, ",") : std::vector<std::string>(),
19+
[](std::vector<int>& vec, const std::string& str) {
20+
if (auto num = numFromString<int>(str)) vec.push_back(num.unwrap());
21+
});
1922

2023
SearchHistoryObject obj = {
2124
.time = time,
@@ -40,9 +43,7 @@ void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
4043
.star = search->m_starFilter
4144
};
4245

43-
auto found = std::find_if(history.begin(), history.end(), [&obj](SearchHistoryObject const& o) {
44-
return obj == o;
45-
});
46+
auto found = std::ranges::find_if(history, [&obj](const SearchHistoryObject& o) { return obj == o; });
4647

4748
if (found != history.end()) history.erase(found);
4849

@@ -64,3 +65,69 @@ void SearchHistory::remove(int index) {
6465
history.erase(history.begin() + index);
6566
Mod::get()->setSavedValue("search-history", history);
6667
}
68+
69+
Result<std::vector<SearchHistoryObject>> matjson::Serialize<std::vector<SearchHistoryObject>>::fromJson(const matjson::Value& value) {
70+
if (!value.isArray()) return Err("Expected array");
71+
72+
return Ok(ranges::reduce<std::vector<SearchHistoryObject>>(value.asArray().unwrap(),
73+
[](std::vector<SearchHistoryObject>& vec, const matjson::Value& elem) {
74+
SearchHistoryObject obj = {
75+
.time = (int64_t)elem["time"].asInt().unwrapOr(0),
76+
.type = (int)elem["type"].asInt().unwrapOr(0),
77+
.query = elem["query"].asString().unwrapOr(""),
78+
.difficulties = ranges::map<std::vector<int>>(
79+
elem["difficulties"].isArray() ? elem["difficulties"].asArray().unwrap() : std::vector<matjson::Value>(),
80+
[](const matjson::Value& e) { return e.asInt().unwrapOr(0); }),
81+
.lengths = ranges::map<std::vector<int>>(
82+
elem["lengths"].isArray() ? elem["lengths"].asArray().unwrap() : std::vector<matjson::Value>(),
83+
[](const matjson::Value& e) { return e.asInt().unwrapOr(0); }),
84+
.uncompleted = elem["uncompleted"].asBool().unwrapOr(false),
85+
.completed = elem["completed"].asBool().unwrapOr(false),
86+
.featured = elem["featured"].asBool().unwrapOr(false),
87+
.original = elem["original"].asBool().unwrapOr(false),
88+
.twoPlayer = elem["two-player"].asBool().unwrapOr(false),
89+
.coins = elem["coins"].asBool().unwrapOr(false),
90+
.epic = elem["epic"].asBool().unwrapOr(false),
91+
.legendary = elem["legendary"].asBool().unwrapOr(false),
92+
.mythic = elem["mythic"].asBool().unwrapOr(false),
93+
.song = elem["song"].asBool().unwrapOr(false),
94+
.customSong = elem["custom-song"].asBool().unwrapOr(false),
95+
.songID = (int)elem["song-id"].asInt().unwrapOr(0),
96+
.demonFilter = (int)elem["demon-filter"].asInt().unwrapOr(0),
97+
.noStar = elem["no-star"].asBool().unwrapOr(false),
98+
.star = elem["star"].asBool().unwrapOr(false)
99+
};
100+
101+
if (!std::ranges::any_of(vec, [&obj](const SearchHistoryObject& o) { return obj == o; })) vec.push_back(obj);
102+
}));
103+
}
104+
105+
matjson::Value matjson::Serialize<std::vector<SearchHistoryObject>>::toJson(const std::vector<SearchHistoryObject>& vec) {
106+
return ranges::map<std::vector<matjson::Value>>(vec, [](const SearchHistoryObject& obj) {
107+
matjson::Value historyObject;
108+
historyObject["time"] = obj.time;
109+
historyObject["type"] = obj.type;
110+
if (!obj.query.empty()) historyObject["query"] = obj.query;
111+
if (!obj.difficulties.empty()) historyObject["difficulties"] = obj.difficulties;
112+
if (!obj.lengths.empty()) historyObject["lengths"] = obj.lengths;
113+
if (obj.uncompleted) historyObject["uncompleted"] = obj.uncompleted;
114+
if (obj.completed) historyObject["completed"] = obj.completed;
115+
if (obj.featured) historyObject["featured"] = obj.featured;
116+
if (obj.original) historyObject["original"] = obj.original;
117+
if (obj.twoPlayer) historyObject["two-player"] = obj.twoPlayer;
118+
if (obj.coins) historyObject["coins"] = obj.coins;
119+
if (obj.epic) historyObject["epic"] = obj.epic;
120+
if (obj.legendary) historyObject["legendary"] = obj.legendary;
121+
if (obj.mythic) historyObject["mythic"] = obj.mythic;
122+
if (obj.song) {
123+
historyObject["song"] = obj.song;
124+
if (obj.customSong) historyObject["custom-song"] = obj.customSong;
125+
historyObject["song-id"] = obj.songID;
126+
}
127+
if (obj.demonFilter != 0) historyObject["demon-filter"] = obj.demonFilter;
128+
if (obj.noStar) historyObject["no-star"] = obj.noStar;
129+
if (obj.star) historyObject["star"] = obj.star;
130+
131+
return historyObject;
132+
});
133+
}

src/SearchHistory.hpp

Lines changed: 6 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
#include <Geode/GeneratedPredeclare.hpp>
4+
#include <matjson.hpp>
5+
36
struct SearchHistoryObject {
47
int64_t time;
58
int type;
@@ -22,7 +25,7 @@ struct SearchHistoryObject {
2225
bool noStar;
2326
bool star;
2427

25-
bool operator==(SearchHistoryObject const& other) const {
28+
bool operator==(const SearchHistoryObject& other) const {
2629
return floor(time / 86400.0) == floor(other.time / 86400.0) &&
2730
type == other.type &&
2831
query == other.query &&
@@ -55,98 +58,6 @@ class SearchHistory {
5558

5659
template<>
5760
struct matjson::Serialize<std::vector<SearchHistoryObject>> {
58-
static geode::Result<std::vector<SearchHistoryObject>> fromJson(matjson::Value const& value) {
59-
if (!value.isArray()) return geode::Err("Expected array");
60-
61-
std::vector<SearchHistoryObject> vec;
62-
63-
for (auto const& elem : value.asArray().unwrap()) {
64-
std::vector<int> difficulties;
65-
if (elem.contains("difficulties") && elem["difficulties"].isArray()) {
66-
for (auto const& e : elem["difficulties"].asArray().unwrap()) {
67-
difficulties.push_back(e.asInt().unwrapOr(0));
68-
}
69-
}
70-
71-
std::vector<int> lengths;
72-
if (elem.contains("lengths") && elem["lengths"].isArray()) {
73-
for (auto const& e : elem["lengths"].asArray().unwrap()) {
74-
lengths.push_back(e.asInt().unwrapOr(0));
75-
}
76-
}
77-
78-
SearchHistoryObject obj = {
79-
.time = (int64_t)elem["time"].asInt().unwrapOr(0),
80-
.type = (int)elem["type"].asInt().unwrapOr(0),
81-
.query = elem["query"].asString().unwrapOr(""),
82-
.difficulties = difficulties,
83-
.lengths = lengths,
84-
.uncompleted = elem["uncompleted"].asBool().unwrapOr(false),
85-
.completed = elem["completed"].asBool().unwrapOr(false),
86-
.featured = elem["featured"].asBool().unwrapOr(false),
87-
.original = elem["original"].asBool().unwrapOr(false),
88-
.twoPlayer = elem["two-player"].asBool().unwrapOr(false),
89-
.coins = elem["coins"].asBool().unwrapOr(false),
90-
.epic = elem["epic"].asBool().unwrapOr(false),
91-
.legendary = elem["legendary"].asBool().unwrapOr(false),
92-
.mythic = elem["mythic"].asBool().unwrapOr(false),
93-
.song = elem["song"].asBool().unwrapOr(false),
94-
.customSong = elem["custom-song"].asBool().unwrapOr(false),
95-
.songID = (int)elem["song-id"].asInt().unwrapOr(0),
96-
.demonFilter = (int)elem["demon-filter"].asInt().unwrapOr(0),
97-
.noStar = elem["no-star"].asBool().unwrapOr(false),
98-
.star = elem["star"].asBool().unwrapOr(false)
99-
};
100-
101-
if (!std::any_of(vec.begin(), vec.end(), [&obj](SearchHistoryObject const& o) {
102-
return obj == o;
103-
})) vec.push_back(obj);
104-
}
105-
106-
return geode::Ok(vec);
107-
}
108-
109-
static matjson::Value toJson(std::vector<SearchHistoryObject> const& vec) {
110-
std::vector<matjson::Value> arr;
111-
112-
for (auto const& obj : vec) {
113-
std::vector<matjson::Value> difficulties;
114-
for (int const& e : obj.difficulties) {
115-
difficulties.push_back(e);
116-
}
117-
118-
std::vector<matjson::Value> lengths;
119-
for (int const& e : obj.lengths) {
120-
lengths.push_back(e);
121-
}
122-
123-
matjson::Value historyObject;
124-
historyObject["time"] = obj.time;
125-
historyObject["type"] = obj.type;
126-
if (!obj.query.empty()) historyObject["query"] = obj.query;
127-
if (!difficulties.empty()) historyObject["difficulties"] = difficulties;
128-
if (!lengths.empty()) historyObject["lengths"] = lengths;
129-
if (obj.uncompleted) historyObject["uncompleted"] = obj.uncompleted;
130-
if (obj.completed) historyObject["completed"] = obj.completed;
131-
if (obj.featured) historyObject["featured"] = obj.featured;
132-
if (obj.original) historyObject["original"] = obj.original;
133-
if (obj.twoPlayer) historyObject["two-player"] = obj.twoPlayer;
134-
if (obj.coins) historyObject["coins"] = obj.coins;
135-
if (obj.epic) historyObject["epic"] = obj.epic;
136-
if (obj.legendary) historyObject["legendary"] = obj.legendary;
137-
if (obj.mythic) historyObject["mythic"] = obj.mythic;
138-
if (obj.song) {
139-
historyObject["song"] = obj.song;
140-
if (obj.customSong) historyObject["custom-song"] = obj.customSong;
141-
historyObject["song-id"] = obj.songID;
142-
}
143-
if (obj.demonFilter != 0) historyObject["demon-filter"] = obj.demonFilter;
144-
if (obj.noStar) historyObject["no-star"] = obj.noStar;
145-
if (obj.star) historyObject["star"] = obj.star;
146-
147-
arr.push_back(historyObject);
148-
}
149-
150-
return arr;
151-
}
61+
static geode::Result<std::vector<SearchHistoryObject>> fromJson(const matjson::Value&);
62+
static matjson::Value toJson(const std::vector<SearchHistoryObject>&);
15263
};

src/SearchHistoryNode.hpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)