mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
xxx
This commit is contained in:
@@ -281,3 +281,52 @@ function STATIC:ReSpawnAt(Coordinate, Heading, Delay)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Find the first(!) STATIC matching using patterns. Note that this is **a lot** slower than `:FindByName()`!
|
||||
-- @param #STATIC self
|
||||
-- @param #string Pattern The pattern to look for. Refer to [LUA patterns](http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_\(Regular_Expressions\)) for regular expressions in LUA.
|
||||
-- @return #STATIC The STATIC.
|
||||
-- @usage
|
||||
-- -- Find a static with a partial static name
|
||||
-- local grp = STATIC:FindByMatching( "Apple" )
|
||||
-- -- will return e.g. a static named "Apple-1-1"
|
||||
--
|
||||
-- -- using a pattern
|
||||
-- local grp = STATIC:FindByMatching( ".%d.%d$" )
|
||||
-- -- will return the first static found ending in "-1-1" to "-9-9", but not e.g. "-10-1"
|
||||
function STATIC:FindByMatching( Pattern )
|
||||
local GroupFound = nil
|
||||
|
||||
for name,static in pairs(_DATABASE.STATICS) do
|
||||
if string.match(name, Pattern ) then
|
||||
GroupFound = static
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return GroupFound
|
||||
end
|
||||
|
||||
--- Find all STATIC objects matching using patterns. Note that this is **a lot** slower than `:FindByName()`!
|
||||
-- @param #STATIC self
|
||||
-- @param #string Pattern The pattern to look for. Refer to [LUA patterns](http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_\(Regular_Expressions\)) for regular expressions in LUA.
|
||||
-- @return #table Groups Table of matching #STATIC objects found
|
||||
-- @usage
|
||||
-- -- Find all static with a partial static name
|
||||
-- local grptable = STATIC:FindAllByMatching( "Apple" )
|
||||
-- -- will return all statics with "Apple" in the name
|
||||
--
|
||||
-- -- using a pattern
|
||||
-- local grp = STATIC:FindAllByMatching( ".%d.%d$" )
|
||||
-- -- will return the all statics found ending in "-1-1" to "-9-9", but not e.g. "-10-1" or "-1-10"
|
||||
function STATIC:FindAllByMatching( Pattern )
|
||||
local GroupsFound = {}
|
||||
|
||||
for name,static in pairs(_DATABASE.STATICS) do
|
||||
if string.match(name, Pattern ) then
|
||||
GroupsFound[#GroupsFound+1] = static
|
||||
end
|
||||
end
|
||||
|
||||
return GroupsFound
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user