/src/frontend/console.html
HTML | 332 lines | 303 code | 29 blank | 0 comment | 0 complexity | 128a764690c893d52370b0925473d194 MD5 | raw file
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="bootstrap-3.1.1-dist/css/bootstrap.min.css">
- <link rel="stylesheet" href="/js/vendor/codemirror-4.3/lib/codemirror.css">
- <link rel="stylesheet" href="/js/vendor/codemirror-4.3/theme/neat.css">
- <style>
- .CodeMirror {
- border: 1px solid #eee;
- height: auto;
- }
- .CodeMirror-scroll {
- overflow-y: hidden;
- overflow-x: auto;
- }
- .luasnippet {
- margin-top: 10px;
- margin-left: 10px;
- margin-right: 10px;
- border-radius: 5px;
- padding: 5px;
- border: 1px solid #ddd;
- }
- .luaoutput {
- white-space: pre-wrap;
- font-family: monospace;
- }
- .luaoutput-scrolling {
- min-height: 2em;
- max-height: 20em;
- overflow: auto;
- box-shadow: inset 0px -20px 30px -20px black;
- }
- .scrolltoggle-gutter {
- width: 2em;
- }
- .luasnippet-controls {
- float: right;
- background-color: inherit;
- }
- </style>
- </head>
- <body ng-app="witchcraftApp">
- <div id="snippet-container">
- <div ng-controller="LuaSnippetController" ng-init="setId(snippet.id)" ng-repeat="snippet in snippets"></div>
- <button ng-click="snippetManager.appendSnippet();" style="margin-left:10px; margin-top: 10px;">New Snippet</button>
- </div>
- <div id="snippet-templates" style="display: none;">
- <div title="clear"></div>
- <div title="list all unit IDs">
- -- requires MiST to be included
- local unit_names = {}
- for _, u in pairs(mist.DBs.aliveUnits) do
- unit_names[#unit_names+1] = u.unit:getName()
- end
- return unit_names
- </div>
- <div title="check user flag">
- -- to set a flag:
- -- trigger.action.setUserFlag(42, 23) -- set flag 42 to 23
- return trigger.misc.getUserFlag(42)
- </div>
- <div title="_G dump using MiST">
- return mist.utils.tableShow(_G)
- </div>
- <div title="spawn HMMWVs (Lua Interaction)">
- -- 1. Execute this code
- -- 2. In another tab, have the map open and select the "Lua Interaction" tool
- -- 3. Place the camera in DCS: World so it looks at where you are about to place units
- -- 4. Mousewheel rotates, left click places a HMMWV
- witchcraft.heading = 0.0 -- global variable
- function respawn_unit(event, copy)
- lastevent = event
- local unitsTable = {
- ["visible"] = false,
- ["taskSelected"] = true,
- ["route"] =
- {
- ["spans"] =
- {
- }, -- end of ["spans"]
- ["points"] =
- {
- [1] =
- {
- ["alt"] = event.vec3.y,
- ["type"] = "Turning Point",
- ["ETA"] = 0,
- ["alt_type"] = "BARO",
- ["formation_template"] = "",
- ["y"] = event.vec2.y,
- ["x"] = event.vec2.x,
- ["ETA_locked"] = true,
- ["speed"] = 5.5555555555556,
- ["action"] = "Off Road",
- ["task"] =
- {
- ["id"] = "ComboTask",
- ["params"] =
- {
- ["tasks"] =
- {
- [1] =
- {
- ["enabled"] = true,
- ["auto"] = true,
- ["id"] = "WrappedAction",
- ["number"] = 1,
- ["params"] =
- {
- ["action"] =
- {
- ["id"] = "EPLRS",
- ["params"] =
- {
- ["value"] = true,
- ["groupId"] = 2,
- }, -- end of ["params"]
- }, -- end of ["action"]
- }, -- end of ["params"]
- }, -- end of [1]
- }, -- end of ["tasks"]
- }, -- end of ["params"]
- }, -- end of ["task"]
- ["speed_locked"] = true,
- }, -- end of [1]
- }, -- end of ["points"]
- }, -- end of ["route"]
- ["groupId"] = 30,
- ["tasks"] =
- {
- }, -- end of ["tasks"]
- ["hidden"] = false,
- ["units"] =
- {
- [1] =
- {
- ["y"] = event.vec2.y,
- ["type"] = "M1043 HMMWV Armament",
- ["name"] = "cursor_unit",
- ["unitId"] = 30,
- ["heading"] = witchcraft.heading,
- ["playerCanDrive"] = true,
- ["skill"] = "Average",
- ["x"] = event.vec2.x,
- }, -- end of [1]
- }, -- end of ["units"]
- ["y"] = event.vec2.y,
- ["x"] = event.vec2.x,
- ["name"] = "CursorGroup",
- ["start_time"] = 0,
- ["task"] = "Ground Nothing",
- }
- unitsTable.country = "USA"
- unitsTable.category = "vehicle"
- if copy then
- unitsTable.groupId = nil
- unitsTable.name = nil
- unitsTable.units[1].unitId = nil
- unitsTable.units[1].name = nil
- end
- mist.dynAdd(unitsTable)
- end
- -- define event handlers
- -- event handlers will be passed an event object with the
- -- following properties:
- -- vec2: click position
- -- vec3: click position (altitude determined by land.getHeight)
- -- onClick: called for every click on the map
- witchcraft.onClick = nil
- -- onSingleClick: called after 250 ms when OpenLayers has
- -- determined this is not a drag action or double click
- witchcraft.onSingleClick = function(event)
- Unit.getByName("cursor_unit"):destroy()
- respawn_unit(event, true)
- respawn_unit(event)
- end
- -- onDblClick: for double clicks
- witchcraft.onDblClick = nil
- -- onMousewheel: handles mousewheel events
- -- event.deltaY has the direction info (typically +3 or -3)
- witchcraft.onMousewheel = function(event)
- if event.deltaY < 0 then
- witchcraft.heading = witchcraft.heading - .1
- else
- witchcraft.heading = witchcraft.heading + .1
- end
- respawn_unit(event)
- end
- -- onMove: called when the pointer is moved over the map
- -- rate-limited to 10 times per second
- witchcraft.onMove = function(event)
- respawn_unit(event)
- end
- </div>
- <div title="move units (Lua Interaction)">
- if witchcraft.unitUpdateInterval == 0 then witchcraft.unitUpdateInterval = .5 end
-
- witchcraft.unitmover = {}
- witchcraft.unitmover.moving = false
- witchcraft.unitmover.heading = 0.0
- witchcraft.unitmover.hdgstep = math.pi/16
- witchcraft.unitmover.do_move = function(event)
- local un = witchcraft.unitmover.unitName
- local gn = Unit.getByName(un):getGroup():getName()
-
- local groupTable = mist.utils.deepCopy(mist.DBs.groupsByName[gn])
- for _, unit in pairs(groupTable.units) do
- if unit.unitName == un then
- unit.heading = witchcraft.unitmover.heading
- unit.x = event.vec2.x
- unit.y = event.vec2.y
- else
- local u = Unit.getByName(unit.unitName)
- if u and u:isExist() then
- local pos = u:getPosition()
- local hdg = math.pi / 2 -math.atan2(pos.x.x, pos.x.z)
- unit.x = pos.p.x
- unit.y = pos.p.z
- unit.heading = hdg
- end
- end
- end
- mist.dynAdd(groupTable)
- end
- -- define event handlers
- -- event handlers will be passed an event object with the
- -- following properties:
- -- vec2: click position
- -- vec3: click position (altitude determined by land.getHeight)
- -- onClick: called for every click on the map
- witchcraft.onClick = nil
- -- onSingleClick: called after 250 ms when OpenLayers has
- -- determined this is not a drag action or double click
- witchcraft.onSingleClick = function(event)
- if witchcraft.unitmover.moving then
- witchcraft.unitmover.moving = false
- return
- end
-
- if not event.clickedUnitName then return end
-
- witchcraft.unitmover.unitName = event.clickedUnitName
- local pos = Unit.getByName(event.clickedUnitName):getPosition()
- local hdg = math.pi / 2 -math.atan2(pos.x.x, pos.x.z)
- witchcraft.unitmover.heading = hdg
- witchcraft.unitmover.moving = true
- witchcraft.unitmover.do_move(event)
- end
- -- onDblClick: for double clicks
- witchcraft.onDblClick = nil
- -- onMousewheel: handles mousewheel events
- -- event.deltaY has the direction info (typically +3 or -3)
- witchcraft.onMousewheel = function(event)
- if not witchcraft.unitmover.moving then return end
- if event.deltaY < 0 then
- witchcraft.unitmover.heading = witchcraft.unitmover.heading - witchcraft.unitmover.hdgstep
- else
- witchcraft.unitmover.heading = witchcraft.unitmover.heading + witchcraft.unitmover.hdgstep
- end
- witchcraft.unitmover.do_move(event)
- end
- -- onMove: called when the pointer is moved over the map
- -- rate-limited to 10 times per second
- witchcraft.onMove = function(event)
- if not witchcraft.unitmover.moving then return end
- witchcraft.unitmover.do_move(event)
- end
-
- </div>
- <div title="disable all Lua Interaction event handlers">
- witchcraft.onClick = nil
- witchcraft.onSingleClick = nil
- witchcraft.onDblClick = nil
- witchcraft.onMousewheel = nil
- witchcraft.onMove = nil
- </div>
- <div title="enable unit updates">
- -- units on the map will be updated approximately two times per second
- witchcraft.unitUpdateInterval = .5
- </div>
- <div title="disable unit updates">
- -- disable regular unit updates
- witchcraft.unitUpdateInterval = 0
- </div>
- </div>
- </body>
- <script src="/js/vendor/jquery/jquery-2.1.1.min.js"></script>
- <script src="bootstrap-3.1.1-dist/js/bootstrap.min.js"></script>
- <script src="/js/vendor/codemirror-4.3/lib/codemirror.js"></script>
- <script src="/js/vendor/codemirror-4.3/mode/lua/lua.js"></script>
- <script src="/js/vendor/codemirror-4.3/addon/selection/active-line.js"></script>
- <script src="/js/vendor/lodash/dist/lodash.js"></script>
- <script>var lodash = _;</script>
- <script src="/js/vendor/StateTree/statetree.js"></script>
-
- <script src="/js/vendor/angularjs/angular.js"></script>
- <script src="/socket.io/socket.io.js"></script>
- <script src="/js/app.js"></script>
- <script src="/js/factories/socket.js"></script>
- <script src="/js/factories/luashell.js"></script>
- <script src="/js/controllers/luasnippet.js"></script>
- <script src="/js/factories/snippetmanager.js"></script>
-
- <script>
- app.run(['snippetManager', function(snippetManager) {
- snippetManager.appendSnippet();
- }]);
- </script>
-
- </html>