Optimized code structure, added comments. Time to eat lunch!
This commit is contained in:
Binary file not shown.
+55
-22
@@ -1,4 +1,4 @@
|
||||
MarkLisener = {}
|
||||
MarkListener = {}
|
||||
|
||||
--[[
|
||||
Event = {
|
||||
@@ -11,14 +11,28 @@ MarkLisener = {}
|
||||
text = string markText,
|
||||
pos = vec3
|
||||
}
|
||||
|
||||
Command format: "/[command] h[heading] [speed] [altitude]"
|
||||
- EX: "/KC135 h325 320 12000"
|
||||
- "/KC135MPRS 320 12000 h325 "
|
||||
|
||||
MarkSpawner can only spawn [Groups] that defined in ME and "commandPresets" down below.
|
||||
]]
|
||||
|
||||
|
||||
do
|
||||
MarkLisener.Debug = true
|
||||
MarkListener.Debug = true --toggle debug messages.
|
||||
|
||||
--Contains commands and it's groupPresets.
|
||||
MarkListener.commandPresets = {
|
||||
['/KC135'] = {
|
||||
-- groupName isAvailable
|
||||
['KC135-1'] = true,
|
||||
},
|
||||
}
|
||||
|
||||
function MarkLisener.showMarkItems(event)
|
||||
--Displays mark event args.
|
||||
function MarkListener.showMarkItems(event)
|
||||
local msg = " "
|
||||
if event.id then
|
||||
msg = msg..'id: '..event.id..'\n'
|
||||
@@ -59,10 +73,11 @@ do
|
||||
trigger.action.outText(msg,5)
|
||||
end
|
||||
|
||||
function MarkLisener.getParams(text)
|
||||
--Translates mark text into command params.
|
||||
function MarkListener.getParams(text)
|
||||
-- command heading altitude speed
|
||||
|
||||
local command, heading, altitude, speed
|
||||
local result = {}
|
||||
if not text or text == '' then return nil end
|
||||
|
||||
local parts = {}
|
||||
@@ -70,49 +85,67 @@ do
|
||||
table.insert(parts,part)
|
||||
end
|
||||
|
||||
command = parts[1]
|
||||
result.command = parts[1]
|
||||
for i=2,4,1 do
|
||||
if not parts[i] then break end
|
||||
|
||||
parts[i] = tonumber(parts[i])
|
||||
if string.sub(parts[i],1,1) == "h" then
|
||||
if not result.heading then
|
||||
local heading = tonumber(string.sub(parts[i],2,string.len(parts[i])))
|
||||
if heading > 360 then heading = heading % 360 end
|
||||
|
||||
if not heading then
|
||||
if parts[i] >= 0 and parts[i] < 360 then
|
||||
heading = parts[i]
|
||||
result.heading = math.ceil(heading)
|
||||
end
|
||||
end
|
||||
|
||||
if not speed then
|
||||
if parts[i] >= 230 and parts[i] <= 430 then --节
|
||||
speed = parts[i]
|
||||
end
|
||||
end
|
||||
if string.sub(parts[i],1,1) ~= "h" then
|
||||
parts[i] = math.ceil(tonumber(parts[i]))
|
||||
|
||||
if not altitude then
|
||||
if parts[i] >= 3000 and parts[i] <= 45000 then --英尺
|
||||
altitude = parts[i]
|
||||
if not result.speed then
|
||||
if parts[i] >= 230 and parts[i] <= 430 then --节
|
||||
result.speed = parts[i]
|
||||
end
|
||||
end
|
||||
|
||||
if not result.altitude then
|
||||
if parts[i] >= 3000 and parts[i] <= 45000 then --英尺
|
||||
result.altitude = parts[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return command, heading, altitude, speed
|
||||
return result
|
||||
end
|
||||
|
||||
--Event listener.
|
||||
local ev = {}
|
||||
|
||||
function ev:onEvent(event)
|
||||
if event.id == 25 or event.id == 26 then
|
||||
--Debug
|
||||
if MarkLisener.Debug then
|
||||
MarkLisener.showMarkItems(event)
|
||||
if MarkListener.Debug then
|
||||
MarkListener.showMarkItems(event)
|
||||
end
|
||||
--Debug
|
||||
|
||||
local markID = event.idx
|
||||
local pos = event.pos
|
||||
local text = event.text
|
||||
|
||||
if string.sub(text,1,1) == "/" then
|
||||
MarkLisener.getParams(text)
|
||||
local args = MarkListener.getParams(text)
|
||||
args.altitude = args.altitude or 12000
|
||||
args.speed = args.speed or 300
|
||||
args.heading = args.heading or 0
|
||||
|
||||
--Debug
|
||||
local msg = 'command: '..args.command..' alt: '..args.altitude..' speed: '
|
||||
..args.speed..' heading: '..args.heading
|
||||
trigger.action.outText(msg,10)
|
||||
--Debug
|
||||
|
||||
--TODO: Use mist.teleportToPoint to spawn groups
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user