opal-js_wrap-three 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (503) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.lock +4 -4
  4. data/lib/opal/js_wrap/three/version.rb +1 -1
  5. data/lib-opal/js_wrap/three/WebGL.js +102 -0
  6. data/lib-opal/js_wrap/three/animation/AnimationClipCreator.js +116 -0
  7. data/lib-opal/js_wrap/three/animation/CCDIKSolver.js +436 -0
  8. data/lib-opal/js_wrap/three/animation/MMDAnimationHelper.js +941 -0
  9. data/lib-opal/js_wrap/three/animation/MMDPhysics.js +1183 -0
  10. data/lib-opal/js_wrap/three/cameras/CinematicCamera.js +204 -0
  11. data/lib-opal/js_wrap/three/controls/ArcballControls.js +2649 -0
  12. data/lib-opal/js_wrap/three/controls/DragControls.js +234 -0
  13. data/lib-opal/js_wrap/three/controls/FirstPersonControls.js +301 -0
  14. data/lib-opal/js_wrap/three/controls/FlyControls.js +357 -0
  15. data/lib-opal/js_wrap/three/controls/OrbitControls.js +908 -0
  16. data/lib-opal/js_wrap/three/controls/PointerLockControls.js +173 -0
  17. data/lib-opal/js_wrap/three/controls/TrackballControls.js +666 -0
  18. data/lib-opal/js_wrap/three/controls/TransformControls.js +1210 -0
  19. data/lib-opal/js_wrap/three/controls/experimental/CameraControls.js +860 -0
  20. data/lib-opal/js_wrap/three/csm/CSM.js +346 -0
  21. data/lib-opal/js_wrap/three/csm/CSMFrustum.js +123 -0
  22. data/lib-opal/js_wrap/three/csm/CSMHelper.js +197 -0
  23. data/lib-opal/js_wrap/three/csm/CSMShader.js +29 -0
  24. data/lib-opal/js_wrap/three/curves/CurveExtras.js +544 -0
  25. data/lib-opal/js_wrap/three/curves/NURBSCurve.js +122 -0
  26. data/lib-opal/js_wrap/three/curves/NURBSSurface.js +78 -0
  27. data/lib-opal/js_wrap/three/curves/NURBSUtils.js +413 -0
  28. data/lib-opal/js_wrap/three/deprecated/Geometry.js +1373 -0
  29. data/lib-opal/js_wrap/three/effects/AnaglyphEffect.js +113 -0
  30. data/lib-opal/js_wrap/three/effects/AsciiEffect.js +267 -0
  31. data/lib-opal/js_wrap/three/effects/OutlineEffect.js +400 -0
  32. data/lib-opal/js_wrap/three/effects/ParallaxBarrierEffect.js +90 -0
  33. data/lib-opal/js_wrap/three/effects/PeppersGhostEffect.js +160 -0
  34. data/lib-opal/js_wrap/three/effects/StereoEffect.js +63 -0
  35. data/lib-opal/js_wrap/three/environments/DebugEnvironment.js +107 -0
  36. data/lib-opal/js_wrap/three/environments/RoomEnvironment.js +166 -0
  37. data/lib-opal/js_wrap/three/exporters/ColladaExporter.js +442 -0
  38. data/lib-opal/js_wrap/three/exporters/DRACOExporter.js +205 -0
  39. data/lib-opal/js_wrap/three/exporters/GLTFExporter.js +2042 -0
  40. data/lib-opal/js_wrap/three/exporters/MMDExporter.js +189 -0
  41. data/lib-opal/js_wrap/three/exporters/OBJExporter.js +241 -0
  42. data/lib-opal/js_wrap/three/exporters/PLYExporter.js +370 -0
  43. data/lib-opal/js_wrap/three/exporters/STLExporter.js +186 -0
  44. data/lib-opal/js_wrap/three/exporters/USDZExporter.js +402 -0
  45. data/lib-opal/js_wrap/three/geometries/BoxLineGeometry.js +106 -0
  46. data/lib-opal/js_wrap/three/geometries/ConvexGeometry.js +88 -0
  47. data/lib-opal/js_wrap/three/geometries/DecalGeometry.js +302 -0
  48. data/lib-opal/js_wrap/three/geometries/LightningStrike.js +817 -0
  49. data/lib-opal/js_wrap/three/geometries/ParametricGeometries.js +280 -0
  50. data/lib-opal/js_wrap/three/geometries/ParametricGeometry.js +146 -0
  51. data/lib-opal/js_wrap/three/geometries/RoundedBoxGeometry.js +183 -0
  52. data/lib-opal/js_wrap/three/geometries/TeapotGeometry.js +352 -0
  53. data/lib-opal/js_wrap/three/geometries/TextGeometry.js +76 -0
  54. data/lib-opal/js_wrap/three/helpers/LightProbeHelper.js +95 -0
  55. data/lib-opal/js_wrap/three/helpers/PositionalAudioHelper.js +138 -0
  56. data/lib-opal/js_wrap/three/helpers/RectAreaLightHelper.js +115 -0
  57. data/lib-opal/js_wrap/three/helpers/VertexNormalsHelper.js +131 -0
  58. data/lib-opal/js_wrap/three/helpers/VertexTangentsHelper.js +118 -0
  59. data/lib-opal/js_wrap/three/interactive/HTMLMesh.js +307 -0
  60. data/lib-opal/js_wrap/three/interactive/InteractiveGroup.js +138 -0
  61. data/lib-opal/js_wrap/three/interactive/SelectionBox.js +264 -0
  62. data/lib-opal/js_wrap/three/interactive/SelectionHelper.js +88 -0
  63. data/lib-opal/js_wrap/three/libs/OimoPhysics/OimoPhysics.js +46059 -0
  64. data/lib-opal/js_wrap/three/libs/OimoPhysics/index.js +92 -0
  65. data/lib-opal/js_wrap/three/libs/chevrotain.module.min.js +6947 -0
  66. data/lib-opal/js_wrap/three/libs/ecsy.module.js +1999 -0
  67. data/lib-opal/js_wrap/three/libs/fflate.module.js +3002 -0
  68. data/lib-opal/js_wrap/three/libs/flow.module.js +3033 -0
  69. data/lib-opal/js_wrap/three/libs/ktx-parse.module.js +392 -0
  70. data/lib-opal/js_wrap/three/libs/lil-gui.module.min.js +821 -0
  71. data/lib-opal/js_wrap/three/libs/meshopt_decoder.module.js +136 -0
  72. data/lib-opal/js_wrap/three/libs/mmdparser.module.js +11022 -0
  73. data/lib-opal/js_wrap/three/libs/motion-controllers.module.js +589 -0
  74. data/lib-opal/js_wrap/three/libs/opentype.module.min.js +6132 -0
  75. data/lib-opal/js_wrap/three/libs/potpack.module.js +171 -0
  76. data/lib-opal/js_wrap/three/libs/rhino3dm/rhino3dm.js +6781 -0
  77. data/lib-opal/js_wrap/three/libs/rhino3dm/rhino3dm.module.js +6783 -0
  78. data/lib-opal/js_wrap/three/libs/stats.module.js +139 -0
  79. data/lib-opal/js_wrap/three/libs/tween.module.min.js +349 -0
  80. data/lib-opal/js_wrap/three/lights/LightProbeGenerator.js +233 -0
  81. data/lib-opal/js_wrap/three/lights/RectAreaLightUniformsLib.js +75 -0
  82. data/lib-opal/js_wrap/three/lines/Line2.js +66 -0
  83. data/lib-opal/js_wrap/three/lines/LineGeometry.js +122 -0
  84. data/lib-opal/js_wrap/three/lines/LineMaterial.js +227 -0
  85. data/lib-opal/js_wrap/three/lines/LineSegments2.js +312 -0
  86. data/lib-opal/js_wrap/three/lines/LineSegmentsGeometry.js +238 -0
  87. data/lib-opal/js_wrap/three/lines/Wireframe.js +98 -0
  88. data/lib-opal/js_wrap/three/lines/WireframeGeometry2.js +65 -0
  89. data/lib-opal/js_wrap/three/loaders/3DMLoader.js +1230 -0
  90. data/lib-opal/js_wrap/three/loaders/3MFLoader.js +1123 -0
  91. data/lib-opal/js_wrap/three/loaders/AMFLoader.js +445 -0
  92. data/lib-opal/js_wrap/three/loaders/BVHLoader.js +365 -0
  93. data/lib-opal/js_wrap/three/loaders/BasisTextureLoader.js +692 -0
  94. data/lib-opal/js_wrap/three/loaders/ColladaLoader.js +3046 -0
  95. data/lib-opal/js_wrap/three/loaders/DDSLoader.js +264 -0
  96. data/lib-opal/js_wrap/three/loaders/DRACOLoader.js +531 -0
  97. data/lib-opal/js_wrap/three/loaders/EXRLoader.js +1834 -0
  98. data/lib-opal/js_wrap/three/loaders/FBXLoader.js +3125 -0
  99. data/lib-opal/js_wrap/three/loaders/FontLoader.js +201 -0
  100. data/lib-opal/js_wrap/three/loaders/GCodeLoader.js +248 -0
  101. data/lib-opal/js_wrap/three/loaders/GLTFLoader.js +3334 -0
  102. data/lib-opal/js_wrap/three/loaders/HDRCubeTextureLoader.js +144 -0
  103. data/lib-opal/js_wrap/three/loaders/IFCLoader.js +2395 -0
  104. data/lib-opal/js_wrap/three/loaders/KMZLoader.js +142 -0
  105. data/lib-opal/js_wrap/three/loaders/KTX2Loader.js +535 -0
  106. data/lib-opal/js_wrap/three/loaders/KTXLoader.js +202 -0
  107. data/lib-opal/js_wrap/three/loaders/LDrawLoader.js +1737 -0
  108. data/lib-opal/js_wrap/three/loaders/LUT3dlLoader.js +163 -0
  109. data/lib-opal/js_wrap/three/loaders/LUTCubeLoader.js +171 -0
  110. data/lib-opal/js_wrap/three/loaders/LWOLoader.js +831 -0
  111. data/lib-opal/js_wrap/three/loaders/LogLuvLoader.js +713 -0
  112. data/lib-opal/js_wrap/three/loaders/LottieLoader.js +103 -0
  113. data/lib-opal/js_wrap/three/loaders/MD2Loader.js +258 -0
  114. data/lib-opal/js_wrap/three/loaders/MDDLoader.js +116 -0
  115. data/lib-opal/js_wrap/three/loaders/MMDLoader.js +1687 -0
  116. data/lib-opal/js_wrap/three/loaders/MTLLoader.js +465 -0
  117. data/lib-opal/js_wrap/three/loaders/NRRDLoader.js +554 -0
  118. data/lib-opal/js_wrap/three/loaders/NodeMaterialLoader.js +248 -0
  119. data/lib-opal/js_wrap/three/loaders/OBJLoader.js +673 -0
  120. data/lib-opal/js_wrap/three/loaders/PCDLoader.js +322 -0
  121. data/lib-opal/js_wrap/three/loaders/PDBLoader.js +318 -0
  122. data/lib-opal/js_wrap/three/loaders/PLYLoader.js +489 -0
  123. data/lib-opal/js_wrap/three/loaders/PRWMLoader.js +247 -0
  124. data/lib-opal/js_wrap/three/loaders/PVRLoader.js +240 -0
  125. data/lib-opal/js_wrap/three/loaders/RGBELoader.js +462 -0
  126. data/lib-opal/js_wrap/three/loaders/RGBMLoader.js +1169 -0
  127. data/lib-opal/js_wrap/three/loaders/STLLoader.js +345 -0
  128. data/lib-opal/js_wrap/three/loaders/SVGLoader.js +2162 -0
  129. data/lib-opal/js_wrap/three/loaders/TDSLoader.js +982 -0
  130. data/lib-opal/js_wrap/three/loaders/TGALoader.js +444 -0
  131. data/lib-opal/js_wrap/three/loaders/TTFLoader.js +210 -0
  132. data/lib-opal/js_wrap/three/loaders/TiltLoader.js +391 -0
  133. data/lib-opal/js_wrap/three/loaders/VOXLoader.js +272 -0
  134. data/lib-opal/js_wrap/three/loaders/VRMLLoader.js +2685 -0
  135. data/lib-opal/js_wrap/three/loaders/VRMLoader.js +103 -0
  136. data/lib-opal/js_wrap/three/loaders/VTKLoader.js +894 -0
  137. data/lib-opal/js_wrap/three/loaders/XYZLoader.js +136 -0
  138. data/lib-opal/js_wrap/three/loaders/ifc/web-ifc-api.js +60504 -0
  139. data/lib-opal/js_wrap/three/loaders/lwo/IFFParser.js +931 -0
  140. data/lib-opal/js_wrap/three/loaders/lwo/LWO2Parser.js +450 -0
  141. data/lib-opal/js_wrap/three/loaders/lwo/LWO3Parser.js +406 -0
  142. data/lib-opal/js_wrap/three/math/Capsule.js +133 -0
  143. data/lib-opal/js_wrap/three/math/ColorConverter.js +104 -0
  144. data/lib-opal/js_wrap/three/math/ConvexHull.js +924 -0
  145. data/lib-opal/js_wrap/three/math/ImprovedNoise.js +86 -0
  146. data/lib-opal/js_wrap/three/math/Lut.js +170 -0
  147. data/lib-opal/js_wrap/three/math/MeshSurfaceSampler.js +187 -0
  148. data/lib-opal/js_wrap/three/math/OBB.js +345 -0
  149. data/lib-opal/js_wrap/three/math/Octree.js +409 -0
  150. data/lib-opal/js_wrap/three/math/SimplexNoise.js +425 -0
  151. data/lib-opal/js_wrap/three/misc/ConvexObjectBreaker.js +447 -0
  152. data/lib-opal/js_wrap/three/misc/GPUComputationRenderer.js +322 -0
  153. data/lib-opal/js_wrap/three/misc/Gyroscope.js +94 -0
  154. data/lib-opal/js_wrap/three/misc/MD2Character.js +225 -0
  155. data/lib-opal/js_wrap/three/misc/MD2CharacterComplex.js +424 -0
  156. data/lib-opal/js_wrap/three/misc/MorphAnimMesh.js +109 -0
  157. data/lib-opal/js_wrap/three/misc/MorphBlendMesh.js +283 -0
  158. data/lib-opal/js_wrap/three/misc/ProgressiveLightMap.js +324 -0
  159. data/lib-opal/js_wrap/three/misc/RollerCoaster.js +489 -0
  160. data/lib-opal/js_wrap/three/misc/TubePainter.js +158 -0
  161. data/lib-opal/js_wrap/three/misc/Volume.js +427 -0
  162. data/lib-opal/js_wrap/three/misc/VolumeSlice.js +210 -0
  163. data/lib-opal/js_wrap/three/modifiers/CurveModifier.js +291 -0
  164. data/lib-opal/js_wrap/three/modifiers/EdgeSplitModifier.js +308 -0
  165. data/lib-opal/js_wrap/three/modifiers/SimplifyModifier.js +435 -0
  166. data/lib-opal/js_wrap/three/modifiers/TessellateModifier.js +264 -0
  167. data/lib-opal/js_wrap/three/node-editor/NodeEditor.js +402 -0
  168. data/lib-opal/js_wrap/three/node-editor/accessors/NormalEditor.js +80 -0
  169. data/lib-opal/js_wrap/three/node-editor/accessors/PositionEditor.js +80 -0
  170. data/lib-opal/js_wrap/three/node-editor/accessors/UVEditor.js +71 -0
  171. data/lib-opal/js_wrap/three/node-editor/display/BlendEditor.js +78 -0
  172. data/lib-opal/js_wrap/three/node-editor/inputs/ColorEditor.js +111 -0
  173. data/lib-opal/js_wrap/three/node-editor/inputs/FloatEditor.js +69 -0
  174. data/lib-opal/js_wrap/three/node-editor/inputs/SliderEditor.js +97 -0
  175. data/lib-opal/js_wrap/three/node-editor/inputs/Vector2Editor.js +73 -0
  176. data/lib-opal/js_wrap/three/node-editor/inputs/Vector3Editor.js +75 -0
  177. data/lib-opal/js_wrap/three/node-editor/inputs/Vector4Editor.js +77 -0
  178. data/lib-opal/js_wrap/three/node-editor/materials/StandardMaterialEditor.js +121 -0
  179. data/lib-opal/js_wrap/three/node-editor/math/DotEditor.js +76 -0
  180. data/lib-opal/js_wrap/three/node-editor/math/InvertEditor.js +80 -0
  181. data/lib-opal/js_wrap/three/node-editor/math/LimiterEditor.js +85 -0
  182. data/lib-opal/js_wrap/three/node-editor/math/NormalizeEditor.js +69 -0
  183. data/lib-opal/js_wrap/three/node-editor/math/OperatorEditor.js +91 -0
  184. data/lib-opal/js_wrap/three/node-editor/math/PowerEditor.js +73 -0
  185. data/lib-opal/js_wrap/three/node-editor/math/TrigonometryEditor.js +83 -0
  186. data/lib-opal/js_wrap/three/node-editor/procedural/CheckerEditor.js +69 -0
  187. data/lib-opal/js_wrap/three/node-editor/utils/OscillatorEditor.js +87 -0
  188. data/lib-opal/js_wrap/three/node-editor/utils/TimerEditor.js +89 -0
  189. data/lib-opal/js_wrap/three/nodes/Nodes.js +481 -0
  190. data/lib-opal/js_wrap/three/nodes/accessors/CameraNode.js +222 -0
  191. data/lib-opal/js_wrap/three/nodes/accessors/ColorsNode.js +99 -0
  192. data/lib-opal/js_wrap/three/nodes/accessors/LightNode.js +100 -0
  193. data/lib-opal/js_wrap/three/nodes/accessors/NormalNode.js +152 -0
  194. data/lib-opal/js_wrap/three/nodes/accessors/PositionNode.js +163 -0
  195. data/lib-opal/js_wrap/three/nodes/accessors/ReflectNode.js +161 -0
  196. data/lib-opal/js_wrap/three/nodes/accessors/ResolutionNode.js +99 -0
  197. data/lib-opal/js_wrap/three/nodes/accessors/ScreenUVNode.js +101 -0
  198. data/lib-opal/js_wrap/three/nodes/accessors/UVNode.js +105 -0
  199. data/lib-opal/js_wrap/three/nodes/core/AttributeNode.js +106 -0
  200. data/lib-opal/js_wrap/three/nodes/core/ConstNode.js +149 -0
  201. data/lib-opal/js_wrap/three/nodes/core/ExpressionNode.js +57 -0
  202. data/lib-opal/js_wrap/three/nodes/core/FunctionCallNode.js +138 -0
  203. data/lib-opal/js_wrap/three/nodes/core/FunctionNode.js +259 -0
  204. data/lib-opal/js_wrap/three/nodes/core/InputNode.js +124 -0
  205. data/lib-opal/js_wrap/three/nodes/core/Node.js +193 -0
  206. data/lib-opal/js_wrap/three/nodes/core/NodeBuilder.js +782 -0
  207. data/lib-opal/js_wrap/three/nodes/core/NodeFrame.js +69 -0
  208. data/lib-opal/js_wrap/three/nodes/core/NodeLib.js +56 -0
  209. data/lib-opal/js_wrap/three/nodes/core/NodeUniform.js +53 -0
  210. data/lib-opal/js_wrap/three/nodes/core/NodeUtils.js +60 -0
  211. data/lib-opal/js_wrap/three/nodes/core/StructNode.js +131 -0
  212. data/lib-opal/js_wrap/three/nodes/core/TempNode.js +160 -0
  213. data/lib-opal/js_wrap/three/nodes/core/VarNode.js +105 -0
  214. data/lib-opal/js_wrap/three/nodes/effects/BlurNode.js +160 -0
  215. data/lib-opal/js_wrap/three/nodes/effects/ColorAdjustmentNode.js +139 -0
  216. data/lib-opal/js_wrap/three/nodes/effects/LuminanceNode.js +106 -0
  217. data/lib-opal/js_wrap/three/nodes/inputs/BoolNode.js +95 -0
  218. data/lib-opal/js_wrap/three/nodes/inputs/ColorNode.js +99 -0
  219. data/lib-opal/js_wrap/three/nodes/inputs/CubeTextureNode.js +136 -0
  220. data/lib-opal/js_wrap/three/nodes/inputs/FloatNode.js +95 -0
  221. data/lib-opal/js_wrap/three/nodes/inputs/IntNode.js +95 -0
  222. data/lib-opal/js_wrap/three/nodes/inputs/Matrix3Node.js +102 -0
  223. data/lib-opal/js_wrap/three/nodes/inputs/Matrix4Node.js +102 -0
  224. data/lib-opal/js_wrap/three/nodes/inputs/PropertyNode.js +85 -0
  225. data/lib-opal/js_wrap/three/nodes/inputs/RTTNode.js +164 -0
  226. data/lib-opal/js_wrap/three/nodes/inputs/ReflectorNode.js +111 -0
  227. data/lib-opal/js_wrap/three/nodes/inputs/ScreenNode.js +69 -0
  228. data/lib-opal/js_wrap/three/nodes/inputs/TextureNode.js +140 -0
  229. data/lib-opal/js_wrap/three/nodes/inputs/Vector2Node.js +98 -0
  230. data/lib-opal/js_wrap/three/nodes/inputs/Vector3Node.js +99 -0
  231. data/lib-opal/js_wrap/three/nodes/inputs/Vector4Node.js +100 -0
  232. data/lib-opal/js_wrap/three/nodes/materials/BasicNodeMaterial.js +63 -0
  233. data/lib-opal/js_wrap/three/nodes/materials/MeshStandardNodeMaterial.js +63 -0
  234. data/lib-opal/js_wrap/three/nodes/materials/NodeMaterial.js +202 -0
  235. data/lib-opal/js_wrap/three/nodes/materials/PhongNodeMaterial.js +63 -0
  236. data/lib-opal/js_wrap/three/nodes/materials/SpriteNodeMaterial.js +63 -0
  237. data/lib-opal/js_wrap/three/nodes/materials/StandardNodeMaterial.js +63 -0
  238. data/lib-opal/js_wrap/three/nodes/materials/nodes/BasicNode.js +146 -0
  239. data/lib-opal/js_wrap/three/nodes/materials/nodes/MeshStandardNode.js +133 -0
  240. data/lib-opal/js_wrap/three/nodes/materials/nodes/PhongNode.js +273 -0
  241. data/lib-opal/js_wrap/three/nodes/materials/nodes/RawNode.js +101 -0
  242. data/lib-opal/js_wrap/three/nodes/materials/nodes/SpriteNode.js +176 -0
  243. data/lib-opal/js_wrap/three/nodes/materials/nodes/StandardNode.js +397 -0
  244. data/lib-opal/js_wrap/three/nodes/math/CondNode.js +151 -0
  245. data/lib-opal/js_wrap/three/nodes/math/MathNode.js +266 -0
  246. data/lib-opal/js_wrap/three/nodes/math/OperatorNode.js +120 -0
  247. data/lib-opal/js_wrap/three/nodes/misc/BumpMapNode.js +139 -0
  248. data/lib-opal/js_wrap/three/nodes/misc/NormalMapNode.js +122 -0
  249. data/lib-opal/js_wrap/three/nodes/misc/TextureCubeNode.js +107 -0
  250. data/lib-opal/js_wrap/three/nodes/misc/TextureCubeUVNode.js +191 -0
  251. data/lib-opal/js_wrap/three/nodes/postprocessing/NodePass.js +117 -0
  252. data/lib-opal/js_wrap/three/nodes/postprocessing/NodePostProcessing.js +128 -0
  253. data/lib-opal/js_wrap/three/nodes/procedural/CheckerNode.js +104 -0
  254. data/lib-opal/js_wrap/three/nodes/procedural/Fractal3DNode.js +121 -0
  255. data/lib-opal/js_wrap/three/nodes/procedural/Noise2DNode.js +115 -0
  256. data/lib-opal/js_wrap/three/nodes/procedural/Noise3DNode.js +112 -0
  257. data/lib-opal/js_wrap/three/nodes/utils/BypassNode.js +115 -0
  258. data/lib-opal/js_wrap/three/nodes/utils/ColorSpaceNode.js +214 -0
  259. data/lib-opal/js_wrap/three/nodes/utils/JoinNode.js +138 -0
  260. data/lib-opal/js_wrap/three/nodes/utils/MaxMIPLevelNode.js +88 -0
  261. data/lib-opal/js_wrap/three/nodes/utils/RemapNode.js +117 -0
  262. data/lib-opal/js_wrap/three/nodes/utils/SpecularMIPLevelNode.js +121 -0
  263. data/lib-opal/js_wrap/three/nodes/utils/SubSlotNode.js +112 -0
  264. data/lib-opal/js_wrap/three/nodes/utils/SwitchNode.js +129 -0
  265. data/lib-opal/js_wrap/three/nodes/utils/TimerNode.js +126 -0
  266. data/lib-opal/js_wrap/three/nodes/utils/UVTransformNode.js +104 -0
  267. data/lib-opal/js_wrap/three/nodes/utils/VelocityNode.js +181 -0
  268. data/lib-opal/js_wrap/three/objects/Lensflare.js +285 -0
  269. data/lib-opal/js_wrap/three/objects/LightningStorm.js +238 -0
  270. data/lib-opal/js_wrap/three/objects/MarchingCubes.js +667 -0
  271. data/lib-opal/js_wrap/three/objects/Reflector.js +205 -0
  272. data/lib-opal/js_wrap/three/objects/ReflectorForSSRPass.js +288 -0
  273. data/lib-opal/js_wrap/three/objects/ReflectorRTT.js +63 -0
  274. data/lib-opal/js_wrap/three/objects/Refractor.js +243 -0
  275. data/lib-opal/js_wrap/three/objects/ShadowMesh.js +100 -0
  276. data/lib-opal/js_wrap/three/objects/Sky.js +107 -0
  277. data/lib-opal/js_wrap/three/objects/Water.js +246 -0
  278. data/lib-opal/js_wrap/three/objects/Water2.js +238 -0
  279. data/lib-opal/js_wrap/three/offscreen/jank.js +51 -0
  280. data/lib-opal/js_wrap/three/offscreen/offscreen.js +24 -0
  281. data/lib-opal/js_wrap/three/offscreen/scene.js +99 -0
  282. data/lib-opal/js_wrap/three/physics/AmmoPhysics.js +266 -0
  283. data/lib-opal/js_wrap/three/physics/OimoPhysics.js +214 -0
  284. data/lib-opal/js_wrap/three/postprocessing/AdaptiveToneMappingPass.js +307 -0
  285. data/lib-opal/js_wrap/three/postprocessing/AfterimagePass.js +116 -0
  286. data/lib-opal/js_wrap/three/postprocessing/BloomPass.js +132 -0
  287. data/lib-opal/js_wrap/three/postprocessing/BokehPass.js +143 -0
  288. data/lib-opal/js_wrap/three/postprocessing/ClearPass.js +85 -0
  289. data/lib-opal/js_wrap/three/postprocessing/CubeTexturePass.js +104 -0
  290. data/lib-opal/js_wrap/three/postprocessing/DotScreenPass.js +90 -0
  291. data/lib-opal/js_wrap/three/postprocessing/EffectComposer.js +272 -0
  292. data/lib-opal/js_wrap/three/postprocessing/FilmPass.js +91 -0
  293. data/lib-opal/js_wrap/three/postprocessing/GlitchPass.js +140 -0
  294. data/lib-opal/js_wrap/three/postprocessing/HalftonePass.js +108 -0
  295. data/lib-opal/js_wrap/three/postprocessing/LUTPass.js +132 -0
  296. data/lib-opal/js_wrap/three/postprocessing/MaskPass.js +142 -0
  297. data/lib-opal/js_wrap/three/postprocessing/OutlinePass.js +480 -0
  298. data/lib-opal/js_wrap/three/postprocessing/Pass.js +101 -0
  299. data/lib-opal/js_wrap/three/postprocessing/RenderPass.js +109 -0
  300. data/lib-opal/js_wrap/three/postprocessing/SAOPass.js +384 -0
  301. data/lib-opal/js_wrap/three/postprocessing/SMAAPass.js +199 -0
  302. data/lib-opal/js_wrap/three/postprocessing/SSAARenderPass.js +186 -0
  303. data/lib-opal/js_wrap/three/postprocessing/SSAOPass.js +388 -0
  304. data/lib-opal/js_wrap/three/postprocessing/SSRPass.js +537 -0
  305. data/lib-opal/js_wrap/three/postprocessing/SSRrPass.js +481 -0
  306. data/lib-opal/js_wrap/three/postprocessing/SavePass.js +96 -0
  307. data/lib-opal/js_wrap/three/postprocessing/ShaderPass.js +98 -0
  308. data/lib-opal/js_wrap/three/postprocessing/TAARenderPass.js +159 -0
  309. data/lib-opal/js_wrap/three/postprocessing/TexturePass.js +91 -0
  310. data/lib-opal/js_wrap/three/postprocessing/UnrealBloomPass.js +335 -0
  311. data/lib-opal/js_wrap/three/renderers/CSS2DRenderer.js +213 -0
  312. data/lib-opal/js_wrap/three/renderers/CSS3DRenderer.js +277 -0
  313. data/lib-opal/js_wrap/three/renderers/Projector.js +733 -0
  314. data/lib-opal/js_wrap/three/renderers/SVGRenderer.js +470 -0
  315. data/lib-opal/js_wrap/three/renderers/nodes/Nodes.js +531 -0
  316. data/lib-opal/js_wrap/three/renderers/nodes/ShaderNode.js +386 -0
  317. data/lib-opal/js_wrap/three/renderers/nodes/accessors/CameraNode.js +114 -0
  318. data/lib-opal/js_wrap/three/renderers/nodes/accessors/MaterialNode.js +140 -0
  319. data/lib-opal/js_wrap/three/renderers/nodes/accessors/MaterialReferenceNode.js +79 -0
  320. data/lib-opal/js_wrap/three/renderers/nodes/accessors/ModelNode.js +62 -0
  321. data/lib-opal/js_wrap/three/renderers/nodes/accessors/ModelViewProjectionNode.js +80 -0
  322. data/lib-opal/js_wrap/three/renderers/nodes/accessors/NormalNode.js +113 -0
  323. data/lib-opal/js_wrap/three/renderers/nodes/accessors/Object3DNode.js +136 -0
  324. data/lib-opal/js_wrap/three/renderers/nodes/accessors/PointUVNode.js +70 -0
  325. data/lib-opal/js_wrap/three/renderers/nodes/accessors/PositionNode.js +117 -0
  326. data/lib-opal/js_wrap/three/renderers/nodes/accessors/ReferenceNode.js +124 -0
  327. data/lib-opal/js_wrap/three/renderers/nodes/accessors/SkinningNode.js +129 -0
  328. data/lib-opal/js_wrap/three/renderers/nodes/accessors/UVNode.js +77 -0
  329. data/lib-opal/js_wrap/three/renderers/nodes/core/ArrayInputNode.js +74 -0
  330. data/lib-opal/js_wrap/three/renderers/nodes/core/AttributeNode.js +97 -0
  331. data/lib-opal/js_wrap/three/renderers/nodes/core/BypassNode.js +84 -0
  332. data/lib-opal/js_wrap/three/renderers/nodes/core/CodeNode.js +131 -0
  333. data/lib-opal/js_wrap/three/renderers/nodes/core/ContextNode.js +84 -0
  334. data/lib-opal/js_wrap/three/renderers/nodes/core/ExpressionNode.js +81 -0
  335. data/lib-opal/js_wrap/three/renderers/nodes/core/FunctionCallNode.js +123 -0
  336. data/lib-opal/js_wrap/three/renderers/nodes/core/FunctionNode.js +126 -0
  337. data/lib-opal/js_wrap/three/renderers/nodes/core/InputNode.js +103 -0
  338. data/lib-opal/js_wrap/three/renderers/nodes/core/Node.js +120 -0
  339. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeAttribute.js +37 -0
  340. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeBuilder.js +650 -0
  341. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeCode.js +42 -0
  342. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeFrame.js +70 -0
  343. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeFunction.js +55 -0
  344. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeFunctionInput.js +44 -0
  345. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeKeywords.js +117 -0
  346. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeParser.js +46 -0
  347. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeUniform.js +55 -0
  348. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeVar.js +37 -0
  349. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeVary.js +37 -0
  350. data/lib-opal/js_wrap/three/renderers/nodes/core/PropertyNode.js +90 -0
  351. data/lib-opal/js_wrap/three/renderers/nodes/core/TempNode.js +89 -0
  352. data/lib-opal/js_wrap/three/renderers/nodes/core/VarNode.js +101 -0
  353. data/lib-opal/js_wrap/three/renderers/nodes/core/VaryNode.js +101 -0
  354. data/lib-opal/js_wrap/three/renderers/nodes/core/constants.js +42 -0
  355. data/lib-opal/js_wrap/three/renderers/nodes/display/ColorSpaceNode.js +165 -0
  356. data/lib-opal/js_wrap/three/renderers/nodes/display/NormalMapNode.js +120 -0
  357. data/lib-opal/js_wrap/three/renderers/nodes/functions/BSDFs.js +133 -0
  358. data/lib-opal/js_wrap/three/renderers/nodes/inputs/BufferNode.js +78 -0
  359. data/lib-opal/js_wrap/three/renderers/nodes/inputs/ColorNode.js +67 -0
  360. data/lib-opal/js_wrap/three/renderers/nodes/inputs/FloatNode.js +67 -0
  361. data/lib-opal/js_wrap/three/renderers/nodes/inputs/IntNode.js +67 -0
  362. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Matrix3Node.js +67 -0
  363. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Matrix4Node.js +67 -0
  364. data/lib-opal/js_wrap/three/renderers/nodes/inputs/TextureNode.js +120 -0
  365. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Vector2Node.js +67 -0
  366. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Vector3Node.js +67 -0
  367. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Vector4Node.js +67 -0
  368. data/lib-opal/js_wrap/three/renderers/nodes/lights/LightContextNode.js +103 -0
  369. data/lib-opal/js_wrap/three/renderers/nodes/lights/LightNode.js +115 -0
  370. data/lib-opal/js_wrap/three/renderers/nodes/lights/LightsNode.js +117 -0
  371. data/lib-opal/js_wrap/three/renderers/nodes/materials/LineBasicNodeMaterial.js +82 -0
  372. data/lib-opal/js_wrap/three/renderers/nodes/materials/Materials.js +49 -0
  373. data/lib-opal/js_wrap/three/renderers/nodes/materials/MeshBasicNodeMaterial.js +82 -0
  374. data/lib-opal/js_wrap/three/renderers/nodes/materials/MeshStandardNodeMaterial.js +96 -0
  375. data/lib-opal/js_wrap/three/renderers/nodes/materials/PointsNodeMaterial.js +84 -0
  376. data/lib-opal/js_wrap/three/renderers/nodes/math/CondNode.js +98 -0
  377. data/lib-opal/js_wrap/three/renderers/nodes/math/MathNode.js +255 -0
  378. data/lib-opal/js_wrap/three/renderers/nodes/math/OperatorNode.js +163 -0
  379. data/lib-opal/js_wrap/three/renderers/nodes/parsers/GLSLNodeFunction.js +158 -0
  380. data/lib-opal/js_wrap/three/renderers/nodes/parsers/GLSLNodeParser.js +68 -0
  381. data/lib-opal/js_wrap/three/renderers/nodes/parsers/WGSLNodeFunction.js +126 -0
  382. data/lib-opal/js_wrap/three/renderers/nodes/parsers/WGSLNodeParser.js +68 -0
  383. data/lib-opal/js_wrap/three/renderers/nodes/procedural/CheckerNode.js +84 -0
  384. data/lib-opal/js_wrap/three/renderers/nodes/utils/ArrayElementNode.js +79 -0
  385. data/lib-opal/js_wrap/three/renderers/nodes/utils/ConvertNode.js +82 -0
  386. data/lib-opal/js_wrap/three/renderers/nodes/utils/JoinNode.js +88 -0
  387. data/lib-opal/js_wrap/three/renderers/nodes/utils/OscNode.js +105 -0
  388. data/lib-opal/js_wrap/three/renderers/nodes/utils/SplitNode.js +96 -0
  389. data/lib-opal/js_wrap/three/renderers/nodes/utils/SpriteSheetUVNode.js +98 -0
  390. data/lib-opal/js_wrap/three/renderers/nodes/utils/TimerNode.js +93 -0
  391. data/lib-opal/js_wrap/three/renderers/webgl/nodes/SlotNode.js +72 -0
  392. data/lib-opal/js_wrap/three/renderers/webgl/nodes/WebGLNodeBuilder.js +463 -0
  393. data/lib-opal/js_wrap/three/renderers/webgl/nodes/WebGLNodes.js +62 -0
  394. data/lib-opal/js_wrap/three/renderers/webgl/nodes/WebGLPhysicalContextNode.js +95 -0
  395. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPU.js +62 -0
  396. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUAttributes.js +118 -0
  397. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBackground.js +109 -0
  398. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBinding.js +52 -0
  399. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBindings.js +254 -0
  400. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBufferUtils.js +39 -0
  401. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUComputePipelines.js +82 -0
  402. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUGeometries.js +84 -0
  403. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUInfo.js +86 -0
  404. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUObjects.js +64 -0
  405. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUProgrammableStage.js +46 -0
  406. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUProperties.js +63 -0
  407. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderLists.js +180 -0
  408. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderPipeline.js +662 -0
  409. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderPipelines.js +275 -0
  410. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderer.js +883 -0
  411. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUSampledTexture.js +139 -0
  412. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUSampler.js +76 -0
  413. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUStorageBuffer.js +69 -0
  414. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUTextureRenderer.js +64 -0
  415. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUTextureUtils.js +125 -0
  416. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUTextures.js +681 -0
  417. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUUniform.js +237 -0
  418. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUUniformBuffer.js +90 -0
  419. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUUniformsGroup.js +294 -0
  420. data/lib-opal/js_wrap/three/renderers/webgpu/constants.js +263 -0
  421. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeBuilder.js +619 -0
  422. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeSampledTexture.js +67 -0
  423. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeSampler.js +71 -0
  424. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeUniform.js +229 -0
  425. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js +68 -0
  426. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodes.js +106 -0
  427. data/lib-opal/js_wrap/three/shaders/ACESFilmicToneMappingShader.js +45 -0
  428. data/lib-opal/js_wrap/three/shaders/AfterimageShader.js +46 -0
  429. data/lib-opal/js_wrap/three/shaders/BasicShader.js +34 -0
  430. data/lib-opal/js_wrap/three/shaders/BleachBypassShader.js +43 -0
  431. data/lib-opal/js_wrap/three/shaders/BlendShader.js +47 -0
  432. data/lib-opal/js_wrap/three/shaders/BokehShader.js +65 -0
  433. data/lib-opal/js_wrap/three/shaders/BokehShader2.js +125 -0
  434. data/lib-opal/js_wrap/three/shaders/BrightnessContrastShader.js +47 -0
  435. data/lib-opal/js_wrap/three/shaders/ColorCorrectionShader.js +47 -0
  436. data/lib-opal/js_wrap/three/shaders/ColorifyShader.js +41 -0
  437. data/lib-opal/js_wrap/three/shaders/ConvolutionShader.js +75 -0
  438. data/lib-opal/js_wrap/three/shaders/CopyShader.js +41 -0
  439. data/lib-opal/js_wrap/three/shaders/DOFMipMapShader.js +49 -0
  440. data/lib-opal/js_wrap/three/shaders/DepthLimitedBlurShader.js +95 -0
  441. data/lib-opal/js_wrap/three/shaders/DigitalGlitch.js +79 -0
  442. data/lib-opal/js_wrap/three/shaders/DotScreenShader.js +52 -0
  443. data/lib-opal/js_wrap/three/shaders/FXAAShader.js +78 -0
  444. data/lib-opal/js_wrap/three/shaders/FilmShader.js +69 -0
  445. data/lib-opal/js_wrap/three/shaders/FocusShader.js +52 -0
  446. data/lib-opal/js_wrap/three/shaders/FreiChenShader.js +44 -0
  447. data/lib-opal/js_wrap/three/shaders/GammaCorrectionShader.js +39 -0
  448. data/lib-opal/js_wrap/three/shaders/GodRaysShader.js +140 -0
  449. data/lib-opal/js_wrap/three/shaders/HalftoneShader.js +77 -0
  450. data/lib-opal/js_wrap/three/shaders/HorizontalBlurShader.js +47 -0
  451. data/lib-opal/js_wrap/three/shaders/HorizontalTiltShiftShader.js +49 -0
  452. data/lib-opal/js_wrap/three/shaders/HueSaturationShader.js +47 -0
  453. data/lib-opal/js_wrap/three/shaders/KaleidoShader.js +50 -0
  454. data/lib-opal/js_wrap/three/shaders/LuminosityHighPassShader.js +52 -0
  455. data/lib-opal/js_wrap/three/shaders/LuminosityShader.js +39 -0
  456. data/lib-opal/js_wrap/three/shaders/MMDToonShader.js +48 -0
  457. data/lib-opal/js_wrap/three/shaders/MirrorShader.js +44 -0
  458. data/lib-opal/js_wrap/three/shaders/NormalMapShader.js +48 -0
  459. data/lib-opal/js_wrap/three/shaders/PixelShader.js +44 -0
  460. data/lib-opal/js_wrap/three/shaders/RGBShiftShader.js +50 -0
  461. data/lib-opal/js_wrap/three/shaders/SAOShader.js +85 -0
  462. data/lib-opal/js_wrap/three/shaders/SMAAShader.js +95 -0
  463. data/lib-opal/js_wrap/three/shaders/SSAOShader.js +113 -0
  464. data/lib-opal/js_wrap/three/shaders/SSRShader.js +126 -0
  465. data/lib-opal/js_wrap/three/shaders/SSRrShader.js +106 -0
  466. data/lib-opal/js_wrap/three/shaders/SepiaShader.js +43 -0
  467. data/lib-opal/js_wrap/three/shaders/SobelOperatorShader.js +44 -0
  468. data/lib-opal/js_wrap/three/shaders/SubsurfaceScatteringShader.js +64 -0
  469. data/lib-opal/js_wrap/three/shaders/TechnicolorShader.js +41 -0
  470. data/lib-opal/js_wrap/three/shaders/ToneMapShader.js +53 -0
  471. data/lib-opal/js_wrap/three/shaders/ToonShader.js +148 -0
  472. data/lib-opal/js_wrap/three/shaders/TriangleBlurShader.js +47 -0
  473. data/lib-opal/js_wrap/three/shaders/UnpackDepthRGBAShader.js +42 -0
  474. data/lib-opal/js_wrap/three/shaders/VerticalBlurShader.js +47 -0
  475. data/lib-opal/js_wrap/three/shaders/VerticalTiltShiftShader.js +49 -0
  476. data/lib-opal/js_wrap/three/shaders/VignetteShader.js +46 -0
  477. data/lib-opal/js_wrap/three/shaders/VolumeShader.js +55 -0
  478. data/lib-opal/js_wrap/three/shaders/WaterRefractionShader.js +46 -0
  479. data/lib-opal/js_wrap/three/textures/FlakesTexture.js +61 -0
  480. data/lib-opal/js_wrap/three/utils/BufferGeometryUtils.js +683 -0
  481. data/lib-opal/js_wrap/three/utils/CameraUtils.js +97 -0
  482. data/lib-opal/js_wrap/three/utils/GPUStatsPanel.js +154 -0
  483. data/lib-opal/js_wrap/three/utils/GeometryCompressionUtils.js +468 -0
  484. data/lib-opal/js_wrap/three/utils/GeometryUtils.js +192 -0
  485. data/lib-opal/js_wrap/three/utils/PackedPhongMaterial.js +77 -0
  486. data/lib-opal/js_wrap/three/utils/RoughnessMipmapper.js +169 -0
  487. data/lib-opal/js_wrap/three/utils/SceneUtils.js +62 -0
  488. data/lib-opal/js_wrap/three/utils/ShadowMapViewer.js +182 -0
  489. data/lib-opal/js_wrap/three/utils/SkeletonUtils.js +400 -0
  490. data/lib-opal/js_wrap/three/utils/UVsDebug.js +132 -0
  491. data/lib-opal/js_wrap/three/utils/WorkerPool.js +130 -0
  492. data/lib-opal/js_wrap/three/webxr/ARButton.js +203 -0
  493. data/lib-opal/js_wrap/three/webxr/OculusHandModel.js +131 -0
  494. data/lib-opal/js_wrap/three/webxr/OculusHandPointerModel.js +328 -0
  495. data/lib-opal/js_wrap/three/webxr/Text2D.js +54 -0
  496. data/lib-opal/js_wrap/three/webxr/VRButton.js +181 -0
  497. data/lib-opal/js_wrap/three/webxr/XRControllerModelFactory.js +266 -0
  498. data/lib-opal/js_wrap/three/webxr/XREstimatedLight.js +221 -0
  499. data/lib-opal/js_wrap/three/webxr/XRHandMeshModel.js +93 -0
  500. data/lib-opal/js_wrap/three/webxr/XRHandModelFactory.js +127 -0
  501. data/lib-opal/js_wrap/three/webxr/XRHandPrimitiveModel.js +85 -0
  502. data/opal-js_wrap-three.gemspec +4 -4
  503. metadata +502 -5
@@ -0,0 +1,1999 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports);
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports);
11
+ global.ecsyModule = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.Component = void 0;
20
+ _exports.Not = Not;
21
+ _exports.copyValue = _exports.copyJSON = _exports.copyCopyable = _exports.copyArray = _exports.cloneValue = _exports.cloneJSON = _exports.cloneClonable = _exports.cloneArray = _exports._Entity = _exports.World = _exports.Version = _exports.Types = _exports.TagComponent = _exports.SystemStateComponent = _exports.System = _exports.ObjectPool = void 0;
22
+ _exports.createType = createType;
23
+ _exports.enableRemoteDevtools = enableRemoteDevtools;
24
+
25
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
26
+
27
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
28
+
29
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
30
+
31
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
32
+
33
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
34
+
35
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
36
+
37
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
38
+
39
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
+
41
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
42
+
43
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
44
+
45
+ /**
46
+ * Return the name of a component
47
+ * @param {Component} Component
48
+ * @private
49
+ */
50
+
51
+ /**
52
+ * Get a key from a list of components
53
+ * @param {Array(Component)} Components Array of components to generate the key
54
+ * @private
55
+ */
56
+ function queryKey(Components) {
57
+ var ids = [];
58
+
59
+ for (var n = 0; n < Components.length; n++) {
60
+ var T = Components[n];
61
+
62
+ if (!componentRegistered(T)) {
63
+ throw new Error("Tried to create a query with an unregistered component");
64
+ }
65
+
66
+ if (typeof T === "object") {
67
+ var operator = T.operator === "not" ? "!" : T.operator;
68
+ ids.push(operator + T.Component._typeId);
69
+ } else {
70
+ ids.push(T._typeId);
71
+ }
72
+ }
73
+
74
+ return ids.sort().join("-");
75
+ } // Detector for browser's "window"
76
+
77
+
78
+ var hasWindow = typeof window !== "undefined"; // performance.now() "polyfill"
79
+
80
+ var now = hasWindow && typeof window.performance !== "undefined" ? performance.now.bind(performance) : Date.now.bind(Date);
81
+
82
+ function componentRegistered(T) {
83
+ return typeof T === "object" && T.Component._typeId !== undefined || T.isComponent && T._typeId !== undefined;
84
+ }
85
+
86
+ var SystemManager = /*#__PURE__*/function () {
87
+ function SystemManager(world) {
88
+ _classCallCheck(this, SystemManager);
89
+
90
+ this._systems = [];
91
+ this._executeSystems = []; // Systems that have `execute` method
92
+
93
+ this.world = world;
94
+ this.lastExecutedSystem = null;
95
+ }
96
+
97
+ _createClass(SystemManager, [{
98
+ key: "registerSystem",
99
+ value: function registerSystem(SystemClass, attributes) {
100
+ if (!SystemClass.isSystem) {
101
+ throw new Error("System '".concat(SystemClass.name, "' does not extend 'System' class"));
102
+ }
103
+
104
+ if (this.getSystem(SystemClass) !== undefined) {
105
+ console.warn("System '".concat(SystemClass.getName(), "' already registered."));
106
+ return this;
107
+ }
108
+
109
+ var system = new SystemClass(this.world, attributes);
110
+ if (system.init) system.init(attributes);
111
+ system.order = this._systems.length;
112
+
113
+ this._systems.push(system);
114
+
115
+ if (system.execute) {
116
+ this._executeSystems.push(system);
117
+
118
+ this.sortSystems();
119
+ }
120
+
121
+ return this;
122
+ }
123
+ }, {
124
+ key: "unregisterSystem",
125
+ value: function unregisterSystem(SystemClass) {
126
+ var system = this.getSystem(SystemClass);
127
+
128
+ if (system === undefined) {
129
+ console.warn("Can unregister system '".concat(SystemClass.getName(), "'. It doesn't exist."));
130
+ return this;
131
+ }
132
+
133
+ this._systems.splice(this._systems.indexOf(system), 1);
134
+
135
+ if (system.execute) {
136
+ this._executeSystems.splice(this._executeSystems.indexOf(system), 1);
137
+ } // @todo Add system.unregister() call to free resources
138
+
139
+
140
+ return this;
141
+ }
142
+ }, {
143
+ key: "sortSystems",
144
+ value: function sortSystems() {
145
+ this._executeSystems.sort(function (a, b) {
146
+ return a.priority - b.priority || a.order - b.order;
147
+ });
148
+ }
149
+ }, {
150
+ key: "getSystem",
151
+ value: function getSystem(SystemClass) {
152
+ return this._systems.find(function (s) {
153
+ return s instanceof SystemClass;
154
+ });
155
+ }
156
+ }, {
157
+ key: "getSystems",
158
+ value: function getSystems() {
159
+ return this._systems;
160
+ }
161
+ }, {
162
+ key: "removeSystem",
163
+ value: function removeSystem(SystemClass) {
164
+ var index = this._systems.indexOf(SystemClass);
165
+
166
+ if (!~index) return;
167
+
168
+ this._systems.splice(index, 1);
169
+ }
170
+ }, {
171
+ key: "executeSystem",
172
+ value: function executeSystem(system, delta, time) {
173
+ if (system.initialized) {
174
+ if (system.canExecute()) {
175
+ var startTime = now();
176
+ system.execute(delta, time);
177
+ system.executeTime = now() - startTime;
178
+ this.lastExecutedSystem = system;
179
+ system.clearEvents();
180
+ }
181
+ }
182
+ }
183
+ }, {
184
+ key: "stop",
185
+ value: function stop() {
186
+ this._executeSystems.forEach(function (system) {
187
+ return system.stop();
188
+ });
189
+ }
190
+ }, {
191
+ key: "execute",
192
+ value: function execute(delta, time, forcePlay) {
193
+ var _this = this;
194
+
195
+ this._executeSystems.forEach(function (system) {
196
+ return (forcePlay || system.enabled) && _this.executeSystem(system, delta, time);
197
+ });
198
+ }
199
+ }, {
200
+ key: "stats",
201
+ value: function stats() {
202
+ var stats = {
203
+ numSystems: this._systems.length,
204
+ systems: {}
205
+ };
206
+
207
+ for (var i = 0; i < this._systems.length; i++) {
208
+ var system = this._systems[i];
209
+ var systemStats = stats.systems[system.getName()] = {
210
+ queries: {},
211
+ executeTime: system.executeTime
212
+ };
213
+
214
+ for (var name in system.ctx) {
215
+ systemStats.queries[name] = system.ctx[name].stats();
216
+ }
217
+ }
218
+
219
+ return stats;
220
+ }
221
+ }]);
222
+
223
+ return SystemManager;
224
+ }();
225
+
226
+ var ObjectPool = /*#__PURE__*/function () {
227
+ // @todo Add initial size
228
+ function ObjectPool(T, initialSize) {
229
+ _classCallCheck(this, ObjectPool);
230
+
231
+ this.freeList = [];
232
+ this.count = 0;
233
+ this.T = T;
234
+ this.isObjectPool = true;
235
+
236
+ if (typeof initialSize !== "undefined") {
237
+ this.expand(initialSize);
238
+ }
239
+ }
240
+
241
+ _createClass(ObjectPool, [{
242
+ key: "acquire",
243
+ value: function acquire() {
244
+ // Grow the list by 20%ish if we're out
245
+ if (this.freeList.length <= 0) {
246
+ this.expand(Math.round(this.count * 0.2) + 1);
247
+ }
248
+
249
+ var item = this.freeList.pop();
250
+ return item;
251
+ }
252
+ }, {
253
+ key: "release",
254
+ value: function release(item) {
255
+ item.reset();
256
+ this.freeList.push(item);
257
+ }
258
+ }, {
259
+ key: "expand",
260
+ value: function expand(count) {
261
+ for (var n = 0; n < count; n++) {
262
+ var clone = new this.T();
263
+ clone._pool = this;
264
+ this.freeList.push(clone);
265
+ }
266
+
267
+ this.count += count;
268
+ }
269
+ }, {
270
+ key: "totalSize",
271
+ value: function totalSize() {
272
+ return this.count;
273
+ }
274
+ }, {
275
+ key: "totalFree",
276
+ value: function totalFree() {
277
+ return this.freeList.length;
278
+ }
279
+ }, {
280
+ key: "totalUsed",
281
+ value: function totalUsed() {
282
+ return this.count - this.freeList.length;
283
+ }
284
+ }]);
285
+
286
+ return ObjectPool;
287
+ }();
288
+ /**
289
+ * @private
290
+ * @class EventDispatcher
291
+ */
292
+
293
+
294
+ _exports.ObjectPool = ObjectPool;
295
+
296
+ var EventDispatcher = /*#__PURE__*/function () {
297
+ function EventDispatcher() {
298
+ _classCallCheck(this, EventDispatcher);
299
+
300
+ this._listeners = {};
301
+ this.stats = {
302
+ fired: 0,
303
+ handled: 0
304
+ };
305
+ }
306
+ /**
307
+ * Add an event listener
308
+ * @param {String} eventName Name of the event to listen
309
+ * @param {Function} listener Callback to trigger when the event is fired
310
+ */
311
+
312
+
313
+ _createClass(EventDispatcher, [{
314
+ key: "addEventListener",
315
+ value: function addEventListener(eventName, listener) {
316
+ var listeners = this._listeners;
317
+
318
+ if (listeners[eventName] === undefined) {
319
+ listeners[eventName] = [];
320
+ }
321
+
322
+ if (listeners[eventName].indexOf(listener) === -1) {
323
+ listeners[eventName].push(listener);
324
+ }
325
+ }
326
+ /**
327
+ * Check if an event listener is already added to the list of listeners
328
+ * @param {String} eventName Name of the event to check
329
+ * @param {Function} listener Callback for the specified event
330
+ */
331
+
332
+ }, {
333
+ key: "hasEventListener",
334
+ value: function hasEventListener(eventName, listener) {
335
+ return this._listeners[eventName] !== undefined && this._listeners[eventName].indexOf(listener) !== -1;
336
+ }
337
+ /**
338
+ * Remove an event listener
339
+ * @param {String} eventName Name of the event to remove
340
+ * @param {Function} listener Callback for the specified event
341
+ */
342
+
343
+ }, {
344
+ key: "removeEventListener",
345
+ value: function removeEventListener(eventName, listener) {
346
+ var listenerArray = this._listeners[eventName];
347
+
348
+ if (listenerArray !== undefined) {
349
+ var index = listenerArray.indexOf(listener);
350
+
351
+ if (index !== -1) {
352
+ listenerArray.splice(index, 1);
353
+ }
354
+ }
355
+ }
356
+ /**
357
+ * Dispatch an event
358
+ * @param {String} eventName Name of the event to dispatch
359
+ * @param {Entity} entity (Optional) Entity to emit
360
+ * @param {Component} component
361
+ */
362
+
363
+ }, {
364
+ key: "dispatchEvent",
365
+ value: function dispatchEvent(eventName, entity, component) {
366
+ this.stats.fired++;
367
+ var listenerArray = this._listeners[eventName];
368
+
369
+ if (listenerArray !== undefined) {
370
+ var array = listenerArray.slice(0);
371
+
372
+ for (var i = 0; i < array.length; i++) {
373
+ array[i].call(this, entity, component);
374
+ }
375
+ }
376
+ }
377
+ /**
378
+ * Reset stats counters
379
+ */
380
+
381
+ }, {
382
+ key: "resetCounters",
383
+ value: function resetCounters() {
384
+ this.stats.fired = this.stats.handled = 0;
385
+ }
386
+ }]);
387
+
388
+ return EventDispatcher;
389
+ }();
390
+
391
+ var Query = /*#__PURE__*/function () {
392
+ /**
393
+ * @param {Array(Component)} Components List of types of components to query
394
+ */
395
+ function Query(Components, manager) {
396
+ var _this2 = this;
397
+
398
+ _classCallCheck(this, Query);
399
+
400
+ this.Components = [];
401
+ this.NotComponents = [];
402
+ Components.forEach(function (component) {
403
+ if (typeof component === "object") {
404
+ _this2.NotComponents.push(component.Component);
405
+ } else {
406
+ _this2.Components.push(component);
407
+ }
408
+ });
409
+
410
+ if (this.Components.length === 0) {
411
+ throw new Error("Can't create a query without components");
412
+ }
413
+
414
+ this.entities = [];
415
+ this.eventDispatcher = new EventDispatcher(); // This query is being used by a reactive system
416
+
417
+ this.reactive = false;
418
+ this.key = queryKey(Components); // Fill the query with the existing entities
419
+
420
+ for (var i = 0; i < manager._entities.length; i++) {
421
+ var entity = manager._entities[i];
422
+
423
+ if (this.match(entity)) {
424
+ // @todo ??? this.addEntity(entity); => preventing the event to be generated
425
+ entity.queries.push(this);
426
+ this.entities.push(entity);
427
+ }
428
+ }
429
+ }
430
+ /**
431
+ * Add entity to this query
432
+ * @param {Entity} entity
433
+ */
434
+
435
+
436
+ _createClass(Query, [{
437
+ key: "addEntity",
438
+ value: function addEntity(entity) {
439
+ entity.queries.push(this);
440
+ this.entities.push(entity);
441
+ this.eventDispatcher.dispatchEvent(Query.prototype.ENTITY_ADDED, entity);
442
+ }
443
+ /**
444
+ * Remove entity from this query
445
+ * @param {Entity} entity
446
+ */
447
+
448
+ }, {
449
+ key: "removeEntity",
450
+ value: function removeEntity(entity) {
451
+ var index = this.entities.indexOf(entity);
452
+
453
+ if (~index) {
454
+ this.entities.splice(index, 1);
455
+ index = entity.queries.indexOf(this);
456
+ entity.queries.splice(index, 1);
457
+ this.eventDispatcher.dispatchEvent(Query.prototype.ENTITY_REMOVED, entity);
458
+ }
459
+ }
460
+ }, {
461
+ key: "match",
462
+ value: function match(entity) {
463
+ return entity.hasAllComponents(this.Components) && !entity.hasAnyComponents(this.NotComponents);
464
+ }
465
+ }, {
466
+ key: "toJSON",
467
+ value: function toJSON() {
468
+ return {
469
+ key: this.key,
470
+ reactive: this.reactive,
471
+ components: {
472
+ included: this.Components.map(function (C) {
473
+ return C.name;
474
+ }),
475
+ not: this.NotComponents.map(function (C) {
476
+ return C.name;
477
+ })
478
+ },
479
+ numEntities: this.entities.length
480
+ };
481
+ }
482
+ /**
483
+ * Return stats for this query
484
+ */
485
+
486
+ }, {
487
+ key: "stats",
488
+ value: function stats() {
489
+ return {
490
+ numComponents: this.Components.length,
491
+ numEntities: this.entities.length
492
+ };
493
+ }
494
+ }]);
495
+
496
+ return Query;
497
+ }();
498
+
499
+ Query.prototype.ENTITY_ADDED = "Query#ENTITY_ADDED";
500
+ Query.prototype.ENTITY_REMOVED = "Query#ENTITY_REMOVED";
501
+ Query.prototype.COMPONENT_CHANGED = "Query#COMPONENT_CHANGED";
502
+ /**
503
+ * @private
504
+ * @class QueryManager
505
+ */
506
+
507
+ var QueryManager = /*#__PURE__*/function () {
508
+ function QueryManager(world) {
509
+ _classCallCheck(this, QueryManager);
510
+
511
+ this._world = world; // Queries indexed by a unique identifier for the components it has
512
+
513
+ this._queries = {};
514
+ }
515
+
516
+ _createClass(QueryManager, [{
517
+ key: "onEntityRemoved",
518
+ value: function onEntityRemoved(entity) {
519
+ for (var queryName in this._queries) {
520
+ var query = this._queries[queryName];
521
+
522
+ if (entity.queries.indexOf(query) !== -1) {
523
+ query.removeEntity(entity);
524
+ }
525
+ }
526
+ }
527
+ /**
528
+ * Callback when a component is added to an entity
529
+ * @param {Entity} entity Entity that just got the new component
530
+ * @param {Component} Component Component added to the entity
531
+ */
532
+
533
+ }, {
534
+ key: "onEntityComponentAdded",
535
+ value: function onEntityComponentAdded(entity, Component) {
536
+ // @todo Use bitmask for checking components?
537
+ // Check each indexed query to see if we need to add this entity to the list
538
+ for (var queryName in this._queries) {
539
+ var query = this._queries[queryName];
540
+
541
+ if (!!~query.NotComponents.indexOf(Component) && ~query.entities.indexOf(entity)) {
542
+ query.removeEntity(entity);
543
+ continue;
544
+ } // Add the entity only if:
545
+ // Component is in the query
546
+ // and Entity has ALL the components of the query
547
+ // and Entity is not already in the query
548
+
549
+
550
+ if (!~query.Components.indexOf(Component) || !query.match(entity) || ~query.entities.indexOf(entity)) continue;
551
+ query.addEntity(entity);
552
+ }
553
+ }
554
+ /**
555
+ * Callback when a component is removed from an entity
556
+ * @param {Entity} entity Entity to remove the component from
557
+ * @param {Component} Component Component to remove from the entity
558
+ */
559
+
560
+ }, {
561
+ key: "onEntityComponentRemoved",
562
+ value: function onEntityComponentRemoved(entity, Component) {
563
+ for (var queryName in this._queries) {
564
+ var query = this._queries[queryName];
565
+
566
+ if (!!~query.NotComponents.indexOf(Component) && !~query.entities.indexOf(entity) && query.match(entity)) {
567
+ query.addEntity(entity);
568
+ continue;
569
+ }
570
+
571
+ if (!!~query.Components.indexOf(Component) && !!~query.entities.indexOf(entity) && !query.match(entity)) {
572
+ query.removeEntity(entity);
573
+ continue;
574
+ }
575
+ }
576
+ }
577
+ /**
578
+ * Get a query for the specified components
579
+ * @param {Component} Components Components that the query should have
580
+ */
581
+
582
+ }, {
583
+ key: "getQuery",
584
+ value: function getQuery(Components) {
585
+ var key = queryKey(Components);
586
+ var query = this._queries[key];
587
+
588
+ if (!query) {
589
+ this._queries[key] = query = new Query(Components, this._world);
590
+ }
591
+
592
+ return query;
593
+ }
594
+ /**
595
+ * Return some stats from this class
596
+ */
597
+
598
+ }, {
599
+ key: "stats",
600
+ value: function stats() {
601
+ var stats = {};
602
+
603
+ for (var queryName in this._queries) {
604
+ stats[queryName] = this._queries[queryName].stats();
605
+ }
606
+
607
+ return stats;
608
+ }
609
+ }]);
610
+
611
+ return QueryManager;
612
+ }();
613
+
614
+ var Component = /*#__PURE__*/function () {
615
+ function Component(props) {
616
+ _classCallCheck(this, Component);
617
+
618
+ if (props !== false) {
619
+ var schema = this.constructor.schema;
620
+
621
+ for (var key in schema) {
622
+ if (props && props.hasOwnProperty(key)) {
623
+ this[key] = props[key];
624
+ } else {
625
+ var schemaProp = schema[key];
626
+
627
+ if (schemaProp.hasOwnProperty("default")) {
628
+ this[key] = schemaProp.type.clone(schemaProp.default);
629
+ } else {
630
+ var type = schemaProp.type;
631
+ this[key] = type.clone(type.default);
632
+ }
633
+ }
634
+ }
635
+
636
+ if (props !== undefined) {
637
+ this.checkUndefinedAttributes(props);
638
+ }
639
+ }
640
+
641
+ this._pool = null;
642
+ }
643
+
644
+ _createClass(Component, [{
645
+ key: "copy",
646
+ value: function copy(source) {
647
+ var schema = this.constructor.schema;
648
+
649
+ for (var key in schema) {
650
+ var prop = schema[key];
651
+
652
+ if (source.hasOwnProperty(key)) {
653
+ this[key] = prop.type.copy(source[key], this[key]);
654
+ }
655
+ } // @DEBUG
656
+
657
+
658
+ {
659
+ this.checkUndefinedAttributes(source);
660
+ }
661
+ return this;
662
+ }
663
+ }, {
664
+ key: "clone",
665
+ value: function clone() {
666
+ return new this.constructor().copy(this);
667
+ }
668
+ }, {
669
+ key: "reset",
670
+ value: function reset() {
671
+ var schema = this.constructor.schema;
672
+
673
+ for (var key in schema) {
674
+ var schemaProp = schema[key];
675
+
676
+ if (schemaProp.hasOwnProperty("default")) {
677
+ this[key] = schemaProp.type.copy(schemaProp.default, this[key]);
678
+ } else {
679
+ var type = schemaProp.type;
680
+ this[key] = type.copy(type.default, this[key]);
681
+ }
682
+ }
683
+ }
684
+ }, {
685
+ key: "dispose",
686
+ value: function dispose() {
687
+ if (this._pool) {
688
+ this._pool.release(this);
689
+ }
690
+ }
691
+ }, {
692
+ key: "getName",
693
+ value: function getName() {
694
+ return this.constructor.getName();
695
+ }
696
+ }, {
697
+ key: "checkUndefinedAttributes",
698
+ value: function checkUndefinedAttributes(src) {
699
+ var _this3 = this;
700
+
701
+ var schema = this.constructor.schema; // Check that the attributes defined in source are also defined in the schema
702
+
703
+ Object.keys(src).forEach(function (srcKey) {
704
+ if (!schema.hasOwnProperty(srcKey)) {
705
+ console.warn("Trying to set attribute '".concat(srcKey, "' not defined in the '").concat(_this3.constructor.name, "' schema. Please fix the schema, the attribute value won't be set"));
706
+ }
707
+ });
708
+ }
709
+ }]);
710
+
711
+ return Component;
712
+ }();
713
+
714
+ _exports.Component = Component;
715
+ Component.schema = {};
716
+ Component.isComponent = true;
717
+
718
+ Component.getName = function () {
719
+ return this.displayName || this.name;
720
+ };
721
+
722
+ var SystemStateComponent = /*#__PURE__*/function (_Component) {
723
+ _inherits(SystemStateComponent, _Component);
724
+
725
+ var _super = _createSuper(SystemStateComponent);
726
+
727
+ function SystemStateComponent() {
728
+ _classCallCheck(this, SystemStateComponent);
729
+
730
+ return _super.apply(this, arguments);
731
+ }
732
+
733
+ return _createClass(SystemStateComponent);
734
+ }(Component);
735
+
736
+ _exports.SystemStateComponent = SystemStateComponent;
737
+ SystemStateComponent.isSystemStateComponent = true;
738
+
739
+ var EntityPool = /*#__PURE__*/function (_ObjectPool) {
740
+ _inherits(EntityPool, _ObjectPool);
741
+
742
+ var _super2 = _createSuper(EntityPool);
743
+
744
+ function EntityPool(entityManager, entityClass, initialSize) {
745
+ var _this4;
746
+
747
+ _classCallCheck(this, EntityPool);
748
+
749
+ _this4 = _super2.call(this, entityClass, undefined);
750
+ _this4.entityManager = entityManager;
751
+
752
+ if (typeof initialSize !== "undefined") {
753
+ _this4.expand(initialSize);
754
+ }
755
+
756
+ return _this4;
757
+ }
758
+
759
+ _createClass(EntityPool, [{
760
+ key: "expand",
761
+ value: function expand(count) {
762
+ for (var n = 0; n < count; n++) {
763
+ var clone = new this.T(this.entityManager);
764
+ clone._pool = this;
765
+ this.freeList.push(clone);
766
+ }
767
+
768
+ this.count += count;
769
+ }
770
+ }]);
771
+
772
+ return EntityPool;
773
+ }(ObjectPool);
774
+ /**
775
+ * @private
776
+ * @class EntityManager
777
+ */
778
+
779
+
780
+ var EntityManager = /*#__PURE__*/function () {
781
+ function EntityManager(world) {
782
+ _classCallCheck(this, EntityManager);
783
+
784
+ this.world = world;
785
+ this.componentsManager = world.componentsManager; // All the entities in this instance
786
+
787
+ this._entities = [];
788
+ this._nextEntityId = 0;
789
+ this._entitiesByNames = {};
790
+ this._queryManager = new QueryManager(this);
791
+ this.eventDispatcher = new EventDispatcher();
792
+ this._entityPool = new EntityPool(this, this.world.options.entityClass, this.world.options.entityPoolSize); // Deferred deletion
793
+
794
+ this.entitiesWithComponentsToRemove = [];
795
+ this.entitiesToRemove = [];
796
+ this.deferredRemovalEnabled = true;
797
+ }
798
+
799
+ _createClass(EntityManager, [{
800
+ key: "getEntityByName",
801
+ value: function getEntityByName(name) {
802
+ return this._entitiesByNames[name];
803
+ }
804
+ /**
805
+ * Create a new entity
806
+ */
807
+
808
+ }, {
809
+ key: "createEntity",
810
+ value: function createEntity(name) {
811
+ var entity = this._entityPool.acquire();
812
+
813
+ entity.alive = true;
814
+ entity.name = name || "";
815
+
816
+ if (name) {
817
+ if (this._entitiesByNames[name]) {
818
+ console.warn("Entity name '".concat(name, "' already exist"));
819
+ } else {
820
+ this._entitiesByNames[name] = entity;
821
+ }
822
+ }
823
+
824
+ this._entities.push(entity);
825
+
826
+ this.eventDispatcher.dispatchEvent(ENTITY_CREATED, entity);
827
+ return entity;
828
+ } // COMPONENTS
829
+
830
+ /**
831
+ * Add a component to an entity
832
+ * @param {Entity} entity Entity where the component will be added
833
+ * @param {Component} Component Component to be added to the entity
834
+ * @param {Object} values Optional values to replace the default attributes
835
+ */
836
+
837
+ }, {
838
+ key: "entityAddComponent",
839
+ value: function entityAddComponent(entity, Component, values) {
840
+ // @todo Probably define Component._typeId with a default value and avoid using typeof
841
+ if (typeof Component._typeId === "undefined" && !this.world.componentsManager._ComponentsMap[Component._typeId]) {
842
+ throw new Error("Attempted to add unregistered component \"".concat(Component.getName(), "\""));
843
+ }
844
+
845
+ if (~entity._ComponentTypes.indexOf(Component)) {
846
+ {
847
+ console.warn("Component type already exists on entity.", entity, Component.getName());
848
+ }
849
+ return;
850
+ }
851
+
852
+ entity._ComponentTypes.push(Component);
853
+
854
+ if (Component.__proto__ === SystemStateComponent) {
855
+ entity.numStateComponents++;
856
+ }
857
+
858
+ var componentPool = this.world.componentsManager.getComponentsPool(Component);
859
+ var component = componentPool ? componentPool.acquire() : new Component(values);
860
+
861
+ if (componentPool && values) {
862
+ component.copy(values);
863
+ }
864
+
865
+ entity._components[Component._typeId] = component;
866
+
867
+ this._queryManager.onEntityComponentAdded(entity, Component);
868
+
869
+ this.world.componentsManager.componentAddedToEntity(Component);
870
+ this.eventDispatcher.dispatchEvent(COMPONENT_ADDED, entity, Component);
871
+ }
872
+ /**
873
+ * Remove a component from an entity
874
+ * @param {Entity} entity Entity which will get removed the component
875
+ * @param {*} Component Component to remove from the entity
876
+ * @param {Bool} immediately If you want to remove the component immediately instead of deferred (Default is false)
877
+ */
878
+
879
+ }, {
880
+ key: "entityRemoveComponent",
881
+ value: function entityRemoveComponent(entity, Component, immediately) {
882
+ var index = entity._ComponentTypes.indexOf(Component);
883
+
884
+ if (!~index) return;
885
+ this.eventDispatcher.dispatchEvent(COMPONENT_REMOVE, entity, Component);
886
+
887
+ if (immediately) {
888
+ this._entityRemoveComponentSync(entity, Component, index);
889
+ } else {
890
+ if (entity._ComponentTypesToRemove.length === 0) this.entitiesWithComponentsToRemove.push(entity);
891
+
892
+ entity._ComponentTypes.splice(index, 1);
893
+
894
+ entity._ComponentTypesToRemove.push(Component);
895
+
896
+ entity._componentsToRemove[Component._typeId] = entity._components[Component._typeId];
897
+ delete entity._components[Component._typeId];
898
+ } // Check each indexed query to see if we need to remove it
899
+
900
+
901
+ this._queryManager.onEntityComponentRemoved(entity, Component);
902
+
903
+ if (Component.__proto__ === SystemStateComponent) {
904
+ entity.numStateComponents--; // Check if the entity was a ghost waiting for the last system state component to be removed
905
+
906
+ if (entity.numStateComponents === 0 && !entity.alive) {
907
+ entity.remove();
908
+ }
909
+ }
910
+ }
911
+ }, {
912
+ key: "_entityRemoveComponentSync",
913
+ value: function _entityRemoveComponentSync(entity, Component, index) {
914
+ // Remove T listing on entity and property ref, then free the component.
915
+ entity._ComponentTypes.splice(index, 1);
916
+
917
+ var component = entity._components[Component._typeId];
918
+ delete entity._components[Component._typeId];
919
+ component.dispose();
920
+ this.world.componentsManager.componentRemovedFromEntity(Component);
921
+ }
922
+ /**
923
+ * Remove all the components from an entity
924
+ * @param {Entity} entity Entity from which the components will be removed
925
+ */
926
+
927
+ }, {
928
+ key: "entityRemoveAllComponents",
929
+ value: function entityRemoveAllComponents(entity, immediately) {
930
+ var Components = entity._ComponentTypes;
931
+
932
+ for (var j = Components.length - 1; j >= 0; j--) {
933
+ if (Components[j].__proto__ !== SystemStateComponent) this.entityRemoveComponent(entity, Components[j], immediately);
934
+ }
935
+ }
936
+ /**
937
+ * Remove the entity from this manager. It will clear also its components
938
+ * @param {Entity} entity Entity to remove from the manager
939
+ * @param {Bool} immediately If you want to remove the component immediately instead of deferred (Default is false)
940
+ */
941
+
942
+ }, {
943
+ key: "removeEntity",
944
+ value: function removeEntity(entity, immediately) {
945
+ var index = this._entities.indexOf(entity);
946
+
947
+ if (!~index) throw new Error("Tried to remove entity not in list");
948
+ entity.alive = false;
949
+ this.entityRemoveAllComponents(entity, immediately);
950
+
951
+ if (entity.numStateComponents === 0) {
952
+ // Remove from entity list
953
+ this.eventDispatcher.dispatchEvent(ENTITY_REMOVED, entity);
954
+
955
+ this._queryManager.onEntityRemoved(entity);
956
+
957
+ if (immediately === true) {
958
+ this._releaseEntity(entity, index);
959
+ } else {
960
+ this.entitiesToRemove.push(entity);
961
+ }
962
+ }
963
+ }
964
+ }, {
965
+ key: "_releaseEntity",
966
+ value: function _releaseEntity(entity, index) {
967
+ this._entities.splice(index, 1);
968
+
969
+ if (this._entitiesByNames[entity.name]) {
970
+ delete this._entitiesByNames[entity.name];
971
+ }
972
+
973
+ entity._pool.release(entity);
974
+ }
975
+ /**
976
+ * Remove all entities from this manager
977
+ */
978
+
979
+ }, {
980
+ key: "removeAllEntities",
981
+ value: function removeAllEntities() {
982
+ for (var i = this._entities.length - 1; i >= 0; i--) {
983
+ this.removeEntity(this._entities[i]);
984
+ }
985
+ }
986
+ }, {
987
+ key: "processDeferredRemoval",
988
+ value: function processDeferredRemoval() {
989
+ if (!this.deferredRemovalEnabled) {
990
+ return;
991
+ }
992
+
993
+ for (var i = 0; i < this.entitiesToRemove.length; i++) {
994
+ var entity = this.entitiesToRemove[i];
995
+
996
+ var index = this._entities.indexOf(entity);
997
+
998
+ this._releaseEntity(entity, index);
999
+ }
1000
+
1001
+ this.entitiesToRemove.length = 0;
1002
+
1003
+ for (var _i = 0; _i < this.entitiesWithComponentsToRemove.length; _i++) {
1004
+ var _entity = this.entitiesWithComponentsToRemove[_i];
1005
+
1006
+ while (_entity._ComponentTypesToRemove.length > 0) {
1007
+ var _Component2 = _entity._ComponentTypesToRemove.pop();
1008
+
1009
+ var component = _entity._componentsToRemove[_Component2._typeId];
1010
+ delete _entity._componentsToRemove[_Component2._typeId];
1011
+ component.dispose();
1012
+ this.world.componentsManager.componentRemovedFromEntity(_Component2); //this._entityRemoveComponentSync(entity, Component, index);
1013
+ }
1014
+ }
1015
+
1016
+ this.entitiesWithComponentsToRemove.length = 0;
1017
+ }
1018
+ /**
1019
+ * Get a query based on a list of components
1020
+ * @param {Array(Component)} Components List of components that will form the query
1021
+ */
1022
+
1023
+ }, {
1024
+ key: "queryComponents",
1025
+ value: function queryComponents(Components) {
1026
+ return this._queryManager.getQuery(Components);
1027
+ } // EXTRAS
1028
+
1029
+ /**
1030
+ * Return number of entities
1031
+ */
1032
+
1033
+ }, {
1034
+ key: "count",
1035
+ value: function count() {
1036
+ return this._entities.length;
1037
+ }
1038
+ /**
1039
+ * Return some stats
1040
+ */
1041
+
1042
+ }, {
1043
+ key: "stats",
1044
+ value: function stats() {
1045
+ var stats = {
1046
+ numEntities: this._entities.length,
1047
+ numQueries: Object.keys(this._queryManager._queries).length,
1048
+ queries: this._queryManager.stats(),
1049
+ numComponentPool: Object.keys(this.componentsManager._componentPool).length,
1050
+ componentPool: {},
1051
+ eventDispatcher: this.eventDispatcher.stats
1052
+ };
1053
+
1054
+ for (var ecsyComponentId in this.componentsManager._componentPool) {
1055
+ var pool = this.componentsManager._componentPool[ecsyComponentId];
1056
+ stats.componentPool[pool.T.getName()] = {
1057
+ used: pool.totalUsed(),
1058
+ size: pool.count
1059
+ };
1060
+ }
1061
+
1062
+ return stats;
1063
+ }
1064
+ }]);
1065
+
1066
+ return EntityManager;
1067
+ }();
1068
+
1069
+ var ENTITY_CREATED = "EntityManager#ENTITY_CREATE";
1070
+ var ENTITY_REMOVED = "EntityManager#ENTITY_REMOVED";
1071
+ var COMPONENT_ADDED = "EntityManager#COMPONENT_ADDED";
1072
+ var COMPONENT_REMOVE = "EntityManager#COMPONENT_REMOVE";
1073
+
1074
+ var ComponentManager = /*#__PURE__*/function () {
1075
+ function ComponentManager() {
1076
+ _classCallCheck(this, ComponentManager);
1077
+
1078
+ this.Components = [];
1079
+ this._ComponentsMap = {};
1080
+ this._componentPool = {};
1081
+ this.numComponents = {};
1082
+ this.nextComponentId = 0;
1083
+ }
1084
+
1085
+ _createClass(ComponentManager, [{
1086
+ key: "hasComponent",
1087
+ value: function hasComponent(Component) {
1088
+ return this.Components.indexOf(Component) !== -1;
1089
+ }
1090
+ }, {
1091
+ key: "registerComponent",
1092
+ value: function registerComponent(Component, objectPool) {
1093
+ if (this.Components.indexOf(Component) !== -1) {
1094
+ console.warn("Component type: '".concat(Component.getName(), "' already registered."));
1095
+ return;
1096
+ }
1097
+
1098
+ var schema = Component.schema;
1099
+
1100
+ if (!schema) {
1101
+ throw new Error("Component \"".concat(Component.getName(), "\" has no schema property."));
1102
+ }
1103
+
1104
+ for (var propName in schema) {
1105
+ var prop = schema[propName];
1106
+
1107
+ if (!prop.type) {
1108
+ throw new Error("Invalid schema for component \"".concat(Component.getName(), "\". Missing type for \"").concat(propName, "\" property."));
1109
+ }
1110
+ }
1111
+
1112
+ Component._typeId = this.nextComponentId++;
1113
+ this.Components.push(Component);
1114
+ this._ComponentsMap[Component._typeId] = Component;
1115
+ this.numComponents[Component._typeId] = 0;
1116
+
1117
+ if (objectPool === undefined) {
1118
+ objectPool = new ObjectPool(Component);
1119
+ } else if (objectPool === false) {
1120
+ objectPool = undefined;
1121
+ }
1122
+
1123
+ this._componentPool[Component._typeId] = objectPool;
1124
+ }
1125
+ }, {
1126
+ key: "componentAddedToEntity",
1127
+ value: function componentAddedToEntity(Component) {
1128
+ this.numComponents[Component._typeId]++;
1129
+ }
1130
+ }, {
1131
+ key: "componentRemovedFromEntity",
1132
+ value: function componentRemovedFromEntity(Component) {
1133
+ this.numComponents[Component._typeId]--;
1134
+ }
1135
+ }, {
1136
+ key: "getComponentsPool",
1137
+ value: function getComponentsPool(Component) {
1138
+ return this._componentPool[Component._typeId];
1139
+ }
1140
+ }]);
1141
+
1142
+ return ComponentManager;
1143
+ }();
1144
+
1145
+ var Version = "0.3.1";
1146
+ _exports.Version = Version;
1147
+ var proxyMap = new WeakMap();
1148
+ var proxyHandler = {
1149
+ set: function set(target, prop) {
1150
+ throw new Error("Tried to write to \"".concat(target.constructor.getName(), "#").concat(String(prop), "\" on immutable component. Use .getMutableComponent() to modify a component."));
1151
+ }
1152
+ };
1153
+
1154
+ function wrapImmutableComponent(T, component) {
1155
+ if (component === undefined) {
1156
+ return undefined;
1157
+ }
1158
+
1159
+ var wrappedComponent = proxyMap.get(component);
1160
+
1161
+ if (!wrappedComponent) {
1162
+ wrappedComponent = new Proxy(component, proxyHandler);
1163
+ proxyMap.set(component, wrappedComponent);
1164
+ }
1165
+
1166
+ return wrappedComponent;
1167
+ }
1168
+
1169
+ var Entity = /*#__PURE__*/function () {
1170
+ function Entity(entityManager) {
1171
+ _classCallCheck(this, Entity);
1172
+
1173
+ this._entityManager = entityManager || null; // Unique ID for this entity
1174
+
1175
+ this.id = entityManager._nextEntityId++; // List of components types the entity has
1176
+
1177
+ this._ComponentTypes = []; // Instance of the components
1178
+
1179
+ this._components = {};
1180
+ this._componentsToRemove = {}; // Queries where the entity is added
1181
+
1182
+ this.queries = []; // Used for deferred removal
1183
+
1184
+ this._ComponentTypesToRemove = [];
1185
+ this.alive = false; //if there are state components on a entity, it can't be removed completely
1186
+
1187
+ this.numStateComponents = 0;
1188
+ } // COMPONENTS
1189
+
1190
+
1191
+ _createClass(Entity, [{
1192
+ key: "getComponent",
1193
+ value: function getComponent(Component, includeRemoved) {
1194
+ var component = this._components[Component._typeId];
1195
+
1196
+ if (!component && includeRemoved === true) {
1197
+ component = this._componentsToRemove[Component._typeId];
1198
+ }
1199
+
1200
+ return wrapImmutableComponent(Component, component);
1201
+ }
1202
+ }, {
1203
+ key: "getRemovedComponent",
1204
+ value: function getRemovedComponent(Component) {
1205
+ var component = this._componentsToRemove[Component._typeId];
1206
+ return wrapImmutableComponent(Component, component);
1207
+ }
1208
+ }, {
1209
+ key: "getComponents",
1210
+ value: function getComponents() {
1211
+ return this._components;
1212
+ }
1213
+ }, {
1214
+ key: "getComponentsToRemove",
1215
+ value: function getComponentsToRemove() {
1216
+ return this._componentsToRemove;
1217
+ }
1218
+ }, {
1219
+ key: "getComponentTypes",
1220
+ value: function getComponentTypes() {
1221
+ return this._ComponentTypes;
1222
+ }
1223
+ }, {
1224
+ key: "getMutableComponent",
1225
+ value: function getMutableComponent(Component) {
1226
+ var component = this._components[Component._typeId];
1227
+
1228
+ if (!component) {
1229
+ return;
1230
+ }
1231
+
1232
+ for (var i = 0; i < this.queries.length; i++) {
1233
+ var query = this.queries[i]; // @todo accelerate this check. Maybe having query._Components as an object
1234
+ // @todo add Not components
1235
+
1236
+ if (query.reactive && query.Components.indexOf(Component) !== -1) {
1237
+ query.eventDispatcher.dispatchEvent(Query.prototype.COMPONENT_CHANGED, this, component);
1238
+ }
1239
+ }
1240
+
1241
+ return component;
1242
+ }
1243
+ }, {
1244
+ key: "addComponent",
1245
+ value: function addComponent(Component, values) {
1246
+ this._entityManager.entityAddComponent(this, Component, values);
1247
+
1248
+ return this;
1249
+ }
1250
+ }, {
1251
+ key: "removeComponent",
1252
+ value: function removeComponent(Component, forceImmediate) {
1253
+ this._entityManager.entityRemoveComponent(this, Component, forceImmediate);
1254
+
1255
+ return this;
1256
+ }
1257
+ }, {
1258
+ key: "hasComponent",
1259
+ value: function hasComponent(Component, includeRemoved) {
1260
+ return !!~this._ComponentTypes.indexOf(Component) || includeRemoved === true && this.hasRemovedComponent(Component);
1261
+ }
1262
+ }, {
1263
+ key: "hasRemovedComponent",
1264
+ value: function hasRemovedComponent(Component) {
1265
+ return !!~this._ComponentTypesToRemove.indexOf(Component);
1266
+ }
1267
+ }, {
1268
+ key: "hasAllComponents",
1269
+ value: function hasAllComponents(Components) {
1270
+ for (var i = 0; i < Components.length; i++) {
1271
+ if (!this.hasComponent(Components[i])) return false;
1272
+ }
1273
+
1274
+ return true;
1275
+ }
1276
+ }, {
1277
+ key: "hasAnyComponents",
1278
+ value: function hasAnyComponents(Components) {
1279
+ for (var i = 0; i < Components.length; i++) {
1280
+ if (this.hasComponent(Components[i])) return true;
1281
+ }
1282
+
1283
+ return false;
1284
+ }
1285
+ }, {
1286
+ key: "removeAllComponents",
1287
+ value: function removeAllComponents(forceImmediate) {
1288
+ return this._entityManager.entityRemoveAllComponents(this, forceImmediate);
1289
+ }
1290
+ }, {
1291
+ key: "copy",
1292
+ value: function copy(src) {
1293
+ // TODO: This can definitely be optimized
1294
+ for (var ecsyComponentId in src._components) {
1295
+ var srcComponent = src._components[ecsyComponentId];
1296
+ this.addComponent(srcComponent.constructor);
1297
+ var component = this.getComponent(srcComponent.constructor);
1298
+ component.copy(srcComponent);
1299
+ }
1300
+
1301
+ return this;
1302
+ }
1303
+ }, {
1304
+ key: "clone",
1305
+ value: function clone() {
1306
+ return new Entity(this._entityManager).copy(this);
1307
+ }
1308
+ }, {
1309
+ key: "reset",
1310
+ value: function reset() {
1311
+ this.id = this._entityManager._nextEntityId++;
1312
+ this._ComponentTypes.length = 0;
1313
+ this.queries.length = 0;
1314
+
1315
+ for (var ecsyComponentId in this._components) {
1316
+ delete this._components[ecsyComponentId];
1317
+ }
1318
+ }
1319
+ }, {
1320
+ key: "remove",
1321
+ value: function remove(forceImmediate) {
1322
+ return this._entityManager.removeEntity(this, forceImmediate);
1323
+ }
1324
+ }]);
1325
+
1326
+ return Entity;
1327
+ }();
1328
+
1329
+ _exports._Entity = Entity;
1330
+ var DEFAULT_OPTIONS = {
1331
+ entityPoolSize: 0,
1332
+ entityClass: Entity
1333
+ };
1334
+
1335
+ var World = /*#__PURE__*/function () {
1336
+ function World() {
1337
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1338
+
1339
+ _classCallCheck(this, World);
1340
+
1341
+ this.options = Object.assign({}, DEFAULT_OPTIONS, options);
1342
+ this.componentsManager = new ComponentManager(this);
1343
+ this.entityManager = new EntityManager(this);
1344
+ this.systemManager = new SystemManager(this);
1345
+ this.enabled = true;
1346
+ this.eventQueues = {};
1347
+
1348
+ if (hasWindow && typeof CustomEvent !== "undefined") {
1349
+ var event = new CustomEvent("ecsy-world-created", {
1350
+ detail: {
1351
+ world: this,
1352
+ version: Version
1353
+ }
1354
+ });
1355
+ window.dispatchEvent(event);
1356
+ }
1357
+
1358
+ this.lastTime = now() / 1000;
1359
+ }
1360
+
1361
+ _createClass(World, [{
1362
+ key: "registerComponent",
1363
+ value: function registerComponent(Component, objectPool) {
1364
+ this.componentsManager.registerComponent(Component, objectPool);
1365
+ return this;
1366
+ }
1367
+ }, {
1368
+ key: "registerSystem",
1369
+ value: function registerSystem(System, attributes) {
1370
+ this.systemManager.registerSystem(System, attributes);
1371
+ return this;
1372
+ }
1373
+ }, {
1374
+ key: "hasRegisteredComponent",
1375
+ value: function hasRegisteredComponent(Component) {
1376
+ return this.componentsManager.hasComponent(Component);
1377
+ }
1378
+ }, {
1379
+ key: "unregisterSystem",
1380
+ value: function unregisterSystem(System) {
1381
+ this.systemManager.unregisterSystem(System);
1382
+ return this;
1383
+ }
1384
+ }, {
1385
+ key: "getSystem",
1386
+ value: function getSystem(SystemClass) {
1387
+ return this.systemManager.getSystem(SystemClass);
1388
+ }
1389
+ }, {
1390
+ key: "getSystems",
1391
+ value: function getSystems() {
1392
+ return this.systemManager.getSystems();
1393
+ }
1394
+ }, {
1395
+ key: "execute",
1396
+ value: function execute(delta, time) {
1397
+ if (!delta) {
1398
+ time = now() / 1000;
1399
+ delta = time - this.lastTime;
1400
+ this.lastTime = time;
1401
+ }
1402
+
1403
+ if (this.enabled) {
1404
+ this.systemManager.execute(delta, time);
1405
+ this.entityManager.processDeferredRemoval();
1406
+ }
1407
+ }
1408
+ }, {
1409
+ key: "stop",
1410
+ value: function stop() {
1411
+ this.enabled = false;
1412
+ }
1413
+ }, {
1414
+ key: "play",
1415
+ value: function play() {
1416
+ this.enabled = true;
1417
+ }
1418
+ }, {
1419
+ key: "createEntity",
1420
+ value: function createEntity(name) {
1421
+ return this.entityManager.createEntity(name);
1422
+ }
1423
+ }, {
1424
+ key: "stats",
1425
+ value: function stats() {
1426
+ var stats = {
1427
+ entities: this.entityManager.stats(),
1428
+ system: this.systemManager.stats()
1429
+ };
1430
+ return stats;
1431
+ }
1432
+ }]);
1433
+
1434
+ return World;
1435
+ }();
1436
+
1437
+ _exports.World = World;
1438
+
1439
+ var System = /*#__PURE__*/function () {
1440
+ function System(world, attributes) {
1441
+ var _this5 = this;
1442
+
1443
+ _classCallCheck(this, System);
1444
+
1445
+ this.world = world;
1446
+ this.enabled = true; // @todo Better naming :)
1447
+
1448
+ this._queries = {};
1449
+ this.queries = {};
1450
+ this.priority = 0; // Used for stats
1451
+
1452
+ this.executeTime = 0;
1453
+
1454
+ if (attributes && attributes.priority) {
1455
+ this.priority = attributes.priority;
1456
+ }
1457
+
1458
+ this._mandatoryQueries = [];
1459
+ this.initialized = true;
1460
+
1461
+ if (this.constructor.queries) {
1462
+ var _loop = function _loop() {
1463
+ queryConfig = _this5.constructor.queries[queryName];
1464
+ Components = queryConfig.components;
1465
+
1466
+ if (!Components || Components.length === 0) {
1467
+ throw new Error("'components' attribute can't be empty in a query");
1468
+ } // Detect if the components have already been registered
1469
+
1470
+
1471
+ var unregisteredComponents = Components.filter(function (Component) {
1472
+ return !componentRegistered(Component);
1473
+ });
1474
+
1475
+ if (unregisteredComponents.length > 0) {
1476
+ throw new Error("Tried to create a query '".concat(_this5.constructor.name, ".").concat(queryName, "' with unregistered components: [").concat(unregisteredComponents.map(function (c) {
1477
+ return c.getName();
1478
+ }).join(", "), "]"));
1479
+ }
1480
+
1481
+ query = _this5.world.entityManager.queryComponents(Components);
1482
+ _this5._queries[queryName] = query;
1483
+
1484
+ if (queryConfig.mandatory === true) {
1485
+ _this5._mandatoryQueries.push(query);
1486
+ }
1487
+
1488
+ _this5.queries[queryName] = {
1489
+ results: query.entities
1490
+ }; // Reactive configuration added/removed/changed
1491
+
1492
+ validEvents = ["added", "removed", "changed"];
1493
+ var eventMapping = {
1494
+ added: Query.prototype.ENTITY_ADDED,
1495
+ removed: Query.prototype.ENTITY_REMOVED,
1496
+ changed: Query.prototype.COMPONENT_CHANGED // Query.prototype.ENTITY_CHANGED
1497
+
1498
+ };
1499
+
1500
+ if (queryConfig.listen) {
1501
+ validEvents.forEach(function (eventName) {
1502
+ if (!_this5.execute) {
1503
+ console.warn("System '".concat(_this5.getName(), "' has defined listen events (").concat(validEvents.join(", "), ") for query '").concat(queryName, "' but it does not implement the 'execute' method."));
1504
+ } // Is the event enabled on this system's query?
1505
+
1506
+
1507
+ if (queryConfig.listen[eventName]) {
1508
+ var event = queryConfig.listen[eventName];
1509
+
1510
+ if (eventName === "changed") {
1511
+ query.reactive = true;
1512
+
1513
+ if (event === true) {
1514
+ // Any change on the entity from the components in the query
1515
+ var eventList = _this5.queries[queryName][eventName] = [];
1516
+ query.eventDispatcher.addEventListener(Query.prototype.COMPONENT_CHANGED, function (entity) {
1517
+ // Avoid duplicates
1518
+ if (eventList.indexOf(entity) === -1) {
1519
+ eventList.push(entity);
1520
+ }
1521
+ });
1522
+ } else if (Array.isArray(event)) {
1523
+ var _eventList = _this5.queries[queryName][eventName] = [];
1524
+
1525
+ query.eventDispatcher.addEventListener(Query.prototype.COMPONENT_CHANGED, function (entity, changedComponent) {
1526
+ // Avoid duplicates
1527
+ if (event.indexOf(changedComponent.constructor) !== -1 && _eventList.indexOf(entity) === -1) {
1528
+ _eventList.push(entity);
1529
+ }
1530
+ });
1531
+ }
1532
+ } else {
1533
+ var _eventList2 = _this5.queries[queryName][eventName] = [];
1534
+
1535
+ query.eventDispatcher.addEventListener(eventMapping[eventName], function (entity) {
1536
+ // @fixme overhead?
1537
+ if (_eventList2.indexOf(entity) === -1) _eventList2.push(entity);
1538
+ });
1539
+ }
1540
+ }
1541
+ });
1542
+ }
1543
+ };
1544
+
1545
+ for (var queryName in this.constructor.queries) {
1546
+ var queryConfig;
1547
+ var Components;
1548
+ var query;
1549
+ var validEvents;
1550
+
1551
+ _loop();
1552
+ }
1553
+ }
1554
+ }
1555
+
1556
+ _createClass(System, [{
1557
+ key: "canExecute",
1558
+ value: function canExecute() {
1559
+ if (this._mandatoryQueries.length === 0) return true;
1560
+
1561
+ for (var i = 0; i < this._mandatoryQueries.length; i++) {
1562
+ var query = this._mandatoryQueries[i];
1563
+
1564
+ if (query.entities.length === 0) {
1565
+ return false;
1566
+ }
1567
+ }
1568
+
1569
+ return true;
1570
+ }
1571
+ }, {
1572
+ key: "getName",
1573
+ value: function getName() {
1574
+ return this.constructor.getName();
1575
+ }
1576
+ }, {
1577
+ key: "stop",
1578
+ value: function stop() {
1579
+ this.executeTime = 0;
1580
+ this.enabled = false;
1581
+ }
1582
+ }, {
1583
+ key: "play",
1584
+ value: function play() {
1585
+ this.enabled = true;
1586
+ } // @question rename to clear queues?
1587
+
1588
+ }, {
1589
+ key: "clearEvents",
1590
+ value: function clearEvents() {
1591
+ for (var queryName in this.queries) {
1592
+ var query = this.queries[queryName];
1593
+
1594
+ if (query.added) {
1595
+ query.added.length = 0;
1596
+ }
1597
+
1598
+ if (query.removed) {
1599
+ query.removed.length = 0;
1600
+ }
1601
+
1602
+ if (query.changed) {
1603
+ if (Array.isArray(query.changed)) {
1604
+ query.changed.length = 0;
1605
+ } else {
1606
+ for (var name in query.changed) {
1607
+ query.changed[name].length = 0;
1608
+ }
1609
+ }
1610
+ }
1611
+ }
1612
+ }
1613
+ }, {
1614
+ key: "toJSON",
1615
+ value: function toJSON() {
1616
+ var _this6 = this;
1617
+
1618
+ var json = {
1619
+ name: this.getName(),
1620
+ enabled: this.enabled,
1621
+ executeTime: this.executeTime,
1622
+ priority: this.priority,
1623
+ queries: {}
1624
+ };
1625
+
1626
+ if (this.constructor.queries) {
1627
+ var queries = this.constructor.queries;
1628
+
1629
+ var _loop2 = function _loop2(queryName) {
1630
+ var query = _this6.queries[queryName];
1631
+ var queryDefinition = queries[queryName];
1632
+ var jsonQuery = json.queries[queryName] = {
1633
+ key: _this6._queries[queryName].key
1634
+ };
1635
+ jsonQuery.mandatory = queryDefinition.mandatory === true;
1636
+ jsonQuery.reactive = queryDefinition.listen && (queryDefinition.listen.added === true || queryDefinition.listen.removed === true || queryDefinition.listen.changed === true || Array.isArray(queryDefinition.listen.changed));
1637
+
1638
+ if (jsonQuery.reactive) {
1639
+ jsonQuery.listen = {};
1640
+ var methods = ["added", "removed", "changed"];
1641
+ methods.forEach(function (method) {
1642
+ if (query[method]) {
1643
+ jsonQuery.listen[method] = {
1644
+ entities: query[method].length
1645
+ };
1646
+ }
1647
+ });
1648
+ }
1649
+ };
1650
+
1651
+ for (var queryName in queries) {
1652
+ _loop2(queryName);
1653
+ }
1654
+ }
1655
+
1656
+ return json;
1657
+ }
1658
+ }]);
1659
+
1660
+ return System;
1661
+ }();
1662
+
1663
+ _exports.System = System;
1664
+ System.isSystem = true;
1665
+
1666
+ System.getName = function () {
1667
+ return this.displayName || this.name;
1668
+ };
1669
+
1670
+ function Not(Component) {
1671
+ return {
1672
+ operator: "not",
1673
+ Component: Component
1674
+ };
1675
+ }
1676
+
1677
+ var TagComponent = /*#__PURE__*/function (_Component3) {
1678
+ _inherits(TagComponent, _Component3);
1679
+
1680
+ var _super3 = _createSuper(TagComponent);
1681
+
1682
+ function TagComponent() {
1683
+ _classCallCheck(this, TagComponent);
1684
+
1685
+ return _super3.call(this, false);
1686
+ }
1687
+
1688
+ return _createClass(TagComponent);
1689
+ }(Component);
1690
+
1691
+ _exports.TagComponent = TagComponent;
1692
+ TagComponent.isTagComponent = true;
1693
+
1694
+ var copyValue = function copyValue(src) {
1695
+ return src;
1696
+ };
1697
+
1698
+ _exports.copyValue = copyValue;
1699
+
1700
+ var cloneValue = function cloneValue(src) {
1701
+ return src;
1702
+ };
1703
+
1704
+ _exports.cloneValue = cloneValue;
1705
+
1706
+ var copyArray = function copyArray(src, dest) {
1707
+ if (!src) {
1708
+ return src;
1709
+ }
1710
+
1711
+ if (!dest) {
1712
+ return src.slice();
1713
+ }
1714
+
1715
+ dest.length = 0;
1716
+
1717
+ for (var i = 0; i < src.length; i++) {
1718
+ dest.push(src[i]);
1719
+ }
1720
+
1721
+ return dest;
1722
+ };
1723
+
1724
+ _exports.copyArray = copyArray;
1725
+
1726
+ var cloneArray = function cloneArray(src) {
1727
+ return src && src.slice();
1728
+ };
1729
+
1730
+ _exports.cloneArray = cloneArray;
1731
+
1732
+ var copyJSON = function copyJSON(src) {
1733
+ return JSON.parse(JSON.stringify(src));
1734
+ };
1735
+
1736
+ _exports.copyJSON = copyJSON;
1737
+
1738
+ var cloneJSON = function cloneJSON(src) {
1739
+ return JSON.parse(JSON.stringify(src));
1740
+ };
1741
+
1742
+ _exports.cloneJSON = cloneJSON;
1743
+
1744
+ var copyCopyable = function copyCopyable(src, dest) {
1745
+ if (!src) {
1746
+ return src;
1747
+ }
1748
+
1749
+ if (!dest) {
1750
+ return src.clone();
1751
+ }
1752
+
1753
+ return dest.copy(src);
1754
+ };
1755
+
1756
+ _exports.copyCopyable = copyCopyable;
1757
+
1758
+ var cloneClonable = function cloneClonable(src) {
1759
+ return src && src.clone();
1760
+ };
1761
+
1762
+ _exports.cloneClonable = cloneClonable;
1763
+
1764
+ function createType(typeDefinition) {
1765
+ var mandatoryProperties = ["name", "default", "copy", "clone"];
1766
+ var undefinedProperties = mandatoryProperties.filter(function (p) {
1767
+ return !typeDefinition.hasOwnProperty(p);
1768
+ });
1769
+
1770
+ if (undefinedProperties.length > 0) {
1771
+ throw new Error("createType expects a type definition with the following properties: ".concat(undefinedProperties.join(", ")));
1772
+ }
1773
+
1774
+ typeDefinition.isType = true;
1775
+ return typeDefinition;
1776
+ }
1777
+ /**
1778
+ * Standard types
1779
+ */
1780
+
1781
+
1782
+ var Types = {
1783
+ Number: createType({
1784
+ name: "Number",
1785
+ default: 0,
1786
+ copy: copyValue,
1787
+ clone: cloneValue
1788
+ }),
1789
+ Boolean: createType({
1790
+ name: "Boolean",
1791
+ default: false,
1792
+ copy: copyValue,
1793
+ clone: cloneValue
1794
+ }),
1795
+ String: createType({
1796
+ name: "String",
1797
+ default: "",
1798
+ copy: copyValue,
1799
+ clone: cloneValue
1800
+ }),
1801
+ Array: createType({
1802
+ name: "Array",
1803
+ default: [],
1804
+ copy: copyArray,
1805
+ clone: cloneArray
1806
+ }),
1807
+ Ref: createType({
1808
+ name: "Ref",
1809
+ default: undefined,
1810
+ copy: copyValue,
1811
+ clone: cloneValue
1812
+ }),
1813
+ JSON: createType({
1814
+ name: "JSON",
1815
+ default: null,
1816
+ copy: copyJSON,
1817
+ clone: cloneJSON
1818
+ })
1819
+ };
1820
+ _exports.Types = Types;
1821
+
1822
+ function generateId(length) {
1823
+ var result = "";
1824
+ var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1825
+ var charactersLength = characters.length;
1826
+
1827
+ for (var i = 0; i < length; i++) {
1828
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
1829
+ }
1830
+
1831
+ return result;
1832
+ }
1833
+
1834
+ function injectScript(src, onLoad) {
1835
+ var script = document.createElement("script"); // @todo Use link to the ecsy-devtools repo?
1836
+
1837
+ script.src = src;
1838
+ script.onload = onLoad;
1839
+ (document.head || document.documentElement).appendChild(script);
1840
+ }
1841
+ /* global Peer */
1842
+
1843
+
1844
+ function hookConsoleAndErrors(connection) {
1845
+ var wrapFunctions = ["error", "warning", "log"];
1846
+ wrapFunctions.forEach(function (key) {
1847
+ if (typeof console[key] === "function") {
1848
+ var fn = console[key].bind(console);
1849
+
1850
+ console[key] = function () {
1851
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1852
+ args[_key] = arguments[_key];
1853
+ }
1854
+
1855
+ connection.send({
1856
+ method: "console",
1857
+ type: key,
1858
+ args: JSON.stringify(args)
1859
+ });
1860
+ return fn.apply(null, args);
1861
+ };
1862
+ }
1863
+ });
1864
+ window.addEventListener("error", function (error) {
1865
+ connection.send({
1866
+ method: "error",
1867
+ error: JSON.stringify({
1868
+ message: error.error.message,
1869
+ stack: error.error.stack
1870
+ })
1871
+ });
1872
+ });
1873
+ }
1874
+
1875
+ function includeRemoteIdHTML(remoteId) {
1876
+ var infoDiv = document.createElement("div");
1877
+ infoDiv.style.cssText = "\n align-items: center;\n background-color: #333;\n color: #aaa;\n display:flex;\n font-family: Arial;\n font-size: 1.1em;\n height: 40px;\n justify-content: center;\n left: 0;\n opacity: 0.9;\n position: absolute;\n right: 0;\n text-align: center;\n top: 0;\n ";
1878
+ infoDiv.innerHTML = "Open ECSY devtools to connect to this page using the code:&nbsp;<b style=\"color: #fff\">".concat(remoteId, "</b>&nbsp;<button onClick=\"generateNewCode()\">Generate new code</button>");
1879
+ document.body.appendChild(infoDiv);
1880
+ return infoDiv;
1881
+ }
1882
+
1883
+ function enableRemoteDevtools(remoteId) {
1884
+ if (!hasWindow) {
1885
+ console.warn("Remote devtools not available outside the browser");
1886
+ return;
1887
+ }
1888
+
1889
+ window.generateNewCode = function () {
1890
+ window.localStorage.clear();
1891
+ remoteId = generateId(6);
1892
+ window.localStorage.setItem("ecsyRemoteId", remoteId);
1893
+ window.location.reload(false);
1894
+ };
1895
+
1896
+ remoteId = remoteId || window.localStorage.getItem("ecsyRemoteId");
1897
+
1898
+ if (!remoteId) {
1899
+ remoteId = generateId(6);
1900
+ window.localStorage.setItem("ecsyRemoteId", remoteId);
1901
+ }
1902
+
1903
+ var infoDiv = includeRemoteIdHTML(remoteId);
1904
+ window.__ECSY_REMOTE_DEVTOOLS_INJECTED = true;
1905
+ window.__ECSY_REMOTE_DEVTOOLS = {};
1906
+ var Version = ""; // This is used to collect the worlds created before the communication is being established
1907
+
1908
+ var worldsBeforeLoading = [];
1909
+
1910
+ var onWorldCreated = function onWorldCreated(e) {
1911
+ var world = e.detail.world;
1912
+ Version = e.detail.version;
1913
+ worldsBeforeLoading.push(world);
1914
+ };
1915
+
1916
+ window.addEventListener("ecsy-world-created", onWorldCreated);
1917
+
1918
+ var onLoaded = function onLoaded() {
1919
+ // var peer = new Peer(remoteId);
1920
+ var peer = new Peer(remoteId, {
1921
+ host: "peerjs.ecsy.io",
1922
+ secure: true,
1923
+ port: 443,
1924
+ config: {
1925
+ iceServers: [{
1926
+ url: "stun:stun.l.google.com:19302"
1927
+ }, {
1928
+ url: "stun:stun1.l.google.com:19302"
1929
+ }, {
1930
+ url: "stun:stun2.l.google.com:19302"
1931
+ }, {
1932
+ url: "stun:stun3.l.google.com:19302"
1933
+ }, {
1934
+ url: "stun:stun4.l.google.com:19302"
1935
+ }]
1936
+ },
1937
+ debug: 3
1938
+ });
1939
+ peer.on("open", function
1940
+ /* id */
1941
+ () {
1942
+ peer.on("connection", function (connection) {
1943
+ window.__ECSY_REMOTE_DEVTOOLS.connection = connection;
1944
+ connection.on("open", function () {
1945
+ // infoDiv.style.visibility = "hidden";
1946
+ infoDiv.innerHTML = "Connected"; // Receive messages
1947
+
1948
+ connection.on("data", function (data) {
1949
+ if (data.type === "init") {
1950
+ var script = document.createElement("script");
1951
+ script.setAttribute("type", "text/javascript");
1952
+
1953
+ script.onload = function () {
1954
+ script.parentNode.removeChild(script); // Once the script is injected we don't need to listen
1955
+
1956
+ window.removeEventListener("ecsy-world-created", onWorldCreated);
1957
+ worldsBeforeLoading.forEach(function (world) {
1958
+ var event = new CustomEvent("ecsy-world-created", {
1959
+ detail: {
1960
+ world: world,
1961
+ version: Version
1962
+ }
1963
+ });
1964
+ window.dispatchEvent(event);
1965
+ });
1966
+ };
1967
+
1968
+ script.innerHTML = data.script;
1969
+ (document.head || document.documentElement).appendChild(script);
1970
+ script.onload();
1971
+ hookConsoleAndErrors(connection);
1972
+ } else if (data.type === "executeScript") {
1973
+ var value = eval(data.script);
1974
+
1975
+ if (data.returnEval) {
1976
+ connection.send({
1977
+ method: "evalReturn",
1978
+ value: value
1979
+ });
1980
+ }
1981
+ }
1982
+ });
1983
+ });
1984
+ });
1985
+ });
1986
+ }; // Inject PeerJS script
1987
+
1988
+
1989
+ injectScript("https://cdn.jsdelivr.net/npm/peerjs@0.3.20/dist/peer.min.js", onLoaded);
1990
+ }
1991
+
1992
+ if (hasWindow) {
1993
+ var urlParams = new URLSearchParams(window.location.search); // @todo Provide a way to disable it if needed
1994
+
1995
+ if (urlParams.has("enable-remote-devtools")) {
1996
+ enableRemoteDevtools();
1997
+ }
1998
+ }
1999
+ });