Refactor view count map creation
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user