Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Implement remote.does_remote_sensor_exist and remote.remove_remote_sensor #66

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions remote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,42 @@ local function update_remote_sensor(sensor_name, sensor_text, sensor_color)
end
end

--
-- Checks if a remote sensor exists, returns true if one was does
-- sensor_name: internal name of the sensor.
-- example: remote.call("EvoGUI", "does_remote_sensor_exist", "mymod_my_sensor_name")
local function does_remote_sensor_exist(sensor_name)
if not sensor_name then
evogui.log({"err_nosensorname"})
return
end
local sensor = RemoteSensor.get_by_name(sensor_name)
return sensor ~= nil
end

--
-- Removes a sensor managed by a remote interface, returns true if one was removed
-- sensor_name: internal name of the sensor. The sensor should have been previously created.
-- example: remote.call("EvoGUI", "remove_remote_sensor", "mymod_my_sensor_name")
local function remove_remote_sensor(sensor_name)
if not sensor_name then
evogui.log({"err_nosensorname"})
return
end
local sensor = RemoteSensor.get_by_name(sensor_name)
if not sensor then
-- impossible to know if the sensor was removed in advance, so just return a status
return false
end
evogui.hide_sensor(sensor)
for idx, sensor in pairs(evogui.value_sensors) do
if sensor.name == ("remote_sensor_" .. sensor_name) then
table.remove(evogui.value_sensors, idx)
end
end
global.remote_sensors[sensor_name] = nil
return true
end

interface = {
rebuild = function(player_name)
Expand All @@ -114,6 +150,20 @@ interface = {
update_remote_sensor = function(sensor_name, sensor_text, sensor_color)
local status, err = pcall(update_remote_sensor, sensor_name, sensor_text, sensor_color)
if err then evogui.log({"err_generic", "remote.update_remote_sensor", err}) end
end,

does_remote_sensor_exist = function(sensor_name)
local status, err = pcall(does_remote_sensor_exist, sensor_name)
-- properly pass the return value
if status then return err
elseif err then evogui.log({"err_generic", "remote.remove_remote_sensor", err}) end
end,

remove_remote_sensor = function(sensor_name)
local status, err = pcall(remove_remote_sensor, sensor_name)
-- properly pass the return value
if status then return err
elseif err then evogui.log({"err_generic", "remote.remove_remote_sensor", err}) end
end
}

Expand Down