Action nodes work better now
This commit is contained in:
@@ -60,12 +60,39 @@ public:
|
||||
};
|
||||
struct PlayerActionModule {
|
||||
struct ActionWordHandler {
|
||||
virtual void operator()(flecs::entity town, int index,
|
||||
const Ogre::String &word) = 0;
|
||||
/** actor is -1 for player >=0 for NPCs */
|
||||
virtual void operator()(int actor, flecs::entity town, int index,
|
||||
const Ogre::String &word, int actionNode) = 0;
|
||||
};
|
||||
struct ActivatedWordHandler {
|
||||
enum {OK = 0, BUSY, ERROR};
|
||||
private:
|
||||
bool active;
|
||||
public:
|
||||
ActivatedWordHandler(): active(false) {}
|
||||
int _update(float delta)
|
||||
{
|
||||
if (!active) {
|
||||
enter();
|
||||
active = true;
|
||||
}
|
||||
int ret = update(delta);
|
||||
if (ret != BUSY) {
|
||||
exit(ret);
|
||||
active = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
virtual ~ActivatedWordHandler() {}
|
||||
bool _is_active() {return active;}
|
||||
private:
|
||||
virtual void enter() = 0;
|
||||
virtual void exit(int result) = 0;
|
||||
virtual int update(float delta) = 0;
|
||||
};
|
||||
|
||||
std::multimap<Ogre::String, ActionWordHandler *>
|
||||
actionWords;
|
||||
std::multimap<Ogre::String, ActivatedWordHandler *> activatedWords;
|
||||
|
||||
PlayerActionModule(flecs::world &ecs);
|
||||
void addWordHandler(const Ogre::String &word, ActionWordHandler *handler);
|
||||
@@ -73,6 +100,8 @@ struct PlayerActionModule {
|
||||
void addLuaWordHandler(const Ogre::String &word, lua_State *L, int ref);
|
||||
void removeLuaWordHandler(const Ogre::String &word, lua_State *L, int ref);
|
||||
int setupLuaActionHandler(lua_State *L);
|
||||
void addActivatedWordHandler(const Ogre::String &word, ActivatedWordHandler *handler);
|
||||
void removeActivatedWordHandler(const Ogre::String &word, ActivatedWordHandler *handler);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user