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

Global drawing (callback after drawing) #81

Closed
edemaine opened this issue Aug 1, 2022 · 4 comments
Closed

Global drawing (callback after drawing) #81

edemaine opened this issue Aug 1, 2022 · 4 comments

Comments

@edemaine
Copy link
Owner

edemaine commented Aug 1, 2022

The idea is to provide a callback that gets called after the tiling/drawing job is complete, so that additional "global" layers can be drawn below/above the "main" drawing. Possible interface:

export globalDrawing = (drawing) -> ...

Example use cases:

  • Want to draw a big background rectangle behind everything. (generalization of Background #57)

    export globalDrawing = (drawing) ->
      <rect z-index="-10" x={drawing.minX} y={drawing.minY}
       width={drawing.width} height={drawing.height} fill="purple"/>
  • Draw a graph overlay over chess pieces.

    export globalDrawing = (drawing) ->
      <g z-index="100">{
        for piece in drawing.tiles when isPiece piece.key
          for attackable in ...
            <line x1={piece.centerX} y1={piece.centerY}
                  x2={attackable.centerX} y2={attackable.centerY}/>
      }</g>

The drawing and the symbols have already been laid out so have min/max/center coordinates defined.

We can use top-level z-index to specify how the global drawing relates to other symbols (overlay/underlay), though there isn't a wrapping <symbol> in this case.

For symmetry with #79, could maybe be called afterDrawing.

@diomidov
Copy link

diomidov commented Aug 23, 2022

Another way to implement this would be to call the mapping with fake symbols ::before and ::after before and after each drawing. ::before could also be used for sideeffectful initialization.

@edemaine
Copy link
Owner Author

Funny, I misinterpreted this as an approach to #33 (multiple layers in a symbol), by rendering an x::before, then x, then x::after when we see tile x.

I'm not sure it makes sense to implement a global symbols ::before/::after, because global drawing feels fundamentally different from a regular symbol. Presumably you want to interact with the whole grid, not just a particular context object. And you'd need to use code to look at the width and height of the drawing at least (for all the applications I can think of, even just adding a <rect> in the background). So it doesn't really make sense to have these global drawings in e.g. .txt mapping file; you really need to use JS/CS code for them to make sense. (Unless I'm missing a use-case?)

@diomidov
Copy link

For #33 I would prefer not to limit it to just 3 layers.

Yes, this would only be useful for script mappings.

After thinking about it some more, I agree that separate exports are better.

@edemaine
Copy link
Owner Author

I ended up implementing this as an API call svgtiler.afterRender, so you can add multiple over/underlays if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants