Skip to content

refactor: code quality improvements and utility modules#10

Open
VX1D wants to merge 10 commits into1srscx4:mainfrom
VX1D:refactor/code-quality
Open

refactor: code quality improvements and utility modules#10
VX1D wants to merge 10 commits into1srscx4:mainfrom
VX1D:refactor/code-quality

Conversation

@VX1D
Copy link
Copy Markdown

@VX1D VX1D commented Mar 7, 2026

Changes

New Utility Modules (modules/utils/)

Eight focused modules providing reusable functionality:

  • constants.lua - Centralized constants (suits, songs, limits) eliminating magic strings
  • joker_utils.lua - Joker lookup helpers (find_joker, has_joker, count_cards)
  • probability.lua - Odds calculation with roll_with_odds, get_probability_scale
  • card_analysis.lua - Card inspection (count_suit, is_flush, has_enhancement)
  • random_utils.lua - Randomization helpers (random_suit, random_rank, random_song)
  • config_builder.lua - Config factory for common joker patterns
  • joker_patterns.lua - Reusable calculate() patterns
  • safety.lua - Defensive programming utilities (safe_access)

Refactored Files

  • Neuratro.lua - Added module loading system
  • content/hooks/hooks.lua - Removed duplicate joker search loops, uses find_jokers
  • content/hooks/nothooks.lua - Fixed global pollution (seaNeuratro.sea)
  • content/objects/blind.lua - Uses utility probability functions
  • content/objects/editions.lua - DRY coin flip logic
  • content/objects/enhancements.lua - Consolidated duplicate loops

Benefits

  • Maintainability: Common logic in one place
  • Readability: Helper functions replace inline complexity
  • Safety: Consistent nil-checking via safe_access
  • Performance: Reduced code duplication (-140 lines net)
  • Testing: Utility modules are independently testable

VX1D added 2 commits March 7, 2026 19:26
Bug fixes:

1. Frog Hat (content/objects/jokers.lua line 358-360):
   - Fixed seal propagation not rendering visually
   - Changed: set_seal(seal) -> set_seal(seal, nil, true)
   - The nil, true params trigger immediate visual update

2. Glorp deck (content/objects/decks.lua lines 77-90):
   - Added Cerber joker integration
   - When Glorp deck creates cards, checks if j_cerber exists
   - If Cerber is present and card is rank 2, applies Negative edition
   - Uses inline check (no dependency on utility modules)

Testing:
- Verify Frog Hat seal propagation shows visually
- Verify 2s from Glorp deck become Negative with Cerber active
@VX1D VX1D force-pushed the refactor/code-quality branch from ac89062 to f7fc1f3 Compare March 7, 2026 19:33
VX1D added 6 commits March 18, 2026 10:58
Add nil-safe context and pool checks across jokers, enhancements, suit, blind, and editions to reduce runtime crashes from missing game state tables. Keep probability and scoring-hand operations bounded and defensive without changing intended gameplay flow.

(cherry picked from commit 69496b56b9881daaa3d1cf4aca3ffb13b8f4770c)
Replace strict assert with soft warning for Lovely patch detection to prevent crash when Lovely isn't properly loaded.

(cherry picked from commit 4b8c04f3add1479a5102963a9ebb7e79fdaacd93)
Add safety guards to:
- hooks.lua: jokers.cards iteration in open_booster
- tags.lua: G.CONTROLLER.locks access in both tag apply functions
- modules/hooks/general.lua: jokers.cards check in draw_card hook

Prevents crashes when game areas are not yet initialized.

(cherry picked from commit 9128a9defb8faa6ce8c49854c539f3c1f3d5defb)
Fix j_vedalsdrink2 description typo (remove extra 'equal' word)

Remove 9 commented-out sendDebugMessage calls from handtype.lua

(cherry picked from commit 176638e0decd79f4744858c64404a9585f0ee89e)
# Conflicts:
#	content/hooks/hooks.lua
#	content/objects/blind.lua
#	content/objects/editions.lua
#	content/objects/enhancements.lua
@VX1D VX1D force-pushed the refactor/code-quality branch 3 times, most recently from f7fc1f3 to b95fc62 Compare March 23, 2026 13:11
@VX1D VX1D force-pushed the refactor/code-quality branch from ff5cb09 to 44a51e2 Compare March 24, 2026 23:01
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.

1 participant