-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigilines.lua
More file actions
91 lines (82 loc) · 2.27 KB
/
Copy pathdigilines.lua
File metadata and controls
91 lines (82 loc) · 2.27 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local rules = technic_cnc.use_technic and technic.digilines.rules or digilines.rules.default
local def = {
receptor = {
rules = rules,
},
effector = {
rules = rules,
},
}
local function check_message(meta, channel, msg)
-- Digiline channel check
if channel ~= meta:get_string("channel") then
return false
end
-- Message type check
if type(msg) == "string" then
-- String is is always valid, get out skipping all table checks
return true
elseif type(msg) ~= "table" then
return false
end
-- Verify that size is either nil or number between 1-2
if msg.size ~= nil and (type(msg.size) ~= "number" or msg.size < 1 or msg.size > 2) then
msg.size = nil
end
-- Verify program if provided
if msg.program ~= nil then
-- If program is set it must be string and available
if type(msg.program) ~= "string" or not technic_cnc.products[msg.program] then
msg.program = nil
end
end
-- Message is valid (but not necessarily useful)
return true
end
function def.effector.action(pos, node, channel, msg)
-- Validate message contents,
local meta = minetest.get_meta(pos)
if not check_message(meta, channel, msg) then
return
end
-- Process message and execute required actions
if type(msg) == "string" then
msg = msg:lower()
if msg == "programs" then
digilines.receptor_send(pos, rules, channel, technic_cnc.products)
elseif msg == "status" then
local inv = meta:get_inventory()
local srcstack = inv:get_stack("src", 1)
local status = {
enabled = technic_cnc.is_enabled(meta),
time = meta:get_int("src_time"),
size = meta:get_int("size"),
program = meta:get_string("program"),
user = meta:get_string("cnc_user"),
material = {
name = srcstack:get_name(),
count = srcstack:get_count(),
}
}
digilines.receptor_send(pos, rules, channel, status)
elseif msg == "enable" then
technic_cnc.enable(meta)
elseif msg == "disable" then
technic_cnc.disable(meta)
end
else
-- Configure milling programs
if msg.program then
technic_cnc.set_program(meta, msg.program, msg.size)
elseif msg.size then
meta:set_int("size", msg.size)
end
-- Enable / disable CNC machine
if msg.enabled == true then
technic_cnc.enable(meta)
elseif msg.enabled == false then
technic_cnc.disable(meta)
end
end
end
return def