Refactor shop code to use generic Item (#536)

* Turned SpriteObject into a member of JokerObject and CardObject and expiremented with casting

* Extracted shop code to use generic `SpriteObject`

* Extracted shop joker generation to a function

* Renamed object -> item

* Added setters and getters for `SpriteObject` members and updated all accesses to use them with casting (AI used for tedious work and reviewed - model Raptor mini)

* Added sprite_object_set_vx() because sprite_object_set_vy() exists and reordered the function order to have x,y parameters first, then targets

* Added Item object to act as a purchasable interface for the shop - AI used (model Raptor mini)

* Added -fms-extensions and switched to anonymous inheritance

* Fixed anonymous inheritance for joker and added direct access for that too

* fix build error from previous commit + clang-format

* Fixed build errors + clang-format for real this time (I hope...)

* clang-format one last time, I don't understand it anymore

* clang-format is annoying

* Added uses of CHECK_NULL_ARG macros

* Merged item_defs.h into item.h and fixed build error from previous commit

* clang-format...?

* Changed sprite_object_new() into sprite_object_init() and made it accept a parameter instead of returning one to make it less awkward

* Updated sprite_object_init() documentation

* Updated sprite_object_destroy documentation

* More clang-format

* Renamed add_to_inventory to acquire and updated documentation

* Added function documentations

* Update documentation + swap order of consumable and playing card types

* Added documentation for new files (+ small addition to button.h)

* clang-format

* Used typedef

* A bit more documentation

* Changed sho pcode to use generic Item instead of SpriteObject

* clang-format + fixed NULL-check error

* Revert weird clang-format...?

* clang-format for real

* Fixed errors from rebase on log_function_name

* Fixed build errors from rebase on main

* Added some more documentation about first member struct inheritance

* typo fix

* typo fix for real

* Removed SpriteObject field getters/setters (AI used - model Raptor mini)

* Renamed item_acquire -> item_on_acquired

* Added item_can_acquire()

* clang-format

* Fixed some sprite issues but not all...

* Fixed some more issues

* Cleanup JokerObject some more JokerObjects in the shop

* Added `item_destroy()`

* Added item_set_available_to_shop, CHECK_ITEM_TYPE macros + small documentation updates

* Another small JokerObject->Item replacement

* Removed item_set_available_to_shop and replaced with item_roll_new() and item_dispose(), also changed "available_to_shop" semantics to "rollable"

* Re-applied changes from game.c to round.c after rebase on main

* Added partial implementations of item functions for playing cards

* Line endings fix...

* Macro renames, function documentations

* Updated documentations

* Apply fixes from Copilot review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Fix card_object_get_buy_price type checking

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Avoid double pointer cast on dispose

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Apply suggestions from @ricfehr3's code review

Co-authored-by: Rickey <ric@rf3.xyz>

* Remove redundant comments

* Moved error checking before joker_get_random_rarity

Co-authored-by: Rickey <ric@rf3.xyz>

* Fixed build error from rebase

* clang-format

* Added doxygen documentation for Item explaining inheritance

* Removed unnecessary comment

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Rickey <ric@rf3.xyz>
This commit is contained in:
MeirGavish
2026-07-09 09:13:51 +03:00
committed by GitHub
parent 369c680cb7
commit d24b0b5619
23 changed files with 796 additions and 329 deletions
+47 -2
View File
@@ -9,7 +9,7 @@
#include "card.h"
#include "game.h"
#include "graphic_utils.h"
#include "sprite.h"
#include "item.h"
#include <maxmod.h>
@@ -112,8 +112,8 @@ typedef struct
typedef struct JokerObject
{
Item; // First member struct inheritance
Joker* joker;
SpriteObject* sprite_object;
} JokerObject;
typedef struct // These jokers are triggered after the played hand has finished scoring.
@@ -197,6 +197,51 @@ JokerObject* joker_object_new(Joker* joker);
void joker_object_destroy(JokerObject** joker_object);
// This doesn't actually score anything, it just performs an animation and plays a sound effect
void joker_object_shake(JokerObject* joker_object, mm_word sound_id);
/**
* @brief Returns the buy price of the joker object.
*
* @param joker_object the joker object whose price to return.
*
* @return UNDEFINED in case of error, the buy price of the joker otherwise.
*/
int joker_object_get_buy_price(Item* joker_object);
// TODO: Move to an owned_jokers.c/.h file?
/**
* @brief Add a Joker to the list of owned Jokers and place it in the joker row.
*
* @param joker_object The JokerObject to add cast to Item*
*/
void joker_object_add_to_owned(Item* joker_object);
/**
* @brief Destroy a JokerObject item, free its resources, and make it available to be rolled.
*
* @param joker_object Pointer to the JokerObject Item* to destroy; set to NULL.
*/
void joker_object_dispose(Item** joker_object);
/**
* @brief Set whether a Joker is available to be rolled for the shop, packs, etc.
*
* @param joker_id The ID of the joker whose availability to set.
* @param rollable true to make it rollable, false otherwise.
*/
void joker_set_rollable(int joker_id, bool rollable);
/**
* @brief Reset rollable jokers to include all jokers in the registry.
*/
void joker_reset_rollable_jokers(void);
/**
* @brief Roll and create a new JokerObject item.
*
* @return Newly created `Item*` (JokerObject) or NULL if none available.
*/
Item* joker_object_roll_new(void);
// This scores the joker and returns true if it was scored successfully
// card_object = NULL means the joker_event does not concern a particular Card, i.e. Independend or
// On_Blind_Selected as opposed to events that concern a particular card, i.e. On_Card_Scored or