Skip to content

refactor: remove redundant marine_number references - #1437

Open
OH296 wants to merge 5 commits into
Adeptus-Dominus:mainfrom
OH296:remove_marine_number
Open

refactor: remove redundant marine_number references#1437
OH296 wants to merge 5 commits into
Adeptus-Dominus:mainfrom
OH296:remove_marine_number

Conversation

@OH296

@OH296 OH296 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary by cubic

Removes redundant marine_number usage and shifts member references to unit structs to decouple logic from company indices. Introduces centralized index maintenance via normalise_marine_numbers and cleans up stale entries during tally and deserialization.

  • Deserialization converts squad members to unit structs and prunes undefined entries in a single reverse pass; UnitSquad.member_loop now uses the stored struct directly.
  • Adds normalise_marine_numbers(company, start_index, length) and calls it after deletions/moves; tally_marines now removes holes and normalizes while counting only Astartes.
  • Drops marine_id arrays and all references from roster, unit panels, and weapon stack helpers; screenshot filenames no longer include the marine id.
  • Artifact bearer API now expects a unit struct; update any callers still passing [company, marine_number].
  • Required: in scr_company_order, replace the bare normalise_marine_numbers() call with normalise_marine_numbers(co, 0) (and length if needed) to avoid missing arguments.

Written for commit 1688998. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added Size: Small Type: Refactor Rewriting/restructuring code, while keeping general behavior labels Aug 12, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 13 files

Confidence score: 2/5

  • In scripts/scr_company_order/scr_company_order.gml, normalise_marine_numbers() is invoked without the required company and start_index inputs, which can pass undefined into downstream length/index logic and cause incorrect ordering or runtime failures in company processing — pass the expected arguments at the call site (or add defensive defaults/guards in the helper).
  • In scripts/ArtifactStruct/ArtifactStruct.gml, the set_bearer @param doc still advertises {Array|undefined} even though the value is now a unit struct, which can mislead future callers and reviewers into using the old shape — update the annotation to the current struct type (TTRPG_stats/struct) to prevent integration mistakes.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/ArtifactStruct/ArtifactStruct.gml">

<violation number="1" location="scripts/ArtifactStruct/ArtifactStruct.gml:561">
P3: The @param type annotation on set_bearer still reads `{Array|undefined}`, but this PR converts the bearer reference from a `[company, marine_number]` array to a unit Struct (TTRPG_stats). The value is now a struct (callers pass `self`, and from_json sets `fetch_unit_uid(...)`), so the Array annotation is stale and contradicts the new comment text. Update it to `{Struct|undefined}` (or `{TTRPG_stats|undefined}`), mirroring the get_bearer @returns change to `{struct|undefined}`.</violation>
</file>

<file name="scripts/scr_company_order/scr_company_order.gml">

<violation number="1" location="scripts/scr_company_order/scr_company_order.gml:145">
P1: `normalise_marine_numbers()` is called with no arguments in `scr_company_order`, but the helper requires `company` and `start_index`. Missing params become `undefined`, so `company_length(undefined)` reads `obj_ini.TTRPG[undefined]` (runtime error caught by the try/catch, or renumbering of the wrong company), and the reordered company's `marine_number` fields are never updated. Pass the company and a start index of 0: `normalise_marine_numbers(co, 0);`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

for (var i = 0; i < array_length(TTRPG[co]); i++) {
TTRPG[co][i].marine_number = i;
}
normalise_marine_numbers();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: normalise_marine_numbers() is called with no arguments in scr_company_order, but the helper requires company and start_index. Missing params become undefined, so company_length(undefined) reads obj_ini.TTRPG[undefined] (runtime error caught by the try/catch, or renumbering of the wrong company), and the reordered company's marine_number fields are never updated. Pass the company and a start index of 0: normalise_marine_numbers(co, 0);.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/scr_company_order/scr_company_order.gml, line 145:

<comment>`normalise_marine_numbers()` is called with no arguments in `scr_company_order`, but the helper requires `company` and `start_index`. Missing params become `undefined`, so `company_length(undefined)` reads `obj_ini.TTRPG[undefined]` (runtime error caught by the try/catch, or renumbering of the wrong company), and the reordered company's `marine_number` fields are never updated. Pass the company and a start index of 0: `normalise_marine_numbers(co, 0);`.</comment>

<file context>
@@ -126,9 +142,7 @@ function scr_company_order(company) {
-        for (var i = 0; i < array_length(TTRPG[co]); i++) {
-            TTRPG[co][i].marine_number = i;
-        }
+        normalise_marine_numbers();
     } catch (_exception) {
         ERROR_HANDLER.handle_exception(_exception);
</file context>
Suggested change
normalise_marine_numbers();
normalise_marine_numbers(co, 0);


/// @desc Sets the bearer reference.
/// @param {Array|undefined} value [company, marine_number] or undefined.
/// @param {Array|undefined} value TTRPG_stats instance or undefined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: The @PARAM type annotation on set_bearer still reads {Array|undefined}, but this PR converts the bearer reference from a [company, marine_number] array to a unit Struct (TTRPG_stats). The value is now a struct (callers pass self, and from_json sets fetch_unit_uid(...)), so the Array annotation is stale and contradicts the new comment text. Update it to {Struct|undefined} (or {TTRPG_stats|undefined}), mirroring the get_bearer @returns change to {struct|undefined}.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/ArtifactStruct/ArtifactStruct.gml, line 561:

<comment>The @param type annotation on set_bearer still reads `{Array|undefined}`, but this PR converts the bearer reference from a `[company, marine_number]` array to a unit Struct (TTRPG_stats). The value is now a struct (callers pass `self`, and from_json sets `fetch_unit_uid(...)`), so the Array annotation is stale and contradicts the new comment text. Update it to `{Struct|undefined}` (or `{TTRPG_stats|undefined}`), mirroring the get_bearer @returns change to `{struct|undefined}`.</comment>

<file context>
@@ -558,7 +558,7 @@ function ArtifactStruct(_type_name = "", _tags = [], _identification_timer = 0,
 
     /// @desc Sets the bearer reference.
-    /// @param {Array|undefined} value [company, marine_number] or undefined.
+    /// @param {Array|undefined} value TTRPG_stats instance or undefined.
     static set_bearer = function(value) {
         __bearer = value;
</file context>
Suggested change
/// @param {Array|undefined} value TTRPG_stats instance or undefined.
/// @param {Struct|undefined} value TTRPG_stats instance or undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: Small Type: Refactor Rewriting/restructuring code, while keeping general behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant