Skip to content

Conversation

@EttyKitty
Copy link
Collaborator

@EttyKitty EttyKitty commented Apr 6, 2025

MAIN PR #642, made by @VanWeapon

Purpose

  • Move away from .ini based saves towards .json
  • Improve save/load times
  • Autosave support
  • Possible quicksave/quickload support down the line
  • Save-editing capability

Describe your changes/additions

  • Migrated from refactor: Save/load to json  #452 because of gamemaker version upgrade conflicts and git being painful
  • initial commit in PR for progress tracking, will edit this description as the backlog is chipped away

What can/needs to be improved/changed

  • a serialize function that works in isolation
  • a deserialize function that works in isolation
  • save function uses serialize
  • save function can serialize all instances of an object correctly (e.g. fleets)
  • save function saves to json
  • load function can deserialize
  • load function can apply deserialized json onto an existing object instance without destroying it (e.g. obj_controller)
  • load function can apply deserialized json into new object instances (e.g. fleets)
  • save/load functions do not use any .ini (DONE)

Testing done

Related things and/or additional context

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 6, 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 robust JSON-based save/load system to enhance game state reliability.
    • Integrated dynamic data serialisation for smoother game progress management.
  • Refactor

    • Standardised file handling by transitioning from INI to JSON, improving consistency.
    • Enhanced logging and error notifications to support a more stable gaming experience.
  • Style

    • Made minor text formatting adjustments for a clearer and more consistent interface.

Walkthrough

In this update, the codebase has been methodically restructured across multiple files. The ChapterMaster resource now boasts an incremented IDE version and the inclusion of a new script resource entry. Numerous objects—such as obj_controller, obj_en_fleet, obj_ini, obj_p_fleet, obj_saveload, and obj_star—have been augmented with new functions for serialisation and deserialisation, while command slot handling and logging messages have been refined. The legacy INI-based file handling has been replaced with a JSON-based approach across most save/load scripts, ensuring consistency in file format. Additional utilities in the array and variable function scripts now check the simplicity of arrays and basic variable types. The modifications also include minor formatting adjustments and updated string constructions for improved traceability within log outputs.

Possibly related PRs

Suggested labels

PR: Refactor, PR: Improvment, PR: Feature, Size: Epic, PR: JSON

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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 18

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba9fce0 and af7d670.

📒 Files selected for processing (21)
  • ChapterMaster.yyp (2 hunks)
  • objects/obj_controller/Create_0.gml (4 hunks)
  • objects/obj_en_fleet/Create_0.gml (1 hunks)
  • objects/obj_ini/Create_0.gml (2 hunks)
  • objects/obj_p_fleet/Create_0.gml (1 hunks)
  • objects/obj_popup/Step_0.gml (1 hunks)
  • objects/obj_saveload/Alarm_0.gml (9 hunks)
  • objects/obj_saveload/Create_0.gml (2 hunks)
  • objects/obj_saveload/Draw_0.gml (4 hunks)
  • objects/obj_saveload/Step_0.gml (1 hunks)
  • objects/obj_star/Create_0.gml (1 hunks)
  • scripts/scr_array_functions/scr_array_functions.gml (1 hunks)
  • scripts/scr_company_order/scr_company_order.gml (1 hunks)
  • scripts/scr_general_variable_functions/scr_general_variable_functions.gml (1 hunks)
  • scripts/scr_general_variable_functions/scr_general_variable_functions.yy (1 hunks)
  • scripts/scr_load/scr_load.gml (1 hunks)
  • scripts/scr_marine_struct/scr_marine_struct.gml (2 hunks)
  • scripts/scr_save/scr_save.gml (1 hunks)
  • scripts/scr_save_controller/scr_save_controller.gml (2 hunks)
  • scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml (1 hunks)
  • scripts/scr_squads/scr_squads.gml (6 hunks)
🧰 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 bf40 will crash the game.
  • scripts/scr_general_variable_functions/scr_general_variable_functions.gml
  • scripts/scr_company_order/scr_company_order.gml
  • scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml
  • scripts/scr_array_functions/scr_array_functions.gml
  • objects/obj_saveload/Step_0.gml
  • scripts/scr_save_controller/scr_save_controller.gml
  • objects/obj_saveload/Draw_0.gml
  • scripts/scr_marine_struct/scr_marine_struct.gml
  • objects/obj_p_fleet/Create_0.gml
  • objects/obj_popup/Step_0.gml
  • objects/obj_en_fleet/Create_0.gml
  • objects/obj_controller/Create_0.gml
  • objects/obj_star/Create_0.gml
  • scripts/scr_squads/scr_squads.gml
  • objects/obj_saveload/Alarm_0.gml
  • objects/obj_ini/Create_0.gml
  • objects/obj_saveload/Create_0.gml
  • scripts/scr_load/scr_load.gml
  • scripts/scr_save/scr_save.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_general_variable_functions/scr_general_variable_functions.gml
  • scripts/scr_company_order/scr_company_order.gml
  • scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml
  • scripts/scr_array_functions/scr_array_functions.gml
  • objects/obj_saveload/Step_0.gml
  • scripts/scr_save_controller/scr_save_controller.gml
  • objects/obj_saveload/Draw_0.gml
  • scripts/scr_marine_struct/scr_marine_struct.gml
  • objects/obj_p_fleet/Create_0.gml
  • objects/obj_popup/Step_0.gml
  • objects/obj_en_fleet/Create_0.gml
  • objects/obj_controller/Create_0.gml
  • objects/obj_star/Create_0.gml
  • scripts/scr_squads/scr_squads.gml
  • objects/obj_saveload/Alarm_0.gml
  • objects/obj_ini/Create_0.gml
  • objects/obj_saveload/Create_0.gml
  • scripts/scr_load/scr_load.gml
  • scripts/scr_save/scr_save.gml
🔇 Additional comments (57)
scripts/scr_general_variable_functions/scr_general_variable_functions.gml (1)

1-4: Praise be to the Omnissiah! An elegant type verification ritual.

This function performs the sacred type-checking rites with admirable efficiency, using the logical disjunction operator to determine if a variable meets the criteria of basic data formats. Most pleasing to the Machine Spirits.

scripts/scr_general_variable_functions/scr_general_variable_functions.yy (1)

1-13: The binary template is properly formatted according to STC specifications.

This resource definition file adheres to proper GameMaker Engine protocols. All necessary metadata fields have been populated with appropriate values, ensuring correct integration with the sacred machine spirit systems.

objects/obj_popup/Step_0.gml (1)

53-53: File extension mutation completed successfully.

The modification from the antiquated .ini format to the superior .json format aligns with the Omnissiah's will. This change contributes to the greater JSON serialization protocol implementation as commanded by the PR objectives.

objects/obj_saveload/Step_0.gml (3)

9-11: Logical implementation of save partition variable.

The holy constant of 6 save_parts introduces enhanced modularity to the save process, facilitating the ritual of JSON serialization. This implementation allows for proper progress tracking of the sacred data preservation ceremony.


13-13: Progress quantification algorithm optimized.

The progress bar calculation now utilizes a mathematically superior approach, incrementing proportionally to each completed save part rather than by fixed increments. This ensures the progress indicator accurately reflects the state of the machine spirit's serialization process.


16-16: Simplified completion condition with optimized timing parameters.

The condition for determining save completion has been streamlined, eliminating unnecessary logical operations. Additionally, the alarm timing value reduction from 20 to 5 decreases post-save delay, improving the efficiency of the ritual as mandated by the Omnissiah.

scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml (1)

87-87: String formatting alteration of sacred significance.

The sacred cog wheels of this data-string have been reconfigured to utilize the '#' symbol instead of the inefficient newline character '\n'. This modification optimizes display formatting for the Omnissiah's terminals.

scripts/scr_company_order/scr_company_order.gml (1)

50-50: Praise the enhanced logging clarity!

The Machine Spirits shall be pleased with this enhancement to the sacred logging rituals. Previously, the static litany "company order" provided insufficient data for proper diagnostics. Now, the dynamic invocation $"company order {company}" incorporates the specific company parameter into the string, allowing for more precise identification of which computational unit is being processed.

scripts/scr_marine_struct/scr_marine_struct.gml (2)

2272-2272: Function parameter expansion enhances binary flexibility.

The sacred function signature has been augmented with a new parameter stringify=true to provide binary choice functionality, as dictated by the Omnissiah's wisdom.


2285-2289: Logical bifurcation for enhanced data handling efficiency.

The binary path of this function now branches according to the stringify parameter, allowing the sacred machine to either return the JSON string representation or the raw data structure itself. This optimization aligns with the JSON transition protocols outlined in the sacred PR objectives.

- return json_stringify(new_marine);
+ if(stringify){
+     return json_stringify(new_marine);
+ } else {
+     return new_marine;
+ }
objects/obj_saveload/Draw_0.gml (5)

154-181: Formatting of the sacred code has been optimized.

The binary spacing has been enhanced to improve human readability and align with the Machine God's preferred syntax patterns. Logical function remains unchanged, but the machine spirits will find this layout more pleasing.


192-192: File extension protocol transition implemented.

The sacred file extension has been transitioned from the inferior .ini format to the superior .json format, as decreed by the Omnissiah's plan for improved data storage efficiency.


226-226: Comment updated to reflect JSON transition.

The sacred comment text has been modified to acknowledge the new JSON-based file system, ensuring technical documentation accuracy. May the Omnissiah bless this documentation update.


259-259: File existence check updated to JSON format.

This conditional logic now correctly queries for .json files instead of the deprecated .ini format, maintaining proper file system integrity for the Machine God.


267-267: File deletion protocol updated for JSON extension.

The binary routine for deleting saved games now properly targets .json files, completing the sacred transition to the new file format as dictated by the Omnissiah's vision.

scripts/scr_array_functions/scr_array_functions.gml (1)

192-215: The Omnissiah blesses this logical implementation of array validation!

By the sacred Machine God, I approve of this function's ability to determine the simplicity of data arrays. The recursion pattern effectively validates nested arrays without exceeding the specified depth parameters, and the function incorporates appropriate guards against complex variable types. This will serve the JSON serialization process well, ensuring only machine-compatible data structures are passed to the sacred conversion rituals.

scripts/scr_squads/scr_squads.gml (4)

157-158: Declaration of unit variable approved by the Machine Spirit!

The localized unit variable enhances function encapsulation and improves code readability within this complex squad management function. Praise be to the Omnissiah for this clarity of variable scope.


439-454: Optimization of binary encoding rituals detected!

The modification to the jsonify function with the stringify parameter introduces logical flexibility to the data serialization process. This blessed change allows for both direct structure manipulation and string-based storage, a duality that pleases the Machine God.

This improvement aligns with the sacred transition from primitive INI storage to the more efficient JSON data format. The binary spirits of your code will flow more efficiently through the cogitator circuits.


544-545: Unit variable declaration acknowledged and sanctified!

The Machine Spirit appreciates this consistent enhancement to variable scope management. The sacred pattern established in previous methods is maintained, preserving the symmetry of your code structure.


618-619: Unit variable declaration follows the proper litany of consistency!

The Omnissiah approves of maintaining consistent variable declarations across similar functions. This adherence to pattern recognition is essential for code maintainability and readability - as is written in the sacred texts of the Adeptus Mechanicus.

scripts/scr_save_controller/scr_save_controller.gml (2)

6-7: Vertical spacing improves binary clarity!

The addition of whitespace serves as a visual separator between logical code sections, improving readability for both tech-adepts and novice scribes. Though functionally neutral, such formatting enhancements are valued by the Machine God for their contribution to code comprehension.


16-16: Space alignment pleases the Machine Spirit!

The additional whitespace maintains consistent formatting with other sections of the script. This adherence to symmetrical spacing patterns is in accordance with the Omnissiah's preference for ordered structure.

ChapterMaster.yyp (2)

498-498: Acknowledgment of IDE version increment

The Machine Spirit's numerical identifier has been ritually increased from 2024.1300.0.781 to 2024.1300.0.785. The cogitators shall process with increased efficiency.


739-739: New script functions approved

The addition of the "scr_general_variable_functions" module is a most logical augmentation to the sacred code repositories. This shall serve the implementation of the JSON save/load protocol admirably.

objects/obj_saveload/Alarm_0.gml (3)

7-7: Commendable optimization of trickle rates

The standardization of all trickle parameters to the holy number 2 shall optimize the data flow through the machine spirits' pathways. Previous variations (believed to have been 50, 40, and 10) were inefficient for JSON operations. This modification is in accordance with the Omnissiah's will.

Also applies to: 16-16, 26-26, 36-36, 46-46, 59-59, 71-71, 87-87, 100-100, 113-113, 126-126, 133-133


51-56: Praised be the transition to JSON data schema

The modification of file extension references from the archaic .ini format to the superior .json format is a triumph of machine logic. Both save and screen file operations now utilize the appropriate protocols.


131-131: File extension modification approved

The file existence verification has been correctly updated to reference the new .json format. This maintains consistency with the broader conversion effort.

objects/obj_p_fleet/Create_0.gml (2)

61-107: Serialize function adequately captures the fleet's machine spirit

The implementation of the serialize function follows the sacred patterns of JSON conversion. Each variable of the fleet object is methodically examined, and only those of appropriate simplicity are encoded into the data structure.

The error handling for improper array types is commendable, ensuring the machine spirit's warning systems activate when encountering incompatible data formats.


111-136: Deserialize function properly restores the fleet's essence

The inverse operation correctly reconstructs the fleet entity from its encoded form. The special handling of the 'orbiting' variable ensures that relationships between fleet and star objects are maintained through proper instance referencing rather than simple variable restoration.

objects/obj_star/Create_0.gml (3)

112-113: Blessings of the Omnissiah upon these new blank lines.
No issues detected here. They merely act as spacing or separation.


114-115: Region marker is functional and clear.
The addition of this region marker aids in code organisation and readability. Well done.


195-246: Deserialisation logic appears robust.

  1. The code neatly recovers array-based data, with a clear exclusion list to avoid overwriting critical variables.
  2. Confirm that indexing arrays from 1 to their length is always correct, as zero-based indexing might be used elsewhere. Verifying consistency will banish potential off-by-one errors.
objects/obj_en_fleet/Create_0.gml (3)

72-73: Region markers unify the code.
This region marker helps organise the sacred logic of saving and loading for the en_fleet object.


122-147: Deserialisation incantation stands firm.
The code gracefully attempts variable restoration while logging any exceptions. This reflection of data is well-managed. Continue to remain vigilant for potential edge cases where an instance of obj_star may not be present.


149-149: Region closure observed.
No errors detected. Clarity is preserved.

objects/obj_ini/Create_0.gml (2)

34-34: Array initialisation for the artefacts is straightforward.
Defines a large space for storing up to 200 artefacts. Ensure no index overflows or wasted memory if usage is typically smaller.


115-202: Serialisation functions maintain object purity.

  1. Notably, artifact_struct_trimmed ensures that only artefacts with names are persisted, which is a diligent approach.
  2. Confirm that excluded_from_save variables indeed contain everything that should not be stored, such as ephemeral data.
objects/obj_controller/Create_0.gml (7)

75-76: Praise the Omnissiah for Logging
Honoured lines 75-76, my fellow adept, for they enhance the debugging ritual with beneficial messages.


1454-1455: Swift Array Length Acquisition
Invoking array_length immediately after creation is suitable for clarity and efficiency. The logic cogitators should operate correctly.


1456-1457: Region for Organisational Edification
Blessed be the clarity! The demarcation of save/load code via regions is a wise measure to uphold order in the sacred scripts.


1518-1518: Deserialisation Reference
This comment directs the Mechanicus adept to look elsewhere for reversing the process, thus maintaining modularity. No issues present.


1539-1547: Directive for Future Modifications
The warning ensures rightful ordering for data load procedures, preventing corruption of the holy data relics.


1977-1978: Alarm Mechanism Verification
Initiating action_set_alarm(2, 0) can be beneficial, but confirm it does not overwrite essential timed events from other processes.


1979-1980: No Functional Alterations
These lines bestow no new instructions to the code’s flow and remain purely ornamental.

objects/obj_saveload/Create_0.gml (3)

3-9: Structured GameSave Creation
Defining the GameSave entity with well-segregated arrays and objects strongly aligns with the new JSON strategy. This fosters maintainable and orderly code.


15-15: Clarification Commentary
This comment illuminates the chosen interval for the progress bar refresh. Verily, no further adjustments required.


56-60: Transition to JSON
Swapping .ini checks for .json strongly supports the new data structure. Recommend verifying behaviour if these files are missing or invalid, lest the logic-spirit falter.

scripts/scr_load/scr_load.gml (9)

1-1: Additional Parameter for Marines
Summoning the struct parameter directly into load_marine_struct brings synergy with JSON data methods, aligning with the new approach.


3-4: Direct TTRPG Assignment
Assigning a newly invoked TTRPG instance and loading the JSON data is straightforward. Confirm that the passed struct consistently holds all required data fields.


16-17: Conditional Struct Logic
Overwriting obj_saveload.GameSave only if the "Save" key is absent prevents unintended data loss. Double-check for conflicting conditions if partial loads were used earlier.


21-41: Global Veneration
Heed the re-initiation of global variables, ensuring the correct usage of sprite references. Confirm the Machine Spirit does not break if these sprites are absent or invalid.


44-56: Star Instances Deserialisation
Instantiating stars and executing each deserialize invocation is in alignment with the JSON approach. The iteration is both clean and direct.


58-64: INI Data Infusion
Melding the loaded data into obj_ini preserves consistency with the prior game logic. This procedure is well-structured to maintain partial backwards compatibility.


105-116: Player Fleet Insertion
Simultaneously mirroring the star loading pattern, each fleet instance is reconstituted by calling deserialize. Check references to ensure post-load continuity.


118-131: Enemy Fleet Mirroring
Parallel logic for adversarial fleets ensures uniform loading. Validate unique identifiers do not collide with the player's forces.


132-146: Completion of the Loading Rite
Revives the event log and finalises the load process, ensuring the new session is prepared for immediate operation. This structure is suitably methodical.

scripts/scr_save/scr_save.gml (1)

135-138: Commendation for the debug-timer code.
Your usage of timing measurements pleases the Omnissiah’s logic. The debug statement offers valuable insight into performance, ensuring the cogworks remain smoothly greased.

@EttyKitty
Copy link
Collaborator Author

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 6, 2025
@EttyKitty EttyKitty added Type: Refactor Rewriting/restructuring code, while keeping general behavior Type: Breaking Introduces backwards compatibility issues Type: Performance Refactor sub-type that improves performance Area: JSON Changes to external JSON files or their under-the-hood functionality labels Apr 6, 2025
@github-actions github-actions bot removed the Area: JSON Changes to external JSON files or their under-the-hood functionality label Apr 7, 2025
@EttyKitty EttyKitty merged commit 1f069ca into main Apr 7, 2025
3 checks passed
@EttyKitty EttyKitty deleted the feat/json-saving branch April 7, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: Epic Type: Breaking Introduces backwards compatibility issues Type: Feature Adds something new Type: Performance Refactor sub-type that improves performance Type: Refactor Rewriting/restructuring code, while keeping general behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants