-
Notifications
You must be signed in to change notification settings - Fork 7
/
validate.lua
63 lines (48 loc) · 1.36 KB
/
validate.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)
if not steps then
return { success=false, failed=true, msg="No steps" }
end
for i,step in ipairs(steps) do
local spec = missions.get_step_spec_by_type(step.type)
if not spec then
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
local result = spec.validate({
pos=pos,
step=step
})
if result and result.failed then
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