forked from LeenkxTeam/Leenkx_Examples
update
This commit is contained in:
0
file_read/Bundled/canvas/MyCanvas.files
Normal file
0
file_read/Bundled/canvas/MyCanvas.files
Normal file
1
file_read/Bundled/canvas/MyCanvas.json
Normal file
1
file_read/Bundled/canvas/MyCanvas.json
Normal file
@ -0,0 +1 @@
|
||||
{"name":"untitled","x":0,"y":0,"width":1280,"height":720,"elements":[{"id":0,"type":0,"name":"Text","event":"","x":0,"y":0,"width":372,"height":44,"rotation":0,"text":"My Text","asset":"","color":-1,"anchor":0,"parent":null,"children":[],"visible":true,"color_text":-16744449}],"assets":[],"theme":"Default Light"}
|
||||
1
file_read/Bundled/canvas/_themes.json
Normal file
1
file_read/Bundled/canvas/_themes.json
Normal file
@ -0,0 +1 @@
|
||||
[{"NAME":"Default Light","WINDOW_BG_COL":-1052689,"WINDOW_TINT_COL":-14540254,"ACCENT_COL":-1118482,"ACCENT_HOVER_COL":-4473925,"ACCENT_SELECT_COL":-5592406,"BUTTON_COL":-3355444,"BUTTON_TEXT_COL":-14540254,"BUTTON_HOVER_COL":-5000269,"BUTTON_PRESSED_COL":-5131855,"TEXT_COL":-6710887,"LABEL_COL":-5592406,"SEPARATOR_COL":-6710887,"HIGHLIGHT_COL":-14656100,"CONTEXT_COL":-5592406,"PANEL_BG_COL":-5592406,"FONT_SIZE":26,"ELEMENT_W":200,"ELEMENT_H":48,"ELEMENT_OFFSET":8,"ARROW_SIZE":10,"BUTTON_H":44,"CHECK_SIZE":30,"CHECK_SELECT_SIZE":16,"SCROLL_W":12,"TEXT_OFFSET":16,"TAB_W":24,"FILL_WINDOW_BG":false,"FILL_BUTTON_BG":true,"FILL_ACCENT_BG":false,"LINK_STYLE":0}]
|
||||
3
file_read/Bundled/my_file.json
Normal file
3
file_read/Bundled/my_file.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"my_text": "Hello from json!"
|
||||
}
|
||||
1
file_read/README.md
Normal file
1
file_read/README.md
Normal file
@ -0,0 +1 @@
|
||||
Loads a json file from the `Bundled/` directory.
|
||||
34
file_read/Sources/lnx/ReadFile.hx
Normal file
34
file_read/Sources/lnx/ReadFile.hx
Normal file
@ -0,0 +1,34 @@
|
||||
package lnx;
|
||||
|
||||
import leenkx.trait.internal.CanvasScript;
|
||||
import iron.data.Data;
|
||||
import iron.Scene;
|
||||
|
||||
class ReadFile extends iron.Trait {
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnInit(function() {
|
||||
|
||||
// Relative or absolute path to file
|
||||
// In this case we load the file placed in the "Bundled/" directory
|
||||
var file = "my_file.json";
|
||||
|
||||
// Load the file asynchronously
|
||||
Data.getBlob(file, function(b:kha.Blob) {
|
||||
// File is now loaded
|
||||
// Get string from loaded bytes
|
||||
var string = b.toString();
|
||||
|
||||
// Get json from string
|
||||
var json = haxe.Json.parse(string);
|
||||
|
||||
// Get canvas trait
|
||||
var canvas = Scene.active.getTrait(CanvasScript);
|
||||
|
||||
// Display "my_text" entry found in the loaded json file
|
||||
canvas.getElement("Text").text = json.my_text;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
file_read/file_read.blend
Normal file
BIN
file_read/file_read.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user