2021-03-25 16:53:13 +01:00
|
|
|
module obj
|
2021-04-20 16:16:35 +02:00
|
|
|
|
2021-03-25 16:53:13 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
// read a file as single lines
|
|
|
|
pub fn read_lines_from_file(file_path string) []string {
|
2021-04-20 16:16:35 +02:00
|
|
|
mut path := ''
|
2021-03-25 16:53:13 +01:00
|
|
|
mut rows := []string{}
|
|
|
|
$if android {
|
2021-04-20 16:16:35 +02:00
|
|
|
path = 'models/' + file_path
|
2021-03-25 16:53:13 +01:00
|
|
|
bts := os.read_apk_asset(path) or {
|
2021-04-20 16:16:35 +02:00
|
|
|
eprintln('File [$path] NOT FOUND!')
|
2021-03-25 16:53:13 +01:00
|
|
|
return rows
|
|
|
|
}
|
|
|
|
rows = bts.bytestr().split_into_lines()
|
|
|
|
} $else {
|
2021-04-27 07:18:48 +02:00
|
|
|
path = os.resource_abs_path('assets/models/' + file_path)
|
2021-03-25 16:53:13 +01:00
|
|
|
rows = os.read_lines(path) or {
|
2021-04-27 07:18:48 +02:00
|
|
|
eprintln('File [$path] NOT FOUND! file_path: $file_path')
|
2021-03-25 16:53:13 +01:00
|
|
|
return rows
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows
|
|
|
|
}
|
|
|
|
|
2022-04-15 14:35:35 +02:00
|
|
|
// read a file as []u8
|
|
|
|
pub fn read_bytes_from_file(file_path string) []u8 {
|
2021-04-20 16:16:35 +02:00
|
|
|
mut path := ''
|
2022-04-15 14:35:35 +02:00
|
|
|
mut buffer := []u8{}
|
2021-03-25 16:53:13 +01:00
|
|
|
$if android {
|
2021-04-20 16:16:35 +02:00
|
|
|
path = 'models/' + file_path
|
2021-03-25 16:53:13 +01:00
|
|
|
buffer = os.read_apk_asset(path) or {
|
2021-04-20 16:16:35 +02:00
|
|
|
eprintln('Texure file: [$path] NOT FOUND!')
|
2021-03-25 16:53:13 +01:00
|
|
|
exit(0)
|
|
|
|
}
|
|
|
|
} $else {
|
2021-04-27 07:18:48 +02:00
|
|
|
path = os.resource_abs_path('assets/models/' + file_path)
|
2021-03-25 16:53:13 +01:00
|
|
|
buffer = os.read_bytes(path) or {
|
2021-04-20 16:16:35 +02:00
|
|
|
eprintln('Texure file: [$path] NOT FOUND!')
|
2021-03-25 16:53:13 +01:00
|
|
|
exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buffer
|
2021-04-20 16:16:35 +02:00
|
|
|
}
|