[#12808] Add ContentStatsEvent for injecting custom content stats
自动翻译暂时不可用
本帖暂时展示 GitHub 原始内容。
What this does Adds a new ContentStatsEvent that fires at the end of UnlockableContent.computeStats(), right after setStats() and before the result is used by the UI. The event carries the content instance and its freshly built Stats object.
That's fine for vanilla content since every setStats() override re-adds its own entries, but mods that want to attach stats to content they don't own (vanilla units, other mods' blocks, etc.) have no place to do it. Anything added to content.stats during mod initialization is thrown away the moment the panel is opened, because that Stats instance is replaced.
The only workaround right now is subclassing or mixins, neither of which is practical for content owned by another mod.
<img width="314" height="101" alt="74d124ea-bb5b-440a-a1bb-5b20f9e5efb0" src="https://github.com/user-attachments/assets/b2dd3e8e-bcf5-4c17-8ddb-92c3e2b3803e" />
<img width="587" height="218" alt="image" src="https://github.com/user-attachments/assets/ef24f5c5-2ce3-4e1d-a271-9abca2372cfc" />
Purely additive: the event has no listeners by default and changes nothing for existing content.
Fired once per computeStats() call, which only happens when the info dialog is opened, so there's no per-frame cost.
I put it in computeStats() rather than in ContentInfoDialog so that any other consumer of the stats (present or future) gets the same hook.
I have read the contribution guidelines.
I have ensured that any new features or fixes in this PR function correctly in-game, if applicable.
I affirm that this code follows Mindustry's AI policy.
由 MDT GitHub 同步机器人自动同步。