Search in sources :

Example 6 with OrderedPropertiesBuilder

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");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonValue(com.badlogic.gdx.utils.JsonValue) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) JsonReader(com.badlogic.gdx.utils.JsonReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 7 with OrderedPropertiesBuilder

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JsonValue(com.badlogic.gdx.utils.JsonValue) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) JsonReader(com.badlogic.gdx.utils.JsonReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with OrderedPropertiesBuilder

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) OrderedProperties(com.bladecoder.engineeditor.common.OrderedProperties) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 9 with OrderedPropertiesBuilder

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;
}
Also used : OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder)

Example 10 with OrderedPropertiesBuilder

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.");
    }
}
Also used : Lwjgl3Graphics(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics) SerializationException(com.badlogic.gdx.utils.SerializationException) Lwjgl3Window(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder)

Aggregations

OrderedPropertiesBuilder (com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder)10 FileInputStream (java.io.FileInputStream)8 InputStreamReader (java.io.InputStreamReader)8 File (java.io.File)7 BufferedWriter (java.io.BufferedWriter)5 FileWriter (java.io.FileWriter)5 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 BufferedReader (java.io.BufferedReader)3 JsonReader (com.badlogic.gdx.utils.JsonReader)2 JsonValue (com.badlogic.gdx.utils.JsonValue)2 IOException (java.io.IOException)2 Lwjgl3Graphics (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics)1 Lwjgl3Window (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window)1 SerializationException (com.badlogic.gdx.utils.SerializationException)1 OrderedProperties (com.bladecoder.engineeditor.common.OrderedProperties)1 FilenameFilter (java.io.FilenameFilter)1 Entry (java.util.Map.Entry)1