Skip to content

Commit

Permalink
bug fix update
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 committed Sep 18, 2024
1 parent b855727 commit 9eedf5a
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 136 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v1.2.2
- Added a requirement for 1 tag to be added for uploading
- Prevent searching in My Objects and Favorites
- Fixed issue with Object Workshop button not centering in the Editor
- Fixed the "reset zoom" button to also reset positioning
- Fixed zooming to "act like zooming" (instead of scaling based on the center)
- (hopefully) Fixed issue with crash on clicking on the cancel button of a comment popup
# v1.2.1
- Fixed bug with attempting to render invalid icons crashing
# v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions 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.2.1",
"version": "v1.2.2",
"developer": "Firee",
"description": "Download, upload, or find custom objects made by other creators!",
"resources": {
Expand Down Expand Up @@ -59,7 +59,7 @@
},
{
"id": "alphalaneous.editortab_api",
"version": ">=v1.0.0-beta.3",
"version": ">=v1.0.0",
"importance": "required"
}
]
Expand Down
6 changes: 3 additions & 3 deletions server/src/controllers/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ oRouter.post('/objects/upload',
return false;
})
if (hasBlacklistedIDs) return res.status(403).json({error: "Blacklisted IDs are not allowed."});
if (!tags || !tags.length) tags = [];
if (!tags || !tags.length) return res.status(400).json({error: "You need to add at least 1 tag!"});
if (tags.length > 5) return res.status(413).json({error: "You can only add a maximum of 5 tags!"});
if (data.length == 1) return res.status(400).json({error: "hi my name is firee"});
if (data.length == 2) return res.status(400).json({error: "hola me llamo firee"});
Expand Down Expand Up @@ -747,7 +747,7 @@ oRouter.post('/objects/:id/update',
if (!verifyRes.user) return res.status(404).json({error: "Couldn't retrieve user."});
const accountID = verifyRes.user.account_id;
try {
if (verifyRes.user && verifyRes.user.role == 3) {
if (verifyRes.user && verifyRes.user.role == 2) {
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1)", [objectID])
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
} else {
Expand Down Expand Up @@ -971,7 +971,7 @@ oRouter.get('/objects/:id/comments',
users u ON c.account_id = u.account_id
WHERE c.object_id = $1
GROUP BY c.id, u.name, u.icon, u.role
ORDER BY c.timestamp, c.pinned ASC
ORDER BY c.pinned DESC, c.timestamp DESC
LIMIT $2 OFFSET $3
`;
const result = await pool.query(query, [objectID, limit, offset]);
Expand Down
2 changes: 2 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
//#define HOST_URL "http://localhost:3000"

#define RESULT_LIMIT 9
#define MAX_ZOOM 10
#define MIN_ZOOM 0.01
69 changes: 28 additions & 41 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class $modify(LevelEditorLayer) {
bool CustomObjects::init(LevelEditorLayer* editorLayer) {
if (!EditorUI::init(editorLayer)) return false;
EditorTabs::addTab(this, TabType::BUILD, "workshop"_spr, [this](EditorUI* ui, CCMenuItemToggler* toggler) -> CCNode* { //create the tab
auto arr = CCArray::create();
auto folder = CCSprite::createWithSpriteFrameName("gj_folderBtn_001.png");
folder->setScale(0.4F);
auto labelC = CCLabelBMFont::create("C+", "bigFont.fnt");
Expand Down Expand Up @@ -140,9 +139,6 @@ bool CustomObjects::init(LevelEditorLayer* editorLayer) {
m_fields->btn1 = CCMenuItemSpriteExtra::create(btn1Spr, this, menu_selector(CustomObjects::onWorkshop));
m_fields->menu->addChildAtPosition(m_fields->btn1, Anchor::Center, {0, -7});
m_fields->menu->setContentHeight(90.F);
//menu->setPositionY(45.F);

arr->addObject(m_fields->menu);
m_fields->menu->updateLayout();

auto token = Mod::get()->getSettingValue<std::string>("token");
Expand Down Expand Up @@ -186,14 +182,9 @@ bool CustomObjects::init(LevelEditorLayer* editorLayer) {
req.bodyJSON(myjson);
m_fields->m_listener.setFilter(req.post(fmt::format("{}/user/@me", HOST_URL)));
}
//m_fields->menu->setPosition({-2, -112});
m_fields->menu->setPosition({285, 45});
//return EditorTabUtils::createEditButtonBar(arr, ui);
auto winSize = CCDirector::sharedDirector()->getWinSize();
m_fields->menu->setPosition({winSize.width / 2, 45});
return m_fields->menu;
}, [this](EditorUI* ui, bool state, CCNode*) { //toggled the tab (activates on every tab click)
if (m_fields->menu != nullptr) {
//m_fields->menu->setPosition({-2, -112});
}
});

return true;
Expand All @@ -218,35 +209,31 @@ class $modify(ObjectBypass, EditorUI) {
} else {
EditorUI::onNewCustomItem(pSender);
}
}
/*
if ((this->m_selectedObjects == (CCArray *)0x0) ||
(uVar1 = cocos2d::CCArray::count(this->m_selectedObjects), uVar1 < 0x3e9)) {
pGVar2 = GameManager::sharedState();
uVar1 = cocos2d::CCDictionary::count(*(CCDictionary **)(pGVar2 + 0x134));
if (uVar1 < 200) {
if (((this->m_selectedObject == (GameObject *)0x0) &&
(uVar1 = cocos2d::CCArray::count(this->m_selectedObjects), uVar1 == 0)) ||
((this->m_selectedObject != (GameObject *)0x0 &&
(*(int *)((int)&(this->m_selectedObject->GameObject_data).offset_0x100 + 4) == 0x2ed))))
goto LAB_003a366e;
uVar1 = cocos2d::CCArray::count(this->m_selectedObjects);
if (uVar1 == 0) {
this_00 = cocos2d::CCArray::create();
cocos2d::CCArray::addObject(this_00,(CCObject *)this->m_selectedObject);
}
else {
this_00 = this->m_selectedObjects;
}
pGVar3 = copyObjects((EditorUI *)&local_24,(CCArray *)this,false,false);
if ((*(int *)(local_24 + -0xc) != 0) &&
(uVar1 = cocos2d::CCArray::count(this->m_selectedObjects), uVar1 < 1001)) {
pGVar2 = GameManager::sharedState();
GameManager::addNewCustomObject(pGVar2,(basic_string)pGVar3);
this->m_selectedObjectIndex = 0;
reloadCustomItems(this);
}
}

*/
/*
if (m_selectedObjects == nullptr || m_selectedObjects->count() <= 1000) {
if (auto gameManager = GameManager::sharedState()) {
if (gameManager->m_customObjectDict->count() < 200) {
if ((m_selectedObject == nullptr && m_selectedObjects->count() == 0) || (m_selectedObject != nullptr && m_selectedObject->m_objectID == 0x2ed)) return;
CCArray* newSelectedObjs;
if (m_selectedObjects->count() == 0) {
newSelectedObjs = cocos2d::CCArray::create();
newSelectedObjs->addObject(m_selectedObject);
} else {
newSelectedObjs = this->m_selectedObjects;
}
gameManager->addNewCustomObject(copyObjects(newSelectedObjs, false, false));
m_selectedObjectIndex = 0;
reloadCustomItems();
} else {
auto string = cocos2d::CCString::createWithFormat("You cannot create more than <cy>%i</c> custom objects.", 200);
FLAlertLayer::create(nullptr, "Max Custom Objects", string->getCString(), "OK", nullptr)->show();
}
}
} else {
auto string = cocos2d::CCString::createWithFormat("A custom object cannot contain more than <cg>%i</c> objects.", 1000);
FLAlertLayer::create(nullptr, "Max Limit", string->getCString(), "OK", nullptr)->show();
}
*/
}
};
33 changes: 32 additions & 1 deletion src/nodes/CommentCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,38 @@ bool OWCommentCell::init(CommentData data, ObjectData obj, UserData user, utils:
}

void OWCommentCell::onVote(CCObject*) {
VotePopup::create(m_data, m_forceRefresh)->show();
VotePopup::create("Vote", [this](bool like) {
auto token = Mod::get()->getSettingValue<std::string>("token");
m_listener.getFilter().cancel();
m_listener.bind([this, token] (web::WebTask::Event* e) {
if (web::WebResponse* value = e->getValue()) {
auto jsonRes = value->json().unwrapOrDefault();
if (!jsonRes.is_object()) return log::error("Response isn't object.");
auto isError = jsonRes.try_get<std::string>("error");
if (isError) return Notification::create(isError->c_str(), NotificationIcon::Error)->show();
auto message = jsonRes.try_get<std::string>("message");
if (message) {
m_forceRefresh();
Notification::create(message->c_str(), NotificationIcon::Success)->show();
} else {
log::error("Unknown response, expected message. {}", jsonRes.dump());
Notification::create("Got an unknown response, check logs for details.", NotificationIcon::Warning)->show();
}
return;
} else if (web::WebProgress* progress = e->getProgress()) {
// The request is still in progress...
} else if (e->isCancelled()) {
log::error("Request was cancelled.");
}
});
web::WebRequest req = web::WebRequest();
auto myjson = matjson::Value();
myjson.set("token", token);
myjson.set("like", (int)like);
req.header("Content-Type", "application/json");
req.bodyJSON(myjson);
m_listener.setFilter(req.post(fmt::format("{}/objects/{}/comments/{}/vote", HOST_URL, m_data.objectID, m_data.id)));
})->show();
}
void OWCommentCell::onPin(CCObject*) {
geode::createQuickPopup(
Expand Down
54 changes: 39 additions & 15 deletions src/nodes/ExtPreviewBG.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "ExtPreviewBG.hpp"
bool ExtPreviewBG::init(std::string data) {
#include "../config.hpp"
bool ExtPreviewBG::init(std::string data, CCSize contentSize) {
if (!CCLayer::init()) return false;
this->setContentSize({ 124.F, 82.F });
this->setContentSize(contentSize);
this->setAnchorPoint({0.5, 0.5});
bg = CCScale9Sprite::create("square02_small.png");
bg->setOpacity(60);
bg->setContentSize({ 124.F, 82.F });
bg->setContentSize(this->getContentSize());

auto previewLabel = CCLabelBMFont::create("Preview", "goldFont.fnt");
previewLabel->setScale(0.425F);
Expand All @@ -14,21 +15,22 @@ bool ExtPreviewBG::init(std::string data) {

CCLayerColor* mask = CCLayerColor::create({255, 255, 255});
mask->setContentSize(bg->getContentSize());
auto clippingNode = CCClippingNode::create();
clippingNode->setContentSize(bg->getContentSize());
clippingNode->setAnchorPoint({0.5, 0.5});
m_clippingNode = CCClippingNode::create();
m_clippingNode->setContentSize(bg->getContentSize());
m_clippingNode->setAnchorPoint({0.5, 0.5});
if (auto editorUI = EditorUI::get() && data.length() > 0) {
auto renderLimit = Mod::get()->getSettingValue<int64_t>("render-objects");
auto smartBlock = CCArray::create();
objSprite = EditorUI::get()->spriteFromObjectString(data, false, false, renderLimit, smartBlock, (CCArray *)0x0,(GameObject *)0x0);
LevelEditorLayer::get()->updateObjectColors(smartBlock);
objSprite->setScale((clippingNode->getContentSize().height - 20) / objSprite->getContentSize().height);
objSprite->setScale((m_clippingNode->getContentSize().height - 20) / objSprite->getContentSize().height);
m_oldScale = objSprite->getScale();
clippingNode->addChildAtPosition(objSprite, Anchor::Center, {0, -5});
m_clippingNode->addChildAtPosition(objSprite, Anchor::Center, {0, -5});
m_oldPos = objSprite->getPosition();
}
clippingNode->setStencil(mask);
clippingNode->setZOrder(1);
this->addChildAtPosition(clippingNode, Anchor::Center);
m_clippingNode->setStencil(mask);
m_clippingNode->setZOrder(1);
this->addChildAtPosition(m_clippingNode, Anchor::Center);

this->registerWithTouchDispatcher();
this->setTouchEnabled(true);
Expand Down Expand Up @@ -67,18 +69,40 @@ void ExtPreviewBG::ccTouchMoved(CCTouch* touch, CCEvent* event) {
}

void ExtPreviewBG::updateZoom(float amount) {
if (!(m_currentZoom < 0) && m_currentZoom < 25) m_currentZoom += amount;
objSprite->setScale(m_oldScale * m_currentZoom);
float newZoom = m_currentZoom + amount;
if (newZoom >= MIN_ZOOM && newZoom <= 25.0f) {
float oldZoom = m_currentZoom;
m_currentZoom += amount;
float zoomFactor = m_currentZoom / oldZoom;

auto relativePos = (m_oldPos - objSprite->getPosition()) / oldZoom;
objSprite->setScale(m_oldScale * m_currentZoom);
objSprite->setPosition(m_oldPos - (relativePos * m_currentZoom));
}
};

void ExtPreviewBG::setZoom(float amount) {
if (amount >= MIN_ZOOM && amount <= 25.0f) {
float oldZoom = m_currentZoom;
m_currentZoom = amount;
float zoomFactor = m_currentZoom / oldZoom;

auto relativePos = (m_oldPos - objSprite->getPosition()) / oldZoom;
objSprite->setScale(m_oldScale * m_currentZoom);
objSprite->setPosition(m_oldPos - (relativePos * m_currentZoom));
}
};

void ExtPreviewBG::resetZoom() {
m_currentZoom = 1.0F;
objSprite->setScale(m_oldScale * m_currentZoom);
objSprite->setPosition(m_oldPos);
};

ExtPreviewBG* ExtPreviewBG::create(std::string data) {
ExtPreviewBG* ExtPreviewBG::create(std::string data, CCSize contentSize) {
auto pRet = new ExtPreviewBG();
if (pRet) {
if (pRet->init(data)) {
if (pRet->init(data, contentSize)) {
pRet->autorelease();
return pRet;
}
Expand Down
7 changes: 5 additions & 2 deletions src/nodes/ExtPreviewBG.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ class ExtPreviewBG : public CCLayer {
CCSprite* objSprite;
CCScale9Sprite* bg;
CCPoint m_touchStart;
CCClippingNode* m_clippingNode;
float m_oldScale;
CCPoint m_oldPos;
float m_currentZoom = 1.0F;

void touchFinished();
virtual bool init(std::string objData);
virtual bool init(std::string objData, CCSize);
bool ccTouchBegan(CCTouch*, CCEvent*) override;
void ccTouchMoved(CCTouch*, CCEvent*) override;
public:
void updateZoom(float amount);
void setZoom(float amount = 1.0F);
void resetZoom();
static ExtPreviewBG* create(std::string objData);
static ExtPreviewBG* create(std::string objData, CCSize contentSize = {124.F, 82.F});
};
2 changes: 1 addition & 1 deletion src/nodes/ScrollLayerExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void ScrollLayerExt::fixTouchPrio() {
if (auto delegate = typeinfo_cast<CCTouchDelegate*>(this)) {
if (auto handler = CCTouchDispatcher::get()->findHandler(delegate)) {
Loader::get()->queueInMainThread([this, handler, delegate, oldThis]() {
if (oldThis != nullptr) {
if (oldThis != nullptr && handler != nullptr && delegate != nullptr) {
if (auto dispatcher = CCTouchDispatcher::get()) {
dispatcher->setPriority(handler->m_nPriority - 2, delegate);
}
Expand Down
13 changes: 9 additions & 4 deletions src/ui/ObjectWorkshop.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../config.hpp"
#include "ObjectWorkshop.hpp"
#include "Geode/ui/ListView.hpp"
#include "popups/includes.h"
#include "../nodes/CategoryButton.hpp"
#include "../utils.hpp"
Expand Down Expand Up @@ -116,8 +115,9 @@ bool ObjectWorkshop::setup(bool authenticated) {
m_searchInput = TextInput::create(110.0F, "Search...");
m_searchInput->setMaxCharCount(64);
m_searchInput->setScale(0.525F);
m_searchInput->setAnchorPoint({ 0, .5f });
m_searchInput->setTextAlign(TextInputAlign::Left);
m_buttonMenu->addChildAtPosition(m_searchInput, Anchor::BottomLeft, { 38, 18 });
m_buttonMenu->addChildAtPosition(m_searchInput, Anchor::BottomLeft, { 8, 18 });
m_buttonMenu->addChildAtPosition(m_categoryButtons, Anchor::Left, {55, 32});

auto searchSpr = CCSprite::createWithSpriteFrameName("gj_findBtn_001.png");
Expand Down Expand Up @@ -988,8 +988,10 @@ void ObjectWorkshop::onClickObject(CCObject* sender) {
auto reportBtn = CCMenuItemSpriteExtra::create(
reportSpr, this, menu_selector(ObjectWorkshop::onReportBtn)
);
if (m_user.account_id == m_currentObject.authorAccId || m_user.role == 3) {
if (m_user.account_id == m_currentObject.authorAccId || m_user.role == 2) {
menu2->addChild(editBtn);
}
if (m_user.account_id == m_currentObject.authorAccId || m_user.role == 3) {
menu2->addChild(trashBtn);
}
if (m_user.role >= 2 && m_currentObject.pending) {
Expand Down Expand Up @@ -1868,9 +1870,11 @@ void ObjectWorkshop::onUploadBtn(CCObject*) {
void ObjectWorkshop::onSearchBtn(CCObject*) {
if (m_searchInput != nullptr) {
if (m_searchInput->getString().empty()) return FLAlertLayer::create("Error", "You must enter in a <cy>search query</c>!", "OK")->show();
if (currentMenuIndexGD < 2) return FLAlertLayer::create("Error", "You cannot search in <cy>My Objects</c> or <cy>Favorites</c>! Please select another category.", "OK")->show();
isSearching = true;
RegenCategory();
}
}
//ObjectPopup::create(m_currentObject, m_user)->show();
}

void ObjectWorkshop::onReloadBtn(CCObject*) {
Expand Down Expand Up @@ -1903,6 +1907,7 @@ void ObjectWorkshop::onUploadFilterBtn(CCObject*) {
void ObjectWorkshop::onUpload(CCObject*) {
if (auto editor = EditorUI::get()) {
if (auto gameManager = GameManager::sharedState()) {
if (m_filterTags.size() == 0) return FLAlertLayer::create("Error", "You must <cy>set a tag</c>! Click on the grey filter button to set one!", "OK")->show();
if (m_filterTags.size() > 5) return FLAlertLayer::create("Error", "You cannot set more than <cy>5 tags</c>!", "OK")->show();
if (m_objName == nullptr || m_objDesc == nullptr) return FLAlertLayer::create("Error", "Couldn't find <cy>input nodes</c>", "OK")->show();
if (m_objName != nullptr && m_objName->getString().empty()) return FLAlertLayer::create("Error", "You must enter in the <cy>object name</c>!", "OK")->show();
Expand Down
Loading

0 comments on commit 9eedf5a

Please sign in to comment.