Skip to content

Commit

Permalink
Added FileFormats.getLevelData()
Browse files Browse the repository at this point in the history
to extract a data of a currently loaded level
  • Loading branch information
Wohlstand committed Dec 26, 2019
1 parent 2846906 commit b53d49f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
2 changes: 2 additions & 0 deletions LunaDll/LuaMain/LuaProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,10 @@ namespace LuaProxy {
namespace Formats{
luabind::object openLevelHeader(const std::string &filePath, lua_State *L);
luabind::object openLevel(const std::string &filePath, lua_State *L);
luabind::object getLevelData(lua_State *L);
luabind::object openWorldHeader(const std::string &filePath, lua_State *L);
luabind::object openWorld(const std::string &filePath, lua_State *L);
//luabind::object getWorldData(lua_State *L); // TODO: Implement this once PGEFL will handle WorldMap reading
luabind::object openNpcConfig(const std::string &filePath, lua_State *L);
}

Expand Down
50 changes: 30 additions & 20 deletions LunaDll/LuaMain/LuaProxyComponent/LuaProxyFileFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../../../GlobalFuncs.h"
#include "../../libs/PGE_File_Formats/file_formats.h"
#include "../../libs/json/json.hpp"
#include "../../Misc/TestMode.h"
#include <stack>

using json = nlohmann::json;
Expand Down Expand Up @@ -247,12 +248,9 @@ luabind::object LuaProxy::Formats::openLevelHeader(const std::string &filePath,
return outData;
}

luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_State *L)
{
LevelData data;
std::string full_path = getFullPath(filePath);
FileFormats::OpenLevelFile(full_path, data);

static luabind::object openLevelInternal(const LevelData &data, lua_State *L)
{
luabind::object outData = luabind::newtable(L);
outData["meta"] = getMeta(data.meta, L);

Expand All @@ -265,7 +263,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelData::MusicOverrider & mo : data.music_overrides)
for(const LevelData::MusicOverrider & mo : data.music_overrides)
{
luabind::object e = luabind::newtable(L);
e["type"] = static_cast<int>(mo.type);
Expand All @@ -279,7 +277,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelData::MusicOverrider & mo : data.sound_overrides)
for(const LevelData::MusicOverrider & mo : data.sound_overrides)
{
luabind::object e = luabind::newtable(L);
e["type"] = static_cast<int>(mo.type);
Expand All @@ -293,7 +291,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelSection & sct : data.sections)
for(const LevelSection & sct : data.sections)
{
luabind::object e = luabind::newtable(L);
e["id"] = sct.id;
Expand Down Expand Up @@ -328,7 +326,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(PlayerPoint & plr : data.players)
for(const PlayerPoint & plr : data.players)
{
luabind::object e = luabind::newtable(L);
e["id"] = plr.id;
Expand All @@ -345,7 +343,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelBlock & block : data.blocks)
for(const LevelBlock & block : data.blocks)
{
luabind::object e = luabind::newtable(L);
e["x"] = block.x;
Expand Down Expand Up @@ -379,7 +377,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelBGO & bgo : data.bgo)
for(const LevelBGO & bgo : data.bgo)
{
luabind::object e = luabind::newtable(L);
e["x"] = bgo.x;
Expand All @@ -403,7 +401,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelNPC & npc : data.npc)
for(const LevelNPC & npc : data.npc)
{
luabind::object e = luabind::newtable(L);
e["x"] = npc.x;
Expand Down Expand Up @@ -463,7 +461,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelDoor & warp : data.doors)
for(const LevelDoor & warp : data.doors)
{
luabind::object e = luabind::newtable(L);
e["ix"] = warp.ix;
Expand Down Expand Up @@ -531,7 +529,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelPhysEnv & pez : data.physez)
for(const LevelPhysEnv & pez : data.physez)
{
luabind::object e = luabind::newtable(L);
e["x"] = pez.x;
Expand All @@ -558,7 +556,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelLayer & layer : data.layers)
for(const LevelLayer & layer : data.layers)
{
luabind::object e = luabind::newtable(L);
e["name"] = layer.name;
Expand All @@ -573,7 +571,7 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object arr = luabind::newtable(L);
size_t counter = 0;
for(LevelSMBX64Event & event : data.events)
for(const LevelSMBX64Event & event : data.events)
{
luabind::object e = luabind::newtable(L);
e["name"] = event.name;
Expand All @@ -586,29 +584,29 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
{
luabind::object ll = luabind::newtable(L);
size_t counter_2 = 0;
for(PGESTRING &l : event.layers_hide)
for(const PGESTRING &l : event.layers_hide)
ll[++counter_2] = l;
e["layersToHide"] = ll;
}
{
luabind::object ll = luabind::newtable(L);
size_t counter_2 = 0;
for(PGESTRING &l : event.layers_show)
for(const PGESTRING &l : event.layers_show)
ll[++counter_2] = l;
e["layersToShow"] = ll;
}
{
luabind::object ll = luabind::newtable(L);
size_t counter_2 = 0;
for(PGESTRING &l : event.layers_toggle)
for(const PGESTRING &l : event.layers_toggle)
ll[++counter_2] = l;
e["layersToToggle"] = ll;
}

{
size_t counter_2 = 0;
luabind::object sets = luabind::newtable(L);
for(LevelEvent_Sets &s : event.sets)
for(const LevelEvent_Sets &s : event.sets)
{
luabind::object set = luabind::newtable(L);
set["id"] = s.id;
Expand Down Expand Up @@ -691,6 +689,18 @@ luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_St
return outData;
}

luabind::object LuaProxy::Formats::openLevel(const std::string &filePath, lua_State *L)
{
LevelData data;
std::string full_path = getFullPath(filePath);
FileFormats::OpenLevelFile(full_path, data);
return openLevelInternal(data, L);
}

luabind::object LuaProxy::Formats::getLevelData(lua_State *L)
{
return openLevelInternal(getCurrentLevelData(), L);
}

luabind::object LuaProxy::Formats::openWorldHeader(const std::string &filePath, lua_State *L)
{
Expand Down
1 change: 1 addition & 0 deletions LunaDll/LuaMain/LunaLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ void CLunaLua::bindAll()
],
def("openLevel", &LuaProxy::Formats::openLevel),
def("openLevelHeader", &LuaProxy::Formats::openLevelHeader),
def("getLevelData", &LuaProxy::Formats::getLevelData),
def("openWorld", &LuaProxy::Formats::openWorld),
def("openWorldHeader", &LuaProxy::Formats::openWorldHeader),
def("openNpcConfig", &LuaProxy::Formats::openNpcConfig)
Expand Down

0 comments on commit b53d49f

Please sign in to comment.