hidden and validation meta

This commit is contained in:
Thomas Rudin 2018-08-28 11:50:24 +02:00
parent 87bed08c4b
commit 86edc4f5ec
4 changed files with 58 additions and 3 deletions

View File

@ -18,6 +18,9 @@ minetest.register_node("missions:mission", {
meta:set_string("owner", playername)
meta:set_int("selected_step", 1)
meta:set_int("time", 300)
meta:set_int("hidden", 0)
meta:set_int("valid", 1)
meta:set_string("validationresult", "")
meta:set_string("name", "")
meta:set_string("description", "")

View File

@ -9,13 +9,23 @@ missions.form.missionblock_config = function(pos, node, player)
local time = meta:get_string("time")
local owner = meta:get_string("owner")
local description = meta:get_string("description")
local hidden = meta:get_int("hidden")
local hidden_str = "Hidden "
if hidden == 0 then
hidden_str = hidden_str .. "<True>"
else
hidden_str = hidden_str .. "<False>"
end
local formspec = "size[8,8;]" ..
--left
"label[0,0;Mission editor]" ..
"button[4,0;4,1;togglehidden;" .. hidden_str .. "]" ..
"field[0,1;8,1;name;Name;" .. name .. "]" ..
"field[0,2;8,1;time;Time (seconds);" .. time .. "]" ..
"textarea[0,3;8,5;description;Description;" .. description .. "]" ..
"textarea[0,3;8,4;description;Description;" .. description .. "]" ..
"button_exit[0,7;8,1;save;Save]"
minetest.show_formspec(player:get_player_name(),
@ -50,6 +60,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:set_string("time", fields.time)
end
if fields.togglehidden then
local hidden = meta:get_int("hidden")
if hidden == 0 then
meta:set_int("hidden", 1)
else
meta:set_int("hidden", 0)
end
missions.form.missionblock_config(pos, node, player)
end
if fields.description then
meta:set_string("description", fields.description)
end

View File

@ -7,6 +7,18 @@ missions.migrate_mission_block = function(pos, meta)
inv:set_size("main", 8)
end
if meta:get_int("hidden") == nil then
meta:set_int("hidden", 0)
end
if meta:get_int("valid") == nil then
meta:set_int("valid", 1)
end
if meta:get_string("validationresult") == nil then
meta:set_string("validationresult", "")
end
if meta:get_int("successcount") == nil then
meta:set_int("successcount", 0)
end

View File

@ -1,19 +1,34 @@
local function assign_validation_result(meta, result)
meta:set_int("valid", 0)
meta:set_string("validationresult", result.msg)
end
local function clear_validation_result(meta)
meta:set_int("valid", 1)
meta:set_string("validationresult", "")
end
missions.validate_mission = function(pos, player)
local steps = missions.get_steps(pos)
local meta = minetest.get_meta(pos)
for i,step in ipairs(steps) do
local spec = missions.get_step_spec_by_type(step.type)
if not spec then
return {
local result = {
msg="Validation failed in step " .. i ..
" on mission: " .. pos.x .. "/" .. pos.y .. "/" .. pos.z ..
" the step has no spec (specification): " .. step.type,
success=false,
failed=true
}
assign_validation_result(meta, result)
return result
end
if spec.validate then
@ -23,17 +38,22 @@ missions.validate_mission = function(pos, player)
})
if result and result.failed then
return {
local validation_result = {
msg="Validation failed in step " .. i ..
" on mission: " .. pos.x .. "/" .. pos.y .. "/" .. pos.z ..
" with message: " .. result.msg,
success=false,
failed=true
}
assign_validation_result(meta, validation_result)
return validation_result
end
end
end
clear_validation_result(meta)
return { success=true }
end