PathCreator

Create path never been so easy

当前为 2018-01-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         PathCreator
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Create path never been so easy
// @author       Drigtime
// @match        https://dofus-map.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

var icon = [
    L.icon({
        iconUrl: 'https://svgshare.com/i/54N.svg', // Top
        className: 'top-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54m.svg', // Left
        className: 'left-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/51x.svg', // Bottom
        className: 'bottom-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/53t.svg', // Right
        className: 'right-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/556.svg', // Top Gather
        className: 'top-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/555.svg', // Left Gather
        className: 'left-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54b.svg', // Bottom Gather
        className: 'bottom-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54p.svg', // Right Gather
        className: 'right-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/53n.svg', // Top Fight
        className: 'top-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54H.svg', // Left Fight
        className: 'left-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54o.svg', // Bottom Fight
        className: 'bottom-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/527.svg', // Right Fight
        className: 'right-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54G.svg', // Top Bank
        className: 'top-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54w.svg', // Right Bank
        className: 'right-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54v.svg', // Left Bank
        className: 'left-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/53x.svg', // Bottom Bank
        className: 'bottom-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54x.svg', // Top Phenix
        className: 'top-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/557.svg', // Left Phenix
        className: 'left-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/54q.svg', // Bottom Phenix
        className: 'bottom-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/543.svg', // Right Phenix
        className: 'right-arrow'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/58M.svg', // Havenbag Move
        className: 'havenbag-icon'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/58N.svg', // Havenbag Gather
        className: 'havenbag-icon'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/5BW.svg', // Havenbag Fight
        className: 'havenbag-icon'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/5BL.svg', // Havenbag Bank
        className: 'havenbag-icon'
    }),
    L.icon({
        iconUrl: 'https://svgshare.com/i/5BB.svg', // Havenbag Phoenix
        className: 'havenbag-icon'
    }),
];

var actualMap;
var pathData = [];
var bankData = [];
var phenixData = [];
var havenBagData = [];

var ressources = [
    [1, "Frêne"],
    [8, "Chêne"],
    [17, "Fer"],
    [24, "Argent"],
    [25, "Or"],
    [26, "Pierre de Bauxite"],
    [28, "If"],
    [29, "Ebène"],
    [30, "Orme"],
    [31, "Erable"],
    [32, "Charme"],
    [33, "Châtaignier"],
    [34, "Noyer"],
    [35, "Merisier"],
    [37, "Pierre de Kobalte"],
    [38, "Blé"],
    [39, "Houblon"],
    [42, "Lin"],
    [43, "Orge"],
    [44, "Seigle"],
    [45, "Avoine"],
    [46, "Chanvre"],
    [47, "Malt"],
    [48, "Tas de patates"],
    [52, "Etain"],
    [53, "Pierre Cuivrée"],
    [54, "Manganèse"],
    [55, "Bronze"],
    [61, "Edelweiss"],
    [63, "Froment"],
    [64, "Epeautre"],
    [65, "Sorgho"],
    [66, "Menthe Sauvage"],
    [67, "Trèfle à 5 feuilles"],
    [68, "Orchidée Freyesque"],
    [71, "Greuvette"],
    [72, "Somoon Agressif"],
    [73, "Pwoulpe"],
    [74, "Truite"],
    [75, "Goujon"],
    [76, "Poisson-Chaton"],
    [77, "Crabe"],
    [78, "Poisson Pané"],
    [79, "Carpe d'Iem"],
    [80, "Truite Vaseuse"],
    [81, "Sardine Brillante"],
    [82, "Coton"],
    [84, "Puits"],
    [98, "Bombu"],
    [99, "Ombre étrange"],
    [100, "Pichon"],
    [101, "Oliviolet"],
    [102, "Machine de force"],
    [104, "Koinkoin"],
    [108, "Bambou"],
    [109, "Bambou sombre"],
    [110, "Bambou sacré"],
    [111, "Riz"],
    [112, "Pandouille"],
    [113, "Dolomite"],
    [114, "Silicate"],
    [121, "Kaliptus"],
    [131, "Perce-neige"],
    [132, "Poisskaille"],
    [133, "Tremble"],
    [134, "Frostiz"],
    [135, "Obsidienne"],
    [136, "Coquillage"],
    [137, "Machine à coudre de Poss'Ybel"],
    [138, "Fabrique"],
    [141, "Établi de mauvaise qualité"],
    [142, "Machine à coudre de mauvaise qualité"],
    [143, "Machine à jouets"],
    [144, "Pressoir à poisson"],
    [146, "Paquet Cadeau"],
    [167, "Arène"],
    [168, "Banque"],
    [169, "Bar Akouda"],
    [170, "Bibliothèque"],
    [171, "Boutiques de Nowel"],
    [172, "Dojo"],
    [173, "Église"],
    [174, "Épicerie"],
    [175, "Fabricant de skis"],
    [176, "Hôtel de ville"],
    [177, "Hôtel des métiers"],
    [178, "Kanojedo"],
    [179, "Kolizéum"],
    [180, "Milice"],
    [181, "Médecin de Frigost"],
    [206, "Sous-marin Steamer"],
    [207, "Autel"],
    [208, "Krosmaster"],
    [219, "Métier d'Avenir"],
    [220, "Tonneau d'explosifs"],
    [221, "Fleur de Sutol"],
    [222, "Barbecue"],
    [223, "Cawotte fraîche"],
    [224, "Alambic patiné de l'hôtel des métiers"],
    [225, "Bouteille de Rhum"],
    [226, "Ascenseur"],
    [227, "Champignon"],
    [230, "Portail des Bworks"],
    [231, "Distributeur de missions"],
    [232, "Portail"],
    [234, "Glaçon"],
    [235, "Aller vers"],
    [236, "Pupitre"],
    [253, "Portail Eliotrope"],
    [254, "Ortie"],
    [255, "Sauge"],
    [256, "Ginseng"],
    [257, "Belladone"],
    [258, "Mandragore"],
    [259, "Noisetier"],
    [260, "Maïs"],
    [261, "Millet"],
    [262, "Bloc de pierre"],
    [263, "Brochet"],
    [264, "Kralamoure"],
    [265, "Anguille"],
    [266, "Dorade Grise"],
    [267, "Perche"],
    [268, "Raie"],
    [269, "Lotte"],
    [270, "Requin Marteau-Faucille"],
    [271, "Bar Rikain"],
    [272, "Morue"],
    [273, "Tanche"],
    [274, "Espadon"],
    [275, "Enclume de Mulic Bere"],
    [276, "Établi de Mulic Bere"],
    [278, "Assembleur de Mulic Bere"],
    [280, "Plate-forme Huppermage"],
    [281, "Trèfle à 4 feuilles"],
    [282, "Indiquer une sortie"],
    [283, "Chathon"],
    [284, "Escalier"],
    [285, "Porte blindée"],
    [287, "Aquajou"],
    [288, "Salikrone"],
    [289, "Quisnoa"],
    [290, "Patelle"],
    [291, "Écume de mer"],
    [293, "Écume de mer"],
    [294, "Aquajou"],
    [295, "Salikrone"],
    [296, "Quisnoa"],
    [297, "Patelle"],
    [299, "Œufs frais"]
];
var picker = 4;
var gatherData = [];
var loadingFile = false;
var havenToggle = false;

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://code.jquery.com/jquery-3.2.1.slim.min.js';
document.getElementsByTagName('head')[0].appendChild(script);
setTimeout(function () {
    var script2 = document.createElement('script');
    script2.type = 'text/javascript';
    script2.src = 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.3/js/bootstrap.js';
    document.getElementsByTagName('head')[0].appendChild(script2);
}, 500);
var script1 = document.createElement('script');
script1.type = 'text/javascript';
script1.src = 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js';
document.getElementsByTagName('head')[0].appendChild(script1);
var css = document.createElement('style');
css.type = 'text/css';
css.textContent = '.checkbox.checkbox-inline,.radio.radio-inline{margin-top:0}#pathcreator{background:#212121;border-radius:5px;padding:10px;color:#fff;box-shadow:0 0 10px 0 rgba(0,0,0,.6);font-family:arial;opacity:.95}.row{padding-top:.5rem;padding-left:1rem}.checkbox{padding-left:20px}.checkbox label{display:inline-block;position:relative;padding-left:5px}.checkbox label::after,.checkbox label::before{position:absolute;margin-left:-20px;display:inline-block;left:0}.checkbox label::before{content:"";width:17px;height:17px;border:1px solid #ccc;border-radius:3px;background-color:#fff;-webkit-transition:border .15s ease-in-out,color .15s ease-in-out;-o-transition:border .15s ease-in-out,color .15s ease-in-out;transition:border .15s ease-in-out,color .15s ease-in-out}.checkbox label::after{width:16px;height:16px;top:0;padding-left:3px;padding-top:1px;font-size:11px;color:#555}.checkbox input[type=checkbox]{opacity:0}.checkbox input[type=checkbox]:checked+label::after{font-family:FontAwesome;content:"\\f00c"}.checkbox input[type=checkbox]:disabled+label{opacity:.65}.checkbox input[type=checkbox]:disabled+label::before{background-color:#eee;cursor:not-allowed}.checkbox.checkbox-circle label::before{border-radius:50%}.checkbox-primary input[type=checkbox]:checked+label::before{background-color:#428bca;border-color:#428bca}.checkbox-primary input[type=checkbox]:checked+label::after{color:#fff}.radio{padding-left:20px}.radio label{display:inline-block;position:relative;padding-left:5px}.radio label::after,.radio label::before{display:inline-block;position:absolute;margin-left:-20px}.radio label::before{content:"";width:17px;height:17px;left:0;border:1px solid #ccc;border-radius:50%;background-color:#fff;-webkit-transition:border .15s ease-in-out;-o-transition:border .15s ease-in-out;transition:border .15s ease-in-out}.radio label::after{content:" ";width:11px;height:11px;left:3px;top:3px;border-radius:50%;background-color:#555;-webkit-transform:scale(0,0);-ms-transform:scale(0,0);-o-transform:scale(0,0);transform:scale(0,0);-webkit-transition:-webkit-transform .1s cubic-bezier(.8,-.33,.2,1.33);-moz-transition:-moz-transform .1s cubic-bezier(.8,-.33,.2,1.33);-o-transition:-o-transform .1s cubic-bezier(.8,-.33,.2,1.33);transition:transform .1s cubic-bezier(.8,-.33,.2,1.33)}.radio-primary input[type=radio]+label::after,.radio-primary input[type=radio]:checked+label::after{background-color:#428bca}.radio input[type=radio]{opacity:0}.radio input[type=radio]:checked+label::after{-webkit-transform:scale(1,1);-ms-transform:scale(1,1);-o-transform:scale(1,1);transform:scale(1,1)}.radio input[type=radio]:disabled+label{opacity:.65}.radio input[type=radio]:disabled+label::before{cursor:not-allowed}.radio-primary input[type=radio]:checked+label::before{border-color:#428bca}.radio-phenix input[type=radio]+label::after,.radio-phenix input[type=radio]:checked+label::after{background-color:#ab37c8}.radio-phenix input[type=radio]:checked+label::before{border-color:#ab37c8}.radio-danger input[type=radio]+label::after,.radio-danger input[type=radio]:checked+label::after{background-color:#d9534f}.radio-danger input[type=radio]:checked+label::before{border-color:#d9534f}.radio-success input[type=radio]+label::after,.radio-success input[type=radio]:checked+label::after{background-color:#5cb85c}.radio-success input[type=radio]:checked+label::before{border-color:#5cb85c}.btn-secondary{color:#bfbfbf;background-color:#0d0d0d;border-color:#1a1a1a}.btn-secondary.active,.btn-secondary:active,.btn-secondary:focus,.btn-secondary:hover,.open .dropdown-toggle.btn-secondary{color:#bfbfbf;background-color:#1a1a1a;border-color:#0d0d0d}.btn-file{position:relative;overflow:hidden}.btn-file input[type=file]{position:absolute;top:0;right:0;min-width:100%;min-height:100%;font-size:100px;text-align:right;filter:alpha(opacity=0);opacity:0;outline:0;background:#fff;cursor:inherit;display:block}#mapContainer[data-zoom="7"] .top-arrow{width:145px;margin-left:528.5px}#mapContainer[data-zoom="6"] .top-arrow{width:75px;margin-left:262.5px}#mapContainer[data-zoom="5"] .top-arrow{width:36px;margin-left:131.5px}#mapContainer[data-zoom="4"] .top-arrow{width:19px;margin-left:65.75px}#mapContainer[data-zoom="3"] .top-arrow{width:15px;margin-left:30.13px}#mapContainer[data-zoom="2"] .top-arrow{width:9.9px;margin-left:13.86px}#mapContainer[data-zoom="1"] .top-arrow{width:7px;margin-left:5.91px}#mapContainer[data-zoom="0"] .top-arrow{width:5.38px;margin-left:5.01px}#mapContainer[data-zoom="7"] .havenbag-icon{width:500.83px;margin-left:350.5833333px;margin-top:135.8px}#mapContainer[data-zoom="6"] .havenbag-icon{width:250px;margin-left:175px;margin-top:67.5px}#mapContainer[data-zoom="5"] .havenbag-icon{width:124.58px;margin-left:87.20833333px;margin-top:33.35px}#mapContainer[data-zoom="4"] .havenbag-icon{width:61.88px;margin-left:43.3125px;margin-top:16.28px}#mapContainer[data-zoom="3"] .havenbag-icon{width:30.52px;margin-left:21.36458333px;margin-top:7.74px}#mapContainer[data-zoom="2"] .havenbag-icon{width:14.84px;margin-left:10.390625px;margin-top:3.47px}#mapContainer[data-zoom="1"] .havenbag-icon{width:7.01px;margin-left:4.903645833px;margin-top:1.33px}#mapContainer[data-zoom="0"] .havenbag-icon{width:3.09px;margin-left:2.16015625px;margin-top:.27px}#mapContainer[data-zoom="7"] .left-arrow{width:324.26px;margin-top:356.5px}#mapContainer[data-zoom="6"] .left-arrow{width:161.59px;margin-top:177.75px}#mapContainer[data-zoom="5"] .left-arrow{width:80.53px;margin-top:88.38px}#mapContainer[data-zoom="4"] .left-arrow{width:40.13px;margin-top:44.19px}#mapContainer[data-zoom="3"] .left-arrow{width:30.87px;margin-top:19.34px}#mapContainer[data-zoom="2"] .left-arrow{width:23.75px;margin-top:7.42px}#mapContainer[data-zoom="1"] .left-arrow{width:18.27px;margin-top:1.86px}#mapContainer[data-zoom="0"] .left-arrow{width:14.05px;margin-top:1px}#mapContainer[data-zoom="7"] .right-arrow{width:324.26px;margin-left:878.74px;margin-top:356.5px}#mapContainer[data-zoom="6"] .right-arrow{width:161.59px;margin-left:439.41px;margin-top:177.75px}#mapContainer[data-zoom="5"] .right-arrow{width:80.53px;margin-left:219.47px;margin-top:88.38px}#mapContainer[data-zoom="4"] .right-arrow{width:40.13px;margin-left:110.37px;margin-top:44.19px}#mapContainer[data-zoom="3"] .right-arrow{width:30.87px;margin-left:43.38px;margin-top:19.34px}#mapContainer[data-zoom="2"] .right-arrow{width:23.75px;margin-left:12.88px;margin-top:7.42px}#mapContainer[data-zoom="1"] .right-arrow{width:18.27px;margin-left:1px;margin-top:1.86px}#mapContainer[data-zoom="0"] .right-arrow{width:14.05px;margin-left:1px;margin-top:1px}#mapContainer[data-zoom="7"] .bottom-arrow{width:145px;margin-left:528.5px;margin-top:648.2px}#mapContainer[data-zoom="6"] .bottom-arrow{width:75px;margin-left:262.5px;margin-top:319.5px}#mapContainer[data-zoom="5"] .bottom-arrow{width:36px;margin-left:131.5px;margin-top:160.91px}#mapContainer[data-zoom="4"] .bottom-arrow{width:19px;margin-left:65.75px;margin-top:78.02px}#mapContainer[data-zoom="3"] .bottom-arrow{width:15px;margin-left:30.13px;margin-top:31.09px}#mapContainer[data-zoom="2"] .bottom-arrow{width:9.9px;margin-left:13.86px;margin-top:11.59px}#mapContainer[data-zoom="1"] .bottom-arrow{width:7px;margin-left:5.91px;margin-top:3px}#mapContainer[data-zoom="0"] .bottom-arrow{width:5.38px;margin-left:5.01px;margin-top:0}';
document.getElementsByTagName('head')[0].appendChild(css);


document.getElementById('pickRessourceContainer').innerHTML += '\
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css">\
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css">\
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/flag-icon-css/2.9.0/css/flag-icon.css">\
<div id="pathcreator" class="container">\
<div style="text-align: right;">\
<div class="btn-group">\
<button type="button" class="btn dropdown-toggle btn-dark" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><div id="languageDisplayer" class="flag-icon flag-icon-fr"></div>\
</button>\
<div class="dropdown-menu dropdown-menu-right">\
  <a class="dropdown-item" href="javascript:languageSelector(\'fr\')" id="fr"><div class="flag-icon flag-icon-fr"></div> Français</a>\
  <a class="dropdown-item" href="javascript:languageSelector(\'en\')" id="en"><div class="flag-icon flag-icon-gb"></div> English</a>\
  <a class="dropdown-item" href="javascript:languageSelector(\'es\')" id="es"><div class="flag-icon flag-icon-es"></div> Español</a>\
</div>\
</div>\
</div>\
  <div class="row no-gutters">\
    <div class="col checkbox checkbox-primary">\
      <input type="checkbox" id="pathTop" value="option1">\
      <label id="top" for="pathTop">Haut</label>\
    </div>\
    <div class="col checkbox checkbox-primary">\
      <input type="checkbox" id="pathBottom" value="option1">\
      <label id="bottom" for="pathBottom">Bas</label>\
    </div>\
    <div class="w-100"></div>\
    <div class="col checkbox checkbox-primary">\
      <input type="checkbox" id="pathLeft" value="option1">\
      <label id="left" for="pathLeft">Gauche</label>\
    </div>\
    <div class="col checkbox checkbox-primary">\
      <input type="checkbox" id="pathRight" value="option1">\
      <label id="right" for="pathRight">Droite</label>\
    </div>\
    <div class="w-100"></div>\
    <div class="col checkbox checkbox-primary">\
      <input type="checkbox" id="pathHavenBag" value="option1">\
      <label id="havenBag" for="pathHavenBag">Havre-sac</label>\
    </div>\
  </div>\
 <hr style="border-top: 3px solid #111;" />\
  <form>\
    <div class="row no-gutters">\
      <div class="col radio radio-success">\
        <input type="radio" id="gather" name="radioOption">\
        <label id="tdgather" for="gather">Recolte</label>\
      </div>\
      <div class="col radio radio-danger">\
        <input type="radio" id="fight" name="radioOption">\
        <label id="tdfight" for="fight">Combat</label>\
      </div>\
      <div class="w-100"></div>\
      <div class="col radio radio-primary">\
        <input type="radio" id="bank" name="radioOption">\
        <label id="tdbank" for="bank">Banque</label>\
      </div>\
      <div class="col radio radio-phenix">\
        <input type="radio" id="phenix" name="radioOption">\
        <label id="tdphoenix" for="phenix">Phenix</label>\
      </div>\
      <div class="w-100"></div>\
      <div class="col radio">\
        <input type="radio" id="move" name="radioOption" checked>\
        <label id="tdMove" for="move">Deplacement</label>\
      </div>\
    </div>\
  </form>\
 <hr style="border-top: 3px solid #111;" />\
  <p style="text-align: center;" id="restogather">Ressources à récolter</p>\
  <div id="ressourcePickerBot" style="text-align: center;"><span id="ressourcePickerCreator" class="pickRessource" style="background-color: #0000008a; background-position: -260px 0px;">+</span></div>\
 <hr style="border-top: 3px solid #111;" />\
 <div class="btn-group btn-block">\
  <button type="button" class="btn btn-dark btn-block" id="saveFile">Sauvegarder</button>\
  <button type="button" class="btn btn-dark dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\
  </button>\
  <div class="dropdown-menu dropdown-menu-right">\
    <input type="text" placeholder="Nom du trajet" id="fileName">\
  </div>\
</div>\
  <button class="btn btn-dark btn-block" id="deletePath">Supprimer</button>\
  <label class="btn btn-dark btn-block btn-file"><div id="loadAFile">Charger</div><input id="file" type="file" style="display: none;">\
</label>\
</div>\
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style=" top: 300px;">\
  <div class="modal-dialog" role="document">\
    <div class="modal-content">\
      <div class="modal-header">\
        <h5 class="modal-title" id="exampleModalLabel">Zaap</h5>\
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">\
          <span aria-hidden="true">&times;</span>\
        </button>\
      </div>\
      <div class="modal-body">\
        <form>\
          <div class="form-group">\
            <label for="recipient-name" class="form-control-label">Zaap d\'arrivée :</label>\
            <select class="form-control" id="sel1">\
<option value="84674563">Astrub | 4,-19</option>\
<option value="147768">Bonta | -32,-56</option>\
<option value="144419">Brâkmar | -26,35</option>\
<option value="88212746">Amakna (Bord de la forêt maléfique) | -1,13</option>\
<option value="68552706">Amakna (Château d\'Amakna) | 3,-5</option>\
<option value="88082704">Amakna (Coins des Bouftous) | 5,7</option>\
<option value="68419587">Amakna (Port de Madrestam) | 7,-4</option>\
<option value="88213271">Amakna (Village d\'Amakna) | -2,0</option>\
<option value="88212481">Amakna (Plaîne des Scarafeuilles) | -1,24</option>\
<option value="88085249">Baie de Sufokia (Rivage Sufokien) | 10,22</option>\
<option value="95422468">Baie de Sufokia (Sufokia) | 13,26</option>\
<option value="154642">Île d\'Otomaïl (Village côtier) | -46,18</option>\
<option value="54172969">Île de Frigost (La Bourgade) | -79,-41</option>\
<option value="54172489">Île de Frigost (Village enseveli) | -77,-73</option>\
<option value="156762120">Île de Moon (Plage de la Tortue) | 35,12</option>\
<option value="73400320">Montagne des Koalaks (Village des Eleveurs) | -16,1</option>\
<option value="13605">Pandala Neutre (Faubourgs de Pandala) | 26,-37</option>\
<option value="15153">Pandala Feu (Village de Feudala) | 29,-49</option>\
<option value="142087694">Plaine de Cania (Champs de Cania) | -27,-36</option>\
<option value="156240386">Plaine de Cania (Lac de Cania) | -3,-42</option>\
<option value="165152263">Plaine de Cania (Massif de Cania) | -13,-28</option>\
<option value="84806401">Plaine de Cania (Plaine des Porkass) | -5,-23</option>\
<option value="147590153">Plaine de Cania (Plaines Rocheuses) | -17,-47</option>\
<option value="164364304">Plaine de Cania (Route Rocailleuse) | -20,-20</option>\
<option value="173278210">Saharach (Dunes des ossements) | 15,-58</option>\
<option value="171967506">Landes de Sidimote (Route des Roulottes) | -25,12</option>\
  </select>\
          </div>\
        </form>\
      </div>\
      <div class="modal-footer">\
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>\
        <button type="button" class="btn btn-primary">Valider</button>\
      </div>\
    </div>\
  </div>\
</div>';

function checkMaps(mapcoord, array) {
    for (let key = 0; key < array.length; key++) {
        if (array[key][0] == mapcoord) {
            return true;
        }
    }
    return false;
}

function getMapIndex(mapcoord, array) {
    for (let key = 0; key < array.length; key++) {
        if (array[key][0] == mapcoord) {
            return key;
        }
    }
}

function onMapClick() {

    if (!loadingFile)
        actualMap = document.getElementById('mapCoordinates').innerText;

    if (document.getElementById("pathHavenBag").checked) {
        if (!havenToggle) {
            if (!checkMaps(actualMap.split(', ')[0] + ',' + actualMap.split(', ')[1], havenBagData)) {
                havenToggle = true;
                $('#exampleModal').modal('show');
                return
            } else {
                havenBagData.splice(getMapIndex(actualMap.split(', ')[0] + ',' + actualMap.split(', ')[1], havenBagData), 1);
            }
        } else {
            havenToggle = false;
        }
    }
    if (document.getElementById("bank").checked) {
        if (!checkMaps(actualMap, bankData)) {
            bankData.push([actualMap, false, undefined, false, undefined, false, undefined, false, undefined, false, undefined, false]);
            createMarker(getMapIndex(actualMap, bankData), bankData);
            deleteEmptyPath(bankData);
        } else if (checkMaps(actualMap, bankData)) {
            removeArrow(getMapIndex(actualMap, bankData), bankData);
            deleteEmptyPath(bankData);
        }
        console.clear();
        for (let key in bankData) {
            console.log(key + ', map : ' + bankData[key][0] + ', top : ' + bankData[key][1] + ', bottom : ' + bankData[key][5] + ', right : ' + bankData[key][7] + ', left : ' + bankData[key][3] + ', havenbag : ' + bankData[key][9]);
        }
    } else if (document.getElementById("phenix").checked) {
        if (!checkMaps(actualMap, phenixData)) {
            phenixData.push([actualMap, false, undefined, false, undefined, false, undefined, false, undefined, false, undefined, false]);
            createMarker(getMapIndex(actualMap, phenixData), phenixData);
            deleteEmptyPath(phenixData);
        } else if (checkMaps(actualMap, phenixData)) {
            removeArrow(getMapIndex(actualMap, phenixData), phenixData);
            deleteEmptyPath(phenixData);
        }
        console.clear();
        for (let key in phenixData) {
            console.log(key + ', map : ' + phenixData[key][0] + ', top : ' + phenixData[key][1] + ', bottom : ' + phenixData[key][5] + ', right : ' + phenixData[key][7] + ', left : ' + phenixData[key][3] + ', havenbag : ' + phenixData[key][9]);
        }
    } else {
        if (!checkMaps(actualMap, pathData)) {
            pathData.push([actualMap, false, undefined, false, undefined, false, undefined, false, undefined, false, undefined, false, false]);
            createMarker(getMapIndex(actualMap, pathData), pathData);
            deleteEmptyPath(pathData);
        } else if (checkMaps(actualMap, pathData)) {
            removeArrow(getMapIndex(actualMap, pathData), pathData);
            deleteEmptyPath(pathData);
        }
        console.clear();
        for (let key in pathData) {
            console.log(key + ', map : ' + pathData[key][0] + ', top : ' + pathData[key][1] + ', bottom : ' + pathData[key][5] + ', right : ' + pathData[key][7] + ', left : ' + pathData[key][3] + ', havenbag : ' + pathData[key][9] + ', gather : ' + pathData[key][11] + ', fight : ' + pathData[key][12]);
        }
    }
}

function deleteEmptyPath(array) {
    if (!array[getMapIndex(actualMap, array)][1] && !array[getMapIndex(actualMap, array)][3] && !array[getMapIndex(actualMap, array)][5] && !array[getMapIndex(actualMap, array)][7] && !array[getMapIndex(actualMap, array)][9]) {
        array.splice(getMapIndex(actualMap, array), 1);
    }
}

function removeArrow(key, array) {
    removeArrowWay(key, array, "pathTop", 2, 4, 8, 12, 16, 0, 1, 0, 0);
    removeArrowWay(key, array, "pathLeft", 4, 5, 9, 14, 17, 1, 3, 0, 0);
    removeArrowWay(key, array, "pathBottom", 6, 6, 10, 15, 18, 2, 5, 0, 0);
    removeArrowWay(key, array, "pathRight", 8, 7, 11, 13, 19, 3, 7, 0, 0);
    removeArrowWay(key, array, "pathHavenBag", 10, 21, 22, 23, 24, 20, 9, 0, 0);
}

function removeArrowWay(key, array, className, wayMarker, gatherIcon, fightIcon, bankIcon, phenixIcon, moveIcon, wayToggle, x, y) {
    if (document.getElementById(className).checked) {
        if (array[key][wayMarker] !== undefined) {
            array[key][wayToggle] = false;
            map.removeLayer(array[key][wayMarker]);
            array[key][wayMarker] = undefined;
        } else createMarkerWay(key, array, className, wayMarker, gatherIcon, fightIcon, bankIcon, phenixIcon, moveIcon, wayToggle, x, y)
    }
}

function createMarker(key, array) {
    createMarkerWay(key, array, "pathTop", 2, 4, 8, 12, 16, 0, 1, 0, 0);
    createMarkerWay(key, array, "pathLeft", 4, 5, 9, 14, 17, 1, 3, 0, 0);
    createMarkerWay(key, array, "pathBottom", 6, 6, 10, 15, 18, 2, 5, 0, 0);
    createMarkerWay(key, array, "pathRight", 8, 7, 11, 13, 19, 3, 7, 0, 0);
    createMarkerWay(key, array, "pathHavenBag", 10, 21, 22, 23, 24, 20, 9, 0, 0);
}

function createMarkerWay(key, array, className, wayMarker, gatherIcon, fightIcon, bankIcon, phenixIcon, moveIcon, wayToggle, x, y) {
    if (document.getElementById(className).checked) {
        if (document.getElementById("gather").checked) {
            array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + x, actualMap.split(", ")[1] * 1 + y), {
                interactive: false,
                zIndexOffset: 5000,
                icon: icon[gatherIcon]
            }).addTo(map);
            array[key][11] = true;
        } else if (document.getElementById("fight").checked) {
            array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + x, actualMap.split(", ")[1] * 1 + y), {
                interactive: false,
                zIndexOffset: 5000,
                icon: icon[fightIcon]
            }).addTo(map);
            array[key][12] = true;
        } else if (document.getElementById("bank").checked) {
            array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + (x + 0.1), actualMap.split(", ")[1] * 1 + (y + 0.1)), {
                interactive: false,
                zIndexOffset: 5000,
                icon: icon[bankIcon]
            }).addTo(map);
            array[key][11] = true;
        } else if (document.getElementById("phenix").checked) {
            array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + (x + 0.2), actualMap.split(", ")[1] * 1 + (y + 0.2)), {
                interactive: false,
                zIndexOffset: 5000,
                icon: icon[phenixIcon]
            }).addTo(map);
            array[key][11] = true;
        } else {
            array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + x, actualMap.split(", ")[1] * 1 + y), {
                interactive: false,
                zIndexOffset: 5000,
                icon: icon[moveIcon]
            }).addTo(map);
        }
        array[key][wayToggle] = true;
    }
}

function newRessourcePicker() {
    document.getElementById("ressourcePickerBot").innerHTML = '<span id="pickRessource' + picker + '" class="pickRessource ressourceColor1" onclick="clickOnTypePicker(\'' + picker + '\');" data-name="" data-ressourceid=""' +
        'style="background-position: -260px 0px; line-height: 49px !important; width: 49px !important; margin: 2px !important; height: 49px !important;">?</span>' + document.getElementById("ressourcePickerBot").innerHTML;
    gatherData.push('pickRessource' + picker);
    picker += 1;
}

function pathGenerator(index, array) {
    var path = "";
    if (index !== undefined) {
        if (array.length !== 0) {
            if (array[index][9])
                path = "havenbag";
            else {
                if (array[index][1])
                    path = "top";
                if (array[index][5])
                    path += (path === "" ? "" : "|") + "bottom";
                if (array[index][3])
                    path += (path === "" ? "" : "|") + "left";
                if (array[index][7])
                    path += (path === "" ? "" : "|") + "right";
            }
            return path;
        }
    }
}

function afterPhenix(map) {
    for (let index = 0; index < pathData.length; index++) {
        if (map == pathData[index][0]) {
            return index;
        }
    }
}

function gatherFigh(index) {
    var path = "";
    if (pathData[index][11])
        path = ", gather = true";
    if (pathData[index][12])
        path += ", fight = true";
    return path;
}

function addGather() {
    let res = "";
    for (let index = 0; index < gatherData.length; index++) {
        let str = document.getElementById(gatherData[index]).outerHTML;
        let regex = /data-name=\"(.*?)\"/g;
        let matche = regex.exec(str);
        for (let i = 0; i < ressources.length; i++) {
            if (ressources[i][1] == matche[1]) {
                res += '\t' + ressources[i][0] + ',' + ' -- ' + ressources[i][1] + '\r\n';
            }
        }
    }
    return res;
}

function havenbagCheck(option) {
    for (let index = 0; index < havenBagData.length; index++) {
        if (havenBagData[index][option]) {
            return true;
        }
    }
    return false;
}

function generate() {
    var txt = "-- Generated On Dofus-Map with Drigtime's SwiftPath Script Maker --\r\n";
    txt += "GATHER = {\r\n";
    txt += addGather();
    txt += "} -- Les éléments à récolter\r\n" +
        "OPEN_BAGS = true -- Ouvrir les sacs de ressources au fur et à mesure\r\n" +
        "AUTO_DELETE = { } -- Les éléments à supprimer\r\n\r\n" +
        "MAX_MONSTERS = 8 -- Le nombre maximum de monstres dans un groupe à combattre.\r\n" +
        "MIN_MONSTERS = 1 -- Le nombre minimum de monstres dans un groupe à combattre.\r\n\r\n" +
        "FORBIDDEN_MONSTERS = { } -- Monstres interdits\r\n" +
        "FORCE_MONSTERS = { } -- Monstres obligatoires\r\n\r\n" +
        "MAX_COMBAT = 800 -- Nombre de combats maximum\r\n" +
        "\r\nfunction move()\r\n";
    if (havenbagCheck(2)) {
        txt += "\tif map:onMap(\"0,0\") then\r\n";
        firstIf = false;
        for (let index = 0; index < havenBagData.length; index++) {
            if (havenBagData[index][2]) {
                if (!firstIf) {
                    txt += "\t\tif actualMap == \"" + havenBagData[index][0] + "\" then\r\n\t\t\tmap:changeMap(\"zaap(" + havenBagData[index][1] + ")\")\r\n";
                    firstIf = true;
                } else
                    txt += "\t\telseif actualMap == \"" + havenBagData[index][0] + "\" then\r\n" +
                    "\t\t\tmap:changeMap(\"zaap(" + havenBagData[0][1] + ")\")\r\n";
            }
        }
        txt += "\t\tend\r\n" +
            "\telse\r\n" +
            "\t\tactualMap = map:currentMap()\r\n" +
            "\tend\r\n";
    }
    txt += "\treturn {\r\n" +
        "\t\t{map = \"83887104\", path = \"396\"}, --Interieur banque Astrub vers Sortie--\r\n" +
        "\t\t{map = \"54534165\", path = \"424\"}, --Interieur banque Frigost vers Sortie--\r\n" +
        "\t\t{map = \"2885641\", path = \"424\"}, --Interieur banque Bonta vers Sortie--\r\n" +
        "\t\t{map = \"99095051\", path = \"410\"}, --Interieur banque Amakna vers Sortie--\r\n" +
        "\t\t{map = \"8912911\", path = \"424\"}, --Interieur banque Brakmar vers Sortie--\r\n" +
        "\t\t{map = \"91753985\", path = \"396\"}, --Interieur banque Sufokia vers Sortie (Non fait)--\r\n" +
        "\t\t{map = \"86511105\", door = \"452\"}, --Interieur banque Ottomaï vers Sortie--\r\n" +
        "\t\t{map = \"8129542\", path = \"409\"}, --Interieur banque Pandala vers Sortie--\r\n" +
        "\t\t{map = \"84935175\", path = \"425\"}, --Interieur banque Montagne Koalak vers Sortie--\r\n";
    for (let key in pathData) {
        txt += '\t\t{map = "' + pathData[key][0].replace(" ", "") + '", path = "' + pathGenerator(key, pathData) + '"' + gatherFigh(key) + '},\r\n';
    }
    txt += "\t}\r\nend\r\n\r\nfunction bank()\r\n";
    if (havenbagCheck(3)) {
        txt += "\tif map:onMap(\"0,0\") then\r\n";
        firstIf = false;
        for (let index = 0; index < havenBagData.length; index++) {
            if (havenBagData[index][3]) {
                if (!firstIf) {
                    txt += "\t\tif actualMap == \"" + havenBagData[index][0] + "\" then\r\n\t\t\tmap:changeMap(\"zaap(" + havenBagData[index][1] + ")\")\r\n";
                    firstIf = true;
                } else
                    txt += "\t\telseif actualMap == \"" + havenBagData[index][0] + "\" then\r\n" +
                    "\t\t\tmap:changeMap(\"zaap(" + havenBagData[0][1] + ")\")\r\n";
            }
        }
        txt += "\t\tend\r\n" +
            "\telse\r\n" +
            "\t\tactualMap = map:currentMap()\r\n" +
            "\tend\r\n";
    }
    txt += "\treturn {\r\n";
    for (let key in bankData) {
        txt += '\t\t{map = "' + bankData[key][0].replace(" ", "") + '", path = "' + pathGenerator(key, bankData) + '"},\r\n';
    }
    txt += "\t\t{map = \"84674566\", door = \"303\"}, --Devant banque Astrub--\r\n" +
        "\t\t{map = \"83887104\", path = \"396\", npcBank = true}, --Banque Astrub--\r\n" +
        "\t\t{map = \"54172457\", door = \"358\"}, --Devant banque Frigost--\r\n" +
        "\t\t{map = \"54534165\", path = \"424\", npcBank = true}, --Banque Frigost--\r\n" +
        "\t\t{map = \"147254\", door = \"383\"}, --Devant banque Bonta--\r\n" +
        "\t\t{map = \"2885641\", path = \"424\", npcBank = true}, --Banque Bonta--\r\n" +
        "\t\t{map = \"88081177\", door = \"216\"}, --Devant banque Amakna--\r\n" +
        "\t\t{map = \"99095051\", path = \"410\", npcBank = true}, --Banque Amakna--\r\n" +
        "\t\t{map = \"144931\", door = \"248\"}, --Devant banque Brakmar--\r\n" +
        "\t\t{map = \"8912911\", path = \"424\", npcBank = true}, --Banque Brakmar--\r\n" +
        "\t\t{map = \"90703872\", door = \"302\"}, --Devant banque Sufokia --\r\n" +
        "\t\t{map = \"91753985\", path = \"494\", npcBank = true}, --Banque Sufokia--\r\n" +
        "\t\t{map = \"155157\", door = \"355\"}, --Devant banque Ottomaï--\r\n" +
        "\t\t{map = \"86511105\", door = \"452\", npcBank = true}, --Banque Ottomaï--\r\n" +
        "\t\t{map = \"12580\", door = \"284\"}, --Devant banque Pandala--\r\n" +
        "\t\t{map = \"8129542\", path = \"409\", npcBank = true}, --Banque Pandala--\r\n" +
        "\t\t{map = \"73400323\", door = \"330\"}, --Devant banque Montagne Koalak--\r\n" +
        "\t\t{map = \"84935175\", path = \"425\", npcBank = true}, --Banque Montagne Koalak--\r\n\t}\r\nend\r\n" +
        "\r\n\r\nfunction phenix()\r\n";
    if (havenbagCheck(4)) {
        txt += "\tif map:onMap(\"0,0\") then\r\n";
        firstIf = false;
        for (let index = 0; index < havenBagData.length; index++) {
            if (havenBagData[index][4]) {
                if (!firstIf) {
                    txt += "\t\tif actualMap == \"" + havenBagData[index][0] + "\" then\r\n\t\t\tmap:changeMap(\"zaap(" + havenBagData[index][1] + ")\")\r\n";
                    firstIf = true;
                } else
                    txt += "\t\telseif actualMap == \"" + havenBagData[index][0] + "\" then\r\n" +
                    "\t\t\tmap:changeMap(\"zaap(" + havenBagData[0][1] + ")\")\r\n";
            }
        }
        txt += "\t\tend\r\n" +
            "\telse\r\n" +
            "\t\tactualMap = map:currentMap()\r\n" +
            "\tend\r\n";
    }
    txt += "\treturn {\r\n";
    for (let key in phenixData) {
        txt += '\t\t{map = "' + phenixData[key][0].replace(" ", "") + '", path = "' + pathGenerator(key, phenixData) + '"},\r\n';
    }
    txt += "\t\t{map = \"12,12\", phenix = \"184\", path = \"" + pathGenerator(afterPhenix("12, 12"), pathData) + "\"},\r\n" +
        "\t\t{map = \"7,36\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("7, 36"), pathData) + "\"},\r\n" +
        "\t\t{map = \"22,22\", phenix = \"272\", path = \"" + pathGenerator(afterPhenix("22, 22"), pathData) + "\"},\r\n" +
        "\t\t{map = \"10,19\", phenix = \"192\", path = \"" + pathGenerator(afterPhenix("10, 19"), pathData) + "\"},\r\n" +
        "\t\t{map = \"5,1\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("5, 1"), pathData) + "\"},\r\n" +
        "\t\t{map = \"2,-1\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("2, -1"), pathData) + "\"},\r\n" +
        "\t\t{map = \"13,-7\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("13, -7"), pathData) + "\"},\r\n" +
        "\t\t{map = \"5,-9\", phenix = \"116\", path = \"" + pathGenerator(afterPhenix("5, -9"), pathData) + "\"},\r\n" +
        "\t\t{map = \"2,-12\", phenix = \"272\", path = \"" + pathGenerator(afterPhenix("2, -12"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-6,-12\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-6, -12"), pathData) + "\"},\r\n" +
        "\t\t{map = \"36,10\", phenix = \"330\", path = \"" + pathGenerator(afterPhenix("36, 10"), pathData) + "\"},\r\n" +
        "\t\t{map = \"25,-4\", phenix = \"450\", path = \"" + pathGenerator(afterPhenix("25, -4"), pathData) + "\"},\r\n" +
        "\t\t{map = \"27,-33\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("27, -33"), pathData) + "\"},\r\n" +
        "\t\t{map = \"24,-43\", phenix = \"245\", path = \"" + pathGenerator(afterPhenix("24, -43"), pathData) + "\"},\r\n" +
        "\t\t{map = \"17,-36\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("17, -36"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-13,-29\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-13, -29"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-10,-54\", phenix = \"342\", path = \"" + pathGenerator(afterPhenix("-10, -54"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-33,-56\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-33, -56"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-10,13\", phenix = \"354\", path = \"" + pathGenerator(afterPhenix("-10, 13"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-14,31\", phenix = \"243\", path = \"" + pathGenerator(afterPhenix("-14, 31"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-26,34\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-26, 34"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-26,36\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-26, 36"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-55,40\", phenix = \"240\", path = \"" + pathGenerator(afterPhenix("-55, 40"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-58,18\", phenix = \"354\", path = \"" + pathGenerator(afterPhenix("-58, 18"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-60,-3\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-60, -3"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-43,0\", phenix = \"259\", path = \"" + pathGenerator(afterPhenix("-43, 0"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-41,-17\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-41, -17"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-43,-19\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-43, -19"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-53,-40\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-53, -40"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-67,-44\", phenix = \"219\", path = \"" + pathGenerator(afterPhenix("-67 ,-44"), pathData) + "\"},\r\n" +
        "\t\t{map = \"-60,-79\", phenix = \"0\", path = \"" + pathGenerator(afterPhenix("-60, -79"), pathData) + "\"}\r\n\t}\r\nend\r\n";

    saveTextAsFile(txt);
}

function saveTextAsFile(txt) {
    var textToSaveAsBlob = new Blob([txt], {
        type: "text/plain"
    });
    var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
    if (document.getElementById('fileName').value == "") var fileNameToSaveAs = "Trajet.lua";
    else var fileNameToSaveAs = document.getElementById('fileName').value + ".lua";
    var downloadLink = document.createElement("a");
    downloadLink.download = fileNameToSaveAs;
    downloadLink.innerHTML = "Download File";
    downloadLink.href = textToSaveAsURL;
    downloadLink.style.display = "none";
    document.body.appendChild(downloadLink);
    downloadLink.click();
}

function deletePath() {
    for (let index = 0; index < pathData.length; index) {
        if (pathData[index][2]) map.removeLayer(pathData[index][2]);
        if (pathData[index][4]) map.removeLayer(pathData[index][4]);
        if (pathData[index][6]) map.removeLayer(pathData[index][6]);
        if (pathData[index][8]) map.removeLayer(pathData[index][8]);
        if (pathData[index][10]) map.removeLayer(pathData[index][10]);
        pathData.splice(index, 1);
    }
    for (let index = 0; index < bankData.length; index) {
        if (bankData[index][2]) map.removeLayer(bankData[index][2]);
        if (bankData[index][4]) map.removeLayer(bankData[index][4]);
        if (bankData[index][6]) map.removeLayer(bankData[index][6]);
        if (bankData[index][8]) map.removeLayer(bankData[index][8]);
        if (bankData[index][10]) map.removeLayer(bankData[index][10]);
        bankData.splice(index, 1);
    }
    for (let index = 0; index < phenixData.length; index) {
        if (phenixData[index][2]) map.removeLayer(phenixData[index][2]);
        if (phenixData[index][4]) map.removeLayer(phenixData[index][4]);
        if (phenixData[index][6]) map.removeLayer(phenixData[index][6]);
        if (phenixData[index][8]) map.removeLayer(phenixData[index][8]);
        if (phenixData[index][10]) map.removeLayer(phenixData[index][10]);
        phenixData.splice(index, 1);
    }
    console.clear();
}

function languageSelector(params) {
    switch (params) {
        case "fr":
            document.getElementById('top').innerHTML = 'Haut';
            document.getElementById('bottom').innerHTML = 'Bas';
            document.getElementById('left').innerHTML = 'Gauche';
            document.getElementById('right').innerHTML = 'Droite';
            document.getElementById('havenBag').innerHTML = 'Havre-sac';
            document.getElementById('tdgather').innerHTML = 'Récolte';
            document.getElementById('tdfight').innerHTML = 'Combat';
            document.getElementById('tdbank').innerHTML = 'Banque';
            document.getElementById('tdphoenix').innerHTML = 'Phenix';
            document.getElementById('tdMove').innerHTML = 'Deplacement';
            document.getElementById('restogather').innerText = 'Ressources à récolter :';
            document.getElementById('saveFile').innerText = 'Sauvegarder';
            document.getElementById('fileName').placeholder = 'Nom du fichier';
            document.getElementById('deletePath').innerText = 'Supprimer';
            document.getElementById('loadAFile').innerText = 'Charger';
            document.getElementById('languageDisplayer').classList.add('flag-icon-fr');
            document.getElementById('languageDisplayer').classList.remove('flag-icon-es');
            document.getElementById('languageDisplayer').classList.remove('flag-icon-gb');
            break;
        case "en":
            document.getElementById('top').innerHTML = 'Top';
            document.getElementById('bottom').innerHTML = 'Bottom';
            document.getElementById('left').innerHTML = 'Left';
            document.getElementById('right').innerHTML = 'Right';
            document.getElementById('havenBag').innerHTML = 'Haven bag';
            document.getElementById('tdgather').innerHTML = 'Gather';
            document.getElementById('tdfight').innerHTML = 'Fight';
            document.getElementById('tdbank').innerHTML = 'Bank';
            document.getElementById('tdphoenix').innerHTML = 'Phoenix';
            document.getElementById('tdMove').innerHTML = 'Move';
            document.getElementById('restogather').innerText = 'Resources to gather :';
            document.getElementById('saveFile').innerText = 'Save';
            document.getElementById('fileName').placeholder = 'Name of the file';
            document.getElementById('deletePath').innerText = 'Delete';
            document.getElementById('loadAFile').innerText = 'Load';
            document.getElementById('languageDisplayer').classList.remove('flag-icon-fr');
            document.getElementById('languageDisplayer').classList.remove('flag-icon-es');
            document.getElementById('languageDisplayer').classList.add('flag-icon-gb');
            break;
        case "es":
            document.getElementById('top').innerHTML = 'Arriba';
            document.getElementById('bottom').innerHTML = 'Abajo';
            document.getElementById('left').innerHTML = 'Izquierda';
            document.getElementById('right').innerHTML = 'Derecho';
            document.getElementById('havenBag').innerHTML = 'Merkasako';
            document.getElementById('tdgather').innerHTML = 'Cosecha';
            document.getElementById('tdfight').innerHTML = 'Lucha';
            document.getElementById('tdbank').innerHTML = 'Banco';
            document.getElementById('tdphoenix').innerHTML = 'Fénix';
            document.getElementById('tdMove').innerHTML = 'Desplazamiento';
            document.getElementById('restogather').innerText = 'Recursos para cosechar :';
            document.getElementById('saveFile').innerText = 'Salvar';
            document.getElementById('fileName').placeholder = 'Nombre del archivo';
            document.getElementById('deletePath').innerText = 'Borrar';
            document.getElementById('loadAFile').innerText = 'Carga';
            document.getElementById('languageDisplayer').classList.remove('flag-icon-fr');
            document.getElementById('languageDisplayer').classList.add('flag-icon-es');
            document.getElementById('languageDisplayer').classList.remove('flag-icon-gb');
            break;
        default:
            document.getElementById('top').innerHTML = 'Haut';
            document.getElementById('bottom').innerHTML = 'Bas';
            document.getElementById('left').innerHTML = 'Gauche';
            document.getElementById('right').innerHTML = 'Droite';
            document.getElementById('tdgather').innerHTML = 'Récolte';
            document.getElementById('tdfight').innerHTML = 'Combat';
            document.getElementById('tdbank').innerHTML = 'Banque';
            document.getElementById('tdphoenix').innerHTML = 'Phenix';
            document.getElementById('tdMove').innerHTML = 'Deplacement';
            document.getElementById('restogather').innerText = 'Ressources à récolter :';
            document.getElementById('saveFile').innerText = 'Sauvegarder';
            document.getElementById('fileName').placeholder = 'Nom du fichier';
            document.getElementById('deletePath').innerText = 'Supprimer';
            document.getElementById('loadAFile').innerText = 'Charger';
            document.getElementById('languageDisplayer').classList.add('flag-icon-fr');
            document.getElementById('languageDisplayer').classList.remove('flag-icon-es');
            document.getElementById('languageDisplayer').classList.remove('flag-icon-gb');
            break;
    }
}

document.getElementById('file').onchange = function () {

    var file = this.files[0];
    var content;
    var reader = new FileReader();
    reader.onload = function (progressEvent) {
        // Entire file
        content = this.result;
        let regexPath = /function move\(\)[\s\S]+?return.*?{\r\n([\s\S]+?)}\r\n.*end/g;
        let regexBank = /function bank\(\)[\s\S]+?return.*?{\r\n([\s\S]+?)}\r\n.*end/g;
        let regexPhenix = /function phenix\(\)[\s\S]+?return.*?{\r\n([\s\S]+?)}\r\n.*end/g;
        let result;
        let matche = regexBank.exec(content);
        loadingFile = true;
        document.getElementById("pathTop").checked = false;
        document.getElementById("pathLeft").checked = false;
        document.getElementById("pathBottom").checked = false;
        document.getElementById("pathRight").checked = false;
        document.getElementById("pathHavenBag").checked = false;
        if (matche !== null) {
            result = matche[1];
            result = result.split('\r\n');
            for (let index = 0; index < result.length; index++) {
                matche = /map.?=.?"(.*?)"/g.exec(result[index]);
                if (matche !== null) actualMap = matche[1];
                actualMap = actualMap.replace(/,/g, ", ");
                if (/(-|)[0-9]+?,\s(-|)[0-9]+?/g.exec(actualMap)) {
                    matche = /top/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathTop").checked = true;
                    matche = /left/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathLeft").checked = true;
                    matche = /bottom/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathBottom").checked = true;
                    matche = /right/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathRight").checked = true;
                    document.getElementById("bank").checked = true;
                    onMapClick();
                    document.getElementById("pathTop").checked = false;
                    document.getElementById("pathLeft").checked = false;
                    document.getElementById("pathBottom").checked = false;
                    document.getElementById("pathRight").checked = false;
                }
            }
        }
        matche = regexPath.exec(content);
        if (matche !== null) {
            result = matche[1];
            result = result.split('\r\n');
            for (let index = 0; index < result.length; index++) {
                matche = /map.?=.?"(.*?)"/g.exec(result[index]);
                if (matche !== null) actualMap = matche[1];
                actualMap = actualMap.replace(/,/g, ", ");
                if (/(-|)[0-9]+?,\s(-|)[0-9]+?/g.exec(actualMap)) {
                    matche = /top/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathTop").checked = true;
                    matche = /left/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathLeft").checked = true;
                    matche = /bottom/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathBottom").checked = true;
                    matche = /right/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathRight").checked = true;
                    matche = /gather/g.exec(result[index]);
                    if (matche !== null) document.getElementById("gather").checked = true;
                    matche = /fight/g.exec(result[index]);
                    if (matche !== null) document.getElementById("fight").checked = true;
                    onMapClick();
                    document.getElementById("pathTop").checked = false;
                    document.getElementById("pathLeft").checked = false;
                    document.getElementById("pathBottom").checked = false;
                    document.getElementById("pathRight").checked = false;
                    document.getElementById("gather").checked = false;
                    document.getElementById("fight").checked = false;
                }
            }
        }
        matche = regexPhenix.exec(content);
        if (matche !== null) {
            result = matche[1];
            result = result.split('\r\n');
            for (let index = 0; index < result.length; index++) {
                matche = /map.?=.?"(.*?)"/g.exec(result[index]);
                if (matche !== null) actualMap = matche[1];
                actualMap = actualMap.replace(/,/g, ", ");
                if (/(-|)[0-9]+?,\s(-|)[0-9]+?/g.exec(actualMap)) {
                    matche = /top/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathTop").checked = true;
                    matche = /left/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathLeft").checked = true;
                    matche = /bottom/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathBottom").checked = true;
                    matche = /right/g.exec(result[index]);
                    if (matche !== null) document.getElementById("pathRight").checked = true;
                    document.getElementById("phenix").checked = true;
                    onMapClick();
                    document.getElementById("pathTop").checked = false;
                    document.getElementById("pathLeft").checked = false;
                    document.getElementById("pathBottom").checked = false;
                    document.getElementById("pathRight").checked = false;
                }
            }
        }
        loadingFile = false;
    };
    reader.readAsText(file);
};

function keypressHandler(evt) {
    var keyCode = evt.key;
    switch (keyCode) {
        case "z":
            if (!document.getElementById("pathTop").checked)
                document.getElementById("pathTop").checked = true;
            else
                document.getElementById("pathTop").checked = false;
            break;
        case "q":
            if (!document.getElementById("pathLeft").checked)
                document.getElementById("pathLeft").checked = true;
            else
                document.getElementById("pathLeft").checked = false;
            break;
        case "s":
            if (!document.getElementById("pathBottom").checked)
                document.getElementById("pathBottom").checked = true;
            else
                document.getElementById("pathBottom").checked = false;
            break;
        case "d":
            if (!document.getElementById("pathRight").checked)
                document.getElementById("pathRight").checked = true;
            else
                document.getElementById("pathRight").checked = false;
            break;
        default:
            break;
    }
}

setTimeout(function () {
    $('#exampleModal').on('click', '.btn-primary', function () {
        let e = document.getElementById("sel1");
        var zaapMapid = e.options[e.selectedIndex].value;
        if (document.getElementById('move').checked || document.getElementById('gather').checked || document.getElementById('fight').checked)
            havenBagData.push([actualMap.split(", ")[0] + "," + actualMap.split(", ")[1], zaapMapid, true, false, false])
        else if (document.getElementById('bank').checked)
            havenBagData.push([actualMap.split(", ")[0] + "," + actualMap.split(", ")[1], zaapMapid, false, true, false])
        else if (document.getElementById('phenix').checked)
            havenBagData.push([actualMap.split(", ")[0] + "," + actualMap.split(", ")[1], zaapMapid, false, false, true])
        $('#exampleModal').modal('hide');
        onMapClick();
    });
}, 500);

setTimeout(function () {
    $('#exampleModal').on('click', '.btn-secondary', function () {
        havenToggle = false;
        $('#exampleModal').modal('hide');
    });
}, 500);

setTimeout(function () {
    $('#exampleModal').on('click', '.close', function () {
        havenToggle = false;
        $('#exampleModal').modal('hide');
    });
}, 500);

map.on('click', onMapClick);
document.addEventListener("keypress", keypressHandler, false);
document.getElementById("saveFile").addEventListener("click", generate, false);
document.getElementById("ressourcePickerCreator").addEventListener("click", newRessourcePicker, false);
document.getElementById("deletePath").addEventListener("click", deletePath, false);
})();