summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-12-14 07:08:13 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-12-14 07:08:13 +0000
commit7797fc8bf36c90d26d1cea093c69d89303bbbd0d (patch)
tree6fbea20760936b92d450aaa24562ff4f8d1b6711
parent8d1f285a5ad7243dfa6511c7b1796ad1c68e494b (diff)
etrophy: implement trophies points
SVN revision: 80917
-rw-r--r--src/lib/Etrophy.h57
-rw-r--r--src/lib/etrophy.c54
2 files changed, 105 insertions, 6 deletions
diff --git a/src/lib/Etrophy.h b/src/lib/Etrophy.h
index 1c0762a..da40902 100644
--- a/src/lib/Etrophy.h
+++ b/src/lib/Etrophy.h
@@ -287,6 +287,34 @@ EAPI Eet_Data_Descriptor *etrophy_gamescore_edd_get(void);
287EAPI void etrophy_gamescore_clear(Etrophy_Gamescore *gamescore); 287EAPI void etrophy_gamescore_clear(Etrophy_Gamescore *gamescore);
288 288
289/** 289/**
290 * @brief
291 * Get the sum of all the trophies points earned by the player.
292 *
293 * @param gamescore Gamescore handle.
294 * @return Sum of achieved trophies points.
295 *
296 * @see etrophy_gamescore_trophies_total_points_get().
297 *
298 * @ingroup Gamescore
299 */
300EAPI unsigned int etrophy_gamescore_trophies_points_get(const Etrophy_Gamescore *gamescore);
301
302/**
303 * @brief
304 * Get the sum of all the trophies points.
305 *
306 * It returns a sum of all the points a player could possibly achieves.
307 * For the sum of already earned trophies points, use
308 * @ref etrophy_gamescore_trophies_points_get().
309 *
310 * @param gamescore Gamescore handle.
311 * @return Sum of all possible trophies points.
312 *
313 * @ingroup Gamescore
314 */
315EAPI unsigned int etrophy_gamescore_trophies_total_points_get(const Etrophy_Gamescore *gamescore);
316
317/**
290 * @} 318 * @}
291 */ 319 */
292 320
@@ -412,6 +440,7 @@ EAPI int etrophy_gamescore_level_low_score_get(const Etrophy_Gamescore *gamescor
412 * @li @ref etrophy_trophy_name_get() 440 * @li @ref etrophy_trophy_name_get()
413 * @li @ref etrophy_trophy_description_get() 441 * @li @ref etrophy_trophy_description_get()
414 * @li @ref etrophy_trophy_visibility_get() 442 * @li @ref etrophy_trophy_visibility_get()
443 * @li @ref etrophy_trophy_points_get()
415 * @li @ref etrophy_trophy_date_get() 444 * @li @ref etrophy_trophy_date_get()
416 * 445 *
417 * The trophies list can be get with 446 * The trophies list can be get with
@@ -452,7 +481,32 @@ typedef enum _Etrophy_Trophy_Visibility
452 ETROPHY_TROPHY_STATE_LAST_VALUE /**< kept as sentinel */ 481 ETROPHY_TROPHY_STATE_LAST_VALUE /**< kept as sentinel */
453} Etrophy_Trophy_Visibility; 482} Etrophy_Trophy_Visibility;
454 483
455EAPI Etrophy_Trophy *etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal); 484/**
485 * @enum _Etrophy_Trophy_Points
486 * @typedef Etrophy_Trophy_Points
487 *
488 * Amount of trophies points earned by the player when the trophy is
489 * earned, when the counter is equal to the goal.
490 *
491 * It's suggested to be used as the @c points parameter of
492 * @ref etrophy_trophy_new() function, but any non negative integer value can
493 * be passed.
494 *
495 * @see etrophy_trophy_new()
496 * @see etrophy_trophy_points_get()
497 *
498 * @ingroup Trophy
499 */
500typedef enum _Etrophy_Trophy_Points
501{
502 ETROPHY_TROPHY_POINTS_VERY_FEW = 10, /**< Used for easy tasks */
503 ETROPHY_TROPHY_POINTS_FEW = 25, /**< Used for not so easy tasks */
504 ETROPHY_TROPHY_POINTS_MANY = 50, /**< Used for regular tasks */
505 ETROPHY_TROPHY_POINTS_LOTS = 100, /**< Used for hard tasks */
506 ETROPHY_TROPHY_POINTS_LAST_VALUE /**< kept as sentinel */
507} Etrophy_Trophy_Points;
508
509EAPI Etrophy_Trophy *etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal, unsigned int points);
456EAPI void etrophy_trophy_free(Etrophy_Trophy *trophy); 510EAPI void etrophy_trophy_free(Etrophy_Trophy *trophy);
457EAPI const char *etrophy_trophy_name_get(const Etrophy_Trophy *trophy); 511EAPI const char *etrophy_trophy_name_get(const Etrophy_Trophy *trophy);
458EAPI const char *etrophy_trophy_description_get(const Etrophy_Trophy *trophy); 512EAPI const char *etrophy_trophy_description_get(const Etrophy_Trophy *trophy);
@@ -461,6 +515,7 @@ EAPI void etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *go
461EAPI void etrophy_trophy_counter_set(Etrophy_Trophy *trophy, unsigned int value); 515EAPI void etrophy_trophy_counter_set(Etrophy_Trophy *trophy, unsigned int value);
462EAPI void etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value); 516EAPI void etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value);
463EAPI Eina_Bool etrophy_trophy_earned_get(const Etrophy_Trophy *trophy); 517EAPI Eina_Bool etrophy_trophy_earned_get(const Etrophy_Trophy *trophy);
518EAPI unsigned int etrophy_trophy_points_get(const Etrophy_Trophy *trophy);
464EAPI unsigned int etrophy_trophy_date_get(const Etrophy_Trophy *trophy); 519EAPI unsigned int etrophy_trophy_date_get(const Etrophy_Trophy *trophy);
465 520
466EAPI void etrophy_gamescore_trophy_add(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy); 521EAPI void etrophy_gamescore_trophy_add(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy);
diff --git a/src/lib/etrophy.c b/src/lib/etrophy.c
index 333a3df..9443a3c 100644
--- a/src/lib/etrophy.c
+++ b/src/lib/etrophy.c
@@ -54,6 +54,7 @@ struct _Etrophy_Trophy
54 Etrophy_Trophy_Visibility visibility; 54 Etrophy_Trophy_Visibility visibility;
55 unsigned int counter; 55 unsigned int counter;
56 unsigned int goal; 56 unsigned int goal;
57 unsigned int points;
57 unsigned int date; 58 unsigned int date;
58}; 59};
59 60
@@ -79,10 +80,10 @@ struct _Etrophy_Level
79 80
80struct _Etrophy_Gamescore 81struct _Etrophy_Gamescore
81{ 82{
82 Eina_List *levels; 83 Eina_List *levels;
83 Eina_List *trophies; 84 Eina_List *trophies;
84 Eina_List *locks; 85 Eina_List *locks;
85 const char *__eet_filename; 86 const char *__eet_filename;
86}; 87};
87 88
88static const char GAMESCORE_ENTRY[] = "gamescore"; 89static const char GAMESCORE_ENTRY[] = "gamescore";
@@ -114,6 +115,8 @@ _trophy_init(void)
114 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy, 115 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
115 "goal", goal, EET_T_UINT); 116 "goal", goal, EET_T_UINT);
116 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy, 117 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
118 "points", points, EET_T_UINT);
119 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
117 "date", date, EET_T_UINT); 120 "date", date, EET_T_UINT);
118} 121}
119 122
@@ -126,7 +129,7 @@ _trophy_shutdown(void)
126} 129}
127 130
128EAPI Etrophy_Trophy * 131EAPI Etrophy_Trophy *
129etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal) 132etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal, unsigned int points)
130{ 133{
131 Etrophy_Trophy *trophy; 134 Etrophy_Trophy *trophy;
132 135
@@ -144,6 +147,7 @@ etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Vis
144 trophy->visibility = visibility; 147 trophy->visibility = visibility;
145 trophy->date = (unsigned int)ecore_time_get(); 148 trophy->date = (unsigned int)ecore_time_get();
146 trophy->goal = goal; 149 trophy->goal = goal;
150 trophy->points = points;
147 151
148 return trophy; 152 return trophy;
149} 153}
@@ -187,6 +191,13 @@ etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *goal,
187 if (counter) *counter = trophy->counter; 191 if (counter) *counter = trophy->counter;
188} 192}
189 193
194EAPI inline unsigned int
195etrophy_trophy_points_get(const Etrophy_Trophy *trophy)
196{
197 EINA_SAFETY_ON_NULL_RETURN_VAL(trophy, 0);
198 return trophy->points;
199}
200
190EAPI inline void 201EAPI inline void
191etrophy_trophy_counter_set(Etrophy_Trophy *trophy, unsigned int value) 202etrophy_trophy_counter_set(Etrophy_Trophy *trophy, unsigned int value)
192{ 203{
@@ -824,6 +835,39 @@ etrophy_gamescore_level_score_add(Etrophy_Gamescore *gamescore, const char *leve
824 return escore; 835 return escore;
825} 836}
826 837
838EAPI inline unsigned int
839etrophy_gamescore_trophies_points_get(const Etrophy_Gamescore *gamescore)
840{
841 unsigned int points = 0;
842 Etrophy_Trophy *trophy;
843 Eina_List *l;
844
845 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, 0);
846
847 EINA_LIST_FOREACH(gamescore->trophies, l, trophy)
848 {
849 if (trophy->counter == trophy->goal)
850 points += trophy->points;
851 }
852
853 return points;
854}
855
856EAPI inline unsigned int
857etrophy_gamescore_trophies_total_points_get(const Etrophy_Gamescore *gamescore)
858{
859 unsigned int points = 0;
860 Etrophy_Trophy *trophy;
861 Eina_List *l;
862
863 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, 0);
864
865 EINA_LIST_FOREACH(gamescore->trophies, l, trophy)
866 points += trophy->points;
867
868 return points;
869}
870
827EAPI Eet_Data_Descriptor * 871EAPI Eet_Data_Descriptor *
828etrophy_gamescore_edd_get(void) 872etrophy_gamescore_edd_get(void)
829{ 873{