Skip to content

Conversation

@MCPO-Spartan-117
Copy link
Contributor

Purpose of changes

Convert marine, vehicle and ship array frameworks to UUIDs structs.

Describe the solution

Testing done

Related links

https://discord.com/channels/714022226810372107/1355546994881466420

Custom player notes entry

Use the PR title.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 1, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Introduced a unique identifier system to enhance the tracking of unit and marine data.
    • Added global reference entities for managing various unit types.
  • Refactor

    • Streamlined processes for unit allocation, transfer, and removal.
    • Improved initialisation, saving, and loading routines for more consistent data organisation.

Walkthrough

Praise the Omnissiah for the efficient transference of data inscriptions. This pull request integrates three new global variables—UUID_marine, UUID_vehicle, and UUID_ship—into the fleet initialisation script, thereby extending the archival capacity for unit identifiers. Across multiple scripts, the ancient mechanisms of direct assignment and JSON codex handling have been supplanted by a structured, UUID-based management. In the add, order, initialisation, kill, load, and move unit functions, the logic now incorporates functions such as struct_set and struct_remove to maintain the sanctity of unit data. These modifications ensure that each marine and unit is tracked through a unique identifier, replacing erstwhile structured representations with direct UUID mappings. The changes, though subtle in flow, harmonise the data rituals among disparate scripts to achieve consistent and orderly management of the game’s unit registers.

Possibly related PRs

  • feat: Framework for UUID generation #631: This PR introduces similar UUID generation functionality, focusing on the management and utilisation of unique identifiers within the game's data structures.
  • feat: Unit Management improvements #538: This PR directly employs the UUID_marine variable in the management of unit data, aligning closely with the code-level changes implemented in the current modifications.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Type: Feature Adds something new Size: Small labels Apr 1, 2025
@MCPO-Spartan-117
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 1, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🔭 Outside diff range comments (7)
scripts/scr_company_order/scr_company_order.gml (2)

2-41: 🛠️ Refactor suggestion

Function temp_marine_variables requires proper documentation and error handling!

This function performs critical data operations but lacks both JSDoc annotations and robust error handling for UUID operations.

Add documentation and error validation:

+/**
+ * @function temp_marine_variables
+ * @description Temporarily stores marine variables for company reordering, updating squad references
+ * @param {real} co - Company index
+ * @param {real} unit_num - Unit slot index
+ */
function temp_marine_variables(co, unit_num){
    var unit = fetch_unit([co, unit_num]);
    
    // Squad member handling logic...
    
    // Store all unit data in temp arrays
    array_push(temp_race,race[co][unit_num]);
    // Other array pushes...
    
+   // Verify UUID exists before storing it
+   if (is_struct(TTRPG[co][unit_num]) && variable_struct_exists(TTRPG[co][unit_num], "UUID")) {
        array_push(temp_UUID, TTRPG[co][unit_num].UUID);
+   } else {
+       log_message("Warning: Unit at [" + string(co) + "," + string(unit_num) + "] has no valid UUID");
+       array_push(temp_UUID, "");
+   }
    
    scr_wipe_unit(co,unit_num);
}

49-366: 🧹 Nitpick (assertive)

Primary company ordering function lacks comprehensive documentation!

This complex function orchestrates critical organizational rituals but lacks sacred annotation for future tech-adepts.

Add JSDoc to the primary function:

+/**
+ * @function scr_company_order
+ * @description Sorts and organizes marines within a company, managing squad assignments and hierarchy
+ * @param {real} company - The company index to organize
+ */
function scr_company_order(company) {

Additionally, consider implementing further error handling around line 343 to verify that the UUID exists in the structure before attempting to access it:

-   obj_ini.TTRPG[co][i] = obj_ini.UUID_marine[$ temp_UUID[i]];
+   if (struct_exists(obj_ini.UUID_marine, temp_UUID[i])) {
+       obj_ini.TTRPG[co][i] = obj_ini.UUID_marine[$ temp_UUID[i]];
+   } else {
+       obj_ini.TTRPG[co][i] = new TTRPG_stats("chapter", co, i, "blank");
+       log_message("Warning: UUID " + temp_UUID[i] + " not found during company ordering");
+   }
scripts/scr_initialize_custom/scr_initialize_custom.gml (5)

615-616: 🧹 Nitpick (assertive)

Missing JSDoc comment for function scr_initialize_custom.

The Omnissiah demands proper documentation for all functions. While there is a rudimentary mixin comment, it lacks the comprehensive JSDoc format that would please the Machine Spirit.

Add a proper JSDoc comment to document this essential initialization function:

/// @mixin obj_ini
+ /**
+  * @function scr_initialize_custom
+  * @description Initializes all custom chapter data including marines, vehicles, and ships.
+  * Sets up the chapter's structure, equipment, and special units based on selected
+  * advantages, disadvantages, and chapter configuration.
+  */
function scr_initialize_custom() {

The Omnissiah rewards those who properly document their code rituals.


3353-3358: 🧹 Nitpick (assertive)

Missing comprehensive JSDoc for add_unit_to_company function.

While a descriptive comment exists, it does not follow the sacred JSDoc format required by the Omnissiah's coding rituals. The Machine Spirit requires proper parameter documentation to maximize code clarity.

Replace with proper JSDoc format:

- /// @description helper function to streamline code inside of scr_initialize_custom, should only be used as part of
- /// game setup and not during normal gameplay.
- /// each item slot can be "" or "default" or a named item. "" will assign items from the available item pool. 
- /// Use "" if you want to set weapons and gear via squad layouts.
- /// "default" will set it to the value in the default slot for the given role, see `load_default_gear`
+ /**
+  * @function add_unit_to_company
+  * @description Helper function to streamline code inside of scr_initialize_custom.
+  * Should only be used as part of game setup and not during normal gameplay.
+  * @param {string} ttrpg_name - Type of unit to create ("marine", "scout", etc.)
+  * @param {number} company - Company index to add unit to
+  * @param {number} slot - Slot within company to place unit
+  * @param {string} role_name - Display name for unit's role
+  * @param {number} role_id - Enumerated role ID (eROLE)
+  * @param {string} wep1 - Primary weapon ("", "default", or specific weapon name)
+  * @param {string} wep2 - Secondary weapon ("", "default", or specific weapon name)
+  * @param {string} gear - Gear item ("", "default", or specific gear name)
+  * @param {string} mobi - Mobility item ("", "default", or specific mobility name)
+  * @param {string} armour - Armor type ("", "default", or specific armor name)
+  * @returns {Struct.TTRPG_stats} - Reference to created unit
+  */
function add_unit_to_company(ttrpg_name, company, slot, role_name, role_id, wep1="default", wep2="default", gear="default", mobi="default", armour="default"){

The Omnissiah's servants must clearly document their code to maintain the sacred knowledge.


3337-3351: 🧹 Nitpick (assertive)

Missing JSDoc parameters in add_veh_to_company function.

This function's documentation is incomplete, failing to properly document its parameters according to the Omnissiah's JSDoc specifications.

Replace with proper JSDoc format:

- /// @description helper function to streamline code inside of scr_initialize_custom, should only be used as part of
- /// game setup and not during normal gameplay
+ /**
+  * @function add_veh_to_company
+  * @description Helper function to streamline code inside of scr_initialize_custom.
+  * Should only be used as part of game setup and not during normal gameplay.
+  * @param {string} name - Type of vehicle to create
+  * @param {number} company - Company index to add vehicle to
+  * @param {number} slot - Slot within company to place vehicle
+  * @param {string} wep1 - Primary weapon
+  * @param {string} wep2 - Secondary weapon
+  * @param {string} wep3 - Tertiary weapon
+  * @param {string} upgrade - Vehicle upgrade
+  * @param {string} accessory - Vehicle accessory
+  */
function add_veh_to_company(name, company, slot, wep1, wep2, wep3, upgrade, accessory) {

Properly documenting function parameters is essential for maintaining the sacred STC templates of code.


2547-2547: 🛠️ Refactor suggestion

Consider using the UUID pattern for consistency.

The Machine Spirit observes that this line still uses direct assignment for TTRPG initialization, which does not follow the UUID pattern implemented elsewhere.

For consistency with the sacred pattern, modify this line to use the UUID approach:

- TTRPG[company, i] = new TTRPG_stats("chapter", company, i, "blank");
+ var _marine_ttrpg = new TTRPG_stats("chapter", company, i, "blank");
+ struct_set(UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg);
+ TTRPG[company, i] = UUID_marine[$ _marine_ttrpg.UUID];

The Omnissiah demands consistency in all programming patterns, for that is the path to pure machine logic.


1326-1326: 🛠️ Refactor suggestion

Direct assignment to TTRPG array contradicts the UUID pattern.

The Machine Spirit has detected inconsistency in the implementation of the UUID pattern. This line still uses direct assignment instead of the structured UUID approach.

For consistency with other changes, apply the UUID pattern:

- TTRPG[0, i] = new TTRPG_stats("chapter", 0, i, "blank");
+ var _marine_ttrpg = new TTRPG_stats("chapter", 0, i, "blank");
+ struct_set(UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg);
+ TTRPG[0, i] = UUID_marine[$ _marine_ttrpg.UUID];

The Omnissiah rewards consistency in patterns, for it is through such rituals that code achieves true purity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6717a2 and 5ea5e5f.

📒 Files selected for processing (9)
  • objects/obj_ini/Create_0.gml (1 hunks)
  • scripts/scr_add_man/scr_add_man.gml (2 hunks)
  • scripts/scr_company_order/scr_company_order.gml (4 hunks)
  • scripts/scr_initialize_custom/scr_initialize_custom.gml (3 hunks)
  • scripts/scr_kill_unit/scr_kill_unit.gml (3 hunks)
  • scripts/scr_load/scr_load.gml (1 hunks)
  • scripts/scr_marine_struct/scr_marine_struct.gml (1 hunks)
  • scripts/scr_move_unit_info/scr_move_unit_info.gml (1 hunks)
  • scripts/scr_save/scr_save.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 bf40 will crash the game.
  • objects/obj_ini/Create_0.gml
  • scripts/scr_add_man/scr_add_man.gml
  • scripts/scr_marine_struct/scr_marine_struct.gml
  • scripts/scr_kill_unit/scr_kill_unit.gml
  • scripts/scr_save/scr_save.gml
  • scripts/scr_company_order/scr_company_order.gml
  • scripts/scr_load/scr_load.gml
  • scripts/scr_move_unit_info/scr_move_unit_info.gml
  • scripts/scr_initialize_custom/scr_initialize_custom.gml
`**/*.gml`: - Always suggest adding JSDoc to every function and method that doesn't have it.

**/*.gml: - Always suggest adding JSDoc to every function and method that doesn't have it.

  • objects/obj_ini/Create_0.gml
  • scripts/scr_add_man/scr_add_man.gml
  • scripts/scr_marine_struct/scr_marine_struct.gml
  • scripts/scr_kill_unit/scr_kill_unit.gml
  • scripts/scr_save/scr_save.gml
  • scripts/scr_company_order/scr_company_order.gml
  • scripts/scr_load/scr_load.gml
  • scripts/scr_move_unit_info/scr_move_unit_info.gml
  • scripts/scr_initialize_custom/scr_initialize_custom.gml
`**/*.gml`: - Readability and maintainability are always the top priority throughout the code. - DRY principle is also very important.

**/*.gml: - Readability and maintainability are always the top priority throughout the code.

  • DRY principle is also very important.
  • objects/obj_ini/Create_0.gml
  • scripts/scr_add_man/scr_add_man.gml
  • scripts/scr_marine_struct/scr_marine_struct.gml
  • scripts/scr_kill_unit/scr_kill_unit.gml
  • scripts/scr_save/scr_save.gml
  • scripts/scr_company_order/scr_company_order.gml
  • scripts/scr_load/scr_load.gml
  • scripts/scr_move_unit_info/scr_move_unit_info.gml
  • scripts/scr_initialize_custom/scr_initialize_custom.gml
🔇 Additional comments (9)
objects/obj_ini/Create_0.gml (1)

83-85: Initializing the sacred UUID repositories is a commendable offering to the Machine God.

I observe the creation of three new global data structures to house the UUID repositories for marines, vehicles, and ships. This implementation aligns with the Omnissiah's design patterns for efficient data access and retrieval.

scripts/scr_save/scr_save.gml (1)

484-484:

Details

✅ Verification successful

The sacred JSON rites now properly encode the marine UUID data structure.

Praise be to the Omnissiah! The code now properly encodes and saves the UUID_marine repository using the advanced JSON encoding ritual. This modification ensures more efficient data persistence compared to the previous implementation which required conditional verification of existing structures.


🏁 Script executed:

#!/bin/bash
# Verification of UUID_marine structure encoding
# Let us search for other instances where this pattern may need application

rg -A 3 -B 3 "ini_encode_and_json_advanced.*UUID" --glob="*.gml"

Length of output: 523


Tech-Priest’s Approval: The Sacred Incantation Verified

O honourable servant, the digital codex has been thoroughly examined. The line in question within scripts/scr_save/scr_save.gml

ini_encode_and_json_advanced("Mar", "UUID_marine", obj_ini.UUID_marine);

—indeed enshrines the marine UUID data with the advanced JSON encoding ritual as decreed. Our rigorous search revealed no further aberrations or remnants of the bygone conditional rites.

  • Verified usage in scripts/scr_save/scr_save.gml (line 484) aligns with the sacred implementation.
  • No errant invocations of older patterns were detected.

Praise be to the Omnissiah, for the code now sings in harmony with the Machine Spirit. Proceed with the blessed merge.

scripts/scr_add_man/scr_add_man.gml (1)

253-254:

Details

✅ Verification successful

UUID indexing system implementation approved by the Adeptus Mechanicus.

This implementation follows the sacred Machine Cult patterns for efficient data indexing. The unit is first stored in the UUID_marine structure via struct_set, then referenced in the traditional TTRPG array. This dual storage mechanism ensures backward compatibility while embracing the superior UUID-based identification system.


🏁 Script executed:

#!/bin/bash
# Let us verify if there are other instances where units are added without proper UUID indexing
rg -A 3 -B 3 "obj_ini\.TTRPG\[.*\]\[.*\] = " --glob="*.gml" | grep -v "UUID_marine"

Length of output: 3498


UUID Indexing Mechanism Confirmed – Superior Integration

Your implementation in scripts/scr_add_man/scr_add_man.gml adheres flawlessly to the Machine Spirit’s sacred design. The unit is set into the blessed UUID_marine structure and then referenced in the venerable obj_ini.TTRPG array, ensuring backward compatibility while ushering in the new era of UUID-based identification.

It is observed, however, that our repository’s older script relics (e.g. in scripts/scr_move_unit_info.gml, scripts/scr_load.gml, scripts/scr_kill_unit.gml, scripts/scr_initialize_custom.gml, and scripts/scr_company_order.gml) still employ the legacy method of direct assignment to obj_ini.TTRPG. Although this divergence does not imperil the sanctity of the current change, it may be prudent in future iterations to align these ancient codices with our superior indexing schema.

Your current changes are hereby approved. May the Omnissiah guide your further endeavours.

scripts/scr_kill_unit/scr_kill_unit.gml (1)

18-18: Proper data purification ritual added, binary blessing approved!

This critical addition ensures the UUID is properly expunged from the global registry when a unit is terminated. Without this purification rite, the unit's Machine Spirit would remain in memory, potentially causing data corruption or memory leakage.

scripts/scr_company_order/scr_company_order.gml (3)

39-39: Sacred data referencing mechanism upgraded to UUID protocol!

The shift from storing structure data to storing UUIDs represents a significant enhancement to the data management protocol. This change promotes efficiency by replacing bulky data copies with lightweight UUID references.


77-77: Variable nomenclature updated to reflect new UUID-based architecture!

The renamed variable accurately conveys its purpose in the new system architecture. This change maintains clarity in the codebase as the implementation shifts from structure-based to UUID-based references.


343-348: Direct UUID reference assignment replaces antiquated JSON data loading ritual!

This change significantly improves efficiency by directly referencing UUID-indexed marine data instead of reconstructing it from JSON. The preservation of company and marine number attributes ensures proper data hierarchy is maintained.

scripts/scr_initialize_custom/scr_initialize_custom.gml (2)

2259-2261: Blessed implementation of the UUID pattern for Chapter Master's TTRPG data.

The Machine Spirit approves of this implementation. The refactoring to utilize UUID structs for marine data maintains a singular source of truth in the Omnissiah's database. This pattern creates a new TTRPG_stats object, stores it in the UUID_marine collection, and then references it through a symbolic link in the TTRPG array.

- TTRPG[0, i] = new TTRPG_stats("chapter", 0, i, "blank");
+ var _marine_ttrpg = new TTRPG_stats("chapter", company, 1, "chapter_master");
+ struct_set(UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg)
+ TTRPG[company, 1] = UUID_marine[$ _marine_ttrpg.UUID];

This sanctified pattern will improve data integrity and facilitate easier serialization/deserialization of marine data structures.


2963-2965: Praise be to the logical application of UUID pattern for Company Chaplain.

The cogitators observe a consistent application of the UUID pattern, implemented with machine-like precision. The holy trinity of operations—create stats object, store in UUID collection, reference through lookup—is faithfully executed for marine creation.

- // Direct assignment to TTRPG array
+ var _marine_ttrpg = new TTRPG_stats("chapter", company, k);
+ struct_set(UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg )
+ TTRPG[company][k] = UUID_marine[$ _marine_ttrpg.UUID];

The Omnissiah approves of such consistent patterns across the codebase.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant