<commit_before>(function () {
  'use strict';

  const exportUrl = 'https://kancolleimgbuilder.web.app/builder?deck=';
  // const exportUrl = 'http://localhost:4200/builder?deck=';
  const defaultLang = 'en';
  const supportedLangs = ['jp', 'kr', 'scn'];
  const defaultTheme = 'dark';
  const supportedThemes = {
    'dark': 'dark',
    'legacy': 'official',
  };

  window.KC3ImageBuilder = {
    open,
    exportCurrentFleets,
    exportSortie,
    getBaseDeckBuilder,
    getFleetsFromSortie,
    convertFleet,
    createKCFleetObject,
  };

  function open(deckBuilder) {
    const json = JSON.stringify(deckBuilder);
    // console.debug(json);
    const url = exportUrl + encodeURI(json);
    console.debug(url);
    window.open(url);
  }

  function exportCurrentFleets() {
    PlayerManager.loadFleets();
    PlayerManager.loadBases();
    const fleets = PlayerManager.fleets;
    const lbas = PlayerManager.bases;
    const deckBuilder = getBaseDeckBuilder(true);
    buildFleets(deckBuilder, fleets);
    buildLbasFromPlayerManager(deckBuilder, lbas);
    open(deckBuilder);
  }

  function exportSortie(sortieId) {
    KC3Database.get_sortie(sortieId, sortie => {
      const fleets = getFleetsFromSortie(sortie);
      const lbas = sortie.lbas;
      const deckBuilder = getBaseDeckBuilder(true);
      buildFleets(deckBuilder, fleets);
      buildLbasFromSortie(deckBuilder, lbas);
      open(deckBuilder);
    })
  }

  function getFleetsFromSortie(sortie) {
    const fleets = [];
    fleets.push(convertFleet(sortie.fleet1, 1));
    fleets.push(convertFleet(sortie.fleet2, 2));
    fleets.push(convertFleet(sortie.fleet3, 3));
    fleets.push(convertFleet(sortie.fleet4, 4));
    return fleets.map(v => createKCFleetObject(v));
  }

  function getBaseDeckBuilder(isImgBuilder = false) {
    const obj = {
      hqlv: PlayerManager.hq.level,
    };
    if (isImgBuilder) {
      obj.lang = supportedLangs.includes(ConfigManager.language)
        ? ConfigManager.language
        : defaultLang;
      obj.theme = supportedThemes[ConfigManager.sr_theme] || defaultTheme;
    } else {
      obj.version = 4;
    }
    return obj;
  }

  function buildFleets(deckBuilder, fleets) {
    fleets.forEach((v, i) => {
      deckBuilder['f' + (i + 1)] = v.deckbuilder(true);
    });
  }

  function buildLbasFromPlayerManager(deckBuilder, lbas) {
    if (!checkLbasBuilderInput(deckBuilder, lbas)) {
      return;
    }
    lbas.forEach((lb, i) => {
      deckBuilder['a' + (i + 1)] = lb.deckbuilder();
    });
  }

  function buildLbasFromSortie(deckBuilder, lbas) {
    if (!checkLbasBuilderInput(deckBuilder, lbas)) {
      return;
    }
    lbas.forEach((lb, i) => {
      const lbasObj = {
        mode: lb.action,
        items: {},
      };
      lb.planes.forEach((plane, i) => {
        const planeObj = {
          id: plane.mst_id,
          rf: plane.stars,
          mas: plane.ace,
        };
        lbasObj.items['i' + (i + 1)] = planeObj;
      })
      deckBuilder['a' + (i + 1)] = lbasObj;
    })
  }

  function checkLbasBuilderInput(deckBuilder, lbas) {
    const isValid = deckBuilder && typeof deckBuilder === 'object' && Array.isArray(lbas);
    return isValid;
  }

  function convertShip(shipData) {
    if (!shipData || shipData.mst_id <= 0) return null;
    var shipObj = {};
    var masterData = KC3Master.ship(shipData.mst_id);
    var slotnum = masterData.api_slot_num;
    shipObj.id = shipData.mst_id;
    shipObj.level = shipData.level;
    shipObj.morale = shipData.morale;
    shipObj.mod = shipData.kyouka;
    shipObj.stats = shipData.stats;
    shipObj.equipments = [];

    $.each(shipData.equip, function (i, gearId) {
      if (gearId <= 0) {
        shipObj.equipments.push(null);
        return;
      }
      shipObj.equipments.push({
        id: gearId,
        improve: shipData.stars && shipData.stars[i] > 0 ? shipData.stars[i] : 0,<commit_msg>Add semi<commit_after>(function () {
  'use strict';

  const exportUrl = 'https://kancolleimgbuilder.web.app/builder?deck=';
  // const exportUrl = 'http://localhost:4200/builder?deck=';
  const defaultLang = 'en';
  const supportedLangs = ['jp', 'kr', 'scn'];
  const defaultTheme = 'dark';
  const supportedThemes = {
    'dark': 'dark',
    'legacy': 'official',
  };

  window.KC3ImageBuilder = {
    open,
    exportCurrentFleets,
    exportSortie,
    getBaseDeckBuilder,
    getFleetsFromSortie,
    convertFleet,
    createKCFleetObject,
  };

  function open(deckBuilder) {
    const json = JSON.stringify(deckBuilder);
    // console.debug(json);
    const url = exportUrl + encodeURI(json);
    console.debug(url);
    window.open(url);
  }

  function exportCurrentFleets() {
    PlayerManager.loadFleets();
    PlayerManager.loadBases();
    const fleets = PlayerManager.fleets;
    const lbas = PlayerManager.bases;
    const deckBuilder = getBaseDeckBuilder(true);
    buildFleets(deckBuilder, fleets);
    buildLbasFromPlayerManager(deckBuilder, lbas);
    open(deckBuilder);
  }

  function exportSortie(sortieId) {
    KC3Database.get_sortie(sortieId, sortie => {
      const fleets = getFleetsFromSortie(sortie);
      const lbas = sortie.lbas;
      const deckBuilder = getBaseDeckBuilder(true);
      buildFleets(deckBuilder, fleets);
      buildLbasFromSortie(deckBuilder, lbas);
      open(deckBuilder);
    });
  }

  function getFleetsFromSortie(sortie) {
    const fleets = [];
    fleets.push(convertFleet(sortie.fleet1, 1));
    fleets.push(convertFleet(sortie.fleet2, 2));
    fleets.push(convertFleet(sortie.fleet3, 3));
    fleets.push(convertFleet(sortie.fleet4, 4));
    return fleets.map(v => createKCFleetObject(v));
  }

  function getBaseDeckBuilder(isImgBuilder = false) {
    const obj = {
      hqlv: PlayerManager.hq.level,
    };
    if (isImgBuilder) {
      obj.lang = supportedLangs.includes(ConfigManager.language)
        ? ConfigManager.language
        : defaultLang;
      obj.theme = supportedThemes[ConfigManager.sr_theme] || defaultTheme;
    } else {
      obj.version = 4;
    }
    return obj;
  }

  function buildFleets(deckBuilder, fleets) {
    fleets.forEach((v, i) => {
      deckBuilder['f' + (i + 1)] = v.deckbuilder(true);
    });
  }

  function buildLbasFromPlayerManager(deckBuilder, lbas) {
    if (!checkLbasBuilderInput(deckBuilder, lbas)) {
      return;
    }
    lbas.forEach((lb, i) => {
      deckBuilder['a' + (i + 1)] = lb.deckbuilder();
    });
  }

  function buildLbasFromSortie(deckBuilder, lbas) {
    if (!checkLbasBuilderInput(deckBuilder, lbas)) {
      return;
    }
    lbas.forEach((lb, i) => {
      const lbasObj = {
        mode: lb.action,
        items: {},
      };
      lb.planes.forEach((plane, i) => {
        const planeObj = {
          id: plane.mst_id,
          rf: plane.stars,
          mas: plane.ace,
        };
        lbasObj.items['i' + (i + 1)] = planeObj;
      });
      deckBuilder['a' + (i + 1)] = lbasObj;
    });
  }

  function checkLbasBuilderInput(deckBuilder, lbas) {
    const isValid = deckBuilder && typeof deckBuilder === 'object' && Array.isArray(lbas);
    return isValid;
  }

  function convertShip(shipData) {
    if (!shipData || shipData.mst_id <= 0) return null;
    var shipObj = {};
    var masterData = KC3Master.ship(shipData.mst_id);
    var slotnum = masterData.api_slot_num;
    shipObj.id = shipData.mst_id;
    shipObj.level = shipData.level;
    shipObj.morale = shipData.morale;
    shipObj.mod = shipData.kyouka;
    shipObj.stats = shipData.stats;
    shipObj.equipments = [];

    $.each(shipData.equip, function (i, gearId) {
      if (gearId <= 0) {
        shipObj.equipments.push(null);
        return;
      }
      shipObj.equipments.push({
        id: gearId,
        improve: shipData.stars && shipData.stars[i] > 0 ? shipData.stars[i] : 0,
{'fraction_non_alphanumeric': 0.13506926629040533, 'fraction_numerical': 0.0061570035915854285, 'mean_word_length': 2.9498480243161094, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7539810', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2661, 'n_words': 458}