class 'scene_morf_object_effect' (Script)

function scene_morf_object_effect:__init() super()
  self.renderable = nil
  self.use_morf = nil
  self.hide_controller = nil
  self.prev_wide_screen_mode = wide_screen_mode()
end

function scene_morf_object_effect:on_attach()
  self.use_morf = self:scene():object('use_morf')

  if(self.use_morf == nil or not self.use_morf:visible()) then
    self:remove()
    return
  end

  self.prev_wide_screen_mode = wide_screen_mode()

  if(self.renderable == nil) then
    self.renderable = self:add_morf_renderable()
  end
end

function scene_morf_object_effect:on_update()
  self.use_morf = self:scene():object('use_morf') -- ???

  if((self.use_morf == nil or not self.use_morf:visible()) and self.hide_controller == nil) then
    self.hide_controller = self:create_controller(self.renderable)
    self.hide_controller:alpha(0, 1)
  end

  if(self.hide_controller ~= nil and self.hide_controller:time() >= self.hide_controller:total_time()) then
    self:remove_all()
    return
  end

  if(self.prev_wide_screen_mode ~= wide_screen_mode()) then
    self.prev_wide_screen_mode = wide_screen_mode()

    if(self.hide_controller ~= nil) then
      self:remove_all()
      return
    end

    self.renderable:remove()
    self.renderable = self:add_morf_renderable()
  end
end

function scene_morf_object_effect:remove_all()
  self.hide_controller:remove()
  self.renderable:remove()
  self:remove()
end

function scene_morf_object_effect:add_morf_renderable()
  local renderable = self:add_game_renderable(self:morf_renderable_id())
  if(not wide_screen_mode()) then
    renderable:set_position(Position(0, 0) + wide_screen_offset())
  end
  return renderable
end

function scene_morf_object_effect:morf_renderable_id()
  if(wide_screen_mode()) then
    return 'game/scene_morf_effect_wide'
  else
    return 'game/scene_morf_effect'
  end
end