This is a wiki for a reason. Anyone can contribute. If you see something that is inaccurate or can be improved, don't ask that it be fixed--just improve it.
[ Disclaimer, Create new user --- Wiki markup help, Install P99 ]

Magelo Blue:Loramin

From Project 1999 Wiki
Revision as of 19:08, 25 June 2020 by Loramin (Talk | contribs)

Jump to: navigation, search

var allSlots = [

 'Neck', 'Head', 'Ears1', 'Ears2', 'Face', 'Chest', 'Arms', 'Back', 'Waist', 'Shoulders',
 'Wrists1', 'Wrists2', 'Legs', 'Hands', 'Fingers1', 'Fingers2', 'Feet', 'Primary',
 'Secondary', 'Range', 'Ammo', 'Inv1', 'Inv2', 'Inv3', 'Inv4', 'Inv5', 'Inv6', 'Inv7', 'Inv8',

];

var parseEqText = function (eqText) {

 var convertSlot = function (rows, slot) {
   if (slot === 'Ear') return 'Ears' + (rows.Ears1 ? 2 : 1);
   if (slot === 'Fingers') return rows.Fingers1 ? 'Fingers2' : 'Fingers1';
   if (slot === 'Wrist') return rows.Wrists1 ? 'Wrists2' : 'Wrists1';
   if (slot.substr(0, 7) === 'General') {
     var index = slot.substr(7, 8);
     var isBagSlot = '-' === slot.substr(8, 9);
     if (!isBagSlot) return 'Inv' + index;
   }
   return slot;
 };
 var parseRows = function (eqText) {
   var rows = eqText.split('\n');
   return rows.reduce(function (memo, row) {
     var slot = convertSlot(memo, row.split('	')[0]);
     var value = row.split('	')[1];
     memo[slot] = value === 'Empty' ?  : value;
     return memo;
   }, {});
 };
 var buildItemsBySlot = function (itemRows) {
   return allSlots.reduce(function (itemsBySlot, slot) {
     itemsBySlot[slot] = itemRows[slot];
     return itemsBySlot;
   }, {});
 };
 var itemRows = parseRows(eqText);
 return buildItemsBySlot(itemRows);

};

var copyMageloCode = function () {

 try {
   var range = document.createRange();
   range.selectNode($('#magelo-text-output')[0]);
   window.getSelection().addRange(range);
   if (!document.execCommand('copy')) throw new Error();
   alert(
     'Your Magelo code has been copied.  You can now paste in your Magelo profile, in ' +
       'place of your current equipment section.'
   );
 } catch (err) {
   alert('Failed to copy code :( Please select and copy the code yourself.');
 } finally {
   window.getSelection().removeAllRanges();
 }

};

var onTextareaChange = function (e) {

 var parsed = parseEqText($(e.target).val());
 var mageloCode = allSlots
   .map(function (slot) {
     var newLine = slot === 'Primary' || slot === 'Inv1' ? '\n' : ;
     return newLine + '* ' + slot + ': ' + (parsed[slot] || );
   })
   .join('\n');
 $('#magelo-text-output').text(mageloCode);
 window.setTimeout(function() { copyMageloCode(); });

};

$('#magelo-import-placeholder').replaceWith(

 '<textarea id="eq-text-input" style="min-height: 6em; max-width:50em""></textarea>' +
'
'

); $('#eq-text-input').change(onTextareaChange);