67f356369ce567fe1898b7ae72038ee83758a446.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5", "__unresolved_6"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Camera, Component, find, geometry, Layers, Node, PhysicsSystem, Quat, RigidBody, tween, Vec3, gui, UI_Idioms, UI_Main, Container_Manager, Cube_Infor, Cube_State, Hall, _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _class3, _crd, ccclass, property, GameCtl;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfgui(extras) {
  8. _reporterNs.report("gui", "../../core/ui/ui", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfUI_Idioms(extras) {
  11. _reporterNs.report("UI_Idioms", "../ui/UI_Idioms/UI_Idioms", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfUI_Main(extras) {
  14. _reporterNs.report("UI_Main", "../ui/UI_Main/UI_Main", _context.meta, extras);
  15. }
  16. function _reportPossibleCrUseOfContainer_Manager(extras) {
  17. _reporterNs.report("Container_Manager", "./Container_Manager", _context.meta, extras);
  18. }
  19. function _reportPossibleCrUseOfCube_Infor(extras) {
  20. _reporterNs.report("Cube_Infor", "./Cube_Infor", _context.meta, extras);
  21. }
  22. function _reportPossibleCrUseOfCube_State(extras) {
  23. _reporterNs.report("Cube_State", "./Cube_Infor", _context.meta, extras);
  24. }
  25. function _reportPossibleCrUseOfHall(extras) {
  26. _reporterNs.report("Hall", "../hall/Hall", _context.meta, extras);
  27. }
  28. return {
  29. setters: [function (_unresolved_) {
  30. _reporterNs = _unresolved_;
  31. }, function (_cc) {
  32. _cclegacy = _cc.cclegacy;
  33. __checkObsolete__ = _cc.__checkObsolete__;
  34. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  35. _decorator = _cc._decorator;
  36. Camera = _cc.Camera;
  37. Component = _cc.Component;
  38. find = _cc.find;
  39. geometry = _cc.geometry;
  40. Layers = _cc.Layers;
  41. Node = _cc.Node;
  42. PhysicsSystem = _cc.PhysicsSystem;
  43. Quat = _cc.Quat;
  44. RigidBody = _cc.RigidBody;
  45. tween = _cc.tween;
  46. Vec3 = _cc.Vec3;
  47. }, function (_unresolved_2) {
  48. gui = _unresolved_2.gui;
  49. }, function (_unresolved_3) {
  50. UI_Idioms = _unresolved_3.UI_Idioms;
  51. }, function (_unresolved_4) {
  52. UI_Main = _unresolved_4.UI_Main;
  53. }, function (_unresolved_5) {
  54. Container_Manager = _unresolved_5.Container_Manager;
  55. }, function (_unresolved_6) {
  56. Cube_Infor = _unresolved_6.Cube_Infor;
  57. Cube_State = _unresolved_6.Cube_State;
  58. }, function (_unresolved_7) {
  59. Hall = _unresolved_7.Hall;
  60. }],
  61. execute: function () {
  62. _crd = true;
  63. _cclegacy._RF.push({}, "5237f+4/ftIlKW+rC062l8C", "GameCtl", undefined);
  64. __checkObsolete__(['_decorator', 'BoxCollider', 'Camera', 'Component', 'director', 'EventTouch', 'find', 'Game', 'geometry', 'Layers', 'Node', 'PhysicsSystem', 'Quat', 'RigidBody', 'Size', 'tween', 'UITransform', 'v3', 'Vec3']);
  65. ({
  66. ccclass,
  67. property
  68. } = _decorator);
  69. _export("GameCtl", GameCtl = (_dec = ccclass('GameCtl'), _dec2 = property(Camera), _dec3 = property([Node]), _dec(_class = (_class2 = (_class3 = class GameCtl extends Component {
  70. constructor(...args) {
  71. super(...args);
  72. _initializerDefineProperty(this, "camera", _descriptor, this);
  73. _initializerDefineProperty(this, "Ani", _descriptor2, this);
  74. this.canTouch = true;
  75. this.Container = void 0;
  76. }
  77. onLoad() {
  78. GameCtl.instance = this;
  79. console.log(find('Ani'));
  80. console.log('Camera value in onLoad:', this.camera);
  81. this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
  82. this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
  83. this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  84. this.Container = find('Container').getComponent(_crd && Container_Manager === void 0 ? (_reportPossibleCrUseOfContainer_Manager({
  85. error: Error()
  86. }), Container_Manager) : Container_Manager);
  87. }
  88. update(deltaTime) {}
  89. onTouchStart(event) {}
  90. onTouchMove(event) {}
  91. onTouchEnd(event) {
  92. if (this.canTouch) {
  93. this.shootRay(event);
  94. }
  95. } //发射射线检测判断物体是否可消除
  96. shootRay(event) {
  97. if (!this.camera) return;
  98. let ray = new geometry.Ray();
  99. this.camera.screenPointToRay(event.getLocationX(), event.getLocationY(), ray);
  100. const index = Layers.nameToLayer('Cube');
  101. const cubeMask = 2 << index;
  102. const maxDistance = 100000;
  103. const queryTrigger = false;
  104. if (PhysicsSystem.instance.raycastClosest(ray, cubeMask, maxDistance, queryTrigger)) {
  105. const raycastClosestResult = PhysicsSystem.instance.raycastClosestResult;
  106. const hitPoint = raycastClosestResult.hitPoint;
  107. const hitNormal = raycastClosestResult.hitNormal;
  108. const collider = raycastClosestResult.collider;
  109. const distance = raycastClosestResult.distance;
  110. console.log(collider.node.name); //当前其余点击无效
  111. if (collider.node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  112. error: Error()
  113. }), Cube_Infor) : Cube_Infor).state === (_crd && Cube_State === void 0 ? (_reportPossibleCrUseOfCube_State({
  114. error: Error()
  115. }), Cube_State) : Cube_State).live) {
  116. this.entryContainer(collider.node);
  117. }
  118. }
  119. console.log('发射了射线');
  120. }
  121. entryContainer(node) {
  122. // 判断容器剩余容量
  123. let startIndex = -1;
  124. let targetPos = new Vec3();
  125. let txt_length = node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  126. error: Error()
  127. }), Cube_Infor) : Cube_Infor).Text.length;
  128. console.log(txt_length); // 判断字长 并 判断是否还有空间可放置
  129. switch (txt_length) {
  130. case 1:
  131. for (let i = 0; i < this.Container.node_isIdiom.length; i++) {
  132. if (this.Container.node_isIdiom[i] === false) {
  133. startIndex = i; // 找到连续的三个 false,记录起始位置
  134. break; // 找到第一个符合条件的位置后停止
  135. }
  136. }
  137. if (startIndex !== -1) {
  138. // 如果找到了一个值为 false 的元素
  139. targetPos = this.Container.nodes[startIndex].getWorldPosition().clone();
  140. this.Container.node_isIdiom[startIndex] = true;
  141. console.log(targetPos);
  142. } else {
  143. console.log("没有空间了");
  144. }
  145. break;
  146. case 2:
  147. {
  148. for (let i = 0; i < this.Container.node_isIdiom.length - 2; i++) {
  149. if (this.Container.node_isIdiom[i] === false && this.Container.node_isIdiom[i + 1] === false) {
  150. startIndex = i; // 找到连续的两个 false,记录起始位置
  151. break; // 找到第一个符合条件的位置后停止
  152. }
  153. }
  154. if (startIndex !== -1) {
  155. console.log("找到连续的两个 false,起始索引是:", startIndex); // 可以在此使用 startIndex 进行后续操作,例如:
  156. let pos1 = this.Container.nodes[startIndex].getWorldPosition();
  157. let pos2 = this.Container.nodes[startIndex + 1].getWorldPosition();
  158. this.Container.node_isIdiom[startIndex] = true;
  159. this.Container.node_isIdiom[startIndex + 1] = true;
  160. targetPos.set((pos1.x + pos2.x) / 2, (pos1.y + pos2.y) / 2, (pos1.z + pos2.z) / 2);
  161. console.log(targetPos);
  162. }
  163. break;
  164. }
  165. case 3:
  166. {
  167. for (let i = 0; i < this.Container.node_isIdiom.length - 2; i++) {
  168. if (this.Container.node_isIdiom[i] === false && this.Container.node_isIdiom[i + 1] === false && this.Container.node_isIdiom[i + 2] === false) {
  169. startIndex = i; // 找到连续的三个 false,记录起始位置
  170. break; // 找到第一个符合条件的位置后停止
  171. }
  172. }
  173. if (startIndex !== -1) {
  174. // 找到连续三个 false,startIndex 即为最前面的索引
  175. console.log("找到连续的三个 false,起始索引是:", startIndex); // 可以在此使用 startIndex 进行后续操作,例如:
  176. let pos1 = this.Container.nodes[startIndex].getWorldPosition();
  177. let pos2 = this.Container.nodes[startIndex + 1].getWorldPosition();
  178. let pos3 = this.Container.nodes[startIndex + 2].getWorldPosition();
  179. this.Container.node_isIdiom[startIndex] = true;
  180. this.Container.node_isIdiom[startIndex + 1] = true;
  181. this.Container.node_isIdiom[startIndex + 2] = true;
  182. targetPos.set((pos1.x + pos2.x + pos3.x) / 3, (pos1.y + pos2.y + pos3.y) / 3, (pos1.z + pos2.z + pos3.z) / 3);
  183. console.log(targetPos);
  184. } else {
  185. console.log("没有找到连续的三个 false");
  186. }
  187. break;
  188. }
  189. default:
  190. return;
  191. }
  192. if (startIndex !== -1) {
  193. // node.getComponent(Cube_Infor).lock = true;
  194. node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  195. error: Error()
  196. }), Cube_Infor) : Cube_Infor).state = (_crd && Cube_State === void 0 ? (_reportPossibleCrUseOfCube_State({
  197. error: Error()
  198. }), Cube_State) : Cube_State).wait;
  199. node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  200. error: Error()
  201. }), Cube_Infor) : Cube_Infor).rigidbody.type = RigidBody.Type.STATIC; // 禁用重力
  202. let targetRotation = new Quat();
  203. Quat.fromEuler(targetRotation, -90, 0, 0);
  204. this.canTouch = false;
  205. tween(node).to(0.5, {
  206. position: new Vec3(targetPos.x, targetPos.y, targetPos.z + 0.4),
  207. rotation: targetRotation
  208. }).call(() => {
  209. this.Container.idiom_combine.set(node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  210. error: Error()
  211. }), Cube_Infor) : Cube_Infor), startIndex); // 执行判断成语合成逻辑
  212. let matchedCubes = [];
  213. let flag = this.Container.checkIdiom_Combine(node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  214. error: Error()
  215. }), Cube_Infor) : Cube_Infor), matchedCubes);
  216. if (flag) {
  217. // 执行合成动画
  218. console.log("匹配的成语方块:", matchedCubes);
  219. this.combine_ani(matchedCubes[0], matchedCubes[1]);
  220. } else {
  221. //高亮
  222. (_crd && gui === void 0 ? (_reportPossibleCrUseOfgui({
  223. error: Error()
  224. }), gui) : gui).get(_crd && UI_Idioms === void 0 ? (_reportPossibleCrUseOfUI_Idioms({
  225. error: Error()
  226. }), UI_Idioms) : UI_Idioms).light_Show(node.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  227. error: Error()
  228. }), Cube_Infor) : Cube_Infor));
  229. this.canTouch = true;
  230. }
  231. }).start();
  232. }
  233. } //合成动画
  234. combine_ani(cube1, cube2) {
  235. this.canTouch = true;
  236. for (let i = this.Container.idiom_combine.get(cube1); i < this.Container.idiom_combine.get(cube1) + cube1.Text.length; i++) {
  237. this.Container.node_isIdiom[i] = false;
  238. }
  239. this.Container.idiom_combine.delete(cube1);
  240. for (let i = this.Container.idiom_combine.get(cube2); i < this.Container.idiom_combine.get(cube2) + cube2.Text.length; i++) {
  241. this.Container.node_isIdiom[i] = false;
  242. }
  243. this.Container.idiom_combine.delete(cube2); // 取消相关字的高亮显示
  244. (_crd && gui === void 0 ? (_reportPossibleCrUseOfgui({
  245. error: Error()
  246. }), gui) : gui).get(_crd && UI_Idioms === void 0 ? (_reportPossibleCrUseOfUI_Idioms({
  247. error: Error()
  248. }), UI_Idioms) : UI_Idioms).light_Hide(cube1, cube2);
  249. (_crd && gui === void 0 ? (_reportPossibleCrUseOfgui({
  250. error: Error()
  251. }), gui) : gui).get(_crd && UI_Main === void 0 ? (_reportPossibleCrUseOfUI_Main({
  252. error: Error()
  253. }), UI_Main) : UI_Main).evt.emit((_crd && gui === void 0 ? (_reportPossibleCrUseOfgui({
  254. error: Error()
  255. }), gui) : gui).get(_crd && UI_Main === void 0 ? (_reportPossibleCrUseOfUI_Main({
  256. error: Error()
  257. }), UI_Main) : UI_Main).evt.key.update_remain);
  258. this.adjustContainer(); // 检测容器中哪些字需要高亮显示
  259. console.log(this.Container.node_isIdiom); // 在所有动画结束后执行
  260. this.Container.idioms = this.Container.idioms.filter(c => c.idiom !== cube1.Text + cube2.Text); // 创建第一个 tween 动画
  261. const tween1 = tween(cube1.node).to(0.1, {
  262. position: new Vec3(this.Ani[0].position.x, this.Ani[0].position.y, this.Ani[0].position.z + 0.4)
  263. }).call(() => {
  264. setTimeout(() => {
  265. cube1.state = (_crd && Cube_State === void 0 ? (_reportPossibleCrUseOfCube_State({
  266. error: Error()
  267. }), Cube_State) : Cube_State).dead;
  268. this.Container.recycleCube(cube1.node);
  269. }, 500.0);
  270. }); // 创建第二个 tween 动画
  271. const tween2 = tween(cube2.node).to(0.1, {
  272. position: new Vec3(this.Ani[1].position.x, this.Ani[1].position.y, this.Ani[1].position.z + 0.4)
  273. }).call(() => {
  274. setTimeout(() => {
  275. cube2.state = (_crd && Cube_State === void 0 ? (_reportPossibleCrUseOfCube_State({
  276. error: Error()
  277. }), Cube_State) : Cube_State).dead;
  278. this.Container.recycleCube(cube2.node);
  279. }, 500.0);
  280. }); // 使用 tween 的并行组合功能
  281. tween(cube1.node).parallel(tween1, tween2) // 并行执行 tween1 和 tween2
  282. .call(() => {
  283. (_crd && Hall === void 0 ? (_reportPossibleCrUseOfHall({
  284. error: Error()
  285. }), Hall) : Hall).getInstance().player.set_combine_num(1);
  286. }).start();
  287. }
  288. adjustContainer() {
  289. const container = this.Container; // 新的 node_isIdiom 状态数组
  290. const newNodeIsIdiom = Array(container.node_isIdiom.length).fill(false); // 新的 idiom_combine 映射表
  291. const newIdiomCombine = new Map(); // 遍历 idiom_combine,重新计算位置
  292. for (const [cube, startIndex] of container.idiom_combine.entries()) {
  293. const txtLength = cube.Text.length; // 获取字长
  294. let targetIndex = -1; // 目标位置起始索引
  295. let targetPos = new Vec3();
  296. switch (txtLength) {
  297. case 1:
  298. {
  299. // 找到一个空位
  300. for (let i = 0; i < container.node_isIdiom.length; i++) {
  301. if (!newNodeIsIdiom[i]) {
  302. targetIndex = i;
  303. break;
  304. }
  305. }
  306. if (targetIndex !== -1) {
  307. targetPos = container.nodes[targetIndex].getWorldPosition().clone();
  308. newNodeIsIdiom[targetIndex] = true; // 占用位置
  309. } else {
  310. console.log("没有空位容纳单字 Cube_Infor");
  311. }
  312. break;
  313. }
  314. case 2:
  315. {
  316. // 找到连续两个空位
  317. for (let i = 0; i < container.node_isIdiom.length - 1; i++) {
  318. if (!newNodeIsIdiom[i] && !newNodeIsIdiom[i + 1]) {
  319. targetIndex = i;
  320. break;
  321. }
  322. }
  323. if (targetIndex !== -1) {
  324. const pos1 = container.nodes[targetIndex].getWorldPosition();
  325. const pos2 = container.nodes[targetIndex + 1].getWorldPosition();
  326. targetPos.set((pos1.x + pos2.x) / 2, (pos1.y + pos2.y) / 2, (pos1.z + pos2.z) / 2);
  327. newNodeIsIdiom[targetIndex] = true;
  328. newNodeIsIdiom[targetIndex + 1] = true;
  329. } else {
  330. console.log("没有连续两个空位容纳双字 Cube_Infor");
  331. }
  332. break;
  333. }
  334. case 3:
  335. {
  336. // 找到连续三个空位
  337. for (let i = 0; i < container.node_isIdiom.length - 2; i++) {
  338. if (!newNodeIsIdiom[i] && !newNodeIsIdiom[i + 1] && !newNodeIsIdiom[i + 2]) {
  339. targetIndex = i;
  340. break;
  341. }
  342. }
  343. if (targetIndex !== -1) {
  344. const pos1 = container.nodes[targetIndex].getWorldPosition();
  345. const pos2 = container.nodes[targetIndex + 1].getWorldPosition();
  346. const pos3 = container.nodes[targetIndex + 2].getWorldPosition();
  347. targetPos.set((pos1.x + pos2.x + pos3.x) / 3, (pos1.y + pos2.y + pos3.y) / 3, (pos1.z + pos2.z + pos3.z) / 3);
  348. newNodeIsIdiom[targetIndex] = true;
  349. newNodeIsIdiom[targetIndex + 1] = true;
  350. newNodeIsIdiom[targetIndex + 2] = true;
  351. } else {
  352. console.log("没有连续三个空位容纳三字 Cube_Infor");
  353. }
  354. break;
  355. }
  356. default:
  357. return;
  358. } // 移动 Cube_Infor 到目标位置
  359. if (targetIndex !== -1) {
  360. tween(cube.node).to(0.3, {
  361. position: new Vec3(targetPos.x, targetPos.y, targetPos.z + 0.4)
  362. }).start();
  363. newIdiomCombine.set(cube, targetIndex); // 更新新映射
  364. }
  365. } // 更新 container 状态
  366. container.node_isIdiom = newNodeIsIdiom;
  367. container.idiom_combine = newIdiomCombine;
  368. console.log("调整后的容器状态:", container.node_isIdiom);
  369. console.log("更新后的 idiom_combine:", [...container.idiom_combine.entries()]);
  370. }
  371. }, _class3.instance = null, _class3), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "camera", [_dec2], {
  372. configurable: true,
  373. enumerable: true,
  374. writable: true,
  375. initializer: function () {
  376. return null;
  377. }
  378. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "Ani", [_dec3], {
  379. configurable: true,
  380. enumerable: true,
  381. writable: true,
  382. initializer: function () {
  383. return [];
  384. }
  385. })), _class2)) || _class));
  386. _cclegacy._RF.pop();
  387. _crd = false;
  388. }
  389. };
  390. });
  391. //# sourceMappingURL=67f356369ce567fe1898b7ae72038ee83758a446.js.map