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-20 16:16:35 +02:00
|
|
|
path = 'assets/models/' + file_path
|
2021-03-25 16:53:13 +01:00
|
|
|
rows = os.read_lines(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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows
|
|
|
|
}
|
|
|
|
|
|
|
|
// read a file as []byte
|
|
|
|
pub fn read_bytes_from_file(file_path string) []byte {
|
2021-04-20 16:16:35 +02:00
|
|
|
mut path := ''
|
2021-03-25 16:53:13 +01:00
|
|
|
mut buffer := []byte{}
|
|
|
|
$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-20 16:16:35 +02:00
|
|
|
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
|
|
|
}
|