mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 13:11:19 +01:00
Nnnnn different fixes (#11415) 4b0ea7e631
* fix: invalidate effects when sorted * improve scripted converters code Co-authored-by: hernan <hernan@rive.app>
This commit is contained in:
@@ -1 +1 @@
|
||||
a08d538dbf15a1f997108de82b626df71226d271
|
||||
4b0ea7e6317c81f93d766c0ffd7ff60074851ed8
|
||||
|
||||
@@ -58,6 +58,8 @@ private:
|
||||
static const int m_wantsPointerCancelBit = 1 << 7;
|
||||
static const int m_drawsBit = 1 << 8;
|
||||
static const int m_initsBit = 1 << 9;
|
||||
static const int m_dataConvertsBit = 1 << 10;
|
||||
static const int m_dataReverseConvertsBit = 1 << 11;
|
||||
|
||||
int m_implementedMethods = 0;
|
||||
|
||||
@@ -104,6 +106,14 @@ public:
|
||||
}
|
||||
bool draws() { return (m_implementedMethods & m_drawsBit) != 0; }
|
||||
bool inits() { return (m_implementedMethods & m_initsBit) != 0; }
|
||||
bool dataConverts()
|
||||
{
|
||||
return (m_implementedMethods & m_dataConvertsBit) != 0;
|
||||
}
|
||||
bool dataReverseConverts()
|
||||
{
|
||||
return (m_implementedMethods & m_dataReverseConvertsBit) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
class ModuleDetails
|
||||
|
||||
@@ -35,6 +35,7 @@ private:
|
||||
virtual void disposeScriptInputs() override;
|
||||
#ifdef WITH_RIVE_SCRIPTING
|
||||
DataValue* applyConversion(DataValue* value, const std::string& method);
|
||||
bool pushDataValue(DataValue*);
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
@@ -142,6 +142,21 @@ bool OptionalScriptedMethods::verifyImplementation(ScriptedObject* object,
|
||||
}
|
||||
rive_lua_pop(state, 1);
|
||||
}
|
||||
else if (scriptProtocol == ScriptProtocol::converter)
|
||||
{
|
||||
if (static_cast<lua_Type>(lua_getfield(state, -1, "convert")) ==
|
||||
LUA_TFUNCTION)
|
||||
{
|
||||
m_implementedMethods |= m_dataConvertsBit;
|
||||
}
|
||||
rive_lua_pop(state, 1);
|
||||
if (static_cast<lua_Type>(lua_getfield(state, -1, "reverseConvert")) ==
|
||||
LUA_TFUNCTION)
|
||||
{
|
||||
m_implementedMethods |= m_dataReverseConvertsBit;
|
||||
}
|
||||
rive_lua_pop(state, 1);
|
||||
}
|
||||
rive_lua_pop(state, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,45 @@ bool ScriptedDataConverter::scriptInit(LuaState* state)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScriptedDataConverter::pushDataValue(DataValue* value)
|
||||
{
|
||||
auto state = m_state->state;
|
||||
// Stack: [self, field, self]
|
||||
if (value->is<DataValueNumber>())
|
||||
{
|
||||
lua_newrive<ScriptedDataValueNumber>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueNumber>()->value());
|
||||
}
|
||||
else if (value->is<DataValueString>())
|
||||
{
|
||||
lua_newrive<ScriptedDataValueString>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueString>()->value());
|
||||
}
|
||||
else if (value->is<DataValueBoolean>())
|
||||
{
|
||||
lua_newrive<ScriptedDataValueBoolean>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueBoolean>()->value());
|
||||
}
|
||||
else if (value->is<DataValueColor>())
|
||||
{
|
||||
lua_newrive<ScriptedDataValueColor>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueColor>()->value());
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DataValue* ScriptedDataConverter::applyConversion(DataValue* value,
|
||||
const std::string& method)
|
||||
{
|
||||
@@ -59,50 +98,13 @@ DataValue* ScriptedDataConverter::applyConversion(DataValue* value,
|
||||
// Stack: []
|
||||
rive_lua_pushRef(state, m_self);
|
||||
// Stack: [self]
|
||||
if (static_cast<lua_Type>(lua_getfield(state, -1, method.c_str())) !=
|
||||
LUA_TFUNCTION)
|
||||
lua_getfield(state, -1, method.c_str());
|
||||
|
||||
// Stack: [self, field]
|
||||
lua_pushvalue(state, -2);
|
||||
// Stack: [self, field, self]
|
||||
if (pushDataValue(value))
|
||||
{
|
||||
fprintf(stderr, "expected %s to be a function\n", method.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Stack: [self, field]
|
||||
if (value->is<DataValueNumber>())
|
||||
{
|
||||
lua_pushvalue(state, -2);
|
||||
// Stack: [self, field, self]
|
||||
lua_newrive<ScriptedDataValueNumber>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueNumber>()->value());
|
||||
}
|
||||
else if (value->is<DataValueString>())
|
||||
{
|
||||
lua_pushvalue(state, -2);
|
||||
// Stack: [self, field, self]
|
||||
lua_newrive<ScriptedDataValueString>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueString>()->value());
|
||||
}
|
||||
else if (value->is<DataValueBoolean>())
|
||||
{
|
||||
lua_pushvalue(state, -2);
|
||||
// Stack: [self, field, self]
|
||||
lua_newrive<ScriptedDataValueBoolean>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueBoolean>()->value());
|
||||
}
|
||||
else if (value->is<DataValueColor>())
|
||||
{
|
||||
lua_pushvalue(state, -2);
|
||||
// Stack: [self, field, self]
|
||||
lua_newrive<ScriptedDataValueColor>(
|
||||
state,
|
||||
state,
|
||||
value->as<DataValueColor>()->value());
|
||||
}
|
||||
// Stack: [self, field, self, ScriptedData]
|
||||
if (static_cast<lua_Status>(rive_lua_pcall(state, 2, 1)) == LUA_OK)
|
||||
{
|
||||
@@ -127,6 +129,11 @@ DataValue* ScriptedDataConverter::applyConversion(DataValue* value,
|
||||
// Stack: [self, status] or [self, result]
|
||||
rive_lua_pop(state, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Stack: [self, field, self]
|
||||
rive_lua_pop(state, 3);
|
||||
}
|
||||
if (!m_dataValue)
|
||||
{
|
||||
m_dataValue = new DataValue();
|
||||
@@ -136,13 +143,21 @@ DataValue* ScriptedDataConverter::applyConversion(DataValue* value,
|
||||
|
||||
DataValue* ScriptedDataConverter::convert(DataValue* value, DataBind* dataBind)
|
||||
{
|
||||
return applyConversion(value, "convert");
|
||||
if (dataConverts())
|
||||
{
|
||||
return applyConversion(value, "convert");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
DataValue* ScriptedDataConverter::reverseConvert(DataValue* value,
|
||||
DataBind* dataBind)
|
||||
{
|
||||
return applyConversion(value, "reverseConvert");
|
||||
if (dataReverseConverts())
|
||||
{
|
||||
return applyConversion(value, "reverseConvert");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user