Vhati wrote:I'm playing around with a store to get the hang of themes, and designing classes in the style of DiEvAl's ship demo. Not sure yet if I'll end up commiting or discarding it as an exercise...
Stores can sell several different things.
Crew, Augments, (Sub)systems, Weapons, and Drones
There are separate blueprint classes with various attributes. That's a given.
I made StoreShelfItemInfo with standard attributes (icon, description, price). Then subclasses constructed using instances of each blueprint to set those values (StoreShelfCrewInfo sets a "Bob" as its description, etc).
TWL widget+theme pairs render store shelves of each type: Augment renderer for 3 bars, Weapon renderer for squares.
The problem then is how to associate blueprints, store info subclasses, and GUI widgets together.
How flexible should this be?- Hardcoded if/else blocks are straightforward but rigid.
- A centralized class lookup table would allow code to register new mappings or clobber existing ones (e.g., to change GUI widgets). StoreShelfItemInfo subclasses would each have a buy(gameState) method to manipulate the ship (spawning a crewmember, etc).
TWL can be coaxed into adding new subthemes (use ref="*" within the store window's theme, and include toplevel files for each shelf-type made findable with allowWildcard="true") but only with unique names, no replacement. A widget determines layout, so it's pretty much tied to a specific theme. So to mod appearance beyond simple image swapping would mean changing both the theme name and Widget class used. I don't know how that could be done without a registry.
Abstracting blueprints and looking em up doesn't seem so bad, but handling mystery classes in general might get hairy: {spawned thing} occupying a room square checks if {other thing} nearby implements the FriendOrFoe interface, then calls isHostile(), then checks for Damagable interface, then calls addDamage(amt, type, srcObj), etc. We could restrict spawnables to specific classes (and their subclasses) to mitigate that however.