1818#include <ui/world_inspector.h>
1919
2020struct te_editor {
21+ // NULL if the game is not started yet.
22+ te_game_manager * game_manager ;
23+
2124 // Always valid pointer. Must be destroyed during the editor's destruction.
2225 te_editor_camera * editor_camera ;
2326
@@ -41,7 +44,8 @@ te_editor*
4144editor_create () {
4245 te_editor * editor = malloc (sizeof (te_editor ));
4346 editor -> editor_camera = editor_camera_create ();
44- editor -> ui = editor_ui_create ();
47+ editor -> game_manager = NULL ;
48+ editor -> ui = editor_ui_create (editor );
4549 editor -> game_world_stats_widget = NULL ;
4650 editor -> game_world = NULL ;
4751 editor -> editor_world = NULL ;
@@ -77,10 +81,12 @@ editor_on_game_started(void* game_instance, te_game_manager* game_manager) {
7781 te_font_manager * font_manager = renderer_get_font_manager (renderer );
7882 font_manager_load_font (font_manager , "engine/font/font.ttf" );
7983
80- // Create worlds.
8184 te_editor * editor = game_instance ;
85+ editor -> game_manager = game_manager ;
86+
87+ // Create worlds.
8288 editor_create_editor_world (editor , game_manager );
83- editor_create_game_world (editor , game_manager );
89+ editor_create_game_world (editor , NULL );
8490}
8591
8692static void
@@ -95,16 +101,18 @@ prv_editor_destroy_game_world(te_editor* editor, te_game_manager* game_manager)
95101}
96102
97103void
98- editor_create_game_world (te_editor * editor , te_game_manager * game_manager ) {
104+ editor_create_game_world (te_editor * editor , const char * relative_path_to_world ) {
105+ // Cleanup.
106+ editor_ui_reset (editor -> ui );
99107 if (editor -> game_world != NULL ) {
100- prv_editor_destroy_game_world (editor , game_manager );
108+ prv_editor_destroy_game_world (editor , editor -> game_manager );
101109 }
102110
103- editor -> game_world = game_manager_create_world (game_manager , "game" );
111+ editor -> game_world = game_manager_create_world (editor -> game_manager , "game" );
104112 editor_camera_spawn (editor -> editor_camera , editor -> game_world );
105113
106- // Prepare a sample scene.
107- {
114+ if ( relative_path_to_world == NULL ) {
115+ // Prepare a sample scene.
108116 te_model * floor = model_create ();
109117 model_set_name (floor , "floor" );
110118 model_set_scale (floor , (vec3 ){5.0f , 1.0f , 5.0f });
@@ -115,6 +123,8 @@ editor_create_game_world(te_editor* editor, te_game_manager* game_manager) {
115123 model_set_name (box , "box" );
116124 model_set_position (box , (vec3 ){0.0f , 1.0f , -1.0f });
117125 world_spawn_model (editor -> game_world , box );
126+ } else {
127+ world_add_from_file (editor -> game_world , relative_path_to_world );
118128 }
119129
120130 // Prepare stats widget.
@@ -358,8 +368,10 @@ editor_on_input_source_changed(
358368
359369void
360370editor_on_window_received_focus (void * game_instance , struct te_game_manager * game_manager ) {
361- (void )game_instance ;
362371 (void )game_manager ;
372+
373+ te_editor * editor = game_instance ;
374+ editor_ui_refresh_filesystem_view (editor -> ui );
363375}
364376
365377void
0 commit comments