"use strict";
cc._RF.push(module, '5901aPTkUNPJoPoIGCpGGMK', 'Z_04_syys_utils');
// Z_04_syys/script/Z_04_syys_utils.js

"use strict";

exports.__esModule = true;
exports.getPosByAngle = getPosByAngle;
exports.getAngleByPos = getAngleByPos;
exports.exchangeNodePos = exchangeNodePos;
exports.RandomInt = RandomInt;
exports.shuffle = shuffle;
exports.Between = Between;
exports.randomSortByArr = randomSortByArr;
exports.asyncTweenTo = asyncTweenTo;
exports.asyncTweenBy = asyncTweenBy;
exports.asyncDelay = asyncDelay;
exports.asyncPlayDragonBoneAnimation = asyncPlayDragonBoneAnimation;
exports.asyncPlayEffectByUrl = asyncPlayEffectByUrl;

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function getPosByAngle(angle, len) {
  var radian = angle * Math.PI / 180;
  var x = Math.sin(radian) * len;
  var y = Math.cos(radian) * len;
  return {
    x: x,
    y: y
  };
}

function getAngleByPos(px, py, mx, my) {
  var x = Math.abs(px - mx);
  var y = Math.abs(py - my);
  var z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  var cos = y / z;
  var radina = Math.acos(cos); // 用反三角函数求弧度

  var angle = Math.floor(180 / (Math.PI / radina) * 100) / 100; // 将弧度转换成角度

  if (mx > px && my > py) {
    // 鼠标在第四象限
    angle = 180 - angle;
  }

  if (mx === px && my > py) {
    // 鼠标在y轴负方向上
    angle = 180;
  }

  if (mx > px && my === py) {
    // 鼠标在x轴正方向上
    angle = 90;
  }

  if (mx < px && my > py) {
    // 鼠标在第三象限
    angle = 180 + angle;
  }

  if (mx < px && my === py) {
    // 鼠标在x轴负方向
    angle = 270;
  }

  if (mx < px && my < py) {
    // 鼠标在第二象限
    angle = 360 - angle;
  } // console.log('angle: ', angle);


  return angle;
}

function exchangeNodePos(baseNode, targetNode) {
  return baseNode.convertToNodeSpaceAR(targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)));
}

function RandomInt(a, b) {
  if (b === void 0) {
    b = 0;
  }

  var max = Math.max(a, b);
  var min = Math.min(a, b);
  return Math.floor(Math.random() * (max - min) + min);
}

function shuffle(arr) {
  var newArr = [];
  var tmpArr = arr.concat();

  while (tmpArr.length > 0) {
    newArr.push.apply(newArr, tmpArr.splice(RandomInt(tmpArr.length), 1));
  }

  return newArr;
}

function Between(a, b, c) {
  return [a, b, c].sort(function (a, b) {
    return a - b;
  })[1];
}

function randomSortByArr(arr) {
  var newArr = [];
  var tmpArr = arr.concat();

  while (tmpArr.length > 0) {
    var randomIndex = Math.floor(tmpArr.length * Math.random());
    newArr.push(tmpArr[randomIndex]);
    tmpArr.splice(randomIndex, 1);
  }

  return newArr;
}

function asyncTweenTo(node, duration, obj, ease) {
  if (ease === void 0) {
    ease = undefined;
  }

  return new Promise(function (resolve, reject) {
    cc.tween(node).to(duration, obj, ease).call(function () {
      resolve();
    }).start();
  });
}

function asyncTweenBy(node, duration, obj, ease) {
  if (ease === void 0) {
    ease = undefined;
  }

  return new Promise(function (resolve, reject) {
    cc.tween(node).by(duration, obj, ease).call(function () {
      resolve();
    }).start();
  });
}

function asyncDelay(duration) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      resolve();
    }, duration * 1000);
  });
}

function asyncPlayDragonBoneAnimation(_x, _x2, _x3) {
  return _asyncPlayDragonBoneAnimation.apply(this, arguments);
}

function _asyncPlayDragonBoneAnimation() {
  _asyncPlayDragonBoneAnimation = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(node, animationName, time) {
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            if (time === void 0) {
              time = 1;
            }

            return _context.abrupt("return", new Promise(function (resolve, reject) {
              node.getComponent(dragonBones.ArmatureDisplay).once(dragonBones.EventObject.COMPLETE, function () {
                console.log('COMPLETE');
                resolve();
              });
              node.getComponent(dragonBones.ArmatureDisplay).playAnimation(animationName, time);
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _asyncPlayDragonBoneAnimation.apply(this, arguments);
}

function asyncPlayEffectByUrl(_x4, _x5) {
  return _asyncPlayEffectByUrl.apply(this, arguments);
}

function _asyncPlayEffectByUrl() {
  _asyncPlayEffectByUrl = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(url, loop) {
    return regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            if (loop === void 0) {
              loop = false;
            }

            return _context2.abrupt("return", new Promise(function (resolve, reject) {
              cc.assetManager.loadRemote(url, function (err, clip) {
                cc.audioEngine.playEffect(clip, loop);
              });
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _asyncPlayEffectByUrl.apply(this, arguments);
}

cc._RF.pop();