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

feat: new optional contextDepth for archy renderer #92

Merged
merged 5 commits into from
Feb 18, 2019

Conversation

ddurschlag6river
Copy link
Contributor

@ddurschlag6river ddurschlag6river commented Feb 16, 2019

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:


  renderTree
    archy tree
      contextDepth
        before running

          ✓ should show nothing with -1 context depth
...

          ✓ should show root ellipsis with 0 context depth
root (LatchedSequence)
├─┬ 0 (LatchedSequence)
│ ├─┬ 0.0 (LatchedSequence)
│ │ ├── 0.0.0 (ConsumeOnce)
│ │ └── 0.0.1 (ConsumeOnce)
│ └─┬ 0.1 (LatchedSequence)
│   ├── 0.1.0 (ConsumeOnce)
│   └── 0.1.1 (ConsumeOnce)
└─┬ 1 (LatchedSequence)
  ├── 1.0 (ConsumeOnce)
  └── 1.1 (ConsumeOnce)

          ✓ should show everything by default
        after one run
root (LatchedSequence) => RUNNING
├─┬ 0 (LatchedSequence) => RUNNING
│ ├─┬ 0.0 (LatchedSequence) => RUNNING
│ │ ├── 0.0.0 (ConsumeOnce) => RUNNING
│ │ └── 0.0.1 (ConsumeOnce)
│ └─┬ 0.1 (LatchedSequence)
│   ├── 0.1.0 (ConsumeOnce)
│   └── 0.1.1 (ConsumeOnce)
└─┬ 1 (LatchedSequence)
  ├── 1.0 (ConsumeOnce)
  └── 1.1 (ConsumeOnce)

          ✓ should arrow the first path by default
root (LatchedSequence) => RUNNING
├─┬ 0 (LatchedSequence) => RUNNING
│ ├─┬ 0.0 (LatchedSequence) => RUNNING
│ │ ├── 0.0.0 (ConsumeOnce) => RUNNING
│ │ └── ...
│ └── ...
└── ...

          ✓ should show only the active path and ellipses 0 context depth
root (LatchedSequence) => RUNNING
└─┬ 0 (LatchedSequence) => RUNNING
  └─┬ 0.0 (LatchedSequence) => RUNNING
    └── 0.0.0 (ConsumeOnce) => RUNNING

          ✓ should show only the active path at -1 context depth
root (LatchedSequence) => RUNNING
├─┬ 0 (LatchedSequence) => RUNNING
│ ├─┬ 0.0 (LatchedSequence) => RUNNING
│ │ ├── 0.0.0 (ConsumeOnce) => RUNNING
│ │ └── 0.0.1 (ConsumeOnce)
│ └─┬ 0.1 (LatchedSequence)
│   ├── ...
│   └── ...
└─┬ 1 (LatchedSequence)
  ├── ...
  └── ...

          ✓ should show only the active path, siblings, and ellipses
root (LatchedSequence) => RUNNING
├─┬ 0 (LatchedSequence) => RUNNING
│ ├─┬ 0.0 (LatchedSequence) => RUNNING
│ │ ├── 0.0.0 (ConsumeOnce) => RUNNING
│ │ └── 0.0.1 (ConsumeOnce)
│ └─┬ 0.1 (LatchedSequence)
│   ├── 0.1.0 (ConsumeOnce)
│   └── 0.1.1 (ConsumeOnce)
└─┬ 1 (LatchedSequence)
  ├── 1.0 (ConsumeOnce)
  └── 1.1 (ConsumeOnce)

          ✓ should show everything at 2 context depth


  8 passing (25ms)

@codecov
Copy link

codecov bot commented Feb 17, 2019

Codecov Report

Merging #92 into develop will increase coverage by 0.17%.
The diff coverage is 96.96%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
lib/utils/renderTree.ts 100% <100%> (ø) ⬆️
lib/utils/archyTree.ts 96.77% <96.29%> (-3.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3100ca4...b6b162f. Read the comment docs.

Copy link
Contributor

@jbcpollak jbcpollak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments, nothing major

@@ -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
Copy link
Contributor

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()

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));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do.

tree: Base<S, E>, state?: S, contextDepth = Number.MAX_SAFE_INTEGER
): string {
const archyTree = buildArchyTree(tree, state, contextDepth);
if ( archyTree ) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

lib/utils/renderTree.ts Show resolved Hide resolved
@ddurschlag6river ddurschlag6river merged commit 56e91ce into develop Feb 18, 2019
@ddurschlag6river ddurschlag6river deleted the archyContextDepth branch February 18, 2019 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants