Fixed CPack and made lua work from .pack file
Adds a custom searcher to the lua table package.searcher.
This commit is contained in:
parent
e161d6becb
commit
22bed2948f
|
@ -2,6 +2,7 @@
|
|||
/*.dll
|
||||
/tags
|
||||
/assets.pack
|
||||
/data.pack
|
||||
/.vs/
|
||||
*.swp
|
||||
*~
|
||||
|
|
|
@ -123,6 +123,15 @@ if (NOT WIN32)
|
|||
)
|
||||
endif (NOT WIN32)
|
||||
|
||||
if (WIN32)
|
||||
set_target_properties(breakhack PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
|
||||
set_target_properties(breakhack PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
|
||||
set_target_properties(breakhack PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
|
||||
set_target_properties(breakhack PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
|
||||
set_target_properties(breakhack PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")
|
||||
set_target_properties(breakhack PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS")
|
||||
endif (WIN32)
|
||||
|
||||
# TESTS:
|
||||
IF (CHECK_FOUND AND NOT WIN32)
|
||||
find_package(Threads REQUIRED)
|
||||
|
@ -153,6 +162,17 @@ if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
|||
)
|
||||
endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
add_custom_target(data_pack ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E tar "-cf" "../data.pack" "--format=zip" --
|
||||
"mapgen.lua"
|
||||
"maproombuilder.lua"
|
||||
"menumapgen.lua"
|
||||
"monstergen.lua"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
)
|
||||
endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
|
||||
if (WIN32)
|
||||
set(DLL_FILES
|
||||
${CMAKE_SOURCE_DIR}/bin/libFLAC-8.dll
|
||||
|
@ -173,6 +193,22 @@ if (WIN32)
|
|||
endif (WIN32)
|
||||
|
||||
include(InstallRequiredSystemLibraries)
|
||||
INSTALL(TARGETS breakhack
|
||||
COMPONENT Release
|
||||
RUNTIME DESTINATION .
|
||||
)
|
||||
INSTALL(FILES assets.pack data.pack
|
||||
COMPONENT Release
|
||||
DESTINATION .
|
||||
)
|
||||
if (WIN32)
|
||||
INSTALL(FILES ${DLL_FILES}
|
||||
COMPONENT Release
|
||||
DESTINATION .
|
||||
)
|
||||
endif (WIN32)
|
||||
|
||||
set(CPACK_INSTALL_CMAKE_PROJECTS "${PROJECT_BINARY_DIR};breakhack;Release;.")
|
||||
set(CPACK_PACKAGE_NAME "BreakHack")
|
||||
set(CPACK_PACKAGE_VENDOR "OliveShark")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
||||
|
@ -184,26 +220,10 @@ set(CPACK_PACKAGE_VERSION_PATCH "1")
|
|||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "BreakHack")
|
||||
set(CPACK_PACKAGE_FILE_NAME "breakhack-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||
set(CPACK_PACKAGE_CHECKSUM "MD5")
|
||||
set(CPACK_INSTALL_CMAKE_PROJECTS ${PROJECT_BINARY_DIR} breakhack Release package)
|
||||
|
||||
if(UNIX)
|
||||
set(CPACK_STRIP_FILES breakhack)
|
||||
set(CPACK_SOURCE_STRIP_FILES "")
|
||||
endif(UNIX)
|
||||
set(CPACK_PACKAGE_EXECUTABLES breakhack "BreakHack")
|
||||
include(CPack)
|
||||
|
||||
INSTALL(TARGETS breakhack
|
||||
COMPONENT Release
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
INSTALL(FILES assets.pack
|
||||
COMPONENT Release
|
||||
DESTINATION bin
|
||||
)
|
||||
INSTALL(DIRECTORY data
|
||||
COMPONENT Release
|
||||
DESTINATION bin
|
||||
)
|
||||
if (WIN32)
|
||||
INSTALL(FILES ${DLL_FILES} DESTINATION bin)
|
||||
endif (WIN32)
|
||||
include(CPack)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local room_builder = require "data/maproombuilder"
|
||||
local monster_gen = require "data/monstergen"
|
||||
local room_builder = require "maproombuilder"
|
||||
local monster_gen = require "monstergen"
|
||||
|
||||
-- Setting up some functions
|
||||
local time = os.time
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local room_builder = require "data/maproombuilder"
|
||||
local monster_gen = require "data/monstergen"
|
||||
local room_builder = require "maproombuilder"
|
||||
local monster_gen = require "monstergen"
|
||||
|
||||
map = create_map(CURRENT_LEVEL) -- 'map' needs to be global
|
||||
|
||||
|
|
|
@ -632,10 +632,11 @@ int main(int argc, char *argv[])
|
|||
PHYSFS_init(argv[0]);
|
||||
#ifndef DEBUG
|
||||
PHYSFS_mount("assets.pack", NULL, 0);
|
||||
PHYSFS_mount("data.pack", NULL, 0);
|
||||
#else
|
||||
PHYSFS_mount("assets", NULL, 0);
|
||||
#endif // DEBUG
|
||||
PHYSFS_mount("data", NULL, 0);
|
||||
#endif // DEBUG
|
||||
|
||||
if (!init())
|
||||
return 1;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include <physfs.h>
|
||||
|
||||
#include "map_lua.h"
|
||||
#include "util.h"
|
||||
#include "stats.h"
|
||||
|
@ -52,7 +54,7 @@ static int
|
|||
l_print_info(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
info(str);
|
||||
debug(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -173,7 +175,7 @@ static Stats
|
|||
lua_checkstats(lua_State *L, int index)
|
||||
{
|
||||
// Confirm table
|
||||
luaL_checktype(L, index, LUA_TTABLE);
|
||||
lua_istable(L, index);
|
||||
|
||||
// Push to top of stack
|
||||
lua_pushvalue(L, index);
|
||||
|
@ -310,12 +312,38 @@ l_add_monster(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
l_load_script(lua_State *L)
|
||||
{
|
||||
unsigned long size;
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
char *content;
|
||||
|
||||
char filename[20];
|
||||
|
||||
m_sprintf(filename, 20, "%s.lua", name);
|
||||
|
||||
if (!PHYSFS_exists(filename)) {
|
||||
luaL_error(L, "Unable to locate module: %s\n", name);
|
||||
return 1; // Unable to locate file
|
||||
}
|
||||
debug("Loading module: %s from %s", name, filename);
|
||||
|
||||
io_load_lua_buffer(&content, &size, filename);
|
||||
if (luaL_loadbuffer(L, content, size, name) != 0) {
|
||||
luaL_error(L, "Error loading module %s from file %s\n\t%s", lua_tostring(L, 1), filename, lua_tostring(L, -1));
|
||||
}
|
||||
free(content);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Map*
|
||||
generate_map(unsigned int level, const char *file, SDL_Renderer *renderer)
|
||||
{
|
||||
int status, result;
|
||||
|
||||
info("Running lua map script: %s", file);
|
||||
debug("Running lua map script: %s", file);
|
||||
|
||||
lua_State *L = load_lua_state();
|
||||
|
||||
|
@ -360,6 +388,13 @@ generate_map(unsigned int level, const char *file, SDL_Renderer *renderer)
|
|||
lua_pushinteger(L, level);
|
||||
lua_setglobal(L, "CURRENT_LEVEL");
|
||||
|
||||
// Add custom searcher
|
||||
lua_getglobal(L, "package");
|
||||
lua_getfield(L, -1, "searchers");
|
||||
lua_pushcfunction(L, l_load_script);
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_pop(L, 2);
|
||||
|
||||
result = lua_pcall(L, 0, LUA_MULTRET, 0);
|
||||
if (result) {
|
||||
fatal("Failed to run script: %s\n", lua_tostring(L, -1));
|
||||
|
@ -373,7 +408,7 @@ generate_map(unsigned int level, const char *file, SDL_Renderer *renderer)
|
|||
// Reset the map
|
||||
map->currentRoom = (Position) { 0, 0 };
|
||||
|
||||
info("Done");
|
||||
debug("Done");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue