载入中...
搜索中...
未找到
StylizeAction.cpp
浏览该文件的文档.
2
4#include "common/Value.h"
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <cstdint>
10#include <string>
11#include <string_view>
12#include <utility>
13
14namespace eve::stylize_action {
15
24
25namespace {
26
27eve::stylize::AttackVfxHandle makeHandle(std::uint32_t slot, std::uint32_t generation) {
29}
30
32 return eve::Value::Object{{"slot", static_cast<std::int64_t>(handle.slot)},
33 {"generation", static_cast<std::int64_t>(handle.generation)}};
34}
35
36eve::Value projectFrame(eve::stylize::AttackVfxFrame frame) {
38 events.reserve(frame.events.size());
39 for (const auto& event : frame.events) {
40 std::string kind = "cueIgnored";
41 switch (event.kind) {
45 kind = "instanceStopped";
46 break;
51 }
52 events.push_back(eve::Value::Object{
53 {"kind", kind},
54 {"role", std::string(eve::stylize::attackVfxLayerRoleName(event.role))},
55 {"cue", event.cue},
56 {"layerIndex", static_cast<std::int64_t>(event.layerIndex)},
57 {"layerCount", static_cast<std::int64_t>(event.layerCount)},
58 });
59 }
60 return eve::Value::Object{{"advancedCount", static_cast<std::int64_t>(frame.advanced.size())},
61 {"stoppedCount", static_cast<std::int64_t>(frame.stopped.size())},
62 {"eventCount", static_cast<std::int64_t>(frame.events.size())},
63 {"events", std::move(events)}};
64}
65
67 std::int64_t activePhases = 0;
68 for (const auto& phase : state.phases)
69 if (phase.active) ++activePhases;
70 return eve::Value::Object{
71 {"slot", static_cast<std::int64_t>(state.handle.slot)},
72 {"generation", static_cast<std::int64_t>(state.handle.generation)},
73 {"recipeId", state.recipeId.format()},
74 {"age", state.age},
75 {"stopping", state.stopping},
76 {"phaseCount", static_cast<std::int64_t>(state.phases.size())},
77 {"activeCount", activePhases},
78 };
79}
80
81eve::stylize::AttackVfxStopMode parseStopMode(std::string_view mode) {
82 if (mode == "stop" || mode == "stopEmitting") return eve::stylize::AttackVfxStopMode::StopEmitting;
84}
85
86} // namespace
87
89
96
103
105 auto parsed = eve::stylize::AttackVfxRecipe::fromJson(json);
106 if (!parsed) return eve::Result<void>::failure(parsed.status());
107 return runtime_.registerRecipe(std::move(parsed).takeValue());
108}
109
111 auto parsed = eve::stylize::AttackVfxSkin::fromJson(json);
112 if (!parsed) return eve::Result<void>::failure(parsed.status());
113 return runtime_.registerSkin(std::move(parsed).takeValue());
114}
115
117 std::uint32_t sourceId,
118 std::uint32_t targetId) {
119 auto parsed = eve::LogicalId::parse(recipeId);
120 if (!parsed)
122 eve::DiagnosticCode::InvalidArgument, "recipeId is not a LogicalId", "recipeId"));
125 request.targetId = targetId;
126 return runtime_.play(*parsed, request);
127}
128
130 std::uint32_t generation,
131 std::string_view cue) {
132 return runtime_.signal(makeHandle(slot, generation), cue);
133}
134
136 return runtime_.advance(dtSeconds);
137}
138
140 std::uint32_t generation,
141 std::string_view mode) {
142 return runtime_.stop(makeHandle(slot, generation), parseStopMode(mode));
143}
144
146 std::uint32_t generation) {
147 auto snapshot = runtime_.inspect(makeHandle(slot, generation));
148 if (!snapshot)
150 eve::DiagnosticCode::NotFound, "AttackVfx handle is stale", "handle"));
152}
153
154std::size_t StylizeAction::activeCount() const noexcept { return runtime_.activeCount(); }
155
156void StylizeAction::expose(ssq::Table& table) {
157 auto module = table.addClass(name, StylizeAction::create, false);
158 expose(module);
159}
160
161void StylizeAction::expose(ssq::Class& cls) {
162 const auto vm = cls.getHandle();
163 cls.addFunc("registerRecipeJson", [vm](StylizeAction* self, const std::string& json) {
164 auto result = self ? self->registerRecipeJson(json)
165 : eve::Result<void>::failure(eve::Diagnostic::error(
166 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
167 return eve::script::projectResult(vm, std::move(result));
168 });
169 cls.addFunc("registerSkinJson", [vm](StylizeAction* self, const std::string& json) {
170 auto result = self ? self->registerSkinJson(json)
172 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
173 return eve::script::projectResult(vm, std::move(result));
174 });
175 cls.addFunc("play", [vm](StylizeAction* self, const std::string& recipeId, int sourceId,
176 int targetId) {
177 auto result =
178 self ? self->play(recipeId, static_cast<std::uint32_t>(sourceId < 0 ? 0 : sourceId),
179 static_cast<std::uint32_t>(targetId < 0 ? 0 : targetId))
180 : eve::Result<eve::stylize::AttackVfxHandle>::failure(eve::Diagnostic::error(
181 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
182 return eve::script::projectResult(vm, std::move(result),
184 return projectHandle(handle);
185 });
186 });
187 cls.addFunc("signal", [vm](StylizeAction* self, int slot, int generation, const std::string& cue) {
188 auto result =
189 self ? self->signal(static_cast<std::uint32_t>(slot < 0 ? 0 : slot),
190 static_cast<std::uint32_t>(generation < 0 ? 0 : generation), cue)
191 : eve::Result<eve::stylize::AttackVfxFrame>::failure(eve::Diagnostic::error(
192 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
193 return eve::script::projectResult(vm, std::move(result),
195 return projectFrame(std::move(frame));
196 });
197 });
198 cls.addFunc("advance", [vm](StylizeAction* self, float dt) {
199 auto result = self ? self->advance(static_cast<double>(dt))
200 : eve::Result<eve::stylize::AttackVfxFrame>::failure(eve::Diagnostic::error(
201 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
202 return eve::script::projectResult(vm, std::move(result),
204 return projectFrame(std::move(frame));
205 });
206 });
207 cls.addFunc("stop", [vm](StylizeAction* self, int slot, int generation, const std::string& mode) {
208 auto result =
209 self ? self->stop(static_cast<std::uint32_t>(slot < 0 ? 0 : slot),
210 static_cast<std::uint32_t>(generation < 0 ? 0 : generation), mode)
211 : eve::Result<eve::stylize::AttackVfxFrame>::failure(eve::Diagnostic::error(
212 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
213 return eve::script::projectResult(vm, std::move(result),
215 return projectFrame(std::move(frame));
216 });
217 });
218 cls.addFunc("inspect", [vm](StylizeAction* self, int slot, int generation) {
219 auto result =
220 self ? self->inspect(static_cast<std::uint32_t>(slot < 0 ? 0 : slot),
221 static_cast<std::uint32_t>(generation < 0 ? 0 : generation))
222 : eve::Result<eve::stylize::AttackVfxInstanceState>::failure(eve::Diagnostic::error(
223 eve::DiagnosticCode::NotFound, "StylizeAction unavailable", "self"));
224 return eve::script::projectResult(vm, std::move(result),
226 return projectInstance(std::move(state));
227 });
228 });
229 cls.addFunc("activeCount", [](StylizeAction* self) -> int {
230 return self ? static_cast<int>(self->activeCount()) : 0;
231 });
232}
233
234} // namespace eve::stylize_action
bool & active
Data-driven layered attack VFX recipe and element skin (Phase 1 schema).
float phase
Definition CaveMesh.cpp:58
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
std::uint64_t sourceId
const GltfImportRequest & request
TokenKind kind
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
std::string error
Definition Package.cpp:60
std::uint32_t generation
std::uint32_t targetId
PrimitiveHandle handle
The single Squirrel projection for common Result, Status and Value.
Action/camera adapter satellite for AttackVfx presentation blocks.
Battle::Events events
Owning, renderer-independent dynamic values.
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
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 std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
Result< void > registerSkin(const AttackVfxSkin &skin)
Validate and store a reusable skin keyed by skin.id.
std::optional< AttackVfxInstanceState > inspect(AttackVfxHandle handle) const
Snapshot one live instance; empty when the handle is stale.
Result< AttackVfxFrame > stop(AttackVfxHandle handle, AttackVfxStopMode mode)
Stop one instance using the requested teardown mode.
Result< void > registerRecipe(const AttackVfxRecipe &recipe)
Validate and store an immutable recipe copy keyed by recipe.id.
std::size_t activeCount() const noexcept
Number of occupied slots.
Result< AttackVfxHandle > play(const LogicalId &recipeId, const AttackVfxRequest &request)
Spawn one instance from a registered recipe.
Result< AttackVfxFrame > signal(AttackVfxHandle handle, std::string_view cue)
Deliver a named cue to one live instance (e.g. "impact", "cancel").
Result< AttackVfxFrame > advance(double dtSeconds)
Advance all live instances by injected simulation seconds.
Composition entry for AttackVfx Action notify handlers and layer bridges.
eve::Result< eve::stylize::AttackVfxFrame > stop(std::uint32_t slot, std::uint32_t generation, std::string_view mode)
Stop one instance.
eve::Result< void > registerRecipeJson(std::string_view json)
Validate and register a JSON recipe document on the module runtime.
eve::Result< eve::stylize::AttackVfxFrame > signal(std::uint32_t slot, std::uint32_t generation, std::string_view cue)
Deliver a named cue to one live instance.
~StylizeAction() override
Stylize action.
eve::Result< eve::stylize::AttackVfxFrame > advance(double dtSeconds)
Advance all live instances by injected simulation seconds.
std::size_t activeCount() const noexcept
Number of occupied AttackVfx pool slots.
eve::Result< eve::stylize::AttackVfxInstanceState > inspect(std::uint32_t slot, std::uint32_t generation)
Snapshot one live instance; fails with NotFound when stale.
eve::Result< eve::stylize::AttackVfxHandle > play(std::string_view recipeId, std::uint32_t sourceId, std::uint32_t targetId)
Play a registered recipe on the module runtime.
eve::Result< void > registerSkinJson(std::string_view json)
Validate and register a JSON skin document on the module runtime.
eve::Diagnostic Diagnostic
eve::Result< T > Result
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
void unregisterPrefabAttackVfxExecutor()
void unregisterAudioAttackVfxExecutor()
AttackVfxStopMode
How stop() tears down an instance.
std::string_view attackVfxLayerRoleName(AttackVfxLayerRole role) noexcept
Stable JSON spelling for a layer role.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
Owning result of one atomic orchestration step.
std::vector< AttackVfxHandle > advanced
std::vector< AttackVfxFrameEvent > events
std::vector< AttackVfxHandle > stopped
Generation-qualified reference to one pooled attack VFX instance.
Owning observable state for one live instance.
static Result< AttackVfxRecipe > fromJson(std::string_view json)
Parse, validate, and return a complete recipe without mutating live state.
static Result< AttackVfxSkin > fromJson(std::string_view json)
Parse a standalone skin document.