Skip to content

Commit

Permalink
I love refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Feb 6, 2025
1 parent 561407e commit 5fa1ecf
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 237 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ jobs:
- uses: actions/checkout@v4

- name: Build the mod
uses: geode-sdk/build-geode-mod@main
uses: hiimjasmine00/build-geode-mod@main
with:
sdk: nightly
build-config: ${{ matrix.config.build-config || 'Release' }}
export-pdb: true
export-symbols: true
combine: true
target: ${{ matrix.config.target }}

Expand All @@ -47,22 +49,10 @@ jobs:
needs: ['build']

steps:
- uses: geode-sdk/build-geode-mod/combine@main
- uses: hiimjasmine00/build-geode-mod/combine@main
id: build

- uses: actions/upload-artifact@v4
with:
name: Build Output
path: ${{ steps.build.outputs.build-output }}

release:
name: Release the mod
runs-on: ubuntu-latest
needs: ['package']

steps:
- uses: actions/checkout@v4

- uses: hiimjustin000/release-geode-mod@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release Geode Mod

on:
workflow_dispatch:

jobs:
release:
name: Release mod
runs-on: ubuntu-latest
environment:
name: release
url: ${{ steps.mod-release.outputs.url }}

steps:
- uses: actions/checkout@v4

- uses: hiimjasmine00/release-geode-mod@main
id: mod-release
with:
token: ${{ secrets.GITHUB_TOKEN }}

publish:
name: Publish mod
runs-on: ubuntu-latest
needs: ['release']
environment:
name: publish
url: ${{ steps.mod-publish.outputs.url }}

steps:
- uses: actions/checkout@v4

- uses: hiimjasmine00/release-geode-mod/publish@main
id: mod-publish
with:
token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(GEODE_DISABLE_PRECOMPILED_HEADERS ON)

project(BetterSafe VERSION 1.1.2)
project(BetterSafe VERSION 1.1.3)

add_library(${PROJECT_NAME} SHARED
src/classes/BSCalendarPopup.cpp
src/classes/BSHoverNode.cpp
src/classes/BSSelectPopup.cpp
src/hooks/DailyLevelPage.cpp
src/hooks/MenuLayer.cpp
src/BetterSafe.cpp
src/BSCalendarPopup.cpp
src/BSHoverNode.cpp
src/main.cpp
)

if (NOT DEFINED ENV{GEODE_SDK})
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 hiimjustin000
Copyright (c) 2024-2025 hiimjasmine00

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ A mod that expands The Safe with a calendar.

# Features
- Calendars for daily, weekly and event levels, showing what was featured on each day
- daily, weekly and event level previews, showing basic information about the level on click
- Daily, weekly and event level previews, showing basic information about the level on click
- Navigation buttons to go to the previous or next month
- A label showing the current month and year, which can be used to switch to a specific month

# Credits
- [Opianisal](https://gdbrowser.com/u/25221350) - Idea for the mod
- [Every Rated Level Spreadsheet](https://docs.google.com/spreadsheets/d/1BBx9X8IYBtr7dA5cWu_smM2XBkLZzCXy7TjeEWRgag0) - Help with daily/weekly dates
- [hiimjustin000](https://gdbrowser.com/u/7466002) - Creator of the mod
- [hiimjasmine00](https://gdbrowser.com/u/7466002) - Creator of the mod

# Gallery
![Daily Calendar](./resources/daily-calendar.png)\
![Weekly Calendar](./resources/weekly-calendar.png)
![Weekly Calendar](./resources/weekly-calendar.png)\
![Event Calendar](./resources/event-calendar.png)

# License
This mod is licensed under the [MIT License](./LICENSE).
9 changes: 5 additions & 4 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ A mod that expands The Safe with a calendar.

# Features
- Calendars for daily, weekly and event levels, showing what was featured on each day
- daily, weekly and event level previews, showing basic information about the level on click
- Daily, weekly and event level previews, showing basic information about the level on click
- Navigation buttons to go to the previous or next month
- A label showing the current month and year, which can be used to switch to a specific month

# Credits
- [Opianisal](user:25221350) - Idea for the mod
- [Every Rated Level Spreadsheet](https://docs.google.com/spreadsheets/d/1BBx9X8IYBtr7dA5cWu_smM2XBkLZzCXy7TjeEWRgag0) - Help with daily/weekly dates
- [hiimjustin000](user:7466002) - Creator of the mod
- [hiimjasmine00](user:7466002) - Creator of the mod

# Gallery
![Daily Calendar](hiimjustin000.better_safe/daily-calendar.png?scale=0.75)\
![Weekly Calendar](hiimjustin000.better_safe/weekly-calendar.png?scale=0.75)
![Daily Calendar](hiimjustin000.better_safe/daily-calendar.png?width=320)\
![Weekly Calendar](hiimjustin000.better_safe/weekly-calendar.png?width=320)\
![Event Calendar](hiimjustin000.better_safe/event-calendar.png?width=320)
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Better Safe Changelog
## v1.1.3 (2025-02-06)
- Updated the gallery to include the new event levels

## v1.1.2 (2024-11-20)
- Changed the background color of the calendar to match the daily/weekly/event level previews
- Fixed a bug where the refresh button would not load the levels properly ([#5](https://github.com/hiimjustin000/BetterSafe/issues/5))
Expand Down
8 changes: 4 additions & 4 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"geode": "4.0.1",
"geode": "4.2.0",
"gd": {
"android": "2.2074",
"win": "2.2074",
"mac": "2.2074"
},
"version": "v1.1.2",
"version": "v1.1.3",
"id": "hiimjustin000.better_safe",
"name": "Better Safe",
"developer": "hiimjustin000",
"developer": "hiimjasmine00",
"description": "A mod that expands The Safe with a calendar.",
"settings": {
"sunday-first": {
Expand All @@ -25,7 +25,7 @@
},
"links": {
"community": "https://discord.gg/QVKmbvBXA7",
"source": "https://github.com/hiimjustin000/BetterSafe",
"source": "https://github.com/hiimjasmine00/BetterSafe",
"homepage": "https://www.hiimjustin000.com"
},
"tags": [
Expand Down
Binary file modified resources/daily-calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/event-calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/weekly-calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 33 additions & 45 deletions src/BetterSafe.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include "BetterSafe.hpp"
#include <Geode/binding/FLAlertLayer.hpp>
#include <Geode/binding/GJGameLevel.hpp>
#include <Geode/binding/LoadingCircle.hpp>
#include <Geode/utils/ranges.hpp>
#include <Geode/utils/string.hpp>

using namespace geode::prelude;

#define DAILY_SAFE_URL "https://raw.githubusercontent.com/hiimjustin000/the-safe/master/v2/daily.json"
#define WEEKLY_SAFE_URL "https://raw.githubusercontent.com/hiimjustin000/the-safe/master/v2/weekly.json"
#define EVENT_SAFE_URL "https://raw.githubusercontent.com/hiimjustin000/the-safe/master/v2/event.json"
#define DAILY_SAFE_URL "https://raw.githubusercontent.com/hiimjasmine00/the-safe/master/v2/daily.json"
#define WEEKLY_SAFE_URL "https://raw.githubusercontent.com/hiimjasmine00/the-safe/master/v2/weekly.json"
#define EVENT_SAFE_URL "https://raw.githubusercontent.com/hiimjasmine00/the-safe/master/v2/event.json"

SafeDate BetterSafe::parseDate(const std::string& date) {
auto parts = string::split(date, "-");
Expand All @@ -16,55 +21,41 @@ SafeDate BetterSafe::parseDate(const std::string& date) {
}

SafeDate BetterSafe::dateFromTime(time_t time) {
#ifdef GEODE_IS_WINDOWS
struct tm timeinfo;
localtime_s(&timeinfo, &time);
#else
auto timeinfo = *std::localtime(&time);
#endif
return { timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday };
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
auto timeinfo = std::localtime(&time);
#pragma clang diagnostic pop
return { timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday };
}

void BetterSafe::loadSafe(GJTimedLevelType type, EventListener<web::WebTask>&& listenerRef, LoadingCircle* circle, std::function<void()> const& callback) {
if (!getSafeLevels(type).empty()) return callback();
void BetterSafe::loadSafe(
GJTimedLevelType type, EventListener<web::WebTask>&& listenerRef, const std::function<void()>& success, const std::function<void(int)>& failure
) {
if (!getSafeLevels(type).empty()) return success();

auto&& listener = std::move(listenerRef);

listener.bind([callback, circle, type](web::WebTask::Event* e) {
listener.bind([failure, success, type](web::WebTask::Event* e) {
if (auto res = e->getValue()) {
if (!res->ok()) {
FLAlertLayer::create(fmt::format("Load Failed ({})", res->code()).c_str(), "Failed to load the safe. Please try again later.", "OK")->show();
circle->setVisible(false);
return;
return failure(res->code());
}

auto json = res->json().unwrapOr(std::vector<matjson::Value>());
if (!json.isArray()) {
FLAlertLayer::create("Parse Failed", "Failed to parse the safe. Please try again later.", "OK")->show();
circle->setVisible(false);
return;
}
if (!json.isArray()) return success();

for (auto& level : json.asArray().unwrap()) {
std::vector<SafeDate> dates;
if (level.contains("dates") && level["dates"].isArray()) {
for (auto& date : level["dates"].asArray().unwrap()) {
dates.push_back(parseDate(date.asString().unwrapOr("1970-01-01")));
}
}
getSafeLevels(type).push_back({
getSafeLevels(type) = ranges::map<std::vector<SafeLevel>>(json.asArray().unwrap(), [type](const matjson::Value& level) {
return SafeLevel {
.id = (int)level["id"].asInt().unwrapOr(0),
.timelyID = (int)level["timelyID"].asInt().unwrapOr(0),
.dates = dates,
.dates = level.contains("dates") && level["dates"].isArray() ? ranges::map<std::vector<SafeDate>>(level["dates"].asArray().unwrap(),
[](const matjson::Value& date) { return parseDate(date.asString().unwrapOr("1970-01-01")); }) : std::vector<SafeDate>(),
.type = type,
.tier = (int)level["tier"].asInt().unwrapOr(0)
});
}
};
});

if (type != GJTimedLevelType::Event || EVENT_SAFE.size() < 2) {
callback();
return;
}
if (type != GJTimedLevelType::Event || EVENT_SAFE.size() < 2) return success();

auto lastEventDate = EVENT_SAFE[1].dates.back();
tm timeinfo = { 0, 0, 0, lastEventDate.day, lastEventDate.month - 1, lastEventDate.year - 1900 };
Expand All @@ -75,7 +66,7 @@ void BetterSafe::loadSafe(GJTimedLevelType type, EventListener<web::WebTask>&& l
EVENT_SAFE[0].dates.push_back(dateFromTime(lastEventTime));
}

callback();
success();
}
});

Expand All @@ -88,14 +79,11 @@ void BetterSafe::loadSafe(GJTimedLevelType type, EventListener<web::WebTask>&& l
}

std::vector<SafeLevel> BetterSafe::getMonth(int year, int month, GJTimedLevelType type) {
std::vector<SafeLevel> levels;
auto& safe = getSafeLevels(type);
for (auto& level : safe) {
for (auto& date : level.dates) {
if (date.year == year && date.month == month) levels.push_back(level);
}
}
return levels;
return ranges::reduce<std::vector<SafeLevel>>(getSafeLevels(type), [year, month](std::vector<SafeLevel>& levels, const SafeLevel& level) {
ranges::push(levels, ranges::map<std::vector<SafeLevel>>(ranges::filter<std::vector<SafeDate>>(level.dates, [year, month](const SafeDate& date) {
return date.year == year && date.month == month;
}), [&level](const auto&) { return level; }));
});
}

std::vector<SafeLevel>& BetterSafe::getSafeLevels(GJTimedLevelType type) {
Expand Down
4 changes: 3 additions & 1 deletion src/BetterSafe.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <Geode/Enums.hpp>
#include <Geode/GeneratedPredeclare.hpp>
#include <Geode/utils/web.hpp>

struct SafeDate {
Expand All @@ -22,7 +24,7 @@ class BetterSafe {

static SafeDate parseDate(const std::string&);
static SafeDate dateFromTime(time_t);
static void loadSafe(GJTimedLevelType, geode::EventListener<geode::utils::web::WebTask>&&, LoadingCircle*, std::function<void()> const&);
static void loadSafe(GJTimedLevelType, geode::EventListener<geode::utils::web::WebTask>&&, const std::function<void()>&, const std::function<void(int)>&);
static std::vector<SafeLevel> getMonth(int year, int month, GJTimedLevelType type);
static std::vector<SafeLevel>& getSafeLevels(GJTimedLevelType type);
static int getDifficultyFromLevel(GJGameLevel* level);
Expand Down
Loading

0 comments on commit 5fa1ecf

Please sign in to comment.