summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-10 21:50:28 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-10 21:50:28 +0000
commit82c3e5f920f132ff266fa09f4b22d72c595eba3c (patch)
tree053a76a6079559d29afe2dfe0a8caafefa257bc7
parentf0aa0f725c1345cf9e109d5103befe997dad75b3 (diff)
etrophy: add goal / counter for trophy
This way is possible to set goals like: "killing 1500 zombies" and it will be incrementing it until it reaches the goal. In this case, the trophy will be earned. For binary trophies is enought to set the goal as 1. SVN revision: 77827
-rw-r--r--src/lib/Etrophy.h5
-rw-r--r--src/lib/etrophy.c35
2 files changed, 38 insertions, 2 deletions
diff --git a/src/lib/Etrophy.h b/src/lib/Etrophy.h
index 2b689ba..31b3d07 100644
--- a/src/lib/Etrophy.h
+++ b/src/lib/Etrophy.h
@@ -54,12 +54,15 @@ typedef struct _Etrophy_Level Etrophy_Level;
54typedef struct _Etrophy_Gamescore Etrophy_Gamescore; 54typedef struct _Etrophy_Gamescore Etrophy_Gamescore;
55 55
56/* Etrophy_Trophy */ 56/* Etrophy_Trophy */
57EAPI Etrophy_Trophy *etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility); 57EAPI Etrophy_Trophy *etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal);
58EAPI void etrophy_trophy_free(Etrophy_Trophy *trophy); 58EAPI void etrophy_trophy_free(Etrophy_Trophy *trophy);
59 59
60EAPI const char *etrophy_trophy_name_get(const Etrophy_Trophy *trophy); 60EAPI const char *etrophy_trophy_name_get(const Etrophy_Trophy *trophy);
61EAPI const char *etrophy_trophy_description_get(const Etrophy_Trophy *trophy); 61EAPI const char *etrophy_trophy_description_get(const Etrophy_Trophy *trophy);
62EAPI Etrophy_Trophy_Visibility etrophy_trophy_visibility_get(const Etrophy_Trophy *trophy); 62EAPI Etrophy_Trophy_Visibility etrophy_trophy_visibility_get(const Etrophy_Trophy *trophy);
63EAPI void etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *goal, unsigned int *counter);
64EAPI void etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value);
65EAPI Eina_Bool etrophy_trophy_earned_get(const Etrophy_Trophy *trophy);
63EAPI unsigned int etrophy_trophy_date_get(const Etrophy_Trophy *trophy); 66EAPI unsigned int etrophy_trophy_date_get(const Etrophy_Trophy *trophy);
64 67
65/* Etrophy_Lock */ 68/* Etrophy_Lock */
diff --git a/src/lib/etrophy.c b/src/lib/etrophy.c
index eda69fb..c6b729e 100644
--- a/src/lib/etrophy.c
+++ b/src/lib/etrophy.c
@@ -52,6 +52,8 @@ struct _Etrophy_Trophy
52 const char *name; 52 const char *name;
53 const char *description; 53 const char *description;
54 Etrophy_Trophy_Visibility visibility; 54 Etrophy_Trophy_Visibility visibility;
55 unsigned int counter;
56 unsigned int goal;
55 unsigned int date; 57 unsigned int date;
56}; 58};
57 59
@@ -108,6 +110,10 @@ _trophy_init(void)
108 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy, 110 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
109 "visibility", visibility, EET_T_UINT); 111 "visibility", visibility, EET_T_UINT);
110 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy, 112 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
113 "counter", counter, EET_T_UINT);
114 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
115 "goal", goal, EET_T_UINT);
116 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
111 "date", date, EET_T_UINT); 117 "date", date, EET_T_UINT);
112} 118}
113 119
@@ -120,7 +126,7 @@ _trophy_shutdown(void)
120} 126}
121 127
122EAPI Etrophy_Trophy * 128EAPI Etrophy_Trophy *
123etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility) 129etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal)
124{ 130{
125 Etrophy_Trophy *trophy = calloc(1, sizeof(Etrophy_Trophy)); 131 Etrophy_Trophy *trophy = calloc(1, sizeof(Etrophy_Trophy));
126 132
@@ -134,6 +140,7 @@ etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Vis
134 trophy->description = eina_stringshare_add(description); 140 trophy->description = eina_stringshare_add(description);
135 trophy->visibility = visibility; 141 trophy->visibility = visibility;
136 trophy->date = (unsigned int) ecore_time_get(); 142 trophy->date = (unsigned int) ecore_time_get();
143 trophy->goal = goal;
137 144
138 return trophy; 145 return trophy;
139} 146}
@@ -164,6 +171,32 @@ etrophy_trophy_visibility_get(const Etrophy_Trophy *trophy)
164 return trophy->visibility; 171 return trophy->visibility;
165} 172}
166 173
174EAPI inline void
175etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *goal,
176 unsigned int *counter)
177{
178 if (goal) *goal = trophy->goal;
179 if (counter) *counter = trophy->counter;
180}
181
182EAPI inline void
183etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value)
184{
185 if (trophy->counter == trophy->goal) return;
186
187 trophy->counter += value;
188 if (trophy->counter > trophy->goal)
189 trophy->counter = trophy->goal;
190
191 trophy->date = (unsigned int) ecore_time_get();
192}
193
194EAPI inline Eina_Bool
195etrophy_trophy_earned_get(const Etrophy_Trophy *trophy)
196{
197 return (trophy->goal == trophy->counter);
198}
199
167EAPI inline unsigned int 200EAPI inline unsigned int
168etrophy_trophy_date_get(const Etrophy_Trophy *trophy) 201etrophy_trophy_date_get(const Etrophy_Trophy *trophy)
169{ 202{