94 result.status = EditorStatus::Rejected;
95 diagnostic(
result,
"editor.animation.wrong-domain",
"Graph is not an animation state document");
98 if (
graph.schemaVersion != 1) {
99 result.status = EditorStatus::Unsupported;
100 diagnostic(
result,
"editor.animation.unsupported-schema",
"Animation graph schema version is unsupported");
105 const auto* entry = entryValue ? entryValue->getIf<std::string>() :
nullptr;
106 if (!
parameters || !entry || entry->empty()) {
107 result.status = EditorStatus::Failed;
108 diagnostic(
result,
"editor.animation.entry-required",
"Animation graph requires an entry state parameter");
112 std::map<GraphNodeId, const GraphNodeRecord*>
nodes;
113 std::map<GraphPinId, const GraphNodeRecord*> pinOwners;
115 if (
node.type !=
"animation.state" &&
node.type !=
"animation.transition") {
116 diagnostic(
result,
"editor.animation.unknown-node",
"Unknown animation node type: " +
node.type);
120 diagnostic(
result,
"editor.animation.duplicate-node",
"Duplicate animation node id: " +
node.id.value());
123 const auto entryNode =
nodes.find(GraphNodeId(*entry));
124 if (entryNode ==
nodes.end() || entryNode->second->type !=
"animation.state")
125 diagnostic(
result,
"editor.animation.invalid-entry",
"Entry does not reference an animation state node");
127 std::map<GraphNodeId, GraphNodeId> transitionFrom;
128 std::map<GraphNodeId, GraphNodeId> transitionTo;
130 const auto fromOwner = pinOwners.find(
edge.from);
131 const auto toOwner = pinOwners.find(
edge.to);
132 if (fromOwner == pinOwners.end() || toOwner == pinOwners.end()) {
133 diagnostic(
result,
"editor.animation.dangling-edge",
"Animation edge references a missing pin");
138 if (
from->type ==
"animation.state" &&
to->type ==
"animation.transition") {
139 if (!transitionFrom.emplace(
to->id,
from->id).second)
140 diagnostic(
result,
"editor.animation.multiple-transition-sources",
141 "Transition has more than one source state: " +
to->id.value());
142 }
else if (
from->type ==
"animation.transition" &&
to->type ==
"animation.state") {
143 if (!transitionTo.emplace(
from->id,
to->id).second)
144 diagnostic(
result,
"editor.animation.multiple-transition-destinations",
145 "Transition has more than one destination state: " +
from->id.value());
147 diagnostic(
result,
"editor.animation.invalid-flow",
148 "Flow must alternate state and transition nodes");
151 std::ostringstream definition;
152 definition <<
"EVANIM_STATE_GRAPH 1\n" <<
"entry " <<
quote(*entry) <<
'\n';
154 if (
node->type !=
"animation.state")
continue;
155 const auto* clipValue = field(
node->properties,
"clip");
156 const auto* speedValue = field(
node->properties,
"speed");
157 const auto* loopValue = field(
node->properties,
"loop");
158 const auto*
clip = clipValue ? clipValue->getIf<std::string>() :
nullptr;
159 const auto* speed = speedValue ? speedValue->getIf<
double>() :
nullptr;
160 const auto*
loop = loopValue ? loopValue->getIf<
bool>() :
nullptr;
161 if (!
clip ||
clip->empty() || !speed || *speed <= 0.0 || !
loop) {
162 diagnostic(
result,
"editor.animation.invalid-state-properties",
163 "State requires clip, positive speed and loop properties: " +
id.
value());
167 << (*
loop ? 1 : 0) <<
'\n';
170 if (
node->type !=
"animation.transition")
continue;
171 if (!transitionFrom.contains(
id) || !transitionTo.contains(
id)) {
172 diagnostic(
result,
"editor.animation.incomplete-transition",
173 "Transition requires exactly one source and destination: " +
id.
value());
176 const auto*
blend = field(
node->properties,
"blendSeconds");
177 const auto* hasExit = field(
node->properties,
"hasExitTime");
178 const auto* exitTime = field(
node->properties,
"exitTime");
179 const auto*
kind = field(
node->properties,
"conditionKind");
180 const auto*
parameter = field(
node->properties,
"parameter");
181 const auto* op = field(
node->properties,
"operator");
182 const auto* threshold = field(
node->properties,
"threshold");
183 const auto* boolValue = field(
node->properties,
"boolValue");
184 const auto* blendNumber =
blend ?
blend->getIf<
double>() :
nullptr;
185 const auto* exitEnabled = hasExit ? hasExit->getIf<
bool>() :
nullptr;
186 const auto* exitNumber = exitTime ? exitTime->getIf<
double>() :
nullptr;
187 const auto* kindName =
kind ?
kind->getIf<std::string>() :
nullptr;
189 const auto* operatorName = op ? op->getIf<std::string>() :
nullptr;
190 const auto* thresholdNumber = threshold ? threshold->getIf<
double>() :
nullptr;
191 const auto* boolFlag = boolValue ? boolValue->getIf<
bool>() :
nullptr;
192 const bool kindValid = kindName && (*kindName ==
"none" || *kindName ==
"float" ||
193 *kindName ==
"bool" || *kindName ==
"trigger");
194 const bool opValid = operatorName && (*operatorName ==
">" || *operatorName ==
">=" ||
195 *operatorName ==
"<" || *operatorName ==
"<=" ||
196 *operatorName ==
"==" || *operatorName ==
"!=");
197 if (!blendNumber || *blendNumber < 0.0 || !exitEnabled || !exitNumber || *exitNumber < 0.0 ||
198 *exitNumber > 1.0 || !kindValid || !parameterName || !operatorName || !thresholdNumber ||
199 !boolFlag || (*kindName !=
"none" && parameterName->empty()) ||
200 (*kindName ==
"float" && !opValid)) {
201 diagnostic(
result,
"editor.animation.invalid-transition-properties",
202 "Transition metadata is invalid: " +
id.
value());
205 definition <<
"transition " <<
quote(
id.
value()) <<
' ' <<
quote(transitionFrom[
id].
value()) <<
' '
206 <<
quote(transitionTo[
id].
value()) <<
' ' << *blendNumber <<
' '
207 << (*exitEnabled ? 1 : 0) <<
' ' << *exitNumber <<
' ' <<
quote(*kindName) <<
' '
208 <<
quote(*parameterName) <<
' ' <<
quote(*operatorName) <<
' ' << *thresholdNumber <<
' '
209 << (*boolFlag ? 1 : 0) <<
'\n';
211 if (!
result.diagnostics.empty()) {
212 result.status = EditorStatus::Failed;
215 result.status = EditorStatus::Applied;
216 result.definition = definition.str();
Result< GraphNodeRecord > makeStateNode(const GraphNodeId &id, const std::string &clipAsset) const
Construct a state node referencing one animation clip asset.
std::string domain() const override
Domain.
AnimationGraphCompileResult compile(const GraphDocumentData &graph) const
Validate and compile a graph into a deterministic runtime-neutral definition.
Result< GraphNodeRecord > makeTransitionNode(const GraphNodeId &id) const
Construct a transition node with default blend metadata.
GraphConnectionDecision canConnect(const GraphPinRecord &from, const GraphPinRecord &to) const override
Can connect.
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.