2
0

gamemgr.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --Minetest
  2. --Copyright (C) 2013 sapier
  3. --
  4. --This program is free software; you can redistribute it and/or modify
  5. --it under the terms of the GNU Lesser General Public License as published by
  6. --the Free Software Foundation; either version 2.1 of the License, or
  7. --(at your option) any later version.
  8. --
  9. --This program is distributed in the hope that it will be useful,
  10. --but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. --GNU Lesser General Public License for more details.
  13. --
  14. --You should have received a copy of the GNU Lesser General Public License along
  15. --with this program; if not, write to the Free Software Foundation, Inc.,
  16. --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. gamemgr = {}
  18. --------------------------------------------------------------------------------
  19. function gamemgr.find_by_gameid(gameid)
  20. for i=1,#gamemgr.games,1 do
  21. if gamemgr.games[i].id == gameid then
  22. return gamemgr.games[i], i
  23. end
  24. end
  25. return nil, nil
  26. end
  27. --------------------------------------------------------------------------------
  28. function gamemgr.get_game_mods(gamespec, retval)
  29. if gamespec ~= nil and
  30. gamespec.gamemods_path ~= nil and
  31. gamespec.gamemods_path ~= "" then
  32. get_mods(gamespec.gamemods_path, retval)
  33. end
  34. end
  35. --------------------------------------------------------------------------------
  36. function gamemgr.get_game_modlist(gamespec)
  37. local retval = ""
  38. local game_mods = {}
  39. gamemgr.get_game_mods(gamespec, game_mods)
  40. for i=1,#game_mods,1 do
  41. if retval ~= "" then
  42. retval = retval..","
  43. end
  44. retval = retval .. game_mods[i].name
  45. end
  46. return retval
  47. end
  48. --------------------------------------------------------------------------------
  49. function gamemgr.get_game(index)
  50. if index > 0 and index <= #gamemgr.games then
  51. return gamemgr.games[index]
  52. end
  53. return nil
  54. end
  55. --------------------------------------------------------------------------------
  56. function gamemgr.update_gamelist()
  57. gamemgr.games = core.get_games()
  58. end
  59. --------------------------------------------------------------------------------
  60. function gamemgr.gamelist()
  61. local retval = ""
  62. if #gamemgr.games > 0 then
  63. retval = retval .. core.formspec_escape(gamemgr.games[1].name)
  64. for i=2,#gamemgr.games,1 do
  65. retval = retval .. "," .. core.formspec_escape(gamemgr.games[i].name)
  66. end
  67. end
  68. return retval
  69. end
  70. --------------------------------------------------------------------------------
  71. -- read initial data
  72. --------------------------------------------------------------------------------
  73. gamemgr.update_gamelist()