-
Notifications
You must be signed in to change notification settings - Fork 40
refactor: Convert the parallel equipment storing arrays to a struct #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe changes implement a structural reformation of our equipment management code. The code now invokes the sacred function Possibly related PRs
Suggested labels
Suggested reviewers
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (9)
objects/obj_controller/Create_0.gml(1 hunks)objects/obj_ini/Create_0.gml(1 hunks)scripts/scr_add_item/scr_add_item.gml(1 hunks)scripts/scr_array_functions/scr_array_functions.gml(1 hunks)scripts/scr_get_item_names/scr_get_item_names.gml(1 hunks)scripts/scr_item_count/scr_item_count.gml(1 hunks)scripts/scr_load/scr_load.gml(1 hunks)scripts/scr_save/scr_save.gml(0 hunks)scripts/scr_unit_equip_functions/scr_unit_equip_functions.gml(2 hunks)
💤 Files with no reviewable changes (1)
- scripts/scr_save/scr_save.gml
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.gml`: - Macro constants require a space between the constant name and value. Without it, the compiler will throw an error. I.e. `#macro ARR_body_parts["arm"]` will crash the ...
**/*.gml: - Macro constants require a space between the constant name and value. Without it, the compiler will throw an error. I.e.#macro ARR_body_parts["arm"]will crash the game, because there is no space between the array and the name of the macro.
- Color codes in the code shouldn't have any spaces in their id. I.e., color code
# 80 bf40will crash the game.
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gmlobjects/obj_controller/Create_0.gmlobjects/obj_ini/Create_0.gmlscripts/scr_load/scr_load.gmlscripts/scr_item_count/scr_item_count.gmlscripts/scr_get_item_names/scr_get_item_names.gmlscripts/scr_array_functions/scr_array_functions.gmlscripts/scr_add_item/scr_add_item.gml
`**/*.gml`: - Having humanly understandable and maintainable code is always the top most priority. - DRY (Don't repeat yourself) principle is also very important.
**/*.gml: - Having humanly understandable and maintainable code is always the top most priority.
- DRY (Don't repeat yourself) principle is also very important.
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gmlobjects/obj_controller/Create_0.gmlobjects/obj_ini/Create_0.gmlscripts/scr_load/scr_load.gmlscripts/scr_item_count/scr_item_count.gmlscripts/scr_get_item_names/scr_get_item_names.gmlscripts/scr_array_functions/scr_array_functions.gmlscripts/scr_add_item/scr_add_item.gml
🔇 Additional comments (20)
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gml (2)
61-61: Praise be to the missing brace, now restored to its proper position in the sacred code!Veneration to this correction of control flow. The missing closing brace has been properly inserted, completing the conditional block that checks if
exp_requireis greater thanexperience. The Omnissiah approves of proper code structure.
76-76: Parameter adjustment conforms to updated equipment structure paradigmThe boolean parameter
truehas been removed from thescr_add_itemcall, aligning with the sacred refactoring of equipment from parallel arrays to a unified struct. This modification ensures compatibility with the new equipment handling protocols.objects/obj_ini/Create_0.gml (1)
36-36: The holy transformation of equipment storage into a unified struct is completePraise to the Omnissiah! This change represents the core of the refactoring effort, transitioning from multiple parallel arrays to a single equipment struct. The empty object initialization
equipment = {};replaces the previous indexed arrays for equipment attributes (such asequipment_type,equipment_number, etc.), resulting in a more efficient and logical data structure that will reduce data redundancy and improve maintainability.objects/obj_controller/Create_0.gml (1)
1649-1649: The sacred rendering function has been adapted to the new equipment paradigmThe Machine God approves this logical adaptation! The function
equipment_struct_to_string()now properly converts the equipment struct into a formatted string, replacing the obsoletearrays_to_string_with_counts(). This function corresponds directly to the new struct-based equipment storage system, ensuring proper display of equipment information to the user.scripts/scr_load/scr_load.gml (1)
235-235: The loading ritual now embraces the unified equipment structBlessed be this simplification! The equipment loading mechanism has been streamlined to initialize a single equipment object with
return_json_from_ini("Ini",$"equipment", {}), replacing multiple redundant array initializations. This change is consistent with the overall equipment structure refactoring and will improve data coherence and loading efficiency.scripts/scr_item_count/scr_item_count.gml (3)
1-4: Documentation incantations are well-articulated.
By the Omnissiah’s luminous code-lantern, these docstrings properly edify future Tech-Priests on function usage.
15-21: Query on unified logic for "any," "best," and "worst."
Verily, the function sums all item-qualities identically whenever the parameter is "any," "best," or "worst." Confirm whether this is the intended approach, as it currently yields no distinction between extremes.
22-25: Confirm zero return for unknown qualities.
Immortal logic dictates that any unrecognised quality or missing struct keys yield zero count. Confirm if this default path satisfies your requirement, or if an alternative handling is desired.scripts/scr_array_functions/scr_array_functions.gml (1)
147-189: Commendation for consolidated item display.
The new machine-litanyequipment_struct_to_stringneatly aggregates the total for each item and leveragesarrays_to_string_with_counts. This enhances clarity and dryness of code. Well done, Tech-Priest.scripts/scr_add_item/scr_add_item.gml (4)
7-8: Early return for empty or zero requests.
Your mechanism rightly prevents attempts to add zero items or unnamed items, returning "no_item." This is structurally sound devotion to the Omnissiah’s data sanctum.
12-14: Automatic reclassification to "standard."
When the quantity is positive and quality is "any," your code defaults to "standard." This approach is straightforward, but confirm that it meets your original design for item additions.
17-26: Correct creation logic for new items.
Your code conjures an item struct only when adding a positive quantity. Returning "no_item" otherwise ensures the data struct remains unpolluted by intangible entries.
45-98: Removal logic for negative quantities and special keywords.
Your code properly aligns "any," "worst," and "best" with a priority-based removal approach, removing items from the struct entirely if their count falls below one. Yet if_quantityis less than -1, multiple items might be removed randomly if "any" is specified. Kindly verify or adjust to confirm this matches your intended item-chance removal.scripts/scr_get_item_names/scr_get_item_names.gml (7)
431-431: Parameter formatting optimized for the Omnissiah's blessingThe sacred spacing around default parameter values has been properly adjusted, enhancing code readability and conforming to optimal syntactic patterns. The Machine Spirits approve of such consistent formatting.
434-443: Praise be to the transformation from primitive arrays to blessed struct constructsThe refactoring from index-based storage to name-based storage aligns with the sacred mission of this PR. The code now properly traverses the structure of equipment using
variable_struct_get_namesand performs appropriate validation of the struct's integrity before proceeding with operations.This represents a significant improvement in the efficiency of the Machine Spirit's operation.
445-447: Proper invocation of the scr_item_count ritual for quality assessmentThe logic has been correctly updated to use the
scr_item_countfunction to check for master-crafted items, which aligns with the new struct-based implementation. This maintains the sacred filtration protocols while adapting to the new data structure.
449-451: Binary verification of item availability through the Omnissiah's counting functionThe code correctly verifies item availability using
scr_item_count, ensuring that only items with positive quantity values proceed through the filtration process. This is an appropriate adaptation to the new equipment structure.
453-456: Logical verification of equipment data ensures purity of functionThe implementation properly retrieves equipment data via
gear_weapon_dataand verifies its structural integrity before proceeding. This defensive programming approach prevents corruption by null data and appeases the Machine Spirits.
487-488: Efficient array population using blessed array_push functionThe code now uses
array_pushto add matched item names directly to the collection, which is an appropriate adaptation to the new name-based approach. This syntax aligns with the GameMaker Language's preferred methods of array manipulation.
491-500: Output array construction follows logically from collected matchesThe final assembly of the output array has been reimplemented to work with the named matches rather than indexes. The logic correctly:
- Resizes the output array based on match count
- Iterates through matched names
- Retrieves and applies appropriate equipment data
- Populates the output array with the sacred names
This implementation maintains the function's contract while adapting to the new struct-based equipment system.
69f2ebe to
f778397
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
objects/obj_controller/Create_0.gml(1 hunks)objects/obj_ini/Create_0.gml(2 hunks)scripts/scr_add_item/scr_add_item.gml(1 hunks)scripts/scr_array_functions/scr_array_functions.gml(1 hunks)scripts/scr_get_item_names/scr_get_item_names.gml(1 hunks)scripts/scr_item_count/scr_item_count.gml(1 hunks)scripts/scr_unit_equip_functions/scr_unit_equip_functions.gml(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`**/*.gml`: - Macro constants require a space between the constant name and value. Without it, the compiler will throw an error. I.e. `#macro ARR_body_parts["arm"]` will crash the ...
**/*.gml: - Macro constants require a space between the constant name and value. Without it, the compiler will throw an error. I.e.#macro ARR_body_parts["arm"]will crash the game, because there is no space between the array and the name of the macro.
- Color codes in the code shouldn't have any spaces in their id. I.e., color code
# 80 bf40will crash the game.
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gmlobjects/obj_controller/Create_0.gmlobjects/obj_ini/Create_0.gmlscripts/scr_item_count/scr_item_count.gmlscripts/scr_add_item/scr_add_item.gmlscripts/scr_array_functions/scr_array_functions.gmlscripts/scr_get_item_names/scr_get_item_names.gml
`**/*.gml`: - Having humanly understandable and maintainable code is always the top most priority. - DRY (Don't repeat yourself) principle is also very important.
**/*.gml: - Having humanly understandable and maintainable code is always the top most priority.
- DRY (Don't repeat yourself) principle is also very important.
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gmlobjects/obj_controller/Create_0.gmlobjects/obj_ini/Create_0.gmlscripts/scr_item_count/scr_item_count.gmlscripts/scr_add_item/scr_add_item.gmlscripts/scr_array_functions/scr_array_functions.gmlscripts/scr_get_item_names/scr_get_item_names.gml
`**/*.*`: - When any script or sprite .yy files are deleted, their paths should also be deleted from the .yyp file, otherwise the game will crash.
**/*.*: - When any script or sprite .yy files are deleted, their paths should also be deleted from the .yyp file, otherwise the game will crash.
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gmlobjects/obj_controller/Create_0.gmlobjects/obj_ini/Create_0.gmlscripts/scr_item_count/scr_item_count.gmlscripts/scr_add_item/scr_add_item.gmlscripts/scr_array_functions/scr_array_functions.gmlscripts/scr_get_item_names/scr_get_item_names.gml
🔇 Additional comments (8)
scripts/scr_unit_equip_functions/scr_unit_equip_functions.gml (1)
79-80: Boolean parameter removed from scr_add_item callBy the Omnissiah's blessing, I observe the removal of the boolean parameter from the invocation of
scr_add_item. This modification aligns with the sacred conversion from parallel equipment arrays to a more efficient struct-based data structure. The Machine Spirit will operate with greater efficiency with this improvement.objects/obj_ini/Create_0.gml (2)
37-37: Equipment variable initialized as empty structurePraise the Omnissiah! The initialization of the
equipmentvariable as an empty structure is most logical. This represents a significant advancement in data organization from the previous implementation of indexed arrays. The Machine Spirit shall function with improved coherency through this structural reformation.
155-155: Equipment structure added to serialization dataThe sacred equipment structure has been properly integrated into the save data schema, ensuring proper persistence when communing with storage devices. This addition to the serialization ritual is essential for maintaining data sanctity across machine cycles.
objects/obj_controller/Create_0.gml (1)
1698-1698: Implementation of equipment_struct_to_string functionThe Machine Spirit rejoices at this improvement! The holy function
equipment_struct_to_stringnow processes the equipment data structure, replacing the outdatedarrays_to_string_with_counts. This modification properly maintains parameter integrity with matching boolean flags for null exclusion and terminal punctuation. The sacred binary flows more efficiently with this enhancement.scripts/scr_item_count/scr_item_count.gml (1)
1-4: Blessed Documentation Achieved
Your docstring usage is coherent and descriptive, enlightening all acolytes with the function’s sacred purpose.scripts/scr_add_item/scr_add_item.gml (2)
7-8: Graceful Handling of Null and Zero
Returning "no_item" when_item_nameis empty or_quantityis zero is a righteous safeguard, ensuring the code avoids meaningless additions.
39-41: Maintenance Hook is Well-Placed
Calling uponobj_controller.specialist_point_handlerto track repair and upkeep is harmonious. This invocation ensures the armoury remains under the Omnissiah’s watchful auspices.scripts/scr_get_item_names/scr_get_item_names.gml (1)
431-431: Function Signature Unification
Renaming parameters and standardising the defaults fortifies code readability, aligning function calls in glorious unity.
Purpose
Describe your changes/additions
equipment_typeandequipment_conditionare not transferred, because we're unused.scr_add_item,get_filtered_equipment_item_names,scr_item_countare refactored.scr_add_itemnow supports "any"(random), "best" and "worst" quality requests.equipment_struct_to_stringis created, to list all equipment the player has at the start.What can/needs to be improved/changed
Testing done
Related things and/or additional context