rogue-engine-user-scripts.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("rogue-engine"), require("three"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["rogue-engine", "three"], factory);
  6. else if(typeof exports === 'object')
  7. exports["rogue-engine-user-scripts"] = factory(require("rogue-engine"), require("three"));
  8. else
  9. root["rogue-engine-user-scripts"] = factory(root["rogue-engine"], root["three"]);
  10. })(self, function(__WEBPACK_EXTERNAL_MODULE_rogue_engine__, __WEBPACK_EXTERNAL_MODULE_three__) {
  11. return /******/ (() => { // webpackBootstrap
  12. /******/ "use strict";
  13. /******/ var __webpack_modules__ = ({
  14. /***/ "./Assets/Components/DungeonGenerator.re.ts":
  15. /*!**************************************************!*\
  16. !*** ./Assets/Components/DungeonGenerator.re.ts ***!
  17. \**************************************************/
  18. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  19. __webpack_require__.r(__webpack_exports__);
  20. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  21. /* harmony export */ "default": () => (/* binding */ DungeonGenerator)
  22. /* harmony export */ });
  23. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  24. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  25. var __defProp = Object.defineProperty;
  26. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  27. class DungeonGenerator extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  28. awake() {
  29. }
  30. start() {
  31. }
  32. update() {
  33. }
  34. }
  35. __name(DungeonGenerator, "DungeonGenerator");
  36. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(DungeonGenerator);
  37. /***/ }),
  38. /***/ "./Assets/Components/EnemyAI.re.ts":
  39. /*!*****************************************!*\
  40. !*** ./Assets/Components/EnemyAI.re.ts ***!
  41. \*****************************************/
  42. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  43. __webpack_require__.r(__webpack_exports__);
  44. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  45. /* harmony export */ "default": () => (/* binding */ EnemyAI)
  46. /* harmony export */ });
  47. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  48. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  49. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
  50. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
  51. /* harmony import */ var _WorldFPSController_re__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./WorldFPSController.re */ "./Assets/Components/WorldFPSController.re.ts");
  52. var __defProp = Object.defineProperty;
  53. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  54. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  55. var __decorateClass = (decorators, target, key, kind) => {
  56. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  57. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  58. if (decorator = decorators[i])
  59. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  60. if (kind && result)
  61. __defProp(target, key, result);
  62. return result;
  63. };
  64. class EnemyAI extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  65. constructor() {
  66. super(...arguments);
  67. this.movementSpeed = 0.3;
  68. this.attackDistance = 0.3;
  69. this.targetPosition = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
  70. }
  71. awake() {
  72. if (!this.target) {
  73. let gameLogic = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByName("GameLogic");
  74. this.target = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByName("Player") || new three__WEBPACK_IMPORTED_MODULE_1__.Object3D();
  75. this.targetPosition = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.getComponent(_WorldFPSController_re__WEBPACK_IMPORTED_MODULE_2__["default"], gameLogic)?.characterOffset.position || this.target.position;
  76. } else {
  77. this.targetPosition = this.target.position;
  78. }
  79. }
  80. start() {
  81. }
  82. update() {
  83. const deltaTime = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.deltaTime;
  84. this.object3d.lookAt(this.target.position);
  85. let movementVector = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, 1);
  86. if (this.object3d.position.distanceTo(this.targetPosition) <= this.attackDistance) {
  87. movementVector.set(0, 0, 0);
  88. }
  89. movementVector.transformDirection(this.object3d.matrix).multiplyScalar(this.movementSpeed * deltaTime);
  90. this.object3d.position.x += movementVector.x;
  91. this.object3d.position.z += movementVector.z;
  92. }
  93. }
  94. __name(EnemyAI, "EnemyAI");
  95. __decorateClass([
  96. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.object3d()
  97. ], EnemyAI.prototype, "target", 2);
  98. __decorateClass([
  99. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  100. ], EnemyAI.prototype, "movementSpeed", 2);
  101. __decorateClass([
  102. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  103. ], EnemyAI.prototype, "attackDistance", 2);
  104. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(EnemyAI);
  105. /***/ }),
  106. /***/ "./Assets/Components/FPSController.re.ts":
  107. /*!***********************************************!*\
  108. !*** ./Assets/Components/FPSController.re.ts ***!
  109. \***********************************************/
  110. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  111. __webpack_require__.r(__webpack_exports__);
  112. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  113. /* harmony export */ "default": () => (/* binding */ FPSController)
  114. /* harmony export */ });
  115. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  116. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  117. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
  118. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
  119. var __defProp = Object.defineProperty;
  120. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  121. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  122. var __decorateClass = (decorators, target, key, kind) => {
  123. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  124. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  125. if (decorator = decorators[i])
  126. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  127. if (kind && result)
  128. __defProp(target, key, result);
  129. return result;
  130. };
  131. const fwdDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, -1);
  132. const bwdDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, 1);
  133. const leftDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(-1, 0, 0);
  134. const rightDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(1, 0, 0);
  135. class FPSController extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  136. constructor() {
  137. super(...arguments);
  138. this.rotSpeed = 1;
  139. this.minCameraRotY = -1.5708;
  140. this.maxCameraRotY = 1.5708;
  141. this.cameraHeight = 0.4;
  142. this.walkSpeed = 2;
  143. this.fwdSpeedMultiplier = 1.3;
  144. this.runSpeedMultiplier = 1.8;
  145. }
  146. awake() {
  147. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.lock();
  148. this.camera = new three__WEBPACK_IMPORTED_MODULE_1__.PerspectiveCamera();
  149. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.add(this.camera);
  150. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.activeCamera = this.camera.uuid;
  151. this.camera.position.copy(this.character.position);
  152. this.camera.position.y += this.cameraHeight;
  153. this.camera.rotation.copy(this.character.rotation);
  154. const appContainer = document.getElementById("rogue-app");
  155. if (!appContainer)
  156. return;
  157. appContainer.onmousedown = (e) => {
  158. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.lock();
  159. };
  160. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.onStop(() => {
  161. if (!appContainer)
  162. return;
  163. appContainer.onmousedown = null;
  164. });
  165. this.camera.rotation.order = "YXZ";
  166. this.character.rotation.order = "YXZ";
  167. this.camera.up.set(0, 1, 0);
  168. }
  169. update() {
  170. const deltaTime = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.deltaTime;
  171. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.isMoving && document.pointerLockElement) {
  172. const mouseDeltaX = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.movementX * this.rotSpeed * deltaTime;
  173. const mouseDeltaY = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.movementY * this.rotSpeed * deltaTime;
  174. this.character.rotation.set(this.character.rotation.x, this.character.rotation.y - mouseDeltaX, this.character.rotation.z);
  175. this.camera.rotation.set(this.camera.rotation.x - mouseDeltaY, this.character.rotation.y, this.camera.rotation.z);
  176. this.camera.rotation.x = Math.max(this.minCameraRotY, Math.min(this.maxCameraRotY, this.camera.rotation.x));
  177. }
  178. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("Escape") && rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.unlock();
  179. let actualSpeed = this.walkSpeed;
  180. let onlyFwd = true;
  181. const movementVector = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
  182. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyDown("Space")) {
  183. }
  184. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyW")) {
  185. movementVector.add(fwdDirection);
  186. } else if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyS")) {
  187. movementVector.add(bwdDirection);
  188. onlyFwd = false;
  189. }
  190. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyA")) {
  191. movementVector.add(leftDirection);
  192. onlyFwd = false;
  193. } else if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyD")) {
  194. movementVector.add(rightDirection);
  195. onlyFwd = false;
  196. }
  197. if (onlyFwd) {
  198. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("ShiftLeft")) {
  199. actualSpeed *= this.runSpeedMultiplier;
  200. } else {
  201. actualSpeed *= this.fwdSpeedMultiplier;
  202. }
  203. }
  204. movementVector.normalize();
  205. if (movementVector.length() > 0) {
  206. movementVector.copy(movementVector.transformDirection(this.character.matrix).multiplyScalar(actualSpeed * deltaTime));
  207. this.character.position.x += movementVector.x;
  208. this.character.position.z += movementVector.z;
  209. }
  210. this.camera.position.set(this.character.position.x, this.character.position.y + this.cameraHeight, this.character.position.z);
  211. }
  212. }
  213. __name(FPSController, "FPSController");
  214. __decorateClass([
  215. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  216. ], FPSController.prototype, "rotSpeed", 2);
  217. __decorateClass([
  218. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num(-Math.PI / 2, 0)
  219. ], FPSController.prototype, "minCameraRotY", 2);
  220. __decorateClass([
  221. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num(0, Math.PI / 2)
  222. ], FPSController.prototype, "maxCameraRotY", 2);
  223. __decorateClass([
  224. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  225. ], FPSController.prototype, "cameraHeight", 2);
  226. __decorateClass([
  227. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  228. ], FPSController.prototype, "walkSpeed", 2);
  229. __decorateClass([
  230. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  231. ], FPSController.prototype, "fwdSpeedMultiplier", 2);
  232. __decorateClass([
  233. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  234. ], FPSController.prototype, "runSpeedMultiplier", 2);
  235. __decorateClass([
  236. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.object3d()
  237. ], FPSController.prototype, "character", 2);
  238. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(FPSController);
  239. /***/ }),
  240. /***/ "./Assets/Components/Flashlight.re.ts":
  241. /*!********************************************!*\
  242. !*** ./Assets/Components/Flashlight.re.ts ***!
  243. \********************************************/
  244. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  245. __webpack_require__.r(__webpack_exports__);
  246. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  247. /* harmony export */ "default": () => (/* binding */ Flashlight)
  248. /* harmony export */ });
  249. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  250. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  251. var __defProp = Object.defineProperty;
  252. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  253. class Flashlight extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  254. awake() {
  255. }
  256. start() {
  257. this.object3d.getObjectByName("Spotlight")?.lookAt(this.object3d.position.x, this.object3d.position.y - 0.4, this.object3d.position.z - 1);
  258. }
  259. update() {
  260. }
  261. }
  262. __name(Flashlight, "Flashlight");
  263. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(Flashlight);
  264. /***/ }),
  265. /***/ "./Assets/Components/MeshGrid.re.ts":
  266. /*!******************************************!*\
  267. !*** ./Assets/Components/MeshGrid.re.ts ***!
  268. \******************************************/
  269. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  270. __webpack_require__.r(__webpack_exports__);
  271. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  272. /* harmony export */ "default": () => (/* binding */ MeshGrid)
  273. /* harmony export */ });
  274. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  275. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  276. var __defProp = Object.defineProperty;
  277. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  278. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  279. var __decorateClass = (decorators, target, key, kind) => {
  280. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  281. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  282. if (decorator = decorators[i])
  283. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  284. if (kind && result)
  285. __defProp(target, key, result);
  286. return result;
  287. };
  288. class MeshGrid extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  289. constructor() {
  290. super(...arguments);
  291. this.allModels = [];
  292. }
  293. awake() {
  294. let x = 0;
  295. let z = 0;
  296. if (this.allModels.length > 0) {
  297. this.allModels.forEach((prefab) => {
  298. let model = prefab.instantiate(rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene);
  299. model.position.set(x + 0.5 * x, 0, z + 0.5 * z);
  300. x++;
  301. if (x == 6) {
  302. x = 0;
  303. z++;
  304. }
  305. });
  306. }
  307. }
  308. start() {
  309. }
  310. update() {
  311. }
  312. }
  313. __name(MeshGrid, "MeshGrid");
  314. __decorateClass([
  315. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.list.prefab()
  316. ], MeshGrid.prototype, "allModels", 2);
  317. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(MeshGrid);
  318. /***/ }),
  319. /***/ "./Assets/Components/OrbitCamera.re.js":
  320. /*!*********************************************!*\
  321. !*** ./Assets/Components/OrbitCamera.re.js ***!
  322. \*********************************************/
  323. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  324. __webpack_require__.r(__webpack_exports__);
  325. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  326. /* harmony export */ "default": () => (/* binding */ OrbitCamera)
  327. /* harmony export */ });
  328. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  329. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  330. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
  331. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
  332. var __defProp = Object.defineProperty;
  333. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  334. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  335. var __decorateClass = (decorators, target, key, kind) => {
  336. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  337. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  338. if (decorator = decorators[i])
  339. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  340. if (kind && result)
  341. __defProp(target, key, result);
  342. return result;
  343. };
  344. class OrbitCamera extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  345. constructor() {
  346. super(...arguments);
  347. this.rotateStart = new three__WEBPACK_IMPORTED_MODULE_1__.Vector2();
  348. this.rotateEnd = new three__WEBPACK_IMPORTED_MODULE_1__.Vector2();
  349. this.rotateDelta = new three__WEBPACK_IMPORTED_MODULE_1__.Vector2();
  350. this.enableRotate = true;
  351. this.rotateSpeed = 1;
  352. this.minAzimuthAngle = -Infinity;
  353. this.maxAzimuthAngle = Infinity;
  354. this.minPolarAngle = 0;
  355. this.maxPolarAngle = Math.PI;
  356. this.enableDolly = true;
  357. this.dollySpeed = 1;
  358. this.minDistance = 1;
  359. this.maxDistance = 50;
  360. this.scale = 1;
  361. this.EPS = 1e-6;
  362. this.twoPI = 2 * Math.PI;
  363. this.spherical = new three__WEBPACK_IMPORTED_MODULE_1__.Spherical();
  364. this.sphericalDelta = new three__WEBPACK_IMPORTED_MODULE_1__.Spherical();
  365. this.offset = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
  366. this.rotateMouseButton = 2;
  367. this.quat = new three__WEBPACK_IMPORTED_MODULE_1__.Quaternion().setFromUnitVectors(new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 1, 0), new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 1, 0));
  368. this.quatInverse = this.quat.clone().invert();
  369. this.lastPosition = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
  370. this.lastQuaternion = new three__WEBPACK_IMPORTED_MODULE_1__.Quaternion();
  371. this.initialOffset = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
  372. }
  373. awake() {
  374. }
  375. start() {
  376. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.rogueDOMContainer.addEventListener("contextmenu", (event) => {
  377. event.preventDefault();
  378. });
  379. this.quat = new three__WEBPACK_IMPORTED_MODULE_1__.Quaternion().setFromUnitVectors(this.object3d.up, new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 1, 0));
  380. this.quatInverse = this.quat.clone().invert();
  381. this.initialOffset.copy(this.object3d.position).sub(this.target.position);
  382. this.offset.copy(this.initialOffset);
  383. }
  384. update() {
  385. let normalizedScreenPosition = new three__WEBPACK_IMPORTED_MODULE_1__.Vector2(0, 0);
  386. this.normalizeScreenInput(rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse, normalizedScreenPosition);
  387. if (this.enableRotate && rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.getButtonDown(this.rotateMouseButton)) {
  388. this.rotateStart.set(normalizedScreenPosition.x, normalizedScreenPosition.y);
  389. }
  390. if (this.enableRotate && rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.getButtonPressed(this.rotateMouseButton)) {
  391. this.rotateEnd.set(normalizedScreenPosition.x, normalizedScreenPosition.y);
  392. this.rotateDelta.subVectors(this.rotateEnd, this.rotateStart).multiplyScalar(this.rotateSpeed);
  393. this.rotateLeft(this.twoPI * this.rotateDelta.x);
  394. this.rotateUp(this.twoPI * -this.rotateDelta.y);
  395. this.rotateStart.copy(this.rotateEnd);
  396. }
  397. if (this.enableDolly && rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.wheelY > 0) {
  398. this.dollyOut();
  399. }
  400. if (this.enableDolly && rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.wheelY < 0) {
  401. this.dollyIn();
  402. }
  403. this.updateCamera();
  404. }
  405. rotateLeft(angle) {
  406. this.sphericalDelta.theta -= angle;
  407. }
  408. rotateUp(angle) {
  409. this.sphericalDelta.phi -= angle;
  410. }
  411. updateCamera() {
  412. this.offset.applyQuaternion(this.quat);
  413. this.spherical.setFromVector3(this.offset);
  414. this.spherical.theta += this.sphericalDelta.theta;
  415. this.spherical.phi += this.sphericalDelta.phi;
  416. let min = this.minAzimuthAngle;
  417. let max = this.maxAzimuthAngle;
  418. if (isFinite(min) && isFinite(max)) {
  419. if (min < -Math.PI) {
  420. min += this.twoPI;
  421. } else if (min > Math.PI) {
  422. min -= this.twoPI;
  423. }
  424. if (max < -Math.PI) {
  425. max += this.twoPI;
  426. } else if (max > Math.PI) {
  427. max -= this.twoPI;
  428. }
  429. if (min <= max) {
  430. this.spherical.theta = Math.max(min, Math.min(max, this.spherical.theta));
  431. } else {
  432. this.spherical.theta = this.spherical.theta > (min + max) / 2 ? Math.max(min, this.spherical.theta) : Math.min(max, this.spherical.theta);
  433. }
  434. }
  435. this.spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this.spherical.phi));
  436. this.spherical.makeSafe();
  437. this.spherical.radius *= this.scale;
  438. this.spherical.radius = Math.max(this.minDistance, Math.min(this.maxDistance, this.spherical.radius));
  439. this.offset.setFromSpherical(this.spherical);
  440. this.offset.applyQuaternion(this.quatInverse);
  441. this.object3d.position.copy(this.target.position).add(this.offset);
  442. this.object3d.lookAt(this.target.position);
  443. this.sphericalDelta.set(0, 0, 0);
  444. this.scale = 1;
  445. if (this.lastPosition.distanceToSquared(this.object3d.position) > this.EPS || 8 * (1 - this.lastQuaternion.dot(this.object3d.quaternion)) > this.EPS) {
  446. this.lastPosition.copy(this.object3d.position);
  447. this.lastQuaternion.copy(this.object3d.quaternion);
  448. }
  449. }
  450. dollyOut() {
  451. this.scale /= Math.pow(0.95, this.dollySpeed);
  452. }
  453. dollyIn() {
  454. this.scale *= Math.pow(0.95, this.dollySpeed);
  455. }
  456. normalizeScreenInput(browserVector, gameVector) {
  457. const bounds = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.rogueDOMContainer.getBoundingClientRect();
  458. gameVector.x = (browserVector.x - bounds.left) / bounds.width * 2 - 1;
  459. gameVector.y = -((browserVector.y - bounds.top) / bounds.height) * 2 + 1;
  460. }
  461. }
  462. __name(OrbitCamera, "OrbitCamera");
  463. __decorateClass([
  464. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.object3d()
  465. ], OrbitCamera.prototype, "target", 2);
  466. __decorateClass([
  467. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.checkbox()
  468. ], OrbitCamera.prototype, "enableRotate", 2);
  469. __decorateClass([
  470. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  471. ], OrbitCamera.prototype, "rotateSpeed", 2);
  472. __decorateClass([
  473. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  474. ], OrbitCamera.prototype, "minAzimuthAngle", 2);
  475. __decorateClass([
  476. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  477. ], OrbitCamera.prototype, "maxAzimuthAngle", 2);
  478. __decorateClass([
  479. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  480. ], OrbitCamera.prototype, "minPolarAngle", 2);
  481. __decorateClass([
  482. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  483. ], OrbitCamera.prototype, "maxPolarAngle", 2);
  484. __decorateClass([
  485. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.checkbox()
  486. ], OrbitCamera.prototype, "enableDolly", 2);
  487. __decorateClass([
  488. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  489. ], OrbitCamera.prototype, "dollySpeed", 2);
  490. __decorateClass([
  491. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  492. ], OrbitCamera.prototype, "minDistance", 2);
  493. __decorateClass([
  494. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  495. ], OrbitCamera.prototype, "maxDistance", 2);
  496. __decorateClass([
  497. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.vector3()
  498. ], OrbitCamera.prototype, "offset", 2);
  499. __decorateClass([
  500. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  501. ], OrbitCamera.prototype, "rotateMouseButton", 2);
  502. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(OrbitCamera);
  503. /***/ }),
  504. /***/ "./Assets/Components/RaycastReceiver.re.js":
  505. /*!*************************************************!*\
  506. !*** ./Assets/Components/RaycastReceiver.re.js ***!
  507. \*************************************************/
  508. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  509. __webpack_require__.r(__webpack_exports__);
  510. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  511. /* harmony export */ "default": () => (/* binding */ RaycastReceiver)
  512. /* harmony export */ });
  513. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  514. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  515. var __defProp = Object.defineProperty;
  516. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  517. class RaycastReceiver extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  518. onMouseOver(intersect) {
  519. throw new Error("Abstract class: Please inherit from this class to use it's behavior");
  520. }
  521. onMouseOut() {
  522. throw new Error("Abstract class: Please inherit from this class to use it's behavior");
  523. }
  524. }
  525. __name(RaycastReceiver, "RaycastReceiver");
  526. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(RaycastReceiver);
  527. /***/ }),
  528. /***/ "./Assets/Components/RaycastReporter.re.js":
  529. /*!*************************************************!*\
  530. !*** ./Assets/Components/RaycastReporter.re.js ***!
  531. \*************************************************/
  532. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  533. __webpack_require__.r(__webpack_exports__);
  534. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  535. /* harmony export */ "default": () => (/* binding */ RaycastReporter)
  536. /* harmony export */ });
  537. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  538. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  539. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
  540. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
  541. /* harmony import */ var _RaycastReceiver_re__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./RaycastReceiver.re */ "./Assets/Components/RaycastReceiver.re.js");
  542. var __defProp = Object.defineProperty;
  543. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  544. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  545. var __decorateClass = (decorators, target, key, kind) => {
  546. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  547. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  548. if (decorator = decorators[i])
  549. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  550. if (kind && result)
  551. __defProp(target, key, result);
  552. return result;
  553. };
  554. class RaycastReporter extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  555. constructor() {
  556. super(...arguments);
  557. this.receiverClass = ["RaycastReceiver"];
  558. this.allHovered = [];
  559. }
  560. awake() {
  561. }
  562. start() {
  563. this.mouse = new three__WEBPACK_IMPORTED_MODULE_1__.Vector2(0, 0);
  564. this.raycaster = new three__WEBPACK_IMPORTED_MODULE_1__.Raycaster();
  565. this.updated = false;
  566. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.touch.enabled = true;
  567. }
  568. normalizeScreenInput(browserVector, gameVector) {
  569. const bounds = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.rogueDOMContainer.getBoundingClientRect();
  570. gameVector.x = (browserVector.x - bounds.left) / bounds.width * 2 - 1;
  571. gameVector.y = -((browserVector.y - bounds.top) / bounds.height) * 2 + 1;
  572. }
  573. getMouseInput() {
  574. if (!rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.isMoving) {
  575. return;
  576. }
  577. this.normalizeScreenInput(rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse, this.mouse);
  578. this.updated = true;
  579. }
  580. getTouchInput() {
  581. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.touch.touches.length == 0) {
  582. return;
  583. }
  584. this.normalizeScreenInput(rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.touch.touches[0], this.mouse);
  585. this.updated = true;
  586. }
  587. update() {
  588. this.updated = false;
  589. this.getMouseInput();
  590. this.getTouchInput();
  591. if (!this.updated) {
  592. return;
  593. }
  594. this.raycaster.setFromCamera(this.mouse, this.object3d);
  595. let intersects = this.raycaster.intersectObjects(rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.children);
  596. let listeningComponents = [];
  597. intersects.forEach((intersect) => {
  598. let object3d = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByProperty("uuid", intersect.object.uuid);
  599. let component = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.getComponent(_RaycastReceiver_re__WEBPACK_IMPORTED_MODULE_2__["default"], object3d);
  600. while (component == null && object3d.parent != null) {
  601. object3d = object3d.parent;
  602. component = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.getComponent(_RaycastReceiver_re__WEBPACK_IMPORTED_MODULE_2__["default"], object3d);
  603. }
  604. if (component != null) {
  605. listeningComponents = listeningComponents.filter((dataThing) => {
  606. dataThing.component.object3d.uuid != component.object3d.uuid;
  607. });
  608. listeningComponents.push({ component, intersect });
  609. }
  610. });
  611. for (let i = 0; i < this.allHovered.length; i++) {
  612. let dataThing = this.allHovered[i];
  613. if (!listeningComponents.includes(dataThing)) {
  614. dataThing.component.onMouseOut();
  615. }
  616. }
  617. this.allHovered = [];
  618. for (let i = 0; i < listeningComponents.length; i++) {
  619. let dataThing = listeningComponents[i];
  620. this.allHovered.push(dataThing);
  621. if (dataThing.component.onMouseOver(dataThing.intersect) === false) {
  622. break;
  623. }
  624. }
  625. }
  626. }
  627. __name(RaycastReporter, "RaycastReporter");
  628. __decorateClass([
  629. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.PropList("String")
  630. ], RaycastReporter.prototype, "receiverClass", 2);
  631. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(RaycastReporter);
  632. /***/ }),
  633. /***/ "./Assets/Components/TileRaycastReceiver.re.js":
  634. /*!*****************************************************!*\
  635. !*** ./Assets/Components/TileRaycastReceiver.re.js ***!
  636. \*****************************************************/
  637. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  638. __webpack_require__.r(__webpack_exports__);
  639. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  640. /* harmony export */ "default": () => (/* binding */ TileRaycastReceiver)
  641. /* harmony export */ });
  642. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  643. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  644. /* harmony import */ var _RaycastReceiver_re__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./RaycastReceiver.re */ "./Assets/Components/RaycastReceiver.re.js");
  645. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! three */ "three");
  646. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_2__);
  647. var __defProp = Object.defineProperty;
  648. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  649. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  650. var __decorateClass = (decorators, target, key, kind) => {
  651. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  652. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  653. if (decorator = decorators[i])
  654. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  655. if (kind && result)
  656. __defProp(target, key, result);
  657. return result;
  658. };
  659. class TileRaycastReceiver extends _RaycastReceiver_re__WEBPACK_IMPORTED_MODULE_1__["default"] {
  660. constructor() {
  661. super(...arguments);
  662. this.tileSize = new three__WEBPACK_IMPORTED_MODULE_2__.Vector2(1, 1);
  663. this.isHovered = false;
  664. }
  665. onMouseOver(intersect) {
  666. this.isHovered = true;
  667. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.rogueDOMContainer.style.cursor = "pointer";
  668. }
  669. onMouseOut() {
  670. if (this.isHovered) {
  671. this.isHovered = false;
  672. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.rogueDOMContainer.style.cursor = "default";
  673. }
  674. }
  675. getPosition() {
  676. return this.object3d.position;
  677. }
  678. awake() {
  679. }
  680. start() {
  681. }
  682. update() {
  683. if (!this.isHovered) {
  684. return;
  685. }
  686. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.getButtonDown(0) || rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.touch.touches.length == 1) {
  687. let target = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByName("CameraTarget");
  688. if (!target) {
  689. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Debug.logWarning("didn't find CameraTarget Object3D");
  690. return;
  691. }
  692. target.position.set(this.object3d.position.x, this.object3d.position.y, this.object3d.position.z);
  693. }
  694. }
  695. }
  696. __name(TileRaycastReceiver, "TileRaycastReceiver");
  697. __decorateClass([
  698. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.vector2()
  699. ], TileRaycastReceiver.prototype, "tileSize", 2);
  700. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(TileRaycastReceiver);
  701. /***/ }),
  702. /***/ "./Assets/Components/WorldFPSController.re.ts":
  703. /*!****************************************************!*\
  704. !*** ./Assets/Components/WorldFPSController.re.ts ***!
  705. \****************************************************/
  706. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  707. __webpack_require__.r(__webpack_exports__);
  708. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  709. /* harmony export */ "default": () => (/* binding */ WorldFPSController)
  710. /* harmony export */ });
  711. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
  712. /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
  713. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
  714. /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
  715. var __defProp = Object.defineProperty;
  716. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  717. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  718. var __decorateClass = (decorators, target, key, kind) => {
  719. var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  720. for (var i = decorators.length - 1, decorator; i >= 0; i--)
  721. if (decorator = decorators[i])
  722. result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  723. if (kind && result)
  724. __defProp(target, key, result);
  725. return result;
  726. };
  727. const fwdDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, -1);
  728. const bwdDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, 1);
  729. const leftDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(-1, 0, 0);
  730. const rightDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(1, 0, 0);
  731. const upDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 1, 0);
  732. const downDirection = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, -1, 0);
  733. class WorldFPSController extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
  734. constructor() {
  735. super(...arguments);
  736. this.horizontalLookSpeed = 360;
  737. this.verticalLookSpeed = 180;
  738. this.minCameraRotY = -1.5708;
  739. this.maxCameraRotY = 1.5708;
  740. this.cameraHeight = 0.4;
  741. this.walkSpeed = 2;
  742. this.fwdSpeedMultiplier = 1.3;
  743. this.runSpeedMultiplier = 1.8;
  744. this.characterOffset = new three__WEBPACK_IMPORTED_MODULE_1__.Object3D();
  745. }
  746. awake() {
  747. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.lock();
  748. this.characterOffset.position.copy(this.character.position);
  749. this.mainCamera.position.set(0, 0, 0);
  750. this.character.position.set(0, 0, 0);
  751. this.mainCamera.position.y += this.cameraHeight;
  752. this.mainCamera.rotation.copy(this.character.rotation);
  753. this.worldObjects.forEach((worldObject) => {
  754. worldObject.position.set(-this.characterOffset.position.x, -this.characterOffset.position.y, -this.characterOffset.position.z);
  755. });
  756. const appContainer = document.getElementById("rogue-app");
  757. if (!appContainer)
  758. return;
  759. appContainer.onmousedown = (e) => {
  760. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.lock();
  761. };
  762. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.onStop(() => {
  763. if (!appContainer)
  764. return;
  765. appContainer.onmousedown = null;
  766. });
  767. this.mainCamera.rotation.order = "YXZ";
  768. this.character.rotation.order = "YXZ";
  769. this.mainCamera.up.set(0, 1, 0);
  770. }
  771. update() {
  772. const deltaTime = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Runtime.deltaTime;
  773. const appContainer = document.getElementById("rogue-app");
  774. if (!appContainer)
  775. return;
  776. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.isMoving && document.pointerLockElement) {
  777. console.log("movement Ratio", rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.movementX / appContainer.clientWidth, rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.movementY / appContainer.clientHeight);
  778. const mouseDeltaX = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.movementX / appContainer.clientWidth * this.horizontalLookSpeed * deltaTime;
  779. const mouseDeltaY = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.movementY / appContainer.clientHeight * this.verticalLookSpeed * deltaTime;
  780. this.character.rotation.set(this.character.rotation.x, this.character.rotation.y - mouseDeltaX, this.character.rotation.z);
  781. this.mainCamera.rotation.set(this.mainCamera.rotation.x - mouseDeltaY, this.character.rotation.y, this.mainCamera.rotation.z);
  782. this.mainCamera.rotation.x = Math.max(this.minCameraRotY, Math.min(this.maxCameraRotY, this.mainCamera.rotation.x));
  783. }
  784. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("Escape") && rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.mouse.unlock();
  785. let actualSpeed = this.walkSpeed;
  786. let onlyFwd = true;
  787. const movementVector = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
  788. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("Space")) {
  789. movementVector.add(upDirection);
  790. }
  791. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("ControlLeft")) {
  792. movementVector.add(downDirection);
  793. }
  794. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyW")) {
  795. movementVector.add(fwdDirection);
  796. } else if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyS")) {
  797. movementVector.add(bwdDirection);
  798. onlyFwd = false;
  799. }
  800. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyA")) {
  801. movementVector.add(leftDirection);
  802. onlyFwd = false;
  803. } else if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("KeyD")) {
  804. movementVector.add(rightDirection);
  805. onlyFwd = false;
  806. }
  807. if (onlyFwd) {
  808. if (rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Input.keyboard.getKeyPressed("ShiftLeft")) {
  809. actualSpeed *= this.runSpeedMultiplier;
  810. } else {
  811. actualSpeed *= this.fwdSpeedMultiplier;
  812. }
  813. }
  814. movementVector.normalize();
  815. if (movementVector.length() > 0) {
  816. movementVector.copy(movementVector.transformDirection(this.character.matrix).multiplyScalar(actualSpeed * deltaTime));
  817. this.characterOffset.position.x += movementVector.x;
  818. this.characterOffset.position.y += movementVector.y;
  819. this.characterOffset.position.z += movementVector.z;
  820. this.worldObjects.forEach((worldObject) => {
  821. worldObject.position.set(-this.characterOffset.position.x, -this.characterOffset.position.y, -this.characterOffset.position.z);
  822. });
  823. }
  824. this.characterOffsetPosition.set(this.characterOffset.position.x, this.characterOffset.position.y, this.characterOffset.position.z);
  825. this.characterRotatePosition.set(this.characterOffset.rotation.x, this.characterOffset.rotation.y, this.characterOffset.rotation.z);
  826. }
  827. }
  828. __name(WorldFPSController, "WorldFPSController");
  829. __decorateClass([
  830. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.object3d()
  831. ], WorldFPSController.prototype, "mainCamera", 2);
  832. __decorateClass([
  833. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  834. ], WorldFPSController.prototype, "horizontalLookSpeed", 2);
  835. __decorateClass([
  836. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  837. ], WorldFPSController.prototype, "verticalLookSpeed", 2);
  838. __decorateClass([
  839. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num(-Math.PI / 2, 0)
  840. ], WorldFPSController.prototype, "minCameraRotY", 2);
  841. __decorateClass([
  842. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num(0, Math.PI / 2)
  843. ], WorldFPSController.prototype, "maxCameraRotY", 2);
  844. __decorateClass([
  845. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  846. ], WorldFPSController.prototype, "cameraHeight", 2);
  847. __decorateClass([
  848. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  849. ], WorldFPSController.prototype, "walkSpeed", 2);
  850. __decorateClass([
  851. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  852. ], WorldFPSController.prototype, "fwdSpeedMultiplier", 2);
  853. __decorateClass([
  854. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
  855. ], WorldFPSController.prototype, "runSpeedMultiplier", 2);
  856. __decorateClass([
  857. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.object3d()
  858. ], WorldFPSController.prototype, "character", 2);
  859. __decorateClass([
  860. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.list.object3d()
  861. ], WorldFPSController.prototype, "worldObjects", 2);
  862. __decorateClass([
  863. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.vector3()
  864. ], WorldFPSController.prototype, "characterOffsetPosition", 2);
  865. __decorateClass([
  866. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.vector3()
  867. ], WorldFPSController.prototype, "characterRotatePosition", 2);
  868. rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(WorldFPSController);
  869. /***/ }),
  870. /***/ "rogue-engine":
  871. /*!******************************************************************************************************************!*\
  872. !*** external {"commonjs":"rogue-engine","commonjs2":"rogue-engine","amd":"rogue-engine","root":"rogue-engine"} ***!
  873. \******************************************************************************************************************/
  874. /***/ ((module) => {
  875. module.exports = __WEBPACK_EXTERNAL_MODULE_rogue_engine__;
  876. /***/ }),
  877. /***/ "three":
  878. /*!**************************************************************************************!*\
  879. !*** external {"commonjs":"three","commonjs2":"three","amd":"three","root":"three"} ***!
  880. \**************************************************************************************/
  881. /***/ ((module) => {
  882. module.exports = __WEBPACK_EXTERNAL_MODULE_three__;
  883. /***/ })
  884. /******/ });
  885. /************************************************************************/
  886. /******/ // The module cache
  887. /******/ var __webpack_module_cache__ = {};
  888. /******/
  889. /******/ // The require function
  890. /******/ function __webpack_require__(moduleId) {
  891. /******/ // Check if module is in cache
  892. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  893. /******/ if (cachedModule !== undefined) {
  894. /******/ return cachedModule.exports;
  895. /******/ }
  896. /******/ // Create a new module (and put it into the cache)
  897. /******/ var module = __webpack_module_cache__[moduleId] = {
  898. /******/ // no module.id needed
  899. /******/ // no module.loaded needed
  900. /******/ exports: {}
  901. /******/ };
  902. /******/
  903. /******/ // Execute the module function
  904. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  905. /******/
  906. /******/ // Return the exports of the module
  907. /******/ return module.exports;
  908. /******/ }
  909. /******/
  910. /******/ // expose the modules object (__webpack_modules__)
  911. /******/ __webpack_require__.m = __webpack_modules__;
  912. /******/
  913. /************************************************************************/
  914. /******/ /* webpack/runtime/chunk loaded */
  915. /******/ (() => {
  916. /******/ var deferred = [];
  917. /******/ __webpack_require__.O = (result, chunkIds, fn, priority) => {
  918. /******/ if(chunkIds) {
  919. /******/ priority = priority || 0;
  920. /******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];
  921. /******/ deferred[i] = [chunkIds, fn, priority];
  922. /******/ return;
  923. /******/ }
  924. /******/ var notFulfilled = Infinity;
  925. /******/ for (var i = 0; i < deferred.length; i++) {
  926. /******/ var [chunkIds, fn, priority] = deferred[i];
  927. /******/ var fulfilled = true;
  928. /******/ for (var j = 0; j < chunkIds.length; j++) {
  929. /******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {
  930. /******/ chunkIds.splice(j--, 1);
  931. /******/ } else {
  932. /******/ fulfilled = false;
  933. /******/ if(priority < notFulfilled) notFulfilled = priority;
  934. /******/ }
  935. /******/ }
  936. /******/ if(fulfilled) {
  937. /******/ deferred.splice(i--, 1)
  938. /******/ var r = fn();
  939. /******/ if (r !== undefined) result = r;
  940. /******/ }
  941. /******/ }
  942. /******/ return result;
  943. /******/ };
  944. /******/ })();
  945. /******/
  946. /******/ /* webpack/runtime/compat get default export */
  947. /******/ (() => {
  948. /******/ // getDefaultExport function for compatibility with non-harmony modules
  949. /******/ __webpack_require__.n = (module) => {
  950. /******/ var getter = module && module.__esModule ?
  951. /******/ () => (module['default']) :
  952. /******/ () => (module);
  953. /******/ __webpack_require__.d(getter, { a: getter });
  954. /******/ return getter;
  955. /******/ };
  956. /******/ })();
  957. /******/
  958. /******/ /* webpack/runtime/define property getters */
  959. /******/ (() => {
  960. /******/ // define getter functions for harmony exports
  961. /******/ __webpack_require__.d = (exports, definition) => {
  962. /******/ for(var key in definition) {
  963. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  964. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  965. /******/ }
  966. /******/ }
  967. /******/ };
  968. /******/ })();
  969. /******/
  970. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  971. /******/ (() => {
  972. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  973. /******/ })();
  974. /******/
  975. /******/ /* webpack/runtime/make namespace object */
  976. /******/ (() => {
  977. /******/ // define __esModule on exports
  978. /******/ __webpack_require__.r = (exports) => {
  979. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  980. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  981. /******/ }
  982. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  983. /******/ };
  984. /******/ })();
  985. /******/
  986. /******/ /* webpack/runtime/jsonp chunk loading */
  987. /******/ (() => {
  988. /******/ // no baseURI
  989. /******/
  990. /******/ // object to store loaded and loading chunks
  991. /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
  992. /******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
  993. /******/ var installedChunks = {
  994. /******/ "rogue-engine-user-scripts": 0
  995. /******/ };
  996. /******/
  997. /******/ // no chunk on demand loading
  998. /******/
  999. /******/ // no prefetching
  1000. /******/
  1001. /******/ // no preloaded
  1002. /******/
  1003. /******/ // no HMR
  1004. /******/
  1005. /******/ // no HMR manifest
  1006. /******/
  1007. /******/ __webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);
  1008. /******/
  1009. /******/ // install a JSONP callback for chunk loading
  1010. /******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
  1011. /******/ var [chunkIds, moreModules, runtime] = data;
  1012. /******/ // add "moreModules" to the modules object,
  1013. /******/ // then flag all "chunkIds" as loaded and fire callback
  1014. /******/ var moduleId, chunkId, i = 0;
  1015. /******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
  1016. /******/ for(moduleId in moreModules) {
  1017. /******/ if(__webpack_require__.o(moreModules, moduleId)) {
  1018. /******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
  1019. /******/ }
  1020. /******/ }
  1021. /******/ if(runtime) var result = runtime(__webpack_require__);
  1022. /******/ }
  1023. /******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
  1024. /******/ for(;i < chunkIds.length; i++) {
  1025. /******/ chunkId = chunkIds[i];
  1026. /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
  1027. /******/ installedChunks[chunkId][0]();
  1028. /******/ }
  1029. /******/ installedChunks[chunkId] = 0;
  1030. /******/ }
  1031. /******/ return __webpack_require__.O(result);
  1032. /******/ }
  1033. /******/
  1034. /******/ var chunkLoadingGlobal = self["webpackChunk_name_"] = self["webpackChunk_name_"] || [];
  1035. /******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
  1036. /******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
  1037. /******/ })();
  1038. /******/
  1039. /************************************************************************/
  1040. /******/
  1041. /******/ // startup
  1042. /******/ // Load entry module and return exports
  1043. /******/ __webpack_require__("./Assets/Components/DungeonGenerator.re.ts");
  1044. /******/ __webpack_require__("./Assets/Components/EnemyAI.re.ts");
  1045. /******/ __webpack_require__("./Assets/Components/Flashlight.re.ts");
  1046. /******/ __webpack_require__("./Assets/Components/FPSController.re.ts");
  1047. /******/ __webpack_require__("./Assets/Components/MeshGrid.re.ts");
  1048. /******/ __webpack_require__("./Assets/Components/OrbitCamera.re.js");
  1049. /******/ // This entry module is referenced by other modules so it can't be inlined
  1050. /******/ __webpack_require__("./Assets/Components/RaycastReceiver.re.js");
  1051. /******/ __webpack_require__("./Assets/Components/RaycastReporter.re.js");
  1052. /******/ __webpack_require__("./Assets/Components/TileRaycastReceiver.re.js");
  1053. /******/ var __webpack_exports__ = __webpack_require__("./Assets/Components/WorldFPSController.re.ts");
  1054. /******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
  1055. /******/
  1056. /******/ return __webpack_exports__;
  1057. /******/ })()
  1058. ;
  1059. });
  1060. //# sourceMappingURL=rogue-engine-user-scripts.js.map