Adding an error message for callbacks that do not exists

This commit is contained in:
AnonymusRaccoon
2020-03-09 14:49:34 +01:00
parent da2f00aea4
commit 14f28e8339
2 changed files with 10 additions and 4 deletions
-2
View File
@@ -18,7 +18,6 @@ struct gc_scene
{
gc_list *data;
void *(*get_data)(gc_scene *scene, const char *type, const char *name);
void (*add_callback)(gc_scene *scene, const char *name, void *func);
void (*destroy)(gc_scene *scene);
@@ -37,6 +36,5 @@ callback_t scene_get_callback(gc_scene *scene, char *name);
gc_scene *scene_create(gc_engine *engine, const char *mappath);
void scene_load_data(gc_engine *engine, gc_scene *scene, node *n);
void *scene_get_data(gc_scene *scene, const char *type, const char *name);
void scene_add_callback(gc_scene *scene, const char *name, void *func);
void scene_destroy(gc_scene *scene);
void scene_load_entity(gc_scene *this, gc_engine *engine, node *n, int prefab);
+10 -2
View File
@@ -16,20 +16,28 @@ static void ctr(void *component, va_list args)
struct clickable_component *cmp = (struct clickable_component *)component;
gc_scene *scene = va_arg(args, gc_scene *);
char *onclick = va_arg(args, char *);
callback_t callback;
if (!scene)
return;
cmp->onclick = scene->get_callback(scene, onclick);
callback = scene->get_callback(scene, onclick);
if (!callback)
my_printf("No callback found with the name: %s\n", onclick);
cmp->onclick = callback;
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct clickable_component *cmp = (struct clickable_component *)component;
char *onclick = xml_gettempprop(n, "click");
callback_t callback;
if (!scene)
return;
cmp->onclick = scene->get_callback(scene, onclick);
callback = scene->get_callback(scene, onclick);
if (!callback)
my_printf("No callback found with the name: %s\n", onclick);
cmp->onclick = callback;
}
static void dtr(void *component)