Skip to content

refactor(characters): unify auto-resolve and tracked resolution appliers#155

Merged
QMalcolm merged 1 commit into
mainfrom
qmalcolm--refactor-unify-resolution-appliers
Jul 21, 2026
Merged

refactor(characters): unify auto-resolve and tracked resolution appliers#155
QMalcolm merged 1 commit into
mainfrom
qmalcolm--refactor-unify-resolution-appliers

Conversation

@QMalcolm

@QMalcolm QMalcolm commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Closes #127.

What

characters.ex had two parallel families of choice-resolution appliers building identical decision maps: apply_auto_{selection,sub_choice,value} (used by auto_resolve_pending at generation) and track_{selection,sub_choice,value}_resolution (used by random_resolve_all for --random-resolve). The dispatching cond and the evaluate/find/recurse loop drivers were also copy-pasted.

How

  • The tracked versions are now the single implementation, renamed resolve_{selection,sub_choice,value}.
  • One shared loop driver resolve_all/5, parameterized on the two real differences:
    • a resolvability predicate (resolvable_at_level_1?/1 vs resolvable?/1)
    • a value-method fun for value progressions (rolled_value_method/1 always rolls, matching the old apply_auto_value; random_value_method/1 keeps the rolled-or-average coin flip)
  • auto_resolve_pending/2 is now resolve_all with the resolutions list discarded; its public return shape is unchanged.

Notes

The auto path now computes resolution records it discards (two concept_metadata lookups per selection) — cheaper than threading a "skip tracking" flag through the shared code.

No behavior change; existing tests pass unchanged (389 tests, credo and dialyzer clean).

Summary by Bito

  • Refactored character progression resolution logic into a unified `resolve_all` function to reduce code duplication.
  • Replaced hardcoded resolution methods with a flexible `value_method` callback, allowing for different resolution strategies (e.g., rolled vs. random).
  • Removed redundant `apply_auto_resolution` and its helper functions in favor of the new unified resolution pipeline.
  • Standardized resolution naming conventions by renaming `apply_tracked_resolution` and its helpers to `resolve_*`.

Closes #127.

characters.ex carried two parallel families of choice-resolution
appliers: apply_auto_{selection,sub_choice,value} used by
auto_resolve_pending at generation time, and
track_{selection,sub_choice,value}_resolution used by
random_resolve_all for the --random-resolve flag. Each pair built the
identical decision map, and the dispatching cond and the
evaluate/find/recurse loop drivers were copy-pasted. Any change to
decision shape had to be made twice.

The tracked versions are now the single implementation, renamed
resolve_{selection,sub_choice,value}. The two real differences between
the families are parameterized on the shared resolve_all/5 driver:

- a resolvability predicate (resolvable_at_level_1?/1 for generation,
  resolvable?/1 for resolve-all)
- a value-method fun for value progressions (rolled_value_method/1
  always rolls, matching the old apply_auto_value; random_value_method/1
  keeps the rolled-or-average coin flip)

auto_resolve_pending is now resolve_all with the resolutions list
discarded. The auto path computes resolution records it never uses
(two concept_metadata lookups per selection); this was deemed cheaper
than threading a "skip tracking" flag through the shared code.

Alternative considered and rejected: keeping apply_auto_* as thin
wrappers over the resolve_* functions. Since both call sites go through
the same dispatch cond, the wrappers would have added a layer with no
callers other than the shared driver.

No behavior change; existing tests pass unchanged.
@QMalcolm
QMalcolm merged commit f72abc3 into main Jul 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(characters): unify auto-resolve and tracked resolution appliers

1 participant