yarn-co / kepler

Server-side trixel rendering
1 stars 0 forks source link

No multi line card title yet #10

Open JudsonCease opened 8 years ago

JudsonCease commented 8 years ago

This logic for word wrapping the power could be used to word wrap multi line names. Here's that code.

var words = cardData.powerDesc.split(" "); var i = 0; var currentLine = 0; var linesNeeded = Math.ceil(cardData.powerDesc.length / 45); var lines = []; // An array to hold each line once it's been built. console.log("# of lines needed =", linesNeeded); lines[currentLine] = "";

      // And now we build.
      console.log("Buildin' them power lines!");
      for(var i=0;i < words.length; i++) {
        var currentWord = words[i];
        var charsInDesc = lines[currentLine].length; //We need to know the length of the line currently being built.
        var charsInWord = currentWord.length; // And the length of the next word, in advance.
        var totalChars;
        if (currentLine == 0) { // Need a special case for the first line because it includes the title.
          totalChars = charsInWord + charsInTitle + charsInDesc;
        } else {
          totalChars = charsInWord + charsInDesc;
        }
        if(totalChars <= 45) {
            lines[currentLine] = lines[currentLine] + " " + currentWord;
        } else {
          currentLine++;
          lines[currentLine] = currentWord ;
        }
      }