vesper-arch / Slay-the-Spire-in-Python

A text based version of Slay the Spire coded in python. Credit to slaythetext for some really early systems I used.
https://docs.google.com/document/d/1j7c3oHXeQjjF6yyuY0tOMaZeMlAHPokfzw99Azpe6fk/edit?usp=sharing
2 stars 4 forks source link

Initializations on import #77

Open miketwo opened 2 months ago

miketwo commented 2 months ago

https://github.com/vesper-arch/Slay-the-Spire-in-Python/blob/2bc20e2c2dda262da5efeca9c85257df769a7912/items.py#L1301-L1335

It would be better to have all cards, relics, and potions behind functions like:

This is because these initializatons currently happen at import and are global, which makes it harder for testing. (If one test is upgrading cards, then another test might be using the same upgraded cards.) When they're behind functions, each time it's used, you get a fresh copy of the cards. It also removes the need for all the DeepCopy stuff.

vesper-arch commented 2 months ago

How would these be used? Does it happen inside the Game class or somewhere else?

miketwo commented 2 months ago

I think it'd be used wherever items.(cards|relics|potions) is currently used, yeah? Are those things ever meant to be changed? It doesn't seem so. They seem to be used like an infinite catalogue. Like "I want to transform my Curse card into another one -- show me every possible Curse card, whether it's in my deck or not."

In general, you don't want to instantiate a class until you're ready to use it.

vesper-arch commented 2 months ago

Yeah those are meant to be a catalogue of sorts. But I'm still not sure exactly where they should be initialized in the game flow.