#include "defines.hpp"

#include "playstate.hpp"

#include "decoration.hpp"

//using namespace gaia;

Decoration::Decoration(const PlayState *playState, const std::string &filename, e_FilterMode filterMode, const Vector2 &position, float zPosition, float height) : PhysicsObject() {

  this->position = position;
  this->zPosition = zPosition;
  this->height = height;

  sprite = new Sprite();
  sprite->LoadFile(filename, filterMode);
  unsigned int w, h;
  sprite->GetResolution(w, h);

  object = new Object(&playState->GetWorldNode(), sprite);
  //object->spatial.position = position - zPosition;
  object->spatial.orientation = playState->GetViewOrientation();
  object->spatial.scale = Vector2(w / (float)_PIXELSPERMETER, h / (float)_PIXELSPERMETER);
  //object->spatial.scale *= 1.414f;
  object->spatial.scale *= pow(2.0f, 0.5f);
  object->spatial.scale *= 1.005f; // fixes edge artifacts
  object->spatial.z = 0.0f;

}

Decoration::~Decoration() {
  delete object;
  delete sprite;
}

void Decoration::GetSpriteBounds(Vector2 &center, Vector2 &radius) const {
  center = object->spatial.position;
  radius = object->spatial.scale * 0.5;
}

void Decoration::OnStepPhysicsTime() {
  object->spatial.position = GetPosition() - GetZPosition();
}
/*
void Decoration::PostStepPhysicsTime() {
  object->spatial.position = GetPosition() - GetZPosition();
}
*/
void Decoration::Draw(const Viewport &viewport, const Camera &camera) const {
  //object->spatial.position = position - zPosition;
  object->Draw(viewport, camera);
}
