<commit_before>#include "e_mod_main.h"
#include "echievements.x"

#define ECH_INIT(NAME)     EINTERN void echievement_init_cb_##NAME(Echievement *ec)
#define ECH_EH_NAME(NAME, TYPE)  echievement_##NAME##_##TYPE##_handler_cb
#define ECH_EH(NAME, TYPE) static Eina_Bool ECH_EH_NAME(NAME, TYPE)(Echievement *ec, int type EINA_UNUSED, void *event)
#define ECH_EH_UNUSED(NAME, TYPE) static Eina_Bool ECH_EH_NAME(NAME, TYPE)(Echievement *ec, int type EINA_UNUSED, void *event EINA_UNUSED)
#define ECH_EH_ADD(NAME, TYPE) \
   do { \
      if (etrophy_trophy_earned_get(ec->trophy)) break; \
      E_LIST_HANDLER_APPEND(ec->handlers, TYPE, ECH_EH_NAME(NAME, TYPE), ec); \
   } while (0)

#define ECH_BH_NAME(NAME, TYPE)  echievement_##NAME##_border_hook_##TYPE
#define ECH_BH(NAME, TYPE) static void ECH_BH_NAME(NAME, TYPE)(Echievement *ec, E_Border *bd)
#define ECH_BH_ADD(NAME, TYPE) \
   do { \
      if (etrophy_trophy_earned_get(ec->trophy)) break; \
      ec->bh_handlers = 1; \
      ec->handlers = eina_list_append(ec->handlers, \
        e_border_hook_add(E_BORDER_HOOK_##TYPE, (Ecore_End_Cb)ECH_BH_NAME(NAME, TYPE), ec)); \
   } while (0)

#define ECH_MH_NAME(NAME) _ech_##NAME##_mouse_hook
#define ECH_MH(NAME) static void ECH_MH_NAME(NAME)(Echievement *ec)
#define ECH_MH_ADD(NAME) \
   do { \
      ec->mouse_hook = (Ecore_Cb)ECH_MH_NAME(NAME); \
      if (!etrophy_trophy_earned_get(ec->trophy)) \
        mod->mouse.hooks = eina_list_append(mod->mouse.hooks, ec); \
   } while (0)
#define ECH_MH_DEL \
   do { \
     ec->mouse_hook = NULL; \
     mod->mouse.hooks = eina_list_remove(mod->mouse.hooks, ec); \
   } while (0)

static Ecore_Idler *_ech_idler = NULL;

/* helper for init */
static void
_ech_list_add(Etrophy_Trophy *et)
{
   Echievement *ec;

   ec = E_NEW(Echievement, 1);
   ec->trophy = et;
   ec->id = eina_hash_population(mod->trophies);
   eina_hash_add(mod->trophies, &ec->id, ec);
   mod->trophies_list = (Echievement *)eina_inlist_append(EINA_INLIST_GET(mod->trophies_list), EINA_INLIST_GET(ec));
}

static void
_ech_add(Echievement_Id id)
{
   Etrophy_Trophy *et;

   et = etrophy_trophy_new(Echievement_Strings[id], Echievement_Descs[id],
                           Echievement_Hide_States[id], Echievement_Goals[id], Echievement_Points[id]);
   etrophy_gamescore_trophy_add(ech_config->gs, et);
   _ech_list_add(et);
}

static void
_ech_free(Echievement *ec)
{
   /* trophy does NOT get freed here!!! */
   if (ec->bh_handlers)
     E_FREE_LIST(ec->handlers, e_border_hook_del);
   else
     E_FREE_LIST(ec->handlers, ecore_event_handler_del);
   if (ec->mouse_hook) mod->mouse.hooks = eina_list_remove(mod->mouse.hooks, ec);
   if (ec->dialog.icon)
     evas_object_event_callback_del_full(ec->dialog.icon, EVAS_CALLBACK_DEL, mod->obj_del_cb, ec);
   if (ec->dialog.label)
     evas_object_event_callback_del_full(ec->dialog.label, EVAS_CALLBACK_DEL, mod->obj_del_cb, ec);
   free(ec);
}

/* returns trophy only if it has not yet been earned */
static Etrophy_Trophy *
_ech_lookup(Echievement_Id id)
{
   Echievement *ec;

   ec = eina_hash_find(mod->trophies, &id);
   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
   if (!etrophy_trophy_earned_get(ec->trophy)) return ec->trophy;
   INF("TROPHY PREVIOUSLY EARNED: %s - %s",
       etrophy_trophy_name_get(ec->trophy),
       etrophy_trophy_description_get(ec->trophy));
   return NULL;
}

static void
_ech_notify(const char *name, const char *description)
{
   E_Notification *n;
   char summary[128];

   snprintf(summary, sizeof(summary), "Echievement: %s", name);
   n = e_notification_full_new("echievements", 0, PACKAGE_DATA_DIR "/trophy.png",
                               summary, description, -1);
   e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_NORMAL);
   e_notification_send(n, NULL, NULL);
   e_notification_unref(n);
}

static void
_ech_trophy_counter_increment(Echievement *ec, unsigned int value)
{
   if (etrophy_trophy_earned_get(ec->trophy)) return;
   etrophy_trophy_counter_increment(ec->trophy, value);
   ech_cfg_ech_update(ec);
}

static void
_ech_trophy_counter_set(Echievement *ec, unsigned int value)
{
   unsigned int count;

   if (etrophy_trophy_earned_get(ec->trophy)) return;
   etrophy_trophy_goal_get(ec->trophy, NULL, &count);<commit_msg>not sure why I had this only returning unearned trophies...must have been high?<commit_after>#include "e_mod_main.h"
#include "echievements.x"

#define ECH_INIT(NAME)     EINTERN void echievement_init_cb_##NAME(Echievement *ec)
#define ECH_EH_NAME(NAME, TYPE)  echievement_##NAME##_##TYPE##_handler_cb
#define ECH_EH(NAME, TYPE) static Eina_Bool ECH_EH_NAME(NAME, TYPE)(Echievement *ec, int type EINA_UNUSED, void *event)
#define ECH_EH_UNUSED(NAME, TYPE) static Eina_Bool ECH_EH_NAME(NAME, TYPE)(Echievement *ec, int type EINA_UNUSED, void *event EINA_UNUSED)
#define ECH_EH_ADD(NAME, TYPE) \
   do { \
      if (etrophy_trophy_earned_get(ec->trophy)) break; \
      E_LIST_HANDLER_APPEND(ec->handlers, TYPE, ECH_EH_NAME(NAME, TYPE), ec); \
   } while (0)

#define ECH_BH_NAME(NAME, TYPE)  echievement_##NAME##_border_hook_##TYPE
#define ECH_BH(NAME, TYPE) static void ECH_BH_NAME(NAME, TYPE)(Echievement *ec, E_Border *bd)
#define ECH_BH_ADD(NAME, TYPE) \
   do { \
      if (etrophy_trophy_earned_get(ec->trophy)) break; \
      ec->bh_handlers = 1; \
      ec->handlers = eina_list_append(ec->handlers, \
        e_border_hook_add(E_BORDER_HOOK_##TYPE, (Ecore_End_Cb)ECH_BH_NAME(NAME, TYPE), ec)); \
   } while (0)

#define ECH_MH_NAME(NAME) _ech_##NAME##_mouse_hook
#define ECH_MH(NAME) static void ECH_MH_NAME(NAME)(Echievement *ec)
#define ECH_MH_ADD(NAME) \
   do { \
      ec->mouse_hook = (Ecore_Cb)ECH_MH_NAME(NAME); \
      if (!etrophy_trophy_earned_get(ec->trophy)) \
        mod->mouse.hooks = eina_list_append(mod->mouse.hooks, ec); \
   } while (0)
#define ECH_MH_DEL \
   do { \
     ec->mouse_hook = NULL; \
     mod->mouse.hooks = eina_list_remove(mod->mouse.hooks, ec); \
   } while (0)

static Ecore_Idler *_ech_idler = NULL;

/* helper for init */
static void
_ech_list_add(Etrophy_Trophy *et)
{
   Echievement *ec;

   ec = E_NEW(Echievement, 1);
   ec->trophy = et;
   ec->id = eina_hash_population(mod->trophies);
   eina_hash_add(mod->trophies, &ec->id, ec);
   mod->trophies_list = (Echievement *)eina_inlist_append(EINA_INLIST_GET(mod->trophies_list), EINA_INLIST_GET(ec));
}

static void
_ech_add(Echievement_Id id)
{
   Etrophy_Trophy *et;

   et = etrophy_trophy_new(Echievement_Strings[id], Echievement_Descs[id],
                           Echievement_Hide_States[id], Echievement_Goals[id], Echievement_Points[id]);
   etrophy_gamescore_trophy_add(ech_config->gs, et);
   _ech_list_add(et);
}

static void
_ech_free(Echievement *ec)
{
   /* trophy does NOT get freed here!!! */
   if (ec->bh_handlers)
     E_FREE_LIST(ec->handlers, e_border_hook_del);
   else
     E_FREE_LIST(ec->handlers, ecore_event_handler_del);
   if (ec->mouse_hook) mod->mouse.hooks = eina_list_remove(mod->mouse.hooks, ec);
   if (ec->dialog.icon)
     evas_object_event_callback_del_full(ec->dialog.icon, EVAS_CALLBACK_DEL, mod->obj_del_cb, ec);
   if (ec->dialog.label)
     evas_object_event_callback_del_full(ec->dialog.label, EVAS_CALLBACK_DEL, mod->obj_del_cb, ec);
   free(ec);
}

static Etrophy_Trophy *
_ech_lookup(Echievement_Id id)
{
   Echievement *ec;

   ec = eina_hash_find(mod->trophies, &id);
   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
   return ec->trophy;
}

static void
_ech_notify(const char *name, const char *description)
{
   E_Notification *n;
   char summary[128];

   snprintf(summary, sizeof(summary), "Echievement: %s", name);
   n = e_notification_full_new("echievements", 0, PACKAGE_DATA_DIR "/trophy.png",
                               summary, description, -1);
   e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_NORMAL);
   e_notification_send(n, NULL, NULL);
   e_notification_unref(n);
}

static void
_ech_trophy_counter_increment(Echievement *ec, unsigned int value)
{
   if (etrophy_trophy_earned_get(ec->trophy)) return;
   etrophy_trophy_counter_increment(ec->trophy, value);
   ech_cfg_ech_update(ec);
}

static void
_ech_trophy_counter_set(Echievement *ec, unsigned int value)
{
   unsigned int count;

   if (etrophy_trophy_earned_get(ec->trophy)) return;
   etrophy_trophy_goal_get(ec->trophy, NULL, &count);
{'fraction_non_alphanumeric': 0.12790697674418605, 'fraction_numerical': 0.0026372572524574443, 'mean_word_length': 4.714383561643835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '873582', 'n_tokens_mistral': 3453, 'n_tokens_neox': 3290, 'n_words': 566}