75 lines
1.9 KiB
Plaintext
75 lines
1.9 KiB
Plaintext
/**
|
|
* Saving and loading is a messy hack!
|
|
* You'll get a blank line in your save file for each deleted object.
|
|
* That's because of my lack of skills of dodging the garbage collector.
|
|
* I didn't loose data to corruption yet.
|
|
* Don't touch the save files if you don't want to mess them up!
|
|
**/
|
|
|
|
boolean exporting;
|
|
String savePNGpath = dataPath("save.png");
|
|
|
|
void savePNGFile(File selection) {
|
|
savePNGpath = selection.getPath();
|
|
exporting = true;
|
|
}
|
|
|
|
void saveCSVFile(File selection) {
|
|
saveCSV(selection.getPath());
|
|
}
|
|
|
|
void loadCSVFile(File selection) {
|
|
loadCSV(selection.getPath());
|
|
}
|
|
|
|
void loadCSV(String path) {
|
|
for (int i = 0; i < nodeCount; i++) {
|
|
//nodes[i].deleted = true;
|
|
i_selectedNode = i;
|
|
deleteSelectedNode();
|
|
}
|
|
nodeCount = 0;
|
|
|
|
for (int i = 0; i < linkCount; i++) {
|
|
links[i].active = false;
|
|
}
|
|
linkCount = 0;
|
|
|
|
String[] loadString = loadStrings(path);
|
|
for (int i = 0; i < loadString.length-1; i++) {
|
|
//This is ultra shitty
|
|
if (loadString[i].length() == 0) {
|
|
addNode(-1000, -1000, " ");
|
|
i_selectedNode = nodeCount - 1;
|
|
deleteSelectedNode();
|
|
//nodes[nodeCount-1].deleted = true;
|
|
} else {
|
|
String nodeData[] = split(loadString[i], ',');
|
|
addNode(int(nodeData[1]), int(nodeData[2]), nodeData[0]);
|
|
}
|
|
}
|
|
for (int i = 0; i < loadString.length-1; i++) {
|
|
String nodeData[] = split(loadString[i], ',');
|
|
for (int j = 3; j < nodeData.length; j++) {
|
|
Link(i, int(nodeData[j]));
|
|
}
|
|
}
|
|
}
|
|
|
|
void saveCSV(String path) {
|
|
String saveString = "";
|
|
for (int i = 0; i < nodeCount; i++) {
|
|
if (!nodes[i].deleted) {
|
|
saveString += nodes[i].title + "," + nodes[i].x + "," + nodes[i].y;
|
|
for (int j = 0; j < linkCount; j++) {
|
|
if (links[j].parentNode == i && links[j].active) {
|
|
saveString += "," + str(links[j].targetNode);
|
|
}
|
|
}
|
|
}
|
|
saveString += "\n";
|
|
}
|
|
String[] saveArray = split(saveString, '\n');
|
|
saveStrings(path, saveArray);
|
|
}
|