83 lines
2.5 KiB
C++
83 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "CommandBindings.h"
|
|
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace Bilicraft
|
|
{
|
|
enum class ActionKind
|
|
{
|
|
Goto,
|
|
RightClick,
|
|
LeftClick,
|
|
GuiRightClick,
|
|
GuiLeftClick,
|
|
SelectHotbar,
|
|
SwapBackpack,
|
|
Drop,
|
|
SendCommand,
|
|
SendMessage,
|
|
Wait
|
|
};
|
|
|
|
enum class EntityFace
|
|
{
|
|
Any,
|
|
Top,
|
|
Bottom,
|
|
South,
|
|
North,
|
|
West,
|
|
East
|
|
};
|
|
|
|
struct ActionCommand
|
|
{
|
|
ActionKind kind;
|
|
int x = 0, y = 0, z = 0, row = 0, col = 0, slot = 0;
|
|
bool shift = false, destroy = false;
|
|
// Drop: slot == 0 means the current main-hand hotbar slot; all drops the stack.
|
|
bool all = false;
|
|
std::string text, recipient;
|
|
std::filesystem::path source;
|
|
std::size_t line = 0;
|
|
// Wait: exact milliseconds, from zero (yield) through 365 days inclusive.
|
|
std::chrono::milliseconds waitDuration{0};
|
|
// Click entry: target an item frame; Any searches all six block faces.
|
|
bool entity = false;
|
|
EntityFace entityFace = EntityFace::Any;
|
|
};
|
|
|
|
struct ActionProgram
|
|
{
|
|
std::string name;
|
|
std::vector<ActionCommand> commands;
|
|
};
|
|
|
|
// Load UTF-8 .act text and expand imports in place. Coordinates/slots are 1-based
|
|
// where applicable; block coordinates remain signed integers. Errors throw
|
|
// std::runtime_error with source:line context (including import-site context).
|
|
// The entry file must have a .act extension. Action/import names omit .act and
|
|
// 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.
|
|
// 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
|
|
// the face immediately after entry. Existing shift and left-click destroy flags
|
|
// may appear before or after entry; omitted entry retains block-click behavior.
|
|
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.
|
|
// CR, LF and NUL are rejected; errors throw with <console>:1 context.
|
|
std::optional<ActionCommand> ParseInteractiveCommand(std::string_view text);
|
|
} // namespace Bilicraft
|