{"size": 905, "ext": "js", "max_stars_repo_path": "ozaria/engine/cinematic/CameraSystem.js", "max_stars_repo_name": "shfm1969/codecombat", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ozaria/engine/cinematic/CameraSystem.js", "max_issues_repo_name": "shfm1969/codecombat", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ozaria/engine/cinematic/CameraSystem.js", "max_forks_repo_name": "shfm1969/codecombat", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.4242424242, "max_line_length": 95, "alphanum_fraction": 0.6497237569}
import { getCamera, CAMERA_DEFAULT } from '../../../app/schemas/models/selectors/cinematic'
import { SyncFunction } from './commands/commands'

/**
 * Thin wrapper on the camera to provide additional command methods.
 */
export class CameraSystem {
  constructor (camera) {
    this.camera = camera

    camera.zoomTo({ x: CAMERA_DEFAULT.pos.x, y: CAMERA_DEFAULT.pos.y }, CAMERA_DEFAULT.zoom, 0)
  }

  /**
   * May return command to reposition camera.
   * @param {Shot} shot - the cinematic shot data.
   * @returns {AbstractCommand[]} An array of commands to setup the shot.
   */
  parseSetupShot (shot) {
    const commands = []
    const cameraMove = getCamera(shot)
    if (cameraMove) {
      const { pos: { x, y }, zoom } = cameraMove
      commands.push(new SyncFunction(() => this.camera.zoomTo({ x, y }, zoom, 0)))
    }
    return commands
  }

  destroy () {
    this.camera.destroy()
  }
}
