From a3ece7df1445d96e26b0a071b17dff90339ef8d1 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Thu, 12 Dec 2019 18:26:40 +1100 Subject: [PATCH] Entities loaded with entity_load command can now be optionally renamed --- src/game/console.c | 13 +++++++++---- todo.txt | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/game/console.c b/src/game/console.c index aea88f4..0660b9a 100755 --- a/src/game/console.c +++ b/src/game/console.c @@ -198,23 +198,28 @@ void console_command_entity_save(struct Console* console, const char* command) void console_command_entity_load(struct Console* console, const char* command) { char filename[MAX_FILENAME_LEN]; + char new_entity_name[MAX_ENTITY_NAME_LEN]; memset(filename, '\0', MAX_FILENAME_LEN); + memset(new_entity_name, '\0', MAX_ENTITY_NAME_LEN); - int params_read = sscanf(command, "%s", filename); - if(params_read != 1) + int params_read = sscanf(command, "%s %s", filename, new_entity_name); + if(params_read < 1 && params_read > 2) { log_warning("Invalid parameters for command"); - log_warning("Usage: entity_load [file name]"); + log_warning("Usage: entity_load [file name] [optional: new entity name]"); return; } char full_filename[MAX_FILENAME_LEN]; snprintf(full_filename, MAX_FILENAME_LEN, "entities/%s.symtres", filename); - if(!entity_load(full_filename, DIRT_INSTALL)) + struct Entity* new_entity = entity_load(full_filename, DIRT_INSTALL); + if(!new_entity) { log_error("entity_load", "Could not create entity from '%s'", full_filename); return; } + + if(params_read == 2) entity_rename(new_entity, new_entity_name); } void console_command_help(struct Console* console, const char* command) diff --git a/todo.txt b/todo.txt index eea5c5a..34d4c73 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,5 @@ Todo: - Allow renaming scene objects in editor - - Add parameter to entity_load command that renames the newly loaded object to whatever the second specified parameter is - Bring back debug variable display in editor and allow showing colours, textures etc - Implment/Test reading/writing scene that has a mixture of default entites and entity archetypes - Serialize player, camera properties to file @@ -343,4 +342,5 @@ Done: * Added EF_SKIP_RENDER flag to allow entites to skip rendering * Save default entity archetype to be loaded when there is not other archetype or in case of an error as fallback * Ensure cameras are not initialized multiple times - * Fixed cameras not resizing to current resolution when scene is loaded/reloaded \ No newline at end of file + * Fixed cameras not resizing to current resolution when scene is loaded/reloaded + * Added parameter to entity_load command that renames the newly loaded object to whatever the second specified parameter is \ No newline at end of file