diff options
author | krzys-h <krzys_h@interia.pl> | 2014-10-27 21:15:14 +0100 |
---|---|---|
committer | krzys-h <krzys_h@interia.pl> | 2014-10-27 21:15:14 +0100 |
commit | d6e88a07b08585d6a6f151d34a07d8bca78711ea (patch) | |
tree | 1c3f385d0883ef3db787d91e6f11edd8323ebc03 /src | |
parent | 990ecf729038baa995fd7d58d17aceecce343d4b (diff) | |
download | colobot-d6e88a07b08585d6a6f151d34a07d8bca78711ea.tar.gz colobot-d6e88a07b08585d6a6f151d34a07d8bca78711ea.tar.bz2 colobot-d6e88a07b08585d6a6f151d34a07d8bca78711ea.zip |
Support for %lvl% in TerrainInitTextures + cleanup
cleanup:
* Removed CProfile::SetUserPath (unused)
* Removed CProfile::GetUserBasedPath (unused)
* Removed CProfile::CopyFileToTemp (i have no idea why it even existed)
* Removed CopyFileListToTemp (it did the same as CopyFileToTemp but for multiple files, wasn't even fully implemented)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/misc.cpp | 38 | ||||
-rw-r--r-- | src/common/misc.h | 1 | ||||
-rw-r--r-- | src/common/profile.cpp | 49 | ||||
-rw-r--r-- | src/common/profile.h | 20 | ||||
-rw-r--r-- | src/graphics/engine/terrain.cpp | 3 | ||||
-rw-r--r-- | src/object/robotmain.cpp | 13 |
6 files changed, 3 insertions, 121 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 1cbd3b1..4954fc0 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -232,44 +232,6 @@ void TimeToAsciiClean(time_t time, char *buffer) when.tm_hour, when.tm_min); } -// Copy a list of numbered files into the temporary folder. - -bool CopyFileListToTemp(char* filename, int* list, int total) -{ - /*char name[100]; - char ext[10]; - char file[100]; - char save[100]; - char* p; - int i; - - strcpy(name, filename); - p = strchr(name, '.'); - if ( p == 0 ) - { - strcpy(ext, ".tga"); - } - else - { - strcpy(ext, p); - *p = 0; - } - - for ( i=0 ; i<total ; i++ ) - { - sprintf(file, "%s%.3d%s", name, list[i], ext); // nameNNN.ext - CopyFileToTemp(file); - } - - strcpy(save, g_userDir); - strcpy(g_userDir, "temp"); - UserDir(file, filename, "textures"); - strcpy(filename, file); - strcpy(g_userDir, save); -*/ - return false; -} - // Adds an extension to file, if doesn't already one. diff --git a/src/common/misc.h b/src/common/misc.h index a079ba6..4b75ae3 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -33,6 +33,5 @@ extern char GetToLower(char letter); extern void TimeToAscii(time_t time, char *buffer); extern void TimeToAsciiClean(time_t time, char *buffer); -extern bool CopyFileListToTemp(char* filename, int* list, int total); extern void AddExt(char* filename, const char* ext); diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 92fc1d6..75ab135 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -247,52 +247,3 @@ std::vector< std::string > CProfile::GetSection(std::string section, std::string return ret_list; } - -void CProfile::SetUserDir(std::string dir) -{ - m_userDirectory = dir; -} - - -std::string CProfile::GetUserBasedPath(std::string dir, std::string defaultDir) -{ - std::string path = dir; - boost::replace_all(path, "\\", "/"); - if (dir.find("/") == std::string::npos) - { - path = defaultDir + "/" + dir; - } - - if (m_userDirectory.length() > 0) - { - boost::replace_all(path, "%user%", m_userDirectory); - } - else - { - boost::replace_all(path, "%user%", defaultDir); - } - - return fs::path(path).make_preferred().string(); -} - - -bool CProfile::CopyFileToTemp(std::string filename) -{ - std::string src, dst; - std::string tmp_user_dir = m_userDirectory; - - src = GetUserBasedPath(filename, "textures"); - SetUserDir("temp"); - dst = GetUserBasedPath(filename, "textures"); - SetUserDir(tmp_user_dir); - - fs::create_directory(fs::path(dst).parent_path().make_preferred().string()); - fs::copy_file(src, dst, fs::copy_option::overwrite_if_exists); - if (fs::exists(dst)) - { - return true; - } - - return false; -} - diff --git a/src/common/profile.h b/src/common/profile.h index 444975c..d89c5d1 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -116,29 +116,9 @@ public: */ std::vector< std::string > GetSection(std::string section, std::string key); - /** Sets current user directory - * \param dir - */ - void SetUserDir(std::string dir); - - /** Returns path based on current user. Replaces %user% in path with current user dir or - * uses default_dir param if no user dir is specified - * \param dir - * \param default_dir - * \return path - */ - std::string GetUserBasedPath(std::string dir, std::string defaultDir); - - /** Copy a file into the temporary folder. - * \param filename - * \return true on success - */ - bool CopyFileToTemp(std::string filename); - private: boost::property_tree::ptree m_propertyTree; bool m_profileNeedSave; - std::string m_userDirectory; bool m_useCurrentDirectory; }; diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 21d7446..b58685b 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -123,7 +123,8 @@ bool CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int m_useMaterials = false; m_texBaseName = baseName; - size_t pos = baseName.find('.'); + size_t pos = baseName.rfind('.'); + if(pos < baseName.find_last_of('/')) pos = std::string::npos; // If last . is not a part of filename (some directory, possibly . or ..) if (pos == std::string::npos) { diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 62176a1..012b08a 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4123,7 +4123,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "TerrainInitTextures" && !resetObject) { - std::string name = line->GetParam("image")->AsPath(""); //TODO: don't make this relative to textures/ + std::string name = "../"+line->GetParam("image")->AsPath("textures"); if(name.find(".") == std::string::npos) name += ".png"; unsigned int dx = line->GetParam("dx")->AsInt(1); @@ -4154,11 +4154,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } } - /*TODO: ??? - if (strstr(name, "%user%") != 0) - CopyFileListToTemp(name, tt, dx*dy); - */ - m_terrain->InitTextures(name.c_str(), tt, dx, dy); continue; } @@ -4175,12 +4170,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if(name.find(".") == std::string::npos) name += ".png"; name = "../"+name; - /*TODO: ??? - if (strstr(name, "%user%") != 0) - { - GetProfile().CopyFileToTemp(std::string(name)); - } - */ m_terrain->AddMaterial(line->GetParam("id")->AsInt(0), name.c_str(), |