Basically want to resize the BasicPiece according to HexGrid size. How do I get the current instance of the HexGrid from Board? How to get instance of Board? Some basic debugging lead me to OpCache. How do I get an instance of that?
Thinking to put an checkbox option in preferences “Fit game piece to grid”.
What’s the reason for not sizing the piece images correctly? That would let you avoid all of this.
You can get a MapGrid from Board.getGrid(). There’s no guarantee that the MapGrid you get is a HexGrid. It could also be a RegionGrid, SquareGrid, or ZonedGrid. How you get a Board depends on where you’re doing it from. You should never get an instance of OpCache. If you need to scale an ImageOp, you do that via Op.scale().
Oh thought i’d kick it off from an boolean in Preferences, the preferences class doesn’t seem to map to File → Preferences - Post Module and extensions loaded, lets say. After the map is chosen and board is drawn.
Oh, never mind. I always forget that the *Preferences classes under VASASL.preferences aren’t for this—they’re for adding global options in the editor.
What you want is BooleanConfigurer. Look in the code for one of the places that’s used.
Nonetheless, I suggest resizing the images instead.
If you want to resize all pieces uniformly, you could possibly do that by subclassing Map and overriding drawPieces(); that’s going to be inflexible and extremely fiddly to get right. Alternatively, you’d need to have a piece trait specifically for resizing a piece, and you’d have to ensure that is the outermost trait on every piece you want to resize this way. That’s going to be a lot of work and also affect how you construct your pieces.
Thanks, I tried changing the scale in a redraw in Map, which worked, However I have to only redraw this specific scale for specific maps, (small pieces for the large map, and regular piece images for the other maps) so hardcoding the map names seems like a hack, but easiest temporary solution. Also, there are two “pieces” that seems to be drawn the piece after placement, and the “piece” that can be selected. After successful redraw with a different scale, the final result was great on the board, however, the box to select the piece for movement and right clicking was still the large original size.
If you’re subclassing Map, it shouldn’t be necessary to hardcode any map names. What you should be doing instead is using your subclass only for the maps which require it, and using Map for the ones which don’t. (That is, in the Editor, add the maps needing the subclass using that subclass. Don’t select the normal Map for those.)
If you’re drawing the pieces at a different scale, you also need to adjust the size of the selection outline. The selection outline is unlikely to be the only other thing which depends on pieces being drawn at the same scale as the map. You’re likely to find several more such problems.
If you’re subclassing Map , it shouldn’t be necessary to hardcode any map names. What you should be doing instead is using your subclass only for the maps which require it, and using Map for the ones which don’t. (This is, in the Editor, add the maps needing the subclass using that subclass . Don’t select the normal Map for those.)
Wow alright, the power of subclass. I will go about subclassing. Will give it a shot, thank you!
You need to copy the class file(s) into the module first, so that the Editor can find them. That’s a thing you have to do manually, using something that can read and write ZIP archives.
You should not put custom classes in our namespace. That causes problems which are difficult to troubleshoot. (Consider what would happen to your module if we later introduced a class called VASSAL.build.module.MapResizePiece.) Put your subclass outside of VASSAL.*, in a namespace you define.