bool PlatformerObjectBehavior::UpdateProperty(const gd::String& name,
                                              const gd::String& value,
                                              gd::Project& project) {
  if (name == _("Default controls")) ignoreDefaultControls = (value == "0");
  if (name == _("Round coordinates"))
    roundCoordinates = (value == "1");
  else if (name == _("Can grab platform ledges"))
    canGrabPlatforms = (value == "1");
  else if (name == _("Grab offset on Y axis"))
    yGrabOffset = value.To<double>();
  else {
    if (value.To<double>() < 0) return false;

    if (name == _("Gravity"))
      gravity = value.To<double>();
    else if (name == _("Max. falling speed"))
      maxFallingSpeed = value.To<double>();
    else if (name == _("Acceleration"))
      acceleration = value.To<double>();
    else if (name == _("Deceleration"))
      deceleration = value.To<double>();
    else if (name == _("Max. speed"))
      maxSpeed = value.To<double>();
    else if (name == _("Jump speed"))
      jumpSpeed = value.To<double>();
    else if (name == _("Slope max. angle"))
      return SetSlopeMaxAngle(value.To<double>());
    else if (name == _("Grab tolerance on X axis"))
      xGrabTolerance = value.To<double>();
    else
      return false;
  }

  return true;
}
bool PlatformerObjectAutomatism::UpdateProperty(const std::string & name, const std::string & value, gd::Project & project)
{
    if ( name == ToString(_("Default controls")) ) {
        ignoreDefaultControls = (value == "0");
        return true;
    }

    if ( ToDouble(value) < 0 ) return false;

    if ( name == ToString(_("Gravity")) )
        gravity = ToDouble(value);
    else if ( name == ToString(_("Max. falling speed")) )
        maxFallingSpeed = ToDouble(value);
    else if ( name == ToString(_("Acceleration")) )
        acceleration = ToDouble(value);
    else if ( name == ToString(_("Deceleration")) )
        deceleration = ToDouble(value);
    else if ( name == ToString(_("Max. speed")) )
        maxSpeed = ToDouble(value);
    else if ( name == ToString(_("Jump speed")) )
        jumpSpeed = ToDouble(value);
    else if ( name == ToString(_("Slope max. angle")) )
        return SetSlopeMaxAngle(ToDouble(value));
    else
        return false;

    return true;
}
PlatformerObjectAutomatism::PlatformerObjectAutomatism() :
    gravity(1000),
    maxFallingSpeed(700),
    acceleration(1500),
    deceleration(1500),
    maxSpeed(250),
    jumpSpeed(600),
    parentScene(NULL),
    sceneManager(NULL),
    isOnFloor(false),
    isOnLadder(false),
    floorPlatform(NULL),
    currentFallSpeed(0),
    currentSpeed(0),
    jumping(false),
    currentJumpSpeed(0),
    canJump(false),
    hasReallyMoved(false),
    trackSize(true),
    ignoreDefaultControls(false),
    leftKey(false),
    rightKey(false),
    ladderKey(false),
    upKey(false),
    downKey(false),
    jumpKey(false)
{
    SetSlopeMaxAngle(60);
}
void PlatformerObjectAutomatism::UnserializeFrom(const gd::SerializerElement & element)
{
    gravity = element.GetDoubleAttribute("gravity");
    maxFallingSpeed = element.GetDoubleAttribute("maxFallingSpeed");
    acceleration = element.GetDoubleAttribute("acceleration");
    deceleration = element.GetDoubleAttribute("deceleration");
    maxSpeed = element.GetDoubleAttribute("maxSpeed");
    jumpSpeed = element.GetDoubleAttribute("jumpSpeed");
    ignoreDefaultControls = element.GetBoolAttribute("ignoreDefaultControls");
    SetSlopeMaxAngle(element.GetDoubleAttribute("slopeMaxAngle"));
}
void PlatformerObjectBehavior::UnserializeFrom(const gd::SerializerElement & element)
{
    gravity = element.GetDoubleAttribute("gravity");
    maxFallingSpeed = element.GetDoubleAttribute("maxFallingSpeed");
    acceleration = element.GetDoubleAttribute("acceleration");
    deceleration = element.GetDoubleAttribute("deceleration");
    maxSpeed = element.GetDoubleAttribute("maxSpeed");
    jumpSpeed = element.GetDoubleAttribute("jumpSpeed");
    ignoreDefaultControls = element.GetBoolAttribute("ignoreDefaultControls");
    SetSlopeMaxAngle(element.GetDoubleAttribute("slopeMaxAngle"));
    canGrabPlatforms = element.GetBoolAttribute("canGrabPlatforms", false);
    yGrabOffset = element.GetDoubleAttribute("yGrabOffset");
    xGrabTolerance = element.GetDoubleAttribute("xGrabTolerance", 10);
}
PlatformerObjectBehavior::PlatformerObjectBehavior()
    : ignoreTouchingEdges(true),
      roundCoordinates(true),
      gravity(1000),
      maxFallingSpeed(700),
      acceleration(1500),
      deceleration(1500),
      maxSpeed(250),
      jumpSpeed(600),
      canGrabPlatforms(false),
      yGrabOffset(0),
      xGrabTolerance(10),
      parentScene(NULL),
      sceneManager(NULL),
      isOnFloor(false),
      isOnLadder(false),
      floorPlatform(NULL),
      currentFallSpeed(0),
      currentSpeed(0),
      jumping(false),
      currentJumpSpeed(0),
      canJump(false),
      hasReallyMoved(false),
      isGrabbingPlatform(false),
      grabbedPlatform(NULL),
      grabbedPlatformLastX(0),
      grabbedPlatformLastY(0),
      trackSize(true),
      ignoreDefaultControls(false),
      leftKey(false),
      rightKey(false),
      ladderKey(false),
      upKey(false),
      downKey(false),
      jumpKey(false),
      releaseKey(false) {
  SetSlopeMaxAngle(60);
}