Rework touchscreen insert
command and add delete
command (#40)
Co-authored-by: OgelGames <olliverdc28@gmail.com>
This commit is contained in:
parent
80bbcc6739
commit
68ad7b4fcf
@ -34,7 +34,7 @@ digiline_send("touchscreen", {
|
||||
})
|
||||
```
|
||||
|
||||
**`insert`** - Adds an element at a specific index.
|
||||
**`insert`** - Adds an element at a specific index. The index can be any positive number.
|
||||
|
||||
```lua
|
||||
digiline_send("touchscreen", {
|
||||
@ -63,7 +63,7 @@ digiline_send("touchscreen", {
|
||||
})
|
||||
```
|
||||
|
||||
**`remove`** - Removes an element.
|
||||
**`remove`** - Removes an element, shifting elements to fill the space.
|
||||
|
||||
```lua
|
||||
digiline_send("touchscreen", {
|
||||
@ -72,7 +72,16 @@ digiline_send("touchscreen", {
|
||||
})
|
||||
```
|
||||
|
||||
**`clear`** - Removes all elements, but keeps settings.
|
||||
**`delete`** - Removes an element without changing element indexes.
|
||||
|
||||
```lua
|
||||
digiline_send("touchscreen", {
|
||||
command = "delete",
|
||||
index = 1,
|
||||
})
|
||||
```
|
||||
|
||||
**`clear`** - Removes all elements.
|
||||
|
||||
```lua
|
||||
digiline_send("touchscreen", {
|
||||
|
@ -73,11 +73,7 @@ local function process_command(meta, data, msg)
|
||||
local index = tonumber(msg.index)
|
||||
if element and index and index > 0 then
|
||||
local str = create_element_string(element, msg)
|
||||
if index > #data then
|
||||
table.insert(data, str)
|
||||
else
|
||||
table.insert(data, index, str)
|
||||
end
|
||||
table.insert(data, index, str)
|
||||
end
|
||||
|
||||
elseif cmd == "replace" then
|
||||
@ -101,6 +97,12 @@ local function process_command(meta, data, msg)
|
||||
table.remove(data, index)
|
||||
end
|
||||
|
||||
elseif cmd == "delete" then
|
||||
local index = tonumber(msg.index)
|
||||
if index and data[index] then
|
||||
data[index] = nil
|
||||
end
|
||||
|
||||
elseif cmd == "set" then
|
||||
if msg.locked ~= nil then
|
||||
meta:set_int("locked", msg.locked == false and 0 or 1)
|
||||
@ -161,7 +163,18 @@ local function create_formspec(meta, data)
|
||||
if focus then
|
||||
fs = fs.."set_focus["..focus.."]"
|
||||
end
|
||||
return fs..table.concat(data)
|
||||
local data_size = 0
|
||||
for i in pairs(data) do
|
||||
if i > data_size then
|
||||
data_size = i
|
||||
end
|
||||
end
|
||||
for i=1, data_size do
|
||||
if data[i] then
|
||||
fs = fs..data[i]
|
||||
end
|
||||
end
|
||||
return fs
|
||||
end
|
||||
|
||||
local function update_formspec(pos, meta, data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user