Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Trophies for swadge modes.
Welcome to the swadge's trophy system! This fun addition to your game gives players an extrinsic reason to keep playing your game again and again.
The trophies work similarly to a mix of the big three: Valve's Achievements, Xbox's Gamer Score, and Playstation's Trophies. There are several different unlock conditions that can be specifed, there's minimal overhead on the swadge (when set up properly) and trophies give the player points that they can use as bragging rights.
All the dev has to do is make a few data structures and load them into the swadgeMode_t struct. This will automatically initialize the system.
Trophies are drawn from either the top or the bottom of the screen, and the duration they're on screen can be adjusted. All NVS activity is handled for the Dev.
Like Cthulu creeping into your mind, the trophy system sits on top of the swadge mode. It's always there, but sits disabled unless explicitly set active by a developer. To activate it, create the following structs in the .c file for the mode:
This will allow the trophy system to access your trophies and make sure the right text and images are displayed when a trophy is triggered.
There are four settings that can be set for the mode overall:
These can be loaded into the settings struct as shown above.
The largest portion of the work required to set up the trophies it to create all the trophies from scratch. Here's the types of data available to set for each individual trophy:
intptr_t
and used by the Swadge Mode to find a specific trophy in a list of trophyData_t[].Types of trophies:
A special "All trophies gotten" trophy is automatically generated when the first standard trophy is generated.
Use either trophyUpdate()
or trophyUpdateMilestone()
to update the status of the trophy. If the trophy is a 'Trigger' type, it will automatically set the trophy to having been won regardless of the value entered. If the trophy is either 'Additive' or 'Progress' modes, it will either add or replace the previous value if appropriate. Lastly, if it's a checklist, you can use either the standard update command or trophySetChecklistTask()
to shortcut needing to set bit flags yourself.
If the developer wants to update quietly, there is a argument to disable drawing. This allows for times when the banner would cause issues (the middle of a boss fight, for example) to have the drawing disabled without stopping the whole trophy system.
Using the milestone system, the program will automatically display trophy progress at the set percentage thresholds. This is great for trophies that have frequent updates and wish to display only sometimes. An example would be if counting eggs found up to 100, you may only want to update every 10 eggs rather than each egg to avoid spamming banners at the player.
Here's some important notes on sending updates:
trophyUpdate()
call has the potential to save to NVS. NVS has a limited amount of writes over it's lifetime which we're not likely to hit, but maybe don't hammer the NVS by incrementing by one every frame. Only update when reasonable. The code will cut out a lot of frivolous requests such as:Once set, the value can be pulled back out by running trophyGetSavedValue()
.
The last won trophy is saved to the NVS for later use.
Several helper functions exist for the developer to get critical information
checkBitFlag()
& setBitFlag()
: Two complimentary functions to handle that pesky bit shiftingtrophyGetPoints()
: Get either the total number of points for this mode of for the entire swadgetrophyGetLatest()
: Returns the last saved trophytrophySetSystemData()
: Sets the trophy System to the same as provided mode. Used primarily by Trophy Case mode.The Swadge will automatically display trophies as they're unlocked. You do not need to provide draw calls, it is handled automatically.
The banner notifications look like this:
The banner will scroll in from the top by default, but can be set to the bottom in the settings. See system initialization. The banner will be fully visible for the set duration, not including scroll in and scroll out duration.
Banners will automatically queue up. A significant number of calls may slow down the swadge as it has to allocate data for each update.
A trophy 'gallery' type function has been provided. Initialize with trophyDrawListInit()
, set the colors with trophyDrawListColors()
, and display with trophyDrawList()
. It displays a long list that can be scrolled by providing new y values. Remember to deinit the list with trophyDrawListDeinit()
to cover any memory leaks.
In addition, there is an auto-populating Trophy Case mode where this is already done for you, so you can go to see the trophy data. Anything marked hidden will not be shown in there. Trophies can be sorted by unlocked, locked, or all.
Reset a trophy to 0 (but don't remove it from the list of trophies) with trophyClear()
.
Trophies should only be cleared under abnormal circumstances, such as the player having been caught cheating. Consider that the Steamworks API (Valve) has a "Remove trophy" function, yet most people have never lost an trophy.
Clearing a trophy will delete the points acquired if it was previously won.
Go to the source code of this file.
Data Structures | |
struct | trophyData_t |
Individual Trophy data objects. More... | |
struct | trophySettings_t |
Settings for the trophy system. More... | |
struct | trophyDataList_t |
The data object dev hands to the trophy showcase that contains all the const data. More... | |
Macros | |
#define | TROPHY_MAX_TITLE_LEN 48 |
The longest possible name for a trophy. | |
#define | TROPHY_MAX_DESC_LEN 128 |
The longest possible description for a trophy. | |
#define | DRAW_SLIDE_US 262144 |
Recommended slide time, a power of 2 about a quarter second. | |
#define | DRAW_STATIC_US 524288 |
Recommended static time, a power of 2 about a half second. | |
#define | NO_IMAGE_SET CNFS_NUM_FILES |
Special value for trophyData_t.image to indicate no image. | |
Enumerations | |
enum | trophyType_t { TROPHY_TYPE_TRIGGER , TROPHY_TYPE_ADDITIVE , TROPHY_TYPE_PROGRESS , TROPHY_TYPE_CHECKLIST } |
Types of trophies the devs can instantiate. More... | |
enum | trophyDifficulty_t { TROPHY_DIFF_FINAL , TROPHY_DIFF_EASY , TROPHY_DIFF_MEDIUM , TROPHY_DIFF_HARD , TROPHY_DIFF_EXTREME } |
Dev inferred difficulty of achieving, used to distribute points. More... | |
enum | trophyListDisplayMode_t { TROPHY_DISPLAY_ALL , TROPHY_DISPLAY_UNLOCKED , TROPHY_DISPLAY_LOCKED , TROPHY_DISPLAY_INCL_HIDDEN } |
What display mode to use to draw trophies. More... | |
Functions | |
void | trophySystemInit (trophyDataList_t *settings, const char *modeName) |
Initializes the Trophy system settings. The system is a global setting and every mode needs to set this when entered to avoid copying from other modes. | |
bool | trophyUpdate (trophyData_t t, int newVal, bool drawUpdate) |
Updates specifed trophy if required. | |
bool | trophyUpdateMilestone (trophyData_t t, int newVal, int threshold) |
Updates just like trophyUpdate() , but only draws when crossing percentage boundary. | |
int32_t | trophyGetSavedValue (trophyData_t t) |
Returns the value saved to the NVS or 0 if the key isn't found. | |
bool | trophySetChecklistTask (trophyData_t t, int32_t flag, bool unset, bool drawUpdate) |
Sets or unsets a checklist item. | |
void | trophyClear (trophyData_t t) |
Erases completion data from swadge. Only use in extreme circumstances. | |
bool | checkBitFlag (int32_t flags, int8_t idx) |
Checks an individual bit flag out of a int32. | |
void | setBitFlag (int32_t *flags, int8_t idx, bool setTrue) |
Set a bit flag. | |
int | trophyGetPoints (bool total, const char *modeName) |
Get the point totals for the gamer score. | |
trophyData_t | trophyGetLatest (void) |
Get the Latest Trophy Idx object. | |
void | trophySetSystemData (trophyDataList_t *dl, const char *modeName) |
Set the Trophy System to a specific mode's values. | |
void | trophyDraw (font_t *fnt, int64_t elapsedUs) |
Draws the banner if one is queued. | |
void | trophyDrawListInit (trophyListDisplayMode_t mode) |
Initialize the trophy Draw list. | |
void | trophyDrawListColors (paletteColor_t background, paletteColor_t panel, paletteColor_t shadowBoxes, paletteColor_t dimText, paletteColor_t titleText, paletteColor_t checkmark) |
Set the colors of the panel to custom. Call after initialization of the list, or it'll be overwritten. | |
void | trophyDrawListDeinit (void) |
Tears down the WSGs and height list. | |
void | trophyDrawList (font_t *fnt, int yOffset) |
Draws the list. | |
bool | isTrophyDrawing (void) |
Check if a trophy is currently being drawn. | |
struct trophyData_t |
Data Fields | ||
---|---|---|
char | title[TROPHY_MAX_TITLE_LEN] | Name of the Trophy, used as ID. |
char | description[TROPHY_MAX_DESC_LEN] | Short description of task required. |
cnfsFileIdx_t | image | Index of the image. |
trophyType_t | type | Type of trophy. See "trophy.h" for descriptions. |
trophyDifficulty_t | difficulty | How many points the trophy is worth. |
int32_t | maxVal | The value that. |
bool | hidden | If trophy is hidden by default. |
bool | noImage | If trophy will use an image. |
const void * | identifier |
An optional identifier to find trophy data. May be set to a pointer or an integer cast to |
struct trophySettings_t |
Data Fields | ||
---|---|---|
bool | drawFromBottom | If banner should be drawn from the bottom of the screen. |
int32_t | staticDurationUs | How long the banner will be drawn fully extended. |
int32_t | slideDurationUs | How long the banner will take to slide in and out. |
char | namespaceKey[NVS_KEY_NAME_MAX_SIZE] | key used for trophy namespace |
struct trophyDataList_t |
Data Fields | ||
---|---|---|
int32_t | length | Length of the trophy arrays. |
const trophyData_t *const | list | Array of trophies. |
trophySettings_t * | settings | Setting data. |
#define TROPHY_MAX_TITLE_LEN 48 |
The longest possible name for a trophy.
#define TROPHY_MAX_DESC_LEN 128 |
The longest possible description for a trophy.
#define DRAW_SLIDE_US 262144 |
Recommended slide time, a power of 2 about a quarter second.
#define DRAW_STATIC_US 524288 |
Recommended static time, a power of 2 about a half second.
#define NO_IMAGE_SET CNFS_NUM_FILES |
Special value for trophyData_t.image to indicate no image.
enum trophyType_t |
Types of trophies the devs can instantiate.
enum trophyDifficulty_t |
Dev inferred difficulty of achieving, used to distribute points.
Enumerator | |
---|---|
TROPHY_DIFF_FINAL | Only used by the trophy System. Will break normal trophies. |
TROPHY_DIFF_EASY | The easiest trophies to unlock. |
TROPHY_DIFF_MEDIUM | A bit more difficult to unlock than TROPHY_DIFF_EASY. |
TROPHY_DIFF_HARD | A trophy that takes serious skill to unlock. |
TROPHY_DIFF_EXTREME | A trophy that takes skill, dedication, and insanity to unlock. |
What display mode to use to draw trophies.
void trophySystemInit | ( | trophyDataList_t * | settings, |
const char * | modeName ) |
Initializes the Trophy system settings. The system is a global setting and every mode needs to set this when entered to avoid copying from other modes.
settings | The settings data |
modeName | Name of the mode |
bool trophyUpdate | ( | trophyData_t | t, |
int | newVal, | ||
bool | drawUpdate ) |
Updates specifed trophy if required.
t | Trophy to update |
newVal | New value to try to set. Behavior is set by trophy type |
drawUpdate | If this update should be drawn to the screen |
bool trophyUpdateMilestone | ( | trophyData_t | t, |
int | newVal, | ||
int | threshold ) |
Updates just like trophyUpdate()
, but only draws when crossing percentage boundary.
t | Trophy to update |
newVal | Value to attempt to set |
threshold | Value (0-100, representing a percent) to draw at |
int32_t trophyGetSavedValue | ( | trophyData_t | t | ) |
Returns the value saved to the NVS or 0 if the key isn't found.
t | Trophy to grab value for |
bool trophySetChecklistTask | ( | trophyData_t | t, |
int32_t | flag, | ||
bool | unset, | ||
bool | drawUpdate ) |
Sets or unsets a checklist item.
t | Trophy to set |
flag | Task that was just completed |
unset | If we're unsetting the bit |
drawUpdate | If this update should be drawn |
void trophyClear | ( | trophyData_t | t | ) |
Erases completion data from swadge. Only use in extreme circumstances.
t | Trophy to set to 0 |
bool checkBitFlag | ( | int32_t | flags, |
int8_t | idx ) |
Checks an individual bit flag out of a int32.
flags | int32 containing the flag to check |
idx | Index of the bit |
void setBitFlag | ( | int32_t * | flags, |
int8_t | idx, | ||
bool | setTrue ) |
Set a bit flag.
flags | pointer to variable to store flags |
idx | Index of the bit to set |
setTrue | Set to false to unset the |
int trophyGetPoints | ( | bool | total, |
const char * | modeName ) |
Get the point totals for the gamer score.
total | If loading the full score or for the current mode |
modeName | Mode name to load. Set to NULL to get currently loaded mode |
trophyData_t trophyGetLatest | ( | void | ) |
Get the Latest Trophy Idx object.
void trophySetSystemData | ( | trophyDataList_t * | dl, |
const char * | modeName ) |
Set the Trophy System to a specific mode's values.
dl | Data object from the mode |
modeName | Name of the mode |
void trophyDraw | ( | font_t * | fnt, |
int64_t | elapsedUs ) |
Draws the banner if one is queued.
fnt | Font to be used |
elapsedUs | Time since last frame |
void trophyDrawListInit | ( | trophyListDisplayMode_t | mode | ) |
Initialize the trophy Draw list.
mode | What display mode to draw |
void trophyDrawListColors | ( | paletteColor_t | background, |
paletteColor_t | panel, | ||
paletteColor_t | shadowBoxes, | ||
paletteColor_t | dimText, | ||
paletteColor_t | titleText, | ||
paletteColor_t | checkmark ) |
Set the colors of the panel to custom. Call after initialization of the list, or it'll be overwritten.
background | Color of the background behind the panels |
panel | The main panel color |
shadowBoxes | The check box and image shadowbox colors |
dimText | Description text and numbers |
titleText | Title of the trophy |
checkmark | Color of the checkmark |
void trophyDrawListDeinit | ( | void | ) |
Tears down the WSGs and height list.
void trophyDrawList | ( | font_t * | fnt, |
int | yOffset ) |
Draws the list.
fnt | Font to use |
yOffset | Current Y offset. Higher numbers effectively scroll down |
bool isTrophyDrawing | ( | void | ) |
Check if a trophy is currently being drawn.