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:
co-authored by
Copilot Autofix powered by AI
Rickey
parent
369c680cb7
commit
d24b0b5619
+26
-29
@@ -783,7 +783,7 @@ static inline void card_in_hand_loop_handle_discard_and_shuffling(
|
||||
sound_played = true;
|
||||
}
|
||||
|
||||
if (hand[card_idx]->sprite_object->x >= *hand_x)
|
||||
if (hand[card_idx]->x >= *hand_x)
|
||||
{
|
||||
discard_push(hand[card_idx]->card);
|
||||
|
||||
@@ -801,8 +801,8 @@ static inline void card_in_hand_loop_handle_discard_and_shuffling(
|
||||
// and we end up with an element at `card_idx` that is still NULL.
|
||||
if (hand[card_idx] != NULL)
|
||||
{
|
||||
*hand_y = hand[card_idx]->sprite_object->y;
|
||||
*hand_x = hand[card_idx]->sprite_object->x;
|
||||
*hand_y = hand[card_idx]->y;
|
||||
*hand_x = hand[card_idx]->x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1138,8 +1138,8 @@ static inline void card_draw(void)
|
||||
const FIXED deck_x = int2fx(CARD_DRAW_POS.x);
|
||||
const FIXED deck_y = int2fx(CARD_DRAW_POS.y);
|
||||
|
||||
card_object->sprite_object->x = deck_x;
|
||||
card_object->sprite_object->y = deck_y;
|
||||
card_object->x = deck_x;
|
||||
card_object->y = deck_y;
|
||||
|
||||
set_hand_top(get_hand_top() + 1);
|
||||
get_hand_array()[get_hand_top()] = card_object;
|
||||
@@ -1190,16 +1190,16 @@ static inline void game_round_discarded_cards_loop(void)
|
||||
|
||||
// Set the sprite for the discarded card object
|
||||
card_object_set_sprite(discarded_card_object, 0);
|
||||
sprite_object_reset_transform(discarded_card_object->sprite_object);
|
||||
sprite_object_reset_transform((SpriteObject*)discarded_card_object);
|
||||
|
||||
discarded_card_object->sprite_object->tx = int2fx(204);
|
||||
discarded_card_object->sprite_object->ty = int2fx(112);
|
||||
discarded_card_object->sprite_object->x = int2fx(240);
|
||||
discarded_card_object->sprite_object->y = int2fx(80);
|
||||
discarded_card_object->tx = int2fx(204);
|
||||
discarded_card_object->ty = int2fx(112);
|
||||
discarded_card_object->x = int2fx(240);
|
||||
discarded_card_object->y = int2fx(80);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (discarded_card_object->sprite_object->y >= discarded_card_object->sprite_object->ty)
|
||||
if (discarded_card_object->y >= discarded_card_object->ty)
|
||||
{
|
||||
deck_push(discarded_card_object->card); // Put the card back into the deck
|
||||
card_object_destroy(&discarded_card_object);
|
||||
@@ -1301,13 +1301,13 @@ static inline void cards_in_hand_update_loop(void)
|
||||
{
|
||||
hand_y -= int2fx(CARD_FOCUSED_SEL_Y);
|
||||
}
|
||||
if (i != selected_card_idx && hand[i]->sprite_object->y > hand_y)
|
||||
if (i != selected_card_idx && hand[i]->y > hand_y)
|
||||
{
|
||||
hand[i]->sprite_object->y = hand_y;
|
||||
hand[i]->y = hand_y;
|
||||
// Set target y to match y. Ensures target is updated even when vy becomes
|
||||
// 0, preventing immediate snap back.
|
||||
hand[i]->sprite_object->ty = hand_y;
|
||||
hand[i]->sprite_object->vy = 0;
|
||||
hand[i]->ty = hand_y;
|
||||
hand[i]->vy = 0;
|
||||
}
|
||||
|
||||
hand_x = hand_x + (int2fx(i) - int2fx(get_hand_top()) / 2) *
|
||||
@@ -1339,7 +1339,7 @@ static inline void cards_in_hand_update_loop(void)
|
||||
{
|
||||
card_object_set_selected(hand[i], false);
|
||||
played_push(hand[i]);
|
||||
sprite_destroy(&hand[i]->sprite_object->sprite);
|
||||
sprite_destroy(&hand[i]->sprite);
|
||||
hand[i] = NULL;
|
||||
reorder_card_sprites_layers();
|
||||
|
||||
@@ -1376,8 +1376,8 @@ static inline void cards_in_hand_update_loop(void)
|
||||
break;
|
||||
}
|
||||
|
||||
hand[i]->sprite_object->tx = hand_x;
|
||||
hand[i]->sprite_object->ty = hand_y;
|
||||
hand[i]->tx = hand_x;
|
||||
hand[i]->ty = hand_y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1526,14 +1526,14 @@ static inline void play_starting_played_cards_update(int played_idx)
|
||||
}
|
||||
}
|
||||
|
||||
played[played_idx]->sprite_object->tx =
|
||||
played[played_idx]->tx =
|
||||
int2fx(HAND_PLAY_POS.x) + (int2fx(played_top - played_idx) - int2fx(played_top) / 2) * -27;
|
||||
played[played_idx]->sprite_object->ty = int2fx(HAND_PLAY_POS.y);
|
||||
played[played_idx]->ty = int2fx(HAND_PLAY_POS.y);
|
||||
|
||||
card_selected = card_object_is_selected(played[played_idx]);
|
||||
if (card_selected && played_top - played_idx >= scored_card_index)
|
||||
{
|
||||
played[played_idx]->sprite_object->ty -= int2fx(10);
|
||||
played[played_idx]->ty -= int2fx(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1593,10 +1593,7 @@ static inline bool play_scoring_cards_update(void)
|
||||
if (card_object_is_selected(scored_card_object))
|
||||
{
|
||||
// Offset of 1 tile to keep the text on the card
|
||||
tte_set_pos(
|
||||
fx2int(scored_card_object->sprite_object->x) + TILE_SIZE,
|
||||
SCORED_CARD_TEXT_Y
|
||||
);
|
||||
tte_set_pos(fx2int(scored_card_object->x) + TILE_SIZE, SCORED_CARD_TEXT_Y);
|
||||
|
||||
// Set text color to blue from background memory
|
||||
tte_set_special(TTE_BLUE_PB * TTE_SPECIAL_PB_MULT_OFFSET);
|
||||
@@ -1809,7 +1806,7 @@ static inline void play_ending_played_cards_update(int played_idx)
|
||||
|
||||
if (card_object_is_selected(played[played_idx]) && played_top - played_idx >= scored_card_index)
|
||||
{
|
||||
played[played_idx]->sprite_object->ty = int2fx(HAND_PLAY_POS.y);
|
||||
played[played_idx]->ty = int2fx(HAND_PLAY_POS.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1837,7 +1834,7 @@ static bool play_ended_played_cards_update(int played_idx)
|
||||
}
|
||||
|
||||
// card has exited the screen, now discard it and set it to NULL
|
||||
if (played[played_idx]->sprite_object->x >= int2fx(CARD_DISCARD_PNT.x))
|
||||
if (played[played_idx]->x >= int2fx(CARD_DISCARD_PNT.x))
|
||||
{
|
||||
discard_push(played[played_idx]->card); // Push the card to the discard pile
|
||||
card_object_destroy(&played[played_idx]);
|
||||
@@ -1870,7 +1867,7 @@ static bool play_ended_played_cards_update(int played_idx)
|
||||
}
|
||||
|
||||
// put target X position off screen to the right
|
||||
played[played_idx]->sprite_object->tx = int2fx(CARD_DISCARD_PNT.x);
|
||||
played[played_idx]->tx = int2fx(CARD_DISCARD_PNT.x);
|
||||
discarded_card = true;
|
||||
}
|
||||
|
||||
@@ -1968,7 +1965,7 @@ static inline void played_cards_update_loop(void)
|
||||
break;
|
||||
}
|
||||
|
||||
played[played_idx]->sprite_object->tscale = FIX_ONE;
|
||||
played[played_idx]->tscale = FIX_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user