0768d342c91ff0af66ccc62d8bcc9155fde4acfc.js 20 KB

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