Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //THIS INCLUDES /lib/util.js METHODS
- //Statistics constructor
- var pokemonStatistics = function (statistics, pokemonName) {
- this["statistics"] = statistics;
- this["pokemonName"] = pokemonName.toLowerCase();
- this["abilitiesArray"] = new Array();
- this["itemsArray"] = new Array();
- this["spreadsArray"] = new Array();
- this["movesArray"] = new Array();
- this["teammatesArray"] = new Array();
- this["handleProcessingData_string"] = "this.default()";
- this["handleNotFound_string"] = "this.default()";
- this["handleDone_string"] = "this.default()";
- };
- pokemonStatistics.prototype = Object.create(function () { }); //Statistics prototype
- pokemonStatistics.prototype.constructor = pokemonStatistics; //Creates constructor
- pokemonStatistics.prototype.prepareStatistics = function () { //Prepares the statistics
- this["statistics"] = this["statistics"]
- .replace(/\s+/g, " ")
- .toLowerCase();
- }
- pokemonStatistics.prototype.parseStatistics = function () {
- this.handleProcessingData();
- this.prepareStatistics();
- statistics_copy = this.statistics;
- desired_pokemon_start = "+----------------------------------------+ | "+this["pokemonName"]+" | +----------------------------------------+";
- desired_pokemon_end = "+----------------------------------------+ +----------------------------------------+";
- desired_pokemon_start_index = statistics_copy.indexOf(desired_pokemon_start);
- if (desired_pokemon_start_index != -1) { //If the pokemon is on the list
- statistics_copy = statistics_copy.substring(desired_pokemon_start_index, statistics_copy.length);
- desired_pokemon_end_index = statistics_copy.indexOf(desired_pokemon_end);
- if (desired_pokemon_end_index != -1) { //Makes a substring of the statistics with only the pokemon desired
- statistics_copy = statistics_copy.substring(0, desired_pokemon_end_index);
- } else {
- statistics_copy = statistics_copy.substring(0, statistics_copy.length);
- }
- this["abilitiesArray"] = this.getAbilities(statistics_copy); //Gets the value of each Array
- this["itemsArray"] = this.getItems(statistics_copy); //Passes down the substring with the pokemon statistics
- this["spreadsArray"] = this.getSpreads(statistics_copy);
- this["movesArray"] = this.getMoves(statistics_copy);
- this["teammatesArray"] = this.getTeammates(statistics_copy);
- this.handleDone();
- } else { //The pokemon wasn't found on the list
- this.handleNotFound();
- }
- };
- //Get array methods
- pokemonStatistics.prototype.getAbilities = function (stats) {
- search_start = stats.indexOf("abilities") + "abilities | ".length; //Makes a substring based on the pokemon string
- stats = stats.substring(search_start, stats.length);
- search_end = stats.indexOf(" +----------------------------------------+ ");
- stats = stats.substring(0, search_end);
- abilities = new Array(); //Creates the arrays we are gonna need
- percentage = new Array();
- element = "";
- percentage_element = "";
- lcount = 0;
- for (var c1 = 0; c1 < stats.length; c1++) { //Goes through the string char by char
- if (stats[c1] == "|")
- lcount++;
- if (lcount%2 != 0) {
- if (!util.isNumber(stats[c1]) && stats[c1] != "%" && stats[c1] != ".")
- element += stats[c1];
- else
- percentage_element += stats[c1];
- } else {
- abilities.push(element);
- percentage.push(percentage_element);
- element = "";
- percentage_element = "";
- }
- }
- util.trim(abilities);
- util.trim(percentage);
- for (var c1 = 0; c1 < abilities.length; c1++) { //Removes useless characters
- abilities[c1] = abilities[c1].substring(2, abilities[c1].length-2);
- percentage[c1] = percentage[c1].substring(0, percentage[c1].length-1);
- }
- return { "abilities" : abilities, "percentage" : percentage }; //Returns the array
- }
- pokemonStatistics.prototype.getItems = function (stats) {
- search_start = stats.indexOf("items") + "items | ".length; //Makes a substring based on the pokemon string
- stats = stats.substring(search_start, stats.length);
- search_end = stats.indexOf(" +----------------------------------------+ ");
- stats = stats.substring(0, search_end);
- items = new Array(); //Creates the arrays we are gonna need
- percentage = new Array();
- element = "";
- percentage_element = "";
- lcount = 0;
- for (var c1 = 0; c1 < stats.length; c1++) { //Goes through the string char by char
- if (stats[c1] == "|")
- lcount++;
- if (lcount%2 != 0) {
- if (!util.isNumber(stats[c1]) && stats[c1] != "%" && stats[c1] != ".")
- element += stats[c1];
- else
- percentage_element += stats[c1];
- } else {
- items.push(element);
- percentage.push(percentage_element);
- element = "";
- percentage_element = "";
- }
- }
- util.trim(items);
- util.trim(percentage);
- for (var c1 = 0; c1 < items.length; c1++) { //Removes useless characters
- items[c1] = items[c1].substring(2, items[c1].length-2);
- percentage[c1] = percentage[c1].substring(0, percentage[c1].length-1);
- }
- return { "items" : items, "percentage" : percentage }; //Returns the array
- }
- pokemonStatistics.prototype.getMoves = function (stats) {
- search_start = stats.indexOf("moves") + "moves | ".length; //Makes a substring based on the pokemon string
- stats = stats.substring(search_start, stats.length);
- search_end = stats.indexOf(" +----------------------------------------+ ");
- stats = stats.substring(0, search_end);
- moves = new Array(); //Creates the arrays we are gonna need
- percentage = new Array();
- element = "";
- percentage_element = "";
- lcount = 0;
- for (var c1 = 0; c1 < stats.length; c1++) { //Goes through the string char by char
- if (stats[c1] == "|")
- lcount++;
- if (lcount%2 != 0) {
- if (!util.isNumber(stats[c1]) && stats[c1] != "%" && stats[c1] != ".")
- element += stats[c1];
- else
- percentage_element += stats[c1];
- } else {
- moves.push(element);
- percentage.push(percentage_element);
- element = "";
- percentage_element = "";
- }
- }
- util.trim(moves);
- util.trim(percentage);
- for (var c1 = 0; c1 < moves.length; c1++) { //Removes useless characters
- moves[c1] = moves[c1].substring(2, moves[c1].length-2);
- percentage[c1] = percentage[c1].substring(0, percentage[c1].length-1);
- }
- return { "moves" : moves, "percentage" : percentage }; //Returns the array
- }
- pokemonStatistics.prototype.getTeammates = function (stats) {
- search_start = stats.indexOf("teammates") + "teammates | ".length; //Makes a substring based on the pokemon string
- stats = stats.substring(search_start, stats.length);
- search_end = stats.indexOf(" +----------------------------------------+ ");
- stats = stats.substring(0, search_end);
- teammates = new Array(); //Creates the arrays we are gonna need
- percentage = new Array();
- element = "";
- percentage_element = "";
- lcount = 0;
- for (var c1 = 0; c1 < stats.length; c1++) { //Goes through the string char by char
- if (stats[c1] == "|")
- lcount++;
- if (lcount%2 != 0) {
- if (!util.isNumber(stats[c1]) && stats[c1] != "%" && stats[c1] != "." && stats[c1] != "+")
- element += stats[c1];
- else if (stats[c1] != "+")
- percentage_element += stats[c1];
- } else {
- teammates.push(element);
- percentage.push(percentage_element);
- element = "";
- percentage_element = "";
- }
- }
- util.trim(teammates);
- util.trim(percentage);
- for (var c1 = 0; c1 < teammates.length; c1++) { //Removes useless characters
- teammates[c1] = teammates[c1].substring(2, teammates[c1].length-2);
- percentage[c1] = percentage[c1].substring(0, percentage[c1].length-1);
- }
- return { "teammates" : teammates, "percentage" : percentage }; //Returns the array
- }
- pokemonStatistics.prototype.getSpreads = function (stats) {
- search_start = stats.indexOf("spreads") + "spreads | ".length; //Makes a substring based on the pokemon string
- stats = stats.substring(search_start, stats.length);
- search_end = stats.indexOf(" +----------------------------------------+ ");
- stats = stats.substring(0, search_end);
- natures = new Array(); //Creates the arrays we are gonna need
- spreads_array = new Array();
- spreads = new Array();
- element = "";
- spreads_element = "";
- lcount = 0;
- for (var c1 = 0; c1 < stats.length; c1++) { //Goes through the string char by char
- if (stats[c1] == "|")
- lcount++;
- if (lcount%2 != 0) {
- if (!util.isNumber(stats[c1]) && stats[c1] != "%" && stats[c1] != "." && stats[c1] != "/" && stats[c1] != ":" && stats[c1] != " ")
- element += stats[c1];
- else if (stats[c1] != ":" && stats[c1] != "%")
- spreads_element += stats[c1];
- } else {
- natures.push(element);
- spreads_array.push(spreads_element);
- element = "";
- spreads_element = "";
- }
- }
- util.trim(natures);
- util.trim(spreads_array);
- for (var c1 = 0; c1 < natures.length; c1++) { //Removes useless characters
- natures[c1] = natures[c1].substring(1, natures[c1].length);
- spreads_array[c1] = spreads_array[c1].substring(0, spreads_array[c1].length-1);
- spreads_substring = util.trim(spreads_array[c1].split(" ")); //Splits a string that looks like this 252/0/252/4/0/0 98.78
- spreads.push(util.trim(spreads_substring[0].split("/"))); //Returns the ev's inside an array
- percentage.push(spreads_substring[1]); //Returns the percentage
- }
- spreads.pop();
- percentage.pop();
- natures.pop();
- return { "natures" : natures, "spreads": spreads, "percentage" : percentage }; //Returns the array
- }
- //HANDLE Progress
- pokemonStatistics.prototype.handleProcessingData = function () {
- eval(this["handleProcessingData_string"]);
- };
- pokemonStatistics.prototype.setHandleProcessingData = function (functionName) {
- this["handleProcessingData_string"] = functionName;
- };
- pokemonStatistics.prototype.handleNotFound = function () {
- eval(this["handleNotFound_string"]);
- };
- pokemonStatistics.prototype.setHandleNotFound = function (functionName) {
- this["handleNotFound_string"] = functionName;
- };
- pokemonStatistics.prototype.handleDone = function () {
- eval(this["handleDone_string"]);
- };
- pokemonStatistics.prototype.setHandleDone = function (functionName) {
- this["handleDone_string"] = functionName;
- };
- pokemonStatistics.prototype.default = function () { };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement