Skip to content

Commit

Permalink
optimal optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Sep 7, 2024
1 parent 625cb11 commit 1005754
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
config:
- name: Windows
os: windows-latest
build-config: RelWithDebInfo

- name: macOS
os: macos-latest
Expand All @@ -35,7 +36,7 @@ jobs:
- name: Build the mod
uses: geode-sdk/build-geode-mod@main
with:
build-config: RelWithDebInfo
build-config: ${{ matrix.config.build-config || 'Release' }}
export-pdb: true
combine: true
target: ${{ matrix.config.target }}
Expand Down
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.3)
project(SearchHistory VERSION 1.0.4)

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 @@ -9,6 +9,7 @@ A mod that allows you to view your search history.
## Credits
- [Kabslantivity](https://gdbrowser.com/u/17597362) - Initial idea for the mod
- [at4pm](https://gdbrowser.com/u/27791517) - Additional ideas for the mod
- [Krintop](https://gdbrowser.com/u/7242014) - Designer of the mod's button texture
- [hiimjustin000](https://gdbrowser.com/u/7466002) - Creator of the mod

## Gallery
Expand Down
1 change: 1 addition & 0 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A mod that allows you to view your search history.
## Credits
- [Kabslantivity](user:17597362) - Initial idea for the mod
- [at4pm](user:27791517) - Additional ideas for the mod
- [Krintop](user:7242014) - Designer of the mod's button texture
- [hiimjustin000](user:7466002) - Creator of the mod

## Gallery
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Search History Changelog
## v1.0.4 (2024-09-07)
- Removed properties from saved.json that are default values
- Changed the search history button texture and mod logo

## v1.0.3 (2024-08-20)
- Added incognito mode

Expand Down
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 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.3",
"version": "v1.0.4",
"id": "hiimjustin000.search_history",
"name": "Search History",
"developer": "hiimjustin000",
Expand Down Expand Up @@ -48,6 +48,11 @@
"default": false
}
},
"links": {
"community": "https://discord.gg/QVKmbvBXA7",
"source": "https://github.com/hiimjustin000/SearchHistory",
"homepage": "https://www.hiimjustin000.com"
},
"tags": [
"enhancement",
"interface",
Expand Down
Binary file modified resources/SH_historyBtn_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 53 additions & 44 deletions src/SearchHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,49 @@ class SearchHistory {
static void remove(int);
};

#define PROPERTY_OR_DEFAULT(obj, prop, isFunc, asFunc, def) (obj.contains(prop) && obj[prop].isFunc() ? obj[prop].asFunc() : def)

template<>
struct matjson::Serialize<std::vector<SearchHistoryObject>> {
static std::vector<SearchHistoryObject> from_json(matjson::Value const& value) {
std::vector<SearchHistoryObject> vec;

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

std::vector<int> lengths;
for (auto const& e : elem["lengths"].as_array()) {
lengths.push_back(e.as_int());
if (elem.contains("lengths") && elem["lengths"].is_array()) {
for (auto const& e : elem["lengths"].as_array()) {
lengths.push_back(e.as_int());
}
}

vec.push_back({
.time = (int64_t)elem["time"].as_double(),
.type = elem["type"].as_int(),
.query = elem["query"].as_string(),
.time = (int64_t)PROPERTY_OR_DEFAULT(elem, "time", is_number, as_double, 0),
.type = PROPERTY_OR_DEFAULT(elem, "type", is_number, as_int, 0),
.query = PROPERTY_OR_DEFAULT(elem, "query", is_string, as_string, ""),
.difficulties = difficulties,
.lengths = lengths,
.uncompleted = elem["uncompleted"].as_bool(),
.completed = elem["completed"].as_bool(),
.featured = elem["featured"].as_bool(),
.original = elem["original"].as_bool(),
.twoPlayer = elem["two-player"].as_bool(),
.coins = elem["coins"].as_bool(),
.epic = elem["epic"].as_bool(),
.legendary = elem["legendary"].as_bool(),
.mythic = elem["mythic"].as_bool(),
.song = elem["song"].as_bool(),
.customSong = elem["custom-song"].as_bool(),
.songID = elem["song-id"].as_int(),
.demonFilter = elem["demon-filter"].as_int(),
.noStar = elem["no-star"].as_bool(),
.star = elem["star"].as_bool()
.uncompleted = PROPERTY_OR_DEFAULT(elem, "uncompleted", is_bool, as_bool, false),
.completed = PROPERTY_OR_DEFAULT(elem, "completed", is_bool, as_bool, false),
.featured = PROPERTY_OR_DEFAULT(elem, "featured", is_bool, as_bool, false),
.original = PROPERTY_OR_DEFAULT(elem, "original", is_bool, as_bool, false),
.twoPlayer = PROPERTY_OR_DEFAULT(elem, "two-player", is_bool, as_bool, false),
.coins = PROPERTY_OR_DEFAULT(elem, "coins", is_bool, as_bool, false),
.epic = PROPERTY_OR_DEFAULT(elem, "epic", is_bool, as_bool, false),
.legendary = PROPERTY_OR_DEFAULT(elem, "legendary", is_bool, as_bool, false),
.mythic = PROPERTY_OR_DEFAULT(elem, "mythic", is_bool, as_bool, false),
.song = PROPERTY_OR_DEFAULT(elem, "song", is_bool, as_bool, false),
.customSong = PROPERTY_OR_DEFAULT(elem, "custom-song", is_bool, as_bool, false),
.songID = PROPERTY_OR_DEFAULT(elem, "song-id", is_number, as_int, 0),
.demonFilter = PROPERTY_OR_DEFAULT(elem, "demon-filter", is_number, as_int, 0),
.noStar = PROPERTY_OR_DEFAULT(elem, "no-star", is_bool, as_bool, false),
.star = PROPERTY_OR_DEFAULT(elem, "star", is_bool, as_bool, false)
});
}

Expand All @@ -90,28 +96,31 @@ struct matjson::Serialize<std::vector<SearchHistoryObject>> {
lengths.push_back(e);
}

arr.push_back(matjson::Object {
{ "time", obj.time },
{ "type", obj.type },
{ "query", obj.query },
{ "difficulties", difficulties },
{ "lengths", lengths },
{ "uncompleted", obj.uncompleted },
{ "completed", obj.completed },
{ "featured", obj.featured },
{ "original", obj.original },
{ "two-player", obj.twoPlayer },
{ "coins", obj.coins },
{ "epic", obj.epic },
{ "legendary", obj.legendary },
{ "mythic", obj.mythic },
{ "song", obj.song },
{ "custom-song", obj.customSong },
{ "song-id", obj.songID },
{ "demon-filter", obj.demonFilter },
{ "no-star", obj.noStar },
{ "star", obj.star }
});
matjson::Object historyObject;
historyObject["time"] = obj.time;
historyObject["type"] = obj.type;
if (!obj.query.empty()) historyObject["query"] = obj.query;
if (!difficulties.empty()) historyObject["difficulties"] = difficulties;
if (!lengths.empty()) historyObject["lengths"] = lengths;
if (obj.uncompleted) historyObject["uncompleted"] = obj.uncompleted;
if (obj.completed) historyObject["completed"] = obj.completed;
if (obj.featured) historyObject["featured"] = obj.featured;
if (obj.original) historyObject["original"] = obj.original;
if (obj.twoPlayer) historyObject["two-player"] = obj.twoPlayer;
if (obj.coins) historyObject["coins"] = obj.coins;
if (obj.epic) historyObject["epic"] = obj.epic;
if (obj.legendary) historyObject["legendary"] = obj.legendary;
if (obj.mythic) historyObject["mythic"] = obj.mythic;
if (obj.song) {
historyObject["song"] = obj.song;
if (obj.customSong) historyObject["custom-song"] = obj.customSong;
historyObject["song-id"] = obj.songID;
}
if (obj.demonFilter != 0) historyObject["demon-filter"] = obj.demonFilter;
if (obj.noStar) historyObject["no-star"] = obj.noStar;
if (obj.star) historyObject["star"] = obj.star;

arr.push_back(historyObject);
}

return arr;
Expand Down

0 comments on commit 1005754

Please sign in to comment.