fix load out nodes count

This commit is contained in:
Anthony Rabine 2023-05-23 00:22:13 +02:00
parent 843fa7aeba
commit f495e5d944
8 changed files with 40 additions and 15 deletions

BIN
art/pack/dragon.kra Normal file

Binary file not shown.

BIN
art/pack/fairy.kra Normal file

Binary file not shown.

BIN
art/pack/fairy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

View file

@ -549,7 +549,7 @@ void MainWindow::BuildScript()
chip32_initialize(&m_chip32_ctx);
m_dbg.run_result = VM_OK;
updateAll();
DebugContext::DumpCodeAssembler(m_assembler);
// DebugContext::DumpCodeAssembler(m_assembler);
}
else
{

View file

@ -26,7 +26,8 @@ MediaNodeModel::MediaNodeModel(StoryGraphModel &model)
m_ui.image->setMinimumSize(320, 240);
m_ui.image->installEventFilter(this);
connect(m_ui.spinBox, &QSpinBox::valueChanged, [&](int i) {
connect(m_ui.spinBox, QOverload<int>::of(&QSpinBox::valueChanged), [&](int i) {
bool addAction = false;
if (m_ports < i) {
addAction = true;
@ -88,16 +89,14 @@ void MediaNodeModel::setImage(const QString &fileName)
{
QPixmap pix(m_model.BuildFullImagePath(fileName));
if (pix.isNull())
if (!pix.isNull())
{
qCritical() << "Can't find image: " << fileName;
}
int w = m_ui.image->width();
int h = m_ui.image->height();
pix.scaled(w, h, Qt::KeepAspectRatio);
m_ui.image->setPixmap(pix);
m_ui.imageName->setText(fileName);
}
}
void MediaNodeModel::setInternalData(const nlohmann::json &j)
@ -133,6 +132,17 @@ std::string MediaNodeModel::GenerateConstants()
}
// FIXME: Generate choice table if needed (out ports > 1)
std::unordered_set<ConnectionId> conns = m_model.allConnectionIds(getNodeId());
int nb_out_ports = 0;
for (auto & c : conns)
{
if (c.outNodeId > 0)
{
nb_out_ports++;
}
}
return s;
}
@ -164,14 +174,14 @@ std::string MediaNodeModel::Build()
// Call the media executor (image, sound)
ss << "syscall 1\n";
std::unordered_set<ConnectionId> conns = m_model.allConnectionIds(getNodeId());
NodeId id = getNodeId();
std::unordered_set<ConnectionId> conns = m_model.allConnectionIds(id);
int nb_out_ports = 0;
for (auto & c : conns)
{
if (c.outNodeId > 0)
if (c.inNodeId == id)
{
nb_out_ports++;
}
@ -206,6 +216,13 @@ std::string MediaNodeModel::Build()
return ss.str();
}
void MediaNodeModel::SetOutPortCount(int count) {
// m_ui.spinBox->blockSignals(true);
m_ui.spinBox->setValue(count);
// m_ui.spinBox->blockSignals(true);
}
unsigned int MediaNodeModel::nPorts(PortType portType) const
{
unsigned int result = 1;

View file

@ -46,6 +46,8 @@ public:
virtual std::string GenerateConstants() override;
virtual std::string Build() override;
virtual void SetOutPortCount(int count) override;
public:
virtual QString modelName() const { return QString("MediaNode"); }

View file

@ -210,6 +210,8 @@ bool StoryGraphModel::setNodeData(NodeId nodeId, NodeRole role, QVariant value)
auto &model = it->second;
switch (role) {
case NodeRole::Id:
break;
case NodeRole::Type:
break;
case NodeRole::Position: {
@ -460,6 +462,7 @@ void StoryGraphModel::LoadNode(const nlohmann::json &nodeJson)
QPointF const pos(posJson["x"].get<double>(), posJson["y"].get<double>());
setNodeData(restoredNodeId, NodeRole::Position, pos);
model->SetOutPortCount(nodeJson["outPortCount"].get<int>());
_models[restoredNodeId]->FromJson(internalDataJson);
} else {
@ -478,11 +481,10 @@ NodeId StoryGraphModel::FindFirstNode() const
bool foundConnection{false};
for (auto& c : _connectivity)
{
if (c.outNodeId == nodeId)
if (c.inNodeId == nodeId)
{
foundConnection = true;
}
}
if (!foundConnection)

View file

@ -33,6 +33,10 @@ public:
void setNodeId(NodeId id) { m_nodeId = id; }
NodeId getNodeId() const { return m_nodeId; }
virtual void SetOutPortCount(int count) {
// default implementation does nothing
}
virtual nlohmann::json ToJson() const {
nlohmann::json j;