| 1 | /* |
| 2 | * src/util/reader.cpp - Utility functions for config handling. |
| 3 | * Copyright (C) 2010 Florian Forster |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Authors: |
| 20 | * Florian "octo" Forster <supertux at octo.it> |
| 21 | */ |
| 22 | |
| 23 | #include "util/reader.hpp" |
| 24 | |
| 25 | #include <physfs.h> |
| 26 | |
| 27 | #include "editor/editor.hpp" |
| 28 | #include "util/gettext.hpp" |
| 29 | #include "util/reader_mapping.hpp" |
| 30 | #include "video/drawing_context.hpp" |
| 31 | |
| 32 | int reader_get_layer(const ReaderMapping& reader, int def) |
| 33 | { |
| 34 | int tmp = 0; |
| 35 | bool status; |
| 36 | |
| 37 | // 'z-pos' is the canonical name |
| 38 | status = reader.get("z-pos" , tmp); |
| 39 | |
| 40 | // 'layer' is the old name kept for backward compatibility |
| 41 | if (!status) |
| 42 | status = reader.get("layer" , tmp); |
| 43 | |
| 44 | if (!status) |
| 45 | tmp = def; |
| 46 | |
| 47 | if (!Editor::is_active()) { |
| 48 | if (tmp > (LAYER_GUI - 100)) |
| 49 | tmp = LAYER_GUI - 100; |
| 50 | } |
| 51 | |
| 52 | return (tmp); |
| 53 | } |
| 54 | |
| 55 | namespace { |
| 56 | |
| 57 | std::string dirname(const std::string& filename) |
| 58 | { |
| 59 | std::string::size_type p = filename.find_last_of('/'); |
| 60 | if (p == std::string::npos) { |
| 61 | return {}; |
| 62 | } else { |
| 63 | return filename.substr(0, p); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | } // namespace |
| 68 | |
| 69 | void register_translation_directory(const std::string& filename) |
| 70 | { |
| 71 | if (g_dictionary_manager) { |
| 72 | std::string rel_dir = dirname(filename); |
| 73 | if (rel_dir.empty()) { |
| 74 | // Relative dir inside PhysFS search path? |
| 75 | // Get full path from search path, instead. |
| 76 | const char* rel_dir_c = PHYSFS_getRealDir(filename.c_str()); |
| 77 | if (rel_dir_c) { |
| 78 | rel_dir = rel_dir_c; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (!rel_dir.empty()) { |
| 83 | g_dictionary_manager->add_directory(rel_dir); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /* EOF */ |
| 89 | |