mirror of
https://github.com/ApfelTeeSaft/gameBase.git
synced 2026-08-26 19:23:30 +00:00
using sol in code
This commit is contained in:
+1
-1
@@ -23,6 +23,6 @@ target_include_directories(${LIB_NAME} PUBLIC ${LUA_DIR}/external/upstream)
|
|||||||
|
|
||||||
set(SOL_DIR external/sol2)
|
set(SOL_DIR external/sol2)
|
||||||
add_subdirectory(${SOL_DIR})
|
add_subdirectory(${SOL_DIR})
|
||||||
target_include_directories(${LIB_NAME} PUBLIC ${SOL_DIR}/include/sol)
|
target_include_directories(${LIB_NAME} PUBLIC ${SOL_DIR}/include)
|
||||||
|
|
||||||
target_link_libraries(${LIB_NAME} glfw lua::lib)
|
target_link_libraries(${LIB_NAME} glfw lua::lib)
|
||||||
|
|||||||
+6
-15
@@ -1,13 +1,11 @@
|
|||||||
#include "abstractAppState.h"
|
#include "abstractAppState.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "solUtil.h"
|
||||||
#include "mapping.h"
|
#include "mapping.h"
|
||||||
#include "luaManager.h"
|
|
||||||
|
|
||||||
namespace gameBase {
|
namespace gameBase {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef LuaManager::Index Index;
|
|
||||||
|
|
||||||
AbstractAppState::AbstractAppState(int type, int firstMapping, int numMappings, string optionsFile){
|
AbstractAppState::AbstractAppState(int type, int firstMapping, int numMappings, string optionsFile){
|
||||||
this->type = type;
|
this->type = type;
|
||||||
this->firstMapping = firstMapping;
|
this->firstMapping = firstMapping;
|
||||||
@@ -18,22 +16,15 @@ namespace gameBase {
|
|||||||
void AbstractAppState::onAttached(){
|
void AbstractAppState::onAttached(){
|
||||||
attached = true;
|
attached = true;
|
||||||
|
|
||||||
LuaManager *luaManager = LuaManager::getSingleton();
|
SOL_LUA_STATE.script_file(optionsFile);
|
||||||
luaManager->buildScript(vector<string>{optionsFile});
|
|
||||||
string table = "mappings";
|
string table = "mappings";
|
||||||
|
|
||||||
for(int i = firstMapping; i < firstMapping + numMappings; i++){
|
for(int i = firstMapping; i < firstMapping + numMappings; i++){
|
||||||
Index idIndex = Index(i + 1);
|
|
||||||
int bind = luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("bind")});
|
|
||||||
Mapping::BindType type = (Mapping::BindType)luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("bindType")});
|
|
||||||
bool action = luaManager->getBoolFromTable(table, vector<Index>{idIndex, Index("action")});
|
|
||||||
int trigger = luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("trigger")});
|
|
||||||
|
|
||||||
Mapping *m = new Mapping;
|
Mapping *m = new Mapping;
|
||||||
m->bind = bind;
|
m->bind = SOL_LUA_STATE[table][i + 1]["bind"];
|
||||||
m->type = type;
|
m->type = (Mapping::BindType)SOL_LUA_STATE[table][i + 1]["bindType"];
|
||||||
m->action = action;
|
m->action = SOL_LUA_STATE[table][i + 1]["action"];
|
||||||
m->trigger = trigger;
|
m->trigger = SOL_LUA_STATE[table][i + 1]["trigger"];
|
||||||
mappings.push_back(m);
|
mappings.push_back(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef SOL_UTIL_H
|
||||||
|
#define SOL_UTIL_H
|
||||||
|
#define SOL_ALL_SAFETIES_ON 1
|
||||||
|
|
||||||
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
|
namespace gameBase{
|
||||||
|
static sol::state sol, &SOL_LUA_STATE = sol;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user