blueshell
Advanced tools
Comparing version 3.4.2-whileBtv.5 to 3.4.2-whileBtv.6
@@ -28,3 +28,3 @@ "use strict"; | ||
Base_1.Action.treePublisher.publishResult(state, event, false); | ||
Parent_1.modifyLastEventSeenRecursive(this, state, () => ({ action: 'clear' })); | ||
Parent_1.clearEventSeenRecursive(this, state); | ||
return this.handleEvent(state, event); | ||
@@ -31,0 +31,0 @@ } |
@@ -22,7 +22,8 @@ "use strict"; | ||
if (storage.running || this.conditional(state, event)) { | ||
if (storage.ranAtLeastOnce) { | ||
if (storage.beganAtLeastOneLoop) { | ||
Base_1.Action.treePublisher.publishResult(state, event, false); | ||
Parent_1.modifyLastEventSeenRecursive(this.child, state, () => ({ action: 'clear' })); | ||
// clearEventSeenRecursive(this.child, state); | ||
Parent_1.clearEventSeenRecursive(this, state); | ||
} | ||
storage.ranAtLeastOnce = true; | ||
storage.beganAtLeastOneLoop = true; | ||
return handleEvent(state, event); | ||
@@ -44,17 +45,6 @@ } | ||
// teardown internal state and yield to the behavior tree because the loop has completed | ||
// if (storage.lastLoopResult) { | ||
// // While will see one additional event than the descendants when it evaluates the conditional | ||
// // and breaks out of the loop. We still want all descendants who ran on the last loop iteration | ||
// // to display their result in btv, so we will advance those that are behind by one event one event | ||
// // forward to compensate. | ||
// modifyLastEventSeenRecursive(this.child, state, (node: BaseNode<S, E>) => { | ||
// const s = node.getNodeStorage(state); | ||
// if (s.lastEventSeen && s.lastEventSeen === storage.lastEventSeen! - 1) { | ||
// return {action: 'set', value: storage.lastEventSeen!}; | ||
// } else { | ||
// return {action: 'none'}; | ||
// } | ||
// }); | ||
// } | ||
storage.ranAtLeastOnce = undefined; | ||
// FIXME - it is likely that if While is used as the root node, the that lastEventSeen | ||
// property of the decendants may not be correct due to the extra call to _beforeEvent | ||
// required for the while loop to break. | ||
storage.beganAtLeastOneLoop = undefined; | ||
storage.lastLoopResult = undefined; | ||
@@ -61,0 +51,0 @@ storage.break = undefined; |
@@ -12,15 +12,7 @@ import { BlueshellState, BaseNode, ParentNode } from '../models'; | ||
/** | ||
* Modify the lastEventSeen property recursively from a root node according to the supplied nodeQuery | ||
* Clears the last event seen property of node and all of node's children | ||
* @param node The node to clear | ||
* @param state The state holding the node storage | ||
* @param nodeQuery Criteria which dictates how to modify lastEventSeen on each node | ||
*/ | ||
export declare function modifyLastEventSeenRecursive<S extends BlueshellState, E>(node: BaseNode<S, E>, state: S, nodeQuery: (node: BaseNode<S, E>) => ({ | ||
action: 'none'; | ||
} | { | ||
action: 'clear'; | ||
} | { | ||
action: 'set'; | ||
value: number; | ||
})): void; | ||
export declare function clearEventSeenRecursive<S extends BlueshellState, E>(node: BaseNode<S, E>, state: S): void; | ||
/** | ||
@@ -27,0 +19,0 @@ * Base class for all nodes that expose a list of children. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Parent = exports.modifyLastEventSeenRecursive = exports.setEventCounter = void 0; | ||
exports.Parent = exports.clearEventSeenRecursive = exports.setEventCounter = void 0; | ||
const models_1 = require("../models"); | ||
@@ -26,27 +26,16 @@ const Base_1 = require("./Base"); | ||
/** | ||
* Modify the lastEventSeen property recursively from a root node according to the supplied nodeQuery | ||
* Clears the last event seen property of node and all of node's children | ||
* @param node The node to clear | ||
* @param state The state holding the node storage | ||
* @param nodeQuery Criteria which dictates how to modify lastEventSeen on each node | ||
*/ | ||
function modifyLastEventSeenRecursive(node, state, nodeQuery) { | ||
function clearEventSeenRecursive(node, state) { | ||
if (models_1.isParentNode(node)) { | ||
const children = node.getChildren(); | ||
children.forEach((child, index) => { | ||
modifyLastEventSeenRecursive(child, state, nodeQuery); | ||
node.getChildren().forEach((child) => { | ||
clearEventSeenRecursive(child, state); | ||
}); | ||
} | ||
const nodeQueryResult = nodeQuery(node); | ||
const nodeStorage = node.getNodeStorage(state); | ||
if (nodeQueryResult.action === 'none') { | ||
// do nothing | ||
} | ||
else if (nodeQueryResult.action === 'clear') { | ||
nodeStorage.lastEventSeen = undefined; | ||
} | ||
else if (nodeQueryResult.action === 'set') { | ||
nodeStorage.lastEventSeen = nodeQueryResult.value; | ||
} | ||
nodeStorage.lastEventSeen = undefined; | ||
} | ||
exports.modifyLastEventSeenRecursive = modifyLastEventSeenRecursive; | ||
exports.clearEventSeenRecursive = clearEventSeenRecursive; | ||
/** | ||
@@ -53,0 +42,0 @@ * Base class for all nodes that expose a list of children. |
import {ResultCode, BlueshellState, BaseNode, ConditionalWithResult} from '../../models'; | ||
import {Action} from '../Base'; | ||
import {Decorator} from '../Decorator'; | ||
import {modifyLastEventSeenRecursive} from '../Parent'; | ||
import {clearEventSeenRecursive} from '../Parent'; | ||
@@ -29,3 +29,3 @@ /** | ||
Action.treePublisher.publishResult(state, event, false); | ||
modifyLastEventSeenRecursive(this, state, () => ({action: 'clear'})); | ||
clearEventSeenRecursive(this, state); | ||
return this.handleEvent(state, event); | ||
@@ -32,0 +32,0 @@ } else { |
import {ResultCode, BlueshellState, BaseNode, rc, Conditional, NodeStorage} from '../../models'; | ||
import {Action} from '../Base'; | ||
import {Decorator} from '../Decorator'; | ||
import {modifyLastEventSeenRecursive} from '../Parent'; | ||
import {clearEventSeenRecursive} from '../Parent'; | ||
interface WhileNodeStorage extends NodeStorage { | ||
ranAtLeastOnce?: boolean; | ||
beganAtLeastOneLoop?: boolean; | ||
lastLoopResult?: ResultCode, | ||
@@ -31,7 +31,8 @@ break?: boolean, | ||
if (storage.running || this.conditional(state, event)) { | ||
if (storage.ranAtLeastOnce) { | ||
if (storage.beganAtLeastOneLoop) { | ||
Action.treePublisher.publishResult(state, event, false); | ||
modifyLastEventSeenRecursive(this.child, state, () => ({action: 'clear'})); | ||
// clearEventSeenRecursive(this.child, state); | ||
clearEventSeenRecursive(this, state); | ||
} | ||
storage.ranAtLeastOnce = true; | ||
storage.beganAtLeastOneLoop = true; | ||
return handleEvent(state, event); | ||
@@ -54,18 +55,7 @@ } else { | ||
// teardown internal state and yield to the behavior tree because the loop has completed | ||
// if (storage.lastLoopResult) { | ||
// // While will see one additional event than the descendants when it evaluates the conditional | ||
// // and breaks out of the loop. We still want all descendants who ran on the last loop iteration | ||
// // to display their result in btv, so we will advance those that are behind by one event one event | ||
// // forward to compensate. | ||
// modifyLastEventSeenRecursive(this.child, state, (node: BaseNode<S, E>) => { | ||
// const s = node.getNodeStorage(state); | ||
// if (s.lastEventSeen && s.lastEventSeen === storage.lastEventSeen! - 1) { | ||
// return {action: 'set', value: storage.lastEventSeen!}; | ||
// } else { | ||
// return {action: 'none'}; | ||
// } | ||
// }); | ||
// } | ||
storage.ranAtLeastOnce = undefined; | ||
// FIXME - it is likely that if While is used as the root node, the that lastEventSeen | ||
// property of the decendants may not be correct due to the extra call to _beforeEvent | ||
// required for the while loop to break. | ||
storage.beganAtLeastOneLoop = undefined; | ||
storage.lastLoopResult = undefined; | ||
@@ -72,0 +62,0 @@ storage.break = undefined; |
@@ -28,32 +28,14 @@ import {BlueshellState, BaseNode, ParentNode, isParentNode} from '../models'; | ||
/** | ||
* Modify the lastEventSeen property recursively from a root node according to the supplied nodeQuery | ||
* Clears the last event seen property of node and all of node's children | ||
* @param node The node to clear | ||
* @param state The state holding the node storage | ||
* @param nodeQuery Criteria which dictates how to modify lastEventSeen on each node | ||
*/ | ||
export function modifyLastEventSeenRecursive<S extends BlueshellState, E>( | ||
node: BaseNode<S, E>, | ||
state: S, | ||
nodeQuery: (node: BaseNode<S, E>,) => ( | ||
{action: 'none'} | {action: 'clear'} | {action: 'set', value: number} | ||
), | ||
): void { | ||
export function clearEventSeenRecursive<S extends BlueshellState, E>(node: BaseNode<S, E>, state: S) { | ||
if (isParentNode(node)) { | ||
const children = node.getChildren(); | ||
children.forEach((child: any, index: number) => { | ||
modifyLastEventSeenRecursive(child, state, nodeQuery); | ||
node.getChildren().forEach((child: any) => { | ||
clearEventSeenRecursive(child, state); | ||
}); | ||
} | ||
const nodeQueryResult = nodeQuery(node); | ||
const nodeStorage = node.getNodeStorage(state); | ||
if (nodeQueryResult.action === 'none') { | ||
// do nothing | ||
} else if (nodeQueryResult.action === 'clear') { | ||
nodeStorage.lastEventSeen = undefined; | ||
} else if (nodeQueryResult.action === 'set') { | ||
nodeStorage.lastEventSeen = nodeQueryResult.value; | ||
} | ||
nodeStorage.lastEventSeen = undefined; | ||
} | ||
@@ -60,0 +42,0 @@ |
@@ -103,3 +103,3 @@ { | ||
"types": "dist/index.d.ts", | ||
"version": "3.4.2-whileBtv.5" | ||
"version": "3.4.2-whileBtv.6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
170415
3734