sector_base.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SuperTux
  2. // Copyright (C) 2023 Vankata453
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 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 General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "supertux/sector_base.hpp"
  17. #include "util/log.hpp"
  18. namespace Base {
  19. Sector::Sector(const std::string& type) :
  20. m_name(),
  21. m_init_script(),
  22. m_squirrel_environment(new SquirrelEnvironment(SquirrelVirtualMachine::current()->get_vm(), type))
  23. {
  24. }
  25. void
  26. Sector::finish_construction(bool)
  27. {
  28. for (auto& object : get_objects())
  29. object->finish_construction();
  30. }
  31. void
  32. Sector::run_script(const std::string& script, const std::string& sourcename)
  33. {
  34. m_squirrel_environment->run_script(script, sourcename);
  35. }
  36. bool
  37. Sector::before_object_add(GameObject& object)
  38. {
  39. m_squirrel_environment->try_expose(object);
  40. return true;
  41. }
  42. void
  43. Sector::before_object_remove(GameObject& object)
  44. {
  45. m_squirrel_environment->try_unexpose(object);
  46. }
  47. } // namespace Base
  48. /* EOF */