import and export textures, infotext, animation and properties

This commit is contained in:
Sokomine 2023-11-26 00:15:57 +01:00
parent f3b0f10603
commit a1963d6b52

View File

@ -21,6 +21,9 @@ yl_speak_up.input_fs_export = function(player, formname, fields)
"back_from_error_msg")})
end
local pname = player:get_player_name()
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
return
end
local n_id = yl_speak_up.speak_to[pname].n_id
-- actually import the dialog
local new_dialog = minetest.parse_json(fields.new_dialog_input or "")
@ -49,6 +52,39 @@ yl_speak_up.input_fs_export = function(player, formname, fields)
yl_speak_up.update_nametag(ent)
end
end
-- import self.yl_speak_up (contains skin, animation, properties and the like)
local obj = yl_speak_up.speak_to[pname].obj
if(obj and new_dialog.entity_yl_speak_up) then
local entity = obj:get_luaentity()
if(entity) then
-- not all staticdata is changed
local staticdata = entity:get_staticdata()
-- we need to take the ID of this *current* NPC - not of the savedone!
local old_id = entity.yl_speak_up.id
new_dialog.entity_yl_speak_up.id = old_id
-- provide the entity with the new data
entity.yl_speak_up = new_dialog.entity_yl_speak_up
-- textures and infotext may depend on the mod
if(entity.yl_speak_up.entity_textures) then
entity.textures = entity.yl_speak_up.entity_textures
end
if(entity.yl_speak_up.entity_infotext) then
entity.infotext = entity.yl_speak_up.entity_infotext
end
-- update the entity
local dtime_s = 1
entity:on_activate(new_staticdata, dtime_s)
-- apply the changes
entity.object:set_properties(entity)
if(entity.yl_speak_up.animation) then
entity.object:set_animation(entity.yl_speak_up.animation)
end
-- get the updated staticdata (with new yl_speak_up values)
local new_staticdata = entity:get_staticdata()
-- update the nametag if possible
yl_speak_up.update_nametag(entity)
end
end
-- update the stored dialog
yl_speak_up.speak_to[pname].dialog = new_dialog
-- save it
@ -67,6 +103,9 @@ end
yl_speak_up.get_fs_export = function(player, param)
local pname = player:get_player_name()
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
return
end
local n_id = yl_speak_up.speak_to[pname].n_id
-- generic dialogs are not part of the NPC
local dialog = yl_speak_up.speak_to[pname].dialog
@ -102,6 +141,22 @@ yl_speak_up.get_fs_export = function(player, param)
local b3 = "button[13.8,17.2;6.0,0.9;show_simple_dialogs;Show simple dialogs format]"..
"tooltip[show_simple_dialogs;Show the dialog data structure in the format used by\n"..
"the mod \"simple_dialogs\".]"
-- include self.yl_speak_up (contains skin, animation, properties and the like)
local obj = yl_speak_up.speak_to[pname].obj
if(obj) then
local entity = obj:get_luaentity()
if(entity) then
dialog.entity_yl_speak_up = entity.yl_speak_up
-- these data values vary too much depending on mod used for the NPC
if(entity.textures) then
dialog.entity_yl_speak_up.entity_textures = entity.textures
end
if(entity.infotext) then
dialog.entity_yl_speak_up.entity_infotext = entity.infotext
end
end
end
if(param and param == "show_readable") then
b1 = "label[0.2,17.6;This is human readable format]"
explanation = "This is like the raw dialog data format - except that it's written a bit "..