Repository navigation
Introduce central equipment modifier resolver and structured adjustment UI/schema - #37
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3b5e97d89
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| template.enabled = gcsMod.disabled !== true; | ||
| template.level = 1; | ||
| template.cost_factor = /cf$/i.test(rawCostStr) ? Number.parseFloat(rawCostStr) || 0 : 0; | ||
| template.cost_adjustment = rawCostStr.replace("*", "x") || "0 CF"; |
There was a problem hiding this comment.
Convert bare GCS base costs to CF expressions
When GCS supplies a numeric cost such as "1" with cost_type: "to_base_cost", this now stores the expression unchanged. The resolver parses it as a flat addition, but the base-cost stage accepts only CFs and multipliers, so it reports unsupported_operation and leaves the equipment cost unchanged. The previous importer explicitly converted this input to +1 CF; preserve that conversion for base-cost imports.
Useful? React with 👍 / 👎.
| if (target === "cost" && stage === "base") return ["cost_factor", "multiply"].includes(operation); | ||
| if (target === "weight" && stage === "original") return ["add", "percent"].includes(operation); | ||
| if (target === "weight") return ["add", "multiply", "percent_multiplier"].includes(operation); |
There was a problem hiding this comment.
Infer compatible stages for legacy adjustments
For legacy records without structured stage data, normalization assigns both adjustments to base; these checks then reject previously supported expressions such as cost -10%/+50 and weight -10%. Existing equipment modifiers using the old sheet therefore silently stop affecting the displayed resolved values after upgrading. Legacy expressions need an operation-compatible inferred stage rather than all defaulting to base.
Useful? React with 👍 / 👎.
| const costExpression = formData["system.cost_adjustment_data.expression"]; | ||
| const weightExpression = formData["system.weight_adjustment_data.expression"]; | ||
| formData["system.adjustment_schema"] = 1; | ||
| if (costExpression !== undefined) formData["system.cost_adjustment"] = costExpression; |
There was a problem hiding this comment.
Synchronize cost_factor when saving CF expressions
When a modifier is edited to a structured CF expression such as +1 CF, saving updates cost_adjustment but leaves the legacy cost_factor at its previous value, commonly zero. The equipment-modifier browser still builds its CF range filter from system.cost_factor, so newly edited modifiers are misclassified or omitted from nonzero CF searches even though their calculations use the new value.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5fbf5cf1c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| continue; | ||
| } | ||
| if (parsed.operation === "cost_factor") totalFactor += parsed.value * scale; | ||
| if (parsed.operation === "multiply") totalFactor += ((parsed.value * scale) - 1); |
There was a problem hiding this comment.
Scale the multiplier's CF delta rather than its factor
When a base-cost multiplier is marked per-level or per-weight and its scale exceeds 1, this computes (N * scale) - 1 instead of scaling its documented CF equivalent (N - 1) * scale. For example, x2 at level 2 becomes x4, although two +1 CF contributions should produce x3; imported GCS multipliers using either scaling flag therefore overstate equipment costs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7587707003
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| foundry.utils.getProperty(effect, "flags.gum.originItemId") === item.id | ||
| && foundry.utils.getProperty(effect, "flags.gum.source") === EQUIPMENT_GRANTED_EFFECT_SOURCE | ||
| ); | ||
| if ((grants.length > 0) !== (existing.length > 0)) await syncEquipmentModifierGrantedEffects(item); |
There was a problem hiding this comment.
Reconcile the actual granted-effect set
When an item expects multiple grants but only one generated effect remains—for example after one effect was manually deleted or a previous synchronization partially failed—both sides of this boolean comparison are still true, so startup reconciliation does nothing. The same occurs when the remaining effect belongs to an obsolete grant. Compare the expected grant/effect identities against the generated ActiveEffects and resynchronize whenever the sets differ.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2bd26f54c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| console.warn(`GUM | Efeito de ataque "${grant.label}" não possui ações de rolagem ou combate compatíveis.`); | ||
| continue; | ||
| } | ||
| await applySingleEffect(effectItem, targets, { |
There was a problem hiding this comment.
Make lifecycle-bound granted effects persistent
When a wearer or source-attack grant references an ordinary Effect item, this call preserves that Effect's duration; the default Effect template is combat-bound for one round. applySingleEffect therefore creates the grant disabled while outside combat and lets it expire after a round once combat starts, and no hook recreates it while the equipment remains equipped or active. Override the applied duration for lifecycle-managed grants so their presence is governed by while_possessed/while_carried/while_equipped/while_active, rather than by the reusable Effect's transient duration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3963aa9a47
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| item.system.melee_attacks = resolution.meleeAttacks; | ||
| item.system.ranged_attacks = resolution.rangedAttacks; | ||
| for (const [path, value] of Object.entries(resolution.properties)) { | ||
| if (value !== undefined) item.system[path] = value; |
There was a problem hiding this comment.
Keep resolved equipment data out of editable system fields
When an actor-owned equipment item has an attack or property feature, these assignments replace the values exposed through item.system with resolved values. The item sheet binds its editable attack and property inputs to that same system object, so a subsequent sheet submission—such as editing an unrelated field—can persist modified attacks/properties (including generated attacks) as the new base data. Additive features then accumulate on later preparations, and generated attacks remain after their modifier is removed; keep the resolution in separate derived fields or populate editable inputs from _source.system.
Useful? React with 👍 / 👎.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a69db1865a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await this.item.update({ | ||
| [`system.features_data.${id}.effect_uuid`]: effect.uuid, | ||
| [`system.features_data.${id}.effect_name`]: effect.name, | ||
| [`system.features_data.${id}.effect_img`]: effect.img | ||
| }); |
There was a problem hiding this comment.
Preserve unsaved feature edits before linking an effect
When a user changes this feature's domain, lifecycle, or attack filters and then selects a different Effect before the sheet form is submitted, this direct document update persists only the three link fields and triggers a sheet rerender from stored data, discarding the other edits still present only in the form. Submit or merge the current form data before updating the effect link.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f56c1de519
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try { | ||
| const actionIds = grant.domain === "source_attack" | ||
| ? getEffectActions(effectItem.system) | ||
| .filter(action => ["roll_modifier", "skill_modifier", "combat_modifier"].includes(action.type)) |
There was a problem hiding this comment.
Reject skill-only actions from source-attack grants
When a source_attack grant links an Effect whose only compatible-looking action is skill_modifier, this filter installs it, but the effect can never apply: applySingleEffect emits skill modifiers with a skill context and skill_roll_only: true, while the source-attack scope requires the rolled item to be the originating equipment and requires an attack. Consequently, both the roll prompt and derived-NH paths reject the entry, leaving the configured grant silently inert; either exclude skill_modifier here or translate it into an attack-compatible modifier.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d5fc7e259
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| function applyFeatureValue(current, feature, scale, { formula = false } = {}) { | ||
| if (feature.operation === "set") return feature.value; |
There was a problem hiding this comment.
Honor per-level scaling for set features
When a numeric equipment, location-DR, or attack feature uses set and the author enables “Por nível do modificador,” this early return ignores the computed scale entirely. For example, setting RD to 2 per level on a level-3 modifier still produces RD 2 rather than a level-dependent result, even though the sheet exposes that checkbox for set operations. Apply the scale to numeric set values or prevent per-level configuration when set is selected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 313cce9c3b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const drLocationKeys = new Set([...Object.keys(drLocations), ...Object.keys(resolvedDrLocations)]); | ||
| context.drLocationRows = [...drLocationKeys].map(key => [key, drLocations[key] || {}]) |
There was a problem hiding this comment.
Keep derived DR locations out of editable rows
When an equipment_dr feature creates a location absent from the base item, this union renders that derived-only location as an editable row with an empty base value. Any later sheet submission calls _collectDRLocationsFromForm(), which converts the empty value to {base: 0} and persists it into system.dr_locations, so merely saving an unrelated edit mutates the base armor and leaves the location behind after the modifier is removed. Render modifier-only locations separately or exclude them when collecting the editable form.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd9e5e9c2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (uses.mode !== "charges" || uses.max <= 0) { | ||
| return { consumed: true, mode: "quantity", updates: { "system.quantity": Math.max(0, quantity - 1) }, uses }; |
There was a problem hiding this comment.
Keep zero-capacity charge items from consuming quantity
When an item explicitly uses uses_mode: "charges" but its resolved capacity is zero—because max_uses is unset, configured as zero, or reduced by a feature—this branch treats the action as legacy quantity consumption and deletes one whole unit. Since the sheet exposes charge mode independently of capacity, a zero-capacity charge item should report empty_charges; only quantity mode should decrement system.quantity.
Useful? React with 👍 / 👎.
| const base = numericValue(current) ?? 0; | ||
| if (feature.operation === "multiply") return base * scaled; |
There was a problem hiding this comment.
Prevent numeric operations from zeroing textual attack fields
When the sheet's offered multiply operation is selected for a textual attack property such as damage_formula, the current value (for example GdP) cannot be parsed numerically, so this fallback changes the base to zero and resolves GdP × 2 as damage formula 0. Textual equipment properties have a related failure where add/multiply silently do nothing or produce numeric data; restrict those paths to set or implement appropriate formula/text handling instead of coercing a nonnumeric current value to zero.
Useful? React with 👍 / 👎.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e67b8e2b77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <div class="form-grid-3"> | ||
| <label class="custom-checkbox"><input type="checkbox" name="system.features_data.{{feature.id}}.enabled" {{checked feature.enabled}}/><span>Ativa</span></label> | ||
| <div class="form-group"><label>Nome</label><input type="text" name="system.features_data.{{feature.id}}.label" value="{{feature.label}}"/></div> | ||
| <div class="form-group"><label>Tipo</label><select name="system.features_data.{{feature.id}}.type">{{selectOptions ../equipmentFeatureTypeOptions selected=feature.type valueAttr="id" labelAttr="label"}}</select></div> |
There was a problem hiding this comment.
Rerender when feature-shaping selections change
When an author changes the feature type, the type-specific editor remains based on the previously rendered value because GurpsItemSheet.defaultOptions does not enable submit-on-change and no change listener saves/rerenders this select. For example, changing the default equipment_property to granted_effect leaves the effect UUID/domain controls inaccessible until the entire sheet is closed and reopened; the create_attack attack-type selector similarly leaves the wrong melee/ranged fields visible. Persist the current form and rerender when these selections change.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b0cf33020
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const weaponPaths = { | ||
| weapon_bonus: "damage_formula", weapon_acc_bonus: "accuracy", weapon_scope_acc_bonus: "accuracy", | ||
| weapon_dr_divisor_bonus: "armor_divisor", weapon_min_st_bonus: "min_strength", weapon_recoil_bonus: "rcl", | ||
| weapon_bulk_bonus: "bulk" |
There was a problem hiding this comment.
Map imported Bulk bonuses to the runtime field
When GCS supplies a weapon_bulk_bonus, this creates an attack feature targeting bulk, but equipment ranged attacks store and consume that statistic as mag (the sheet, actor attack card, and roll context all read attack.mag). The resolver therefore adds an otherwise unused attack.bulk property, so the imported modifier has no visible or mechanical effect; map this feature to mag or migrate the equipment attack model consistently.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 74d64bea4e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| location: String(location).toLowerCase() === "all" ? "all" : String(location), | ||
| damage_type: !feature.specialization || String(feature.specialization).toLowerCase() === "all" ? "base" : feature.specialization, |
There was a problem hiding this comment.
Normalize imported GCS DR keys
When a GCS modifier targets identifiers such as skull or arm, or specializes in cut, this stores the raw GCS values. The actor preparation path only accepts system locations such as head/arm_l/arm_r, while typed DR uses keys such as cort, so these imported bonuses are ignored or placed under an unused damage type. Reuse the existing getGUMBodyLocationKeysForGCS() and getGCSDrKey() mappings when constructing these features.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0154f835c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <span class="equip-stat-tag">x{{this.system.quantity}}</span> | ||
| <span class="equip-stat-tag">{{this.system.total_weight}} kg</span> | ||
| {{#if this.system.dr}}<span class="equip-stat-tag shield-tag">RD {{this.system.dr}}</span>{{/if}} | ||
| {{#if (eq this.system.uses_mode "charges")}}<span class="equip-stat-tag" title="Cargas restantes">{{this.system.effectiveUsesRemaining}}/{{this.system.effectiveUsesMax}} cargas</span>{{/if}} |
There was a problem hiding this comment.
Show charge counts on every inventory card
When a charge-based item is carried, stored, or inside any container, its card still exposes the “Consumir / Usar” action but does not show the remaining charges; this badge was added only to equipmentInUseLoose, and a repo-wide search shows no equivalent rendering in the other inventory sections. Consumables are normally carried rather than equipped, so users cannot see their updated charge count after using them without opening the item sheet.
Useful? React with 👍 / 👎.
Motivation
Description
module/utils/equipment-resolution.mjsthat implementsparseEquipmentAdjustment,normalizeEquipmentModifierandresolveEquipment, with support for four stages (original,base,final_base,final), per-level and per-weight scaling, unit handling and deterministic calculation traces.module/apps/importers.jsto map GCS fields into the structured schema (adjustment_schema,cost_adjustment_data,weight_adjustment_data, etc.) while preserving legacy expressions.module/item/gurps-item-sheet.js,templates/items/item-sheet.hbs,template.json) to expose structured controls for equipment modifiers (enabled,level, cost/weight expression, stage and per-level/per-weight flags) and show resolved unit/extended totals.scripts/main.jsnow resolvesitem.system.equipmentResolutionand assignseffectiveCost/effectiveWeight, and the equipment modifier browser (module/apps/eqp-modifier-browser.js) clones and preserves structured modifier data when adding modifiers to items.docs/equipment-modifiers.mddescribing the implemented stage model, scaling rules and migration notes.tests/equipment-resolution.test.mjs,tests/equipment-modifier-layout.test.mjs,tests/equipment-modifier-import.test.mjs) and adjusttests/equipment-modifier-browser.test.mjsto expect the structured fields.Testing
equipment-resolution.test.mjs,equipment-modifier-layout.test.mjs,equipment-modifier-import.test.mjsand the updatedequipment-modifier-browser.test.mjs, all of which passed.Codex Task