Keep window size when closing

This commit is contained in:
Synthasmagoria 2026-09-15 21:41:31 +02:00
commit 2b91b8783c
6 changed files with 80 additions and 6 deletions

1
config Normal file
View file

@ -0,0 +1 @@
{"window_size":[1917.00000000,1098.00000000]}

View file

@ -18,3 +18,17 @@ project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError
project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
return _project_read(project, path)
}
CONFIG_FILE_NAME :: "config"
ConfigData :: struct {
window_size: v2,
}
config_write :: proc(config: ConfigData, temp_allocator := context.temp_allocator) -> ConfigWriteError {
return _config_write(config)
}
config_read :: proc(temp_allocator := context.temp_allocator) -> (config: ConfigData, error: ConfigReadError) {
return _config_read(temp_allocator)
}

View file

@ -6,6 +6,7 @@ package game
import "core:os"
import "core:io"
import "core:mem"
import "core:encoding/json"
ProjectReadErrorType :: enum {
FailedReadingHeader,
@ -63,3 +64,25 @@ _project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
_ = io.read_ptr(r, &project.shapes, size_of(project.shapes)) or_return
return nil
}
ConfigWriteError :: union {
json.Marshal_Error,
os.Error,
}
_config_write :: proc(config: ConfigData, temp_allocator := context.temp_allocator) -> ConfigWriteError {
data := json.marshal(config, allocator = temp_allocator) or_return
os.write_entire_file(CONFIG_FILE_NAME, data) or_return
return nil
}
ConfigReadError :: union {
os.Error,
json.Unmarshal_Error,
}
_config_read :: proc(temp_allocator := context.temp_allocator) -> (config: ConfigData, error: ConfigReadError) {
data := os.read_entire_file(CONFIG_FILE_NAME, temp_allocator) or_return
json.unmarshal(data, &config, allocator = temp_allocator) or_return
return config, nil
}

View file

@ -24,3 +24,27 @@ _project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError
_project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
return ProjectReadErrorType.LoadingProjectNotSupportedOnWeb;
}
ConfigWriteErrorType :: enum {
WritingConfigNotSupportedOnWeb,
}
ConfigWriteError :: union {
ConfigWriteErrorType,
}
ConfigReadErrorType :: enum {
ReadingConfigNotSupportedOnWeb,
}
ConfigReadError :: union {
ConfigReadErrorType,
}
_config_write :: proc(config: ConfigData, temp_allocator := context.temp_allocator) -> ConfigWriteError {
return .WritingConfigNotSupportedOnWeb
}
_config_read :: proc(temp_allocator := context.temp_allocator) -> (config: ConfigData, error: ConfigReadError) {
return {}, .ReadingConfigNotSupportedOnWeb
}

View file

@ -35,6 +35,7 @@ shutdown :: proc() {
should_run :: proc() -> bool {
when ODIN_OS != .JS {
if program.window_should_close || rl.WindowShouldClose() {
program_config_write()
return false
}
}

View file

@ -435,15 +435,26 @@ program_init :: proc(allocator := context.allocator) {
if err := program_load_project(&program, default_project_load_location); err != nil {
mem.copy(&program.project_save_string[0], raw_data(default_project_load_location), len(default_project_load_location))
}
when ODIN_OS != .JS {
config, error := config_read()
if error != nil {
error := program_config_write()
if error != nil {
program_show_dialog(&program, .Error, fmt.caprint("Error: Couldn't write config file\n", typeid_of(type_of(error)), ".", error, sep = ""))
}
} else {
rl.SetWindowSize(i32(config.window_size.x), i32(config.window_size.y))
}
}
}
program_get_master_matrix :: proc() -> mat3 {
matrices := (cast([^]mat3)raw_data(program.matrix_float_pool))[:program.matrix_count]
master_matrix := linalg.identity_matrix(mat3)
#reverse for mat in matrices {
master_matrix *= mat
program_config_write :: proc() -> ConfigWriteError {
config := ConfigData{
window_size = program_screen_size()
}
return master_matrix
config_write(config) or_return
return nil
}
program_set_animation_state :: proc(state: ProgramAnimationState) {