formspec API: add on_sending_*_fields
(register/ed)_on_sending_(inventory/nodemeta)_fields Could be useful for translating field values? No clue, sure we'll find a use :]
This commit is contained in:
parent
285b6801a0
commit
57f10ad0c1
@ -107,3 +107,5 @@ core.registered_on_nodemeta_form_open, core.register_on_nodemeta_form_open = mak
|
||||
core.registered_on_recieve_physics_override, core.register_on_recieve_physics_override = make_registration()
|
||||
core.registered_on_play_sound, core.register_on_play_sound = make_registration()
|
||||
core.registered_on_spawn_particle, core.register_on_spawn_particle = make_registration()
|
||||
core.registered_on_sending_inventory_fields, core.register_on_sending_inventory_fields = make_registration()
|
||||
core.registered_on_sending_nodemeta_fields, core.register_on_sending_nodemeta_fields = make_registration()
|
||||
|
@ -1149,6 +1149,9 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
|
||||
|
||||
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of nodemeta fields");
|
||||
|
||||
if (m_script->on_sending_nodemeta_fields(p, formname, fields))
|
||||
return;
|
||||
|
||||
NetworkPacket pkt(TOSERVER_NODEMETA_FIELDS, 0);
|
||||
|
||||
pkt << p << formname << (u16) (fields_size & 0xFFFF);
|
||||
@ -1170,6 +1173,9 @@ void Client::sendInventoryFields(const std::string &formname,
|
||||
size_t fields_size = fields.size();
|
||||
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields");
|
||||
|
||||
if (m_script->on_sending_inventory_fields(formname, fields))
|
||||
return;
|
||||
|
||||
NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0);
|
||||
pkt << formname << (u16) (fields_size & 0xFFFF);
|
||||
|
||||
|
@ -346,6 +346,59 @@ bool ScriptApiClient::on_nodemeta_form_open(v3s16 position, std::string formname
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_sending_inventory_fields(const std::string &formname,
|
||||
const StringMap &fields)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_chat_messages
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_sending_inventory_fields");
|
||||
// Call callbacks
|
||||
// param 1
|
||||
lua_pushstring(L, formname.c_str());
|
||||
// param 2
|
||||
lua_newtable(L);
|
||||
StringMap::const_iterator it;
|
||||
for (it = fields.begin(); it != fields.end(); ++it) {
|
||||
const std::string &name = it->first;
|
||||
const std::string &value = it->second;
|
||||
lua_pushstring(L, name.c_str());
|
||||
lua_pushlstring(L, value.c_str(), value.size());
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_sending_nodemeta_fields(v3s16 position,
|
||||
const std::string &formname,
|
||||
const StringMap &fields)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_chat_messages
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_sending_nodemeta_fields");
|
||||
// Call callbacks
|
||||
// param 1
|
||||
push_v3s16(L, position);
|
||||
// param 2
|
||||
lua_pushstring(L, formname.c_str());
|
||||
// param 3
|
||||
lua_newtable(L);
|
||||
StringMap::const_iterator it;
|
||||
for (it = fields.begin(); it != fields.end(); ++it) {
|
||||
const std::string &name = it->first;
|
||||
const std::string &value = it->second;
|
||||
lua_pushstring(L, name.c_str());
|
||||
lua_pushlstring(L, value.c_str(), value.size());
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
runCallbacks(3, RUN_CALLBACKS_MODE_OR);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
void ScriptApiClient::setEnv(ClientEnvironment *env)
|
||||
{
|
||||
ScriptApiBase::setEnv(env);
|
||||
|
@ -68,5 +68,10 @@ public:
|
||||
bool on_receiving_inventory_form(std::string formname, std::string formspec);
|
||||
bool on_nodemeta_form_open(v3s16 position, std::string formname, std::string formspec);
|
||||
|
||||
bool on_sending_inventory_fields(const std::string &formname,
|
||||
const StringMap &fields);
|
||||
bool on_sending_nodemeta_fields(v3s16 position,
|
||||
const std::string &formname, const StringMap &fields);
|
||||
|
||||
void setEnv(ClientEnvironment *env);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user