excalibur 0.25.2 → 0.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/build/dist/Actions/Action/Blink.js +51 -0
  3. package/build/dist/Actions/Action/Blink.js.map +1 -0
  4. package/build/dist/Actions/Action/CallMethod.js +21 -0
  5. package/build/dist/Actions/Action/CallMethod.js.map +1 -0
  6. package/build/dist/Actions/Action/Delay.js +25 -0
  7. package/build/dist/Actions/Action/Delay.js.map +1 -0
  8. package/build/dist/Actions/Action/Die.js +22 -0
  9. package/build/dist/Actions/Action/Die.js.map +1 -0
  10. package/build/dist/Actions/Action/EaseTo.js +69 -0
  11. package/build/dist/Actions/Action/EaseTo.js.map +1 -0
  12. package/build/dist/Actions/Action/Fade.js +46 -0
  13. package/build/dist/Actions/Action/Fade.js.map +1 -0
  14. package/build/dist/Actions/Action/Follow.js +55 -0
  15. package/build/dist/Actions/Action/Follow.js.map +1 -0
  16. package/build/dist/Actions/Action/Meet.js +52 -0
  17. package/build/dist/Actions/Action/Meet.js.map +1 -0
  18. package/build/dist/Actions/Action/MoveBy.js +47 -0
  19. package/build/dist/Actions/Action/MoveBy.js.map +1 -0
  20. package/build/dist/Actions/Action/MoveTo.js +40 -0
  21. package/build/dist/Actions/Action/MoveTo.js.map +1 -0
  22. package/build/dist/Actions/Action/Repeat.js +31 -0
  23. package/build/dist/Actions/Action/Repeat.js.map +1 -0
  24. package/build/dist/Actions/Action/RepeatForever.js +37 -0
  25. package/build/dist/Actions/Action/RepeatForever.js.map +1 -0
  26. package/build/dist/Actions/Action/RotateBy.js +91 -0
  27. package/build/dist/Actions/Action/RotateBy.js.map +1 -0
  28. package/build/dist/Actions/Action/RotateTo.js +90 -0
  29. package/build/dist/Actions/Action/RotateTo.js.map +1 -0
  30. package/build/dist/Actions/Action/ScaleBy.js +45 -0
  31. package/build/dist/Actions/Action/ScaleBy.js.map +1 -0
  32. package/build/dist/Actions/Action/ScaleTo.js +56 -0
  33. package/build/dist/Actions/Action/ScaleTo.js.map +1 -0
  34. package/build/dist/Actions/Action.js +2 -0
  35. package/build/dist/Actions/Action.js.map +1 -0
  36. package/build/dist/Actions/ActionContext.js +305 -0
  37. package/build/dist/Actions/ActionContext.js.map +1 -0
  38. package/build/dist/Actions/ActionQueue.js +87 -0
  39. package/build/dist/Actions/ActionQueue.js.map +1 -0
  40. package/build/dist/Actions/Actionable.js +2 -0
  41. package/build/dist/Actions/Actionable.js.map +1 -0
  42. package/build/dist/Actions/ActionsComponent.js +198 -0
  43. package/build/dist/Actions/ActionsComponent.js.map +1 -0
  44. package/build/dist/Actions/ActionsSystem.js +18 -0
  45. package/build/dist/Actions/ActionsSystem.js.map +1 -0
  46. package/build/dist/Actions/Index.js +22 -0
  47. package/build/dist/Actions/Index.js.map +1 -0
  48. package/build/dist/Actions/RotationType.js +27 -0
  49. package/build/dist/Actions/RotationType.js.map +1 -0
  50. package/build/dist/Actor.js +831 -0
  51. package/build/dist/Actor.js.map +1 -0
  52. package/build/dist/Camera.js +663 -0
  53. package/build/dist/Camera.js.map +1 -0
  54. package/build/dist/Class.js +48 -0
  55. package/build/dist/Class.js.map +1 -0
  56. package/build/dist/Collision/BodyComponent.js +351 -0
  57. package/build/dist/Collision/BodyComponent.js.map +1 -0
  58. package/build/dist/Collision/BoundingBox.js +361 -0
  59. package/build/dist/Collision/BoundingBox.js.map +1 -0
  60. package/build/dist/Collision/ColliderComponent.js +198 -0
  61. package/build/dist/Collision/ColliderComponent.js.map +1 -0
  62. package/build/dist/Collision/Colliders/CircleCollider.js +264 -0
  63. package/build/dist/Collision/Colliders/CircleCollider.js.map +1 -0
  64. package/build/dist/Collision/Colliders/ClosestLineJumpTable.js +211 -0
  65. package/build/dist/Collision/Colliders/ClosestLineJumpTable.js.map +1 -0
  66. package/build/dist/Collision/Colliders/Collider.js +26 -0
  67. package/build/dist/Collision/Colliders/Collider.js.map +1 -0
  68. package/build/dist/Collision/Colliders/CollisionJumpTable.js +301 -0
  69. package/build/dist/Collision/Colliders/CollisionJumpTable.js.map +1 -0
  70. package/build/dist/Collision/Colliders/CompositeCollider.js +232 -0
  71. package/build/dist/Collision/Colliders/CompositeCollider.js.map +1 -0
  72. package/build/dist/Collision/Colliders/EdgeCollider.js +253 -0
  73. package/build/dist/Collision/Colliders/EdgeCollider.js.map +1 -0
  74. package/build/dist/Collision/Colliders/PolygonCollider.js +389 -0
  75. package/build/dist/Collision/Colliders/PolygonCollider.js.map +1 -0
  76. package/build/dist/Collision/Colliders/SeparatingAxis.js +67 -0
  77. package/build/dist/Collision/Colliders/SeparatingAxis.js.map +1 -0
  78. package/build/dist/Collision/Colliders/Shape.js +102 -0
  79. package/build/dist/Collision/Colliders/Shape.js.map +1 -0
  80. package/build/dist/Collision/CollisionSystem.js +116 -0
  81. package/build/dist/Collision/CollisionSystem.js.map +1 -0
  82. package/build/dist/Collision/CollisionType.js +33 -0
  83. package/build/dist/Collision/CollisionType.js.map +1 -0
  84. package/build/dist/Collision/Detection/CollisionContact.js +46 -0
  85. package/build/dist/Collision/Detection/CollisionContact.js.map +1 -0
  86. package/build/dist/Collision/Detection/CollisionProcessor.js +2 -0
  87. package/build/dist/Collision/Detection/CollisionProcessor.js.map +1 -0
  88. package/build/dist/Collision/Detection/DynamicTree.js +442 -0
  89. package/build/dist/Collision/Detection/DynamicTree.js.map +1 -0
  90. package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js +211 -0
  91. package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js.map +1 -0
  92. package/build/dist/Collision/Detection/Pair.js +92 -0
  93. package/build/dist/Collision/Detection/Pair.js.map +1 -0
  94. package/build/dist/Collision/Group/CollisionGroup.js +114 -0
  95. package/build/dist/Collision/Group/CollisionGroup.js.map +1 -0
  96. package/build/dist/Collision/Group/CollisionGroupManager.js +52 -0
  97. package/build/dist/Collision/Group/CollisionGroupManager.js.map +1 -0
  98. package/build/dist/Collision/Index.js +29 -0
  99. package/build/dist/Collision/Index.js.map +1 -0
  100. package/build/dist/Collision/Integrator.js +11 -0
  101. package/build/dist/Collision/Integrator.js.map +1 -0
  102. package/build/dist/Collision/MotionSystem.js +42 -0
  103. package/build/dist/Collision/MotionSystem.js.map +1 -0
  104. package/build/dist/Collision/Physics.js +163 -0
  105. package/build/dist/Collision/Physics.js.map +1 -0
  106. package/build/dist/Collision/Side.js +51 -0
  107. package/build/dist/Collision/Side.js.map +1 -0
  108. package/build/dist/Collision/Solver/ArcadeSolver.js +101 -0
  109. package/build/dist/Collision/Solver/ArcadeSolver.js.map +1 -0
  110. package/build/dist/Collision/Solver/ContactConstraintPoint.js +83 -0
  111. package/build/dist/Collision/Solver/ContactConstraintPoint.js.map +1 -0
  112. package/build/dist/Collision/Solver/RealisticSolver.js +248 -0
  113. package/build/dist/Collision/Solver/RealisticSolver.js.map +1 -0
  114. package/build/dist/Collision/Solver/Solver.js +37 -0
  115. package/build/dist/Collision/Solver/Solver.js.map +1 -0
  116. package/build/dist/Color.js +461 -0
  117. package/build/dist/Color.js.map +1 -0
  118. package/build/dist/Configurable.js +32 -0
  119. package/build/dist/Configurable.js.map +1 -0
  120. package/build/dist/Debug/Debug.js +375 -0
  121. package/build/dist/Debug/Debug.js.map +1 -0
  122. package/build/dist/Debug/DebugFlags.js +40 -0
  123. package/build/dist/Debug/DebugFlags.js.map +1 -0
  124. package/build/dist/Debug/DebugSystem.js +251 -0
  125. package/build/dist/Debug/DebugSystem.js.map +1 -0
  126. package/build/dist/Debug/index.js +4 -0
  127. package/build/dist/Debug/index.js.map +1 -0
  128. package/build/dist/Deprecated.js +2 -0
  129. package/build/dist/Deprecated.js.map +1 -0
  130. package/build/dist/Drawing/Animation.js +294 -0
  131. package/build/dist/Drawing/Animation.js.map +1 -0
  132. package/build/dist/Drawing/CanvasDrawComponent.js +16 -0
  133. package/build/dist/Drawing/CanvasDrawComponent.js.map +1 -0
  134. package/build/dist/Drawing/CanvasDrawingSystem.js +95 -0
  135. package/build/dist/Drawing/CanvasDrawingSystem.js.map +1 -0
  136. package/build/dist/Drawing/Index.js +10 -0
  137. package/build/dist/Drawing/Index.js.map +1 -0
  138. package/build/dist/Drawing/Polygon.js +139 -0
  139. package/build/dist/Drawing/Polygon.js.map +1 -0
  140. package/build/dist/Drawing/Sprite.js +355 -0
  141. package/build/dist/Drawing/Sprite.js.map +1 -0
  142. package/build/dist/Drawing/SpriteEffects.js +246 -0
  143. package/build/dist/Drawing/SpriteEffects.js.map +1 -0
  144. package/build/dist/Drawing/SpriteSheet.js +413 -0
  145. package/build/dist/Drawing/SpriteSheet.js.map +1 -0
  146. package/build/dist/Drawing/Texture.js +69 -0
  147. package/build/dist/Drawing/Texture.js.map +1 -0
  148. package/build/dist/Engine.d.ts +4 -1
  149. package/build/dist/Engine.js +985 -0
  150. package/build/dist/Engine.js.map +1 -0
  151. package/build/dist/EntityComponentSystem/Component.js +65 -0
  152. package/build/dist/EntityComponentSystem/Component.js.map +1 -0
  153. package/build/dist/EntityComponentSystem/Components/MotionComponent.js +33 -0
  154. package/build/dist/EntityComponentSystem/Components/MotionComponent.js.map +1 -0
  155. package/build/dist/EntityComponentSystem/Components/TransformComponent.js +249 -0
  156. package/build/dist/EntityComponentSystem/Components/TransformComponent.js.map +1 -0
  157. package/build/dist/EntityComponentSystem/Entity.js +452 -0
  158. package/build/dist/EntityComponentSystem/Entity.js.map +1 -0
  159. package/build/dist/EntityComponentSystem/EntityManager.js +128 -0
  160. package/build/dist/EntityComponentSystem/EntityManager.js.map +1 -0
  161. package/build/dist/EntityComponentSystem/Query.js +91 -0
  162. package/build/dist/EntityComponentSystem/Query.js.map +1 -0
  163. package/build/dist/EntityComponentSystem/QueryManager.js +90 -0
  164. package/build/dist/EntityComponentSystem/QueryManager.js.map +1 -0
  165. package/build/dist/EntityComponentSystem/System.js +76 -0
  166. package/build/dist/EntityComponentSystem/System.js.map +1 -0
  167. package/build/dist/EntityComponentSystem/SystemManager.js +102 -0
  168. package/build/dist/EntityComponentSystem/SystemManager.js.map +1 -0
  169. package/build/dist/EntityComponentSystem/Util.js +5 -0
  170. package/build/dist/EntityComponentSystem/Util.js.map +1 -0
  171. package/build/dist/EntityComponentSystem/World.js +55 -0
  172. package/build/dist/EntityComponentSystem/World.js.map +1 -0
  173. package/build/dist/EntityComponentSystem/index.js +11 -0
  174. package/build/dist/EntityComponentSystem/index.js.map +1 -0
  175. package/build/dist/EventDispatcher.js +114 -0
  176. package/build/dist/EventDispatcher.js.map +1 -0
  177. package/build/dist/Events/ExEvent.js +12 -0
  178. package/build/dist/Events/ExEvent.js.map +1 -0
  179. package/build/dist/Events/MediaEvents.js +75 -0
  180. package/build/dist/Events/MediaEvents.js.map +1 -0
  181. package/build/dist/Events/PointerEvents.js +52 -0
  182. package/build/dist/Events/PointerEvents.js.map +1 -0
  183. package/build/dist/Events.js +497 -0
  184. package/build/dist/Events.js.map +1 -0
  185. package/build/dist/Flags.js +90 -0
  186. package/build/dist/Flags.js.map +1 -0
  187. package/build/dist/Graphics/Animation.js +310 -0
  188. package/build/dist/Graphics/Animation.js.map +1 -0
  189. package/build/dist/Graphics/Canvas.js +38 -0
  190. package/build/dist/Graphics/Canvas.js.map +1 -0
  191. package/build/dist/Graphics/Circle.js +47 -0
  192. package/build/dist/Graphics/Circle.js.map +1 -0
  193. package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js +2 -0
  194. package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js.map +1 -0
  195. package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js +207 -0
  196. package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js.map +1 -0
  197. package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js +331 -0
  198. package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js.map +1 -0
  199. package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js +160 -0
  200. package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js.map +1 -0
  201. package/build/dist/Graphics/Context/debug-text.js +47 -0
  202. package/build/dist/Graphics/Context/debug-text.js.map +1 -0
  203. package/build/dist/Graphics/Context/image-renderer/image-renderer.js +209 -0
  204. package/build/dist/Graphics/Context/image-renderer/image-renderer.js.map +1 -0
  205. package/build/dist/Graphics/Context/line-renderer/line-renderer.js +87 -0
  206. package/build/dist/Graphics/Context/line-renderer/line-renderer.js.map +1 -0
  207. package/build/dist/Graphics/Context/point-renderer/point-renderer.js +82 -0
  208. package/build/dist/Graphics/Context/point-renderer/point-renderer.js.map +1 -0
  209. package/build/dist/Graphics/Context/quad-index-buffer.js +69 -0
  210. package/build/dist/Graphics/Context/quad-index-buffer.js.map +1 -0
  211. package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js +272 -0
  212. package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js.map +1 -0
  213. package/build/dist/Graphics/Context/render-source.js +16 -0
  214. package/build/dist/Graphics/Context/render-source.js.map +1 -0
  215. package/build/dist/Graphics/Context/render-target.js +65 -0
  216. package/build/dist/Graphics/Context/render-target.js.map +1 -0
  217. package/build/dist/Graphics/Context/renderer.js +2 -0
  218. package/build/dist/Graphics/Context/renderer.js.map +1 -0
  219. package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js +53 -0
  220. package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js.map +1 -0
  221. package/build/dist/Graphics/Context/shader.js +236 -0
  222. package/build/dist/Graphics/Context/shader.js.map +1 -0
  223. package/build/dist/Graphics/Context/state-stack.js +27 -0
  224. package/build/dist/Graphics/Context/state-stack.js.map +1 -0
  225. package/build/dist/Graphics/Context/texture-loader.d.ts +8 -0
  226. package/build/dist/Graphics/Context/texture-loader.js +121 -0
  227. package/build/dist/Graphics/Context/texture-loader.js.map +1 -0
  228. package/build/dist/Graphics/Context/transform-stack.js +30 -0
  229. package/build/dist/Graphics/Context/transform-stack.js.map +1 -0
  230. package/build/dist/Graphics/Context/vertex-buffer.js +45 -0
  231. package/build/dist/Graphics/Context/vertex-buffer.js.map +1 -0
  232. package/build/dist/Graphics/Context/vertex-layout.js +93 -0
  233. package/build/dist/Graphics/Context/vertex-layout.js.map +1 -0
  234. package/build/dist/Graphics/Context/webgl-adapter.js +19 -0
  235. package/build/dist/Graphics/Context/webgl-adapter.js.map +1 -0
  236. package/build/dist/Graphics/Context/webgl-util.js +105 -0
  237. package/build/dist/Graphics/Context/webgl-util.js.map +1 -0
  238. package/build/dist/Graphics/DebugGraphicsComponent.js +15 -0
  239. package/build/dist/Graphics/DebugGraphicsComponent.js.map +1 -0
  240. package/build/dist/Graphics/Filtering.js +17 -0
  241. package/build/dist/Graphics/Filtering.js.map +1 -0
  242. package/build/dist/Graphics/Font.js +293 -0
  243. package/build/dist/Graphics/Font.js.map +1 -0
  244. package/build/dist/Graphics/FontCommon.js +109 -0
  245. package/build/dist/Graphics/FontCommon.js.map +1 -0
  246. package/build/dist/Graphics/Graphic.js +200 -0
  247. package/build/dist/Graphics/Graphic.js.map +1 -0
  248. package/build/dist/Graphics/GraphicsComponent.js +290 -0
  249. package/build/dist/Graphics/GraphicsComponent.js.map +1 -0
  250. package/build/dist/Graphics/GraphicsDiagnostics.js +9 -0
  251. package/build/dist/Graphics/GraphicsDiagnostics.js.map +1 -0
  252. package/build/dist/Graphics/GraphicsGroup.js +69 -0
  253. package/build/dist/Graphics/GraphicsGroup.js.map +1 -0
  254. package/build/dist/Graphics/GraphicsSystem.js +153 -0
  255. package/build/dist/Graphics/GraphicsSystem.js.map +1 -0
  256. package/build/dist/Graphics/ImageSource.js +116 -0
  257. package/build/dist/Graphics/ImageSource.js.map +1 -0
  258. package/build/dist/Graphics/Polygon.js +59 -0
  259. package/build/dist/Graphics/Polygon.js.map +1 -0
  260. package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js +7 -0
  261. package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js.map +1 -0
  262. package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js +52 -0
  263. package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js.map +1 -0
  264. package/build/dist/Graphics/PostProcessor/PostProcessor.js +2 -0
  265. package/build/dist/Graphics/PostProcessor/PostProcessor.js.map +1 -0
  266. package/build/dist/Graphics/PostProcessor/ScreenShader.js +56 -0
  267. package/build/dist/Graphics/PostProcessor/ScreenShader.js.map +1 -0
  268. package/build/dist/Graphics/Raster.js +207 -0
  269. package/build/dist/Graphics/Raster.js.map +1 -0
  270. package/build/dist/Graphics/Rectangle.js +29 -0
  271. package/build/dist/Graphics/Rectangle.js.map +1 -0
  272. package/build/dist/Graphics/Sprite.js +103 -0
  273. package/build/dist/Graphics/Sprite.js.map +1 -0
  274. package/build/dist/Graphics/SpriteFont.js +120 -0
  275. package/build/dist/Graphics/SpriteFont.js.map +1 -0
  276. package/build/dist/Graphics/SpriteSheet.js +115 -0
  277. package/build/dist/Graphics/SpriteSheet.js.map +1 -0
  278. package/build/dist/Graphics/Text.js +94 -0
  279. package/build/dist/Graphics/Text.js.map +1 -0
  280. package/build/dist/Graphics/index.js +42 -0
  281. package/build/dist/Graphics/index.js.map +1 -0
  282. package/build/dist/Id.js +8 -0
  283. package/build/dist/Id.js.map +1 -0
  284. package/build/dist/Input/CapturePointerConfig.js +5 -0
  285. package/build/dist/Input/CapturePointerConfig.js.map +1 -0
  286. package/build/dist/Input/EngineInput.js +2 -0
  287. package/build/dist/Input/EngineInput.js.map +1 -0
  288. package/build/dist/Input/Gamepad.js +358 -0
  289. package/build/dist/Input/Gamepad.js.map +1 -0
  290. package/build/dist/Input/Index.js +22 -0
  291. package/build/dist/Input/Index.js.map +1 -0
  292. package/build/dist/Input/Keyboard.js +267 -0
  293. package/build/dist/Input/Keyboard.js.map +1 -0
  294. package/build/dist/Input/NativePointerButton.js +12 -0
  295. package/build/dist/Input/NativePointerButton.js.map +1 -0
  296. package/build/dist/Input/PointerAbstraction.js +41 -0
  297. package/build/dist/Input/PointerAbstraction.js.map +1 -0
  298. package/build/dist/Input/PointerButton.js +12 -0
  299. package/build/dist/Input/PointerButton.js.map +1 -0
  300. package/build/dist/Input/PointerComponent.js +28 -0
  301. package/build/dist/Input/PointerComponent.js.map +1 -0
  302. package/build/dist/Input/PointerEvent.js +25 -0
  303. package/build/dist/Input/PointerEvent.js.map +1 -0
  304. package/build/dist/Input/PointerEventReceiver.js +414 -0
  305. package/build/dist/Input/PointerEventReceiver.js.map +1 -0
  306. package/build/dist/Input/PointerScope.js +16 -0
  307. package/build/dist/Input/PointerScope.js.map +1 -0
  308. package/build/dist/Input/PointerSystem.js +217 -0
  309. package/build/dist/Input/PointerSystem.js.map +1 -0
  310. package/build/dist/Input/PointerType.js +11 -0
  311. package/build/dist/Input/PointerType.js.map +1 -0
  312. package/build/dist/Input/WheelDeltaMode.js +7 -0
  313. package/build/dist/Input/WheelDeltaMode.js.map +1 -0
  314. package/build/dist/Input/WheelEvent.js +21 -0
  315. package/build/dist/Input/WheelEvent.js.map +1 -0
  316. package/build/dist/Interfaces/Audio.js +2 -0
  317. package/build/dist/Interfaces/Audio.js.map +1 -0
  318. package/build/dist/Interfaces/AudioImplementation.js +11 -0
  319. package/build/dist/Interfaces/AudioImplementation.js.map +1 -0
  320. package/build/dist/Interfaces/Clonable.js +2 -0
  321. package/build/dist/Interfaces/Clonable.js.map +1 -0
  322. package/build/dist/Interfaces/Drawable.js +2 -0
  323. package/build/dist/Interfaces/Drawable.js.map +1 -0
  324. package/build/dist/Interfaces/Evented.js +2 -0
  325. package/build/dist/Interfaces/Evented.js.map +1 -0
  326. package/build/dist/Interfaces/Index.js +10 -0
  327. package/build/dist/Interfaces/Index.js.map +1 -0
  328. package/build/dist/Interfaces/LifecycleEvents.js +51 -0
  329. package/build/dist/Interfaces/LifecycleEvents.js.map +1 -0
  330. package/build/dist/Interfaces/Loadable.js +2 -0
  331. package/build/dist/Interfaces/Loadable.js.map +1 -0
  332. package/build/dist/Interfaces/PointerEventHandlers.js +2 -0
  333. package/build/dist/Interfaces/PointerEventHandlers.js.map +1 -0
  334. package/build/dist/Interfaces/Trait.js +2 -0
  335. package/build/dist/Interfaces/Trait.js.map +1 -0
  336. package/build/dist/Label.js +273 -0
  337. package/build/dist/Label.js.map +1 -0
  338. package/build/dist/Loader.js +367 -0
  339. package/build/dist/Loader.js.map +1 -0
  340. package/build/dist/Math/Index.js +10 -0
  341. package/build/dist/Math/Index.js.map +1 -0
  342. package/build/dist/Math/Random.js +239 -0
  343. package/build/dist/Math/Random.js.map +1 -0
  344. package/build/dist/Math/global-coordinates.js +30 -0
  345. package/build/dist/Math/global-coordinates.js.map +1 -0
  346. package/build/dist/Math/line.js +194 -0
  347. package/build/dist/Math/line.js.map +1 -0
  348. package/build/dist/Math/matrix.js +446 -0
  349. package/build/dist/Math/matrix.js.map +1 -0
  350. package/build/dist/Math/projection.js +24 -0
  351. package/build/dist/Math/projection.js.map +1 -0
  352. package/build/dist/Math/ray.js +52 -0
  353. package/build/dist/Math/ray.js.map +1 -0
  354. package/build/dist/Math/util.js +82 -0
  355. package/build/dist/Math/util.js.map +1 -0
  356. package/build/dist/Math/vector-view.js +25 -0
  357. package/build/dist/Math/vector-view.js.map +1 -0
  358. package/build/dist/Math/vector.js +326 -0
  359. package/build/dist/Math/vector.js.map +1 -0
  360. package/build/dist/Particles.js +449 -0
  361. package/build/dist/Particles.js.map +1 -0
  362. package/build/dist/Polyfill.js +56 -0
  363. package/build/dist/Polyfill.js.map +1 -0
  364. package/build/dist/Promises.js +205 -0
  365. package/build/dist/Promises.js.map +1 -0
  366. package/build/dist/Resources/Gif.js +479 -0
  367. package/build/dist/Resources/Gif.js.map +1 -0
  368. package/build/dist/Resources/Index.js +4 -0
  369. package/build/dist/Resources/Index.js.map +1 -0
  370. package/build/dist/Resources/Resource.js +74 -0
  371. package/build/dist/Resources/Resource.js.map +1 -0
  372. package/build/dist/Resources/Sound/AudioContext.js +16 -0
  373. package/build/dist/Resources/Sound/AudioContext.js.map +1 -0
  374. package/build/dist/Resources/Sound/Index.js +4 -0
  375. package/build/dist/Resources/Sound/Index.js.map +1 -0
  376. package/build/dist/Resources/Sound/Sound.js +240 -0
  377. package/build/dist/Resources/Sound/Sound.js.map +1 -0
  378. package/build/dist/Resources/Sound/WebAudioInstance.js +160 -0
  379. package/build/dist/Resources/Sound/WebAudioInstance.js.map +1 -0
  380. package/build/dist/Scene.js +458 -0
  381. package/build/dist/Scene.js.map +1 -0
  382. package/build/dist/Screen.js +634 -0
  383. package/build/dist/Screen.js.map +1 -0
  384. package/build/dist/ScreenElement.js +29 -0
  385. package/build/dist/ScreenElement.js.map +1 -0
  386. package/build/dist/TileMap.js +488 -0
  387. package/build/dist/TileMap.js.map +1 -0
  388. package/build/dist/Timer.js +198 -0
  389. package/build/dist/Timer.js.map +1 -0
  390. package/build/dist/Traits/Index.js +5 -0
  391. package/build/dist/Traits/Index.js.map +1 -0
  392. package/build/dist/Traits/OffscreenCulling.js +35 -0
  393. package/build/dist/Traits/OffscreenCulling.js.map +1 -0
  394. package/build/dist/Trigger.js +113 -0
  395. package/build/dist/Trigger.js.map +1 -0
  396. package/build/dist/Util/Actors.js +19 -0
  397. package/build/dist/Util/Actors.js.map +1 -0
  398. package/build/dist/Util/Browser.js +66 -0
  399. package/build/dist/Util/Browser.js.map +1 -0
  400. package/build/dist/Util/Clock.js +219 -0
  401. package/build/dist/Util/Clock.js.map +1 -0
  402. package/build/dist/Util/CullingBox.js +104 -0
  403. package/build/dist/Util/CullingBox.js.map +1 -0
  404. package/build/dist/Util/Decorators.js +78 -0
  405. package/build/dist/Util/Decorators.js.map +1 -0
  406. package/build/dist/Util/Detector.js +167 -0
  407. package/build/dist/Util/Detector.js.map +1 -0
  408. package/build/dist/Util/DrawUtil.js +117 -0
  409. package/build/dist/Util/DrawUtil.js.map +1 -0
  410. package/build/dist/Util/EasingFunctions.js +118 -0
  411. package/build/dist/Util/EasingFunctions.js.map +1 -0
  412. package/build/dist/Util/Fps.js +47 -0
  413. package/build/dist/Util/Fps.js.map +1 -0
  414. package/build/dist/Util/Index.js +7 -0
  415. package/build/dist/Util/Index.js.map +1 -0
  416. package/build/dist/Util/Log.js +195 -0
  417. package/build/dist/Util/Log.js.map +1 -0
  418. package/build/dist/Util/Observable.js +60 -0
  419. package/build/dist/Util/Observable.js.map +1 -0
  420. package/build/dist/Util/Pool.js +66 -0
  421. package/build/dist/Util/Pool.js.map +1 -0
  422. package/build/dist/Util/SortedList.js +261 -0
  423. package/build/dist/Util/SortedList.js.map +1 -0
  424. package/build/dist/Util/Sound.js +22 -0
  425. package/build/dist/Util/Sound.js.map +1 -0
  426. package/build/dist/Util/Util.js +294 -0
  427. package/build/dist/Util/Util.js.map +1 -0
  428. package/build/dist/Util/Watch.js +67 -0
  429. package/build/dist/Util/Watch.js.map +1 -0
  430. package/build/dist/Util/WebAudio.js +62 -0
  431. package/build/dist/Util/WebAudio.js.map +1 -0
  432. package/build/dist/excalibur.js +101 -22
  433. package/build/dist/excalibur.js.map +1 -1
  434. package/build/dist/excalibur.min.js +1 -1
  435. package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
  436. package/build/dist/excalibur.min.js.map +1 -1
  437. package/build/dist/index.js +74 -0
  438. package/build/dist/index.js.map +1 -0
  439. package/build/esm/Engine.d.ts +4 -1
  440. package/build/esm/Graphics/Context/texture-loader.d.ts +8 -0
  441. package/build/esm/excalibur.js +101 -22
  442. package/build/esm/excalibur.js.map +1 -1
  443. package/build/esm/excalibur.min.js +1 -1
  444. package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
  445. package/build/esm/excalibur.min.js.map +1 -1
  446. package/package.json +23 -22
@@ -0,0 +1,452 @@
1
+ import { Component, TagComponent } from './Component';
2
+ import { Observable } from '../Util/Observable';
3
+ import { Class } from '../Class';
4
+ import { InitializeEvent, PreUpdateEvent, PostUpdateEvent } from '../Events';
5
+ import { Util } from '..';
6
+ /**
7
+ * AddedComponent message
8
+ */
9
+ export class AddedComponent {
10
+ constructor(data) {
11
+ this.data = data;
12
+ this.type = 'Component Added';
13
+ }
14
+ }
15
+ /**
16
+ * Type guard to know if message is f an Added Component
17
+ */
18
+ export function isAddedComponent(x) {
19
+ return !!x && x.type === 'Component Added';
20
+ }
21
+ /**
22
+ * RemovedComponent message
23
+ */
24
+ export class RemovedComponent {
25
+ constructor(data) {
26
+ this.data = data;
27
+ this.type = 'Component Removed';
28
+ }
29
+ }
30
+ /**
31
+ * Type guard to know if message is for a Removed Component
32
+ */
33
+ export function isRemovedComponent(x) {
34
+ return !!x && x.type === 'Component Removed';
35
+ }
36
+ /**
37
+ * An Entity is the base type of anything that can have behavior in Excalibur, they are part of the built in entity component system
38
+ *
39
+ * Entities can be strongly typed with the components they contain
40
+ *
41
+ * ```typescript
42
+ * const entity = new Entity<ComponentA | ComponentB>();
43
+ * entity.components.a; // Type ComponentA
44
+ * entity.components.b; // Type ComponentB
45
+ * ```
46
+ */
47
+ export class Entity extends Class {
48
+ constructor(components, name) {
49
+ super();
50
+ /**
51
+ * The unique identifier for the entity
52
+ */
53
+ this.id = Entity._ID++;
54
+ this._name = 'anonymous';
55
+ /**
56
+ * Whether this entity is active, if set to false it will be reclaimed
57
+ */
58
+ this.active = true;
59
+ /**
60
+ * Bucket to hold on to deferred removals
61
+ */
62
+ this._componentsToRemove = [];
63
+ this._componentTypeToInstance = new Map();
64
+ this._componentStringToInstance = new Map();
65
+ this._tagsMemo = [];
66
+ this._typesMemo = [];
67
+ /**
68
+ * Observable that keeps track of component add or remove changes on the entity
69
+ */
70
+ this.componentAdded$ = new Observable();
71
+ this.componentRemoved$ = new Observable();
72
+ this._parent = null;
73
+ this.childrenAdded$ = new Observable();
74
+ this.childrenRemoved$ = new Observable();
75
+ this._children = [];
76
+ this._isInitialized = false;
77
+ this._setName(name);
78
+ if (components) {
79
+ for (const component of components) {
80
+ this.addComponent(component);
81
+ }
82
+ }
83
+ }
84
+ _setName(name) {
85
+ if (name) {
86
+ this._name = name;
87
+ }
88
+ }
89
+ get name() {
90
+ return this._name;
91
+ }
92
+ get events() {
93
+ return this.eventDispatcher;
94
+ }
95
+ /**
96
+ * Kill the entity, means it will no longer be updated. Kills are deferred to the end of the update.
97
+ */
98
+ kill() {
99
+ this.active = false;
100
+ }
101
+ isKilled() {
102
+ return !this.active;
103
+ }
104
+ /**
105
+ * Specifically get the tags on the entity from [[TagComponent]]
106
+ */
107
+ get tags() {
108
+ return this._tagsMemo;
109
+ }
110
+ /**
111
+ * Check if a tag exists on the entity
112
+ * @param tag name to check for
113
+ */
114
+ hasTag(tag) {
115
+ return this.tags.includes(tag);
116
+ }
117
+ /**
118
+ * Adds a tag to an entity
119
+ * @param tag
120
+ * @returns Entity
121
+ */
122
+ addTag(tag) {
123
+ return this.addComponent(new TagComponent(tag));
124
+ }
125
+ /**
126
+ * Removes a tag on the entity
127
+ *
128
+ * Removals are deferred until the end of update
129
+ * @param tag
130
+ * @param force Remove component immediately, no deferred
131
+ */
132
+ removeTag(tag, force = false) {
133
+ return this.removeComponent(tag, force);
134
+ }
135
+ /**
136
+ * The types of the components on the Entity
137
+ */
138
+ get types() {
139
+ return this._typesMemo;
140
+ }
141
+ _rebuildMemos() {
142
+ this._tagsMemo = Array.from(this._componentStringToInstance.values())
143
+ .filter((c) => c instanceof TagComponent)
144
+ .map((c) => c.type);
145
+ this._typesMemo = Array.from(this._componentStringToInstance.keys());
146
+ }
147
+ getComponents() {
148
+ return Array.from(this._componentStringToInstance.values());
149
+ }
150
+ _notifyAddComponent(component) {
151
+ this._rebuildMemos();
152
+ const added = new AddedComponent({
153
+ component,
154
+ entity: this
155
+ });
156
+ this.componentAdded$.notifyAll(added);
157
+ }
158
+ _notifyRemoveComponent(component) {
159
+ const removed = new RemovedComponent({
160
+ component,
161
+ entity: this
162
+ });
163
+ this.componentRemoved$.notifyAll(removed);
164
+ this._rebuildMemos();
165
+ }
166
+ get parent() {
167
+ return this._parent;
168
+ }
169
+ /**
170
+ * Get the direct children of this entity
171
+ */
172
+ get children() {
173
+ return this._children;
174
+ }
175
+ /**
176
+ * Unparents this entity, if there is a parent. Otherwise it does nothing.
177
+ */
178
+ unparent() {
179
+ if (this._parent) {
180
+ this._parent.removeChild(this);
181
+ this._parent = null;
182
+ }
183
+ }
184
+ /**
185
+ * Adds an entity to be a child of this entity
186
+ * @param entity
187
+ */
188
+ addChild(entity) {
189
+ if (entity.parent === null) {
190
+ if (this.getAncestors().includes(entity)) {
191
+ throw new Error('Cycle detected, cannot add entity');
192
+ }
193
+ this._children.push(entity);
194
+ entity._parent = this;
195
+ this.childrenAdded$.notifyAll(entity);
196
+ }
197
+ else {
198
+ throw new Error('Entity already has a parent, cannot add without unparenting');
199
+ }
200
+ return this;
201
+ }
202
+ /**
203
+ * Remove an entity from children if it exists
204
+ * @param entity
205
+ */
206
+ removeChild(entity) {
207
+ if (entity.parent === this) {
208
+ Util.removeItemFromArray(entity, this._children);
209
+ entity._parent = null;
210
+ this.childrenRemoved$.notifyAll(entity);
211
+ }
212
+ return this;
213
+ }
214
+ /**
215
+ * Removes all children from this entity
216
+ */
217
+ removeAllChildren() {
218
+ this.children.forEach((c) => {
219
+ this.removeChild(c);
220
+ });
221
+ return this;
222
+ }
223
+ /**
224
+ * Returns a list of parent entities starting with the topmost parent. Includes the current entity.
225
+ */
226
+ getAncestors() {
227
+ const result = [this];
228
+ let current = this.parent;
229
+ while (current) {
230
+ result.push(current);
231
+ current = current.parent;
232
+ }
233
+ return result.reverse();
234
+ }
235
+ /**
236
+ * Returns a list of all the entities that descend from this entity. Includes the current entity.
237
+ */
238
+ getDescendants() {
239
+ let result = [this];
240
+ let queue = [this];
241
+ while (queue.length > 0) {
242
+ const curr = queue.pop();
243
+ queue = queue.concat(curr.children);
244
+ result = result.concat(curr.children);
245
+ }
246
+ return result;
247
+ }
248
+ /**
249
+ * Creates a deep copy of the entity and a copy of all its components
250
+ */
251
+ clone() {
252
+ const newEntity = new Entity();
253
+ for (const c of this.types) {
254
+ newEntity.addComponent(this.get(c).clone());
255
+ }
256
+ for (const child of this.children) {
257
+ newEntity.addChild(child.clone());
258
+ }
259
+ return newEntity;
260
+ }
261
+ /**
262
+ * Adds a copy of all the components from another template entity as a "prefab"
263
+ * @param templateEntity Entity to use as a template
264
+ * @param force Force component replacement if it already exists on the target entity
265
+ */
266
+ addTemplate(templateEntity, force = false) {
267
+ for (const c of templateEntity.getComponents()) {
268
+ this.addComponent(c.clone(), force);
269
+ }
270
+ for (const child of templateEntity.children) {
271
+ this.addChild(child.clone().addTemplate(child));
272
+ }
273
+ return this;
274
+ }
275
+ /**
276
+ * Adds a component to the entity
277
+ * @param component Component or Entity to add copy of components from
278
+ * @param force Optionally overwrite any existing components of the same type
279
+ */
280
+ addComponent(component, force = false) {
281
+ // if component already exists, skip if not forced
282
+ if (this.has(component.type)) {
283
+ if (force) {
284
+ // Remove existing component type if exists when forced
285
+ this.removeComponent(component);
286
+ }
287
+ else {
288
+ // early exit component exits
289
+ return this;
290
+ }
291
+ }
292
+ // TODO circular dependencies will be a problem
293
+ if (component.dependencies && component.dependencies.length) {
294
+ for (const ctor of component.dependencies) {
295
+ this.addComponent(new ctor());
296
+ }
297
+ }
298
+ component.owner = this;
299
+ const constuctorType = component.constructor;
300
+ this._componentTypeToInstance.set(constuctorType, component);
301
+ this._componentStringToInstance.set(component.type, component);
302
+ if (component.onAdd) {
303
+ component.onAdd(this);
304
+ }
305
+ this._notifyAddComponent(component);
306
+ return this;
307
+ }
308
+ /**
309
+ * Removes a component from the entity, by default removals are deferred to the end of entity update to avoid consistency issues
310
+ *
311
+ * Components can be force removed with the `force` flag, the removal is not deferred and happens immediately
312
+ * @param componentOrType
313
+ * @param force
314
+ */
315
+ removeComponent(componentOrType, force = false) {
316
+ if (force) {
317
+ if (typeof componentOrType === 'string') {
318
+ this._removeComponentByType(componentOrType);
319
+ }
320
+ else if (componentOrType instanceof Component) {
321
+ this._removeComponentByType(componentOrType.type);
322
+ }
323
+ }
324
+ else {
325
+ this._componentsToRemove.push(componentOrType);
326
+ }
327
+ return this;
328
+ }
329
+ _removeComponentByType(type) {
330
+ if (this.has(type)) {
331
+ const component = this.get(type);
332
+ component.owner = null;
333
+ if (component.onRemove) {
334
+ component.onRemove(this);
335
+ }
336
+ const ctor = component.constructor;
337
+ this._componentTypeToInstance.delete(ctor);
338
+ this._componentStringToInstance.delete(component.type);
339
+ this._notifyRemoveComponent(component);
340
+ }
341
+ }
342
+ /**
343
+ * @hidden
344
+ * @internal
345
+ */
346
+ processComponentRemoval() {
347
+ for (const componentOrType of this._componentsToRemove) {
348
+ const type = typeof componentOrType === 'string' ? componentOrType : componentOrType.type;
349
+ this._removeComponentByType(type);
350
+ }
351
+ this._componentsToRemove.length = 0;
352
+ }
353
+ has(type) {
354
+ if (typeof type === 'string') {
355
+ return this._componentStringToInstance.has(type);
356
+ }
357
+ else {
358
+ return this._componentTypeToInstance.has(type);
359
+ }
360
+ }
361
+ get(type) {
362
+ if (typeof type === 'string') {
363
+ return this._componentStringToInstance.get(type);
364
+ }
365
+ else {
366
+ return this._componentTypeToInstance.get(type);
367
+ }
368
+ }
369
+ /**
370
+ * Gets whether the actor is Initialized
371
+ */
372
+ get isInitialized() {
373
+ return this._isInitialized;
374
+ }
375
+ /**
376
+ * Initializes this entity, meant to be called by the Scene before first update not by users of Excalibur.
377
+ *
378
+ * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
379
+ *
380
+ * @internal
381
+ */
382
+ _initialize(engine) {
383
+ if (!this.isInitialized) {
384
+ this.onInitialize(engine);
385
+ super.emit('initialize', new InitializeEvent(engine, this));
386
+ this._isInitialized = true;
387
+ }
388
+ }
389
+ /**
390
+ * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
391
+ *
392
+ * Internal _preupdate handler for [[onPreUpdate]] lifecycle event
393
+ * @internal
394
+ */
395
+ _preupdate(engine, delta) {
396
+ this.emit('preupdate', new PreUpdateEvent(engine, delta, this));
397
+ this.onPreUpdate(engine, delta);
398
+ }
399
+ /**
400
+ * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
401
+ *
402
+ * Internal _preupdate handler for [[onPostUpdate]] lifecycle event
403
+ * @internal
404
+ */
405
+ _postupdate(engine, delta) {
406
+ this.emit('postupdate', new PostUpdateEvent(engine, delta, this));
407
+ this.onPostUpdate(engine, delta);
408
+ }
409
+ /**
410
+ * `onInitialize` is called before the first update of the entity. This method is meant to be
411
+ * overridden.
412
+ *
413
+ * Synonymous with the event handler `.on('initialize', (evt) => {...})`
414
+ */
415
+ onInitialize(_engine) {
416
+ // Override me
417
+ }
418
+ /**
419
+ * Safe to override onPreUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})`
420
+ *
421
+ * `onPreUpdate` is called directly before an entity is updated.
422
+ */
423
+ onPreUpdate(_engine, _delta) {
424
+ // Override me
425
+ }
426
+ /**
427
+ * Safe to override onPostUpdate lifecycle event handler. Synonymous with `.on('postupdate', (evt) =>{...})`
428
+ *
429
+ * `onPostUpdate` is called directly after an entity is updated.
430
+ */
431
+ onPostUpdate(_engine, _delta) {
432
+ // Override me
433
+ }
434
+ /**
435
+ *
436
+ * Entity update lifecycle, called internally
437
+ *
438
+ * @internal
439
+ * @param engine
440
+ * @param delta
441
+ */
442
+ update(engine, delta) {
443
+ this._initialize(engine);
444
+ this._preupdate(engine, delta);
445
+ for (const child of this.children) {
446
+ child.update(engine, delta);
447
+ }
448
+ this._postupdate(engine, delta);
449
+ }
450
+ }
451
+ Entity._ID = 0;
452
+ //# sourceMappingURL=Entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.js","sourceRoot":"","sources":["../../../src/engine/EntityComponentSystem/Entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,YAAY,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,UAAU,EAAW,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;A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;QAChD,cAAc;IAChB,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,OAAe,EAAE,MAAc;QACjD,cAAc;IAChB,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAc,EAAE,KAAa;QACzC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SAC7B;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;;AAzcc,UAAG,GAAG,CAAC,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { Entity, isAddedComponent, isRemovedComponent } from './Entity';
2
+ import { Util } from '..';
3
+ // Add/Remove entities and components
4
+ export class EntityManager {
5
+ constructor(_world) {
6
+ this._world = _world;
7
+ this.entities = [];
8
+ this._entityIndex = {};
9
+ this._entitiesToRemove = [];
10
+ }
11
+ /**
12
+ * Runs the entity lifecycle
13
+ * @param _context
14
+ */
15
+ updateEntities(_context, elapsed) {
16
+ for (const entity of this.entities) {
17
+ // TODO is this right?
18
+ entity.update(_context.engine, elapsed);
19
+ if (!entity.active) {
20
+ this.removeEntity(entity);
21
+ }
22
+ }
23
+ }
24
+ findEntitiesForRemoval() {
25
+ for (const entity of this.entities) {
26
+ if (!entity.active) {
27
+ this.removeEntity(entity);
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * EntityManager observes changes on entities
33
+ * @param message
34
+ */
35
+ notify(message) {
36
+ if (isAddedComponent(message)) {
37
+ // we don't need the component, it's already on the entity
38
+ this._world.queryManager.addEntity(message.data.entity);
39
+ }
40
+ if (isRemovedComponent(message)) {
41
+ this._world.queryManager.removeComponent(message.data.entity, message.data.component);
42
+ }
43
+ }
44
+ /**
45
+ * Adds an entity to be tracked by the EntityManager
46
+ * @param entity
47
+ */
48
+ addEntity(entity) {
49
+ entity.active = true;
50
+ if (entity && !this._entityIndex[entity.id]) {
51
+ this._entityIndex[entity.id] = entity;
52
+ this.entities.push(entity);
53
+ this._world.queryManager.addEntity(entity);
54
+ entity.componentAdded$.register(this);
55
+ entity.componentRemoved$.register(this);
56
+ // if entity has children
57
+ entity.children.forEach((c) => this.addEntity(c));
58
+ entity.childrenAdded$.register({
59
+ notify: (e) => {
60
+ this.addEntity(e);
61
+ }
62
+ });
63
+ entity.childrenRemoved$.register({
64
+ notify: (e) => {
65
+ this.removeEntity(e, false);
66
+ }
67
+ });
68
+ }
69
+ }
70
+ removeEntity(idOrEntity, deferred = true) {
71
+ var _a;
72
+ let id = 0;
73
+ if (idOrEntity instanceof Entity) {
74
+ id = idOrEntity.id;
75
+ }
76
+ else {
77
+ id = idOrEntity;
78
+ }
79
+ const entity = this._entityIndex[id];
80
+ if (entity && entity.active) {
81
+ entity.kill();
82
+ }
83
+ if (entity && deferred) {
84
+ this._entitiesToRemove.push(entity);
85
+ return;
86
+ }
87
+ delete this._entityIndex[id];
88
+ if (entity) {
89
+ Util.removeItemFromArray(entity, this.entities);
90
+ this._world.queryManager.removeEntity(entity);
91
+ entity.componentAdded$.unregister(this);
92
+ entity.componentRemoved$.unregister(this);
93
+ // if entity has children
94
+ entity.children.forEach((c) => this.removeEntity(c, deferred));
95
+ entity.childrenAdded$.clear();
96
+ entity.childrenRemoved$.clear();
97
+ // stats
98
+ if ((_a = this._world.context) === null || _a === void 0 ? void 0 : _a.engine) {
99
+ this._world.context.engine.stats.currFrame.actors.killed++;
100
+ }
101
+ }
102
+ }
103
+ processEntityRemovals() {
104
+ for (const entity of this._entitiesToRemove) {
105
+ if (entity.active) {
106
+ continue;
107
+ }
108
+ this.removeEntity(entity, false);
109
+ }
110
+ }
111
+ processComponentRemovals() {
112
+ for (const entity of this.entities) {
113
+ entity.processComponentRemoval();
114
+ }
115
+ }
116
+ getById(id) {
117
+ return this._entityIndex[id];
118
+ }
119
+ getByName(name) {
120
+ return this.entities.filter(e => e.name === name);
121
+ }
122
+ clear() {
123
+ for (const entity of this.entities) {
124
+ this.removeEntity(entity);
125
+ }
126
+ }
127
+ }
128
+ //# sourceMappingURL=EntityManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityManager.js","sourceRoot":"","sources":["../../../src/engine/EntityComponentSystem/EntityManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoC,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG1G,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,qCAAqC;AAErC,MAAM,OAAO,aAAa;IAIxB,YAAoB,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;QAHvC,aAAQ,GAAa,EAAE,CAAC;QACxB,iBAAY,GAAmC,EAAE,CAAC;QA2GjD,sBAAiB,GAAa,EAAE,CAAC;IAzGQ,CAAC;IAElD;;;OAGG;IACI,cAAc,CAAC,QAAqB,EAAE,OAAe;QAC1D,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,sBAAsB;YACtB,MAAM,CAAC,MAAM,CAAE,QAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACjD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;gBAClB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;aAC3B;SACF;IACH,CAAC;IAEM,sBAAsB;QAC3B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;gBAClB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;aAC3B;SACF;IACH,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,OAA0C;QACtD,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;YAC7B,0DAA0D;YAC1D,IAAI,CAAC,M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M,CAAC,OAAe,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;aACrE;SACF;IACH,CAAC;IAGM,qBAAqB;QAC1B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC3C,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjB,SAAS;aACV;YACD,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SAClC;IACH,CAAC;IAEM,wBAAwB;QAC7B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,MAAM,CAAC,uBAAuB,EAAE,CAAC;SAClC;IACH,CAAC;IAEM,OAAO,CAAC,EAAU;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAEM,SAAS,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACpD,CAAC;IAEM,KAAK;QACV,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;SAC3B;IACH,CAAC;CACF"}
@@ -0,0 +1,91 @@
1
+ import { Entity } from './Entity';
2
+ import { buildTypeKey } from './Util';
3
+ import { Observable } from '../Util/Observable';
4
+ import { Util } from '..';
5
+ import { AddedEntity, RemovedEntity } from './System';
6
+ /**
7
+ * Represents query for entities that match a list of types that is cached and observable
8
+ *
9
+ * Queries can be strongly typed by supplying a type union in the optional type parameter
10
+ * ```typescript
11
+ * const queryAB = new ex.Query<ComponentTypeA | ComponentTypeB>(['A', 'B']);
12
+ * ```
13
+ */
14
+ export class Query extends Observable {
15
+ constructor(types) {
16
+ super();
17
+ this._entities = [];
18
+ if (types[0] instanceof Function) {
19
+ this.types = types.map(T => (new T).type);
20
+ }
21
+ else {
22
+ this.types = types;
23
+ }
24
+ }
25
+ get key() {
26
+ if (this._key) {
27
+ return this._key;
28
+ }
29
+ return (this._key = buildTypeKey(this.types));
30
+ }
31
+ /**
32
+ * Returns a list of entities that match the query
33
+ *
34
+ * @param sort Optional sorting function to sort entities returned from the query
35
+ */
36
+ getEntities(sort) {
37
+ if (sort) {
38
+ this._entities.sort(sort);
39
+ }
40
+ return this._entities;
41
+ }
42
+ /**
43
+ * Add an entity to the query, will only be added if the entity matches the query types
44
+ * @param entity
45
+ */
46
+ addEntity(entity) {
47
+ if (!Util.contains(this._entities, entity) && this.matches(entity)) {
48
+ this._entities.push(entity);
49
+ this.notifyAll(new AddedEntity(entity));
50
+ }
51
+ }
52
+ /**
53
+ * If the entity is part of the query it will be removed regardless of types
54
+ * @param entity
55
+ */
56
+ removeEntity(entity) {
57
+ if (Util.removeItemFromArray(entity, this._entities)) {
58
+ this.notifyAll(new RemovedEntity(entity));
59
+ }
60
+ }
61
+ /**
62
+ * Removes all entities and observers from the query
63
+ */
64
+ clear() {
65
+ this._entities.length = 0;
66
+ for (const observer of this.observers) {
67
+ this.unregister(observer);
68
+ }
69
+ }
70
+ matches(typesOrEntity) {
71
+ let types = [];
72
+ if (typesOrEntity instanceof Entity) {
73
+ types = typesOrEntity.types;
74
+ }
75
+ else {
76
+ types = typesOrEntity;
77
+ }
78
+ let matches = true;
79
+ for (const type of this.types) {
80
+ matches = matches && types.indexOf(type) > -1;
81
+ if (!matches) {
82
+ return false;
83
+ }
84
+ }
85
+ return matches;
86
+ }
87
+ contain(type) {
88
+ return this.types.indexOf(type) > -1;
89
+ }
90
+ }
91
+ //# sourceMappingURL=Query.js.map