Minor changes in file type handling

master
Eduardo Bart 11 years ago
parent 4536c68f00
commit 773837da98

@ -1,22 +1,23 @@
function init()
local styles = g_resources.listDirectoryFiles('/styles')
for _i,style in pairs(styles) do
if string.ends(style, '.otui') then
g_ui.importStyle('/styles/' .. style)
local files
files = g_resources.listDirectoryFiles('/styles')
for _,file in pairs(files) do
if g_resources.isFileType(file, 'otui') then
g_ui.importStyle('/styles/' .. file)
end
end
local fonts = g_resources.listDirectoryFiles('/fonts')
for _i,font in pairs(fonts) do
if string.ends(font, '.otfont') then
g_fonts.importFont('/fonts/' .. font)
files = g_resources.listDirectoryFiles('/fonts')
for _,file in pairs(files) do
if g_resources.isFileType(file, 'otfont') then
g_fonts.importFont('/fonts/' .. file)
end
end
local particles = g_resources.listDirectoryFiles('/particles')
for _i,particle in pairs(particles) do
if string.ends(particle, '.otps') then
g_particles.importParticle('/particles/' .. particle)
files = g_resources.listDirectoryFiles('/particles')
for _,file in pairs(files) do
if g_resources.isFileType(file, 'otps')then
g_particles.importParticle('/particles/' .. file)
end
end

@ -4,7 +4,7 @@ if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
endif(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
# client options
add_definitions(-DOTCLIENT)
add_definitions(-DCLIENT)
option(BOT_PROTECTION "Enable bot protection" ON)
if(BOT_PROTECTION)
add_definitions(-DBOT_PROTECTION)

@ -66,7 +66,7 @@ PainterShaderProgramPtr ShaderManager::createFragmentShader(const std::string& n
if(!shader)
return nullptr;
file = g_resources.guessFileType(file, "frag");
file = g_resources.guessFilePath(file, "frag");
shader->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
if(!shader->addShaderFromSourceFile(Shader::Fragment, file)) {

@ -45,7 +45,7 @@ bool SpriteManager::loadSpr(std::string file)
m_signature = 0;
m_loaded = false;
try {
file = g_resources.guessFileType(file, "spr");
file = g_resources.guessFilePath(file, "spr");
m_spritesFile = g_resources.openFile(file);
// cache file buffer to avoid lags from hard drive

@ -66,7 +66,7 @@ bool ThingTypeManager::loadDat(std::string file)
m_datLoaded = false;
m_datSignature = 0;
try {
file = g_resources.guessFileType(file, "dat");
file = g_resources.guessFilePath(file, "dat");
FileStreamPtr fin = g_resources.openFile(file);
@ -100,7 +100,7 @@ bool ThingTypeManager::loadDat(std::string file)
bool ThingTypeManager::loadOtml(std::string file)
{
try {
file = g_resources.guessFileType(file, "otml");
file = g_resources.guessFilePath(file, "otml");
OTMLDocumentPtr doc = OTMLDocument::parse(file);
for(const OTMLNodePtr& node : doc->children()) {

@ -1,16 +0,0 @@
# Try to find the libgit2 library
# GIT2_FOUND - system has libgit2
# GIT2_INCLUDE_DIR - the libgit2 include directory
# GIT2_LIBRARY - the libgit2 library
FIND_PATH(GIT2_INCLUDE_DIR NAMES git2.h)
SET(_GIT2_STATIC_LIBS libgit2.a)
SET(_GIT2_SHARED_LIBS libgit2.dll.a git2)
IF(USE_STATIC_LIBS)
FIND_LIBRARY(GIT2_LIBRARY NAMES ${_GIT2_STATIC_LIBS} ${_GIT2_SHARED_LIBS})
ELSE()
FIND_LIBRARY(GIT2_LIBRARY NAMES ${_GIT2_SHARED_LIBS} ${_GIT2_STATIC_LIBS})
ENDIF()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GIT2 DEFAULT_MSG GIT2_LIBRARY GIT2_INCLUDE_DIR)
MARK_AS_ADVANCED(GIT2_LIBRARY GIT2_INCLUDE_DIR)

@ -43,7 +43,7 @@ void ModuleManager::discoverModules()
for(const std::string& moduleDir : moduleDirs) {
auto moduleFiles = g_resources.listDirectoryFiles("/" + moduleDir);
for(const std::string& moduleFile : moduleFiles) {
if(stdext::ends_with(moduleFile, ".otmod")) {
if(g_resources.isFileType(moduleFile, "otmod")) {
ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile);
if(module && module->isAutoLoad())
m_autoLoadModules.insert(std::make_pair(module->getAutoLoadPriority(), module));

@ -311,9 +311,16 @@ std::string ResourceManager::getUserDir()
return PHYSFS_getUserDir();
}
std::string ResourceManager::guessFileType(const std::string& filename, const std::string& type)
std::string ResourceManager::guessFilePath(const std::string& filename, const std::string& type)
{
if(g_resources.fileExists(filename))
if(isFileType(filename, type))
return filename;
return filename + "." + type;
}
bool ResourceManager::isFileType(const std::string& filename, const std::string& type)
{
if(stdext::ends_with(filename, std::string(".") + type))
return true;
return false;
}

@ -71,7 +71,8 @@ public:
std::string getWorkDir() { return m_workDir; }
std::deque<std::string> getSearchPaths() { return m_searchPaths; }
std::string guessFileType(const std::string& filename, const std::string& type);
std::string guessFilePath(const std::string& filename, const std::string& type);
bool isFileType(const std::string& filename, const std::string& type);
private:
std::string m_workDir;

@ -48,7 +48,7 @@ void FontManager::clearFonts()
bool FontManager::importFont(std::string file)
{
try {
file = g_resources.guessFileType(file, "otfont");
file = g_resources.guessFilePath(file, "otfont");
OTMLDocumentPtr doc = OTMLDocument::parse(file);
OTMLNodePtr fontNode = doc->at("Font");

@ -39,7 +39,7 @@ ImagePtr Image::load(std::string file)
{
ImagePtr image;
try {
file = g_resources.guessFileType(file, "png");
file = g_resources.guessFilePath(file, "png");
// load image file data
image = loadPNG(file);

@ -29,7 +29,7 @@ ParticleManager g_particles;
bool ParticleManager::importParticle(std::string file)
{
try {
file = g_resources.guessFileType(file, "otps");
file = g_resources.guessFilePath(file, "otps");
OTMLDocumentPtr doc = OTMLDocument::parse(file);
for(const OTMLNodePtr& node : doc->children()) {

@ -78,7 +78,7 @@ TexturePtr TextureManager::getTexture(const std::string& fileName)
// texture not found, load it
if(!texture) {
try {
std::string filePathEx = g_resources.guessFileType(filePath, "png");
std::string filePathEx = g_resources.guessFilePath(filePath, "png");
// load texture file data
std::stringstream fin;

@ -38,7 +38,7 @@ void Mouse::terminate()
void Mouse::loadCursors(std::string filename)
{
filename = g_resources.guessFileType(filename, "otml");
filename = g_resources.guessFilePath(filename, "otml");
try {
OTMLDocumentPtr doc = OTMLDocument::parse(filename);
OTMLNodePtr cursorsNode = doc->at("Cursors");

@ -328,7 +328,7 @@ void LuaInterface::loadScript(const std::string& fileName)
if(!stdext::starts_with(fileName, "/"))
filePath = getCurrentSourcePath() + "/" + filePath;
filePath = g_resources.guessFileType(filePath, "lua");
filePath = g_resources.guessFilePath(filePath, "lua");
std::string buffer = g_resources.readFileContents(filePath);
std::string source = "@" + filePath;
@ -550,7 +550,7 @@ int LuaInterface::luaScriptLoader(lua_State* L)
{
// loads the script as a function
std::string fileName = g_lua.popString();
fileName += ".lua";
try {
g_lua.loadScript(fileName);
return 1;
@ -580,7 +580,7 @@ int LuaInterface::lua_dofiles(lua_State* L)
std::string directory = g_lua.popString();
for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
if(!stdext::ends_with(fileName, ".lua") && !stdext::ends_with(fileName, ".bc"))
if(!g_resources.isFileType(fileName, "lua"))
continue;
try {
@ -597,8 +597,6 @@ int LuaInterface::lua_dofiles(lua_State* L)
int LuaInterface::lua_loadfile(lua_State* L)
{
std::string fileName = g_lua.popString();
if(!stdext::ends_with(fileName, ".lua"))
fileName += ".lua";
try {
g_lua.loadScript(fileName);

@ -184,6 +184,8 @@ void Application::registerLuaFunctions()
g_lua.bindSingletonFunction("g_resources", "getSearchPaths", &ResourceManager::getSearchPaths, &g_resources);
g_lua.bindSingletonFunction("g_resources", "listDirectoryFiles", &ResourceManager::listDirectoryFiles, &g_resources);
g_lua.bindSingletonFunction("g_resources", "readFileContents", &ResourceManager::readFileContents, &g_resources);
g_lua.bindSingletonFunction("g_resources", "guessFilePath", &ResourceManager::guessFilePath, &g_resources);
g_lua.bindSingletonFunction("g_resources", "isFileType", &ResourceManager::isFileType, &g_resources);
// Module
g_lua.registerClass<Module>();

@ -252,7 +252,7 @@ SoundSourcePtr SoundManager::createSoundSource(const std::string& filename)
std::string SoundManager::resolveSoundFile(std::string file)
{
file = g_resources.guessFileType(file, "ogg");
file = g_resources.guessFilePath(file, "ogg");
file = g_resources.resolvePath(file);
return file;
}

@ -311,7 +311,7 @@ void UIManager::clearStyles()
bool UIManager::importStyle(std::string file)
{
try {
file = g_resources.guessFileType(file, "otui");
file = g_resources.guessFilePath(file, "otui");
OTMLDocumentPtr doc = OTMLDocument::parse(file);
@ -394,7 +394,7 @@ std::string UIManager::getStyleClass(const std::string& styleName)
UIWidgetPtr UIManager::loadUI(std::string file, const UIWidgetPtr& parent)
{
try {
file = g_resources.guessFileType(file, "otui");
file = g_resources.guessFilePath(file, "otui");
OTMLDocumentPtr doc = OTMLDocument::parse(file);
UIWidgetPtr widget;

Loading…
Cancel
Save