diff --git a/config b/config new file mode 100644 index 0000000..054bf6b --- /dev/null +++ b/config @@ -0,0 +1 @@ +{"window_size":[1917.00000000,1098.00000000]} \ No newline at end of file diff --git a/src/project.odin b/src/formats.odin similarity index 55% rename from src/project.odin rename to src/formats.odin index 8d09a98..4aac48a 100644 --- a/src/project.odin +++ b/src/formats.odin @@ -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) +} diff --git a/src/project_default.odin b/src/formats_default.odin similarity index 75% rename from src/project_default.odin rename to src/formats_default.odin index 9b7c61b..5828b78 100644 --- a/src/project_default.odin +++ b/src/formats_default.odin @@ -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 +} diff --git a/src/project_web.odin b/src/formats_web.odin similarity index 51% rename from src/project_web.odin rename to src/formats_web.odin index 1a35c02..037e4b1 100644 --- a/src/project_web.odin +++ b/src/formats_web.odin @@ -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 +} diff --git a/src/main.odin b/src/main.odin index bfac4fe..b11cb4c 100644 --- a/src/main.odin +++ b/src/main.odin @@ -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 } } diff --git a/src/program.odin b/src/program.odin index 6709ba9..2567b65 100644 --- a/src/program.odin +++ b/src/program.odin @@ -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) {