Class BaseModule

java.lang.Object
gaiasky.script.v2.impl.APIModule
gaiasky.script.v2.impl.BaseModule
All Implemented Interfaces:
BaseAPI

public class BaseModule extends APIModule implements BaseAPI
The base module contains methods and calls that are of global nature.
  • Constructor Details

    • BaseModule

      public BaseModule(EventManager em, APIv2 api, String name)
      Create a new module with the given attributes.
      Parameters:
      em - Reference to the event manager.
      api - Reference to the API class.
      name - Name of the module.
  • Method Details

    • get_version

      public String get_version()
      Description copied from interface: BaseAPI
      Return a string with the version number, the build string, the system, the builder, and the build time.
      Specified by:
      get_version in interface BaseAPI
      Returns:
      A string with the full version information.
    • get_version_number

      public String get_version_number()
      Description copied from interface: BaseAPI
      Return the version number string.
      Specified by:
      get_version_number in interface BaseAPI
      Returns:
      The version number string.
    • get_build_string

      public String get_build_string()
      Description copied from interface: BaseAPI
      Return the build string.
      Specified by:
      get_build_string in interface BaseAPI
      Returns:
      The build string.
    • get_assets_dir

      public String get_assets_dir()
      Description copied from interface: BaseAPI
      Gets the location of the asset directory. The asset directory contains some internal files essential for Gaia Sky to function properly, like the default versions of the configuration file, or the UI theme files.

      This location depends on the operating system and launch method.

      Specified by:
      get_assets_dir in interface BaseAPI
    • get_default_frame_output_dir

      public String get_default_frame_output_dir()
      Description copied from interface: BaseAPI
      Get the absolute path of the default output directory for the frame output system. This may be different from where the actual frames are saved, as this is specified in a setting in the configuration file.

      In order to get the actual current output location for the frame output system, use OutputModule.get_current_frame_output_dir().

      Specified by:
      get_default_frame_output_dir in interface BaseAPI
      Returns:
      Absolute path of directory where still frames are saved.
    • get_default_screenshots_dir

      public String get_default_screenshots_dir()
      Description copied from interface: BaseAPI
      Get the absolute path of the default directory where the screenshots are saved. This may be different from where the actual screenshots are saved, as this is specified in a setting in the configuration file.

      In order to get the actual current output location for screenshots, use OutputModule.get_current_screenshots_dir().

      Specified by:
      get_default_screenshots_dir in interface BaseAPI
      Returns:
      Absolute path of directory where screenshots are saved.
    • get_camcorder_dir

      public String get_camcorder_dir()
      Description copied from interface: BaseAPI
      Get the absolute path of the default directory where the camcorder files are saved.
      Specified by:
      get_camcorder_dir in interface BaseAPI
      Returns:
      Absolute path of directory where camcorder files are saved.
    • get_mappings_dir

      public String get_mappings_dir()
      Description copied from interface: BaseAPI
      Get the absolute path to the location of the inputListener mappings.
      Specified by:
      get_mappings_dir in interface BaseAPI
      Returns:
      Absolute path to the location of the inputListener mappings.
    • get_data_dir

      public String get_data_dir()
      Description copied from interface: BaseAPI
      Get the absolute path of the local data directory, configured in your config.yaml file.
      Specified by:
      get_data_dir in interface BaseAPI
      Returns:
      Absolute path to the location of the data files.
    • get_config_dir

      public String get_config_dir()
      Description copied from interface: BaseAPI
      Get the absolute path to the location of the configuration directory.
      Specified by:
      get_config_dir in interface BaseAPI
      Returns:
      Absolute path of config directory.
    • get_default_datasets_dir

      public String get_default_datasets_dir()
      Description copied from interface: BaseAPI
      Get the absolute path to the default datasets directory. This is ~/.gaiasky/ in Windows and macOS, and ~/.local/share/gaiasky in Linux.

      Note that the actual datasets directory may be different, as it is stored in a setting in the configuration file. This only returns the default location. You can get the actual location where datasets are stored with DataModule.get_datasets_directory().

      Specified by:
      get_default_datasets_dir in interface BaseAPI
      Returns:
      Absolute path to the default data directory.
    • sleep

      public void sleep(float value)
      Description copied from interface: BaseAPI
      Sleep for the given number of seconds in the application time (FPS), so if we are capturing frames and the frame rate is set to 30 FPS, the command sleep(1) will put the script to sleep for 30 frames.
      Specified by:
      sleep in interface BaseAPI
      Parameters:
      value - The number of seconds to wait.
    • sleep

      public void sleep(int seconds)
      Alias to sleep(float), but using an int parameter type instead of a float.
    • sleep_frames

      public void sleep_frames(long frames)
      Description copied from interface: BaseAPI
      Sleep for a number of frames. The frame monitor is notified at the beginning of each frame, before the update-render cycle. When frames is 1, this method returns just before the processing of the next frame starts.
      Specified by:
      sleep_frames in interface BaseAPI
      Parameters:
      frames - The number of frames to wait.
    • post_runnable

      public void post_runnable(Runnable r)
      Description copied from interface: BaseAPI
      Post a Runnable to the main loop thread. This Runnable runs once after the update-scene stage, and before the render stage.
      Specified by:
      post_runnable in interface BaseAPI
      Parameters:
      r - The runnable to run.
    • park_scene_runnable

      public void park_scene_runnable(String id, Runnable r)
      Description copied from interface: BaseAPI

      Park an update Runnable to the main loop thread, and keeps it running every frame until it finishes, or it is removed by BaseAPI.remove_runnable(String). This object runs after the update-scene stage and before the render stage, so it is intended for updating scene objects.

      Be careful with this function, as it probably needs a cleanup before the script is finished. Otherwise, all parked runnables will keep running until Gaia Sky is restarted, so make sure to remove them with BaseAPI.remove_runnable(String) if needed.

      Specified by:
      park_scene_runnable in interface BaseAPI
      Parameters:
      id - The string id to identify the runnable.
      r - The scene update runnable to park.
    • park_runnable

      public void park_runnable(String id, Runnable runnable)
    • park_camera_runnable

      public void park_camera_runnable(String id, Runnable r)
      Description copied from interface: BaseAPI

      Park a camera update Runnable to the main loop thread, and keeps it running every frame until it finishes, or it is removed by BaseAPI.remove_runnable(String). This object runs after the update-camera stage and before the update-scene, so it is intended for updating the camera only.

      Be careful with this function, as it probably needs a cleanup before the script is finished. Otherwise, all parked runnables will keep running until Gaia Sky is restarted, so make sure to remove them with BaseAPI.remove_runnable(String) if needed.

      Specified by:
      park_camera_runnable in interface BaseAPI
      Parameters:
      id - The string id to identify the runnable.
      r - The camera update runnable to park.
    • remove_runnable

      public void remove_runnable(String id)
      Description copied from interface: BaseAPI
      Remove the runnable with the given id, if any. Use this method to remove previously parked scene and camera runnables.
      Specified by:
      remove_runnable in interface BaseAPI
      Parameters:
      id - The id of the runnable to remove.
    • settings_backup

      public void settings_backup()
      Description copied from interface: BaseAPI

      Create a backup of the current settings state that can be restored later on. The settings are backed up in a stack, so multiple calls to this method put different copies of the settings on the stack in a LIFO fashion.

      This method, together with BaseAPI.settings_restore(), are useful to back up and restore the settings at the beginning and end of your scripts, respectively, and ensure that the user settings are left unmodified after your script ends.

      Specified by:
      settings_backup in interface BaseAPI
    • settings_restore

      public boolean settings_restore()
      Description copied from interface: BaseAPI

      Take the settings object at the top of the settings stack and makes it effective.

      This method, together with BaseAPI.settings_backup(), are useful to back up and restore the settings at the beginning and end of your scripts, respectively, and ensure that the user settings are left unmodified after your script ends.

      WARN: This function applies all settings immediately, and the user interface may be re-initialized. Be aware that the UI may be set to its default state after this call.

      Specified by:
      settings_restore in interface BaseAPI
      Returns:
      True if the stack was not empty and the settings were restored successfully. False otherwise.
    • settings_clear_stack

      public void settings_clear_stack()
      Description copied from interface: BaseAPI
      Clear the stack of settings objects. This will invalidate all previous calls to BaseAPI.settings_backup(), effectively making the settings stack empty. Calling BaseAPI.settings_restore() after this method will return false.
      Specified by:
      settings_clear_stack in interface BaseAPI
    • m_to_internal

      public double m_to_internal()
      Description copied from interface: BaseAPI
      Returns the meter to internal unit conversion factor. Use this factor to multiply your coordinates in meters to get them in internal units.
      Specified by:
      m_to_internal in interface BaseAPI
      Returns:
      The factor Constants.M_TO_U.
    • internal_to_m

      public double internal_to_m()
      Description copied from interface: BaseAPI
      Returns the internal unit to meter conversion factor. Use this factor to multiply your coordinates in internal units to get them in meters.
      Specified by:
      internal_to_m in interface BaseAPI
      Returns:
      The factor Constants.U_TO_M.
    • internal_to_m

      public double internal_to_m(double iu)
      Description copied from interface: BaseAPI
      Converts the value in internal units to metres.
      Specified by:
      internal_to_m in interface BaseAPI
      Parameters:
      iu - The value in internal units.
      Returns:
      The value in metres.
    • internal_to_km

      public double internal_to_km(double iu)
      Description copied from interface: BaseAPI
      Converts the value in internal units to Kilometers.
      Specified by:
      internal_to_km in interface BaseAPI
      Parameters:
      iu - The value in internal units.
      Returns:
      The value in Kilometers.
    • internal_to_km

      public double[] internal_to_km(double[] iu)
      Description copied from interface: BaseAPI
      Converts the array in internal units to Kilometers.
      Specified by:
      internal_to_km in interface BaseAPI
      Parameters:
      iu - The array in internal units.
      Returns:
      The array in Kilometers.
    • internal_to_pc

      public double internal_to_pc(double iu)
      Description copied from interface: BaseAPI
      Converts the value in internal units to parsecs.
      Specified by:
      internal_to_pc in interface BaseAPI
      Parameters:
      iu - The value in internal units.
      Returns:
      The value in parsecs.
    • internal_to_pc

      public double[] internal_to_pc(double[] iu)
      Description copied from interface: BaseAPI
      Converts the array in internal units to parsecs.
      Specified by:
      internal_to_pc in interface BaseAPI
      Parameters:
      iu - The array in internal units.
      Returns:
      The array in parsecs.
    • internal_to_km

      public double[] internal_to_km(List<?> internalUnits)
    • m_to_internal

      public double m_to_internal(double m)
      Description copied from interface: BaseAPI
      Converts the metres to internal units.
      Specified by:
      m_to_internal in interface BaseAPI
      Parameters:
      m - The value in metres.
      Returns:
      The value in internal units.
    • km_to_internal

      public double km_to_internal(double km)
      Description copied from interface: BaseAPI
      Converts the kilometres to internal units.
      Specified by:
      km_to_internal in interface BaseAPI
      Parameters:
      km - The value in kilometers.
      Returns:
      The value in internal units.
    • pc_to_internal

      public double pc_to_internal(double pc)
      Description copied from interface: BaseAPI
      Converts the parsecs to internal units.
      Specified by:
      pc_to_internal in interface BaseAPI
      Parameters:
      pc - The value in parsecs.
      Returns:
      The value in internal units.
    • kilometersToInternalUnits

      public double kilometersToInternalUnits(double kilometres)
    • print

      public void print(String msg)
      Description copied from interface: BaseAPI
      Print text using the internal logging system.
      Specified by:
      print in interface BaseAPI
      Parameters:
      msg - The message.
    • log

      public void log(String msg)
      Description copied from interface: BaseAPI
      Print text using the internal logging system.
      Specified by:
      log in interface BaseAPI
      Parameters:
      msg - The message.
    • error

      public void error(String msg)
      Description copied from interface: BaseAPI
      Log an error using the internal logging system.
      Specified by:
      error in interface BaseAPI
      Parameters:
      msg - The error message.
    • quit

      public void quit()
      Description copied from interface: BaseAPI
      Initiate the quit action to terminate the program. This call causes Gaia Sky to exit.
      Specified by:
      quit in interface BaseAPI