Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/automated behavior testing #464

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,44 +140,11 @@ public void renderImGuiWidgets(RDXBehaviorTreeNode<?, ?> relativeNode, BehaviorT
ImGui.indent();
for (RDXAvailableBehaviorTreeFile indexedTreeFile : indexedTreeFiles)
{
String textToDisplay = "%s".formatted(indexedTreeFile.getTreeFile().getFileName(),
indexedTreeFile.getNumberOfFramesInWorld(),
indexedTreeFile.getReferenceFrameNames().size());
if (ImGuiTools.textWithUnderlineOnHover(textToDisplay))
if (ImGuiTools.textWithUnderlineOnHover(indexedTreeFile.getTreeFile().getFileName()))
{
if (ImGui.isMouseClicked(ImGuiMouseButton.Left))
{
RDXBehaviorTreeNode<?, ?> loadedNode = null;
try
{
loadedNode = tree.getFileLoader().loadFromFile(indexedTreeFile, topologyOperationQueue);
}
catch (Exception e)
{
LogTools.error("""
Error loading {}.
Please run the JSON sanitizer in debug mode with the NullPointerException breakpoint enabled.
Error: {}
""", textToDisplay, e.getMessage());
}

if (loadedNode != null)
{
RDXBehaviorTreeNode<?, ?> nodeToInsert = loadedNode;

if (tree.getRootNode() == null) // Automatically add a root node if there isn't one
{
nodeToInsert = new RDXBehaviorTreeRootNode(tree.getBehaviorTreeState().getAndIncrementNextID(),
tree.getBehaviorTreeState().getCRDTInfo(),
tree.getBehaviorTreeState().getSaveFileDirectory());
topologyOperationQueue.queueAddAndFreezeNode(loadedNode, nodeToInsert);
}

BehaviorTreeNodeInsertionDefinition<RDXBehaviorTreeNode<?, ?>> insertionDefinition
= BehaviorTreeNodeInsertionDefinition.build(nodeToInsert, tree.getBehaviorTreeState(), tree::setRootNode, relativeNode, insertionType);

complete(insertionDefinition);
}
loadTreeFromFile(relativeNode, insertionType, indexedTreeFile);
}
}

Expand Down Expand Up @@ -216,6 +183,56 @@ public void renderImGuiWidgets(RDXBehaviorTreeNode<?, ?> relativeNode, BehaviorT
}
}

public void loadTreeFromFile(String fileName)
{
for (RDXAvailableBehaviorTreeFile indexedTreeFile : indexedTreeFiles)
{
if (indexedTreeFile.getTreeFile().getFileName().equals(fileName))
{
loadTreeFromFile(null, BehaviorTreeNodeInsertionType.INSERT_ROOT, indexedTreeFile);
}
}

LogTools.error("Failed to load behavior. File not found: {}", fileName);
}

private void loadTreeFromFile(RDXBehaviorTreeNode<?, ?> relativeNode,
BehaviorTreeNodeInsertionType insertionType,
RDXAvailableBehaviorTreeFile indexedTreeFile)
{
RDXBehaviorTreeNode<?, ?> loadedNode = null;
try
{
loadedNode = tree.getFileLoader().loadFromFile(indexedTreeFile, topologyOperationQueue);
}
catch (Exception e)
{
LogTools.error("""
Error loading {}.
Please run the JSON sanitizer in debug mode with the NullPointerException breakpoint enabled.
Error: {}
""", indexedTreeFile.getTreeFile().getFileName(), e.getMessage());
}

if (loadedNode != null)
{
RDXBehaviorTreeNode<?, ?> nodeToInsert = loadedNode;

if (tree.getRootNode() == null) // Automatically add a root node if there isn't one
{
nodeToInsert = new RDXBehaviorTreeRootNode(tree.getBehaviorTreeState().getAndIncrementNextID(),
tree.getBehaviorTreeState().getCRDTInfo(),
tree.getBehaviorTreeState().getSaveFileDirectory());
topologyOperationQueue.queueAddAndFreezeNode(loadedNode, nodeToInsert);
}

BehaviorTreeNodeInsertionDefinition<RDXBehaviorTreeNode<?, ?>> insertionDefinition
= BehaviorTreeNodeInsertionDefinition.build(nodeToInsert, tree.getBehaviorTreeState(), tree::setRootNode, relativeNode, insertionType);

complete(insertionDefinition);
}
}

private void renderNodeCreationClickable(RDXBehaviorTreeNode<?, ?> relativeNode,
BehaviorTreeNodeInsertionType insertionType,
String nodeTypeName,
Expand Down
Loading