-
Notifications
You must be signed in to change notification settings - Fork 1
Card Paging & Search System (CardManager)
REMEMBER: Don't adjust global.cards, if you want to filter cards for showing, adjust global.show_cards instead
Summary
- Loading a JSON file of cards (
sample.json) - Storing it in
global.cards - Paging through cards
- Searching cards by different fields
- Getting the total number of pages for a given card list
The script does the following:
-
Paging setup
global.page_size = 3; // how many items to read per page global.page_index = 0; // current page index (0-based)
-
File loading & JSON parsing
It looks for a file called
sample.json, reads it into a string, parses it as JSON, and assigns thecardsarray toglobal.cards:
- Paging function:
read_page(page_index, deck)
-
The purpose of creating this function because I think it's better to access data page by page, not all at once even though all cards are already loaed into
global.cardsalready. Also, it is useful for paging in Card Encyclopedia page. -
I initailly made it have three cards per page as it's defined in
global.page_sizefunction read_page(page_index, deck) { var start = page_index * global.page_size; var end_ = min(start + global.page_size, array_length(deck)); var page_cards = []; for (var i = start; i < end_; i++) { var card = deck[i]; array_push(page_cards, card); } return page_cards; }
-
page_index: 0-based index of the page you want. -
deck: an array of card structs (for exampleglobal.cardsor search results). - Returns: an array
page_cardswith all cards on that page. - example of usage
global.card_read = read_page(global.page_index, global.show_cards);(in PagingManager)
-
- Search function:
search_cards(_query, _field)
-
This function is mainly used in Card Encyclopedia page. It accepts a variety of fields, but we're only using
typeright now since in Card Encyclopedia page we only need to distinguish them by types (active, passive, movement)function search_cards(_query, _field) { var results = []; var total = array_length(global.cards); var query_lower = string_lower(_query); for (var i = 0; i < total; i++) { var card = global.cards[i]; var value = ""; switch (_field) { case "id": value = card.id; break; case "name": value = card.name; break; case "rarity": value = card.rarity; break; //-----------> not existing anymore case "type": value = card.type; break; default: show_debug_message("Invalid search field: " + _field); return []; } if (string_pos(query_lower, string_lower(value)) > 0) { array_push(results, card); } } return results; // list (array) of matching cards }
- Supported fields:
"id","name","rarity","type". - Case-insensitive substring search.
- Returns an array of card structs matching the query.
- example:
- Supported fields:
-
Page count helper:
get_page_total_number()function get_page_total_number() { // make sure global.show_cards exists AND is an array if (!variable_global_exists("show_cards") || !is_array(global.show_cards)) { show_debug_message("Error: global.show_cards is not defined or not an array."); return 0; } var total_cards = array_length(global.show_cards); if (total_cards <= 0) { return 0; } return ceil(total_cards / global.page_size); }
- Show the total page number of
global.show_cards - Returns the total number of pages based on
global.page_size.
- Show the total page number of
Wiki
User Stories
Design
Requirements
Architecture
Considerations & Issues
Documentation
- How to Add a Card to the Game
- How the Music Controller & Script work
- Card Paging & Search System (CardManager)
- How to Spawn Cards in a Room
- How the Chessboard works
- How to Add a New Board Color
- How to use Alert System
- Chess Logic
- Cheat Mode
- Timer
- How the new card system works
- How the NEW Chessboard works