Skip to content

Commit

Permalink
Mitochondria properly as a node as it should be
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattHolliday committed Jan 30, 2024
1 parent b9dfc93 commit 6ad46c0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
16 changes: 0 additions & 16 deletions src/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,13 @@ Size2 Cell::getSpriteSize() const { return _spriteSize; }
void Cell::_ready() {
_cellState = this->get_node<CellState>("CellState");
_mitochondria = this->get_node<Mitochondria>("Mitochondria");
if (!_mitochondria) {
ERR_PRINT("Mitochondria node not found or not of type Mitochondria!");
} else {
if (!_mitochondria->is_class("Mitochondria")) {
ERR_PRINT("Node named 'Mitochondria' is not of type Mitochondria!");
} else {
ERR_PRINT("Node named 'Mitochondria' is of type Mitochondria");
}
}
}

void Cell::_process(double delta) {
// Don't run if in editor
if (Engine::get_singleton()->is_editor_hint())
return;

if (!_mitochondria) {
_cellState->setAlive(false); // kill cell
this->set_linear_damp(10.0);
ERR_PRINT("Mitochondria node is not initialized!");
return;
}

if (_cellState->getAlive()) {
// Living Cell behavior

Expand Down
2 changes: 1 addition & 1 deletion src/mitochondria.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void Mitochondria::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_nutrients", "amount"), &Mitochondria::addNutrients);
ClassDB::bind_method(D_METHOD("decrement_nutrients", "amount"), &Mitochondria::decrementNutrients);
ClassDB::bind_method(D_METHOD("get_nutrients"), &Mitochondria::getNutrients);
ClassDB::bind_method(D_METHOD("set_nutrients", "level"), &Mitochondria::getNutrients);
ClassDB::bind_method(D_METHOD("set_nutrients", "level"), &Mitochondria::setNutrients);
ClassDB::add_property("Mitochondria", PropertyInfo(Variant::FLOAT, "nutrients"),
"set_nutrients", "get_nutrients");
}
Expand Down
2 changes: 2 additions & 0 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cell_spawner.hpp"
#include "cell_state.hpp"
#include "fps_counter.hpp"
#include "mitochondria.hpp"
#include "start_button.hpp"
#include "stats_counter.hpp"

Expand All @@ -22,6 +23,7 @@ void initialize_gdextension_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<FpsCounter>();
ClassDB::register_class<Cell>();
ClassDB::register_class<CellState>();
ClassDB::register_class<Mitochondria>();
ClassDB::register_class<CellSpawner>();
ClassDB::register_class<StartButton>();
}
Expand Down

0 comments on commit 6ad46c0

Please sign in to comment.