Skip to content

Commit 7d78998

Browse files
committed
implement all the node events
1 parent 0bb8fca commit 7d78998

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include "../loader/Event.hpp"
4+
5+
namespace geode {
6+
7+
enum class NodeEventType {
8+
/// Fired when a CCNode is added to the scene tree.
9+
OnEnter,
10+
11+
/// Fired when a CCNode is removed from the scene tree.
12+
OnExit,
13+
14+
/// Fired when a CCNode is already added to the scene tree but after a scene transition.
15+
OnEnterTransitionDidFinish,
16+
17+
/// Fired when a CCNode is about to be removed from the scene tree before a scene transition.
18+
OnExitTransitionDidStart,
19+
20+
/// Fired when a CCNode is cleaned up (Schedules removed and Actions stopped).
21+
OnCleanup,
22+
};
23+
24+
/// Fired when a CCNode has a specific Event in NodeEventType.
25+
class NodeEvent : public GlobalEvent<NodeEvent, bool(), cocos2d::CCNode*, NodeEventType> {
26+
public:
27+
using GlobalEvent::GlobalEvent;
28+
};
29+
30+
/// Fired when a CCMenuItem is Activated (after the callback).
31+
class MenuItemEvent : public GlobalEvent<NodeEvent, bool(), cocos2d::CCMenuItem*> {
32+
public:
33+
using GlobalEvent::GlobalEvent;
34+
};
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "../loader/Event.hpp"
4+
5+
namespace geode {
6+
7+
/// Fired when any CCObject is destroyed.
8+
class ObjectDestroyedEvent : public GlobalEvent<ObjectDestroyedEvent, bool(), cocos2d::CCObject*> {
9+
public:
10+
using GlobalEvent::GlobalEvent;
11+
};
12+
}

loader/src/loader/ScriptEngine.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <Geode/utils/ObjectDestroyedEvent.hpp>
2+
#include <Geode/ui/NodeEvent.hpp>
3+
4+
using namespace geode::prelude;
5+
6+
namespace geode {
7+
class ScriptEngine : public CCScriptEngineProtocol {
8+
9+
ccScriptType getScriptType() {
10+
// Javascript engine is called without needing to change m_nLuaID
11+
return cocos2d::ccScriptType::kScriptTypeJavascript;
12+
}
13+
14+
void removeScriptObjectByCCObject(CCObject* object) {
15+
ObjectDestroyedEvent(object).send();
16+
}
17+
18+
int executeNodeEvent(CCNode* node, int action) {
19+
NodeEvent(node, static_cast<NodeEventType>(action)).send();
20+
return -1;
21+
}
22+
23+
int executeMenuItemEvent(CCMenuItem* menuItem) {
24+
MenuItemEvent(menuItem).send();
25+
return -1;
26+
}
27+
28+
void removeScriptHandler(int handler) {}
29+
int reallocateScriptHandler(int handler) { return -1; }
30+
int executeString(const char* codes) { return -1; }
31+
int executeScriptFile(const char* filename) { return -1; }
32+
int executeGlobalFunction(const char* functionName) { return -1; }
33+
int executeNotificationEvent(CCNotificationCenter* notificationCenter, const char* name) { return -1; }
34+
int executeCallFuncActionEvent(CCCallFunc* action, CCObject* target) { return -1; }
35+
int executeSchedule(int handler, float dt, CCNode* node) { return -1; }
36+
int executeLayerTouchesEvent(CCLayer* layer, int eventType, CCSet* touches) { return -1; }
37+
int executeLayerTouchEvent(CCLayer* layer, int eventType, CCTouch* touch) { return -1; }
38+
int executeLayerKeypadEvent(CCLayer* layer, int eventType) { return -1; }
39+
int executeAccelerometerEvent(CCLayer* layer, CCAcceleration* accelerationValue) { return -1; }
40+
int executeEvent(int handler, const char* eventName, CCObject* eventSource, const char* eventSourceClassName) { return -1; }
41+
int executeEventWithArgs(int handler, CCArray* args) { return -1; }
42+
bool handleAssert(const char* msg) { return false; }
43+
bool parseConfig(ConfigType type, const gd::string& str) { return false; }
44+
};
45+
}
46+
47+
$execute {
48+
CCScriptEngineManager::sharedManager()->setScriptEngine(new geode::ScriptEngine());
49+
}

0 commit comments

Comments
 (0)