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

Fix: support for compiled jsons ending with an container and not a DONE #56

Merged
merged 2 commits into from
Sep 22, 2023
Merged
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
11 changes: 4 additions & 7 deletions inkcpp/runner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ namespace ink::runtime::internal

bool runner_impl::has_tags() const
{
return _tags.size() > 0;
return num_tags() > 0;
}

size_t runner_impl::num_tags() const
Expand Down Expand Up @@ -1212,7 +1212,7 @@ namespace ink::runtime::internal
if (!_threads.empty())
{
on_done(false);
return;
break;
}
else if (_stack.has_frame(&type) && type == frame_type::function) // implicit return is only for functions
{
Expand All @@ -1222,12 +1222,9 @@ namespace ink::runtime::internal
// HACK
_ptr += sizeof(Command) + sizeof(CommandFlag);
execute_return();
} else if (_container.empty() && _ptr == _story->end()){
on_done(true);
}
/*else TODO I had to remove this to make a test work.... is this important? Have I broken something?
{
on_done(false); // do we need to not set _done here? It wasn't set in the original code #implieddone
return;
}*/
}
} break;
case Command::VISIT:
Expand Down
12 changes: 10 additions & 2 deletions inkcpp_cl/inkcpp_cl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void usage()
<< "Usage: inkcpp_cl <options> <json file>\n"
<< "\t-o <filename>:\tOutput file name\n"
<< "\t-p [<snapshot_file>]:\tPlay mode\n\toptional snapshot file to load\n\tto create a snapshot file enter '-1' as choice\n"
<< "\t--ommit-choice-tags:\tdo not print tags after choices, primarly used to be compatible with inkclecat output"
<< endl;
}

Expand All @@ -35,7 +36,10 @@ int main(int argc, const char** argv)

// Parse options
std::string outputFilename;
bool playMode = false, testMode = false, testDirectory = false;
bool playMode = false,
testMode = false,
testDirectory = false,
ommit_choice_tags = false;
std::string snapshotFile;
for (int i = 1; i < argc - 1; i++)
{
Expand All @@ -52,6 +56,10 @@ int main(int argc, const char** argv)
snapshotFile = argv[i];
}
}
else if (option == "--ommit-choice-tags")
{
ommit_choice_tags = true;
}
else if (option == "-t")
testMode = true;
else if (option == "-td")
Expand Down Expand Up @@ -180,7 +188,7 @@ int main(int argc, const char** argv)
for (const ink::runtime::choice& c : *thread)
{
std::cout << index++ << ": " << c.text();
if(c.has_tags()) {
if(!ommit_choice_tags && c.has_tags()) {
std::cout << "\n\t";
for(size_t i = 0; i < c.num_tags(); ++i) {
std::cout << "# " << c.get_tag(i) << " ";
Expand Down
4 changes: 3 additions & 1 deletion inkcpp_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_executable(inkcpp_test catch.hpp Main.cpp
FallbackFunction.cpp
LabelCondition.cpp
Observer.cpp
InkyJson.cpp
)

target_link_libraries(inkcpp_test PUBLIC inkcpp inkcpp_compiler inkcpp_shared)
Expand All @@ -29,11 +30,12 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif()

add_test(NAME UnitTests COMMAND $<TARGET_FILE:inkcpp_test>)

set (source "${CMAKE_CURRENT_SOURCE_DIR}/ink")
set (destination "${CMAKE_CURRENT_BINARY_DIR}/ink")
add_custom_command(
TARGET inkcpp_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${source} ${destination}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${source} ${destination}
DEPENDS ${destination}
COMMENT "symbolic link resources folder from ${source} => ${destination}"
)
33 changes: 33 additions & 0 deletions inkcpp_test/InkyJson.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "catch.hpp"
// #include "../inkcpp_cl/test.cpp"

#include <story.h>
#include <globals.h>
#include <runner.h>
#include <compiler.h>

using namespace ink::runtime;

static constexpr const char* OUTPUT_PART_1 = "Once upon a time...\n";
static constexpr const char* OUTPUT_PART_2 = "There were two choices.\nThey lived happily ever after.\n";
static constexpr size_t CHOICE = 0;

SCENARIO("run inklecate 1.1.1 story")
{
auto compiler = GENERATE("inklecate", "inky");
GIVEN(compiler)
{
auto input_file = std::string("ink/simple-1.1.1-") + compiler + ".json";
ink::compiler::run(input_file.c_str(), "simple.bin");
auto ink = story::from_file("simple.bin");
runner thread = ink->new_runner();

THEN("Expect normal output") {
REQUIRE(thread->getall() == OUTPUT_PART_1);
REQUIRE(thread->has_choices());
REQUIRE(thread->num_choices() == 2);
thread->choose(CHOICE);
REQUIRE(thread->getall() == OUTPUT_PART_2);
}
}
}
154 changes: 154 additions & 0 deletions inkcpp_test/ink/simple-1.1.1-inklecate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"inkVersion": 21,
"root": [
[
{
"->": "start"
},
[
"done",
{
"#n": "g-0"
}
],
null
],
"done",
{
"start": [
[
"^Once upon a time...",
"\n",
[
"ev",
{
"^->": "start.0.2.$r1"
},
{
"temp=": "$r"
},
"str",
{
"->": ".^.s"
},
[
{
"#n": "$r1"
}
],
"/str",
"/ev",
{
"*": ".^.^.c-0",
"flg": 18
},
{
"s": [
"^There were two choices.",
{
"->": "$r",
"var": true
},
null
]
}
],
[
"ev",
{
"^->": "start.0.3.$r1"
},
{
"temp=": "$r"
},
"str",
{
"->": ".^.s"
},
[
{
"#n": "$r1"
}
],
"/str",
"/ev",
{
"*": ".^.^.c-1",
"flg": 18
},
{
"s": [
"^There were four lines of content.",
{
"->": "$r",
"var": true
},
null
]
}
],
{
"c-0": [
"ev",
{
"^->": "start.0.c-0.$r2"
},
"/ev",
{
"temp=": "$r"
},
{
"->": ".^.^.2.s"
},
[
{
"#n": "$r2"
}
],
"\n",
{
"->": ".^.^.g-0"
},
{
"#f": 5
}
],
"c-1": [
"ev",
{
"^->": "start.0.c-1.$r2"
},
"/ev",
{
"temp=": "$r"
},
{
"->": ".^.^.3.s"
},
[
{
"#n": "$r2"
}
],
"\n",
{
"->": ".^.^.g-0"
},
{
"#f": 5
}
],
"g-0": [
"^They lived happily ever after.",
"\n",
"end",
null
]
}
],
null
]
}
],
"listDefs": {}
}
Loading
Loading