static id fixed

This commit is contained in:
Sebastian
2024-11-05 00:51:25 +01:00
parent dc7eae1931
commit 4a346350f4
3 changed files with 31 additions and 8 deletions
+4 -3
View File
@@ -9,9 +9,9 @@ namespace VISEQ::GRAPH {
class GraphItem{ class GraphItem{
public: public:
GraphItem() {newId();} GraphItem() {newId(-1);}
GraphItem(const GraphItem& G) { GraphItem(const GraphItem& G) {
newId(); newId(-1);
graphItemType = G.graphItemType; graphItemType = G.graphItemType;
neighbors = G.neighbors; neighbors = G.neighbors;
} }
@@ -20,8 +20,9 @@ namespace VISEQ::GRAPH {
int id = 0; int id = 0;
void newId(){ void newId(int start){
static int _id; static int _id;
if(start > -1) _id = start;
id = _id; id = _id;
_id++; _id++;
} }
+15 -5
View File
@@ -9,6 +9,7 @@
#include "graph-manager.h" #include "graph-manager.h"
#include "node.h" #include "node.h"
#include "vmath.h" #include "vmath.h"
#include <alsa/hwdep.h>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
@@ -29,8 +30,6 @@
#include <iterator> #include <iterator>
#include <memory> #include <memory>
#include "state-io.h"
using json = nlohmann::json; using json = nlohmann::json;
VISEQ::APP::AppState app; VISEQ::APP::AppState app;
@@ -85,16 +84,25 @@ int main(){
app.settings = graph.at("settings"); app.settings = graph.at("settings");
// app.gm = graph["graphmanager"].get<VISEQ::GRAPH::GraphManager>();
int highest_id = 0; int highest_id = 0;
std::shared_ptr<Node> hid; std::shared_ptr<Node> hid;
for(auto n : graph.at("graphmanager").at("nodes")){ for(auto n : graph.at("graphmanager").at("nodes")){
std::shared_ptr<MidiNode> mn = n; std::shared_ptr<MidiNode> mn = n;
app.gm.nodes.push_back(mn);
if(mn->id > highest_id) { if(mn->id > highest_id) {
highest_id = mn->id; highest_id = mn->id;
hid = mn; hid = mn;
} }
}
for(auto e : graph.at("graphmanager").at("edges")){
if(e.at("id") > highest_id){
highest_id = e.at("id");
}
}
for(auto n : graph.at("graphmanager").at("nodes")){
std::shared_ptr<MidiNode> mn = n;
app.gm.nodes.push_back(mn);
std::cout << std::format("adding node {}", mn->id) << std::endl; std::cout << std::format("adding node {}", mn->id) << std::endl;
} }
@@ -111,7 +119,9 @@ int main(){
} }
} }
app.gm.edges.back()->newId(highest_id); // reset static id counter in base class
for(auto s : graph.at("signalmanager").at("signals")){ for(auto s : graph.at("signalmanager").at("signals")){
int start_id = s.at("start").get<int>(); int start_id = s.at("start").get<int>();
int next_id = s.at("next").get<int>(); int next_id = s.at("next").get<int>();
+12
View File
@@ -94,6 +94,17 @@ namespace VISEQ::APP::UI{
} }
DrawText(std::format("{}", gm->nodes.size()).c_str(), 20, settings->height - 70, 15, VS_COLOR_WHITE); DrawText(std::format("{}", gm->nodes.size()).c_str(), 20, settings->height - 70, 15, VS_COLOR_WHITE);
DrawFPS(20, settings->height - 30); DrawFPS(20, settings->height - 30);
}
void drawPropertiesBar(){
float left = settings->width - 280.f;
GuiPanel((Rectangle){left,-30,280,(float)settings->height + 31}, "");
const int s_controls = 25;
} }
void drawPerNodeConfig(Camera2D *camera){ void drawPerNodeConfig(Camera2D *camera){
@@ -188,6 +199,7 @@ namespace VISEQ::APP::UI{
void draw(Vec2Df *mouse_pos, Camera2D *camera){ void draw(Vec2Df *mouse_pos, Camera2D *camera){
drawSideBar(); drawSideBar();
drawPropertiesBar();
drawPerNodeConfig(camera); drawPerNodeConfig(camera);
} }