NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

console.log('villa-build-export');

var href = window.location.href;
if (href.indexOf('screen=am_village') < 0 || href.indexOf('mode=queue') < 0 || href.indexOf('template=') < 0) {
alert('This script must be ran while editing a construction template in the account manager!');
exit();
}

var labelToCanonicalNameMap = {
'Quartier Generale': 'main',
'Caserma': 'barracks',
'Stalla': 'stable',
'Officina': 'garage',
'Accademia': 'snob',
'Fabbro': 'smith',
'Punto di raduno': 'place',
'Statua': 'statue',
'Mercato': 'market',
'Taglialegna': 'wood',
'Pozzo di argilla: 'stone',
'Miniera di ferro': 'iron',
'Fattoria': 'farm',
'Magazzino': 'storage',
'Nascondiglio': 'hide',
'Muro': 'wall'
};

function getCurrentConstructionEntries() {
var entries = [];
$('a[class*=building-]').each((i, el) => {
var $label = $(el);
var $count = $label.next('.level_relative');

var label = $label.text();
var count = $count.text().match(/+(d+)/)[1];
if (!labelToCanonicalNameMap[label]) {
debugger;
}
entries.push({
label: label,
count: count,
name: labelToCanonicalNameMap[label]
});
});
console.log('Got construction entries: ', entries);
return entries;
}

function parseConstructionString(text) {
console.log('Parsing construction text');
text = text.replace('[spoiler]', '').replace('[/spoiler]', '');
console.log('Trimmed BB-code')

var result = [];
var matcher = /([^+;]+)+(d+)/g;
var match;
while (match = matcher.exec(text)) {
if (!match[1] || !match[2]) {
console.warn('Incomplete regex match for line ' + text);
}
var canonicalName = labelToCanonicalNameMap[match[1]]
if (!canonicalName) {
console.log('Unable to get canonical name for building name: ', match[1]);
}
result.push({
label: match[1],
count: parseInt(match[2]),
name: canonicalName
});
}
console.log('Parsed construction string: ', result)
return result;
}

function makeConstructionString(commands) {
var result = [];
commands.forEach((cmd) => {
result.push(`${cmd.label}+${cmd.count}`);
});
return '[spoiler]' + result.join(';') + '[/spoiler]';
}

function updateTemplateWithEntries(entries) {
$('a[class*=building-]').closest('.vis_item').remove();
var $target = $('#template_queue');
entries.forEach(command => {
console.log('Sending account manager command: ', command);
Accountmanager.addQueueItem(command.name, command.label, command.count, false);
});
}




$('#vbe-container').remove();

var $container = $(`
<div id="vbe-container">
<input type="button" id="vbe-save" value="Export"> <input type="text" id="vbe-save-output">
<br>
<input type="button" id="vbe-load" value="Import"> <input type="text" id="vbe-load-input">
</div>
`.trim());

$container.find('#vbe-save').click(() => {
var commandText = makeConstructionString(getCurrentConstructionEntries());
$('#vbe-save-output').val(commandText);
});

$container.find('#vbe-load').click(() => {
var commandText = $('#vbe-load-input').val();
if (!commandText.trim().length) {
alert('No text was entered');
return;
}

var originalBuild = getCurrentConstructionEntries();
try {
updateTemplateWithEntries(parseConstructionString(commandText));
} catch (ex) {
console.warn('Exception occurred while trying to parse construction string: ', ex);
updateTemplateWithEntries(originalBuild);
alert("Couldn't understand the imported text");
}
});

$container.insertAfter('#content_value h3');





// TW Accountmanager.addQueueItem
function addQueueItem(buildingType, buildingLabel, numUpgrades, error) { // is it 'error'?
// ...
}

//# sourceURL=https://tylercamp.me/tw/villa-build-export.js
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.