Skip to content

Commit

Permalink
CWT TextOnText - Done and Done [MM]
Browse files Browse the repository at this point in the history
Quickly finished the rest of the functionality on this one. Now for the 
massive cleanup phase before heading deep into the game. Will do a pass 
looking for bugs and issues, and overall cleaning up loose comments.

- Finished JSlix functionality [J/JS]
- Updated Testbed to match [J/JS]
- Updated Img README [J/JS]

- Finished Major Milestone [MM] :)
  • Loading branch information
ctomni231 committed Jan 2, 2021
1 parent af7f7ea commit 0b767f1
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 48 deletions.
91 changes: 73 additions & 18 deletions engine/js/jslix.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,24 @@ export function addLetterImage(index, str, limit){
addTextImage(index, str, -1, -limit)
}

// This is the problem, we have to make the text image beforehand
// A helper function for addTextImage turns words into paragraphs
export function addParagraghImage(index, str, limit){
addTextImage(index, str, -1, limit)
}

// A helper function for getting words out of an image, use row to
// target getting words out of a paragraph
export function addWordImage(index, str, row, limit){
addTextImage(index, str, row, limit)
}

// A helper function for getting pieces of words out of a limited line
export function addTextLineImage(index, str, row, limit){
addTextImage(index, str, row, -limit)
}

// Adds an image to the list made purely of text image characters you choose.
// Also can be used for spritesheets, if savvy enough.
// index - The image index to use (negative for font images)
// str - The string to try and draw out
// row (Opt) - used to pull a specific row from an image (negative for all)
Expand Down Expand Up @@ -200,7 +217,7 @@ export function addTextImage(index, str, row, limit){

// Pulls relevant information from the textInfo class
let tmpInfo = jslix.textInfo[index];
//str = normalizeStr([index, str, row, limit]);
str = normalizeStr([index, str, row, limit]);
let drop = 0;
let back = 0;

Expand Down Expand Up @@ -811,8 +828,7 @@ function normalizeStr(txtArr){
if(letdim[0] > 0 && letdim[1] > 0){

// Set the mode (which determines \n spacing)
let wordmode = (lim >= 0);
let count = 1;
let wordmode = (lim > 0);

// Make sure limit is always valid
if(lim <= 0)
Expand All @@ -821,25 +837,64 @@ function normalizeStr(txtArr){
let newstr = "";
let max = 0;

if(wordmode){
let tracker = -1;
let word = "";
for(let i = 0; i < str.length; i++){
max += 1;
word += str[i];
if(str.charAt(i) === ' ' || str.charAt(i) === '-') {
tracker = i;
newstr += word;
word = "";
}
if(str.charAt(i) === '\n' || max*letdim[0] > lim){
if(tracker >= 0){
if(str.charAt(i) !== '\n')
newstr += '\n';
newstr += word;
max = word.length;
word = "";
}else{
newstr += word;
word = "";
max = 0
if(str.charAt(i) !== '\n'){
if(i+1 < str.length){
if(str.charAt(i+1) === '\n')
continue
}
newstr += '\n';
}
}
}
}
if(word.length > 0)
newstr += word;
}
// This is the lettermode stuff
for(let i = 0; i < str.length; i++){
max += 1;
newstr += str[i];
if(str.charAt(i) === '\n' || max*letdim[0] > lim){
count += 1
max = 0
if(str.charAt(i) !== '\n'){
if(i+1 < str.length){
if(str.charAt(i+1) === '\n')
continue
else{
for(let i = 0; i < str.length; i++){
max += 1;
newstr += str[i];
if(str.charAt(i) === '\n' || max*letdim[0] > lim){
max = 0
if(str.charAt(i) !== '\n'){
if(i+1 < str.length){
if(str.charAt(i+1) === '\n')
continue
}
newstr += '\n';
}
newstr += '\n';
}
}
}
}

// Something completely different for word mode

// If we have a row, the string is now that row (or blank)
if(row >= 0) {
let strArr = newstr.split("\n");
newstr = (row < strArr.length) ? strArr[row].trim() : "";
}
// Return to sender
str = newstr;
}
Expand Down
11 changes: 6 additions & 5 deletions src/com/cwt/screen/TestBed.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public void init() {
// System.out.println(cool.get(i).toString());
//}

//String incr = "INCREDIBLE 01234";
//int[] temp = imgLib.getTextDim(2, incr);
//System.out.println("("+temp[0]+","+temp[1]+")");
String incr = "INCREDIBLE 01234";

imgLib.addLetterImage(2, "INCREDIBLE 01234", 10);
int[] temp = imgLib.getTextDim(2, incr);
System.out.println("("+temp[0]+","+temp[1]+")");

imgLib.addLetterImage(2, incr, 10);
//imgLib.addTextImage(2, "I DONT KNOW");
//imgLib.addTextImage(-1, (String)cool.get(0).get(0));
}
Expand All @@ -61,7 +62,7 @@ public void init() {
public void update(int timePassed) {

if(onthefly) {
imgLib.addTextImage(2, (String)cool.get(0).get(0));
imgLib.addWordImage(2, (String)cool.get(0).get(0), 2, 120);
onthefly = false;
}

Expand Down
80 changes: 63 additions & 17 deletions src/com/jslix/image/ImgLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,18 @@ public void addLetterImage(int index, String str, int limit) {
addTextImage(index, str, -1, -limit);
}

public void addParagraphImage(int index, String str, int limit) {
addTextImage(index, str, -1, limit);
}

public void addWordImage(int index, String str, int row, int limit) {
addTextImage(index, str, row, limit);
}

public void addTextLineImage(int index, String str, int row, int limit) {
addTextImage(index, str, row, limit);
}

public void addTextImage(int index, String str) {
addTextImage(index, str, -1, 0);
}
Expand Down Expand Up @@ -1375,7 +1387,6 @@ private void addTextImage(int index, String str, int row, int limit) {
int[] textdim = getTextDim(index, str);
str = normalizeStr(index, str, row, limit);


// Out with the old and in with the new
createImg(1,1);
createImg(textdim[0], textdim[1]);
Expand All @@ -1393,7 +1404,6 @@ private void addTextImage(int index, String str, int row, int limit) {
for(int i = 0; i < str.length(); i++) {

String chart = tmpInfo[7];
System.out.println("Previous - Letter: "+str.charAt(i));

// If we have an enter, time for manipulation
if(str.charAt(i) == '\n') {
Expand Down Expand Up @@ -1425,38 +1435,74 @@ private void addTextImage(int index, String str, int row, int limit) {
placeCutImg(g, index, tmppx+((i-back)*letsx), tmppy+(drop*(letsy+1)), posx*letsx, posy*letsy, letsx, letsy, this);
}
}
System.out.println(str);
int len = length();
//addImage(getGridImage());
addImage(pimg);
}

private String normalizeStr(int index, String str, int row, int limit) {

System.out.println("FINAL: " + index + " " + str + " " + row + " " + limit);
int[] letdim = getLetterDim(index);
String newstr = new String();

// Makes sure our Letters actually have dimensions
if(letdim[0] > 0 && letdim[1] > 0){

boolean wordmode = (limit >= 0);
int count = 1;
// Sets to word mode if you write a positive limit
boolean wordmode = (limit > 0);

// Make sure limit is always valid
if(limit <= 0)
limit = (limit < 0) ? -limit : str.length()*letdim[0];

int max = 0;

for(int i = 0; i < str.length(); i++){
max += 1;
newstr += str.charAt(i);
if(str.charAt(i) == '\n' || max*letdim[0] > limit){
count += 1;
max = 0;
if(str.charAt(i) != '\n')
newstr += '\n';
}
// This curates a string for Word mode
if(wordmode) {
int tracker = -1;
String word = new String();
for(int i = 0; i < str.length(); i++){
max += 1;
word += str.charAt(i);
if(str.charAt(i) == ' ' || str.charAt(i) == '-') {
tracker = i;
newstr += word;
word = "";
}
if(str.charAt(i) == '\n' || max*letdim[0] > limit){
if(tracker >= 0 ) {
if(str.charAt(i) != '\n')
newstr += '\n';
newstr += word;
max = word.length();
word = "";
}else {
newstr += word;
word = "";
max = 0;
if(str.charAt(i) != '\n')
newstr += '\n';
}
}
}
if(word.length() > 0)
newstr += word;
}
// This curates a string for Letter Mode
else {
for(int i = 0; i < str.length(); i++){
max += 1;
newstr += str.charAt(i);
if(str.charAt(i) == '\n' || max*letdim[0] > limit){
max = 0;
if(str.charAt(i) != '\n')
newstr += '\n';
}
}
}

// If we have a row, the string is now that row (or blank)
if(row >= 0) {
String[] strArr = newstr.split("\n");
newstr = (row < strArr.length) ? strArr[row].trim() : "";
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/com/jslix/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ The Java version actually sets a limit in pixels of how far something should go
- [x] Verify the addTextInfo functionality is working [Java]
- [x] Verify the addTextImage functionality is working [Java]
- [x] Verify the addLetterImage functionality is working [Java]
- [ ] Verify the addWordImage functionality is working [Java]
- [ ] Verify the addParagraphLineImage functionality is working [Java]
- [ ] Verify the addParagraphImage functionality is working [Java]
- [x] Verify the addWordImage functionality is working [Java]
- [x] Verify the addTextLineImage functionality is working [Java]
- [x] Verify the addParagraphImage functionality is working [Java]

The JavaScript version works way differently, first creating an image and pushing it into the main pipeline of images, and then displaying the image as a normal image. I suppose that is okay, but there is a lot more tracking that'll have to take place.

- [x] Verify the addTextInfo functionality is working [JavaScript]
- [x] Verify the addTextImage functionality is working [JavaScript]
- [x] Create the addLetterImage functionality is working [JavaScript]
- [ ] Create the addWordImage functionality is added [JavaScript]
- [ ] Create the addParagraphLineImage functionality is added [JavaScript]
- [ ] Create the addParagraphImage functionality is added [JavaScript]
- [x] Create the addWordImage functionality is added [JavaScript]
- [x] Create the addTextLineImage functionality is added [JavaScript]
- [x] Create the addParagraphImage functionality is added [JavaScript]

So far, really good progress to start the new year. Both versions work the exact same, and the way to draw text is infinitely less clunky than the old way of doing TextImgLibrary. Once all the spacing functionality is in, this will be the defacto JSlix class for all kinds of images.
5 changes: 3 additions & 2 deletions testbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function init(){
jslix.addTextInfo(2, 9, 5, 0, jslix.jslix.ASCII_COMBINE)

// No longer works well while pre-loading (missing letters)
jslix.addLetterImage(2, "INCREDIBLE \n012\n34", 10);
let str = "INCREDIBLE \n012\n34";
jslix.addLetterImage(2, str, 10);
}

export function update(){
Expand All @@ -30,7 +31,7 @@ export function update(){

// Works really well on the fly loading
//jslix.addLetterImage(2, "INCREDIBLE\n012\n34");
jslix.addTextImage(2, text);
jslix.addWordImage(2, text, 2, 120);

print = false;
}
Expand Down

0 comments on commit 0b767f1

Please sign in to comment.