Items/load

From Portals of Phereon Wiki
[view | edit | purge]Documentation

Pre-script preparation:

  1. Replace all ' to \'
  2. Replace all \n to \\n
  3. Optionally Remove spaces at the beginning of line (in notepad++ this is edit->operations with whitespaces->remove initial whitespaces)
  4. Find \r\n and replace with | in regex mode (text mode)

Script operation:

  1. Open web console
  2. Set the file text, type and copy the text inside the single quotes
    let itemText = 'TEXT FROM ITEMS FILE HERE';
    
  3. Run this script: (text mode)
    let itemRe = / Item /g,common = [], rare = [], legendary = [],special = [],mythic = [],matchItem,curArr,outputText = "";
    function parseItem(regIndex) {
      let firstI = itemText.indexOf('skill =',regIndex);
      let secondI = itemText.indexOf('|',firstI);
      curArr.push(itemText.substring(regIndex, secondI));
    }
    function getValue(str, name, nextIndex) {
      let index = str.indexOf(' ' + name + ' =') + name.length + 3;
      if (nextIndex) { index = str.indexOf(' ' + name + ' =', str.indexOf('|',index)) + name.length + 3; }
      let upIndex = str.indexOf('|',index);
      if (upIndex == -1) { upIndex = str.length; }
      return str.substring(index, upIndex).replace(/"/g,'').replace(/\\'/g,"'").trim();
    }
    function createEntry(str, rarity) {
      let outStr = "{{Cargo Items";
      outStr += "|rarity = " + rarity;
      outStr += "|name = " + getValue(str, "name", false);
      outStr += "|icon = [[File:" + getValue(str, "name", false) + "Item.png]]";
      outStr += "|inPortal = " + getValue(str, "useableOutsideOfCombat", false);
      outStr += "|inTown = " + getValue(str, "useableInTown", false);
      outStr += "|inBattle = " + getValue(str, "useableInbattle", false);
      outStr += "|itemType = " + getValue(str, "type", false);
      outStr += "|atkType = " + getValue(str, "changedAtkType", false);
      outStr += "|damageType = " + getValue(str, "changedDamageType", false);
      outStr += "|value = " + getValue(str, "value", false);
      outStr += "|uses = " + getValue(str, "uses", false);
      outStr += "|manaCost = " + getValue(str, "manaCost", false);
      outStr += "|apCost = " + getValue(str, "apCost", false);
      outStr += "|itemRange = " + getValue(str, "range", false);
      outStr += "|hp = " + getValue(str, "hp", false);
      outStr += "|mana = " + getValue(str, "mana", false);
      outStr += "|speed = " + getValue(str, "speed", false);
      outStr += "|strength = " + getValue(str, "strength", false);
      outStr += "|armor = " + getValue(str, "armor", false);
      outStr += "|lDmg = " + getValue(str, "lDmg", false);
      outStr += "|lRes = " + getValue(str, "lRes", false);
      outStr += "|magicStrength = " + getValue(str, "magicStrength", false);
      outStr += "|description = " + getValue(str, "description", false).trim().replace(/\\n/g,'<br>');
      outStr += "|passiveType = " + getValue(str, "type", true);
      outStr += "|passiveEffect = " + getValue(str, "name", true);
      outStr += "|activeSkill = " + getValue(str, "skill", false);
      outStr += "}}";
      return outStr;
    }
    while (match = itemRe.exec(itemText)) {
      switch(itemText.substring(itemRe.lastIndex, itemText.indexOf('|',itemRe.lastIndex)).trim()) {
        case 'data': parseItem(itemRe.lastIndex); break;
        case 'commonItems': curArr = common; break;
        case 'rareItems': curArr = rare; break;
        case 'legendaryItems': curArr = legendary; break;
        case 'specialItems': curArr = special; break;
        case 'mythicItems': curArr = mythic; break;
      }
    }
    for (i=0;i<common.length;i++) {
       outputText += createEntry(common[i], 0);
    }
    for (i=0;i<rare.length;i++) {
       outputText += createEntry(rare[i], 1);
    }
    for (i=0;i<legendary.length;i++) {
       outputText += createEntry(legendary[i], 2);
    }
    for (i=0;i<special.length;i++) {
       outputText += createEntry(special[i], 3);
    }
    for (i=0;i<mythic.length;i++) {
       outputText += createEntry(mythic[i], 4);
    }
    outputText += "{{Documentation}}";
    outputText;
    
  4. Or run this script: (json mode)
    let json = {},outputText = "";
    function createEntry(str, rarity) {
      let outStr = "{{Cargo Items";
      outStr += "|rarity = " + rarity;
      outStr += "|name = " + str.name;
      outStr += "|icon = [[File:" + str.name + "Item.png]]";
      outStr += "|inPortal = " + (str.useableOutsideOfCombat ? "1" : "0");
      outStr += "|inTown = " + (str.useableInTown ? "1" : "0");
      outStr += "|inBattle = " + (str.useableInbattle ? "1" : "0");
      outStr += "|itemType = " + str.type;
      outStr += "|atkType = " + str.changedAtkType;
      outStr += "|damageType = " + str.changedDamageType;
      outStr += "|value = " + str.value;
      outStr += "|uses = " + str.uses;
      outStr += "|manaCost = " + str.manaCost;
      outStr += "|apCost = " + str.apCost;
      outStr += "|itemRange = " + str.range;
      outStr += "|hp = " + str.hp;
      outStr += "|mana = " + str.mana;
      outStr += "|speed = " + str.speed;
      outStr += "|strength = " + str.strength;
      outStr += "|armor = " + str.armor;
      outStr += "|lDmg = " + str.lDmg;
      outStr += "|lRes = " + str.lRes;
      outStr += "|magicStrength = " + str.magicStrength;
      outStr += "|description = " + str.description.trim().replace(/\n/g,'<br>');
      outStr += "|passiveType = " + str.passiveEffects.type;
      outStr += "|passiveEffect = " + str.passiveEffects.name;
      outStr += "|activeSkill = " + str.skill;
      outStr += "}}";
      return outStr;
    }
    json = JSON.parse(itemText);
    for (i=0;i<json.commonItems.length;i++) {
       outputText += createEntry(json.commonItems[i], 0);
    }
    for (i=0;i<json.rareItems.length;i++) {
       outputText += createEntry(json.rareItems[i], 1);
    }
    for (i=0;i<json.legendaryItems.length;i++) {
       outputText += createEntry(json.legendaryItems[i], 2);
    }
    for (i=0;i<json.specialItems.length;i++) {
       outputText += createEntry(json.specialItems[i], 3);
    }
    for (i=0;i<json.mythicItems.length;i++) {
       outputText += createEntry(json.mythicItems[i], 4);
    }
    outputText += "{{Documentation}}";
    outputText;
    
  5. Press copy button on the output string
  6. Replace all the text in Items/load with the output, remove any " before and after the output
[view | edit | purge]The above documentation is transcluded fromItems/load/doc.