-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some console logging into GWT game input code, to help track d…
…own Safari issue.
- Loading branch information
1 parent
6577ab6
commit df2239a
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,10 @@ public void openFileDialog(AppConfigItem appConfigItem, String fileType, String | |
showHtmlOpenFileDialog(fileType, new GwtOpenFileResultsHandler() { | ||
@Override | ||
public void onFileResultsReady(GwtOpenFileResult[] openFileResultArray) { | ||
if (openFileResultArray.length > 0) { | ||
logToJSConsole("Game files are now being imported into AGILE..."); | ||
} | ||
|
||
boolean hasVolFile = false; | ||
boolean hasDirFile = false; | ||
String directoryName = null; | ||
|
@@ -257,6 +261,8 @@ private boolean isGameFile(String filename) { | |
} | ||
|
||
private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResultsHandler resultsHandler)/*-{ | ||
console.log('About to create input element of type file...'); | ||
var fileInputElem = document.createElement('input'); | ||
fileInputElem.type = "file"; | ||
|
@@ -272,22 +278,33 @@ private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResults | |
fileInputElem.multiple = true; | ||
} | ||
console.log('Finished creating input element of type file'); | ||
// The onchange event occurs after a file is chosen. | ||
fileInputElem.onchange = function(event) { | ||
console.log('File input element onchange event triggered.'); | ||
console.log('The event object is: ' + event); | ||
if (this.files.length === 0) { | ||
console.log('No files selected for import'); | ||
// No file was selected, so nothing more to do. | ||
[email protected]::onFileResultsReady([Lcom/agifans/agile/gwt/GwtOpenFileResult;)([]); | ||
} | ||
else { | ||
console.log('File(s) were selected for import. Reading them now...'); | ||
// There can be multiple files, so we need to fetch all of them, and | ||
// only when all have finished loading do we invoke the callback with | ||
// content of the files. | ||
Promise.all([].map.call(this.files, function (file) { | ||
console.log('Starting to read in file ' + file.name); | ||
return new Promise(function (resolve, reject) { | ||
var reader = new FileReader(); | ||
// NOTE 1: loadend called regards of whether it was successful or not. | ||
// NOTE 2: file has .name, .size and .lastModified fields. | ||
reader.onloadend = function (event) { | ||
console.log('Finished reading in file ' + file.name); | ||
resolve({ | ||
fileName: file.name, | ||
filePath: file.webkitRelativePath? file.webkitRelativePath : '', | ||
|
@@ -297,6 +314,8 @@ private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResults | |
reader.readAsArrayBuffer(file); | ||
}); | ||
})).then(function (results) { | ||
console.log('Finished reading in all selected files.'); | ||
// The results param is an array of result objects | ||
[email protected]::onFileResultsReady([Lcom/agifans/agile/gwt/GwtOpenFileResult;)(results); | ||
}); | ||
|
@@ -305,6 +324,8 @@ private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResults | |
// Trigger the display of the open file dialog. | ||
fileInputElem.click(); | ||
console.log('File input element has been clicked.'); | ||
}-*/; | ||
|
||
@Override | ||
|
@@ -352,4 +373,8 @@ private final native void showHtmlMessageBox(String message)/*-{ | |
public boolean isDialogOpen() { | ||
return dialogOpen; | ||
} | ||
|
||
private final native void logToJSConsole(String message)/*-{ | ||
console.log(message); | ||
}-*/; | ||
} |