WIP nodegraph

This commit is contained in:
2025-08-29 19:31:49 -05:00
parent 284032cdce
commit 65dc6695cc
3 changed files with 98 additions and 1 deletions

View File

@@ -1100,3 +1100,73 @@ node_condition_builder_t& node_condition_builder_t::loc(eSpecField a, eSpecField
self.loc(a, b, type, where);
return *this;
}
short cSpecial::get(eSpecField fld) {
switch(fld){
case eSpecField::SDF1: return sd1;
case eSpecField::SDF2: return sd2;
case eSpecField::MSG1: return m1;
case eSpecField::MSG2: return m2;
case eSpecField::MSG3: return m3;
case eSpecField::PICT: return pic;
case eSpecField::PTYP: return pictype;
case eSpecField::EX1A: return ex1a;
case eSpecField::EX1B: return ex1b;
case eSpecField::EX1C: return ex1c;
case eSpecField::EX2A: return ex2a;
case eSpecField::EX2B: return ex2b;
case eSpecField::EX2C: return ex2c;
case eSpecField::JUMP: return jumpto;
default: return -1; // Or should it throw?
}
}
// TODO oh god the edit stack won't be reflected when graphing on a stack
std::vector<graph_node_t> global_node_graph(std::vector<cSpecial>& globals) {
std::vector<graph_node_t> graph_nodes;
for(int i = 0; i < globals.size(); ++ i){
graph_node_t node = { std::make_pair(true, i) };
cSpecial& special = globals[i];
node_properties_t props = *(special.type);
// Forward connections
for(int i = 1; i <= static_cast<int>(eSpecField::JUMP); ++i){
eSpecField fld = static_cast<eSpecField>(i);
if(props.get(special, fld).button == eSpecPicker::NODE){
if(special.get(fld) >= 0){
node.to_nodes.insert(std::make_pair(true, i));
}
// TODO negative numbers can be pointers, which the graph can't follow,
// but that ambiguity or the pointer's identity could be noted on the graph
}
}
graph_nodes.push_back(node);
}
// Backward connections
for(int i = 0; i < globals.size(); ++ i){
graph_node_t& node = graph_nodes[i];
for(node_id id : node.to_nodes){
graph_nodes[id.second].from_nodes.insert(id);
}
}
return graph_nodes;
}
bool node_compare::operator()(node_id a, node_id b) const {
// This is just a lexicographical ordering.
if(a.first != b.first) return a.first < b.first;
if(a.second != b.second) return a.second < b.second;
return false;
}
std::vector<graph_node_t> local_node_graph(std::vector<cSpecial>& locals, std::vector<cSpecial>& globals) {
std::vector<graph_node_t> global_nodes = global_node_graph(globals);
std::vector<graph_node_t> local_nodes;
return local_nodes;
}

View File

@@ -12,11 +12,13 @@
#include <iosfwd>
#include <string>
#include <functional>
#include <set>
#include "location.hpp"
#include "dialogxml/widgets/pictypes.hpp"
namespace legacy { struct special_node_type; };
class cUniverse;
enum class eSpecField;
static const short SDF_COMPLETE = 250;
@@ -90,6 +92,7 @@ public:
void import_legacy(legacy::special_node_type& old);
void writeTo(std::ostream& file, int n) const;
short get(eSpecField fld);
bool operator==(const cSpecial& other) const {
CHECK_EQ(other, type);
CHECK_EQ(other, sd1);
@@ -112,6 +115,20 @@ public:
std::string editor_hint(cUniverse& univ) const;
};
typedef std::pair<bool, size_t> node_id;
struct node_compare {
bool operator()(node_id a, node_id b) const;
};
struct graph_node_t {
node_id id;
std::set<node_id, node_compare> from_nodes;
std::set<node_id, node_compare> to_nodes;
};
std::vector<graph_node_t> global_node_graph(std::vector<cSpecial>& globals);
std::vector<graph_node_t> local_node_graph(std::vector<cSpecial>& locals, std::vector<cSpecial&> globals);
enum class eSpecCtxType {
SCEN, OUTDOOR, TOWN,
};
@@ -242,10 +259,10 @@ struct node_properties_t {
node_function_t ex1a(const cSpecial&) const, ex1b(const cSpecial&) const, ex1c(const cSpecial&) const;
node_function_t ex2a(const cSpecial&) const, ex2b(const cSpecial&) const, ex2c(const cSpecial&) const;
node_properties_t() : node_properties_t(eSpecType::INVALID) {}
node_function_t get(const cSpecial& spec, eSpecField fld) const;
bool can_preview;
private:
node_properties_t(eSpecType type);
node_function_t get(const cSpecial& spec, eSpecField fld) const;
void set(eSpecField fld, node_function_t fcn);
std::map<eSpecField, node_function_t> fields;
std::vector<std::pair<node_condition_t, node_properties_t>> conditions;

View File

@@ -814,6 +814,16 @@ static void setup_node_field(cDialog& me, std::string field, short value, const
static void put_spec_enc_in_dlog(cDialog& me, node_stack_t& edit_stack) {
cSpecial& spec = edit_stack.back().node;
// Graph fun!
std::vector<graph_node_t> globals = global_node_graph(scenario.scen_specials);
graph_node_t which = globals[edit_stack.back().which];
for(node_id from_id : which.from_nodes){
LOG(fmt::format("{} -> {}", from_id.second, which.id.second));
}
for(node_id to_id : which.from_nodes){
LOG(fmt::format("{} -> {}", which.id.second, to_id.second));
}
// Show which node is being edited and what type of node it is
switch(edit_stack.back().mode) {