Exposed BarrierManager to the API*
This commit is contained in:
@@ -64,6 +64,18 @@ static int getInstance(lua_State* L) {
|
||||
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[] = {
|
||||
{"SetScript", setScript},
|
||||
{"GetScript", getScript},
|
||||
@@ -71,6 +83,8 @@ static const luaL_Reg barrierLib[] = {
|
||||
{"GetTag", getTag},
|
||||
{"SetInstance", setInstance},
|
||||
{"GetInstance", getInstance},
|
||||
{"SetStatus", setStatus},
|
||||
{"GetStatus", getStatus},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
@@ -84,6 +84,20 @@ int BarrierData::GetInstanceIndex() const {
|
||||
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() {
|
||||
return status;
|
||||
}
|
||||
@@ -44,6 +44,9 @@ public:
|
||||
int SetInstanceIndex(int i);
|
||||
int GetInstanceIndex() const;
|
||||
|
||||
int SetStatus(int k, int v);
|
||||
int GetStatus(int k);
|
||||
|
||||
int* GetStatusArray();
|
||||
|
||||
private:
|
||||
|
||||
@@ -44,6 +44,9 @@ int BarrierManager::Create(int instanceIndex) {
|
||||
//implicitly create the new object
|
||||
elementMap.emplace( std::pair<int, BarrierData>(counter, BarrierData(instanceIndex)) );
|
||||
|
||||
//set the script
|
||||
//TODO: (0)
|
||||
|
||||
//TODO: do various things like saving to the database
|
||||
return counter++;
|
||||
}
|
||||
@@ -103,3 +106,20 @@ sqlite3* BarrierManager::SetDatabase(sqlite3* db) {
|
||||
sqlite3* BarrierManager::GetDatabase() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +55,18 @@ public:
|
||||
sqlite3* SetDatabase(sqlite3* db);
|
||||
sqlite3* GetDatabase();
|
||||
|
||||
int SetCreateReference(int i);
|
||||
int SetUnloadReference(int i);
|
||||
|
||||
int GetCreateReference();
|
||||
int GetUnloadReference();
|
||||
|
||||
private:
|
||||
//members
|
||||
std::map<int, BarrierData> elementMap;
|
||||
int counter = 0;
|
||||
lua_State* lua = nullptr;
|
||||
sqlite3* database = nullptr;
|
||||
int createRef = LUA_NOREF;
|
||||
int unloadRef = LUA_NOREF;
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "entity_api.hpp"
|
||||
#include "barrier_api.hpp"
|
||||
#include "barrier_manager_api.hpp"
|
||||
#include "character_api.hpp"
|
||||
#include "character_manager_api.hpp"
|
||||
#include "region_api.hpp"
|
||||
@@ -70,6 +71,7 @@ static const luaL_Reg loadedlibs[] = {
|
||||
static const luaL_Reg preloadedlibs[] = {
|
||||
{TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes
|
||||
{TORTUGA_BARRIER_API, openBarrierAPI},
|
||||
{TORTUGA_BARRIER_MANAGER_API, openBarrierManagerAPI},
|
||||
{TORTUGA_CHARACTER_API, openCharacterAPI},
|
||||
{TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI},
|
||||
{TORTUGA_CREATURE_API, openCreatureAPI},
|
||||
|
||||
@@ -50,6 +50,12 @@ static int getTilesetName(lua_State* L) {
|
||||
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) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetCreatureMgr()) );
|
||||
@@ -135,6 +141,7 @@ static const luaL_Reg roomLib[] = {
|
||||
{"SetTileset", setTilesetName},
|
||||
{"GetTileset", getTilesetName},
|
||||
|
||||
{"GetBarrierMgr", getBarrierMgr},
|
||||
{"GetCreatureMgr",getCreatureMgr},
|
||||
{"GetPager",getPager},
|
||||
{"GetTriggerMgr",getTriggerMgr},
|
||||
|
||||
Reference in New Issue
Block a user