RoadPointLayer.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  6. (this && this.__decorate) ||
  7. function (t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. };
  17. Object.defineProperty(i, "__esModule", {value: !0});
  18. const r = t("MapType"),
  19. u = t("MapRoadUtils"),
  20. {ccclass: o} = cc._decorator;
  21. t = s = class extends cc.Component {
  22. constructor() {
  23. super(...arguments),
  24. (this._roadPointDic = {}),
  25. (this._roadNodeDic = {}),
  26. (this._graphicDic = {}),
  27. (this._roadTypeShowDic = {}),
  28. (this._type = 1),
  29. (this._gsize = 16),
  30. (this.blockScale = 0.95);
  31. }
  32. onLoad() {
  33. (this._roadTypeShowDic[0] = !0),
  34. (this._roadTypeShowDic[1] = !0),
  35. (this._roadTypeShowDic[2] = !0),
  36. (this._roadTypeShowDic[3] = !0),
  37. (this._roadTypeShowDic[4] = !0),
  38. (this._roadTypeShowDic[5] = !0),
  39. (this._roadTypeShowDic[6] = !0),
  40. (this._roadTypeShowDic[7] = !0),
  41. (this._roadTypeShowDic[8] = !0),
  42. (this._roadTypeShowDic[9] = !0);
  43. }
  44. initRoadPointInfo(i) {
  45. if ((this.clear(), i.roadDataArr && 0 != i.roadDataArr.length)) {
  46. var t = i.roadDataArr.length,
  47. s = i.roadDataArr[0].length;
  48. for (let e = 0; e < t; e++)
  49. for (let t = 0; t < s; t++) {
  50. const o = i.roadDataArr[e][t],
  51. a = u.default.instance.getNodeByDerect(t, e);
  52. (a.value = o), 1 != a.value && (this._roadNodeDic[a.dx + "_" + a.dy] = a);
  53. }
  54. this.drawRointPoint();
  55. }
  56. }
  57. getRoadPointInfo() {
  58. for (var t = u.default.instance.row, e = u.default.instance.col, i = [], s = 0; s < 2 * t; s++) {
  59. i[s] = [];
  60. for (var o = 0; o < e; o++)
  61. null == this._roadNodeDic[o + "_" + s]
  62. ? (i[s][o] = 1)
  63. : (i[s][o] = this._roadNodeDic[o + "_" + s].value);
  64. }
  65. return i;
  66. }
  67. drawRointPoint() {
  68. var t = u.default.instance.row,
  69. e = u.default.instance.col,
  70. i = u.default.instance.mapType,
  71. s = t / this._gsize;
  72. i == r.MapType.angle45 && (s = (2 * t) / this._gsize);
  73. for (var o = e / this._gsize, a = 0; a < s; a++) for (var n = 0; n < o; n++) this.drawGraphic(n, a);
  74. }
  75. drawGraphic(t, i, e = !0) {
  76. var s = this.getGraphic(t + "_" + i);
  77. e && s.clear();
  78. var o = u.default.instance.halfNodeWidth,
  79. a = u.default.instance.halfNodeHeight,
  80. n = u.default.instance.mapType,
  81. r = "00ff0050",
  82. l = t * this._gsize,
  83. h = l + this._gsize,
  84. i = i * this._gsize,
  85. c = i + this._gsize;
  86. for (let e = i; e < c; e++)
  87. for (let t = l; t < h; t++) {
  88. var d = this._roadNodeDic[t + "_" + e];
  89. d &&
  90. this._roadTypeShowDic[d.value] &&
  91. (0 == d.value
  92. ? (r = "#00ff0050")
  93. : 1 == d.value
  94. ? (r = "#d4d4d450")
  95. : 2 == d.value
  96. ? (r = "#0000ff50")
  97. : 3 == d.value && (r = "#ffff0050"),
  98. 0 == n && this.draw45AngleMapRoadPoint(s, d, r, o, a),
  99. 1 == n
  100. ? this.draw90AngleMapRoadPoint(s, d, r, o, a)
  101. : 2 == n && this.drawHoneycombMapRoadPoint(s, d, r, o, a));
  102. }
  103. }
  104. getGraphic(t) {
  105. var e;
  106. return (
  107. this._graphicDic[t] ||
  108. (((e = new cc.Node()).parent = this.node),
  109. (e.position = cc.v2(0, 0)),
  110. (e = e.addComponent(cc.Graphics)),
  111. (this._graphicDic[t] = e)),
  112. this._graphicDic[t]
  113. );
  114. }
  115. draw45AngleMapRoadPoint(t, e, i, s, o) {
  116. t.fillColor.fromHEX(i),
  117. t.moveTo(-s * this.blockScale + e.px, 0 + e.py),
  118. t.lineTo(0 + e.px, -o * this.blockScale + e.py),
  119. t.lineTo(s * this.blockScale + e.px, 0 + e.py),
  120. t.lineTo(0 + e.px, o * this.blockScale + e.py),
  121. t.fill();
  122. }
  123. draw90AngleMapRoadPoint(t, e, i, s, o) {
  124. t.fillColor.fromHEX(i),
  125. t.rect(
  126. -s * this.blockScale + e.px,
  127. -o * this.blockScale + e.py,
  128. s * this.blockScale * 2,
  129. o * this.blockScale * 2
  130. ),
  131. t.fill();
  132. }
  133. drawHoneycombMapRoadPoint(t, e, i, s, o) {
  134. t.fillColor.fromHEX(i);
  135. var a = u.default.instance.nodeWidth * this.blockScale,
  136. n = u.default.instance.nodeHeight * this.blockScale,
  137. r = a / 4,
  138. l = 3 * r,
  139. h = n / 2,
  140. c = -2 * r,
  141. i = -h;
  142. t.moveTo(c + r + e.px, i + e.py),
  143. t.lineTo(c + l + e.px, i + e.py),
  144. t.lineTo(c + a + e.px, h + i + e.py),
  145. t.lineTo(c + l + e.px, n + i + e.py),
  146. t.lineTo(c + r + e.px, n + i + e.py),
  147. t.lineTo(0 + c + e.px, h + i + e.py),
  148. t.lineTo(c + r + e.px, i + e.py),
  149. t.fill();
  150. }
  151. addRoadPoint(t) {
  152. this._roadNodeDic[t.dx + "_" + t.dy] = t;
  153. var e = Math.floor(t.dx / this._gsize),
  154. t = Math.floor(t.dy / this._gsize);
  155. this.drawGraphic(e, t);
  156. }
  157. addRoadPoints(t) {
  158. for (var e, i = {}, s = 0; s < t.length; s++) {
  159. this._roadNodeDic[t[s].dx + "_" + t[s].dy] = t[s];
  160. var o = Math.floor(t[s].dx / this._gsize),
  161. a = Math.floor(t[s].dy / this._gsize);
  162. i[o + "_" + a] = [o, a];
  163. }
  164. for (e in i) this.drawGraphic(i[e][0], i[e][1]);
  165. }
  166. removeRoadPoint(t) {
  167. null != this._roadNodeDic[t.dx + "_" + t.dy] &&
  168. ((this._roadNodeDic[t.dx + "_" + t.dy] = null), delete this._roadNodeDic[t.dx + "_" + t.dy]);
  169. var e = Math.floor(t.dx / this._gsize),
  170. t = Math.floor(t.dy / this._gsize);
  171. this.drawGraphic(e, t);
  172. }
  173. removeRoadPoints(t) {
  174. for (var e, i = {}, s = 0; s < t.length; s++) {
  175. null != this._roadNodeDic[t[s].dx + "_" + t[s].dy] &&
  176. ((this._roadNodeDic[t[s].dx + "_" + t[s].dy] = null),
  177. delete this._roadNodeDic[t[s].dx + "_" + t[s].dy]);
  178. var o = Math.floor(t[s].dx / this._gsize),
  179. a = Math.floor(t[s].dy / this._gsize);
  180. i[o + "_" + a] = [o, a];
  181. }
  182. for (e in i) this.drawGraphic(i[e][0], i[e][1]);
  183. }
  184. changeRoadPointStyle() {
  185. for (var t in (this._type++, (this._type = this._type % 3), this._roadPointDic)) {
  186. var e = this._roadPointDic[t];
  187. e && e.reset(e.node, this._type);
  188. }
  189. }
  190. hiddenUnWalkAbleRoadPoint() {
  191. var t, e;
  192. if (((s.hiddenUnWalkAble = !s.hiddenUnWalkAble), s.hiddenUnWalkAble))
  193. for (t in this._roadPointDic) (e = this._roadPointDic[t]) && 1 == e.node.value && e.clear();
  194. else
  195. for (t in this._roadPointDic)
  196. (e = this._roadPointDic[t]) && 1 == e.node.value && e.reset(e.node, this._type);
  197. }
  198. clear() {
  199. for (var t in this._roadPointDic)
  200. this._roadPointDic[t].destroy(), (this._roadPointDic[t] = null), delete this._roadPointDic[t];
  201. for (t in this._graphicDic)
  202. this._graphicDic[t] &&
  203. (this._graphicDic[t].clear(),
  204. this._graphicDic[t].destroy(),
  205. (this._graphicDic[t] = null),
  206. delete this._roadNodeDic[t]);
  207. this._roadNodeDic = {};
  208. }
  209. };
  210. (t.hiddenUnWalkAble = !1), (t = s = e([o], t)), (i.default = t = s);