use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method extractInkTexts.
public static void extractInkTexts(String file, String lang) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
StringBuilder sb = new StringBuilder();
try {
String line = br.readLine();
// Replace the BOM mark
if (line != null)
line = line.replace('\uFEFF', ' ');
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
} finally {
br.close();
}
JsonValue root = new JsonReader().parse(sb.toString());
// .tsv generation to help in translation
StringBuilder tsvString = new StringBuilder();
// .md generation to have a better readable document of texts
StringBuilder mdString = new StringBuilder();
OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
builder.withSuppressDateInComment(true);
OrderedProperties prop = builder.build();
extractInkTextsInternal(root, tsvString, mdString, prop);
FileUtils.writeStringToFile(new File(file + ".tsv"), tsvString.toString());
FileUtils.writeStringToFile(new File(file + ".txt"), mdString.toString());
String json = root.toJson(OutputType.json);
FileUtils.writeStringToFile(new File(file), json);
try {
String file2 = file.substring(0, file.length() - EngineAssetManager.INK_EXT.length());
if (lang == null || lang.isEmpty() || lang.equals("default"))
file2 += "-ink.properties";
else
file2 += "-ink" + "_" + lang + ".properties";
FileOutputStream os = new FileOutputStream(file2);
Writer out = new OutputStreamWriter(os, I18N.ENCODING);
prop.store(out, null);
} catch (IOException e) {
EditorLogger.error("ERROR WRITING BUNDLE: " + file + ".properties");
}
}
use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method readableInkDialogs.
public static void readableInkDialogs(String story, String lang) throws IOException {
String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
StringBuilder sb = new StringBuilder();
try {
String line = br.readLine();
// Replace the BOM mark
if (line != null)
line = line.replace('\uFEFF', ' ');
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
} finally {
br.close();
}
JsonValue root = new JsonReader().parse(sb.toString());
// TODO: Add lang and check if default
File propFile = new File(Ctx.project.getModelPath() + "/" + story + "-ink.properties");
OrderedProperties langProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
langProp.load(new InputStreamReader(new FileInputStream(propFile), I18N.ENCODING));
// .md generation to have a better readable document of texts
StringBuilder mdString = new StringBuilder();
readableInkDialogsInternal(root, mdString, langProp);
FileUtils.writeStringToFile(new File(Ctx.project.getModelPath() + "/" + story + "-DIALOGS.txt"), mdString.toString());
}
use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class I18NHandler method loadI18N.
private OrderedProperties loadI18N(String modelFilename) {
String i18nFilename = getI18NFilename(modelFilename);
// To save in alphabetical order we use the OrderedProperties
OrderedProperties i18n = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
try {
i18n.load(new InputStreamReader(new FileInputStream(i18nFilename), I18N.ENCODING));
} catch (IOException e) {
EditorLogger.error("ERROR LOADING BUNDLE: " + i18nFilename);
}
return i18n;
}
use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class Project method getGradleProperties.
public OrderedProperties getGradleProperties(File projectPath) throws FileNotFoundException, IOException {
OrderedProperties prop = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrderingCaseSensitive().build();
prop.load(new FileReader(projectPath.getAbsolutePath() + "/gradle.properties"));
return prop;
}
use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class Project method loadProject.
public void loadProject(File projectToLoad) throws IOException {
projectToLoad = checkProjectStructure(projectToLoad);
if (projectToLoad != null) {
// dispose the current project
closeProject();
this.projectFile = projectToLoad;
// Use FolderClassLoader for loading CUSTOM actions.
// TODO Add 'core/bin' and '/core/out' folders???
FolderClassLoader folderClassLoader = null;
if (new File(projectFile, "/assets").exists()) {
folderClassLoader = new FolderClassLoader(projectFile.getAbsolutePath() + "/core/build/classes/java/main");
} else {
folderClassLoader = new FolderClassLoader(projectFile.getAbsolutePath() + "/core/build/classes/main");
}
ActionFactory.setActionClassLoader(folderClassLoader);
EngineAssetManager.createEditInstance(getAssetPath());
try {
// Clear last project to avoid reloading if the project fails.
getEditorConfig().remove(LAST_PROJECT_PROP);
saveConfig();
world.loadWorldDesc();
} catch (SerializationException ex) {
// check for not compiled custom actions
if (ex.getCause() != null && ex.getCause() instanceof ClassNotFoundException) {
EditorLogger.msg("Custom action class not found. Trying to compile...");
if (RunProccess.runGradle(getProjectDir(), "desktop:compileJava")) {
folderClassLoader.reload();
world.loadWorldDesc();
} else {
this.projectFile = null;
throw new IOException("Failed to run Gradle.");
}
} else {
this.projectFile = null;
throw ex;
}
}
chapter = new Chapter(getAssetPath() + Project.MODEL_PATH);
i18n = new I18NHandler(getAssetPath() + Project.MODEL_PATH);
// No need to load the chapter. It's loaded by the chapter combo.
// loadChapter(world.getInitChapter());
projectConfig = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrderingCaseSensitive().build();
projectConfig.load(new FileInputStream(getAssetPath() + "/" + Config.PROPERTIES_FILENAME));
modified = false;
Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
window.setTitle("Adventure Editor v" + Versions.getVersion() + " - " + projectFile.getAbsolutePath());
firePropertyChange(NOTIFY_PROJECT_LOADED);
} else {
closeProject();
throw new IOException("Project not found.");
}
}
Aggregations