Skip to content

Commit

Permalink
You've gone Incognito
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Aug 21, 2024
1 parent 3e155d5 commit 625cb11
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(SearchHistory VERSION 1.0.2)
project(SearchHistory VERSION 1.0.3)

add_library(${PROJECT_NAME} SHARED
src/main.cpp
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ A mod that allows you to view your search history.
## Features
- A button in the level search menu that allows you to view your search history
- A popup that shows your search history, including a filter text box, and entries that can be used to search again
- Incognito mode, which allows you to search without saving to your search history

## Credits
- [Kabslantivity](https://gdbrowser.com/u/17597362) - Initial idea for the mod
Expand Down
5 changes: 3 additions & 2 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ A mod that allows you to view your search history.
## Features
- A button in the level search menu that allows you to view your search history
- A popup that shows your search history, including a filter text box, and entries that can be used to search again
- Incognito mode, which allows you to search without saving to your search history

## Credits
- [Kabslantivity](user:17597362) - Initial idea for the mod
- [at4pm](user:27791517) - Additional ideas for the mod
- [hiimjustin000](user:7466002) - Creator of the mod

## Gallery
![Search History Popup 1](hiimjustin000.search_history/image1.png?scale=0.6)\
![Search History Popup 2](hiimjustin000.search_history/image2.png?scale=0.6)
![Search History Popup 1](hiimjustin000.search_history/image1.png?scale=0.625)\
![Search History Popup 2](hiimjustin000.search_history/image2.png?scale=0.625)
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Search History Changelog
## v1.0.3 (2024-08-20)
- Added incognito mode

## v1.0.2 (2024-08-08)
- Removed the search confirmation popup

Expand Down
8 changes: 7 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"win": "2.206",
"mac": "2.206"
},
"version": "v1.0.2",
"version": "v1.0.3",
"id": "hiimjustin000.search_history",
"name": "Search History",
"developer": "hiimjustin000",
Expand All @@ -29,6 +29,12 @@
}
},
"settings": {
"incognito-mode": {
"name": "Incognito Mode",
"description": "Whether or not to hide the search history button and not save any searches.",
"type": "bool",
"default": false
},
"12-hour-time": {
"name": "12-Hour Time",
"description": "Whether or not to use 12-hour time on the time label.",
Expand Down
6 changes: 3 additions & 3 deletions src/SearchHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
auto history = Mod::get()->getSavedValue<std::vector<SearchHistoryObject>>("search-history");

auto difficultyStrings = search->m_difficulty != "-" ? string::split(search->m_difficulty, ",") : std::vector<std::string>();
auto difficulties = std::vector<int>();
std::vector<int> difficulties;
for (auto const& str : difficultyStrings) {
difficulties.push_back(std::stoi(str));
}

auto lengthStrings = search->m_length != "-" ? string::split(search->m_length, ",") : std::vector<std::string>();
auto lengths = std::vector<int>();
std::vector<int> lengths;
for (auto const& str : lengthStrings) {
lengths.push_back(std::stoi(str));
}
Expand Down Expand Up @@ -42,7 +42,7 @@ void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
}

void SearchHistory::clear() {
Mod::get()->setSavedValue("search-history", std::vector<SearchHistoryObject>());
Mod::get()->setSavedValue<std::vector<SearchHistoryObject>>("search-history", {});
}

std::vector<SearchHistoryObject> SearchHistory::get() {
Expand Down
12 changes: 6 additions & 6 deletions src/SearchHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class SearchHistory {
template<>
struct matjson::Serialize<std::vector<SearchHistoryObject>> {
static std::vector<SearchHistoryObject> from_json(matjson::Value const& value) {
auto vec = std::vector<SearchHistoryObject>();
std::vector<SearchHistoryObject> vec;

for (auto const& elem : value.as_array()) {
auto difficulties = std::vector<int>();
std::vector<int> difficulties;
for (auto const& e : elem["difficulties"].as_array()) {
difficulties.push_back(e.as_int());
}

auto lengths = std::vector<int>();
std::vector<int> lengths;
for (auto const& e : elem["lengths"].as_array()) {
lengths.push_back(e.as_int());
}
Expand Down Expand Up @@ -77,15 +77,15 @@ struct matjson::Serialize<std::vector<SearchHistoryObject>> {
}

static matjson::Value to_json(std::vector<SearchHistoryObject> const& vec) {
auto arr = matjson::Array();
matjson::Array arr;

for (auto const& obj : vec) {
auto difficulties = matjson::Array();
matjson::Array difficulties;
for (int const& e : obj.difficulties) {
difficulties.push_back(e);
}

auto lengths = matjson::Array();
matjson::Array lengths;
for (int const& e : obj.lengths) {
lengths.push_back(e);
}
Expand Down
14 changes: 10 additions & 4 deletions src/SearchHistoryNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
addChild(difficultiesNode);

for (auto difficulty : object.difficulties) {
auto difficultyFrame = std::string();
std::string difficultyFrame;
switch (difficulty) {
case -1: difficultyFrame = "diffIcon_00_btn_001.png"; break;
case -2: difficultyFrame = "diffIcon_06_btn_001.png"; break;
Expand All @@ -142,7 +142,7 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
}

if (type < 1) for (auto time : object.lengths) {
auto length = std::string();
auto length = "";
switch (time) {
case 0: length = "Tiny"; break;
case 1: length = "Short"; break;
Expand All @@ -152,7 +152,7 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
case 5: length = "Plat."; break;
}

auto lengthLabel = CCLabelBMFont::create(length.c_str(), "bigFont.fnt");
auto lengthLabel = CCLabelBMFont::create(length, "bigFont.fnt");
lengthLabel->setScale(0.3f);
difficultiesNode->addChild(lengthLabel);
}
Expand Down Expand Up @@ -198,8 +198,14 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
}

std::stringstream ss;
auto time = (time_t)object.time;
time_t time = object.time;
#ifdef GEODE_IS_WINDOWS
struct tm tm;
localtime_s(&tm, &time);
ss << std::put_time(&tm, h12 ? "%Y-%m-%d %I:%M:%S %p" : "%Y-%m-%d %H:%M:%S");
#else
ss << std::put_time(std::localtime(&time), h12 ? "%Y-%m-%d %I:%M:%S %p" : "%Y-%m-%d %H:%M:%S");
#endif

auto timeLabel = CCLabelBMFont::create(ss.str().c_str(), "chatFont.fnt");
timeLabel->setColor(white ? ccColor3B { 255, 255, 255 } : ccColor3B { 51, 51, 51 });
Expand Down
2 changes: 1 addition & 1 deletion src/SearchHistoryPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool SearchHistoryPopup::setup(SearchHistoryCallback callback) {
void SearchHistoryPopup::page(int p) {
m_scrollLayer->m_contentLayer->removeAllChildren();

auto history = std::vector<SearchHistoryObject>();
std::vector<SearchHistoryObject> history;
auto query = string::toLower(m_searchInput->getString());
for (auto const& object : SearchHistory::get()) {
if (string::toLower(object.query).find(query) != std::string::npos) history.push_back(object);
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class $modify(SHLevelSearchLayer, LevelSearchLayer) {
bool init(int type) {
if (!LevelSearchLayer::init(type)) return false;

if (Mod::get()->getSettingValue<bool>("incognito-mode")) return true;

auto historyButtonSprite = CircleButtonSprite::createWithSprite("SH_historyBtn_001.png"_spr);
historyButtonSprite->getTopNode()->setScale(1.0f);
historyButtonSprite->setScale(0.8f);
Expand Down Expand Up @@ -64,11 +66,13 @@ class $modify(SHLevelSearchLayer, LevelSearchLayer) {

void onSearch(CCObject* sender) {
LevelSearchLayer::onSearch(sender);
if (Mod::get()->getSettingValue<bool>("incognito-mode")) return;
SearchHistory::add(getSearchObject(SearchType::Search, m_searchInput->getString()), time(0), m_type);
}

void onSearchUser(CCObject* sender) {
LevelSearchLayer::onSearchUser(sender);
if (Mod::get()->getSettingValue<bool>("incognito-mode")) return;
SearchHistory::add(getSearchObject(SearchType::Users, m_searchInput->getString()), time(0), 2);
}
};

0 comments on commit 625cb11

Please sign in to comment.