The rabbit is moving on it's own
This commit is contained in:
@@ -52,11 +52,26 @@ static int getScript(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: autogen docs
|
||||
static int setTag(lua_State* L) {
|
||||
CreatureData* creature = static_cast<CreatureData*>(lua_touserdata(L, 1));
|
||||
creature->SetTag(lua_tostring(L, 2), lua_tostring(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getTag(lua_State* L) {
|
||||
CreatureData* creature = static_cast<CreatureData*>(lua_touserdata(L, 1));
|
||||
lua_pushstring(L, creature->GetTag(lua_tostring(L, 2)).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg creatureLib[] = {
|
||||
{"SetAvatar", setAvatar},
|
||||
{"GetAvatar", getAvatar},
|
||||
{"SetScript", setScript},
|
||||
{"GetScript", getScript},
|
||||
{"SetTag", setTag},
|
||||
{"GetTag", getTag},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ int CreatureData::Update(lua_State* L) {
|
||||
ret += lua_tonumber(L, -1);
|
||||
}
|
||||
|
||||
ret += Entity::Update();
|
||||
Entity::Update();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -75,4 +75,12 @@ int CreatureData::SetScriptReference(int i) {
|
||||
|
||||
int CreatureData::GetScriptReference() {
|
||||
return scriptRef;
|
||||
}
|
||||
|
||||
std::string CreatureData::SetTag(std::string key, std::string value) {
|
||||
return tags[key] = value;
|
||||
}
|
||||
|
||||
std::string CreatureData::GetTag(std::string key) {
|
||||
return tags[key];
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/* DOCS: Creature attributes, read more
|
||||
@@ -49,9 +50,13 @@ public:
|
||||
int SetScriptReference(int);
|
||||
int GetScriptReference();
|
||||
|
||||
std::string SetTag(std::string key, std::string value);
|
||||
std::string GetTag(std::string key);
|
||||
|
||||
private:
|
||||
friend class CreatureManager;
|
||||
|
||||
std::string avatar;
|
||||
int scriptRef = LUA_NOREF;
|
||||
std::map<std::string, std::string> tags;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ CreatureManager::~CreatureManager() {
|
||||
}
|
||||
|
||||
//arg: a list of creatures to be updated in the clients
|
||||
int CreatureManager::Update(std::list<std::pair<const int, CreatureData*>>* creatureList) {
|
||||
void CreatureManager::Update(std::list<std::pair<const int, CreatureData*>>* creatureList) {
|
||||
int ret;
|
||||
for (auto& it : elementMap) {
|
||||
ret = it.second.Update(lua);
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
~CreatureManager();
|
||||
|
||||
//common public methods
|
||||
int Update(std::list<std::pair<const int, CreatureData*>>* creatureList);
|
||||
void Update(std::list<std::pair<const int, CreatureData*>>* creatureList);
|
||||
|
||||
int Create(std::string avatar, int scriptRef);
|
||||
void Unload(int uid);
|
||||
|
||||
@@ -25,8 +25,12 @@
|
||||
|
||||
//args: mgr, avatar, script
|
||||
static int create(lua_State* L) {
|
||||
//register the function at the top of the stack
|
||||
lua_pushinteger(L, luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
|
||||
//create the actual creature
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3));
|
||||
int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3)); //3 should be the unique reference within LUA_REGISTRYINDEX
|
||||
CreatureData* creature = mgr->Get(index);
|
||||
lua_pushlightuserdata(L, static_cast<void*>(creature));
|
||||
lua_pushinteger(L, index);
|
||||
|
||||
Reference in New Issue
Block a user