Refactor view count map creation

This commit is contained in:
2019-03-26 11:35:09 -06:00
parent efebbdf212
commit ad877b4351
4 changed files with 15 additions and 7 deletions

View File

@@ -28,6 +28,8 @@ class HInterface {
if (variables.exists(name)) {
return variables[name];
} else {
trace(Type.typeof(container)) ;
trace(Type.typeof(container).getName()) ;
if (Type.typeof(container).getName() == 'StoryNode') {
var node: StoryNode = cast(container, StoryNode);
switch (node.resolve(name)) {

View File

@@ -37,10 +37,7 @@ class Story {
ast = parser.parseFile(script);
storyTree = StoryNode.FromAST(ast);
viewCounts = new Map();
for (node in storyTree.traverseAll()) {
viewCounts[node] = 0;
}
viewCounts = storyTree.createViewCounts();
hInterface = new HInterface(storyTree, viewCounts);
hInterface.addVariable('story', this);

View File

@@ -34,6 +34,14 @@ class StoryNode {
return nodes;
}
public function createViewCounts(): Map<StoryNode, Int> {
var viewCounts = new Map();
for (node in traverseAll()) {
viewCounts[node] = 0;
}
return viewCounts;
}
public static function FromAST(ast: HankAST) {
var exprIndex = 0;
var root = new StoryNode(-1);

View File

@@ -15,10 +15,11 @@ class HInterfaceTest extends utest.Test {
public function setup() {
var storyTree = StoryNode.FromAST(new Parser().parseFile("examples/subsections/main.hank"));
hInterface = new HInterface(storyTree, [
storyTree.resolve("start").unwrap() => 5,
var viewCounts = storyTree.createViewCounts();
]);
viewCounts[storyTree.resolve("start").unwrap()] = 5;
hInterface = new HInterface(storyTree, viewCounts);
}
function assertExpr(name: String, value: Dynamic) {