Skip to content

Commit

Permalink
Merge branch 'master' into jz/reverse-dynamic-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
smwhr authored May 14, 2024
2 parents 87f8596 + b35555e commit 97254b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
55 changes: 33 additions & 22 deletions script/inkjs-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var path = require('path');
import * as fs from "fs";
import { ErrorHandler } from '../src/engine/Error';

const BOM = '\u{feff}';

const help = process.argv.includes("-h");
if(help){
process.stdout.write(`
Expand Down Expand Up @@ -36,30 +38,39 @@ if(!inputFile){
process.stderr.write("No input file specified. -h for help\n");
process.exit(1);
}
outputfile = outputfile || inputFile+".json";

const fileHandler = new PosixFileHandler(path.dirname(inputFile));
const mainInk = fileHandler.LoadInkFileContents(inputFile);

const errorHandler: ErrorHandler = (message, errorType) => {
process.stderr.write(message + "\n");
};
const options = new CompilerOptions(
inputFile, [], countAllVisit, errorHandler, fileHandler
)

const c = new Compiler(mainInk, options);
const rstory = c.Compile();
if (!rstory) {
process.stderr.write("*** Compilation failed ***\n");
process.exit(1);
}

const jsonStory = rstory.ToJson()
let jsonStory: string = "";

if(!inputFile.endsWith(".json")){
outputfile = outputfile || inputFile+".json";

const fileHandler = new PosixFileHandler(path.dirname(inputFile));
const mainInk = fileHandler.LoadInkFileContents(inputFile);

const errorHandler: ErrorHandler = (message, errorType) => {
process.stderr.write(message + "\n");
};
const options = new CompilerOptions(
inputFile, [], countAllVisit, errorHandler, fileHandler
)

if(jsonStory && write){
const BOM = '\u{feff}';
fs.writeFileSync(outputfile, BOM+jsonStory);
const c = new Compiler(mainInk, options);
const rstory = c.Compile();
if (!rstory) {
process.stderr.write("*** Compilation failed ***\n");
process.exit(1);
}
let jsonified: string | void;

if((jsonified = rstory.ToJson())){
jsonStory = jsonified
}

if(jsonStory && write){
fs.writeFileSync(outputfile, BOM+jsonStory);
}
}else{
jsonStory = fs.readFileSync(inputFile,"utf-8").replace(BOM, "")
}

if(jsonStory && play){
Expand Down
2 changes: 1 addition & 1 deletion src/engine/ControlCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class ControlCommand extends InkObject {
return new ControlCommand(ControlCommand.CommandType.EndTag);
}
public toString() {
return this.commandType.toString();
return "ControlCommand " + this.commandType.toString();
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/engine/Void.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { InkObject } from "./Object";

export class Void extends InkObject {}
export class Void extends InkObject {
public toString() {
return "Void";
}
}

0 comments on commit 97254b0

Please sign in to comment.