Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: script functions for generating and manipulating card images #34

Merged
merged 4 commits into from
Aug 15, 2022

Conversation

haganbmj
Copy link
Owner

@haganbmj haganbmj commented Jul 28, 2022

The ultimate goal here is both #32 and #33.

  • Add to_card_image(input, zoom, angle) as a script function to allow for variable access to resolved card images.
  • Add card_region as a stylesheet property to define slice regions for a card.

Example of card_region

# within a `style`
card width: 400
card height: 600
card dpi: 150
card region:
	name: front
	x: 0
	y: 0
	width: 200
	height: 600
card region:
	name: back
	x: 200
	y: 0
	width: 200
	height: 600
  • Add width_of(input) and height_of(input) script functions for accessing image width/height.

Ideally I would want width/height to be properties, but the nature of images in MSE is that they don't have these values until drawn so this internally is having to draw the images. There's probably a better way around that by drawing intermediate layers and storing the values for property access, but haven't really sorted that out - nor did I find a good way to reflect the return value of a function as a property. Images right now don't have reflected properties at all.


I think next steps from here would be...

  • Overload some image generation methods to permit being region aware and return a map of images keyed by their name. A complication there is going to be when/how to apply the slices while factoring in scale. The actual draw function can build subregions before apply the scale - but once you have the output it's a bit late. So that means digging all the way down into the draw functions again.
  • write_image_file() could add a param then to be region aware and return a map of images.
  • to_card_image() could do the same, rather then leaving it for the script writer to try and slice their own cards which would require math to adjust for scale factor.
  • Enhance the Export behavior to have some kind of pattern for doing regions. This gets potentially tricky with single card exports where the use can specify the file name as it likely means either suffixing the file name provided (and thereby guessing at any kind of overwrite behavior) or generating multiple dialogs. Multi-Export would probably be easier to update.

@haganbmj
Copy link
Owner Author

haganbmj commented Jul 30, 2022

So reading around the way that style works for determining the positioning of fields on the card is that it re-evaluates when the context changes and stores the width/height/top/bottom/etc to avoid having to redraw on every access. That works pretty well, but it seems to be fairly attached to a card as a concept.

Need to look at if there's some way to do a similar pattern with Images. Could probably calculate as part of the constructor of a GeneratedImage, but that relies on the assumption that underlyling layers don't change - or have some way to alert when they do. Most of MSE seems to assume non reassignment, so maybe that's possible for the time being.

Just messing around in the console it looks like you can't modify something by changing its earlier layers by doing something like this -

# Assign a value to img.
img := built_in_image("bool_yes")

# Transform the image by referencing img.
rotated := rotate(img, angle: 90)

# Reassign the value to the underlying object.
img := built_in_image("bool_no")

# modified image still shows the "yes" icon
rotated

@haganbmj haganbmj marked this pull request as ready for review August 14, 2022 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant