Skip to content

Commit 46f5594

Browse files
committed
Compile Ink Dialog.
1 parent 8047715 commit 46f5594

File tree

4 files changed

+89
-59
lines changed

4 files changed

+89
-59
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorCommandExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.FilenameFilter;
55
import java.io.IOException;
66

7+
import com.bladecoder.engine.assets.EngineAssetManager;
78
import com.bladecoder.engineeditor.Ctx;
89
import com.bladecoder.engineeditor.common.EditorLogger.Levels;
910
import com.bladecoder.engineeditor.model.Project;
@@ -78,7 +79,7 @@ public boolean accept(File arg0, String arg1) {
7879

7980
public void extractInkTexts(String story, String lang) {
8081
try {
81-
ModelTools.extractInkTexts(story, lang);
82+
ModelTools.extractInkTexts(Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT, lang);
8283
} catch (Exception e) {
8384
EditorLogger.printStackTrace(e);
8485
}

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/ModelTools.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public static final void checkI18NMissingKeys()
386386
}
387387

388388
public static void printUnusedSounds() {
389-
ArrayList<String> unusedSounds = new ArrayList<String>(Arrays.asList(getSoundList()));
389+
ArrayList<String> unusedSounds = new ArrayList<>(Arrays.asList(getSoundList()));
390390

391391
HashMap<String, SoundDesc> sounds = Ctx.project.getWorld().getSounds();
392392

@@ -424,8 +424,7 @@ public boolean accept(File arg0, String arg1) {
424424
return soundFiles;
425425
}
426426

427-
public static void extractInkTexts(String story, String lang) throws IOException {
428-
String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT;
427+
public static void extractInkTexts(String file, String lang) throws IOException {
429428

430429
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
431430
StringBuilder sb = new StringBuilder();
@@ -464,16 +463,12 @@ public static void extractInkTexts(String story, String lang) throws IOException
464463
FileUtils.writeStringToFile(new File(file + ".txt"), mdString.toString());
465464

466465
String json = root.toJson(OutputType.json);
467-
FileUtils.writeStringToFile(new File(file + ".new"), json);
468-
469-
FileUtils.copyFile(new File(file), new File(file + ".old"));
470-
FileUtils.copyFile(new File(file + ".new"), new File(file));
471-
new File(file + ".new").delete();
466+
FileUtils.writeStringToFile(new File(file), json);
472467

473468
try {
474469
String file2 = file.substring(0, file.length() - EngineAssetManager.INK_EXT.length());
475470

476-
if (lang.equals("default"))
471+
if (lang == null || lang.isEmpty() || lang.equals("default"))
477472
file2 += "-ink.properties";
478473
else
479474
file2 += "-ink" + "_" + lang + ".properties";
@@ -484,8 +479,6 @@ public static void extractInkTexts(String story, String lang) throws IOException
484479
} catch (IOException e) {
485480
EditorLogger.error("ERROR WRITING BUNDLE: " + file + ".properties");
486481
}
487-
488-
// Ctx.project.setModified();
489482
}
490483

491484
private static void extractInkTextsInternal(JsonValue v, StringBuilder sbTSV, StringBuilder sbMD,
@@ -499,8 +492,8 @@ else if (v.parent.parent.parent.parent == null)
499492
sbMD.append("\n==== " + v.name + " ====\n");
500493
else if (v.name.equals("s"))
501494
sbMD.append(" * ");
502-
// else
503-
// sbMD.append("\n-- " + v.name + " --\n");
495+
// else
496+
// sbMD.append("\n-- " + v.name + " --\n");
504497
}
505498

506499
for (int i = 0; i < v.size; i++) {
@@ -511,7 +504,6 @@ else if (v.name.equals("s"))
511504

512505
} else if (v.isString() && v.asString().charAt(0) == '^') {
513506
String value = v.asString().substring(1).trim();
514-
// String key = "ink." + value.hashCode();
515507

516508
if (value.length() == 0 || value.charAt(0) == '>')
517509
return;
@@ -540,7 +532,6 @@ else if (v.name.equals("s"))
540532
return;
541533
}
542534

543-
// Ctx.project.getI18N().setTranslation(key, value);
544535
prop.setProperty(key, value);
545536
sbTSV.append(key + "\t" + charName + "\t" + value + "\n");
546537

@@ -603,8 +594,8 @@ else if (v.parent.parent.parent.parent == null)
603594
sbMD.append("\n==== " + v.name + " ====\n");
604595
else if (v.name.equals("s"))
605596
sbMD.append(" * ");
606-
// else
607-
// sbMD.append("\n-- " + v.name + " --\n");
597+
// else
598+
// sbMD.append("\n-- " + v.name + " --\n");
608599
}
609600

610601
for (int i = 0; i < v.size; i++) {

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/RunProccess.java

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ private static String getClasspath(List<String> classpathEntries) {
4646
return builder.toString();
4747
}
4848

49-
public static boolean runBladeEngine(File prjFolder, String chapter,
50-
String scene, boolean fullscreen) throws IOException {
51-
List<String> args = new ArrayList<String>();
49+
public static boolean runBladeEngine(File prjFolder, String chapter, String scene, boolean fullscreen)
50+
throws IOException {
51+
List<String> args = new ArrayList<>();
5252
args.add(":desktop:run");
5353
String appArgs = "-PappArgs=['-d'";
54-
55-
if(!fullscreen)
54+
55+
if (!fullscreen)
5656
appArgs += ",'-w'";
5757

5858
if (chapter != null) {
@@ -69,49 +69,45 @@ public static boolean runBladeEngine(File prjFolder, String chapter,
6969
return runGradle(prjFolder, args);
7070
}
7171

72-
public static boolean runBladeEngineInternal(File prjFolder, String chapter,
73-
String scene)
74-
throws IOException {
75-
List<String> args = new ArrayList<String>();
72+
public static boolean runBladeEngineInternal(File prjFolder, String chapter, String scene) throws IOException {
73+
List<String> args = new ArrayList<>();
7674
args.add("-w");
7775
args.add("-adv-dir");
7876
args.add(prjFolder.getAbsolutePath());
79-
80-
if(scene != null) {
77+
78+
if (scene != null) {
8179
args.add("-t");
8280
args.add(scene);
8381
}
84-
82+
8583
if (chapter != null) {
8684
args.add("-chapter");
8785
args.add(chapter);
8886
}
8987

90-
List<String> cp = new ArrayList<String>();
88+
List<String> cp = new ArrayList<>();
9189
cp.add(System.getProperty("java.class.path"));
9290

9391
runJavaProccess("com.bladecoder.engineeditor.utils.DesktopLauncher", cp, args);
94-
92+
9593
return true;
9694
}
9795

98-
public static void runAnt(String buildFile, String target, String distDir,
99-
String projectDir, Properties props) throws IOException {
96+
public static void runAnt(String buildFile, String target, String distDir, String projectDir, Properties props)
97+
throws IOException {
10098
String packageFilesDir = "package-files/";
10199

102100
if (!new File(packageFilesDir).exists()) {
103-
EditorLogger
104-
.error("package-files folder not found. Searching folder for IDE mode.");
101+
EditorLogger.error("package-files folder not found. Searching folder for IDE mode.");
105102

106103
packageFilesDir = "src/dist/package-files/";
107104
if (!new File(packageFilesDir).exists()) {
108-
EditorLogger.error(new File(packageFilesDir).getAbsolutePath()
109-
+ " folder not found in IDE mode.");
105+
EditorLogger.error(new File(packageFilesDir).getAbsolutePath() + " folder not found in IDE mode.");
110106
return;
111107
}
112108
}
113109

114-
List<String> args = new ArrayList<String>();
110+
List<String> args = new ArrayList<>();
115111
args.add("-f");
116112
args.add(packageFilesDir + buildFile);
117113
args.add("-Dproject=" + projectDir);
@@ -127,7 +123,7 @@ public static void runAnt(String buildFile, String target, String distDir,
127123

128124
args.add(target);
129125

130-
List<String> cp = new ArrayList<String>();
126+
List<String> cp = new ArrayList<>();
131127
// cp.add(System.getProperty("java.class.path") );
132128
cp.add(packageFilesDir + "ant.jar");
133129
cp.add(packageFilesDir + "ant-launcher.jar");
@@ -146,13 +142,12 @@ public static void runAnt(String buildFile, String target, String distDir,
146142
}
147143
}
148144

149-
public static Process runJavaProccess(String mainClass,
150-
List<String> classpathEntries, List<String> args)
145+
public static Process runJavaProccess(String mainClass, List<String> classpathEntries, List<String> args)
151146
throws IOException {
152147
String javaRT = System.getProperty("java.home") + "/bin/java";
153148
String workingDirectory = ".";
154149

155-
List<String> argumentsList = new ArrayList<String>();
150+
List<String> argumentsList = new ArrayList<>();
156151
argumentsList.add(javaRT);
157152

158153
if (classpathEntries != null && classpathEntries.size() > 0) {
@@ -165,39 +160,66 @@ public static Process runJavaProccess(String mainClass,
165160
if (args != null)
166161
argumentsList.addAll(args);
167162

168-
ProcessBuilder processBuilder = new ProcessBuilder(
169-
argumentsList.toArray(new String[argumentsList.size()]));
163+
ProcessBuilder processBuilder = new ProcessBuilder(argumentsList.toArray(new String[argumentsList.size()]));
170164
// processBuilder.redirectErrorStream(true);
171165
processBuilder.directory(new File(workingDirectory));
172166
processBuilder.inheritIO();
173167

174168
return processBuilder.start();
175169
}
176-
177-
public static boolean runGradle(File workingDir, List<String> parameters) {
178-
String exec = workingDir.getAbsolutePath()
179-
+ "/"
180-
+ (System.getProperty("os.name").contains("Windows") ? "gradlew.bat"
181-
: "gradlew");
182-
183-
List<String> argumentsList = new ArrayList<String>();
170+
171+
public static boolean runGradle(File workingDir, List<String> parameters) {
172+
String exec = workingDir.getAbsolutePath() + "/"
173+
+ (System.getProperty("os.name").contains("Windows") ? "gradlew.bat" : "gradlew");
174+
175+
List<String> argumentsList = new ArrayList<>();
184176
argumentsList.add(exec);
185177
argumentsList.addAll(parameters);
186178

187179
EditorLogger.msgThreaded("Executing 'gradlew " + parameters + "'");
188180

189181
try {
190-
final ProcessBuilder pb = new ProcessBuilder(argumentsList).directory(
191-
workingDir).redirectErrorStream(true);
182+
final ProcessBuilder pb = new ProcessBuilder(argumentsList).directory(workingDir).redirectErrorStream(true);
192183

193184
// TODO: READ OUTPUT FROM pb AND print in output stream
194185
// if (System.console() != null)
195186
// pb.inheritIO();
196187

197188
final Process process = pb.start();
198189

199-
BufferedReader in = new BufferedReader(new InputStreamReader(
200-
process.getInputStream()));
190+
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
191+
String line;
192+
while ((line = in.readLine()) != null) {
193+
EditorLogger.msgThreaded(line);
194+
}
195+
196+
process.waitFor();
197+
return process.exitValue() == 0;
198+
} catch (Exception e) {
199+
EditorLogger.msgThreaded("ERROR: " + e.getMessage());
200+
return false;
201+
}
202+
}
203+
204+
public static boolean runInklecate(File workingDir, List<String> parameters) {
205+
String exec = workingDir.getAbsolutePath() + "/" + "inklecate.exe";
206+
207+
List<String> argumentsList = new ArrayList<>();
208+
argumentsList.add(exec);
209+
argumentsList.addAll(parameters);
210+
211+
EditorLogger.msgThreaded("Executing 'inklecate " + parameters + "'");
212+
213+
try {
214+
final ProcessBuilder pb = new ProcessBuilder(argumentsList).directory(workingDir).redirectErrorStream(true);
215+
216+
// TODO: READ OUTPUT FROM pb AND print in output stream
217+
// if (System.console() != null)
218+
// pb.inheritIO();
219+
220+
final Process process = pb.start();
221+
222+
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
201223
String line;
202224
while ((line = in.readLine()) != null) {
203225
EditorLogger.msgThreaded(line);
@@ -212,7 +234,7 @@ public static boolean runGradle(File workingDir, List<String> parameters) {
212234
}
213235

214236
public static boolean runGradle(File workingDir, String parameters) {
215-
237+
216238
String[] split = parameters.split(" ");
217239

218240
return runGradle(workingDir, Arrays.asList(split));

adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ToolsWindow.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.bladecoder.engineeditor.common.ModelTools;
4444
import com.bladecoder.engineeditor.common.RunProccess;
4545
import com.bladecoder.engineeditor.model.Project;
46+
import com.bladecoder.engineeditor.ui.CompileInkDialog;
4647
import com.kotcrab.vis.ui.widget.file.FileChooser;
4748
import com.kotcrab.vis.ui.widget.file.FileChooser.Mode;
4849
import com.kotcrab.vis.ui.widget.file.FileChooser.SelectionMode;
@@ -70,6 +71,7 @@ public ToolsWindow(Skin skin, ScnWidget sw) {
7071
TextButton exportUIImages = new TextButton("Export UI Images", skin, "no-toggled");
7172
TextButton createUIAtlas = new TextButton("Create UI Atlas", skin, "no-toggled");
7273
TextButton particleEditor = new TextButton("Particle Editor", skin, "no-toggled");
74+
TextButton compileInk = new TextButton("Compile Ink Script", skin, "no-toggled");
7375

7476
table.defaults().left().expandX();
7577
table.top().pad(DPIUtils.getSpacing() / 2);
@@ -112,6 +114,9 @@ public ToolsWindow(Skin skin, ScnWidget sw) {
112114
table.row();
113115
table.add(particleEditor).expandX().fill();
114116

117+
table.row();
118+
table.add(compileInk).expandX().fill();
119+
115120
// table.row();
116121
// table.add(tmpButton).expandX().fill();
117122

@@ -194,12 +199,23 @@ public void changed(ChangeEvent event, Actor actor) {
194199
}
195200
});
196201

202+
compileInk.addListener(new ChangeListener() {
203+
@Override
204+
public void changed(ChangeEvent event, Actor actor) {
205+
compileInk();
206+
}
207+
});
208+
197209
table.pack();
198210
setActor(table);
199211
prefSize(table.getWidth(), Math.max(200, table.getHeight()));
200212
setSize(table.getWidth(), Math.max(200, table.getHeight()));
201213
}
202214

215+
protected void compileInk() {
216+
new CompileInkDialog(getActor().getSkin()).show(getStage());
217+
}
218+
203219
protected void createUIAtlas() {
204220
FileChooser fileChooser = new FileChooser(Mode.OPEN);
205221
fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
@@ -553,7 +569,7 @@ public void run() {
553569

554570
private void particleEditor() {
555571
// Open the particle editor
556-
List<String> cp = new ArrayList<String>();
572+
List<String> cp = new ArrayList<>();
557573
cp.add(System.getProperty("java.class.path"));
558574
try {
559575
RunProccess.runJavaProccess("com.badlogic.gdx.tools.particleeditor.ParticleEditor", cp, null);

0 commit comments

Comments
 (0)