2018-12-20 02:51:30 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: ScriptEngine.cpp
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Created: 20/12/2018 00:42:55
|
|
|
|
*
|
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
2019-01-07 01:26:02 +01:00
|
|
|
#include "LuaGUI.hpp"
|
2019-01-04 18:05:35 +01:00
|
|
|
#include "LuaMod.hpp"
|
2018-12-20 02:51:30 +01:00
|
|
|
#include "Player.hpp"
|
|
|
|
#include "Registry.hpp"
|
2019-01-04 18:05:35 +01:00
|
|
|
#include "ScriptEngine.hpp"
|
2018-12-20 02:51:30 +01:00
|
|
|
|
|
|
|
ScriptEngine *ScriptEngine::s_instance = nullptr;
|
|
|
|
|
|
|
|
void ScriptEngine::init() {
|
|
|
|
setInstance(this);
|
|
|
|
|
2018-12-20 03:30:11 +01:00
|
|
|
initUsertypes();
|
|
|
|
|
2019-01-07 02:05:23 +01:00
|
|
|
// FIXME: Remove these lines when they're not needed anymore
|
2018-12-20 12:58:23 +01:00
|
|
|
m_lua["registry"] = &Registry::getInstance();
|
2019-01-05 04:00:55 +01:00
|
|
|
m_lua["open_furnace"] = &openFurnace;
|
|
|
|
m_lua["update_furnace"] = &updateFurnace;
|
2018-12-20 03:30:11 +01:00
|
|
|
|
2018-12-20 05:19:56 +01:00
|
|
|
m_lua.open_libraries(sol::lib::base);
|
2018-12-20 03:30:11 +01:00
|
|
|
m_lua.safe_script_file("mods/test.lua");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngine::initUsertypes() {
|
2018-12-20 02:51:30 +01:00
|
|
|
m_lua.new_usertype<Player>("Player",
|
|
|
|
"inventory", &Player::inventory);
|
|
|
|
|
|
|
|
m_lua.new_usertype<Inventory>("Inventory",
|
2019-01-07 03:55:37 +01:00
|
|
|
"add_stack", &Inventory::addStack
|
2018-12-20 02:51:30 +01:00
|
|
|
);
|
|
|
|
|
2019-01-07 03:55:37 +01:00
|
|
|
m_lua.new_usertype<glm::ivec3>("ivec3",
|
|
|
|
"x", &glm::ivec3::x,
|
|
|
|
"y", &glm::ivec3::y,
|
|
|
|
"z", &glm::ivec3::z
|
2019-01-04 18:05:35 +01:00
|
|
|
);
|
2019-01-07 01:26:02 +01:00
|
|
|
|
2019-01-07 03:55:37 +01:00
|
|
|
LuaMod::initUsertype(m_lua);
|
|
|
|
LuaGUI::initUsertype(m_lua);
|
2018-12-20 02:51:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 02:05:23 +01:00
|
|
|
// FIXME: All the code below will be removed once these blocks are fully implemented in Lua
|
|
|
|
|
2019-01-05 04:00:55 +01:00
|
|
|
#include "BlockFurnace.hpp"
|
|
|
|
#include "Chunk.hpp"
|
|
|
|
#include "Player.hpp"
|
|
|
|
#include "World.hpp"
|
|
|
|
|
|
|
|
bool ScriptEngine::openFurnace(const glm::ivec3 &position, Player &player, World &world) {
|
|
|
|
BlockFurnace block;
|
|
|
|
return block.onBlockActivated(position, player, world);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngine::updateFurnace(const glm::ivec3 &position, Player &player, Chunk &chunk, World &world) {
|
|
|
|
BlockFurnace block;
|
|
|
|
return block.onTick(position, player, chunk, world);
|
|
|
|
}
|
|
|
|
|