Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor: Lua table as a set convention
  • Loading branch information
KoharaKazuya committed Dec 19, 2020
1 parent 4bdc757 commit ae46076
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
8 changes: 6 additions & 2 deletions control.lua
Expand Up @@ -8,7 +8,9 @@ script.on_init(function()
global = {}
global.entities = {}
global.locomotive_type_names = {
key.locomotive, key.locomotive_mk2, key.locomotive_mk3
[key.locomotive] = true,
[key.locomotive_mk2] = true,
[key.locomotive_mk3] = true
}
global.schema_version = 2
end)
Expand All @@ -18,7 +20,9 @@ script.on_configuration_changed(function(data)
local version = global.schema_version or 1
if version < 2 then
global.locomotive_type_names = {
key.locomotive, key.locomotive_mk2, key.locomotive_mk3
[key.locomotive] = true,
[key.locomotive_mk2] = true,
[key.locomotive_mk3] = true
}
end
global.schema_version = 2
Expand Down
6 changes: 1 addition & 5 deletions remote-interface.lua
@@ -1,11 +1,7 @@
--- register a new locomotive type
-- @param name string of lomotive type name
local function register_locomotive_type(name)
local contains = false
for _, v in pairs(global.locomotive_type_names) do
if v == name then contains = true end
end
if not (contains) then table.insert(global.locomotive_type_names, name) end
global.locomotive_type_names[name] = true
end

remote.add_interface("BatteryLocomotive",
Expand Down
5 changes: 1 addition & 4 deletions utils/train.lua
Expand Up @@ -44,10 +44,7 @@ end

local function is_battery_locomotive(entity)
if not entity then return false end
local name = entity.name
for _, v in pairs(global.locomotive_type_names) do
if v == name then return true end
end
if global.locomotive_type_names[entity.name] then return true end
return false
end

Expand Down

0 comments on commit ae46076

Please sign in to comment.