Keep window size when closing
This commit is contained in:
parent
82e02c98a4
commit
2b91b8783c
6 changed files with 80 additions and 6 deletions
1
config
Normal file
1
config
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"window_size":[1917.00000000,1098.00000000]}
|
||||||
|
|
@ -18,3 +18,17 @@ project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError
|
||||||
project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
||||||
return _project_read(project, path)
|
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)
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ package game
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:io"
|
import "core:io"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
import "core:encoding/json"
|
||||||
|
|
||||||
ProjectReadErrorType :: enum {
|
ProjectReadErrorType :: enum {
|
||||||
FailedReadingHeader,
|
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
|
_ = io.read_ptr(r, &project.shapes, size_of(project.shapes)) or_return
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
@ -24,3 +24,27 @@ _project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError
|
||||||
_project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
_project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
||||||
return ProjectReadErrorType.LoadingProjectNotSupportedOnWeb;
|
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
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,7 @@ shutdown :: proc() {
|
||||||
should_run :: proc() -> bool {
|
should_run :: proc() -> bool {
|
||||||
when ODIN_OS != .JS {
|
when ODIN_OS != .JS {
|
||||||
if program.window_should_close || rl.WindowShouldClose() {
|
if program.window_should_close || rl.WindowShouldClose() {
|
||||||
|
program_config_write()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -435,15 +435,26 @@ program_init :: proc(allocator := context.allocator) {
|
||||||
if err := program_load_project(&program, default_project_load_location); err != nil {
|
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))
|
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 {
|
program_config_write :: proc() -> ConfigWriteError {
|
||||||
matrices := (cast([^]mat3)raw_data(program.matrix_float_pool))[:program.matrix_count]
|
config := ConfigData{
|
||||||
master_matrix := linalg.identity_matrix(mat3)
|
window_size = program_screen_size()
|
||||||
#reverse for mat in matrices {
|
|
||||||
master_matrix *= mat
|
|
||||||
}
|
}
|
||||||
return master_matrix
|
config_write(config) or_return
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
program_set_animation_state :: proc(state: ProgramAnimationState) {
|
program_set_animation_state :: proc(state: ProgramAnimationState) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue