123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- var t = require;
- var e = module;
- var i = exports;
- e =
- (this && this.__decorate) ||
- function (t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(i, "__esModule", {value: !0});
- const s = t("MapType"),
- {ccclass: o, property: a, menu: n, requireComponent: r, executeInEditMode: l} = cc._decorator;
- t = class extends cc.Component {
- constructor() {
- super(...arguments),
- (this.graphics = null),
- (this.lineSize1 = 6),
- (this.lineSize2 = 3),
- (this.lingColor3 = cc.color(0, 0, 0, 187).fromHEX("#bbbbbbbb")),
- (this.lingColor1 = cc.color(255, 0, 0, 187).fromHEX("#00550025")),
- (this.lingColor2 = "#11115566"),
- (this._test = !1);
- }
- onLoad() {
- this.graphics ||
- ((this.graphics = this.getComponent(cc.Graphics)),
- this.graphics || (this.graphics = this.addComponent(cc.Graphics)));
- }
- set test(t) {
- (this._test = t), this.drawGrid(this.node.parent.width, this.node.parent.height, 100, 100, s.MapType.angle90);
- }
- get test() {
- return this._test;
- }
- clear() {
- this.graphics.clear();
- }
- drawGrid(t, e, i, s, o) {
- (this._mapWidth = t),
- (this._mapHeight = e),
- (this._ceilWidth = i),
- (this._ceilHeight = s),
- (this._halfCeilWidth = Math.floor(i / 2)),
- (this._halfCeilHeight = Math.floor(s / 2));
- (i = 2 * Math.ceil(t / this._ceilWidth) + 1),
- (s = 2 * Math.ceil(e / this._ceilHeight) + 1),
- (t = i * this._halfCeilWidth),
- (e = s * this._halfCeilHeight);
- 0 == o
- ? this.draw45AngleGrid(s, i, t, e)
- : 1 == o
- ? this.draw90AngleGrid(s, i, t, e)
- : 2 == o && this.drawHoneycombGrid(t, e);
- }
- draw45AngleGrid(t, e, i, s) {
- this.graphics.clear();
- for (var o = 0; o < t + 1; o++)
- o % 2 == 0
- ? this.graphics.strokeColor.fromHEX(this.lingColor2)
- : (this.graphics.strokeColor = this.lingColor1),
- (this.graphics.lineWidth = 1),
- this.graphics.moveTo(0, o * this._halfCeilHeight),
- this.graphics.lineTo(i, o * this._halfCeilHeight),
- this.graphics.stroke();
- for (var a = 0; a < e + 1; a++)
- a % 2 == 0
- ? this.graphics.strokeColor.fromHEX(this.lingColor2)
- : (this.graphics.strokeColor = this.lingColor1),
- (this.graphics.lineWidth = 1),
- this.graphics.moveTo(a * this._halfCeilWidth, 0),
- this.graphics.lineTo(a * this._halfCeilWidth, s),
- this.graphics.stroke();
- for (var n, r, l, h, c = 1; c < e + t; c++)
- (this.graphics.strokeColor = this.lingColor3),
- (this.graphics.lineWidth = 2),
- (n = c * this._halfCeilWidth),
- c % 2 == 1
- ? ((l = r = 0),
- (h = c * this._halfCeilHeight),
- i < n && ((n = i), (r = (c - e) * this._halfCeilHeight)),
- s < h && ((l = (c - t) * this._halfCeilWidth), (h = s)),
- this.graphics.moveTo(n, r),
- this.graphics.lineTo(l, h))
- : ((r = s),
- (h = (t - c) * this._halfCeilHeight),
- i < n && ((n = i), (r = (t - (c - e)) * this._halfCeilHeight)),
- h < (l = 0) && ((l = (c - t) * this._halfCeilWidth), (h = 0)),
- this.graphics.moveTo(n, r),
- this.graphics.lineTo(l, h),
- this.graphics.stroke());
- }
- draw90AngleGrid(t, e, i, s) {
- this.graphics.clear();
- for (var o = this.lineSize1, a = this.lineSize2, n = 0; n < t + 1; n++)
- n % 2 == 0
- ? ((this.graphics.strokeColor = this.lingColor3), (this.graphics.lineWidth = o))
- : ((this.graphics.strokeColor = this.lingColor1), (this.graphics.lineWidth = a)),
- this.graphics.moveTo(0, n * this._halfCeilHeight),
- this.graphics.lineTo(i, n * this._halfCeilHeight),
- this.graphics.stroke();
- for (var r = 0; r < e + 1; r++)
- r % 2 == 0
- ? ((this.graphics.strokeColor = this.lingColor3), (this.graphics.lineWidth = o))
- : ((this.graphics.strokeColor = this.lingColor1), (this.graphics.lineWidth = a)),
- this.graphics.moveTo(r * this._halfCeilWidth, 0),
- this.graphics.lineTo(r * this._halfCeilWidth, s),
- this.graphics.stroke();
- }
- drawHoneycombGrid(t, e) {
- this.graphics.clear(), this._ceilWidth;
- for (
- var i = this._ceilWidth / 4,
- s = 3 * i,
- o = this._ceilHeight / 2,
- a = 2 * i - o,
- n = t / this._ceilWidth,
- r = e / this._ceilWidth,
- l = 2 * Math.ceil((this._mapWidth - i) / (6 * i)),
- h = Math.ceil((this._mapHeight - o) / this._ceilHeight),
- c = 0;
- c < 4 * r + 1;
- c++
- )
- c % 4 == 0
- ? (this.graphics.strokeColor.fromHEX(this.lingColor2), (this.graphics.lineWidth = 1))
- : ((this.graphics.strokeColor = this.lingColor1), (this.graphics.lineWidth = 1.2)),
- c % 4 == 1
- ? (this.graphics.moveTo(0, (c - 1) * i + a), this.graphics.lineTo(t, (c - 1) * i + a))
- : c % 4 == 3
- ? (this.graphics.moveTo(0, (c - 1) * i + o), this.graphics.lineTo(t, (c - 1) * i + o))
- : (this.graphics.moveTo(0, c * i), this.graphics.lineTo(t, c * i)),
- this.graphics.stroke();
- for (var d = 0; d < 4 * n + 1; d++)
- d % 4 == 0
- ? this.graphics.strokeColor.fromHEX(this.lingColor2)
- : (this.graphics.strokeColor = this.lingColor1),
- (this.graphics.lineWidth = 1),
- this.graphics.moveTo(d * i, 0),
- this.graphics.lineTo(d * i, e),
- this.graphics.stroke();
- (this.graphics.strokeColor = this.lingColor3), (this.graphics.lineWidth = 1.5);
- for (var u = 0; u < l; u++) {
- var p = u * s,
- f = 0;
- u % 2 != 0 && (f = o);
- for (var g = 0; g < h; g++) {
- var m = g * this._ceilHeight + f;
- u % 2 == 0
- ? (this.drawLine(p + i, 0 + m, p + s, 0 + m),
- this.drawLine(p + s, 0 + m, p + this._ceilWidth, o + m),
- this.drawLine(p + this._ceilWidth, o + m, p + s, this._ceilHeight + m),
- g == h - 1 && this.drawLine(p + s, this._ceilHeight + m, p + i, this._ceilHeight + m),
- this.drawLine(p + i, this._ceilHeight + m, 0 + p, o + m),
- this.drawLine(0 + p, o + m, p + i, 0 + m))
- : (this.drawLine(p + i, 0 + m, p + s, 0 + m),
- u == l - 1 &&
- (this.drawLine(p + s, 0 + m, p + this._ceilWidth, o + m),
- this.drawLine(p + this._ceilWidth, o + m, p + s, this._ceilHeight + m)),
- g == h - 1 &&
- (this.drawLine(p + s, this._ceilHeight + m, p + i, this._ceilHeight + m),
- this.drawLine(p + i, this._ceilHeight + m, 0 + p, o + m),
- u != l - 1 && this.drawLine(p + this._ceilWidth, o + m, p + s, this._ceilHeight + m)));
- }
- }
- }
- drawLine(t, e, i, s) {
- this.graphics.moveTo(t, e), this.graphics.lineTo(i, s), this.graphics.stroke();
- }
- };
- e([a(cc.Graphics)], t.prototype, "graphics", void 0),
- e([a()], t.prototype, "lineSize1", void 0),
- e([a()], t.prototype, "lineSize2", void 0),
- e([a()], t.prototype, "lingColor3", void 0),
- e([a()], t.prototype, "lingColor1", void 0),
- e([a], t.prototype, "_test", void 0),
- e([a()], t.prototype, "test", null),
- (t = e([o, r(cc.Graphics), n("game/map/GridLayer"), l], t)),
- (i.default = t);
|