reader.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "util/reader.hpp"
  23. #include <physfs.h>
  24. #include "editor/editor.hpp"
  25. #include "util/gettext.hpp"
  26. #include "util/reader_mapping.hpp"
  27. #include "video/drawing_context.hpp"
  28. int reader_get_layer(const ReaderMapping& reader, int def)
  29. {
  30. int tmp = 0;
  31. bool status;
  32. // 'z-pos' is the canonical name
  33. status = reader.get("z-pos", tmp);
  34. // 'layer' is the old name kept for backward compatibility
  35. if (!status)
  36. status = reader.get("layer", tmp);
  37. if (!status)
  38. tmp = def;
  39. if (!Editor::is_active()) {
  40. if (tmp > (LAYER_GUI - 100))
  41. tmp = LAYER_GUI - 100;
  42. }
  43. return (tmp);
  44. }
  45. namespace {
  46. std::string dirname(const std::string& filename)
  47. {
  48. std::string::size_type p = filename.find_last_of('/');
  49. if (p == std::string::npos) {
  50. return {};
  51. } else {
  52. return filename.substr(0, p);
  53. }
  54. }
  55. } // namespace
  56. void register_translation_directory(const std::string& filename)
  57. {
  58. if (g_dictionary_manager) {
  59. std::string rel_dir = dirname(filename);
  60. if (rel_dir.empty()) {
  61. // Relative dir inside PhysFS search path?
  62. // Get full path from search path, instead.
  63. const char* rel_dir_c = PHYSFS_getRealDir(filename.c_str());
  64. if (rel_dir_c) {
  65. rel_dir = rel_dir_c;
  66. }
  67. }
  68. if (!rel_dir.empty()) {
  69. g_dictionary_manager->add_directory(rel_dir);
  70. }
  71. }
  72. }
  73. /* EOF */