daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. const fs = require("fs");
  4. // const path = require("path");
  5.  
  6. const isUpperCase = char => char === char.toUpperCase();
  7.  
  8. const snakeify = string => {
  9.   let snakeString = "";
  10.  
  11.   for (let [i, char] of Array.from(string).entries()) {
  12.     const lowerChar = char.toLowerCase();
  13.  
  14.     if (i === 0) {
  15.       snakeString += lowerChar;
  16.       continue;
  17.     }
  18.  
  19.     if (isUpperCase(char)) {
  20.       snakeString += `_${lowerChar}`;
  21.       continue;
  22.     }
  23.  
  24.     snakeString += char;
  25.   }
  26.  
  27.   return snakeString;
  28. }
  29.  
  30. const fp = process.argv[2];
  31. if (fp == null) {
  32.   return console.error("fp required");
  33. }
  34.  
  35. let card;
  36. try {
  37.   card = JSON.parse(fs.readFileSync(fp))
  38. } catch(error) {
  39.   return console.error(`failed to read json input: ${error}`);
  40. }
  41.  
  42. let out = {};
  43.  
  44. out.name = card.Name[0];
  45. out.description = card.Description.replace(/(?<=\{)(.*?)(?=\})/g, match => snakeify(match));
  46. out.image = card.Image;
  47. out.mana_cost = parseInt(card.ManaCost);
  48. out.damage = parseInt(card.Damage);
  49. out.health = parseInt(card.Health);
  50. out.type = card.Type.toLowerCase();
  51. out.character_type = card.Type !== "Spell" ? card.CharacterType.toLowerCase() : null;
  52. out.rarity = parseInt(card.Rarity);
  53. switch(card.Theme) {
  54.   case "Fan": {
  55.     out.theme = "fantasy";
  56.   };
  57.   case "Adv": {
  58.     out.theme = "adventure";
  59.   };
  60.   case "Sci": {
  61.     out.theme = "sci-fi";
  62.   };
  63.   case "Gen": {
  64.     out.theme = "general";
  65.   };
  66.   case "Mys": {
  67.     out.theme = "mystical";
  68.   };
  69. }
  70.  
  71. out.cast_area = snakeify(card.CastArea);
  72.  
  73. out.max_velocity = card.Type !== "Spell" && card.CharacterType !== "Totem" ? parseFloat(card.MaxVelocity) : null;
  74. out.time_to_reach_max_velocity = card.Type !== "Spell" && card.CharacterType !== "Totem" ? parseFloat(card.TimeToReachMaxVelocity) : null;
  75. out.agro_range_multiplier = card.Type !== "Spell" && card.CharacterType !== "Totem" ? parseFloat(card.AgroRangeMultiplier) : null;
  76.  
  77. out.can_attack = card.Type !== "Spell" && card.CharacterType !== "Totem" ? card.CanAttack : null;
  78. out.attack_range = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.CanAttack === true ? parseFloat(card.AttackRange) : null;
  79. out.pre_attack_delay = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.CanAttack === true ? parseFloat(card.PreAttackDelay) : null;
  80. out.knockback = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.CanAttack === true ? parseFloat(card.KnockbackImpulse) : null;
  81. out.knockback_angle = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.CanAttack === true ? parseFloat(card.KnockbackAngleDeg) : null;
  82. out.time_between_attacks = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.CanAttack === true ? parseFloat(card.TimeInBetweenAttacks) : null;
  83.  
  84. // TODO: power stuff
  85. for (let [k, v] of Object.entries(card)) {
  86.   if (k.startsWith("Power") && k !== "PowerDuration" && v != null) {
  87.     out.power_type = snakeify(k);
  88.     out.power_amount = parseInt(v);
  89.     break;
  90.   }
  91. }
  92. if (out.power_type == null) {
  93.   out.has_power = false;
  94.   out.power_type = null;
  95.   out.power_amount = null;
  96. } else {
  97.   out.has_power = true;
  98. }
  99.  
  100. out.charged_power_regen = card.Type !== "Spell" && card.CharacterType !== "Totem" ? parseFloat(card.ChargedPowerRegen) : null;
  101. if (out.charged_power_regen == null) {
  102.   out.is_power_charged = false;
  103.   out.charged_power_radius = null;
  104. } else {
  105.   out.is_power_charged = true;
  106.   out.charged_power_radius = card.ChargedPowerRadius === "Global" ? 0 : parseFloat(card.ChargedPowerRadius);
  107. }
  108.  
  109. if (out.power_type == null && out.charged_power_regen == null) {
  110.   out.power_duration = null;
  111. } else {
  112.   out.power_duration = parseFloat(card.PowerDuration);
  113. }
  114.  
  115. out.has_aoe = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.AOEAttackType !== "No";
  116. out.aoe_type = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.AOEAttackType !== "No" ? card.AOEAttackType : null;
  117. out.aoe_damage_percentage = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.AOEAttackType !== "No" ? parseFloat(card.AOEDamagePercentage) : null;
  118. out.aoe_knockback_percentage = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.AOEAttackType !== "No" ? parseFloat(card.AOEKnockbackPercentage) : null;
  119. out.aoe_radius = card.Type !== "Spell" && card.CharacterType !== "Totem" && card.AOEAttackType !== "No" ? parseFloat(card.AOERadius) : null;
  120.  
  121. out.min_episode_completed = parseInt(card.Requirements.MinEpisodeCompleted);
  122. out.min_pvp_rank = parseInt(card.Requirements.MinPlayerLevel);
  123. out.min_player_level = parseInt(card.Requirements.MinPVPRank);
  124.  
  125. // tech tree
  126. const transformSlot = slot => ({
  127.   property: slot.property.startsWith("Power") ? `power_${snakeify(slot.property.slice(5, slot.property.length - 3))}` : slot.property.endsWith("Power") ? "power_unlock" : `stat_${snakeify(slot.property)}`,
  128.   value: parseInt(slot.value)
  129. })
  130.  
  131. out.tech_tree = {};
  132. out.tech_tree.slots = card.TechTree2.Slots.map(transformSlot);
  133. out.tech_tree.levels = card.TechTree2.Evolve.map(e => ({
  134.   slots: e.Slots.map(transformSlot)
  135. }));
  136.  
  137. // save modified
  138. const ext = fp.split(".")[fp.split(".").length - 1];
  139. const extLess = fp.split(".").slice(0, -1).join(".");
  140.  
  141. fs.writeFileSync(`${extLess}_conv.${ext}`, JSON.stringify(out));
  142.  
  143. console.log("successfully converted card");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top