Parser for dialogues

master
Jonathan Hager 5 years ago
parent ee41910b9a
commit 5cae1b9bfa

@ -0,0 +1,11 @@
Ultra geile ultra Frage
Antwort 2#5
Antwort 7#9
Frage von Antwort 2
Nice#-1
Nice2#-1
Frage von Antwort 7
lolol#-1
lolol#-1

@ -0,0 +1,6 @@
package com.trs.main;
public class Dialogue {
String question;
String[] ans;
}

@ -0,0 +1,51 @@
package com.trs.main;
import java.util.ArrayList;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
public class DialogueParser {
private int line;
private String[] file;
public DialogueParser(String filename) {
line = 0;
FileHandle fileHandle = Gdx.files.internal(filename);
String text = fileHandle.readString();
file = text.split("\\r?\\n");
}
public DialogueParser(String filename, int line) {
this.line = line - 1;
FileHandle fileHandle = Gdx.files.internal(filename);
String text = fileHandle.readString();
file = text.split("\\r?\\n");
}
public Dialogue nextDialog(int selectedAns) {
Dialogue result = new Dialogue();
String s = file[line + selectedAns];
String[] newLine = s.split("#");
line = Integer.parseInt(newLine[1]);
if(line == -1) {
return null;
}
result.question = file[line];
ArrayList<String> ans = new ArrayList<>();
for(int i = line + 1; i < file.length; i++) {
String tempAns = file[i];
if(tempAns.equals("")) {
break;
}
else {
ans.add(tempAns);
}
}
result.ans = (String[]) ans.toArray();
return result;
}
}

@ -91,7 +91,7 @@ public class MapContainer {
p.movementX = 0;
p.movementY = 0;
stage.addActor(p);
}

@ -30,11 +30,14 @@ public class MovingNpc extends Actor{
float movementX;
float movementY;
DialogueParser parser;
Vector2 POI;
public MovingNpc(Rectangle area, float xPos, float yPos){
setName("npc");
Texture t = new Texture(Gdx.files.internal("player.png"));
parser = new DialogueParser("dialogues/test.txt");
animatedSprite = new AnimatedSprite(t, 64, 64);
animatedSprite.setRow(0);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 48);

Loading…
Cancel
Save