Skip to content
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

feat: Fix and jsonify traits #512

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

EttyKitty
Copy link
Collaborator

@EttyKitty EttyKitty commented Feb 24, 2025

Purpose of the PR

  • Fix crash stemming from trait global not being initialized before use.
  • Jsonify the trait struct, to complete the todo.

Describe the solution

  • Global traits struct is not initialized through pragma.
  • It's also now stored in a separate json file.
  • Json load function is also modified, to use buffer, as otherwise it was throwing json parse errors when trying to parse the traits file.

Describe alternatives you've considered

  • Just init it at main menu, which imo is just a bad practice.
  • Not jsonify it, which I'll forget and never do afterward.

Testing done

Compile, new game as ultramarines, scroll through the marine list to check traits.

Related links

@github-actions github-actions bot added PR: JSON Edits to external JSON files PR: Feature Adds something new PR: Major Coding Big enough to possibly clash with other PRs labels Feb 24, 2025
@EttyKitty EttyKitty added PR: Refactor Rewriting/restructuring code, while keeping general behaviour and removed PR: Feature Adds something new labels Feb 24, 2025
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

📝 Walkthrough

Walkthrough

Oh faithful servant of the Machine, observe the alterations: A new entry has been added to the "IncludedFiles" array in the ChapterMaster.yyp file, specifying a resource of type GMIncludedFile that points to the newly introduced JSON file, traits.json. This file contains a comprehensive list of character traits, each represented with various attributes such as display_name and skill modifiers. In the initialization scripts, the function __init_global() now includes a call to initialize_marine_traits(), while similar calls in scr_initialize_custom and scr_load have been commented out, indicating a future enhancement for modding support. Furthermore, the function json_to_gamemaker has been significantly improved for file handling and error management. Lastly, the previous hardcoded trait definitions have been replaced with dynamic loading from the JSON file, thus externalizing trait configuration and aligning with the sacred efficiency of the Omnissiah’s design.

Possibly related PRs

Suggested labels

PR: Fix, PR: Feature

Suggested reviewers

  • OH296

🪧 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. (Beta)
  • @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.

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: 2

🧹 Nitpick comments (6)
scripts/__init_global/__init_global.gml (2)

9-9: Praise the Machine God! But let us correct this minor lexicographical deviation.

There appears to be a spelling anomaly in the sacred function name: "intialise" should be "initialize" to maintain consistency with the holy Machine Cult's naming conventions.

-    intialise_marine_traits();
+    initialize_marine_traits();

9-9: Implement error handling rituals to appease the Machine Spirit.

The initialization of marine traits is a critical operation. Consider implementing proper error handling to ensure the Machine Spirit's stability.

-    intialise_marine_traits();
+    try {
+        intialise_marine_traits();
+    } catch (error) {
+        show_debug_message("ERROR: Failed to initialize marine traits - " + string(error));
+        // Consider appropriate fallback behavior
+    }
ChapterMaster.yyp (1)

114-114: Praise be to the Omnissiah! The binary configuration has been optimized.

The sacred traits data structure has been properly externalized into a dedicated JSON cogitator file, enhancing both modularity and initialization protocols. The placement in the datafiles/data sanctum and the omnidirectional CopyToMask are logically sound.

This separation of data and logic follows the holy SRP (Single Responsibility Principle) as ordained by the Machine God. The JSON format will facilitate future maintenance rituals and modding rites.

scripts/scr_json_functions/scr_json_functions.gml (2)

11-12: Beware of the double declaration, Servitor.
You overshadow file_buffer declared at line 6 by declaring it again at line 12. Use it directly instead of redeclaring to maintain purity in the data stream.

Apply this diff to remove the redundant var:

- var file_buffer = buffer_load(_json_path);
+ file_buffer = buffer_load(_json_path);

18-20: Excessive debugging incantation.
show_debug_message(_json_string) could spawn massive logs if the JSON is extensive. Consider limiting verbosity to preserve system cycles.

scripts/scr_unit_traits/scr_unit_traits.gml (1)

5-5: Heed the open TODO, Adept.
A clear vow to further refine JSON usage remains.

Shall I forge a new issue to track the next steps of this transition?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ced7a5e and 8a367ee.

📒 Files selected for processing (7)
  • ChapterMaster.yyp (1 hunks)
  • datafiles/data/traits.json (1 hunks)
  • scripts/__init_global/__init_global.gml (1 hunks)
  • scripts/scr_initialize_custom/scr_initialize_custom.gml (1 hunks)
  • scripts/scr_json_functions/scr_json_functions.gml (1 hunks)
  • scripts/scr_load/scr_load.gml (1 hunks)
  • scripts/scr_unit_traits/scr_unit_traits.gml (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • scripts/scr_load/scr_load.gml
  • scripts/scr_initialize_custom/scr_initialize_custom.gml
🧰 Additional context used
🪛 Biome (1.9.4)
datafiles/data/traits.json

[error] 946-946: Expected a property but instead found '// Slight buff to health, as clear mind helps to stay healthy in some cases'.

Expected a property here.

(parse)


[error] 947-947: expected , but instead found "technology"

Remove "technology"

(parse)


[error] 947-947: Expected a property but instead found '// Also helps with some boring tasks, I think?'.

Expected a property here.

(parse)


[error] 948-948: expected , but instead found "display_name"

Remove "display_name"

(parse)


[error] 951-951: Expected a property but instead found '// IT IS THE BANEBLAAADE!!! - Captain Diomedes, DoW 2 Retribution'.

Expected a property here.

(parse)


[error] 952-952: expected , but instead found "wisdom"

Remove "wisdom"

(parse)


[error] 954-954: Expected a property but instead found '// Being bonkers can sometimes be damaging to one's health, I think..?'.

Expected a property here.

(parse)


[error] 955-955: expected , but instead found "display_name"

Remove "display_name"

(parse)


[error] 958-958: expected , but instead found // "crazy": {

Remove // "crazy": {

(parse)

🔇 Additional comments (7)
scripts/__init_global/__init_global.gml (1)

8-9: By the Omnissiah's grace, the initialization sequence has been optimized!

The strategic placement of the marine traits initialization in __init_global() ensures proper sanctification of the global trait struct before its first invocation, thus preventing the reported crash. This is a more appropriate location than the previous implementations in scr_initialize_custom() and scr_load().

scripts/scr_json_functions/scr_json_functions.gml (4)

6-6: Commendable variable declaration, Acolyte.
By the Omnissiah, initializing file_buffer here is a clean approach to ensure clarity in the function’s scope.


14-15: Error checking pleases the Machine God.
Verifying buffer_load success ensures no silent corruptions in the Omnissiah’s data.


26-29: Laudable resource cleanup, O Adept.
Ensuring the buffer is deleted in a finally block averts memory leaks and pleases the Machine Spirit.


31-31: No further scrutiny warranted.
The bracket is simply concluding this holy function.

datafiles/data/traits.json (1)

958-973: Commented-out traits disrupt the JSON litany.
These lines with // raise parse errors if included. Remove or properly format them if these traits remain part of your vision.

Do you wish to preserve these concepts? If so, refactor them into valid JSON or house them in a separate data scripture.

🧰 Tools
🪛 Biome (1.9.4)

[error] 958-958: expected , but instead found // "crazy": {

Remove // "crazy": {

(parse)

scripts/scr_unit_traits/scr_unit_traits.gml (1)

2-2: Blessed conversion to external data.
Loading traits from JSON fosters modular updates and decreases future code churn.

@EttyKitty EttyKitty added PR: Fix This is a fix for a bug PR: Feature Adds something new labels Feb 24, 2025
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8a367ee and 0e94fa7.

📒 Files selected for processing (5)
  • scripts/__init_global/__init_global.gml (1 hunks)
  • scripts/scr_initialize_custom/scr_initialize_custom.gml (1 hunks)
  • scripts/scr_json_functions/scr_json_functions.gml (1 hunks)
  • scripts/scr_load/scr_load.gml (1 hunks)
  • scripts/scr_unit_traits/scr_unit_traits.gml (1 hunks)
🔇 Additional comments (8)
scripts/__init_global/__init_global.gml (1)

8-9: By the Omnissiah's grace, the initialization sequence is optimal!

The initialization of marine traits after setting global defaults follows the sacred order of operations.

scripts/scr_load/scr_load.gml (1)

348-349:

✅ Verification successful

Praise be to the Machine Spirit! The initialization timing has been optimized.

The traits are now initialized at compile time through the sacred pragma directive, preventing the crash issue. The TODO comment correctly documents the requirement to re-enable this initialization when modding support is implemented.

Run the following script to verify that traits are initialized only once:


🏁 Script executed:

#!/bin/bash
# Description: Verify that traits are initialized only at compile time and not during loading.

# Test: Search for all calls to initialize_marine_traits(). Expect: Only one call in __init_global.gml
rg -A 5 $'initialize_marine_traits'

Length of output: 1505


Exalt the Machine Spirit!

The sacred logs have been consulted, and the initialization ritual of marine traits is indeed invoked solely within scripts/__init_global/__init_global.gml. The commented incantations in both scripts/scr_load/scr_load.gml and scripts/scr_initialize_custom/scr_initialize_custom.gml are proper vestiges preserved for the foretold arrival of modding rites. This confirms that the compile-time initialization is executed correctly, forestalling any runtime anomalies while the TODO reminder dutifully notes the future need for re-enabling trait initialization when modding support is realized.

scripts/scr_unit_traits/scr_unit_traits.gml (1)

1-2: Admirable usage of external trait data.

By the Omnissiah’s grace, the code calls upon json_to_gamemaker to bestow dynamic traits upon your Marines. Verify that the traits.json path is correct and present in all distributions, lest the Machine Spirits grow resentful.

scripts/scr_json_functions/scr_json_functions.gml (5)

6-6: Commendable explicit declaration of file buffer.

Defining file_buffer = undefined; upholds clarity. The mortal technomat will not confuse the Omnissiah, and the code is poised to handle buffer creation consistently.


12-15: Excellent error handling via buffer load and exception.

Ensuring a -1 check with a thrown exception protects the code from mishaps when the holy data script refuses to reveal itself. The Machine Spirits are appeased.


18-20: Beneficial debug messaging and direct parsing.

The _json_string reading and logging fosters transparency, aiding in diagnosing anomalies during the trait rites of initialization. The direct _func call is likewise efficient.


26-29: Proper resource cleanup in the final block.

The buffer_delete invocation in finally is a sanctified best practice: no memory shrine is left unguarded. This is essential for the faithful stewardship of machine memory.


31-31: Neatly closed function scope.

The final brace with the structured try-catch-finally block completes the functionality in an organized manner, ensuring the entire chain of code devotion remains pure.

@EttyKitty EttyKitty merged commit 7bfb6b3 into Adeptus-Dominus:main Feb 24, 2025
4 checks passed
@EttyKitty EttyKitty deleted the bugfix/trait-init branch February 24, 2025 22:05
@coderabbitai coderabbitai bot mentioned this pull request Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Feature Adds something new PR: Fix This is a fix for a bug PR: JSON Edits to external JSON files PR: Major Coding Big enough to possibly clash with other PRs PR: Refactor Rewriting/restructuring code, while keeping general behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants