Skip to content

Commit

Permalink
[win] fix pathes and toolkit execution, works on windows for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jkb0o committed Feb 28, 2021
1 parent 642e0d6 commit 3645569
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ if (settings) {
fl.showIdleMessage(false);

let originalDoc = fl.getDocumentDOM();
let originalUri = "file://" + originalDoc.path;
let originalUri = FLfile.platformPathToURI(originalDoc.path);
originalDoc.save(false);

let exportProjectArchive = settings.exportPath;
let exportProjectDir = path.getProjectPrefix() + ".fnx.export/";
let exportProjectPath = exportProjectDir + path.file(exportProjectDir) + ".xfl";
let exportProjectDirUri = "file://" + exportProjectDir;
let exportProjectPathUri = "file://" + exportProjectPath;
let exportProjectDirUri = FLfile.platformPathToURI(exportProjectDir);
let exportProjectPathUri = FLfile.platformPathToURI(exportProjectPath);
fl.trace("Export Project URI: " + exportProjectPathUri);
if (FLfile.exists(exportProjectDirUri)) FLfile.remove(exportProjectDirUri);
FLfile.createFolder(exportProjectDirUri);
fl.trace("Exporting project");
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rasterizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Rasterizer {
this.rasterizeItem(item.name);
}

let baseUri = "file://" + path.base(fl.getDocumentDOM().path) + "/LIBRARY/";
let baseUri = FLfile.platformPathToURI(path.base(fl.getDocumentDOM().path) + "/LIBRARY/");
let result: FlashBitmapItem[] = [];
for (let item of fl.getDocumentDOM().library.items.filter(item => item.name in this.bitmapItems)) {
let bitmap = item as FlashBitmapItem;
Expand Down
25 changes: 18 additions & 7 deletions src/lib/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function generateSpriteSheets(bitmaps: FlashBitmapItem[], padding: number
}

let exporters = attempts.sort( (a, b) => a.getSquare() - b.getSquare())[0].exporters;
let baseUri = "file://" + path.base(fl.getDocumentDOM().path);
let baseUri = FLfile.platformPathToURI(path.base(fl.getDocumentDOM().path));
let idx = 0;
let exportedSpriteSheets = "";
//fl.trace(`created ${exporters.length} spritesheets`);
Expand All @@ -126,7 +126,7 @@ export function generateSpriteSheets(bitmaps: FlashBitmapItem[], padding: number
// to rename and move bitmaps to own folder
function normalizeLibrary(bitmaps: FlashBitmapItem[]) {
let lib = fl.getDocumentDOM().library;
let basePath = `file://${path.base(fl.getDocumentDOM().path)}/LIBRARY`;
let basePath = FLfile.platformPathToURI(`${path.base(fl.getDocumentDOM().path)}/LIBRARY`);
let idx = 0;
lib.newFolder("gdexp");
for (let bitmap of bitmaps) {
Expand Down Expand Up @@ -163,8 +163,8 @@ function normalizeLibrary(bitmaps: FlashBitmapItem[]) {

// removes bin folder & clears images from library (all required images are stored in atlases already)
export function cleanUpProject(path: String) {
FLfile.remove(`file://${path}bin/`)
let rootUri = `file://${path}LIBRARY/`;
FLfile.remove(FLfile.platformPathToURI(`${path}bin/`))
let rootUri = FLfile.platformPathToURI(`${path}LIBRARY/`);
let dirs = [""];

while (dirs.length) {
Expand All @@ -185,13 +185,24 @@ export function cleanUpProject(path: String) {
// invokes toolkig command
export function invoke(command: string, args:{ [id: string] : string; } = { }) {
let isOSX = (fl.version.indexOf("MAC") != -1);
let doc = fl.getDocumentDOM();
let toolkitPath = `${fl.configDirectory}Commands/Funexpected Tools/toolkit`;
if (!isOSX) toolkitPath += ".exe";
let cmd = `"${toolkitPath}" ${command}`;
for (let arg in args) {
cmd += ` --${arg} "${args[arg]}"`;
}
//fl.trace("executing " + cmd);
FLfile.runCommandLine(cmd);
if (isOSX) {
FLfile.runCommandLine(cmd);
return;
}

// there is smthing wrong with FLfile.runCommandLine
// see https://stackoverflow.com/questions/9116828/jsfl-flfile-runcommandline-properly-escaping-spaces-for-windows-commandline-a
let tmpBatDir = FLfile.platformPathToURI("c:/temp");
if (!FLfile.exists(tmpBatDir)) {
FLfile.createFolder(tmpBatDir)
}
let tmpBat = "c:/temp/fnxcmd.bat"
FLfile.write(FLfile.platformPathToURI(tmpBat), cmd);
FLfile.runCommandLine(tmpBat);
}

0 comments on commit 3645569

Please sign in to comment.