-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: new optional contextDepth for archy renderer #92
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #92 +/- ##
===========================================
+ Coverage 89.85% 90.03% +0.17%
===========================================
Files 18 18
Lines 276 291 +15
Branches 38 47 +9
===========================================
+ Hits 248 262 +14
- Misses 23 24 +1
Partials 5 5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments, nothing major
lib/utils/archyTree.ts
Outdated
@@ -4,40 +4,64 @@ import {BlueshellState} from '../nodes/BlueshellState'; | |||
import * as archy from 'archy'; | |||
import {Data} from 'archy'; | |||
|
|||
function buildArchyTree<S extends BlueshellState, E>(node: Base<S, E>, state?: S): Data { | |||
function buildArchyTree<S extends BlueshellState, E>( | |||
node: Base<S, E>, state?: S, contextDepth = Number.MAX_SAFE_INTEGER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this function need a default contextDepth? Its not exported and is only accessed by serializeArchyTree()
lib/utils/archyTree.ts
Outdated
for (let child of (<any>node).children) { | ||
archyTree.nodes.push(buildArchyTree(<Base<S,E>>child, state)); | ||
for (const child of (<any>node).children) { | ||
const subTree = buildArchyTree(<Base<S, E>>child, state, contextDepth - (onPath ? 0 : 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split the contextDepth calculation in't its own const declaration for clarity and to add a comment to describe the logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do.
lib/utils/archyTree.ts
Outdated
tree: Base<S, E>, state?: S, contextDepth = Number.MAX_SAFE_INTEGER | ||
): string { | ||
const archyTree = buildArchyTree(tree, state, contextDepth); | ||
if ( archyTree ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't have spaces here, did the linter not catch that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess not. I rely heavily on my VSCode linter plugin, which seems to work reliably with almost all our repos, but occasionally gets pissy and doesn't like one or another. Given that this one is configured differently, I wouldn't be shocked if it wasn't auto-cleaning-up after me (though I thought I saw it doing that...). Could also just be that the lint config here is different.
This adds an optional contextDepth parameter when using the archy renderer for the behavior tree.
Leaving out this optional parameter causes the existing behavior.
Describing the effect when the parameter is used is best done by example. Here are the unit tests for the new behavior, with the addition of showing the output they are testing: