Items/load/doc: Difference between revisions

From Portals of Phereon Wiki
< Items‎ | load
Content added Content deleted
m (forgot new lines)
mNo edit summary
Line 1: Line 1:
Pre-script preparation:
Pre-script preparation:
#Replace all ' to \'
#Replace all ' to \'
#Replace all \n to \\n
#''Optionally Remove spaces at the beginning of line (in notepad++ this is edit->operations with whitespaces->remove initial whitespaces)''
#''Optionally Remove spaces at the beginning of line (in notepad++ this is edit->operations with whitespaces->remove initial whitespaces)''
#Find \r\n and replace with | in regex mode
#Find \r\n and replace with | in regex mode

Revision as of 05:10, 11 January 2021

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

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:
    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. Press copy button on the output string
  5. Replace all the text in Items/load with the output