Skip to content

Commit

Permalink
Move some direction functions from scripting class to game object class
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Dec 29, 2023
1 parent daddb62 commit 743714b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
60 changes: 43 additions & 17 deletions src/object/gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,11 @@ Gradient::Gradient(const ReaderMapping& reader) :
std::string direction;
if (reader.get("direction", direction))
{
if (direction == "horizontal")
{
m_gradient_direction = HORIZONTAL;
}
else if (direction == "horizontal_sector")
{
m_gradient_direction = HORIZONTAL_SECTOR;
}
else if (direction == "vertical_sector")
{
m_gradient_direction = VERTICAL_SECTOR;
}
else
{
m_gradient_direction = VERTICAL;
}
set_direction(direction);
}
else
{
m_gradient_direction = VERTICAL;
set_direction(VERTICAL);
}

if (reader.get("top_color", bkgd_top_color)) {
Expand Down Expand Up @@ -209,12 +194,53 @@ Gradient::fade_gradient(const Color& top, const Color& bottom, float time)
m_fade_time = time;
}

std::string
Gradient::get_direction_string() const
{
if (m_gradient_direction == HORIZONTAL)
return "horizontal";
if (m_gradient_direction == VERTICAL)
return "vertical";
if (m_gradient_direction == HORIZONTAL_SECTOR)
return "horizontal_sector";
if (m_gradient_direction == VERTICAL_SECTOR)
return "vertical_sector";

return nullptr;
}

void
Gradient::set_direction(const GradientDirection& direction)
{
m_gradient_direction = direction;
}

void
Gradient::set_direction(const std::string& direction)
{
if (direction == "horizontal")
{
m_gradient_direction = HORIZONTAL;
}
else if (direction == "horizontal_sector")
{
m_gradient_direction = HORIZONTAL_SECTOR;
}
else if (direction == "vertical_sector")
{
m_gradient_direction = VERTICAL_SECTOR;
}
else if (direction == "vertical")
{
m_gradient_direction = VERTICAL;
}
else
{
log_info << "Invalid direction for gradient \"" << direction << "\"";
m_gradient_direction = VERTICAL;
}
}

void
Gradient::draw(DrawingContext& context)
{
Expand Down
2 changes: 2 additions & 0 deletions src/object/gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class Gradient final :
Color get_gradient_bottom() const { return m_gradient_bottom; }

GradientDirection get_direction() const { return m_gradient_direction; }
std::string get_direction_string() const;
void set_direction(const GradientDirection& direction);
void set_direction(const std::string& direction);

void set_layer(int layer) { m_layer = layer; }
int get_layer() const { return m_layer; }
Expand Down
26 changes: 2 additions & 24 deletions src/scripting/gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,14 @@ void
Gradient::set_direction(const std::string& direction)
{
SCRIPT_GUARD_VOID;

if (direction == "horizontal")
object.set_direction(GradientDirection::HORIZONTAL);
else if (direction == "vertical")
object.set_direction(GradientDirection::VERTICAL);
else if (direction == "horizontal_sector")
object.set_direction(GradientDirection::HORIZONTAL_SECTOR);
else if (direction == "vertical_sector")
object.set_direction(GradientDirection::VERTICAL_SECTOR);
else
log_info << "Invalid direction for gradient \"" << direction << "\"";
object.set_direction(direction);
}

std::string
Gradient::get_direction() const
{
SCRIPT_GUARD_DEFAULT;

auto direction = object.get_direction();

if (direction == GradientDirection::HORIZONTAL)
return "horizontal";
if (direction == GradientDirection::VERTICAL)
return "vertical";
if (direction == GradientDirection::HORIZONTAL_SECTOR)
return "horizontal_sector";
if (direction == GradientDirection::VERTICAL_SECTOR)
return "vertical_sector";

return nullptr;
return object.get_direction_string();
}

void
Expand Down

0 comments on commit 743714b

Please sign in to comment.