add missing files
This commit is contained in:
57
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageInfoNode.cpp
Normal file
57
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageInfoNode.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageInfoNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageInfoNode::ImageInfoNode()
|
||||
: BaseNode()
|
||||
{
|
||||
setName("ImageInfoNode");
|
||||
setCaption("Image Info");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<ImageData>(PortType::In, "Image", true);
|
||||
|
||||
addPort<Vector2DData>(PortType::Out, "Size<Vector2D>", true);
|
||||
addPort<BooleanData>(PortType::Out, "HasAlpha<Boolean>", true);
|
||||
addPort<BooleanData>(PortType::Out, "IsNull<Boolean>", true);
|
||||
addPort<IntegerData>(PortType::Out, "Depth<Integer>", true);
|
||||
}
|
||||
|
||||
void ImageInfoNode::compute()
|
||||
{
|
||||
QPixmap image = static_cast<ImageData*>(_in_ports[0].in_value.lock().get())->value();
|
||||
|
||||
auto size = image.size();
|
||||
_out_ports[0].out_value = std::make_shared<Vector2DData>(glm::vec2(size.width(), size.height()));
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<BooleanData>(image.hasAlpha());
|
||||
Q_EMIT dataUpdated(1);
|
||||
|
||||
_out_ports[2].out_value = std::make_shared<BooleanData>(image.isNull());
|
||||
Q_EMIT dataUpdated(2);
|
||||
|
||||
_out_ports[3].out_value = std::make_shared<IntegerData>(image.depth());
|
||||
Q_EMIT dataUpdated(3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
NodeValidationState ImageInfoNode::validate()
|
||||
{
|
||||
|
||||
if (!static_cast<ImageData*>(_in_ports[0].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
34
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageInfoNode.hpp
Normal file
34
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageInfoNode.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGEINFONODE_HPP
|
||||
#define NOGGIT_IMAGEINFONODE_HPP
|
||||
|
||||
#include "noggit/Red/NodeEditor/Nodes/BaseNode.hpp"
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageInfoNode : public BaseNode
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageInfoNode();
|
||||
NodeValidationState validate() override;
|
||||
void compute() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGEINFONODE_HPP
|
||||
105
src/noggit/Red/NodeEditor/Nodes/Data/Image/LoadImageNode.cpp
Normal file
105
src/noggit/Red/NodeEditor/Nodes/Data/Image/LoadImageNode.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "LoadImageNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QImage>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
LoadImageNode::LoadImageNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("LoadImageNode");
|
||||
setCaption("Load Image");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<LogicData>(PortType::In, "Logic", true);
|
||||
|
||||
addPort<StringData>(PortType::In, "Path<String>", true);
|
||||
addDefaultWidget(_in_ports[1].data_type->default_widget(&_embedded_widget), PortType::In, 1);
|
||||
|
||||
_load_button = new QPushButton("Load", &_embedded_widget);
|
||||
addWidgetTop(_load_button);
|
||||
|
||||
connect(_load_button, &QPushButton::clicked
|
||||
, [=]
|
||||
{
|
||||
auto result(QFileDialog::getOpenFileName(
|
||||
nullptr, "Load image", static_cast<QLineEdit*>(_in_ports[1].default_widget)->text(), "*.png"));
|
||||
|
||||
if (!result.isNull())
|
||||
{
|
||||
static_cast<QLineEdit*>(_in_ports[1].default_widget)->setText(result);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
|
||||
}
|
||||
|
||||
void LoadImageNode::compute()
|
||||
{
|
||||
QImage image;
|
||||
auto path_ptr = static_cast<StringData*>(_in_ports[1].in_value.lock().get());
|
||||
QString path = path_ptr ? path_ptr->value().c_str() : static_cast<QLineEdit*>(_in_ports[1].default_widget)->text();
|
||||
|
||||
if (!image.load(path, ".png"))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to load image.");
|
||||
return;
|
||||
}
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(QPixmap::fromImage(image));
|
||||
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
QJsonObject LoadImageNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
json_obj["filepath"] = static_cast<QLineEdit*>(_in_ports[1].default_widget)->text();
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void LoadImageNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
|
||||
static_cast<QLineEdit*>(_in_ports[1].default_widget)->setText(json_obj["filepath"].toString());
|
||||
}
|
||||
|
||||
void LoadImageNode::inputConnectionCreated(Connection const& connection)
|
||||
{
|
||||
BaseNode::inputConnectionCreated(connection);
|
||||
PortIndex port_index = connection.getPortIndex(PortType::In);
|
||||
|
||||
if (port_index != 1)
|
||||
return;
|
||||
|
||||
_load_button->setHidden(true);
|
||||
|
||||
}
|
||||
|
||||
void LoadImageNode::inputConnectionDeleted(const Connection& connection)
|
||||
{
|
||||
BaseNode::inputConnectionDeleted(connection);
|
||||
PortIndex port_index = connection.getPortIndex(PortType::In);
|
||||
|
||||
if (port_index != 1)
|
||||
return;
|
||||
|
||||
_load_button->setHidden(false);
|
||||
}
|
||||
42
src/noggit/Red/NodeEditor/Nodes/Data/Image/LoadImageNode.hpp
Normal file
42
src/noggit/Red/NodeEditor/Nodes/Data/Image/LoadImageNode.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_LOADIMAGENODE_HPP
|
||||
#define NOGGIT_LOADIMAGENODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class LoadImageNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LoadImageNode();
|
||||
void compute() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void inputConnectionCreated(Connection const& connection) override;
|
||||
void inputConnectionDeleted(Connection const& connection) override;
|
||||
|
||||
private:
|
||||
QPushButton* _load_button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_LOADIMAGENODE_HPP
|
||||
145
src/noggit/Red/NodeEditor/Nodes/Data/SetVariableNode.cpp
Normal file
145
src/noggit/Red/NodeEditor/Nodes/Data/SetVariableNode.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "SetVariableNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Scene/NodeScene.hpp>
|
||||
#include "noggit/Red/NodeEditor/Nodes/Scene/Context.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <external/NodeEditor/include/nodes/Node>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
SetVariableNodeBase::SetVariableNodeBase()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<LogicData>(PortType::In, "Logic", true);
|
||||
addDefaultWidget(new QLabel(&_embedded_widget), PortType::In, 0);
|
||||
addPort<StringData>(PortType::In, "Name<String>", true);
|
||||
addDefaultWidget(_in_ports[1].data_type->default_widget(&_embedded_widget), PortType::In, 1);
|
||||
addPort<AnyData>(PortType::In, "Any", true);
|
||||
addDefaultWidget(new QLabel(&_embedded_widget), PortType::In, 2);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
}
|
||||
|
||||
void SetVariableNodeBase::compute()
|
||||
{
|
||||
if (!static_cast<LogicData*>(_in_ports[0].in_value.lock().get())->value())
|
||||
return;
|
||||
|
||||
auto variables = getVariableMap();
|
||||
|
||||
auto variable_name = _in_ports[1].connected ? static_cast<StringData*>(_in_ports[1].in_value.lock().get())->value() : static_cast<QLineEdit*>(_in_ports[1].default_widget)->text().toStdString();
|
||||
|
||||
// search for existing variable
|
||||
auto it = variables->find(variable_name);
|
||||
|
||||
if (it != variables->end() && _in_ports[2].data_type->type().id != it->second.first.c_str())
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage((boost::format("Error: existing variable \"%s\" of type \"%s\" does not match required type \"%s\".")
|
||||
% variable_name % it->second.first.c_str() % _in_ports[2].data_type->type().id.toStdString()).str().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
(*variables)[variable_name] = std::make_pair<std::string, std::shared_ptr<NodeData>>(_in_ports[2].data_type->type().id.toStdString(), _in_ports[2].in_value.lock());
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
}
|
||||
|
||||
QJsonObject SetVariableNodeBase::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
json_obj["variable_name"] = static_cast<QLineEdit*>(_in_ports[1].default_widget)->text();
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void SetVariableNodeBase::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
|
||||
static_cast<QLineEdit*>(_in_ports[1].default_widget)->setText(json_obj["variable_name"].toString());
|
||||
}
|
||||
|
||||
void SetVariableNodeBase::inputConnectionCreated(const Connection& connection)
|
||||
{
|
||||
BaseNode::inputConnectionCreated(connection);
|
||||
|
||||
auto port_index = connection.getPortIndex(PortType::In);
|
||||
|
||||
if (port_index != 2)
|
||||
return;
|
||||
|
||||
auto data_type = connection.dataType(PortType::Out);
|
||||
_in_ports[2].data_type.reset(TypeFactory::create(data_type.id.toStdString()));
|
||||
_in_ports[2].caption = data_type.name;
|
||||
|
||||
}
|
||||
|
||||
void SetVariableNodeBase::inputConnectionDeleted(const Connection& connection)
|
||||
{
|
||||
BaseNode::inputConnectionDeleted(connection);
|
||||
|
||||
auto port_index = connection.getPortIndex(PortType::In);
|
||||
|
||||
if (port_index != 2)
|
||||
return;
|
||||
|
||||
_in_ports[2].data_type.reset(TypeFactory::create("any"));
|
||||
_in_ports[2].caption = "Any";
|
||||
|
||||
}
|
||||
|
||||
NodeValidationState SetVariableNodeBase::validate()
|
||||
{
|
||||
return LogicNodeBase::validate();
|
||||
|
||||
if (!_in_ports[2].connected)
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: missing value input");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
// Scene scope
|
||||
|
||||
SetVariableNode::SetVariableNode()
|
||||
: SetVariableNodeBase()
|
||||
{
|
||||
setName("SetVariableNode");
|
||||
setCaption("Set Variable");
|
||||
}
|
||||
|
||||
VariableMap* SetVariableNode::getVariableMap()
|
||||
{
|
||||
return static_cast<NodeScene*>(_node->nodeGraphicsObject().scene())->getVariableMap();
|
||||
}
|
||||
|
||||
// Context scope
|
||||
|
||||
SetContextVariableNode::SetContextVariableNode()
|
||||
: SetVariableNodeBase()
|
||||
{
|
||||
setName("SetContextVariableNode");
|
||||
setCaption("Set Context Variable");
|
||||
}
|
||||
|
||||
VariableMap* SetContextVariableNode::getVariableMap()
|
||||
{
|
||||
return gCurrentContext->getVariableMap();
|
||||
}
|
||||
|
||||
|
||||
|
||||
73
src/noggit/Red/NodeEditor/Nodes/Data/SetVariableNode.hpp
Normal file
73
src/noggit/Red/NodeEditor/Nodes/Data/SetVariableNode.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_SETVARIABLENODE_HPP
|
||||
#define NOGGIT_SETVARIABLENODE_HPP
|
||||
|
||||
#include "noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp"
|
||||
#include <external/tsl/robin_map.h>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
using VariableMap = tsl::robin_map<std::string, std::pair<std::string, std::shared_ptr<NodeData>>>;
|
||||
|
||||
class SetVariableNodeBase : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SetVariableNodeBase();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void inputConnectionCreated(const Connection& connection) override;
|
||||
void inputConnectionDeleted(const Connection& connection) override;
|
||||
|
||||
protected:
|
||||
virtual VariableMap* getVariableMap() = 0;
|
||||
|
||||
};
|
||||
|
||||
// Scene scope
|
||||
|
||||
class SetVariableNode : public SetVariableNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SetVariableNode();
|
||||
|
||||
protected:
|
||||
VariableMap* getVariableMap() override;
|
||||
};
|
||||
|
||||
// Context scope
|
||||
|
||||
class SetContextVariableNode : public SetVariableNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SetContextVariableNode();
|
||||
|
||||
protected:
|
||||
VariableMap* getVariableMap() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_SETVARIABLENODE_HPP
|
||||
42
src/noggit/Red/NodeEditor/Nodes/Data/TypeParameterNode.cpp
Normal file
42
src/noggit/Red/NodeEditor/Nodes/Data/TypeParameterNode.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "TypeParameterNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
TypeParameterNode::TypeParameterNode()
|
||||
: BaseNode()
|
||||
{
|
||||
setName("TypeParameterNode");
|
||||
setCaption("Type Parameter");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<AnyData>(PortType::In, "Any", true);
|
||||
addPort<StringData>(PortType::Out, "Type<String>", true);
|
||||
}
|
||||
|
||||
void TypeParameterNode::compute()
|
||||
{
|
||||
auto data = _in_ports[0].in_value.lock();
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<StringData>(data->type().parameter_type_id.toStdString());
|
||||
Q_EMIT dataUpdated(0);
|
||||
}
|
||||
|
||||
NodeValidationState TypeParameterNode::validate()
|
||||
{
|
||||
auto data = _in_ports[0].in_value.lock();
|
||||
|
||||
if (!data)
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
37
src/noggit/Red/NodeEditor/Nodes/Data/TypeParameterNode.hpp
Normal file
37
src/noggit/Red/NodeEditor/Nodes/Data/TypeParameterNode.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_TYPEPARAMETERNODE_HPP
|
||||
#define NOGGIT_TYPEPARAMETERNODE_HPP
|
||||
|
||||
#include "noggit/Red/NodeEditor/Nodes/BaseNode.hpp"
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class TypeParameterNode : public BaseNode
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TypeParameterNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_TYPEPARAMETERNODE_HPP
|
||||
80
src/noggit/Red/NodeEditor/Nodes/Functions/PrintNode.cpp
Normal file
80
src/noggit/Red/NodeEditor/Nodes/Functions/PrintNode.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "PrintNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
#include <noggit/Log.h>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
PrintNode::PrintNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("PrintNode");
|
||||
setCaption("Print()");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<LogicData>(PortType::In, "Logic", true);
|
||||
addDefaultWidget(new QLabel(&_embedded_widget), PortType::In, 0);
|
||||
|
||||
addPort<StringData>(PortType::In, "String", true);
|
||||
_text = new QLineEdit(&_embedded_widget);
|
||||
addDefaultWidget(_text, PortType::In, 1);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true, ConnectionPolicy::One);
|
||||
|
||||
}
|
||||
|
||||
void PrintNode::compute()
|
||||
{
|
||||
auto logic = static_cast<LogicData*>(_in_ports[0].in_value.lock().get());
|
||||
|
||||
if(!logic->value())
|
||||
return;
|
||||
|
||||
auto text = _in_ports[1].in_value.lock();
|
||||
auto text_ptr = static_cast<StringData*>(text.get());
|
||||
|
||||
auto msg = text_ptr ? text_ptr->value() : _text->text().toStdString();
|
||||
|
||||
LogDebug << msg << std::endl;
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
}
|
||||
|
||||
QJsonObject PrintNode::save() const
|
||||
{
|
||||
QJsonObject json_obj;
|
||||
json_obj["name"] = name();
|
||||
json_obj["caption"] = caption();
|
||||
json_obj["text"] = _text->text();
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void PrintNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
setName(json_obj["name"].toString());
|
||||
setCaption(json_obj["caption"].toString());
|
||||
_text->setText(json_obj["text"].toString());
|
||||
}
|
||||
|
||||
NodeValidationState PrintNode::validate()
|
||||
{
|
||||
setValidationState(NodeValidationState::Valid);
|
||||
auto logic = static_cast<LogicData*>(_in_ports[0].in_value.lock().get());
|
||||
|
||||
if (!logic)
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: Failed to evaluate logic input");
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(false);
|
||||
Q_EMIT dataUpdated(0);
|
||||
}
|
||||
|
||||
return _validation_state;
|
||||
|
||||
}
|
||||
|
||||
|
||||
39
src/noggit/Red/NodeEditor/Nodes/Functions/PrintNode.hpp
Normal file
39
src/noggit/Red/NodeEditor/Nodes/Functions/PrintNode.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef NOGGIT_PRINTNODE_HPP
|
||||
#define NOGGIT_PRINTNODE_HPP
|
||||
|
||||
#include "noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp"
|
||||
#include <QLineEdit>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class PrintNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PrintNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
private:
|
||||
QLineEdit* _text;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_PRINTNODE_HPP
|
||||
Reference in New Issue
Block a user