forked from Sokomine/yl_speak_up
		
	edit and store preconditions of type "evaluate"
This commit is contained in:
		
							parent
							
								
									f00a7752d8
								
							
						
					
					
						commit
						073b9d4284
					
				@ -205,7 +205,7 @@ yl_speak_up.custom_functions_r_ = {}
 | 
			
		||||
-- example function for preconditions:
 | 
			
		||||
yl_speak_up.custom_functions_p_[ "example function" ] = {
 | 
			
		||||
	function_call = "yl_speak_up.custom_example_function",
 | 
			
		||||
	description = "This function is just an example. It does nothing.",
 | 
			
		||||
	description = "This function is just an example. It tells the player its parameters.",
 | 
			
		||||
	param1_text = "1. Parameter:",
 | 
			
		||||
	param1_desc = "This is the value passed to the function as first parameter.",
 | 
			
		||||
	param2_text = "2. Parameter:",
 | 
			
		||||
@ -258,8 +258,8 @@ yl_speak_up.custom_functions_r_[ "set_variable_to_random_value_from_list" ] = {
 | 
			
		||||
-- example function for results/effects:
 | 
			
		||||
yl_speak_up.custom_functions_r_[ "example function" ] = {
 | 
			
		||||
	function_call = "yl_speak_up.custom_example_function",
 | 
			
		||||
	description = "Describe here in short form what your function does.",
 | 
			
		||||
	description = "This function is just an example. It does nothing.",
 | 
			
		||||
	-- Describe here in short form what your function does:
 | 
			
		||||
	description = "This function is just an example. It tells the player its parameters.",
 | 
			
		||||
	param1_text = "1. Parameter:",
 | 
			
		||||
	param1_desc = "This is the value passed to the function as first parameter.",
 | 
			
		||||
	param2_text = "2. Parameter:",
 | 
			
		||||
 | 
			
		||||
@ -236,7 +236,8 @@ yl_speak_up.save_element_p_or_a_or_e = function(
 | 
			
		||||
		v[ id_prefix.."var_cmp_value" ] = (data.var_cmp_value or "")
 | 
			
		||||
		-- transfer the parameters
 | 
			
		||||
		for i = 1, 9 do
 | 
			
		||||
			v[ id_prefix.."param"..str(i) ] = (data["param"..str(i)] or "")
 | 
			
		||||
			local s = "param"..tostring(i)
 | 
			
		||||
			v[ id_prefix..s ] = (data[s] or "")
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	-- "a block somewhere", -- 3
 | 
			
		||||
@ -966,6 +967,22 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
 | 
			
		||||
	if(fields.lua_code) then
 | 
			
		||||
		data.lua_code = fields.lua_code
 | 
			
		||||
	end
 | 
			
		||||
	-- if the type of operator is changed: store any new values that may need storing
 | 
			
		||||
	if(what_type == "evaluate"
 | 
			
		||||
	   and (fields.set_param0 or fields.set_param1 or fields.set_param2 or fields.set_param3
 | 
			
		||||
	     or fields.set_param4 or fields.set_param5 or fields.set_param6 or fields.set_param7
 | 
			
		||||
	     or fields.set_param8 or fields.set_param9)) then
 | 
			
		||||
		for i = 1, 9 do
 | 
			
		||||
			local pn = "param"..tostring(i)
 | 
			
		||||
			if(fields["set_"..pn]) then
 | 
			
		||||
				if(data[pn] ~= fields["set_"..pn]) then
 | 
			
		||||
					data[pn] = fields["set_"..pn]
 | 
			
		||||
					was_changed = true
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	-- the save button was pressed
 | 
			
		||||
	if(fields.save_element and data and data.what and values_what[ data.what ]) then
 | 
			
		||||
@ -1655,10 +1672,15 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
 | 
			
		||||
	if(e) then
 | 
			
		||||
		--data.function_name = e[ id_prefix.."value"]
 | 
			
		||||
		data.function_name = e[ id_prefix.."value"]
 | 
			
		||||
		for i = 1, 9 do
 | 
			
		||||
			local s = "param"..tostring(i)
 | 
			
		||||
			if(e[id_prefix..s]) then
 | 
			
		||||
				data[s] = e[id_prefix..s]
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	local add_description = "Nothing selected."
 | 
			
		||||
	if(data.function_name) then
 | 
			
		||||
		-- TODO: create the dropdown
 | 
			
		||||
		func_data = yl_speak_up["custom_functions_"..id_prefix][data.function_name]
 | 
			
		||||
		-- add the fields for param1..param9:
 | 
			
		||||
		if(func_data) then
 | 
			
		||||
@ -1676,7 +1698,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
 | 
			
		||||
						"field["..(4.0 + xoff)..","..(5.8 + ((i-1)%5)*0.8)..
 | 
			
		||||
							";5.0,0.6;set_"..paramn..";;"..
 | 
			
		||||
							minetest.formspec_escape(
 | 
			
		||||
								data[paramn] or "- enter value -").."]"..
 | 
			
		||||
								data[paramn] or "").."]"..
 | 
			
		||||
						"tooltip[set_"..paramn..";"..
 | 
			
		||||
							minetest.formspec_escape(
 | 
			
		||||
								func_data[paramn.."_desc"] or "?").."]"
 | 
			
		||||
@ -1684,6 +1706,8 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
 | 
			
		||||
			end
 | 
			
		||||
			func_selected = table.indexof(fun_list, func_data["description"])
 | 
			
		||||
			add_description = func_data["description"]
 | 
			
		||||
			-- necessary so that the save_button can be shown
 | 
			
		||||
			data["function"] = func_selected
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	local operator_list = {}
 | 
			
		||||
@ -1710,11 +1734,13 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
 | 
			
		||||
		"label[7.5,3.3;"..minetest.formspec_escape(add_description).."]"..
 | 
			
		||||
		"dropdown[0.2,4.8;6.5,0.6;select_function_name;"..
 | 
			
		||||
			"- please select -,"..table.concat(fun_list, ",")..";"..
 | 
			
		||||
			tostring(func_selected + 1)..";]"
 | 
			
		||||
--		"hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
 | 
			
		||||
--			"<b>Note:</b> Functions are called with parameters which are passed on to them. "..
 | 
			
		||||
--			"The function then calculates a result. This can be compared to a given value."..
 | 
			
		||||
--			"</normal>]"
 | 
			
		||||
			tostring(func_selected + 1)..";]"..
 | 
			
		||||
		"hypertext[1.2,9.6;16.0,2.5;some_text;<normal>"..
 | 
			
		||||
			"<b>Note:</b> Functions are called with parameters which are passed on to them. "..
 | 
			
		||||
			"The function then calculates a result. This result can be compared to a given "..
 | 
			
		||||
			"value. What the function calculates and what it returns depends on its "..
 | 
			
		||||
			"implementation."..
 | 
			
		||||
			"</normal>]"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -241,7 +241,7 @@ yl_speak_up.show_precondition = function(p, pname)
 | 
			
		||||
	elseif(p.p_type == "evaluate") then
 | 
			
		||||
		local str = ""
 | 
			
		||||
		for i = 1, 9 do
 | 
			
		||||
			str = str..tostring(p["p_param" + tostring(i)])
 | 
			
		||||
			str = str..tostring(p["p_param"..tostring(i)])
 | 
			
		||||
			if(i < 9) then
 | 
			
		||||
				str = str..","
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user