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)
|
||||
|
||||
--called ~60 times per second
|
||||
roomSystem.Room.SetOnTick(room, function(room)
|
||||
roomSystem.Room.ForEachCharacter(room, function(character)
|
||||
print(characterSystem.Character.GetHandle(character))
|
||||
end)
|
||||
-- roomSystem.Room.SetOnTick(room, function(room)
|
||||
-- roomSystem.Room.ForEachCharacter(room, function(character)
|
||||
-- print(characterSystem.Character.GetHandle(character))
|
||||
-- end)
|
||||
--[[
|
||||
local character = characterSystem.CharacterManager.GetCharacter("handle")
|
||||
if character ~= nil then
|
||||
@@ -36,7 +36,7 @@ roomSystem.RoomManager.SetOnCreate(function(room, index)
|
||||
end
|
||||
end
|
||||
--]]
|
||||
end)
|
||||
-- end)
|
||||
end)
|
||||
|
||||
roomSystem.RoomManager.SetOnUnload(function(room, index)
|
||||
@@ -47,20 +47,21 @@ end)
|
||||
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
||||
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
||||
|
||||
--[[
|
||||
--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)
|
||||
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
||||
trigger2, uid2 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
||||
|
||||
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)
|
||||
--]]
|
||||
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)
|
||||
|
||||
dumpTrigger(trigger1)
|
||||
dumpTrigger(trigger2)
|
||||
dumpTrigger(trigger3)
|
||||
|
||||
print("Finished the lua script")
|
||||
|
||||
@@ -96,7 +96,7 @@ static int setOnTick(lua_State* L) {
|
||||
|
||||
static int getOnTick(lua_State* L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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