Dear forum,
I was looking for similar approaches for quite some time now, but can’t find much useful reference.
I try to program something like a mindmap, that looks like a classic Diablo 2 skill tree. This skill tree shall be generated automatically on run time, because there will be A LOT of “skills” (it’s a tech tree actually) visualized by cards to be placed in the tree. Also by A LOT I mean that they might change over time, depending on me adding additional techs etc. in addons or whatnot.
Anyhow this is my current approach (caution, no real code):
class MapCreator {
int Grid[,] // the cards will be placed on a grid
int AllCards[] // stores all unique card IDs
int clm // stores the current(?) column information
int row // stores the current(?) row information
scriptableObject card {
int cID[] // each cards unique ID, row, column (row and column will be determined on runtime)
int parentID[] // one (or more) parent IDs, referencing the unique ID of cID[]
int childID[] // one or more childen IDs, referencing the unique ID of cID[]
}
/*
Rules
1) A child will always be created to the right of the previous one if it is dividable by 2, otherwise to the left of the previous one
2) A card always has an empty space to its right
______x_____
______|_____
____x_x_x___
________|___
________x_x_
*/
void switch CreateChildren {
// defined cases based on the number of children to make things easier (max. 5 children);
// foreach, if etc. would be sexier
case x { // 0 = no children, 1 = 1 child, 2 = 2 children etc.
position[] = [clm, row] // much complexer based on case and based on rules
CheckPosition();
PositionOkay:
CreateNode(); // save position in the grid in cID[]
CreateConnector(); // creates the connecting wire, I have an idea about this already
}
...
}
CheckPosition:
void CheckPosition() {
Check if recently added node already exists {
if no goto: PositionOkay;
else goto: PositionNOkay;
}
PositionNOkay:
void MoveParent() {
find already existing nodes parent;
find position of current node in current nodes parent childenID[];
if this position %2 = 0 { // move it to the right of the was added to the right in the first place
parent.clm+2;
goto CreateChildren;
}
else { // otherwise move it to the left
parent.clm-2;
goto CreateChildren;
}
}
}
Obviously this is very messy, I have no access to a developer right now.
I don’t need a fully fleshed out solution for this, just wanted to ask if this is the right path to go or if there are other wonders of scripting that I have not thought about before. Especially I’m not sure if this process is looping correctly. Can I even start it or to I need to have it run in update?
By the way: the initialisation and visualisation will be seperated most probably. I “only” need the tree to develop itself.
Basically the tree should generate itself based on all existing scriptableObjects (the first one will be set to start the process) AND the nodes need to be referencable later on (I hope this works already by giving them a unique ID (that is also the same as the cards unique ID) so that I can simply match them later).
Hope this was not too messy, but again, it’s really more about the concept right now.
Thanks a ton and kind regards from Germany,
Marcel
