载入中...
搜索中...
未找到
RpgDialect.cpp
浏览该文件的文档.
46const eve::Value* field(const SequenceNode& node, const char* name) { return node.payload.find(name); }
72std::function<eve::Result<void>(const SequenceNode&)> exactlyOneOf(std::vector<std::string> names,
74 return [names = std::move(names), stepType = std::move(stepType)](const SequenceNode& node) -> eve::Result<void> {
86 eve::DiagnosticCode::InvalidArgument, "step '" + stepType + "' requires exactly one of " + expected, {}, {}, "rpg.dnut-story"));
107 eve::DiagnosticCode::InvalidArgument, "step '" + stepType + "' field '" + fieldName + "' must be one of " + accepted, {}, {}, "rpg.dnut-story"));
131 if (!forget || !forget->isString()) return failed("skill step: neither learn nor forget is set");
133 return failed("skill step: actor '" + actorId + "' does not know skill '" + forget->asString() + "'");
179 return failed("item step: bag does not hold " + std::to_string(quantity) + " of '" + remove->asString() +
188 if (!binding || !binding->equipment) return failed("equipment step: no equipment set is bound");
193 if (bagSlot < 0) return failed("equipment step: bag does not hold '" + equip->asString() + "'");
195 return failed("equipment step: cannot equip '" + equip->asString() + "' into slot '" + slotName + "'");
199 if (!unequip || !unequip->isString()) return failed("equipment step: neither equip nor unequip is set");
268 return failed(diagnostic ? diagnostic->message() : "move step: the movement controller failed");
273 return failed("move step: actor '" + request.actorId + "' cannot reach (" + formatCoordinate(request.x) +
315 return failed(diagnostic ? diagnostic->message() : "animation step: the playback controller failed");
320 return failed("animation step: target '" + request.targetId + "' cannot play clip '" + request.clip + "'");
372SequenceConditionOutcome evaluateCondition(const eve::Value& condition, const RpgStoryBinding* binding) {
405 expectedNumber = expected->isInt64() ? static_cast<double>(expected->asInt()) : expected->asDouble();
415StepField requiredField(std::string name, StepFieldType type) { return StepField{std::move(name), type, true}; }
416StepField optionalField(std::string name, StepFieldType type) { return StepField{std::move(name), type, false}; }
424 eve::DiagnosticCode::InvalidArgument, "step 'equipment' requires 'slot' when 'equip' is set", {}, {}, "rpg.dnut-story"));
453 optionalField("loop", StepFieldType::Boolean), optionalField("hold", StepFieldType::Boolean)}});
459 {requiredField("object", StepFieldType::String), optionalField("prompt", StepFieldType::String)}});
473 skill.fields = {requiredField("actor", StepFieldType::String), optionalField("learn", StepFieldType::String),
484 attribute.fields = {requiredField("actor", StepFieldType::String), requiredField("name", StepFieldType::String),
495 item.fields = {optionalField("add", StepFieldType::String), optionalField("remove", StepFieldType::String),
506 equipment.fields = {requiredField("actor", StepFieldType::String), optionalField("equip", StepFieldType::String),
521 flag.fields = {requiredField("name", StepFieldType::String), requiredField("state", StepFieldType::Boolean)};
530 variable.fields = {requiredField("name", StepFieldType::String), requiredField("op", StepFieldType::String),
553eve::Result<int> RpgStoryCatalogue::replaceFromDnutStrict(const std::string& source, const std::string& path) {
554 eve::dnut::DnutCompileOutput output = eve::dnut::compileDnut(source, path, rpgStoryStepRegistry());
568 eve::DiagnosticCode::InvalidArgument, "document declares no 'story' block", path, {}, "rpg.dnut-story"));
583bool RpgStoryCatalogue::contains(const std::string& storyId) { return storyCatalogue().contains(storyId); }
663 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "story '" + storyId + "' is not published", "storyId", {}, "rpg.dnut-story"));
668 const double completed = hasCompleted ? binding->gameState->getSelfVariable(scope, "completed") : 0.0;
671 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "persisted story-completion flag is invalid", scope + ".completed", {}, "rpg.dnut-story"));
676 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "non-repeatable story '" + storyId + "' is already complete", "storyId", {}, "rpg.dnut-story"));
686 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "persisted story cursor is not valid JSON", scope + ".cursor", {}, "rpg.dnut-story"));
691 const std::string message = diagnostic ? diagnostic->message() : "story cursor could not be restored";
694 eve::Diagnostic::error(eve::DiagnosticCode::Failed, message, scope + ".cursor", {}, "rpg.dnut-story"));
706 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "story '" + storyId + "' is not published", "storyId", {}, "rpg.dnut-story"));
721 eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation, "story session is not active", "advance", {}, "rpg.dnut-story"));
725 eve::Diagnostic::error(eve::DiagnosticCode::Failed, diagnostic ? diagnostic->message() : "story could not advance", "advance", {}, "rpg.dnut-story"));
734 eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation, "story session is not active", "select", {}, "rpg.dnut-story"));
738 eve::Diagnostic::error(eve::DiagnosticCode::Failed, diagnostic ? diagnostic->message() : "choice could not be selected", "select", {}, "rpg.dnut-story"));
747 eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation, "story session is not active", "resume", {}, "rpg.dnut-story"));
751 eve::Diagnostic::error(eve::DiagnosticCode::Failed, diagnostic ? diagnostic->message() : "story could not resume", "resume", {}, "rpg.dnut-story"));
788eve::Result<void> RpgStorySession::captureState(eve::Value& out) const { return impl_->runtime.captureState(out); }
790eve::Result<void> RpgStorySession::restoreState(const std::string& storyId, const eve::Value& in,
796 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "story '" + storyId + "' is not published", "storyId", {}, "rpg.dnut-story"));
801 const std::string message = diagnostic ? diagnostic->message() : "story cursor could not be restored";
Registry-driven compiler for the `.dnut` story dialect.
全局游戏状态:开关(bool)、变量(数字)、独立变量(按作用域)。
Generation-safe ordered RPG party relationships.
RPG vocabulary for the .dnut sequence language, plus its catalogue and session.
Cross-frame interpreter for compiled `.dnut` sequences.
Extensible step vocabulary, payload schema and dispatch.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:67
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:87
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
bool isNumeric() const noexcept
Return whether this value is an integer or finite number.
Definition Value.h:159
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:69
bool asBool() const
Return the boolean payload; the caller must have checked the kind.
Definition Value.cpp:81
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:124
Caller-owned interpreter over a compiled sequence asset.
Definition SequenceRuntime.h:67
void setHostContext(void *host)
Install the opaque consumer context forwarded to every step handler.
Definition SequenceRuntime.h:206
void setConditionEvaluator(ConditionEvaluator evaluator)
Definition SequenceRuntime.h:188
eve::Result< void > captureState(eve::Value &out) const
Capture the complete cursor, bindings, locals and call stack.
Definition SequenceRuntime.cpp:534
void setStepRegistry(const StepKindRegistry *registry)
Bind the step vocabulary; passing nullptr disables non-core steps.
Definition SequenceRuntime.h:190
void setAssetResolver(AssetResolver resolver)
Definition SequenceRuntime.h:187
Canonical step vocabulary owner and runtime handler router.
Definition StepKindRegistry.h:108
bool isInt64() const
True when the JSON number was an integer literal that fits Int64.
Definition Json.cpp:328
void clearSelfString(const std::string &scope, const std::string &name)
Remove one scoped string fact; no-op when absent.
Definition GameState.cpp:105
void setSelfString(const std::string &scope, const std::string &name, std::string value)
Scoped string facts (for example a .dnut story cursor JSON blob).
Definition GameState.cpp:88
bool hasSelfVariable(const std::string &scope, const std::string &name) const
True when self variable.
Definition GameState.cpp:82
void setSelfVariable(const std::string &scope, const std::string &name, double value)
独立变量:scope(如 "map:1:event:3")下按名字存数字。
Definition GameState.cpp:71
Authoritative ordered relationship between stable party member IDs and RPG actors....
Definition Party.h:24
static eve::Result< int > replaceFromDnutStrict(const std::string &source, const std::string &path)
Compile and atomically publish every story block of one document.
Definition RpgDialect.cpp:553
static std::vector< std::string > storyIds()
Return every published story id in lexical order.
Definition RpgDialect.cpp:585
static bool contains(const std::string &storyId)
Return whether an exact story id is published.
Definition RpgDialect.cpp:583
eve::dnut::SequenceRuntime runtime
Definition RpgDialect.cpp:595
void publishCompletion()
Record completion once a successful run leaves the runtime inactive.
Definition RpgDialect.cpp:640
RpgStoryBinding ownedBinding
Definition RpgDialect.cpp:596
bool snapshot(const std::string &id)
Snapshot the whole catalogue so nothing borrows it after a hot replacement.
Definition RpgDialect.cpp:615
void persistProgress()
Publish or clear the GameState-backed cursor after a transition.
Definition RpgDialect.cpp:622
std::map< std::string, eve::dnut::SequenceAsset > assets
Definition RpgDialect.cpp:594
void configureRuntime()
Install the resolver, vocabulary, host binding and condition evaluator.
Definition RpgDialect.cpp:602
Caller-owned cursor over one published .dnut story.
Definition RpgDialect.h:275
bool isBlocked() const
Whether the story is suspended and awaiting acknowledgement.
Definition RpgDialect.cpp:765
std::vector< std::string > getChoiceLabels() const
Authored labels of the current choice step, empty for other step types.
Definition RpgDialect.cpp:779
std::string getStepKind() const
Current step type (move, choice, wait, …), or an empty string.
Definition RpgDialect.cpp:769
eve::Result< void > resume(eve::Value result)
Resume a step whose handler suspended the story.
Definition RpgDialect.cpp:744
eve::Result< void > captureState(eve::Value &out) const
Capture the complete cursor for persistence.
Definition RpgDialect.cpp:788
eve::Result< void > begin(const std::string &storyId, RpgStoryBinding *binding)
Start a published story and run it to its first suspension point.
Definition RpgDialect.cpp:658
eve::Result< void > advance()
Acknowledge the presented move / animation / select / dialogue / message / camera / wait step and con...
Definition RpgDialect.cpp:718
eve::Result< void > restoreState(const std::string &storyId, const eve::Value &in, RpgStoryBinding *binding)
Restore a captured cursor into a fresh session.
Definition RpgDialect.cpp:790
std::string getStoryId() const
Owning copy of the running story id, or an empty string.
Definition RpgDialect.cpp:767
eve::Result< void > select(const std::string &routeLabel)
Answer a blocked choice step by its authored label.
Definition RpgDialect.cpp:731
bool isWaitingStep() const
Whether the suspension expects resume rather than advance.
Definition RpgDialect.cpp:766
std::function< StepOutcome(const SequenceNode &, const StepContext &)> StepHandler
Consumer-owned handler for one registered step type.
Definition StepKindRegistry.h:96
StepShape
Declares whether a step completes inside its call or suspends the runtime.
Definition StepKindRegistry.h:20
DnutCompileOutput compileDnut(std::string_view source, const std::string &path, const StepKindRegistry ®istry)
Compile every story block of one .dnut document.
Definition DnutCompiler.cpp:482
Result< T > failed(Status status, eve::DiagnosticCode code, RuleId rule, std::string message)
Construct a failed editing result with explicit status and diagnostic categories.
Definition EditingResult.h:70
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
StepKindRegistry & rpgStoryStepRegistry()
Process-local step vocabulary for the RPG story dialect.
Definition RpgDialect.cpp:548
@ Unavailable
The target or the clip cannot be played, so the animation step fails.
@ Finished
The clip was applied instantaneously, so the step completes inline.
@ Playing
Playback was accepted and is still running; the host acknowledges the step when it ends.
@ Arrived
The actor is already at the destination, so the step completes inline.
@ Unreachable
The destination cannot be reached, so the move step fails.
@ Travelling
The move was accepted and is still running; the host acknowledges the step when it ends.
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ InvariantViolation
@ Failed
@ ParseError
@ Conflict
Definition Container.h:602
Owning outcome of compiling one .dnut document.
Definition DnutCompiler.h:24
Immutable, parameterized and versioned compiled sequence.
Definition SequenceAsset.h:77
Outcome of one authored condition, as seen by the language core.
Definition SequenceRuntime.h:24
Borrowed execution context handed to one step handler.
Definition StepKindRegistry.h:79
Owning authoring/runtime contract for one step type.
Definition StepKindRegistry.h:45
Borrowed domain objects an RPG story step runs against.
Definition RpgDialect.h:169
GameState * gameState
Owner of switches, variables and per-story completion facts.
Definition RpgDialect.h:171