Filled out the APIs a bit
This commit is contained in:
@@ -21,13 +21,55 @@
|
||||
*/
|
||||
#include "generator_api.hpp"
|
||||
|
||||
static int getGenerator(lua_State* L) {
|
||||
//TODO: return a generator based on the given parameter
|
||||
return 0;
|
||||
#include "base_generator.hpp"
|
||||
|
||||
static int getMapType(lua_State* L) {
|
||||
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
|
||||
switch(ptr->GetMapType()) {
|
||||
case MapType::NONE:
|
||||
lua_pushstring(L, "none");
|
||||
break;
|
||||
case MapType::OVERWORLD:
|
||||
lua_pushstring(L, "overworld");
|
||||
break;
|
||||
case MapType::RUINS:
|
||||
lua_pushstring(L, "ruins");
|
||||
break;
|
||||
case MapType::TOWERS:
|
||||
lua_pushstring(L, "towers");
|
||||
break;
|
||||
case MapType::FORESTS:
|
||||
lua_pushstring(L, "forests");
|
||||
break;
|
||||
case MapType::CAVES:
|
||||
lua_pushstring(L, "caves");
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getChunk(lua_State* L) {
|
||||
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
|
||||
ChunkData* chunk = ptr->GetChunk(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(chunk));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getMapWidth(lua_State* L) {
|
||||
lua_pushinteger(L, MAP_WIDTH);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getMapHeight(lua_State* L) {
|
||||
lua_pushinteger(L, MAP_HEIGHT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg generatorlib[] = {
|
||||
{"getgenerator", getGenerator},
|
||||
{"gettype", getMapType},
|
||||
{"getchunk", getChunk},
|
||||
{"getmapwidth", getMapWidth},
|
||||
{"getmapheight", getMapHeight},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=.
|
||||
INCLUDES+=. generators
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
+10
-13
@@ -21,28 +21,25 @@
|
||||
*/
|
||||
#include "room_api.hpp"
|
||||
|
||||
#include "room_manager.hpp"
|
||||
#include "room_data.hpp"
|
||||
|
||||
static int getType(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, static_cast<int>(room->type));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: parameters
|
||||
|
||||
static int getRegionPager(lua_State* L) {
|
||||
static int getPager(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: generators
|
||||
static int getGenerator(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->generator));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: parameters
|
||||
|
||||
static const luaL_Reg roomlib[] = {
|
||||
{"gettype",getType},
|
||||
{"getregionpager",getRegionPager},
|
||||
{"getpager",getPager},
|
||||
{"getgenerator",getGenerator},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
struct RoomData {
|
||||
//members
|
||||
MapType type;
|
||||
RegionPagerLua pager;
|
||||
BaseGenerator* generator = nullptr;
|
||||
|
||||
|
||||
@@ -35,8 +35,33 @@ static int getRoom(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int createRoom(lua_State* L) {
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//TODO: create room
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unloadRoom(lua_State* L) {
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//unload the specified room
|
||||
roomMgr->UnloadRoom(lua_tointeger(L, -2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg roommgrlib[] = {
|
||||
{"getroom",getRoom},
|
||||
{"createroom",createRoom},
|
||||
{"unloadroom",unloadRoom},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user