PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/frontend/console.html

https://gitlab.com/132nd-etcher/dcs-witchcraft
HTML | 332 lines | 303 code | 29 blank | 0 comment | 0 complexity | 128a764690c893d52370b0925473d194 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" href="bootstrap-3.1.1-dist/css/bootstrap.min.css">
  5. <link rel="stylesheet" href="/js/vendor/codemirror-4.3/lib/codemirror.css">
  6. <link rel="stylesheet" href="/js/vendor/codemirror-4.3/theme/neat.css">
  7. <style>
  8. .CodeMirror {
  9. border: 1px solid #eee;
  10. height: auto;
  11. }
  12. .CodeMirror-scroll {
  13. overflow-y: hidden;
  14. overflow-x: auto;
  15. }
  16. .luasnippet {
  17. margin-top: 10px;
  18. margin-left: 10px;
  19. margin-right: 10px;
  20. border-radius: 5px;
  21. padding: 5px;
  22. border: 1px solid #ddd;
  23. }
  24. .luaoutput {
  25. white-space: pre-wrap;
  26. font-family: monospace;
  27. }
  28. .luaoutput-scrolling {
  29. min-height: 2em;
  30. max-height: 20em;
  31. overflow: auto;
  32. box-shadow: inset 0px -20px 30px -20px black;
  33. }
  34. .scrolltoggle-gutter {
  35. width: 2em;
  36. }
  37. .luasnippet-controls {
  38. float: right;
  39. background-color: inherit;
  40. }
  41. </style>
  42. </head>
  43. <body ng-app="witchcraftApp">
  44. <div id="snippet-container">
  45. <div ng-controller="LuaSnippetController" ng-init="setId(snippet.id)" ng-repeat="snippet in snippets"></div>
  46. <button ng-click="snippetManager.appendSnippet();" style="margin-left:10px; margin-top: 10px;">New Snippet</button>
  47. </div>
  48. <div id="snippet-templates" style="display: none;">
  49. <div title="clear"></div>
  50. <div title="list all unit IDs">
  51. -- requires MiST to be included
  52. local unit_names = {}
  53. for _, u in pairs(mist.DBs.aliveUnits) do
  54. unit_names[#unit_names+1] = u.unit:getName()
  55. end
  56. return unit_names
  57. </div>
  58. <div title="check user flag">
  59. -- to set a flag:
  60. -- trigger.action.setUserFlag(42, 23) -- set flag 42 to 23
  61. return trigger.misc.getUserFlag(42)
  62. </div>
  63. <div title="_G dump using MiST">
  64. return mist.utils.tableShow(_G)
  65. </div>
  66. <div title="spawn HMMWVs (Lua Interaction)">
  67. -- 1. Execute this code
  68. -- 2. In another tab, have the map open and select the "Lua Interaction" tool
  69. -- 3. Place the camera in DCS: World so it looks at where you are about to place units
  70. -- 4. Mousewheel rotates, left click places a HMMWV
  71. witchcraft.heading = 0.0 -- global variable
  72. function respawn_unit(event, copy)
  73. lastevent = event
  74. local unitsTable = {
  75. ["visible"] = false,
  76. ["taskSelected"] = true,
  77. ["route"] =
  78. {
  79. ["spans"] =
  80. {
  81. }, -- end of ["spans"]
  82. ["points"] =
  83. {
  84. [1] =
  85. {
  86. ["alt"] = event.vec3.y,
  87. ["type"] = "Turning Point",
  88. ["ETA"] = 0,
  89. ["alt_type"] = "BARO",
  90. ["formation_template"] = "",
  91. ["y"] = event.vec2.y,
  92. ["x"] = event.vec2.x,
  93. ["ETA_locked"] = true,
  94. ["speed"] = 5.5555555555556,
  95. ["action"] = "Off Road",
  96. ["task"] =
  97. {
  98. ["id"] = "ComboTask",
  99. ["params"] =
  100. {
  101. ["tasks"] =
  102. {
  103. [1] =
  104. {
  105. ["enabled"] = true,
  106. ["auto"] = true,
  107. ["id"] = "WrappedAction",
  108. ["number"] = 1,
  109. ["params"] =
  110. {
  111. ["action"] =
  112. {
  113. ["id"] = "EPLRS",
  114. ["params"] =
  115. {
  116. ["value"] = true,
  117. ["groupId"] = 2,
  118. }, -- end of ["params"]
  119. }, -- end of ["action"]
  120. }, -- end of ["params"]
  121. }, -- end of [1]
  122. }, -- end of ["tasks"]
  123. }, -- end of ["params"]
  124. }, -- end of ["task"]
  125. ["speed_locked"] = true,
  126. }, -- end of [1]
  127. }, -- end of ["points"]
  128. }, -- end of ["route"]
  129. ["groupId"] = 30,
  130. ["tasks"] =
  131. {
  132. }, -- end of ["tasks"]
  133. ["hidden"] = false,
  134. ["units"] =
  135. {
  136. [1] =
  137. {
  138. ["y"] = event.vec2.y,
  139. ["type"] = "M1043 HMMWV Armament",
  140. ["name"] = "cursor_unit",
  141. ["unitId"] = 30,
  142. ["heading"] = witchcraft.heading,
  143. ["playerCanDrive"] = true,
  144. ["skill"] = "Average",
  145. ["x"] = event.vec2.x,
  146. }, -- end of [1]
  147. }, -- end of ["units"]
  148. ["y"] = event.vec2.y,
  149. ["x"] = event.vec2.x,
  150. ["name"] = "CursorGroup",
  151. ["start_time"] = 0,
  152. ["task"] = "Ground Nothing",
  153. }
  154. unitsTable.country = "USA"
  155. unitsTable.category = "vehicle"
  156. if copy then
  157. unitsTable.groupId = nil
  158. unitsTable.name = nil
  159. unitsTable.units[1].unitId = nil
  160. unitsTable.units[1].name = nil
  161. end
  162. mist.dynAdd(unitsTable)
  163. end
  164. -- define event handlers
  165. -- event handlers will be passed an event object with the
  166. -- following properties:
  167. -- vec2: click position
  168. -- vec3: click position (altitude determined by land.getHeight)
  169. -- onClick: called for every click on the map
  170. witchcraft.onClick = nil
  171. -- onSingleClick: called after 250 ms when OpenLayers has
  172. -- determined this is not a drag action or double click
  173. witchcraft.onSingleClick = function(event)
  174. Unit.getByName("cursor_unit"):destroy()
  175. respawn_unit(event, true)
  176. respawn_unit(event)
  177. end
  178. -- onDblClick: for double clicks
  179. witchcraft.onDblClick = nil
  180. -- onMousewheel: handles mousewheel events
  181. -- event.deltaY has the direction info (typically +3 or -3)
  182. witchcraft.onMousewheel = function(event)
  183. if event.deltaY < 0 then
  184. witchcraft.heading = witchcraft.heading - .1
  185. else
  186. witchcraft.heading = witchcraft.heading + .1
  187. end
  188. respawn_unit(event)
  189. end
  190. -- onMove: called when the pointer is moved over the map
  191. -- rate-limited to 10 times per second
  192. witchcraft.onMove = function(event)
  193. respawn_unit(event)
  194. end
  195. </div>
  196. <div title="move units (Lua Interaction)">
  197. if witchcraft.unitUpdateInterval == 0 then witchcraft.unitUpdateInterval = .5 end
  198. witchcraft.unitmover = {}
  199. witchcraft.unitmover.moving = false
  200. witchcraft.unitmover.heading = 0.0
  201. witchcraft.unitmover.hdgstep = math.pi/16
  202. witchcraft.unitmover.do_move = function(event)
  203. local un = witchcraft.unitmover.unitName
  204. local gn = Unit.getByName(un):getGroup():getName()
  205. local groupTable = mist.utils.deepCopy(mist.DBs.groupsByName[gn])
  206. for _, unit in pairs(groupTable.units) do
  207. if unit.unitName == un then
  208. unit.heading = witchcraft.unitmover.heading
  209. unit.x = event.vec2.x
  210. unit.y = event.vec2.y
  211. else
  212. local u = Unit.getByName(unit.unitName)
  213. if u and u:isExist() then
  214. local pos = u:getPosition()
  215. local hdg = math.pi / 2 -math.atan2(pos.x.x, pos.x.z)
  216. unit.x = pos.p.x
  217. unit.y = pos.p.z
  218. unit.heading = hdg
  219. end
  220. end
  221. end
  222. mist.dynAdd(groupTable)
  223. end
  224. -- define event handlers
  225. -- event handlers will be passed an event object with the
  226. -- following properties:
  227. -- vec2: click position
  228. -- vec3: click position (altitude determined by land.getHeight)
  229. -- onClick: called for every click on the map
  230. witchcraft.onClick = nil
  231. -- onSingleClick: called after 250 ms when OpenLayers has
  232. -- determined this is not a drag action or double click
  233. witchcraft.onSingleClick = function(event)
  234. if witchcraft.unitmover.moving then
  235. witchcraft.unitmover.moving = false
  236. return
  237. end
  238. if not event.clickedUnitName then return end
  239. witchcraft.unitmover.unitName = event.clickedUnitName
  240. local pos = Unit.getByName(event.clickedUnitName):getPosition()
  241. local hdg = math.pi / 2 -math.atan2(pos.x.x, pos.x.z)
  242. witchcraft.unitmover.heading = hdg
  243. witchcraft.unitmover.moving = true
  244. witchcraft.unitmover.do_move(event)
  245. end
  246. -- onDblClick: for double clicks
  247. witchcraft.onDblClick = nil
  248. -- onMousewheel: handles mousewheel events
  249. -- event.deltaY has the direction info (typically +3 or -3)
  250. witchcraft.onMousewheel = function(event)
  251. if not witchcraft.unitmover.moving then return end
  252. if event.deltaY < 0 then
  253. witchcraft.unitmover.heading = witchcraft.unitmover.heading - witchcraft.unitmover.hdgstep
  254. else
  255. witchcraft.unitmover.heading = witchcraft.unitmover.heading + witchcraft.unitmover.hdgstep
  256. end
  257. witchcraft.unitmover.do_move(event)
  258. end
  259. -- onMove: called when the pointer is moved over the map
  260. -- rate-limited to 10 times per second
  261. witchcraft.onMove = function(event)
  262. if not witchcraft.unitmover.moving then return end
  263. witchcraft.unitmover.do_move(event)
  264. end
  265. </div>
  266. <div title="disable all Lua Interaction event handlers">
  267. witchcraft.onClick = nil
  268. witchcraft.onSingleClick = nil
  269. witchcraft.onDblClick = nil
  270. witchcraft.onMousewheel = nil
  271. witchcraft.onMove = nil
  272. </div>
  273. <div title="enable unit updates">
  274. -- units on the map will be updated approximately two times per second
  275. witchcraft.unitUpdateInterval = .5
  276. </div>
  277. <div title="disable unit updates">
  278. -- disable regular unit updates
  279. witchcraft.unitUpdateInterval = 0
  280. </div>
  281. </div>
  282. </body>
  283. <script src="/js/vendor/jquery/jquery-2.1.1.min.js"></script>
  284. <script src="bootstrap-3.1.1-dist/js/bootstrap.min.js"></script>
  285. <script src="/js/vendor/codemirror-4.3/lib/codemirror.js"></script>
  286. <script src="/js/vendor/codemirror-4.3/mode/lua/lua.js"></script>
  287. <script src="/js/vendor/codemirror-4.3/addon/selection/active-line.js"></script>
  288. <script src="/js/vendor/lodash/dist/lodash.js"></script>
  289. <script>var lodash = _;</script>
  290. <script src="/js/vendor/StateTree/statetree.js"></script>
  291. <script src="/js/vendor/angularjs/angular.js"></script>
  292. <script src="/socket.io/socket.io.js"></script>
  293. <script src="/js/app.js"></script>
  294. <script src="/js/factories/socket.js"></script>
  295. <script src="/js/factories/luashell.js"></script>
  296. <script src="/js/controllers/luasnippet.js"></script>
  297. <script src="/js/factories/snippetmanager.js"></script>
  298. <script>
  299. app.run(['snippetManager', function(snippetManager) {
  300. snippetManager.appendSnippet();
  301. }]);
  302. </script>
  303. </html>