0ad/source/simulation2
trompetin17 5b8cb7f34b
Support std::optional in FromJSVal
This commit introduces support for std::optional<T> in
Script::FromJSVal. When a JavaScript value is undefined or null, the
resulting optional is set to std::nullopt; otherwise, the value is
converted and wrapped.

This change allows components to cleanly handle optional script values
without needing manual null checks or exception handling in C++.

As a direct application of this feature, the Identity component now uses
std::optional<std::wstring> for the return value of GetCiv(). This
resolves a bug where formation templates (e.g., those inheriting from
template_formation.xml) do not explicitly define a civ. After commit
03f7903fec, the code assumed GetCiv() would always return a valid
string, leading to undefined behavior when it was missing.

With this update:
- GetCiv() returning undefined results in an empty optional.
- The Identity component defaults to an empty civilization string ("")
  when the civ is not defined.
- This avoids crashes or actor parsing errors for civ-less templates and
  improves robustness in script-C++ interaction.

Closes: #8107
Fixes: #8091
2025-06-19 08:52:24 -05:00
..
components Support std::optional in FromJSVal 2025-06-19 08:52:24 -05:00
docs Remove the name of some unused arguments 2025-06-18 12:49:59 +02:00
helpers Remove the name of some unused arguments 2025-06-18 12:49:59 +02:00
scripting Remove the name of some unused arguments 2025-06-18 12:49:59 +02:00
serialization Fix no-pch build following #7829 2025-05-11 11:24:50 +02:00
system Remove the name of some unused arguments 2025-06-18 12:49:59 +02:00
tests Fix a bunch of spelling mistakes 2025-04-11 06:24:32 +02:00
MessageTypes.h Store whether a player is activ in C++ 2025-01-05 19:57:12 +01:00
Simulation2.cpp Stop running shrinking gcs & simplify GC logic. 2025-04-22 17:03:29 +02:00
Simulation2.h Don't use std::shared_ptr<ScriptContext> in the CSimulation2 2024-03-08 17:15:25 +00:00
TypeList.h Store whether a player is activ in C++ 2025-01-05 19:57:12 +01:00