Variants and renderer system#740
Conversation
|
Bringing my suggestions from the developer server, a small simple framework should be implemented as the current implementation is muddled. A Additionally, a component-based system could be introduced to allow easy modification of card elements. Components could be declared using a @component(name: str)
def new_component(self):
passRenders could have the following methods:
Proposed class FullArt(Renderer):
"""
Handles full card art.
"""
def render(self):
self.extend_components() # Adds the components from `Renderer`
self.remove_component("artwork")
self.add_component(name="rarity", order=1)
@component("rarity")
def rarity_text(self):
self.draw.text(
(520, 1670),
str(self.ball_instance.rarity),
font=stats_font,
fill=(255, 255, 255),
stroke_width=1,
stroke_fill=(0, 0, 0, 255),
) |
|
I'm not really a fan of a class-based system, since a) whatever draws the card art really should be stateless (sans caching), and b) classes add a decent bit of overhead. I don't really think that individually-overrideable components are simpler, and adding a whole bunch of decorators and components adds a whole lot of OOP complexity that I really don't think is needed. There'd also be a bunch of maintenance burden involved and mental modeling with trying to keep track with what is overriden and what isn't, so I think it's better just to have each renderer be a function, and if someone wants to duplicate code from the function, they can just duplicate the code, there's not really a need for premature abstraction here. |
Your points are good, but there are a few flaws and misconceptions. I'll also include extra points I didn't state in my previous comment.
Overall, I still believe a class-based approach would fit better, similar to the class-based approach that spawn managers have. |
|
Just to be clear, I'm talking mostly about implementation complexity, not usage complexity. This is not intended to be a perfect DSL on top of python with a full component system, it's intended as a minimal viable system to replace the if soup that BD currently uses for things like frames and whatnot. I don't really see a need to add a vast amount of implementation complexity for what appears to me as extremely small advantage over composing functions. If a third-party-developer wants to implement the kind of thing that you're describing above, it's very possible to do on top of the system in the PR here inside of a package, but I don't think there's much value in putting that kind of system into core BD. I agree that |
656fa1d to
e4a75c8
Compare
e4a75c8 to
eaead1f
Compare
eaead1f to
70bb51f
Compare
Description of the changes
This is a successor to #636 that I think is a better fit for BD. Resolves #275, supersedes #275.
It introduces two ideas:
RendererandVariant.A
Variantis kinda like a special but specific to a given Ball. In it you can specify a differentcollection_cardthan normal for the rendering of a specificBallInstance, and also set a renderer.A renderer is just a function that takes a BallInstance and outputs an image.
image_gen.pygets a dict of renderers, which have string keys mapping to renderers.Renderers can be set in four places: in a
Variant(applies to BallInstance), in aSpecial, in aBall, and the default renderer (in descending order of precedence).For this PR, I've written 3 (also mildly refactored the existing renderer):
default,blackscreen(for testing), andfullart(names are hopefully self-explanatory).Some examples
Here is Chewytapioca's full card art China with the

fullartrendererHere is another China ball again rendering with the default one.

Here is another China ball, with the default renderer, but I poorly drew a birthday hat on it.

All of these examples are BallInstance specific and require no intervention after setting the Variant on the panel.
Extensibility
If a package wants to add a renderer, all it has to do is append to the RENDERERS dict in image_gen.py, and everything should work out.
Were the changes in this PR tested?
Yes, though not for performance (presumably there's some overhead)
There could be some polishing done on the admin panel probably.