j
This commit is contained in:
parent
5b65c4c0e4
commit
985aa16236
13 changed files with 1381 additions and 241 deletions
43
client/odin/settings.odin
Normal file
43
client/odin/settings.odin
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
import json "core:encoding/json"
|
||||
|
||||
Editor_Settings :: struct {
|
||||
font_path: string,
|
||||
}
|
||||
|
||||
editor_settings_load :: proc() -> Editor_Settings {
|
||||
settings := Editor_Settings{}
|
||||
path, ok := editor_settings_path(context.temp_allocator)
|
||||
if !ok do return settings
|
||||
|
||||
data, err := os.read_entire_file(path, context.allocator)
|
||||
if err != nil do return settings
|
||||
defer delete(data)
|
||||
|
||||
value, parse_err := json.parse_string(string(data), .JSON, true)
|
||||
if parse_err != nil do return settings
|
||||
defer json.destroy_value(value)
|
||||
|
||||
font_path, has_font_path := json_get_string(value, "fontPath")
|
||||
if has_font_path && len(strings.trim_space(font_path)) > 0 {
|
||||
settings.font_path = strings.clone(strings.trim_space(font_path))
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
editor_settings_destroy :: proc(settings: ^Editor_Settings) {
|
||||
delete(settings.font_path)
|
||||
}
|
||||
|
||||
editor_settings_path :: proc(allocator := context.allocator) -> (string, bool) {
|
||||
if env := os.get_env("NATIVE_EDITOR_SETTINGS", allocator); len(env) > 0 {
|
||||
return env, true
|
||||
}
|
||||
home := os.get_env("HOME", allocator)
|
||||
if len(home) == 0 do return "", false
|
||||
return fmt.aprintf("%s/.config/native-kotlin-editor/settings.json", home), true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue