1. if (process.argv.indexOf("--help") >= 0) {
  2. [
  3. "",
  4. " [b]findGravityRegions.js originally intended[/b] to generate [b]vertex sequences[/b] for zero-gravity outlines, but now can trace outlines for any given tile.", "",
  5. " required argument: tile target, e.g. 3 to outline all sections of tile type 3", "",
  6. " optional flag: --invert to outline regions that are NOT the provided tile type (e.g. used to generate full-level outlines",
  7. ""
  8. ].forEach(function(s) {
  9. // consistent indentation
  10. var shouldIndent = (s.substr(0, 2) === " "),
  11. indentString = "";
  12. while (s.substr(0, 2) === " ") {
  13. indentString += " ";
  14. s = s.substr(2);
  15. }
  16. var isBold = false;
  17. words = s.split(" ");
  18. var buffer = shouldIndent ? indentString : "",
  19. charsUsed = 0;
  20. while (words.length > 0) {
  21. var nextWord = words.splice(0, 1)[0] + " ",
  22. nextWordLength = nextWord.replace("[b]", "").replace("[/b]").length;
  23. // enable bold
  24. if (nextWord.substr(0, 3) === "[b]") {
  25. isBold = true;
  26. nextWord = "\x1b[1m" + nextWord.substr(3);
  27. }
  28. if (charsUsed + nextWordLength < 75) {
  29. buffer += nextWord;
  30. charsUsed += nextWordLength;
  31. // disable bold?
  32. if (nextWord.substr(nextWord.length - 5, 4) === "[/b]") {
  33. isBold = false;
  34. buffer = buffer.substr(0, buffer.length - 5) + " " + "\x1b[0m";
  35. }
  36. } else {
  37. console.log(buffer);
  38. buffer = (shouldIndent ? indentString : "") + nextWord;
  39. charsUsed = (shouldIndent ? indentString.length : 0) + nextWordLength;
  40. if (isBold) {
  41. buffer = "\x1b[1m" + buffer;
  42. }
  43. // disable bold?
  44. if (nextWord.substr(nextWord.length - 5, 4) === "[/b]") {
  45. isBold = false;
  46. buffer = buffer.substr(0, buffer.length - 5) + " " + "\x1b[0m";
  47. }
  48. }
  49. }
  50. // remainder
  51. if (buffer.length > 0)
  52. console.log(buffer);
  53. else
  54. console.log("");
  55. });
  56. process.exit(0);
  57. }