Skip to content

Commit

Permalink
a bug fix update
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 committed Sep 6, 2024
1 parent 68f0426 commit 8a820e7
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ file(GLOB SOURCES
src/*.cpp
src/nodes/*.cpp
src/ui/*.cpp
src/ui/popups/*.cpp
src/ui/auth/*.cpp
)

# Set up the mod binary
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v1.1.1
- Made typing in pages work
- Made pressing escape while in an object not close the menu, but instead "go back"
- Added a loading circle so people dont accidentally click on the object workshop button twice
- Fixed issue searching with spaces causing an error
# v1.1.0
- Added color preview to objects (no color triggers work :<)
- Moved uploading to My Objects
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"id": "firee.object-workshop",
"name": "Object Workshop",
"version": "v1.1.0",
"version": "v1.1.1",
"developer": "Firee",
"description": "Download, upload, or find custom objects made by other creators!",
"resources": {
Expand Down
2 changes: 2 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once
#define HOST_URL "https://ow.firee.dev"
//#define HOST_URL "http://localhost:3000"

#define RESULT_LIMIT 9
16 changes: 12 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using namespace geode::prelude;

#include "ui/ObjectWorkshop.hpp"
#include "ui/AuthMenu.hpp"
#include "ui/auth/AuthMenu.hpp"
#include "config.hpp"
#include "ui/auth/AuthLoadLayer.hpp"
#include <fig.authentication/include/authentication.hpp>
#include <alphalaneous.editortab_api/include/EditorTabs.hpp>

Expand All @@ -16,27 +17,34 @@ void CustomObjects::setupCustomMenu(EditButtonBar* bar, bool hideItems) {
void CustomObjects::onWorkshop(CCObject*) {
int authServer = Mod::get()->getSettingValue<int64_t>("auth-server");
if (authServer != -1) {
auto loadLayer = AuthLoadLayer::create();
loadLayer->show();
auto token = Mod::get()->getSettingValue<std::string>("token");
AuthMenu::testAuth(token, [authServer, token](int value) {
AuthMenu::testAuth(token, [loadLayer, authServer, token](int value) {
if (value == 1) {
loadLayer->finished();
ObjectWorkshop::create(true)->show();
} else if (value == -1) {
loadLayer->finished();
FLAlertLayer::create("Error", "Currently, Object Workshop <cy>servers are down</c> at the moment! View your logs, or view announcements on the <cy>Discord Server</c> for more information, or if there are no announcements, inform the developer of this error!", "OK")->show();
} else {
switch (AuthMenu::intToAuth(authServer)) {
default:
case AuthMethod::None:
case AuthMethod::DashAuth: {
loadLayer->finished();
FLAlertLayer::create("Error", "Unsupported <cy>authentication method</c>.", "OK")->show();
break;
}
case AuthMethod::Custom: {
loadLayer->finished();
FLAlertLayer::create("Error", "Either the token you set is <cy>expired</c>, or you <cy>entered the token incorrectly!</c>", "OK")->show();
break;
}
case AuthMethod::GDAuth: {
authentication::AuthenticationManager::get()->getAuthenticationToken([](std::string token) {
AuthMenu::genAuthToken(AuthMethod::GDAuth, token, false, [](int value) {
authentication::AuthenticationManager::get()->getAuthenticationToken([loadLayer](std::string token) {
AuthMenu::genAuthToken(AuthMethod::GDAuth, token, false, [loadLayer](int value) {
loadLayer->finished();
if (value == 1) {
ObjectWorkshop::create(true)->show();
} else if (value == -1) {
Expand Down
63 changes: 47 additions & 16 deletions src/ui/ObjectWorkshop.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#include "DescPopup.hpp"
#include "EditPopup.hpp"
#include "Geode/ui/Notification.hpp"
#include "Geode/ui/Popup.hpp"
#include "Geode/ui/TextInput.hpp"
#include "../config.hpp"
#include "ObjectWorkshop.hpp"
#include "popups/includes.h"
#include "../nodes/CategoryButton.hpp"
#include "Geode/utils/cocos.hpp"
#include "Geode/utils/web.hpp"
#include "../utils.hpp"
#include "FiltersPopup.hpp"
#include "../nodes/ScrollLayerExt.hpp"
#include "ReportPopup.hpp"
//#include <dashauth.hpp>

int currentMenuIndexGD = 2;
Expand Down Expand Up @@ -277,6 +268,8 @@ bool ObjectWorkshop::setup(bool authenticated) {
m_pageInput->setString("1");
m_pageInput->setMaxCharCount(8);
m_pageInput->setScale(0.525F);
m_pageInput->setCommonFilter(CommonFilter::Uint);
m_pageInput->setDelegate(this);
pagesMenu->addChild(m_pageInput);

RegenCategory();
Expand Down Expand Up @@ -322,6 +315,22 @@ void ObjectWorkshop::onRightPage(CCObject*) {
}
}

void ObjectWorkshop::textInputOpened(CCTextInputNode* input) {
input->setString("");
}

void ObjectWorkshop::textInputClosed(CCTextInputNode* input) {
if (input->getString().empty()) return m_pageInput->setString(std::to_string(m_currentPage).c_str());
int page = std::stoi(input->getString());
if (page == m_currentPage) return m_pageInput->setString(std::to_string(m_currentPage).c_str());
if (page < 1) page = 1;
if (page <= m_maxPage) {
m_currentPage = page;
m_pageInput->setString(std::to_string(m_currentPage).c_str());
RegenCategory();
}
}

void ObjectWorkshop::RegenCategory() {
int myItems = 0;
int items = 0;
Expand Down Expand Up @@ -722,16 +731,17 @@ void ObjectWorkshop::load() {
}
});
if (isSearching && !m_searchInput->getString().empty()) {
std::string query = Utils::url_encode(m_searchInput->getString());
if (m_filterTags.empty()) {
m_listener1.setFilter(request.post(fmt::format("{}/objects/search?query={}&limit=9&page={}", HOST_URL, m_searchInput->getString(), m_currentPage)));
m_listener1.setFilter(request.post(fmt::format("{}/objects/search?query={}&limit={}&page={}", HOST_URL, query, RESULT_LIMIT, m_currentPage)));
} else {
std::ostringstream oss;
std::copy(m_filterTags.begin(), m_filterTags.end(),
std::ostream_iterator<std::string>(oss, ","));
std::string tagsString = oss.str();

if (!tagsString.empty()) tagsString.pop_back();
m_listener1.setFilter(request.post(fmt::format("{}/objects/search?query={}&page={}&limit=9&tags={}", HOST_URL, m_searchInput->getString(), m_currentPage, tagsString)));
m_listener1.setFilter(request.post(fmt::format("{}/objects/search?query={}&page={}&limit={}&tags={}", HOST_URL, query, m_currentPage, RESULT_LIMIT, tagsString)));
}
return;
}
Expand All @@ -744,27 +754,27 @@ void ObjectWorkshop::load() {
if (currentMenuIndexGD == 0) { // my uploads
m_listener1.setFilter(request.get(fmt::format("{}/user/@me/objects?page=0&limit=false", HOST_URL, m_currentPage)));
} else if (currentMenuIndexGD == 1) { // favorited
m_listener1.setFilter(request.post(fmt::format("{}/user/@me/favorites?page={}&limit=9", HOST_URL, m_currentPage)));
m_listener1.setFilter(request.post(fmt::format("{}/user/@me/favorites?page={}&limit={}", HOST_URL, m_currentPage, RESULT_LIMIT)));
} else if (currentMenuIndexGD == 7) { // pending
m_listener1.setFilter(request.post(fmt::format("{}/objects/pending?page={}", HOST_URL, m_currentPage)));
} else if (currentMenuIndexGD == 8) { // reports
m_listener1.setFilter(request.post(fmt::format("{}/objects/reports?page={}", HOST_URL, m_currentPage)));
}
} else {
FLAlertLayer::create("Error", "You aren't <cy>authenticated!</c>", "OK")->show();
m_listener1.setFilter(request.get(fmt::format("{}/objects?page={}&category={}&limit=9", HOST_URL, m_currentPage, 0)));
m_listener1.setFilter(request.get(fmt::format("{}/objects?page={}&category={}&limit={}", HOST_URL, m_currentPage, 0, RESULT_LIMIT)));
}
} else {
if (m_filterTags.empty()) {
m_listener1.setFilter(request.get(fmt::format("{}/objects?page={}&category={}&limit=9", HOST_URL, m_currentPage, currentMenuIndexGD - 2)));
m_listener1.setFilter(request.get(fmt::format("{}/objects?page={}&category={}&limit={}", HOST_URL, m_currentPage, currentMenuIndexGD - 2, RESULT_LIMIT)));
} else {
std::ostringstream oss;
std::copy(m_filterTags.begin(), m_filterTags.end(),
std::ostream_iterator<std::string>(oss, ","));
std::string tagsString = oss.str();

if (!tagsString.empty()) tagsString.pop_back();
m_listener1.setFilter(request.get(fmt::format("{}/objects?page={}&category={}&tags={}&limit=9", HOST_URL, m_currentPage, currentMenuIndexGD - 2, tagsString)));
m_listener1.setFilter(request.get(fmt::format("{}/objects?page={}&category={}&tags={}&limit={}", HOST_URL, m_currentPage, currentMenuIndexGD - 2, tagsString, RESULT_LIMIT)));
}
}
}
Expand Down Expand Up @@ -1722,3 +1732,24 @@ void ObjectWorkshop::onInfoBtn(CCObject*) {
"OK" // Not having another button will only show this one button.
)->show();
}

void ObjectWorkshop::keyDown(cocos2d::enumKeyCodes key) {
if (key == cocos2d::enumKeyCodes::KEY_Escape) {
if (rightBg->isVisible()) {
this->onClose(nullptr);
} else {
this->onBackBtn(nullptr);
}
return;
}
if (key == cocos2d::enumKeyCodes::KEY_Space) return;
return FLAlertLayer::keyDown(key);
}

void ObjectWorkshop::keyBackClicked() {
if (rightBg->isVisible()) {
this->onClose(nullptr);
} else {
this->onBackBtn(nullptr);
}
}
11 changes: 9 additions & 2 deletions src/ui/ObjectWorkshop.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once
#include <Geode/utils/web.hpp>
#include <Geode/Geode.hpp>
#include <Geode/ui/Notification.hpp>
#include <Geode/ui/Popup.hpp>
#include <Geode/ui/TextInput.hpp>
#include "../nodes/ObjectItem.hpp"
#include "../nodes/ScrollLayerExt.hpp"
#include "../nodes/ExtPreviewBG.hpp"
#include "../nodes/ScrollLayerExt.hpp"

using namespace geode::prelude;

Expand Down Expand Up @@ -65,9 +69,8 @@ struct UserData {
};

// do i really need a bunch of event listeners
class ObjectWorkshop : public geode::Popup<bool> {
class ObjectWorkshop : public geode::Popup<bool>, public TextInputDelegate {
protected:
//CCScale9Sprite* leftBar;
std::unordered_set<std::string> m_availableTags;
EventListener<web::WebTask> m_listener2;
EventListener<web::WebTask> m_listener1;
Expand All @@ -90,6 +93,10 @@ class ObjectWorkshop : public geode::Popup<bool> {
int m_maxPage = 1;
void onLeftPage(CCObject*);
void onRightPage(CCObject*);
void textInputOpened(CCTextInputNode* input) override;
void textInputClosed(CCTextInputNode* input) override;
void keyDown(cocos2d::enumKeyCodes) override;
virtual void keyBackClicked() override;

LoadingCircle* loadingCircle;
TextInput* m_searchInput;
Expand Down
21 changes: 21 additions & 0 deletions src/ui/auth/AuthLoadLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "AuthLoadLayer.hpp"

bool AuthLoadLayer::init() {
if (!this->initWithColor({0, 0, 0, 75})) return false;
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
this->m_mainLayer = CCLayer::create();
this->m_buttonMenu = cocos2d::CCMenu::create();
this->m_mainLayer->addChild(this->m_buttonMenu);
this->addChild(this->m_mainLayer);
this->registerWithTouchDispatcher();
this->setTouchEnabled(true);

m_loadingCircle = LoadingCircle::create();
//m_loadingCircle->setPosition(winSize / 2);
m_loadingCircle->setParentLayer(m_mainLayer);
m_loadingCircle->show();
return true;
}
void AuthLoadLayer::finished() {
this->removeFromParentAndCleanup(true);
}
22 changes: 22 additions & 0 deletions src/ui/auth/AuthLoadLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

using namespace geode::prelude;

// definitely not copied from geode
class AuthLoadLayer : public FLAlertLayer {
protected:
LoadingCircle* m_loadingCircle;
virtual bool init();
public:
void finished();
static AuthLoadLayer* create() {
auto ret = new AuthLoadLayer();
if (ret->init()) {
ret->autorelease();
return ret;
}

delete ret;
return nullptr;
}
};
5 changes: 2 additions & 3 deletions src/ui/AuthMenu.cpp → src/ui/auth/AuthMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "../config.hpp"
#include "../../config.hpp"
#include "AuthMenu.hpp"
#include "Geode/ui/Popup.hpp"
#include "ObjectWorkshop.hpp"
#include "../ObjectWorkshop.hpp"
#include <fig.authentication/include/authentication.hpp>

EventListener<web::WebTask> m_authListener;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ui/DescPopup.hpp → src/ui/popups/DescPopup.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Geode/ui/Popup.hpp>
#include "../nodes/ObjectItem.hpp"
#include "../../nodes/ObjectItem.hpp"
using namespace geode::prelude;

class DescPopup : public geode::Popup<ObjectData> {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/EditPopup.cpp → src/ui/popups/EditPopup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "EditPopup.hpp"
#include "../utils.hpp"
#include "../config.hpp"
#include "../../utils.hpp"
#include "../../config.hpp"
#include "FiltersPopup.hpp"

bool EditPopup::setup(ObjectData obj, std::unordered_set<std::string> availableTags) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/EditPopup.hpp → src/ui/popups/EditPopup.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Geode/ui/Popup.hpp>
#include "../nodes/ObjectItem.hpp"
#include "../../nodes/ObjectItem.hpp"
#include <Geode/utils/web.hpp>
using namespace geode::prelude;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/FiltersPopup.cpp → src/ui/popups/FiltersPopup.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "FiltersPopup.hpp"
#include "../utils.hpp"
#include "../../utils.hpp"

bool FiltersPopup::setup(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, bool uploading, utils::MiniFunction<void(std::unordered_set<std::string>)> callback) {
m_callback = callback;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ui/ReportPopup.cpp → src/ui/popups/ReportPopup.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ReportPopup.hpp"
#include "../config.hpp"
#include "../../config.hpp"

bool ReportPopup::setup(ObjectData obj) {
m_object = obj;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ReportPopup.hpp → src/ui/popups/ReportPopup.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Geode/ui/Popup.hpp>
#include "../nodes/ObjectItem.hpp"
#include "../../nodes/ObjectItem.hpp"
#include <Geode/utils/web.hpp>
using namespace geode::prelude;

Expand Down
5 changes: 5 additions & 0 deletions src/ui/popups/includes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include "DescPopup.hpp"
#include "EditPopup.hpp"
#include "FiltersPopup.hpp"
#include "ReportPopup.hpp"
15 changes: 15 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ class Utils {
static matjson::Array unorderedSetToArray(std::unordered_set<T> set) {
return matjson::Array(set.begin(), set.end());
};
static std::string url_encode(const std::string &value) {
std::ostringstream escaped;
escaped.fill('0');
escaped << std::hex;

for (char c : value) {
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
escaped << c;
} else {
escaped << '%' << std::setw(2) << int((unsigned char) c);
}
}

return escaped.str();
}
static std::string menuIndexToString(int menuIndex) {
switch (menuIndex) {
case 0:
Expand Down

0 comments on commit 8a820e7

Please sign in to comment.