Allow AsInt from Float EffectParameter, and AsFloat from Int EffectParameter.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f65b2f74bd
commit
119e71e86a
|
@ -34,6 +34,9 @@ namespace CreatureLib::Library {
|
||||||
}
|
}
|
||||||
int64_t AsInt() const {
|
int64_t AsInt() const {
|
||||||
if (_type != EffectParameterType::Int) {
|
if (_type != EffectParameterType::Int) {
|
||||||
|
if (_type == EffectParameterType::Float) {
|
||||||
|
return static_cast<int64_t>(std::get<float>(_value));
|
||||||
|
}
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type);
|
ss << "Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type);
|
||||||
throw CreatureException(ss.str());
|
throw CreatureException(ss.str());
|
||||||
|
@ -42,6 +45,9 @@ namespace CreatureLib::Library {
|
||||||
}
|
}
|
||||||
float AsFloat() const {
|
float AsFloat() const {
|
||||||
if (_type != EffectParameterType::Float) {
|
if (_type != EffectParameterType::Float) {
|
||||||
|
if (_type == EffectParameterType::Int) {
|
||||||
|
return static_cast<float>(std::get<int64_t>(_value));
|
||||||
|
}
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type);
|
ss << "Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type);
|
||||||
throw CreatureException(ss.str());
|
throw CreatureException(ss.str());
|
||||||
|
|
|
@ -13,6 +13,7 @@ TEST_CASE("Bool EffectParameter", "[Library]") {
|
||||||
TEST_CASE("Int EffectParameter", "[Library]") {
|
TEST_CASE("Int EffectParameter", "[Library]") {
|
||||||
auto p = EffectParameter((int64_t)684);
|
auto p = EffectParameter((int64_t)684);
|
||||||
REQUIRE(p.AsInt() == 684);
|
REQUIRE(p.AsInt() == 684);
|
||||||
|
REQUIRE(p.AsFloat() == 684);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("String EffectParameter", "[Library]") {
|
TEST_CASE("String EffectParameter", "[Library]") {
|
||||||
|
@ -23,6 +24,7 @@ TEST_CASE("String EffectParameter", "[Library]") {
|
||||||
TEST_CASE("Float EffectParameter", "[Library]") {
|
TEST_CASE("Float EffectParameter", "[Library]") {
|
||||||
auto p = EffectParameter(1.5f);
|
auto p = EffectParameter(1.5f);
|
||||||
REQUIRE(p.AsFloat() == Approx(1.5f));
|
REQUIRE(p.AsFloat() == Approx(1.5f));
|
||||||
|
REQUIRE(p.AsInt() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue