refactor: remove redundant marine_number references - #1437
Conversation
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
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 requiredcompanyandstart_indexinputs, which can passundefinedinto 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, theset_bearer@paramdoc 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(); |
There was a problem hiding this comment.
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>
| 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. |
There was a problem hiding this comment.
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>
| /// @param {Array|undefined} value TTRPG_stats instance or undefined. | |
| /// @param {Struct|undefined} value TTRPG_stats instance or undefined. |
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.
UnitSquad.member_loopnow uses the stored struct directly.normalise_marine_numbers(company, start_index, length)and calls it after deletions/moves;tally_marinesnow removes holes and normalizes while counting only Astartes.marine_idarrays and all references from roster, unit panels, and weapon stack helpers; screenshot filenames no longer include the marine id.[company, marine_number].scr_company_order, replace the barenormalise_marine_numbers()call withnormalise_marine_numbers(co, 0)(and length if needed) to avoid missing arguments.Written for commit 1688998. Summary will update on new commits.