mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
make Event::post return the ListenerResult
This commit is contained in:
parent
97b7cbe211
commit
2fe88f1c33
5 changed files with 20 additions and 12 deletions
|
@ -1234,6 +1234,7 @@ class EditorUI : cocos2d::CCLayer, FLAlertLayerProtocol, ColorSelectDelegate, GJ
|
|||
virtual void ccTouchMoved(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x2f3d0, win 0x90cd0;
|
||||
virtual void ccTouchEnded(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x2fb00, win 0x911a0;
|
||||
virtual void keyDown(cocos2d::enumKeyCodes) = mac 0x30790, win 0x91a30;
|
||||
virtual void keyUp(cocos2d::enumKeyCodes) = mac 0x312b0, win 0x92180;
|
||||
CreateMenuItem* menuItemFromObjectString(gd::string, int) = mac 0x1e130, win 0x84d00;
|
||||
void moveObject(GameObject*, cocos2d::CCPoint) = mac 0x24b10, win 0x8ddb0;
|
||||
void onDuplicate(cocos2d::CCObject*) = mac 0x18ba0, win 0x87d20;
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace geode {
|
|||
struct GEODE_DLL EventListenerPool {
|
||||
virtual bool add(EventListenerProtocol* listener) = 0;
|
||||
virtual void remove(EventListenerProtocol* listener) = 0;
|
||||
virtual void handle(Event* event) = 0;
|
||||
virtual ListenerResult handle(Event* event) = 0;
|
||||
virtual ~EventListenerPool() = default;
|
||||
|
||||
EventListenerPool() = default;
|
||||
|
@ -39,7 +39,7 @@ namespace geode {
|
|||
public:
|
||||
bool add(EventListenerProtocol* listener) override;
|
||||
void remove(EventListenerProtocol* listener) override;
|
||||
void handle(Event* event) override;
|
||||
ListenerResult handle(Event* event) override;
|
||||
|
||||
static DefaultEventListenerPool* get();
|
||||
};
|
||||
|
@ -205,10 +205,10 @@ namespace geode {
|
|||
public:
|
||||
Mod* sender;
|
||||
|
||||
void postFrom(Mod* sender);
|
||||
ListenerResult postFromMod(Mod* sender);
|
||||
template<class = void>
|
||||
void post() {
|
||||
postFrom(getMod());
|
||||
ListenerResult post() {
|
||||
return postFromMod(getMod());
|
||||
}
|
||||
|
||||
virtual ~Event();
|
||||
|
|
|
@ -23,12 +23,14 @@ void DefaultEventListenerPool::remove(EventListenerProtocol* listener) {
|
|||
}
|
||||
}
|
||||
|
||||
void DefaultEventListenerPool::handle(Event* event) {
|
||||
ListenerResult DefaultEventListenerPool::handle(Event* event) {
|
||||
auto res = ListenerResult::Propagate;
|
||||
m_locked += 1;
|
||||
for (auto h : m_listeners) {
|
||||
// if an event listener gets destroyed in the middle of this loop, it
|
||||
// gets set to null
|
||||
if (h && h->handle(event) == ListenerResult::Stop) {
|
||||
res = ListenerResult::Stop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +44,7 @@ void DefaultEventListenerPool::handle(Event* event) {
|
|||
}
|
||||
m_toAdd.clear();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
DefaultEventListenerPool* DefaultEventListenerPool::get() {
|
||||
|
@ -82,7 +85,7 @@ EventListenerPool* Event::getPool() const {
|
|||
return DefaultEventListenerPool::get();
|
||||
}
|
||||
|
||||
void Event::postFrom(Mod* m) {
|
||||
ListenerResult Event::postFromMod(Mod* m) {
|
||||
if (m) this->sender = m;
|
||||
this->getPool()->handle(this);
|
||||
return this->getPool()->handle(this);
|
||||
}
|
||||
|
|
|
@ -320,18 +320,20 @@ void Index::downloadSource(IndexSourceImpl* src) {
|
|||
}
|
||||
}
|
||||
catch(...) {
|
||||
return SourceUpdateEvent(
|
||||
SourceUpdateEvent(
|
||||
src, UpdateFailed("Unable to clear cached index")
|
||||
).post();
|
||||
return;
|
||||
}
|
||||
|
||||
// unzip new index
|
||||
auto unzip = file::Unzip::intoDir(targetFile, targetDir, true)
|
||||
.expect("Unable to unzip new index");
|
||||
if (!unzip) {
|
||||
return SourceUpdateEvent(
|
||||
SourceUpdateEvent(
|
||||
src, UpdateFailed(unzip.unwrapErr())
|
||||
).post();
|
||||
return;
|
||||
}
|
||||
|
||||
// remove the directory github adds to the root of the zip
|
||||
|
|
|
@ -521,9 +521,10 @@ void Loader::Impl::tryDownloadLoaderResources(
|
|||
// unzip resources zip
|
||||
auto unzip = file::Unzip::intoDir(tempResourcesZip, resourcesDir, true);
|
||||
if (!unzip) {
|
||||
return ResourceDownloadEvent(
|
||||
ResourceDownloadEvent(
|
||||
UpdateFailed("Unable to unzip new resources: " + unzip.unwrapErr())
|
||||
).post();
|
||||
return;
|
||||
}
|
||||
ResourceDownloadEvent(UpdateFinished()).post();
|
||||
})
|
||||
|
@ -649,9 +650,10 @@ void Loader::Impl::downloadLoaderUpdate(std::string const& url) {
|
|||
// unzip resources zip
|
||||
auto unzip = file::Unzip::intoDir(updateZip, targetDir, true);
|
||||
if (!unzip) {
|
||||
return LoaderUpdateEvent(
|
||||
LoaderUpdateEvent(
|
||||
UpdateFailed("Unable to unzip update: " + unzip.unwrapErr())
|
||||
).post();
|
||||
return;
|
||||
}
|
||||
m_isNewUpdateDownloaded = true;
|
||||
LoaderUpdateEvent(UpdateFinished()).post();
|
||||
|
|
Loading…
Reference in a new issue