Skip to content

Commit

Permalink
Squirrel: Fix inaccessible class member variables, improvements (#3031)
Browse files Browse the repository at this point in the history
Fixes a bug in simplesquirrel, which caused exposed class member variables to be inaccessible from Squirrel.

Additionally:

* Simplesquirrel now supports custom getters and setters for class member variables. Because of this, more `get_` and `set_` functions of objects now have an alternative variable, which can also be used.
* All `get_` and `set_` functions which were made obsolete by member variables are now un-deprecated, because of a noticeable preference amongst scripters to keep both options available for convenience.
  • Loading branch information
Vankata453 committed Aug 12, 2024
1 parent f5535d2 commit 7aad14c
Show file tree
Hide file tree
Showing 33 changed files with 271 additions and 124 deletions.
2 changes: 1 addition & 1 deletion external/simplesquirrel
2 changes: 2 additions & 0 deletions src/object/candle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Candle::register_class(ssq::VM& vm)
cls.addFunc("puff_smoke", &Candle::puff_smoke);
cls.addFunc("get_burning", &Candle::get_burning);
cls.addFunc("set_burning", &Candle::set_burning);

cls.addVar("burning", &Candle::get_burning, &Candle::set_burning);
}

/* EOF */
4 changes: 4 additions & 0 deletions src/object/candle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Candle final : public MovingSprite
void set_burning(bool burning);

private:
/**
* @scripting
* @description The burning state of the candle.
*/
bool burning; /**< true if candle is currently lighted */
bool flicker; /**< true if candle light is to flicker */
Color lightcolor; /**< determines color or light given off */
Expand Down
9 changes: 9 additions & 0 deletions src/object/conveyor_belt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ ConveyorBelt::set_speed(float target_speed)
m_speed = target_speed;
}

float
ConveyorBelt::get_speed() const
{
return m_speed;
}


void
ConveyorBelt::register_class(ssq::VM& vm)
Expand All @@ -183,6 +189,9 @@ ConveyorBelt::register_class(ssq::VM& vm)
cls.addFunc("move_left", &ConveyorBelt::move_left);
cls.addFunc("move_right", &ConveyorBelt::move_right);
cls.addFunc("set_speed", &ConveyorBelt::set_speed);
cls.addFunc("get_speed", &ConveyorBelt::get_speed);

cls.addVar("speed", &ConveyorBelt::get_speed, &ConveyorBelt::set_speed);
}

/* EOF */
19 changes: 14 additions & 5 deletions src/object/conveyor_belt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,35 @@ class ConveyorBelt final : public MovingSprite
/** @name Scriptable Methods */
/**
* @scripting
* Starts the conveyor belt.
* @description Starts the conveyor belt.
*/
void start();
/**
* @scripting
* Stops the conveyor belt.
* @description Stops the conveyor belt.
*/
void stop();
/**
* @scripting
* Makes the conveyor shift objects to the left.
* @description Makes the conveyor shift objects to the left.
*/
void move_left();
/**
* @scripting
* Makes the conveyor shift objects to the right.
* @description Makes the conveyor shift objects to the right.
*/
void move_right();
/**
* @scripting
* Change the shifting speed of the conveyor.
* @description Change the shifting speed of the conveyor.
* @param float $target_speed
*/
void set_speed(float target_speed);
/**
* @scripting
* @description Returns the shifting speed of the conveyor.
*/
float get_speed() const;

private:
void update_hitbox() override;
Expand All @@ -90,6 +95,10 @@ class ConveyorBelt final : public MovingSprite
bool m_running;
Direction m_dir;
int m_length;
/**
* @scripting
* @description The shifting speed of the conveyor.
*/
float m_speed;

float m_frame;
Expand Down
Loading

0 comments on commit 7aad14c

Please sign in to comment.