Skip to content

Commit

Permalink
Merge pull request #3103 from t3du/WriteForHtml5
Browse files Browse the repository at this point in the history
WriteJsonNode and WriteFileNode: add Html5 version
  • Loading branch information
luboslenco authored Dec 17, 2024
2 parents d9fd784 + 1351eb4 commit 13e2c16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions armory/Sources/armory/logicnode/WriteFileNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class WriteFileNode extends LogicNode {
var path = Krom.getFilesLocation() + "/" + file;
var bytes = haxe.io.Bytes.ofString(data);
Krom.fileSaveBytes(path, bytes.getData());

#elseif kha_html5
var blob = new js.html.Blob([data], {type: "application"});
var url = js.html.URL.createObjectURL(blob);
var a = cast(js.Browser.document.createElement("a"), js.html.AnchorElement);
a.href = url;
a.download = file;
a.click();
js.html.URL.revokeObjectURL(url);
#end
}
}
10 changes: 9 additions & 1 deletion armory/Sources/armory/logicnode/WriteJsonNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ class WriteJsonNode extends LogicNode {
var file: String = inputs[1].get();
var data: Dynamic = inputs[2].get();
var s = haxe.Json.stringify(data);
trace(s);

#if kha_krom
var path = Krom.getFilesLocation() + "/" + file;
var bytes = haxe.io.Bytes.ofString(s);
Krom.fileSaveBytes(path, bytes.getData());

#elseif kha_html5
var blob = new js.html.Blob([s], {type: "application/json"});
var url = js.html.URL.createObjectURL(blob);
var a = cast(js.Browser.document.createElement("a"), js.html.AnchorElement);
a.href = url;
a.download = file;
a.click();
js.html.URL.revokeObjectURL(url);
#end
}
}

0 comments on commit 13e2c16

Please sign in to comment.