factoriax.playground.editor.canvas#
The camera and the tile drawing of the editor canvas.
The canvas draws the part of the map that the camera shows, and no more.
The blocks and the machines come from the sprite atlas that the JAX renderer
reads. The canvas is therefore the same image as the play view, down to new
art in factoriax/assets/atlas.png. block_textures_rgba and
machine_icon_rgba in factoriax.engine.renderer give the RGBA arrays
at the tile size that the camera holds.
- class factoriax.playground.editor.canvas.Viewport(camera_x: float = 0.0, camera_y: float = 0.0, tile_size: int = 32, canvas_w: int = 400, canvas_h: int = 400)#
Position and zoom of the editor camera.
- camera_x, camera_y
Tile at the top left corner of the canvas. The value is a float, so the camera can stop between two tiles.
- canvas_w, canvas_h
Width and height of the canvas in pixels.
- factoriax.playground.editor.canvas.clamp_camera(vp: Viewport, map_w: int, map_h: int) None#
Move the camera back until it shows the map only.
If the map is smaller than the canvas, the camera stops at the top left corner of the map.
- Parameters:
vp – Camera. The function writes to it.
map_w – Map width in tiles.
map_h – Map height in tiles.
- factoriax.playground.editor.canvas.pan(vp: Viewport, dx: float, dy: float, map_w: int, map_h: int) None#
Move the camera across the map.
The function then calls
clamp_camera(), so the camera shows the map only.- Parameters:
vp – Camera. The function writes to it.
dx – Distance to move in tiles. A positive value moves right.
dy – Distance to move in tiles. A positive value moves down.
map_w – Map width in tiles.
map_h – Map height in tiles.
- factoriax.playground.editor.canvas.render_canvas(state: object, vp: Viewport, cursor_tile: tuple[int, int] | None, selection_rect: tuple[int, int, int, int] | None = None, show_resources: bool = False) ndarray#
Draw the part of the map that the camera shows.
The function draws the blocks first, and then the machines, the grid lines, the players, and the highlights. A tile with contents in its machine gets a dot at the top right corner.
- Parameters:
state –
EditorStateto read.vp – Camera to read.
cursor_tile – Column and row of the tile under the mouse, or
Nonewhen the mouse is off the canvas.selection_rect – Corners of the fill rectangle, as
(x0, y0, x1, y1)in tiles. It isNonewhen the user selects no rectangle.show_resources –
Truedraws the ore amount on each tile that holds ore.
- Returns:
RGBA image of shape
(canvas_h, canvas_w, 4), uint8.- Return type:
- factoriax.playground.editor.canvas.screen_to_tile(vp: Viewport, sx: int, sy: int) tuple[int, int]#
Return the tile at one pixel of the canvas.
- factoriax.playground.editor.canvas.tile_to_screen(vp: Viewport, tx: int, ty: int) tuple[int, int]#
Return the pixel at the top left corner of one tile.
- factoriax.playground.editor.canvas.zoom(vp: Viewport, direction: int, mouse_sx: int, mouse_sy: int, map_w: int, map_h: int) None#
Change the tile size, and hold the tile under the mouse in place.
The function moves one step along
TILE_SIZES. At the first or the last size, a step past the end has no effect.- Parameters:
vp – Camera. The function writes to it.
direction –
+1makes the tiles larger.-1makes them smaller.mouse_sx – Mouse offset from the left edge of the canvas.
mouse_sy – Mouse offset from the top edge of the canvas.
map_w – Map width in tiles.
map_h – Map height in tiles.