partial reload from json working, but edges make problems
This commit is contained in:
+1
-1
@@ -3,4 +3,4 @@ build/**
|
||||
viseq
|
||||
viseq.exe
|
||||
compile_commands.json
|
||||
state.json
|
||||
*.json
|
||||
|
||||
+1
-1
@@ -284,6 +284,6 @@ namespace VISEQ::GRAPH {
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, GraphManager& G){
|
||||
j.at("nodes").get_to(G.nodes); // = json{{"nodes", G.nodes}, {"edges", G.edges}};
|
||||
j.at("nodes").template get_to<VEC_SPTR_Node>(G.nodes); // = json{{"nodes", G.nodes}, {"edges", G.edges}};
|
||||
}
|
||||
}
|
||||
|
||||
+21
-3
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "graph-manager.h"
|
||||
#include "node.h"
|
||||
#include "vmath.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -82,7 +83,24 @@ int main(){
|
||||
std::ifstream f("state.json");
|
||||
json graph = json::parse(f);
|
||||
|
||||
app.gm = graph["graphmanager"].template get<VISEQ::GRAPH::GraphManager>();
|
||||
// app.gm = graph["graphmanager"].get<VISEQ::GRAPH::GraphManager>();
|
||||
for(auto n : graph.at("graphmanager").at("nodes")){
|
||||
std::shared_ptr<MidiNode> mn = n;
|
||||
app.gm.nodes.push_back(mn);
|
||||
/*app.gm.addMidiNode(n.at("position").get<Vec2Df>());*/
|
||||
/*app.gm.nodes.back().midi_note_channel = n.at("midi_note_channel").get<int>();*/
|
||||
}
|
||||
|
||||
for(auto e : graph.at("graphmanager").at("edges")){
|
||||
int start_id = e.at("start").get<int>();
|
||||
int end_id = e.at("end").get<int>();
|
||||
|
||||
VEC_SPTR_Node start = app.gm.nodes | RANGE_FILTER([start_id](SPTR_Node n){return n->id == start_id;}) | std::ranges::to<VEC_SPTR_Node>();
|
||||
VEC_SPTR_Node end = app.gm.nodes | RANGE_FILTER([end_id](SPTR_Node n){return n->id == end_id;}) | std::ranges::to<VEC_SPTR_Node>();
|
||||
|
||||
if(!start.empty() && !end.empty()) app.gm.addConnection(start.front(), end.front());
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
for(int i = 0; i < 4; ++i){
|
||||
@@ -403,8 +421,8 @@ int main(){
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
std::ofstream file("state.json");
|
||||
file << json(app);
|
||||
//std::ofstream file("state.json");
|
||||
//file << json(app);
|
||||
|
||||
std::cout << std::setw(4) << json(app) << std::endl;
|
||||
|
||||
|
||||
+19
-19
@@ -69,8 +69,10 @@ namespace VISEQ::GRAPH::NODES {
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, MidiNode& N){
|
||||
std::cout << "MidiNode" << std::endl;
|
||||
|
||||
j.at("id").get_to(N.id);
|
||||
j.at("position").get_to(N.position);
|
||||
j.at("position").get_to<Vec2Df>(N.position);
|
||||
j.at("distributionMode").get_to(N.distributionMode);
|
||||
j.at("nodeType").get_to(N.nodeType);
|
||||
j.at("midi_note_channel").get_to(N.midi_note_channel);
|
||||
@@ -94,6 +96,10 @@ namespace VISEQ::GRAPH::NODES {
|
||||
inline void from_json(const json& j, std::shared_ptr<MidiNode>& N){
|
||||
N.reset(new MidiNode(j.get<MidiNode>()));
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){
|
||||
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
|
||||
}
|
||||
|
||||
|
||||
/* ------------------- NODE ---------------------- */
|
||||
@@ -111,23 +117,14 @@ namespace VISEQ::GRAPH::NODES {
|
||||
std::cout << j.at("nodeType") << std::endl;
|
||||
N = j.template get<MidiNode>();
|
||||
}
|
||||
|
||||
/*j.at("id").get_to(N.id);*/
|
||||
/*j.at("position").get_to(N.position);*/
|
||||
/*j.at("distributionMode").get_to(N.distributionMode);*/
|
||||
/*j.at("nodeType").get_to(N.nodeType);*/
|
||||
//j.at("connections").get_to(N.connections);
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const SPTR_Node& N){
|
||||
j = *N;
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const MidiNode::NodeMidiOut MO){
|
||||
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, std::shared_ptr<Node>& N){
|
||||
std::cout << "SPTR_Node" << std::endl;
|
||||
N.reset(new Node(j.get<Node>()));
|
||||
}
|
||||
|
||||
@@ -136,6 +133,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
namespace VISEQ::GRAPH {
|
||||
inline void to_json(json& j, const GraphItem& G){
|
||||
std::cout << "Movable" << std::endl;
|
||||
j = json{{"id", G.id}, {"type", G.graphItemType}};
|
||||
}
|
||||
|
||||
@@ -146,12 +144,22 @@ namespace VISEQ::GRAPH {
|
||||
|
||||
namespace VISEQ::BASE{
|
||||
inline void to_json(json& j, const Movable& G){
|
||||
std::cout << "Movable" << std::endl;
|
||||
j = json{{"position", G.position}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const std::shared_ptr<Movable>& G){
|
||||
j = *G;
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, Movable& G){
|
||||
std::cout << "Movable" << std::endl;
|
||||
// j = json{{"position", G.position}};
|
||||
}
|
||||
|
||||
inline void from_json(json& j, const std::shared_ptr<Movable>& G){
|
||||
// j = *G;
|
||||
}
|
||||
}
|
||||
|
||||
namespace VISEQ::SIGNAL{
|
||||
@@ -163,11 +171,3 @@ namespace VISEQ::SIGNAL{
|
||||
j = *G;
|
||||
}
|
||||
}
|
||||
|
||||
namespace VISEQ::MIDI {
|
||||
inline void to_json(json& j, const MidiOutPort MO){
|
||||
j = json{{"port_id", MO.number}, {"enabled", MO.enabled}};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "raylib.h"
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
@@ -107,12 +108,13 @@ namespace VISEQ::VMATH{
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void to_json(json& j, const Vec2D<T> V){
|
||||
void to_json(json& j, const Vec2D<T>& V){
|
||||
j = json{{"x",V.x},{"y",V.y}};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void from_json(const json& j, Vec2D<T> V){
|
||||
void from_json(const json& j, Vec2D<T>& V){
|
||||
std::cout << "Vec2D" << std::endl;
|
||||
j.at("x").get_to(V.x);
|
||||
j.at("y").get_to(V.y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user