Add action file loops and display the GPLv3 notice at console startup

This commit is contained in:
cantyonion committed 2026-11-24 16:44:34 +08:00
1 parent 12c7332337
commit b8799a62e7
9 files changed
+305 -47

No files matched your search

+10 -2
View File
@@ -4,6 +4,7 @@
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
@@ -24,7 +25,9 @@ enum class ActionKind
Drop,
SendCommand,
SendMessage,
Wait
Wait,
LoopBegin,
LoopEnd
};
enum class EntityFace
@@ -53,6 +56,9 @@ struct ActionCommand
// Click entry: target an item frame; Any searches all six block faces.
bool entity = false;
EntityFace entityFace = EntityFace::Any;
// LoopBegin: nullopt repeats forever. loopEnd indexes the matching LoopEnd.
std::optional<std::uint64_t> repetitions;
std::size_t loopEnd = 0;
};
struct ActionProgram
@@ -68,6 +74,8 @@ struct ActionProgram
// must be simple names resolving to same-directory name.act files whose action
// headers match. Cycles and symlink escapes are rejected. Limits: 32 active
// files, 100000 expanded commands, 4096 file loads, 1 MiB/file and 16 MiB total.
// do COUNT executes the next statement, or a begin/end block. COUNT may be
// an unsigned decimal integer or always. Loop iterations are scheduled lazily.
// Wait syntax: wait digits[.digits] [s|ms|min|h|d], default s. The duration
// must be an exact whole number of milliseconds and may not exceed 365 days.
// Clicks optionally accept entry [t|b|s|n|w|e] (or full face names), with
@@ -76,7 +84,7 @@ struct ActionProgram
ActionProgram LoadActionFile(const std::filesystem::path &path, CommandBindings bindings = {});
// Parse one console game instruction using the .act grammar, without file I/O.
// Blank/comment lines return nullopt. Wait/import require `run file.act` instead.
// Blank/comment lines return nullopt. Wait/import/loops require `run file.act`.
// CR, LF and NUL are rejected; errors throw with <console>:1 context.
std::optional<ActionCommand> ParseInteractiveCommand(std::string_view text);
} // namespace Bilicraft
+6
View File
@@ -49,6 +49,11 @@ class ActionScheduler
std::vector<std::string> DrainEvents();
private:
struct LoopFrame
{
std::size_t body;
std::optional<std::uint64_t> remaining;
};
struct Task
{
TaskId id;
@@ -57,6 +62,7 @@ class ActionScheduler
State state = State::Ready;
Clock::time_point wakeAt{};
std::uint64_t readyOrder = 0;
std::vector<LoopFrame> loops;
};
void RemoveActive(bool success);
std::map<TaskId, Task> tasks;