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