Full trigger creation
This commit is contained in:
@@ -64,10 +64,10 @@ static int setBoundingBox(lua_State* L) {
|
||||
|
||||
static int getBoundingBox(lua_State* L) {
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().x);
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().y);
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().w);
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().h);
|
||||
lua_pushinteger(L, trigger->GetBoundingBox().x);
|
||||
lua_pushinteger(L, trigger->GetBoundingBox().y);
|
||||
lua_pushinteger(L, trigger->GetBoundingBox().w);
|
||||
lua_pushinteger(L, trigger->GetBoundingBox().h);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ std::string TriggerData::GetHandle() const {
|
||||
return handle;
|
||||
}
|
||||
|
||||
int TriggerData::SetScriptReference(int i) {
|
||||
return scriptRef = i;
|
||||
Vector2 TriggerData::SetOrigin(Vector2 v) {
|
||||
return origin = v;
|
||||
}
|
||||
|
||||
int TriggerData::GetScriptReference() {
|
||||
return scriptRef;
|
||||
Vector2 TriggerData::GetOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
BoundingBox TriggerData::SetBoundingBox(BoundingBox b) {
|
||||
@@ -45,10 +45,10 @@ BoundingBox TriggerData::GetBoundingBox() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Vector2 TriggerData::SetOrigin(Vector2 v) {
|
||||
return origin = v;
|
||||
int TriggerData::SetScriptReference(int i) {
|
||||
return scriptRef = i;
|
||||
}
|
||||
|
||||
Vector2 TriggerData::GetOrigin() {
|
||||
return origin;
|
||||
}
|
||||
int TriggerData::GetScriptReference() {
|
||||
return scriptRef;
|
||||
}
|
||||
@@ -29,13 +29,11 @@ TriggerManager::~TriggerManager() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
int TriggerManager::Create(std::string handle, Vector2 origin, BoundingBox bounds) {
|
||||
int TriggerManager::Create(std::string handle) {
|
||||
//implicitly creates the element
|
||||
TriggerData& triggerData = elementMap[counter];
|
||||
|
||||
triggerData.SetHandle(handle);
|
||||
triggerData.SetOrigin(origin);
|
||||
triggerData.SetBoundingBox(bounds);
|
||||
|
||||
return counter++;
|
||||
}
|
||||
@@ -45,6 +43,7 @@ void TriggerManager::Unload(int uid) {
|
||||
}
|
||||
|
||||
void TriggerManager::UnloadAll() {
|
||||
//TODO: save?
|
||||
elementMap.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
~TriggerManager();
|
||||
|
||||
//common public methods
|
||||
int Create(std::string handle, Vector2 origin, BoundingBox bounds);
|
||||
int Create(std::string handle);
|
||||
void Unload(int uid);
|
||||
|
||||
void UnloadAll();
|
||||
|
||||
@@ -26,36 +26,40 @@
|
||||
//TODO: (1) figure out a way to iterate through elements of managers from lua
|
||||
|
||||
static int create(lua_State* L) {
|
||||
//DOCS: params: create(triggerMgr, name[, originX, originY[, boundsX, boundsY, boundsW, boundsH]][, script])
|
||||
|
||||
//get the trigger manager
|
||||
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||
|
||||
//pad the stack with default parameters
|
||||
if (lua_gettop(L) == 2) {
|
||||
lua_pushnumber(L, 0.0); //vector.x
|
||||
lua_pushnumber(L, 0.0); //vector.y
|
||||
}
|
||||
if (lua_gettop(L) == 4) {
|
||||
lua_pushinteger(L, 0); //bounds.x
|
||||
lua_pushinteger(L, 0); //bounds.y
|
||||
lua_pushinteger(L, 0); //bounds.w
|
||||
lua_pushinteger(L, 0); //bounds.h
|
||||
//create the trigger
|
||||
int index = mgr->Create(lua_tostring(L, 2));
|
||||
TriggerData* triggerData = mgr->Get(index);
|
||||
|
||||
//origin
|
||||
if (lua_gettop(L) >= 4) {
|
||||
triggerData->SetOrigin({lua_tonumber(L, 3), lua_tonumber(L, 4)}); //vectorX, vectorY
|
||||
}
|
||||
|
||||
//create the trigger
|
||||
int index = mgr->Create(
|
||||
lua_tostring(L, 2), //handle
|
||||
{
|
||||
lua_tonumber(L, 3), //vector.x
|
||||
lua_tonumber(L, 4) //vector.y
|
||||
},
|
||||
{
|
||||
lua_tointeger(L, 5), //bounds.x
|
||||
lua_tointeger(L, 6), //bounds.y
|
||||
lua_tointeger(L, 7), //bounds.w
|
||||
lua_tointeger(L, 8) //bounds.h
|
||||
//bounds
|
||||
if (lua_gettop(L) >= 8) {
|
||||
triggerData->SetBoundingBox({
|
||||
lua_tointeger(L, 5), //boundsX
|
||||
lua_tointeger(L, 6), //boundsY
|
||||
lua_tointeger(L, 7), //boundsW
|
||||
lua_tointeger(L, 8) //boundsH
|
||||
});
|
||||
}
|
||||
|
||||
//if the parameter list isn't capped with a script, append a nil instead
|
||||
if (lua_type(L, -1) != LUA_TFUNCTION) {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
//set the script reference (may be nil)
|
||||
triggerData->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
|
||||
//push to the scipts
|
||||
lua_pushlightuserdata(L, static_cast<void*>(mgr->Get(index)) );
|
||||
lua_pushlightuserdata(L, static_cast<void*>(triggerData));
|
||||
lua_pushinteger(L, index);
|
||||
|
||||
return 2;
|
||||
|
||||
Reference in New Issue
Block a user