Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion inkcpp_compiler/binary_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,20 @@ void binary_emitter::build_container_hash_map(
// Search indexed children (which duplicates named childen...)
// TODO: Merge duplicate child arrays, very error-prone.
for (auto child : context->indexed_children) {
build_container_hash_map(hash_map, data, name, child.second);
// A named child was hashed above, under its own name. Walking it again here would hash its
// children under this container's name instead, one level short, and overwrite the right
// _hash with that: "body.dead" became "dead". Every named child is filed under index -1, and
// the map keeps only the first, so it hit the first-compiled knot of every story.
bool named = false;
for (const auto& named_child : context->named_children) {
if (named_child.second == child.second) {
named = true;
break;
}
}
if (! named) {
build_container_hash_map(hash_map, data, name, child.second);
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions inkcpp_test/MoveTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,31 @@ SCENARIO("run a story, but jump around manually", "[move-to][runtime]")
}
}
}

SCENARIO("the current knot is named by its full path", "[move-to][runtime]")
{
// Object keys come out of the compiler's JSON sorted, so "Dialog" is the first knot compiled
// and "Transformations" a later one. The first one's stitches were hashed by their bare names
// ("core"), every later one's by the full path, so which form get_current_knot() returned
// depended on where the knot fell in the alphabet. (A later knot's stitch: Tags.cpp,
// "knot2.sub".)
GIVEN("a story whose first knot has stitches")
{
std::unique_ptr<story> ink{story::from_file(INK_TEST_RESOURCE_DIR "MoveTo.bin")};
globals globStore = ink->new_globals();
runner thread = ink->new_runner(globStore);

WHEN("the story runs into a stitch of the first knot")
{
thread->getall();
THEN("the knot is its full path")
{
REQUIRE(thread->get_current_knot() == ink::hash_string("Dialog.core"));
}
}
WHEN("a stitch is looked up by its bare name")
{
THEN("it is not found") { REQUIRE_FALSE(thread->move_to(ink::hash_string("core"))); }
}
}
}
Loading