Full trigger creation
This commit is contained in:
@@ -19,10 +19,10 @@ roomSystem.RoomManager.SetOnCreate(function(room, index)
|
|||||||
print("", "Creating room: ", roomSystem.Room.GetName(room), index)
|
print("", "Creating room: ", roomSystem.Room.GetName(room), index)
|
||||||
|
|
||||||
--called ~60 times per second
|
--called ~60 times per second
|
||||||
roomSystem.Room.SetOnTick(room, function(room)
|
-- roomSystem.Room.SetOnTick(room, function(room)
|
||||||
roomSystem.Room.ForEachCharacter(room, function(character)
|
-- roomSystem.Room.ForEachCharacter(room, function(character)
|
||||||
print(characterSystem.Character.GetHandle(character))
|
-- print(characterSystem.Character.GetHandle(character))
|
||||||
end)
|
-- end)
|
||||||
--[[
|
--[[
|
||||||
local character = characterSystem.CharacterManager.GetCharacter("handle")
|
local character = characterSystem.CharacterManager.GetCharacter("handle")
|
||||||
if character ~= nil then
|
if character ~= nil then
|
||||||
@@ -36,7 +36,7 @@ roomSystem.RoomManager.SetOnCreate(function(room, index)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
--]]
|
--]]
|
||||||
end)
|
-- end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
roomSystem.RoomManager.SetOnUnload(function(room, index)
|
roomSystem.RoomManager.SetOnUnload(function(room, index)
|
||||||
@@ -47,20 +47,21 @@ end)
|
|||||||
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
||||||
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
||||||
|
|
||||||
--[[
|
|
||||||
--debugging
|
--debugging
|
||||||
|
function dumpTrigger(t)
|
||||||
|
local originX, originY = triggerSystem.Trigger.GetOrigin(t)
|
||||||
|
local bx, by, bw, bh = triggerSystem.Trigger.GetBounds(t)
|
||||||
|
local s = triggerSystem.Trigger.GetScript(t)
|
||||||
|
print(triggerSystem.Trigger.GetHandle(t), originX, originY, bx, by, bw, bh, s)
|
||||||
|
end
|
||||||
|
|
||||||
triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
|
triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
|
||||||
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
||||||
trigger2, uid2 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
trigger2, uid2 = triggerSystem.TriggerManager.Create(triggerMgr, "handle2", 30.2, 40.2)
|
||||||
|
trigger3, uid3 = triggerSystem.TriggerManager.Create(triggerMgr, "handle3", 30.2, 40.2, 0, 16, 32, 32, function() end)
|
||||||
print("triggers:", triggerSystem.TriggerManager.GetCount(triggerMgr))
|
|
||||||
|
|
||||||
local deleted = triggerSystem.TriggerManager.Unload(triggerMgr, triggerSystem.Trigger.GetHandle(trigger1))
|
|
||||||
|
|
||||||
print("triggers:", triggerSystem.TriggerManager.GetCount(triggerMgr))
|
|
||||||
|
|
||||||
print("deleted: ", deleted)
|
|
||||||
--]]
|
|
||||||
|
|
||||||
|
dumpTrigger(trigger1)
|
||||||
|
dumpTrigger(trigger2)
|
||||||
|
dumpTrigger(trigger3)
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ static int setOnTick(lua_State* L) {
|
|||||||
|
|
||||||
static int getOnTick(lua_State* L) {
|
static int getOnTick(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, room->GetTickReference());
|
lua_rawgeti(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ static int setBoundingBox(lua_State* L) {
|
|||||||
|
|
||||||
static int getBoundingBox(lua_State* L) {
|
static int getBoundingBox(lua_State* L) {
|
||||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||||
lua_pushnumber(L, trigger->GetBoundingBox().x);
|
lua_pushinteger(L, trigger->GetBoundingBox().x);
|
||||||
lua_pushnumber(L, trigger->GetBoundingBox().y);
|
lua_pushinteger(L, trigger->GetBoundingBox().y);
|
||||||
lua_pushnumber(L, trigger->GetBoundingBox().w);
|
lua_pushinteger(L, trigger->GetBoundingBox().w);
|
||||||
lua_pushnumber(L, trigger->GetBoundingBox().h);
|
lua_pushinteger(L, trigger->GetBoundingBox().h);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ std::string TriggerData::GetHandle() const {
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TriggerData::SetScriptReference(int i) {
|
Vector2 TriggerData::SetOrigin(Vector2 v) {
|
||||||
return scriptRef = i;
|
return origin = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TriggerData::GetScriptReference() {
|
Vector2 TriggerData::GetOrigin() {
|
||||||
return scriptRef;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox TriggerData::SetBoundingBox(BoundingBox b) {
|
BoundingBox TriggerData::SetBoundingBox(BoundingBox b) {
|
||||||
@@ -45,10 +45,10 @@ BoundingBox TriggerData::GetBoundingBox() {
|
|||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 TriggerData::SetOrigin(Vector2 v) {
|
int TriggerData::SetScriptReference(int i) {
|
||||||
return origin = v;
|
return scriptRef = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 TriggerData::GetOrigin() {
|
int TriggerData::GetScriptReference() {
|
||||||
return origin;
|
return scriptRef;
|
||||||
}
|
}
|
||||||
@@ -29,13 +29,11 @@ TriggerManager::~TriggerManager() {
|
|||||||
UnloadAll();
|
UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TriggerManager::Create(std::string handle, Vector2 origin, BoundingBox bounds) {
|
int TriggerManager::Create(std::string handle) {
|
||||||
//implicitly creates the element
|
//implicitly creates the element
|
||||||
TriggerData& triggerData = elementMap[counter];
|
TriggerData& triggerData = elementMap[counter];
|
||||||
|
|
||||||
triggerData.SetHandle(handle);
|
triggerData.SetHandle(handle);
|
||||||
triggerData.SetOrigin(origin);
|
|
||||||
triggerData.SetBoundingBox(bounds);
|
|
||||||
|
|
||||||
return counter++;
|
return counter++;
|
||||||
}
|
}
|
||||||
@@ -45,6 +43,7 @@ void TriggerManager::Unload(int uid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TriggerManager::UnloadAll() {
|
void TriggerManager::UnloadAll() {
|
||||||
|
//TODO: save?
|
||||||
elementMap.clear();
|
elementMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
~TriggerManager();
|
~TriggerManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string handle, Vector2 origin, BoundingBox bounds);
|
int Create(std::string handle);
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
|
|||||||
@@ -26,36 +26,40 @@
|
|||||||
//TODO: (1) figure out a way to iterate through elements of managers from lua
|
//TODO: (1) figure out a way to iterate through elements of managers from lua
|
||||||
|
|
||||||
static int create(lua_State* L) {
|
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));
|
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||||
|
|
||||||
//pad the stack with default parameters
|
//create the trigger
|
||||||
if (lua_gettop(L) == 2) {
|
int index = mgr->Create(lua_tostring(L, 2));
|
||||||
lua_pushnumber(L, 0.0); //vector.x
|
TriggerData* triggerData = mgr->Get(index);
|
||||||
lua_pushnumber(L, 0.0); //vector.y
|
|
||||||
}
|
//origin
|
||||||
if (lua_gettop(L) == 4) {
|
if (lua_gettop(L) >= 4) {
|
||||||
lua_pushinteger(L, 0); //bounds.x
|
triggerData->SetOrigin({lua_tonumber(L, 3), lua_tonumber(L, 4)}); //vectorX, vectorY
|
||||||
lua_pushinteger(L, 0); //bounds.y
|
|
||||||
lua_pushinteger(L, 0); //bounds.w
|
|
||||||
lua_pushinteger(L, 0); //bounds.h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//create the trigger
|
//bounds
|
||||||
int index = mgr->Create(
|
if (lua_gettop(L) >= 8) {
|
||||||
lua_tostring(L, 2), //handle
|
triggerData->SetBoundingBox({
|
||||||
{
|
lua_tointeger(L, 5), //boundsX
|
||||||
lua_tonumber(L, 3), //vector.x
|
lua_tointeger(L, 6), //boundsY
|
||||||
lua_tonumber(L, 4) //vector.y
|
lua_tointeger(L, 7), //boundsW
|
||||||
},
|
lua_tointeger(L, 8) //boundsH
|
||||||
{
|
|
||||||
lua_tointeger(L, 5), //bounds.x
|
|
||||||
lua_tointeger(L, 6), //bounds.y
|
|
||||||
lua_tointeger(L, 7), //bounds.w
|
|
||||||
lua_tointeger(L, 8) //bounds.h
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
//push to the scipts
|
||||||
lua_pushlightuserdata(L, static_cast<void*>(mgr->Get(index)) );
|
lua_pushlightuserdata(L, static_cast<void*>(triggerData));
|
||||||
lua_pushinteger(L, index);
|
lua_pushinteger(L, index);
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user