| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087 | class Simulation {  constructor(t) {    return (      (this.carriers = []),      (this.ports = [[], []]),      (this.xTracks = []),      (this.lifts = []),      (this.chargers = []),      (this.slots = [[], []]),      (this.input = t.input),      (this.output = t.output),      (this.strategy = t.strategy),      (this.multiply = t.multiply),      (this.process = t.process),      (this.liftAssign = t.liftAssign),      (this.onEnd = t.onEnd),      (this.sharePath = t.sharePath),      (this.loadTime = 6.9),      (this.unLoadTime = 4.7),      (this.chargingTime = 6e4),      (this.workingTime = 12e4),      (this.time0 = null),      (this.time = 0),      (this.palletType = -1),      (this.inputCount = 0),      (this.outputCount = 0),      (this.debuggers = []),      (this.showHelper = !1),      (this.error = ""),      (this.isPlaying = !1),      (this.result = {        carriers: [],        lifts: [],        input: 0,        output: 0,        time: 0,      }),      (this.isReply = t.isReply),      (this.isHorizontal = !0),      this.init(),      "" === this.error && this.start(),      this    );  }  init() {    if (!selectedIcube)      return (        (this.error = "首先绘制货架"), void Utils.logg(this.error, "error")      );    if (0 === selectedIcube.carriers.length)      return (        (this.error = "货架没有载体"), void Utils.logg(this.error, "error")      );    if (0 === selectedIcube.activedXtrackIds.length)      return (        (this.error = "货架没有x-Track"), void Utils.logg(this.error, "error")      );    if (0 === selectedIcube.lifts.length)      return (        (this.error = "货架没有垂直运输机"),        void Utils.logg(this.error, "error")      );    if (0 === selectedIcube.activedIOPorts.length)      return (        (this.error = "货架没有输入/输出端口"),        void Utils.logg(this.error, "error")      );    if (0 === selectedIcube.chargers.length)      return (        (this.error = "货架没有运输充电器"),        void Utils.logg(this.error, "error")      );    if (      ((this.isHorizontal = selectedIcube.isHorizontal),      (this.ports[0] = selectedIcube.activedIOPorts.filter(        t => 1 === t.portType      )),      (this.ports[1] = selectedIcube.activedIOPorts.filter(        t => 2 === t.portType      )),      0 === this.ports[0].length)    )      return (        (this.error = "货架没有输入端口"), void Utils.logg(this.error, "error")      );    if (0 === this.ports[1].length)      return (        (this.error = "货架没有输出端口"), void Utils.logg(this.error, "error")      );    selectedIcube.pallets.forEach(t => t.setEnabled(!1)),      selectedIcube.SPSPalletLabels &&        (selectedIcube.SPSPalletLabels.mesh.isVisible = !1),      (this.carriers = selectedIcube.carriers),      (this.lifts = selectedIcube.lifts),      (this.chargers = [...selectedIcube.activedChargers]);    for (let t = 0; t < selectedIcube.transform[6].data.length; t++)      this.xTracks = this.xTracks.concat({        position: new BABYLON.Vector3(          selectedIcube.transform[6].position[t][0],          selectedIcube.transform[6].position[t][1],          selectedIcube.transform[6].position[t][2]        ),        props: selectedIcube.transform[6].data[t],      });    this.palletType = g_palletInfo.max;    let i = [];    for (let s = 0; s < selectedIcube.stores.length; s++)      for (let e = 0; e < selectedIcube.stores[s].dimension.length; e++) {        var r = selectedIcube.getStoreIndex(          selectedIcube.stores[s].dimension[e]        );        for (          let t = 0;          t < selectedIcube.stores[s].positions[e][g_palletInfo.max].length;          t++        )          i.push({            col: selectedIcube.stores[s].row,            height: selectedIcube.stores[s].height,            idx: t,            max:              selectedIcube.stores[s].positions[e][g_palletInfo.max].length - 1,            position: new BABYLON.Vector3(              selectedIcube.stores[s].positions[e][g_palletInfo.max][t][0],              selectedIcube.stores[s].positions[e][g_palletInfo.max][t][1],              selectedIcube.stores[s].positions[e][g_palletInfo.max][t][2]            ),            rotationY: this.isHorizontal ? 0 : -Math.PI / 2,            slotId: r,            type: g_palletInfo.max,          });      }    for (let t = this.ports[0].length - 1; 0 <= t; t--) {      const s = this._setPorts(this.ports[0][t], i, Task.Input);      null !== s        ? ((s.reserved = []), (this.ports[0][t] = s))        : this.ports[0].splice(t, 1);    }    for (let t = this.ports[1].length - 1; 0 <= t; t--) {      const o = this._setPorts(this.ports[1][t], i, Task.Output);      null !== o        ? ((o.reserved = []), (this.ports[1][t] = o))        : this.ports[1].splice(t, 1);    }    if (0 === this.ports[0].length || 0 === this.ports[1].length)      return (        (this.error = "设置输入/输出端口时出错"),        void Utils.logg(this.error, "error")      );    (this.ports[0] = this.ports[0].sort((t, e) => t.col - e.col)),      (this.ports[1] = this.ports[1].sort((t, e) => t.col - e.col));    for (let e = i.length - 1; 0 <= e; e--) {      for (let t = 0; t < this.ports[0].length; t++)        i[e] &&          i[e].col === this.ports[0][t].col &&          i[e].height === this.ports[0][t].height &&          i[e].slotId === this.ports[0][t].slotId &&          i.splice(e, 1);      for (let t = 0; t < this.ports[1].length; t++)        i[e] &&          i[e].col === this.ports[1][t].col &&          i[e].height === this.ports[1][t].height &&          i[e].slotId === this.ports[1][t].slotId &&          i.splice(e, 1);    }    for (let t = this.chargers.length - 1; 0 <= t; t--) {      var e = this._setPorts(        this.chargers[t],        i,        null,        this.chargers[t].height      );      null !== e ? (this.chargers[t] = e) : this.chargers.splice(t, 1);    }    if (0 === this.chargers.length)      return (        (this.error = "设置充电器时出错"), void Utils.logg(this.error, "error")      );    for (let e = i.length - 1; 0 <= e; e--)      for (let t = 0; t < this.chargers.length; t++)        i[e] &&          i[e].col === this.chargers[t].col &&          i[e].height === this.chargers[t].height &&          i[e].slotId === this.chargers[t].slotId &&          i.splice(e, 1);    for (let e = 0; e < this.lifts.length; e++) {      var t = this.xTracks.filter(        t => t.props[this.isHorizontal ? 1 : 0] === this.lifts[e].row      );      this.lifts[e].entry = t;    }    this._setPalletSlots(i, Task.Output), this._setPalletSlots(i, Task.Input);  }  start() {    if (      0 === this.slots.length ||      (0 === this.slots[0].length && 0 === this.slots[1].length) ||      (0 === this.input && 0 === this.output)    )      return (        (this.error = "错误的模拟数据"), void Utils.logg(this.error, "error")      );    if (0 < this.input && 0 < this.output)      for (        let e = 0;        e < this.carriers.length * (this.sharePath ? 0.5 : 1);        e++      ) {        let t = Task.Input;        this.process === IOProcess.simultan &&          (t = e % 2 == 0 ? Task.Input : Task.Output),          setTimeout(() => {            this._startCarrier(this.carriers[e], t);          }, e * ((1e3 * (t === Task.Input ? this.loadTime : this.unLoadTime)) / this.multiply));      }    else      for (        let t = 0;        t < this.carriers.length * (this.sharePath ? 0.5 : 1);        t++      ) {        const e = 0 < this.output ? Task.Output : Task.Input;        setTimeout(() => {          this._startCarrier(this.carriers[t], e);        }, t * ((1e3 * (e === Task.Input ? this.loadTime : this.unLoadTime)) / this.multiply));      }    (this.time0 = new Date()), (this.isPlaying = !0), renderScene(-1);  }  remove() {    (this.isPlaying = !1),      renderScene(),      scene.stopAllAnimations(),      scene.onAfterRenderObservable.cancelAllCoroutines(),      selectedIcube &&        (selectedIcube.pallets.forEach(t => t.setEnabled(!0)),        selectedIcube.SPSPalletLabels &&          (selectedIcube.SPSPalletLabels.mesh.isVisible = !0)),      this.slots[0].forEach(t => t.forEach(t => t.remove())),      this.slots[1].forEach(t => t.forEach(t => t.remove())),      this.ports[0].forEach(t =>        t.hasOwnProperty("remove") ? t.remove() : null      ),      this.ports[1].forEach(t =>        t.hasOwnProperty("remove") ? t.remove() : null      ),      this.chargers.forEach(t =>        t.hasOwnProperty("remove") ? t.remove() : null      ),      this.carriers.forEach(t => {        (t.node.parent = null),          delete t.time0,          t.reset(),          (t.distance = 0),          (t.jobs = 0),          (t.time = 0),          (t.tasks = []),          (t.status = CarrierState.Idle);      }),      this.lifts.forEach(t => {        delete t.time0, t.reset(), (t.time = 0);      }),      this.debuggers.forEach(t => t.dispose()),      (this.carriers = []),      (this.chargers = []),      (this.ports = [[], []]),      (this.xTracks = []),      (this.lifts = []),      (this.slots = [[], []]);  }  pause() {    const e = new Date();    (this.time += e - this.time0),      this.carriers.forEach(t => {        t.time0 && (t.time += e - t.time0);      }),      this.lifts.forEach(t => {        t.time0 && (t.time += e - t.time0);      }),      scene.animatables.forEach(t => t.pause()),      (this.isPlaying = !1),      renderScene();  }  resume() {    (this.time0 = new Date()),      this.carriers.forEach(t => {        t.time0 && (t.time0 = new Date());      }),      this.lifts.forEach(t => {        t.time0 && (t.time0 = new Date());      }),      scene.animatables.forEach(t => t.restart()),      (this.isPlaying = !0),      renderScene(-1);  }  _getBestPosition(e, s, i, r) {    let o = [],      l = i ? 100 : 0,      n = null;    for (let t = s.length - 1; 0 <= t; t--) {      var a;      s[t].height === r &&        ((a = BABYLON.Vector3.Distance(e.position, s[t].position)),        i ? a < l && ((l = a), (n = s[t])) : a > l && ((l = a), (n = s[t])));    }    if (null !== n)      for (let t = s.length - 1; 0 <= t; t--)        s[t].col === n.col &&          s[t].height === n.height &&          s[t].slotId === n.slotId &&          (o.push(s[t]), s.splice(t, 1));    return o;  }  _setPalletSlots(e, s) {    let i = 0,      r =        this.strategy === Strategy.LIFO          ? selectedIcube.rackingHighLevel - 1          : 0;    for (      ;      i < (s === Task.Input ? this.input : this.output) && 0 < e.length;    ) {      for (let t = 0; t < this.ports[1].length; t++) {        const o = this._getBestPosition(            this.ports[1][t],            e,            this.strategy === Strategy.FIFO,            r          ),          l = [];        for (let t = 0; t < o.length; t++) {          (o[t].ports = this.ports[1]),            (o[t].task = s),            (o[t].strategy = this.strategy);          const n = new Slot(o[t], this.xTracks);          s === Task.Output && n.addPallet(), l.push(n), i++;        }        0 < l.length && this.slots[s === Task.Input ? 0 : 1].push(l);      }      r =        this.strategy === Strategy.LIFO          ? 0 === r            ? selectedIcube.rackingHighLevel - 1            : r - 1          : r === selectedIcube.rackingHighLevel - 1          ? 0          : r + 1;    }  }  _setPorts(e, s, t = null, i = 0) {    let r = null,      o = -1;    for (let t = 0; t < selectedIcube.infos.cols.length; t++)      if (        selectedIcube.infos.cols[t].includes(this.isHorizontal ? e.row : e.col)      ) {        o = t;        break;      }    for (let t = 0; t < s.length; t++)      if (        s[t].height === i &&        s[t].col === (this.isHorizontal ? e.col : e.row) &&        s[t].slotId === o      ) {        var l = e.hasOwnProperty("portPosition")          ? e.portPosition          : e.chargerPos;        if (l === (this.isHorizontal ? "bottom" : "left") && 0 === s[t].idx) {          r = s[t];          break;        }        if (          l === (this.isHorizontal ? "top" : "right") &&          s[t].idx === s[t].max        ) {          r = s[t];          break;        }      }    return r ? ((r.task = t), new Slot(r, this.xTracks)) : null;  }  _getNextTarget(e) {    if (!e.store) return null;    var t = e.store.filter(t =>      e.task === Task.Input ? null === t.pallet : null !== t.pallet    );    return 0 !== t.length && t[0].entry      ? this._getPallet(e, t, t[0].entry.position)      : null;  }  _getPallet(e, s, i) {    let r = null,      o = e.task === Task.Output ? 100 : 0;    for (let t = 0; t < s.length; t++) {      var l = BABYLON.Vector3.Distance(i, s[t].position);      e.task === Task.Output        ? o > l && ((o = l), (r = s[t]))        : o < l && ((o = l), (r = s[t]));    }    return r;  }  _getClosestElement(s, i) {    let r = 1e3,      o = null;    for (let e = 0; e < s.length; e++) {      let t;      if (s[e].node) t = BABYLON.Vector3.Distance(s[e].node.position, i);      else if (Array.isArray(s[e])) {        if (s[e][0].hasOwnProperty("reserved"))          if (Array.isArray(s[e][0].reserved)) {            if (s[e][0].reserved.length) continue;          } else if (s[e][0].reserved) continue;        t = BABYLON.Vector3.Distance(s[e][0].position, i);      } else t = BABYLON.Vector3.Distance(s[e].position, i);      t < r && ((r = t), (o = s[e]));    }    return o;  }  _getPathBetweenTwoSlots(e, s, t) {    let i = [];    if (e.height === s.height) {      const l = this.isHorizontal ? 1 : 0;      e.entry.props[3] === s.entry.props[3]        ? (i =            e.entry.props[l] === s.entry.props[l]              ? [e.position, s.position]              : [e.position, e.entry.position, s.entry.position, s.position])        : ((o = parseInt(Math.abs(e.slotId - s.slotId) / 2)),          this._hasPallet(e.col, o)            ? this._hasPallet(s.col, o)              ? -1 !== this._getAvailableCol(e.col, o) &&                ((o = this.xTracks.filter(                  t =>                    t.props[this.isHorizontal ? 1 : 0] === e.col &&                    0 === t.props[2]                )),                (r = this._getClosestElement(o, e.entry.position)),                (o = this._getClosestElement(o, s.entry.position)),                (i = [                  e.position,                  e.entry.position,                  r.position,                  o.position,                  s.entry.position,                  s.position,                ]))              : ((r = this.xTracks.filter(                  t => t.props[l] === s.col && 0 === t.props[2]                )),                (o = this._getClosestElement(r, e.entry.position)),                (i = [e.position, e.entry.position, o.position, s.position]))            : ((r = this.xTracks.filter(                t => t.props[l] === e.col && 0 === t.props[2]              )),              (o = this._getClosestElement(r, s.entry.position)),              (i = [e.position, o.position, s.entry.position, s.position])));    } else if (t.lift) {      i = [[], []];      const n = t.lift;      i[0].push(e.position);      var r = n.entry.filter(t => t.props[2] === e.height);      const a = this._getClosestElement(r, e.entry.position);      var o = n.entry.filter(t => t.props[2] === s.height);      const h = this._getClosestElement(o, s.entry.position),        p = this.isHorizontal ? 0 : 1;      if (e.entry.props === a.props) i[0].push(n.node.position);      else if (a.props[p] === e.entry.props[p])        i[0].push(e.entry.position, a.position, n.node.position);      else {        let t = this.xTracks.filter(          t =>            t.props[2] === e.entry.props[2] &&            t.props[p] === a.props[p] &&            t.props[1 - p] === e.entry.props[1 - p]        );        0 ===        (t =          0 === t.length            ? this.xTracks.filter(                t =>                  t.props[2] === e.entry.props[2] &&                  t.props[p] === e.entry.props[p] &&                  t.props[1 - p] === a.props[1 - p]              )            : t).length          ? i[0].push(e.entry.position, a.position, n.node.position)          : i[0].push(              e.entry.position,              t[0].position,              a.position,              n.node.position            );      }      if (        (i[1].push(          new BABYLON.Vector3(            n.node.position.x,            s.position.y,            n.node.position.z          )        ),        s.entry.props[0] === h.props[0] && s.entry.props[1] === h.props[1])      )        i[1].push(s.position);      else if (h.props[p] === s.entry.props[p])        i[1].push(h.position, s.entry.position, s.position);      else {        let t = this.xTracks.filter(          t =>            t.props[2] === s.entry.props[2] &&            t.props[p] === h.props[p] &&            t.props[1 - p] === s.entry.props[1 - p]        );        0 ===        (t =          0 === t.length            ? this.xTracks.filter(                t =>                  t.props[2] === s.entry.props[2] &&                  t.props[p] === s.entry.props[p] &&                  t.props[1 - p] === h.props[1 - p]              )            : t).length          ? i[1].push(h.position, s.entry.position, s.position)          : i[1].push(h.position, t[0].position, s.entry.position, s.position);      }      t.pathLength === CarrierPath.ToLift        ? (t.paired && (t.paired.points = i[1].reverse()), (i = i[0]))        : t.pathLength === CarrierPath.FromLift &&          (t.paired && (t.paired.points = i[0].reverse()), (i = i[1]));    }    if (this.showHelper && 0 < i.length) {      let t;      Array.isArray(i[0])        ? (((t = BABYLON.Mesh.CreateLines("asd", i[0], scene)).color =            BABYLON.Color3.Red()),          this.debuggers.push(t),          ((t = BABYLON.Mesh.CreateLines("asd", i[1], scene)).color =            BABYLON.Color3.Red()))        : ((t = BABYLON.Mesh.CreateLines("asd", i, scene)).color =            BABYLON.Color3.Red()),        this.debuggers.push(t);    }    return i;  }  _startCarrier(t, e, s = !1) {    if (t) {      t.reset(),        (t.task = e),        t.tasks.push(e),        (t.status = CarrierState.Working);      const i = this.ports[e].reduce((t, e) =>        t.reserved.length <= e.reserved.length ? t : e      );      if ((i.reserved.push(t), (t.port = i), s)) return t;      this._searchForJob(t);    }  }  _stopCarrier(t, e = !1) {    t.paired &&      e &&      ((t.paired.status = CarrierState.Idle),      t.paired.reset(),      delete t.paired.time0),      (t.status = CarrierState.Idle),      t.reset(),      delete t.time0;    let s = [0, 0];    this.slots[0].forEach(t => {      s[0] += t.filter(t => null === t.pallet).length;    }),      this.slots[1].forEach(t => {        s[1] += t.filter(t => null !== t.pallet).length;      }),      ((this.inputCount === this.input && 0 === s[1]) ||        (this.outputCount === this.output && 0 === s[0]) ||        (0 === s[0] && 0 === s[1])) &&        endSimulation();  }  _waitForLiftHandOff(e) {    const s = setInterval(() => {      const t = this.lifts.filter(t => t.reserved === e && !0 === t.inPosition);      0 < t.length &&        (clearInterval(s),        (t[0].inPosition = !1),        (e.lift = t[0]),        e.pathLength === CarrierPath.ToLift          ? this._searchForJob(e)          : this.beginJob(e));    }, 1e3 / this.multiply);  }  _waitForLift(s) {    const i = setInterval(() => {      var t = this.lifts.filter(t => !0 === t.wait);      if (0 < t.length) {        clearInterval(i);        const e = this._getClosestLift(t, s);        ((s.lift = e).wait = !1),          ((e.reserved = s).points = this._getPathBetweenTwoSlots(            s.port,            s.slot,            s          )),          this.beginJob(s);      }    }, 1e3 / this.multiply);  }  _waitForCharger(e) {    const s = setInterval(() => {      const t = this.chargers.filter(t => null === t.reserved);      0 < t.length &&        (clearInterval(s),        (e.charger = t[0]),        ((t[0].reserved = e).time = new Date()),        (e.status = CarrierState.Charging),        (e.node.position = t[0].position));    }, 1e3 / this.multiply);  }  _searchForJob(e) {    if (this.inputCount === this.input && this.outputCount === this.output)      return (        this._stopCarrier(e, !0),        void (          0 ===            this.carriers.filter(t => t.status === CarrierState.Working)              .length && endSimulation()        )      );    if (this.inputCount === this.input) {      if (e.task === Task.Input)        return (          e.paired && this._stopCarrier(e.paired),          void this._startCarrier(e, 1 - e.task)        );    } else if (this.outputCount === this.output && e.task === Task.Output)      return (        e.paired && this._stopCarrier(e.paired),        void this._startCarrier(e, 1 - e.task)      );    if (e.time > this.workingTime * Math.round(1 + 2 * Math.random()))      return (        e.paired && this._startCarrier(e.paired, e.task),        this._stopCarrier(e, !1),        (e.status = CarrierState.Empty),        void this._waitForCharger(e)      );    if (!e.store) {      const s = this._getClosestElement(        this.slots[e.task],        e.port.position          .clone()          .addInPlace(            new BABYLON.Vector3(              0,              selectedIcube.getHeightAtLevel(                Math.floor(Math.random() * (selectedIcube.rackingHighLevel + 1))              ),              0            )          )      );      if (!s)        return 1 < e.tasks.length          ? void this._stopCarrier(e, !0)          : (e.paired && this._stopCarrier(e.paired),            void this._startCarrier(e, 1 - e.task));      s.forEach(t => (t.reserved = e)), (e.store = s);    }    var t = this._getNextTarget(e);    if (!t) return (e.store = null), void this._searchForJob(e);    if (      ((e.slot = t),      e.task === Task.Input ? this.inputCount++ : this.outputCount++,      0 < t.height && !e.lift)    ) {      t = this.lifts.filter(t => !0 === t.wait);      if (0 === t.length) return void this._waitForLift(e);      const i = this._getClosestLift(t, e);      ((e.lift = i).wait = !1), (i.reserved = e);    }    (e.points = this._getPathBetweenTwoSlots(e.port, e.slot, e)),      e.paired &&        ((e.paired.store = e.store),        (e.paired.slot = e.slot),        (e.paired.position = e.slot.position)),      this.beginJob(e);  }  beeginLiftAnimationWithCarrier(r, t, o = !1) {    const e = r.lift.createAnimation(t, this.multiply),      l =        ((r.lift.platform.animations = [e]),        (r.node.parent = r.lift.platform),        (r.node.position = BABYLON.Vector3.Zero()),        e.getHighestFrame());    o || (r.lift.time0 = new Date()),      scene.beginAnimation(r.lift.platform, 0, l, !1, 1, () => {        (r.node.parent = null),          (r.node.position = r.lift.node.position),          o &&            ((r.lift.time += new Date() - r.lift.time0),            delete r.lift.time0,            (r.lift.wait = !0),            (r.lift.reserved = null),            (r.lift = null));        const t = r.createAnimation(r.points[o ? 0 : 1], this.multiply),          i = ((r.node.animations = [t]), t.getHighestFrame());        (r.time0 = new Date()),          scene.beginAnimation(r.node, o ? i : 0, o ? 0 : i, !1, 1, () => {            if (((r.time += new Date() - r.time0), delete r.time0, o))              this._searchForJob(r);            else {              if (                (r.togglePallet(this.palletType, r.task !== Task.Input),                r.task === Task.Input                  ? (r.slot.addPallet(), r.port.addPallet())                  : (r.slot.removePallet(), r.port.removePallet()),                this.sharePath)              ) {                var t = this.carriers.filter(                  t => t.status === CarrierState.Idle                );                if (0 < t.length) {                  t = t[0];                  if (r.task === Task.Input) {                    (r.lift.wait = !0),                      (r.lift.time0 = new Date()),                      scene.beginAnimation(r.lift.platform, l, 0, !1, 1, () => {                        r.lift &&                          ((r.lift.time += new Date() - r.lift.time0),                          delete r.lift.time0,                          (r.lift.reserved = null),                          (r.lift = null));                      });                    const e = this._startCarrier(t, r.task, !0);                    (e.paired = r),                      (e.pathLength = CarrierPath.ToLift),                      (e.store = r.store),                      (r.paired = e),                      (r.pathLength = CarrierPath.FromLift),                      this._waitForLiftHandOff(r),                      this._searchForJob(e);                  } else {                    const s = this._startCarrier(t, r.task, !0);                    (s.paired = r),                      (s.pathLength = CarrierPath.ToLift),                      (s.store = r.store),                      (r.paired = s),                      (r.pathLength = CarrierPath.FromLift),                      this._waitForLiftHandOff(s),                      this.beginJob(r);                  }                  return;                }              }              (r.time0 = new Date()),                scene.beginAnimation(r.node, i, 0, !1, 1, () => {                  (r.time += new Date() - r.time0),                    delete r.time0,                    this.beeginLiftAnimationWithCarrier(                      r,                      [r.points[1][0].y, r.points[0][0].y],                      !0                    );                });            }          });      });  }  beginJob(s) {    s.setPalletHeight(this.palletType, this.getLevelHeight(s.slot.height)),      s.pathLength === CarrierPath.Full        ? (s.togglePallet(this.palletType, s.task === Task.Input),          s.port.removePallet(),          s.task === Task.Output && 0 < this.outputCount && s.port.addPallet())        : s.pathLength === CarrierPath.ToLift        ? s.togglePallet(this.palletType, s.task === Task.Input)        : s.togglePallet(this.palletType, s.task !== Task.Input),      (s.jobs += 1),      (s.time0 = new Date());    let t;    (t = Array.isArray(s.points[0])      ? s.createAnimation(s.points[0], this.multiply)      : s.createAnimation(s.points, this.multiply)),      (s.node.animations = [t]);    const i = t.getHighestFrame();    (s.time0 = new Date()),      scene.beginAnimation(s.node, 0, i, !1, 1, () => {        if (          ((s.time += new Date() - s.time0),          delete s.time0,          this.sharePath && s.pathLength !== CarrierPath.Full)        ) {          s.lift.setPalletHeight(            this.palletType,            this.getLevelHeight(s.slot.height)          ),            s.pathLength === CarrierPath.ToLift              ? (s.togglePallet(this.palletType, s.task !== Task.Input),                s.lift.togglePallet(this.palletType, s.task === Task.Input),                (s.lift.time0 = new Date()))              : (s.togglePallet(this.palletType, s.task === Task.Input),                s.lift.togglePallet(this.palletType, s.task !== Task.Input),                (s.lift.time += new Date() - s.lift.time0),                delete s.lift.time0);          const t = s.lift.createAnimation(              [0, s.slot.position.y],              this.multiply            ),            e = ((s.lift.platform.animations = [t]), t.getHighestFrame());          setTimeout(() => {            s.lift &&              scene.beginAnimation(                s.lift.platform,                s.pathLength === CarrierPath.ToLift ? 0 : e,                s.pathLength === CarrierPath.ToLift ? e : 0,                !1,                1,                () => {                  s.lift.reserved = s.paired;                }              );          }, (2e3 * s.wheelsetChangeTime) / this.multiply),            (s.time0 = new Date()),            scene.beginAnimation(s.node, i, 0, !1, 1, () => {              (s.time += new Date() - s.time0),                delete s.time0,                this._waitForLiftHandOff(s),                s.pathLength === CarrierPath.FromLift &&                  (s.task === Task.Input                    ? s.slot.addPallet()                    : s.slot.removePallet()),                (s.lift.inPosition = !0);            });        } else          s.lift            ? this.beeginLiftAnimationWithCarrier(s, [                s.points[0][0].y,                s.points[1][0].y,              ])            : (s.togglePallet(this.palletType, s.task !== Task.Input),              s.task === Task.Input                ? (s.slot.addPallet(), s.port.addPallet())                : (s.slot.removePallet(), s.port.removePallet()),              (s.time0 = new Date()),              scene.beginAnimation(s.node, i, 0, !1, 1, () => {                (s.time += new Date() - s.time0),                  delete s.time0,                  this._searchForJob(s);              }));      });  }  _getClosestLift(s, t) {    let i = s[0];    if (0 === this.liftAssign)      i = this._getClosestElement(s, t.port.entry.position);    else if (      0 < this.slots[parseInt(t.task)].length &&      0 < this.slots[parseInt(t.task)][0].length    ) {      let e = 1e3;      var r,        o = t.port.entry.props[this.isHorizontal ? 1 : 0];      for (let t = 0; t < s.length; t++)        s[t].wait ||          ((r = this.isHorizontal ? s[t].col : s[t].row),          (r = Math.abs(r - o)) < e && ((e = r), (i = s[t])));    }    return i;  }  _hasPallet(e, s) {    var t = this.slots[0].filter(        t => t[0].col === e && t[0].slotId === s && null !== t[0].pallet      ),      i = this.slots[1].filter(        t => t[0].col === e && t[0].slotId === s && null !== t[0].pallet      );    return 0 < t.length || 0 < i.length;  }  _getAvailableCol(t, e) {    let s = -1;    if (      2 * t >      (this.isHorizontal ? selectedIcube.maxCol : selectedIcube.maxRow) - 1    ) {      for (        let t =          (this.isHorizontal ? selectedIcube.maxCol : selectedIcube.maxRow) - 1;        0 <= t;        t--      )        if (!this._hasPallet(t, e)) {          s = t;          break;        }    } else      for (        let t = 0;        t <        (this.isHorizontal ? selectedIcube.maxCol : selectedIcube.maxRow) - 1;        t++      )        if (!this._hasPallet(t, e)) {          s = t;          break;        }    return s;  }  _debug(e, s) {    let i = [];    for (let t = 0; t < e.length; t++) {      const r = new BABYLON.Mesh.CreateBox("slots" + t, 0.8, scene);      (r.position = e[t].position),        (r.renderOverlay = !0),        (r.overlayColor = s),        this.debuggers.push(r),        i.push([e[t].position.x, e[t].position.y + 0.41, e[t].position.z]);    }    var t = _generateLabels(      i,      "",      !0,      Math.PI / 2,      this.isHorizontal ? 0 : Math.PI / 2    );    this.debuggers.push(t);  }  getLevelHeight(e) {    let t = selectedIcube.palletHeight;    var s = selectedIcube.palletAtLevel.filter(t => t.idx === e + 1);    return (t = 0 < s.length ? parseFloat(s[0].height) : t);  }}const Strategy = {    FIFO: 0,    LIFO: 1,  },  IOProcess = {    simultan: 0,    apart: 1,  },  Task = {    None: -1,    Input: 0,    Output: 1,  };class Slot {  constructor(t, e) {    for (var s in t) this[s] = t[s];    (this.xtracks = []),      (this.entry = null),      (this.pallet = null),      (this.reserved = null),      (this.isHorizontal = 0 === this.rotationY),      this.init(e);  }  init(t) {    var e,      s,      i,      t = t.filter(        t =>          t.props[2] === this.height &&          t.props[this.isHorizontal ? 1 : 0] === this.col      );    0 !== t.length &&      ((e = this.getClosestXtrack(        t,        this.isHorizontal          ? new BABYLON.Vector3(0, 0, 1)          : new BABYLON.Vector3(1, 0, 0)      )),      (t = this.getClosestXtrack(        t,        this.isHorizontal          ? new BABYLON.Vector3(0, 0, -1)          : new BABYLON.Vector3(-1, 0, 0)      )),      e && t        ? ((this.xtracks = [e, t]),          this.ports            ? ((i = this.getClosestPort(this.ports, this.xtracks[0].position)),              (s = this.getClosestPort(this.ports, this.xtracks[1].position)),              (i = BABYLON.Vector3.Distance(                i.position,                this.xtracks[0].position              )),              (s = BABYLON.Vector3.Distance(                s.position,                this.xtracks[1].position              )),              this.strategy === Strategy.LIFO                ? (this.entry = this.xtracks[i < s ? 0 : 1])                : (this.entry = this.xtracks[s < i ? 0 : 1]))            : ((s = BABYLON.Vector3.Distance(                this.position,                this.xtracks[0].position              )),              (i = BABYLON.Vector3.Distance(                this.position,                this.xtracks[1].position              )),              this.strategy === Strategy.LIFO                ? (this.entry = this.xtracks[s < i ? 0 : 1])                : (this.entry = this.xtracks[i < s ? 0 : 1])))        : ((this.xtracks = e ? [e] : [t]), (this.entry = this.xtracks[0])));  }  remove() {    this.removePallet(),      (this.entry = null),      (this.xtracks = []),      (this.pallet = null),      (this.reserved = null),      (this.task = Task.None);  }  addPallet() {    var t;    this.pallet ||      ((t = selectedIcube.palletAtLevel.filter(t => t.idx === this.height + 1)),      (this.pallet = new Pallet(        this.type,        0 < t.length ? t[0].height : selectedIcube.palletHeight      )),      this.pallet.setPosition(this.position),      this.pallet.setRotation(new BABYLON.Vector3(0, this.rotationY, 0)));  }  removePallet() {    this.pallet && (this.pallet.remove(), (this.pallet = null));  }  getClosestXtrack(e, s) {    let i = 1e3,      r = null;    for (let t = 0; t < e.length; t++) {      const l = this.position.clone();      var o = l.subtractInPlace(e[t].position).normalize();      Math.round(o.x) === s.x &&        Math.round(o.y) === s.y &&        Math.round(o.z) === s.z &&        (o = BABYLON.Vector3.Distance(e[t].position, this.position)) < i &&        ((i = o), (r = e[t]));    }    return r;  }  getClosestPort(e, s) {    let i = 1e3,      r = null;    for (let t = 0; t < e.length; t++) {      var o = BABYLON.Vector3.Distance(e[t].position, s);      o < i && ((i = o), (r = e[t]));    }    return r;  }}
 |