Implemented CharacterManager::ForEach()
This commit is contained in:
@@ -20,6 +20,9 @@ roomSystem.RoomManager.SetOnCreate(function(room, index)
|
||||
|
||||
--called ~60 times per second
|
||||
roomSystem.Room.SetOnTick(room, function(room)
|
||||
characterSystem.CharacterManager.ForEach(function(character)
|
||||
print(characterSystem.Character.GetHandle(character))
|
||||
end)
|
||||
--[[
|
||||
local character = characterSystem.CharacterManager.GetCharacter("handle")
|
||||
if character ~= nil then
|
||||
@@ -44,6 +47,7 @@ end)
|
||||
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
||||
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
||||
|
||||
--[[
|
||||
--debugging
|
||||
triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
|
||||
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
||||
@@ -56,5 +60,7 @@ local deleted = triggerSystem.TriggerManager.Unload(triggerMgr, triggerSystem.Tr
|
||||
print("triggers:", triggerSystem.TriggerManager.GetCount(triggerMgr))
|
||||
|
||||
print("deleted: ", deleted)
|
||||
--]]
|
||||
|
||||
|
||||
print("Finished the lua script")
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
|
||||
#include "character_manager.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
//TODO: (1) character hooks?
|
||||
|
||||
static int setOnCreate(lua_State* L) {
|
||||
//TODO: (9) setOnCreate()
|
||||
}
|
||||
@@ -75,7 +80,20 @@ static int getLoadedCount(lua_State* L) {
|
||||
}
|
||||
|
||||
static int forEach(lua_State* L) {
|
||||
//TODO: (9) forEach()
|
||||
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
||||
//pass each character to the given function
|
||||
for (auto& it : *characterMgr.GetContainer()) {
|
||||
lua_pushvalue(L, -1);
|
||||
lua_pushlightuserdata(L, static_cast<void*>(&it.second));
|
||||
//call each iteration, throwing an exception if something happened
|
||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||
std::ostringstream os;
|
||||
os << "Lua error: ";
|
||||
os << lua_tostring(L, -1);
|
||||
throw(std::runtime_error(os.str()));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg characterManagerLib[] = {
|
||||
@@ -86,7 +104,7 @@ static const luaL_Reg characterManagerLib[] = {
|
||||
// {"SetOnDelete", setOnDelete},
|
||||
{"GetCharacter", getCharacter},
|
||||
{"GetLoadedCount", getLoadedCount},
|
||||
// {"ForEach", forEach},
|
||||
{"ForEach", forEach},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ static int getTriggerMgr(lua_State* L) {
|
||||
|
||||
//TODO: character list
|
||||
|
||||
//TODO: (1) forEachCharacter
|
||||
|
||||
static int setOnTick(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
||||
|
||||
Reference in New Issue
Block a user