Skip to content

Commit 5c084a2

Browse files
committed
fix: better p2d integration
1 parent e4643fa commit 5c084a2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/editor.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ void editor_editing_loop() {
285285
ye_load_scene(entry_scene);
286286
}
287287

288+
// TODO: this project pref loading should become its own thing
289+
290+
// get the p2d gravity and cell size
291+
float p2d_gravity_x = ye_config_float(SETTINGS, "p2d_gravity_x", 0.0f);
292+
float p2d_gravity_y = ye_config_float(SETTINGS, "p2d_gravity_y", 20.0f);
293+
int p2d_grid_size = ye_config_int(SETTINGS, "p2d_grid_size", 250);
294+
295+
// set the gravity
296+
YE_STATE.engine.p2d_state->gravity.x = p2d_gravity_x;
297+
YE_STATE.engine.p2d_state->gravity.y = p2d_gravity_y;
298+
YE_STATE.engine.p2d_state->_cell_size = p2d_grid_size;
299+
288300
entity_list_head = ye_get_entity_list_head();
289301

290302
// TODO: remove in future when we serialize editor prefs

src/ui/editor_settings_ui.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ void ye_editor_paint_project_settings(struct nk_context *ctx){
414414
json_object_set_new(SETTINGS, "p2d_gravity_x", json_real(gravity_x));
415415
json_object_set_new(SETTINGS, "p2d_gravity_y", json_real(gravity_y));
416416
json_object_set_new(SETTINGS, "p2d_grid_size", json_integer(grid_size));
417+
418+
// edge: when saving actually update in p2d_state
419+
YE_STATE.engine.p2d_state->gravity.x = gravity_x;
420+
YE_STATE.engine.p2d_state->gravity.y = gravity_y;
421+
YE_STATE.engine.p2d_state->_cell_size = grid_size;
422+
417423
// save the settings file
418424
ye_json_write(ye_path("settings.yoyo"),SETTINGS);
419425

src/ui/editor_ui.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ void ye_editor_paint_options(struct nk_context *ctx){
291291
if(nk_checkbox_label(ctx, "Physics", (nk_bool*)&dummy_show_physics_overlay)){
292292
ye_set_overlay_state("ye_overlay_physics",dummy_show_physics_overlay);
293293
}
294+
// dumb hack: manual sync it in case scene reload messed with it
295+
dummy_show_physics_overlay = ye_get_overlay_state("ye_overlay_physics");
294296

295297
nk_layout_row_dynamic(ctx, 25, 1);
296298
nk_label(ctx, "Visual Debugging:", NK_TEXT_LEFT);
@@ -572,6 +574,9 @@ void ye_editor_paint_menu(struct nk_context *ctx){
572574
editor_write_scene_to_disk(ye_path_resources(YE_STATE.runtime.scene_file_path));
573575
}
574576
if (nk_menu_item_label(ctx, "Exit", NK_TEXT_LEFT)) {
577+
// OBLITERATE any overlays
578+
ye_set_all_overlays(false);
579+
575580
EDITOR_STATE.mode = ESTATE_WELCOME;
576581

577582
free(EDITOR_STATE.opened_project_path);

0 commit comments

Comments
 (0)