Integrate with the mods actually installed beside us
New integrations.lua, loaded pcall-wrapped at the end of main.lua; every integration gates on its target's global so a missing mod is silence. Both targets load before us by priority. JokerDisplay: each known joker's display definition gains a live '(2 combos)' counter in JD's own parenthetical reminder style -- the same partner count the hover tooltip names -- by appending a dynamic element to reminder_text (created when absent) and wrapping calc_function to fill card.joker_display_values. The wrapper pcalls the original calc and blanks the text when the new jd_combos config toggle is off, so it flips mid-run in both directions. Too Many Jokers: registers the SEARCH_FIELD_FUNCS hook its api.md documents, indexing every joker under its tag labels on both sides, so the collection search finds jokers by 'money', 'Hearts', 'held-card retriggers'. Unknown centers stay nil. The smoke scenario now asserts the JokerDisplay patch against the real mod: 13/13 in-game. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
--- Integrations with other installed mods, applied at the end of main.lua.
|
||||
--- Every integration gates on its target mod's global, so a missing mod is
|
||||
--- silence rather than an error, and each touches only jokers this database
|
||||
--- knows. Both targets load before this mod does (JokerDisplay at priority
|
||||
--- -1e9, Too Many Jokers at -1000, this mod at 0), so their tables exist by
|
||||
--- the time these run. Each returns how much it patched, surfaced in
|
||||
--- JCA.integrations for the tests and the debug log.
|
||||
|
||||
local M = {}
|
||||
|
||||
--- JokerDisplay: a live combo counter under every joker it displays.
|
||||
--- Its model: JokerDisplay.Definitions[key] holds per-joker display specs;
|
||||
--- dynamic text reads card.joker_display_values, which the definition's
|
||||
--- calc_function fills on every display update. We append a counter element
|
||||
--- in JokerDisplay's own parenthetical reminder style -- '(2 combos)', the
|
||||
--- same partner count the hover tooltip names -- and wrap calc_function to
|
||||
--- keep the value fresh. Definitions without a reminder_text row gain one.
|
||||
--- The wrapper blanks the text when config.jd_combos is off, so the toggle
|
||||
--- works mid-run in both directions; the count call is pcall-wrapped like
|
||||
--- every other advisor path that runs inside the game's draw loop.
|
||||
function M.jokerdisplay()
|
||||
if not (JokerDisplay and JokerDisplay.Definitions) then return 0 end
|
||||
local patched = 0
|
||||
for key in pairs(JCA.db) do
|
||||
local def = JokerDisplay.Definitions[key]
|
||||
if def and not def.jca_combo_counter then
|
||||
def.jca_combo_counter = true
|
||||
local node = { ref_table = 'card.joker_display_values',
|
||||
ref_value = 'jca_combos', colour = G.C.GREEN }
|
||||
if def.reminder_text then
|
||||
def.reminder_text[#def.reminder_text + 1] = { text = ' ' }
|
||||
def.reminder_text[#def.reminder_text + 1] = node
|
||||
else
|
||||
def.reminder_text = { node }
|
||||
end
|
||||
local orig = def.calc_function
|
||||
def.calc_function = function(card)
|
||||
-- pcall like every advisor path in the draw loop: if the
|
||||
-- original calc fails, the counter must still not crash.
|
||||
if orig then pcall(orig, card) end
|
||||
local text = ''
|
||||
if JCA.config.jd_combos ~= false then
|
||||
local ok, partners = pcall(JCA.partners_for, card)
|
||||
local n = ok and #partners or 0
|
||||
if n > 0 then
|
||||
text = ('(%d combo%s)'):format(n, n == 1 and '' or 's')
|
||||
end
|
||||
end
|
||||
card.joker_display_values = card.joker_display_values or {}
|
||||
card.joker_display_values.jca_combos = text
|
||||
end
|
||||
patched = patched + 1
|
||||
end
|
||||
end
|
||||
return patched
|
||||
end
|
||||
|
||||
--- Too Many Jokers: its api.md asks for a TMJ.SEARCH_FIELD_FUNCS entry
|
||||
--- mapping a center to searchable strings. We hand it every tag label on
|
||||
--- both sides of a joker, so the collection search finds jokers by what
|
||||
--- they give and want: 'money', 'held-card retriggers', 'Hearts'...
|
||||
--- Unknown centers (other mods' jokers) return nil, the same "score 0"
|
||||
--- silence the engine promises everywhere else.
|
||||
function M.toomanyjokers()
|
||||
if not (TMJ and TMJ.SEARCH_FIELD_FUNCS) then return 0 end
|
||||
TMJ.SEARCH_FIELD_FUNCS[#TMJ.SEARCH_FIELD_FUNCS + 1] = function(center)
|
||||
local entry = center and center.key and JCA.db[center.key]
|
||||
if not entry then return nil end
|
||||
local fields = {}
|
||||
for t in pairs(entry.gives) do
|
||||
if JCA.tag_label[t] then fields[#fields + 1] = JCA.tag_label[t] end
|
||||
end
|
||||
for t in pairs(entry.wants) do
|
||||
if JCA.tag_label[t] then fields[#fields + 1] = JCA.tag_label[t] end
|
||||
end
|
||||
return fields
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user