yagvm/Classes/DotEnv.gd

23 lines
496 B
GDScript3
Raw Normal View History

2023-05-25 16:46:42 +00:00
extends Node
func _init() -> void:
var path = ""
if OS.has_feature("editor"):
path = ProjectSettings.globalize_path("res://.env")
else:
path = OS.get_executable_path().get_base_dir().path_join(".env")
if !FileAccess.file_exists(path):
return
var f := FileAccess.open(path, FileAccess.READ)
while !f.eof_reached():
var line := f.get_line()
var split := line.split("=")
OS.set_environment(split[0].strip_edges(), split[1].strip_edges())
func _ready() -> void:
queue_free()