Checkpoint 1: implement native subsystems and begin the gameplay manual
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <faset/core/json.hpp>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace faset {
|
||||
class Error : public std::runtime_error {
|
||||
public:
|
||||
Error(std::string code, std::string message, Json details = Json::object())
|
||||
: std::runtime_error(std::move(message)), code_(std::move(code)), details_(std::move(details)) {}
|
||||
const std::string& code() const noexcept { return code_; }
|
||||
Json json() const { return {{"code", code_}, {"message", what()}, {"details", details_}}; }
|
||||
private:
|
||||
std::string code_;
|
||||
Json details_;
|
||||
};
|
||||
inline void require(bool condition, const std::string& code, const std::string& message) {
|
||||
if (!condition) throw Error(code, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace faset {
|
||||
std::string sha256(std::span<const std::byte> bytes);
|
||||
inline std::string sha256(std::string_view text) {
|
||||
return sha256(std::as_bytes(std::span(text.data(), text.size())));
|
||||
}
|
||||
std::string sha256_file(const std::filesystem::path& path);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <faset/core/json.hpp>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace faset {
|
||||
std::string new_id();
|
||||
std::string read_text(const std::filesystem::path& path);
|
||||
Json read_json(const std::filesystem::path& path);
|
||||
void atomic_write(const std::filesystem::path& path, std::string_view bytes);
|
||||
void atomic_write_json(const std::filesystem::path& path, const Json& value);
|
||||
// Rejects traversal and symlink escapes before project-scoped file operations.
|
||||
std::filesystem::path project_path(const std::filesystem::path& root, const std::filesystem::path& relative);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include <nlohmann/json.hpp>
|
||||
namespace faset { using Json = nlohmann::json; }
|
||||
Reference in New Issue
Block a user