Exposed BarrierManager to the API*

This commit is contained in:
2016-04-11 01:03:02 +10:00
parent ccb7adbd10
commit f32b8a9b4f
9 changed files with 142 additions and 0 deletions
+14
View File
@@ -64,6 +64,18 @@ static int getInstance(lua_State* L) {
return 1; return 1;
} }
static int setStatus(lua_State* L) {
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
barrier->SetStatus(lua_tointeger(L, 2), lua_tointeger(L, 3));
return 0;
}
static int getStatus(lua_State* L) {
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
lua_pushinteger(L, barrier->GetStatus(lua_tointeger(L, 2)) );
return 1;
}
static const luaL_Reg barrierLib[] = { static const luaL_Reg barrierLib[] = {
{"SetScript", setScript}, {"SetScript", setScript},
{"GetScript", getScript}, {"GetScript", getScript},
@@ -71,6 +83,8 @@ static const luaL_Reg barrierLib[] = {
{"GetTag", getTag}, {"GetTag", getTag},
{"SetInstance", setInstance}, {"SetInstance", setInstance},
{"GetInstance", getInstance}, {"GetInstance", getInstance},
{"SetStatus", setStatus},
{"GetStatus", getStatus},
{nullptr, nullptr} {nullptr, nullptr}
}; };
+14
View File
@@ -84,6 +84,20 @@ int BarrierData::GetInstanceIndex() const {
return instanceIndex; return instanceIndex;
} }
int BarrierData::SetStatus(int k, int v) {
if (k < 0 || k >= 8) {
return -1;
}
return status[k] = v;
}
int BarrierData::GetStatus(int k) {
if (k < 0 || k >= 8) {
return -1;
}
return status[k];
}
int* BarrierData::GetStatusArray() { int* BarrierData::GetStatusArray() {
return status; return status;
} }
+3
View File
@@ -44,6 +44,9 @@ public:
int SetInstanceIndex(int i); int SetInstanceIndex(int i);
int GetInstanceIndex() const; int GetInstanceIndex() const;
int SetStatus(int k, int v);
int GetStatus(int k);
int* GetStatusArray(); int* GetStatusArray();
private: private:
+20
View File
@@ -44,6 +44,9 @@ int BarrierManager::Create(int instanceIndex) {
//implicitly create the new object //implicitly create the new object
elementMap.emplace( std::pair<int, BarrierData>(counter, BarrierData(instanceIndex)) ); elementMap.emplace( std::pair<int, BarrierData>(counter, BarrierData(instanceIndex)) );
//set the script
//TODO: (0)
//TODO: do various things like saving to the database //TODO: do various things like saving to the database
return counter++; return counter++;
} }
@@ -103,3 +106,20 @@ sqlite3* BarrierManager::SetDatabase(sqlite3* db) {
sqlite3* BarrierManager::GetDatabase() { sqlite3* BarrierManager::GetDatabase() {
return database; return database;
} }
int BarrierManager::SetCreateReference(int i) {
return createRef = i;
}
int BarrierManager::SetUnloadReference(int i) {
return unloadRef = i;
}
int BarrierManager::GetCreateReference() {
return createRef;
}
int BarrierManager::GetUnloadReference() {
return unloadRef;
}
+8
View File
@@ -55,10 +55,18 @@ public:
sqlite3* SetDatabase(sqlite3* db); sqlite3* SetDatabase(sqlite3* db);
sqlite3* GetDatabase(); sqlite3* GetDatabase();
int SetCreateReference(int i);
int SetUnloadReference(int i);
int GetCreateReference();
int GetUnloadReference();
private: private:
//members //members
std::map<int, BarrierData> elementMap; std::map<int, BarrierData> elementMap;
int counter = 0; int counter = 0;
lua_State* lua = nullptr; lua_State* lua = nullptr;
sqlite3* database = nullptr; sqlite3* database = nullptr;
int createRef = LUA_NOREF;
int unloadRef = LUA_NOREF;
}; };
+47
View File
@@ -0,0 +1,47 @@
/* Copyright: (c) Kayne Ruse 2013-2016
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "barrier_manager_api.hpp"
#include "barrier_manager.hpp"
static int setOnCreate(lua_State* L) {
BarrierManager* barrierMgr = static_cast<BarrierManager*>(lua_touserdata(L, 1));
barrierMgr->SetCreateReference(luaL_ref(L, LUA_REGISTRYINDEX));
return 0;
}
static int setOnUnload(lua_State* L) {
BarrierManager* barrierMgr = static_cast<BarrierManager*>(lua_touserdata(L, 1));
barrierMgr->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
return 0;
}
static const luaL_Reg barrierManagerLib[] = {
{"SetOnCreate", setOnCreate},
{"SetOnUnload", setOnUnload},
{nullptr, nullptr}
};
LUAMOD_API int openBarrierManagerAPI(lua_State* L) {
luaL_newlib(L, barrierManagerLib);
return 1;
}
+27
View File
@@ -0,0 +1,27 @@
/* Copyright: (c) Kayne Ruse 2013-2016
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#pragma once
#include "lua.hpp"
#define TORTUGA_BARRIER_MANAGER_API "barrier_manager"
LUAMOD_API int openBarrierManagerAPI(lua_State* L);
+2
View File
@@ -38,6 +38,7 @@
#include "entity_api.hpp" #include "entity_api.hpp"
#include "barrier_api.hpp" #include "barrier_api.hpp"
#include "barrier_manager_api.hpp"
#include "character_api.hpp" #include "character_api.hpp"
#include "character_manager_api.hpp" #include "character_manager_api.hpp"
#include "region_api.hpp" #include "region_api.hpp"
@@ -70,6 +71,7 @@ static const luaL_Reg loadedlibs[] = {
static const luaL_Reg preloadedlibs[] = { static const luaL_Reg preloadedlibs[] = {
{TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes {TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes
{TORTUGA_BARRIER_API, openBarrierAPI}, {TORTUGA_BARRIER_API, openBarrierAPI},
{TORTUGA_BARRIER_MANAGER_API, openBarrierManagerAPI},
{TORTUGA_CHARACTER_API, openCharacterAPI}, {TORTUGA_CHARACTER_API, openCharacterAPI},
{TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI}, {TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI},
{TORTUGA_CREATURE_API, openCreatureAPI}, {TORTUGA_CREATURE_API, openCreatureAPI},
+7
View File
@@ -50,6 +50,12 @@ static int getTilesetName(lua_State* L) {
return 1; return 1;
} }
static int getBarrierMgr(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetBarrierMgr()) );
return 1;
}
static int getCreatureMgr(lua_State* L) { static int getCreatureMgr(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1)); RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetCreatureMgr()) ); lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetCreatureMgr()) );
@@ -135,6 +141,7 @@ static const luaL_Reg roomLib[] = {
{"SetTileset", setTilesetName}, {"SetTileset", setTilesetName},
{"GetTileset", getTilesetName}, {"GetTileset", getTilesetName},
{"GetBarrierMgr", getBarrierMgr},
{"GetCreatureMgr",getCreatureMgr}, {"GetCreatureMgr",getCreatureMgr},
{"GetPager",getPager}, {"GetPager",getPager},
{"GetTriggerMgr",getTriggerMgr}, {"GetTriggerMgr",getTriggerMgr},