Add optional Lua scripting module, examples, and validation

This commit is contained in:
emil28092005
2026-09-18 11:28:50 +03:00
parent 06210aac23
commit 5a67735ff4
45 changed files with 3887 additions and 92 deletions
+28 -4
View File
@@ -1,27 +1,51 @@
#include "Gameplay.hpp"
#include <faset/core/io.hpp>
#include <faset/runtime/schema.hpp>
#include <faset/scripting/project.hpp>
#if defined(FASET_HAS_LUA)
#include <faset/scripting/LuaModule.hpp>
#endif
#include <iostream>
#include <stdexcept>
int schema_main(int argc, char** argv) {
try {
std::filesystem::path output;
std::filesystem::path output, projectRoot;
for (int i = 1; i < argc; ++i) {
const std::string argument = argv[i];
if (argument == "--help") {
std::cout << "faset_schema_exporter [--output PATH]\nExports declarative gameplay "
"schemas without creating a world.\n";
std::cout << "faset_schema_exporter [--output PATH] [--project ROOT]\n"
"Exports C++ and declared Lua gameplay schemas without creating a "
"world or invoking lifecycle callbacks.\n";
return 0;
}
if (argument == "--output" && i + 1 < argc && output.empty())
output = faset::path_from_utf8(argv[++i]);
else if (argument == "--project" && i + 1 < argc && projectRoot.empty())
projectRoot = faset::path_from_utf8(argv[++i]);
else
throw std::invalid_argument("Unknown, repeated or incomplete argument: " +
argument);
}
const auto types = faset::gameplay::schema();
auto types = faset::gameplay::schema();
if (!types.is_array())
throw std::runtime_error("Gameplay schema() must return a type array");
if (!projectRoot.empty()) {
const auto project = faset::scripting::loadLuaProject(projectRoot);
if (project.enabled()) {
#if defined(FASET_HAS_LUA)
faset::scripting::LuaModule lua(project);
for (const auto& type : lua.schema())
types.push_back(type);
#else
throw std::runtime_error("This schema exporter was built without Lua support; "
"configure FASET_ENABLE_LUA=ON for this project");
#endif
}
}
// Check all IDs, including unused types, before publishing a manifest.
// This player-side boundary intentionally has no authoring dependency.
faset::runtime::validate_scene_schemas({{"entities", nlohmann::json::array()}}, types);
const nlohmann::json manifest{{"format", "faset.schema"}, {"version", 1}, {"types", types}};
if (output.empty())
std::cout << manifest.dump(2) << '\n';