使用地图和汇总问题-生成的代码包含错误

时间:2019-07-06 16:59:47

标签: typescript rollupjs

我正在使用汇总,但是生成的捆绑软件根本不起作用。

这是我的原始代码:

const selectableCarBones = [
  "door_dside_f", // left door front
  "door_dside_r", // left door back
  "door_pside_f", // right door front
  "door_pside_r", // right door back
  "boot" // trunk
];

function selectVehicle(vehicleId: number, entityPos: alt.Vector3, selectionWorldPos: alt.Vector3, hitEntitySurfacePos: alt.Vector3) {
  let willDrawSprite = false;

  if (natives.isThisModelACar(natives.getEntityModel(vehicleId))) {
    // get bone of vehicle
    let bonesWithDistance = new Map(selectableCarBones.map(bone => {
      let bonePos = natives.getWorldPositionOfEntityBone(vehicleId, natives.getEntityBoneIndexByName(vehicleId, bone));
      let distance = natives.getDistanceBetweenCoords(localPlayer.pos.x, localPlayer.pos.y, localPlayer.pos.z, bonePos.x, bonePos.y, bonePos.z, false);

      return [
        bone,
        {
          distance,
          pos: bonePos
        }];
    }));

    let bonesDistanceSorted = new Map([...bonesWithDistance].sort((a, b) => {
      return a[1].distance - b[1].distance;
    }));

    let firstItem = bonesDistanceSorted.entries().next().value;

    //...
  }
}

这是从汇总的输出文件生成的:

var selectableCarBones = [
  "door_dside_f",
  "door_dside_r",
  "door_pside_f",
  "door_pside_r",
  "boot" // trunk
];

function selectVehicle(vehicleId, entityPos, selectionWorldPos, hitEntitySurfacePos) {
  var willDrawSprite = false;
  if (isThisModelACar(getEntityModel(vehicleId))) {
    // get bone of vehicle
    var bonesWithDistance = new Map(selectableCarBones.map(function(bone) {
      var bonePos = getWorldPositionOfEntityBone(vehicleId, getEntityBoneIndexByName(vehicleId, bone));
      var distance = getDistanceBetweenCoords(localPlayer$a.pos.x, localPlayer$a.pos.y, localPlayer$a.pos.z, bonePos.x, bonePos.y, bonePos.z, false);
      return [
        bone,
        {
          distance: distance,
          pos: bonePos
        }
      ];
    }));
    var bonesDistanceSorted = new Map(bonesWithDistance.slice().sort(function(a, b) {
      return a[1].distance - b[1].distance;
    }));
    var firstItem = bonesDistanceSorted.entries().next().value;

    // ...
  }
}

问题出在第24行:bonesWithDistance.slice()

错误消息是:

[18:39:15][Error] [V8] Exception at levelv:build/client.bundle.js:1245
[18:39:15][Error]           var bonesDistanceSorted = new Map(bonesWithDistance.slice().sort(function (a, b) {
[18:39:15][Error]   TypeError: bonesWithDistance.slice is not a function
    at selectVehicle (build/client.bundle.js:1245:61)
    at Object.updateSelection (build/client.bundle.js:1210:21)
    at build/client.bundle.js:1129:29

我将不胜感激:)

0 个答案:

没有答案