luanti_scripts/fabric_order_controller.lua

207 lines
4.8 KiB
Lua

local function createui()
--if mem.controls then return end
mem.controls = {
{
command = "clear"
},
{
X = 0.4,
H = 0.8,
command = "adddropdown",
choices = {
"drawercontroller"
},
W = 10,
label = "Drawer Controller",
selected_id = 1,
Y = 1.2,
name = "ddController"
},
{
choices = {
"basic_materials:oil_extract",
"default:coal_lump",
"default:cobble",
"default:copper_ingot",
"default:copper_lump",
"default:gold_ingot",
"default:gravel",
"default:iron_lump",
"default:mese_crystal",
"default:silver_sand",
"default:steel_ingot",
"default:stone",
"farming:chocolate_dark",
"farming:cocoa_beans",
"flowers:tulip_black",
"mesecons_materials:glue",
"moreblocks:cobble_compressed",
"moretrees:rubber_tree_trunk",
"technic:chromium_lump",
"technic:sulfur_lump"
},
H = 0.8,
label = "Item name",
selected_id = 1,
W = 10,
command = "adddropdown",
Y = 3.2,
X = 0.4,
name = "ddItem"
},
{
X = 0.4,
H = 0.8,
command = "adddropdown",
choices = {
"Tacit:cobblecompress",
"Tacit:extract",
"Tacit:furnace",
"Tacit:grinder",
"Tacit:grindextract",
"Tacit:grindfurnace",
"Tacit:obsidian",
"Tacit:plasticin",
"Tacit:refab"
},
W = 10,
label = "Destination",
selected_id = 1,
Y = 5.2,
name = "ddDestination"
},
{
default = "99",
command = "addfield",
name = "fldStackSize",
W = 1.2,
X = 0.7,
Y = 7.1,
H = 0.8,
label = "Stack size"
},
{
default = "1",
command = "addfield",
name = "fldStacksCount",
W = 1.6,
X = 1.9,
Y = 7.1,
H = 0.8,
label = "Stacks count"
},
{
command = "addbutton",
name = "btnOrder",
W = 1.6,
X = 3.2,
Y = 6.8,
H = 0.8,
label = "Order"
},
{
default = "",
command = "addfield",
name = "fldController",
W = 9.2,
X = 0.7,
Y = 0.7,
H = 0.8,
label = "Enter drawer controller or select one"
},
{
default = "",
command = "addfield",
name = "fldItem",
W = 9.2,
X = 0.7,
Y = 2.7,
H = 0.8,
label = "Enter item id or select one"
},
{
default = "",
command = "addfield",
X = 0.7,
W = 9.2,
name = "fldDestination",
Y = 4.7,
H = 0.8,
label = "Enter destination name or select one"
},
{
command = "addlabel",
Y = 8.11,
X = 7.18,
label = "Created with SX Digi labs Touch Designer"
}
}
end
local function addvalues(control, value)
local controls = mem.controls
for k,v in pairs(controls) do
if v.name and v.name == control then
for kc,vc in pairs(v.choices) do
if vc == value then
return
end
end
table.insert(v.choices, value)
table.sort(v.choices)
end
end
mem.controls = controls
end
if event.type == "program" then
createui()
digiline_send("touch", mem.controls)
end
if event.type == "digiline" then
if event.channel ~= "touch" then return end
if event.msg.clicker ~= "Tacit" then return end
if event.msg.quit then return end
if event.msg.btnOrder ~= "Order" then return end
mem.event = event.msg
if event.channel == "touch" then
local controller = event.msg.ddController
local item = event.msg.ddItem
local destination = event.msg.ddDestination
if event.msg.fldItem ~= "" then
item = event.msg.fldItem
addvalues("ddItem", event.msg.fldItem)
end
if event.msg.fldDestination ~= "" then
destination = event.msg.fldDestination
addvalues("ddDestination", event.msg.fldDestination)
end
if event.msg.fldController ~= "" then
controller = event.msg.fldController
addvalues("ddController", event.msg.fldController)
end
local order = {
name="fc-" .. tostring(mem.orderNumber),
destination=destination,
item=item,
stacksize=tonumber(event.msg.fldStackSize),
count=tonumber(event.msg.fldStacksCount),
}
mem.order = order
mem.orderNumber = mem.orderNumber + 1
digiline_send("touch", mem.controls)
digiline_send(controller, order)
digiline_send("ordermon", order.name)
end
end