tiles package
Submodules
models.tiles.base_tile_item module
- class models.tiles.base_tile_item.BaseTileItem
Bases:
QGraphicsItem
Base class for tile items in the DnDProject.
- attributes
Dictionary to store custom attributes for the tile item.
- Type:
dict
- event_emitter
External event emitter, to be set externally.
- Type:
object or None
- handle_hover_enter(event)
Handle the hover enter event.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- Raises:
NotImplementedError – If the method is not implemented in a subclass.
- handle_hover_leave(event)
Handle the hover leave event.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- Raises:
NotImplementedError – If the method is not implemented in a subclass.
- handle_right_click(event)
Handle the right click event.
- Parameters:
event (QGraphicsSceneMouseEvent) – The mouse event.
- Raises:
NotImplementedError – If the method is not implemented in a subclass.
models.tiles.hex_tile_item module
- class models.tiles.hex_tile_item.HexTileItem(center, size, tile_data=None, editor_window=None)
Bases:
QGraphicsPolygonItem
,BaseTileItem
A QGraphicsPolygonItem representing a hexagonal tile in the map editor.
This class manages the visual representation and interaction logic for a single hex tile, including painting, sampling presets, and displaying dialogs for editing tile data.
- tile_data
Data associated with the tile, such as position and overlay color.
- Type:
dict
- editor_window
Reference to the editor window, used for accessing paint mode and presets.
- Type:
QWidget or None
- size
The radius of the hexagon.
- Type:
float
- center
The center point of the hexagon.
- Type:
QPointF
- create_hexagon()
Create a QPolygonF representing a regular hexagon centered at self.center.
- Returns:
The polygon representing the hexagon.
- Return type:
QPolygonF
- handle_hover_enter(event)
Custom handler for hover enter event.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- handle_hover_leave(event)
Custom handler for hover leave event.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- handle_right_click(event)
Handle right-click event to open the tile dialog.
- Parameters:
event (QGraphicsSceneMouseEvent) – The mouse event.
- hoverEnterEvent(event)
Handle the hover enter event.
Highlights the tile border if paint mode is active.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- hoverLeaveEvent(event)
Handle the hover leave event.
Resets the tile border and updates overlay color.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- mousePressEvent(event)
Handle mouse press events for painting or sampling presets.
- Parameters:
event (QGraphicsSceneMouseEvent) – The mouse event.
- set_overlay_color(hex_color)
Set the overlay color of the tile.
- Parameters:
hex_color (str) – The hex color string to set as the overlay color.
- update_overlay_color()
Update the brush color of the tile based on the overlay color in tile_data.
models.tiles.tile_preset module
- class models.tiles.tile_preset.TilePreset(terrain=None, tags=None, overlay_color=None, note=None, user_label=None, entities=None, triggers=None)
Bases:
object
Represents a preset configuration for a tile, including terrain, tags, overlay color, notes, user labels, entities, and triggers.
- Variables:
terrain – The terrain type or object associated with the tile.
tags – A list of tags associated with the tile.
overlay_color – The overlay color for the tile.
note – An optional note attached to the tile.
user_label – An optional user-defined label for the tile.
entities – A list of entities present on the tile.
triggers – A list of triggers associated with the tile.
- apply_to(tile_data, logic=True)
Apply the preset’s properties to a TileData object.
- Parameters:
tile_data (TileData) – The TileData object to apply the preset to.
logic (bool, optional) – If True, also applies note, user_label, entities, and triggers (default is True).
models.tiles.square_tile_item module
- class models.tiles.square_tile_item.SquareTileItem(x, y, size, tile_data=None, editor_window=None)
Bases:
QGraphicsRectItem
,BaseTileItem
A QGraphicsRectItem representing a square tile in the editor.
Inherits from QGraphicsRectItem and BaseTileItem, and handles painting, hover, and mouse events for tile editing.
- Parameters:
x (float) – The x-coordinate of the tile.
y (float) – The y-coordinate of the tile.
size (float) – The size (width and height) of the square tile.
tile_data (dict, optional) – The data associated with this tile.
editor_window (QWidget, optional) – Reference to the editor window.
- handle_hover_enter(event)
Custom handler for hover enter, changes brush color.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- handle_hover_leave(event)
Custom handler for hover leave, updates overlay color.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- handle_right_click(event)
Handle right-click event to open the tile dialog.
- Parameters:
event (QGraphicsSceneMouseEvent) – The mouse event.
- hoverEnterEvent(event)
Handle the hover enter event.
Highlights the tile if paint mode is active.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- hoverLeaveEvent(event)
Handle the hover leave event.
Resets the tile’s pen and overlay color.
- Parameters:
event (QGraphicsSceneHoverEvent) – The hover event.
- mousePressEvent(event)
Handle mouse press events for painting or sampling tiles.
- Parameters:
event (QGraphicsSceneMouseEvent) – The mouse event.
- set_overlay_color(hex_color)
Set the overlay color of the tile.
- Parameters:
hex_color (str) – The color in hex format (e.g., ‘#CCCCCC’).
- update_overlay_color()
Update the brush color based on the tile’s overlay color.
models.tiles.tile_data module
- class models.tiles.tile_data.TerrainType(value)
Bases:
Enum
Enum for different types of terrain a tile can have.
- GRASS
Grass terrain.
- Type:
str
- WATER
Water terrain.
- Type:
str
- MOUNTAIN
Mountain terrain.
- Type:
str
- FLOOR
Floor terrain.
- Type:
str
- WALL
Wall terrain.
- Type:
str
- CUSTOM
Custom terrain.
- Type:
str
- CUSTOM = 'custom'
- FLOOR = 'floor'
- GRASS = 'grass'
- MOUNTAIN = 'mountain'
- WALL = 'wall'
- WATER = 'water'
- class models.tiles.tile_data.TileData(tile_id: str = 'new_tile', position: ~typing.Tuple[int, int] = (0, 0), terrain: ~models.tiles.tile_data.TerrainType = TerrainType.FLOOR, entities: ~typing.List[~models.entities.game_entity.GameEntity] = <factory>, note: str | None = None, user_label: str | None = None, overlay_color: str | None = None, tags: ~typing.List[~models.tiles.tile_data.TileTag] = <factory>, last_updated: str | None = None, triggers: ~typing.List[~core.gameCreation.trigger.Trigger] = <factory>)
Bases:
object
Dataclass for representing tile information in the DnDProject.
- tile_id
Unique identifier for the tile.
- Type:
str
- position
The (x, y) coordinates of the tile.
- Type:
Tuple[int, int]
- terrain
The type of terrain for the tile.
- Type:
- entities
List of entities currently on the tile.
- Type:
List[GameEntity]
- note
Optional note attached to the tile.
- Type:
Optional[str]
- user_label
Optional user-defined label for the tile.
- Type:
Optional[str]
- overlay_color
Optional color overlay for the tile.
- Type:
Optional[str]
- last_updated
Timestamp of the last update to the tile.
- Type:
Optional[str]
- add_entity(entity: GameEntity)
Add an entity to the tile.
- Parameters:
entity (GameEntity) – The entity to add.
- entities: List[GameEntity]
- classmethod from_dict(data)
Create a TileData instance from a dictionary, subscribing triggers to the EventBus.
- Parameters:
data (dict) – Dictionary containing tile data.
- Returns:
The created TileData instance.
- Return type:
- has_entity_type(type_name: str) bool
Check if the tile contains an entity of the specified type.
- Parameters:
type_name (str) – The type name to check for.
- Returns:
True if an entity of the specified type is present, False otherwise.
- Return type:
bool
- is_occupied() bool
Check if the tile is occupied by a player, NPC, or enemy entity.
- Returns:
True if the tile is occupied, False otherwise.
- Return type:
bool
- last_updated: str | None = None
- note: str | None = None
- overlay_color: str | None = None
- position: Tuple[int, int] = (0, 0)
- register_trigger(trigger)
Register a trigger to the tile and subscribe it to the EventBus.
- Parameters:
trigger (Trigger) – The trigger to register.
- remove_entity(entity: GameEntity)
Remove an entity from the tile if present.
- Parameters:
entity (GameEntity) – The entity to remove.
- terrain: TerrainType = 'floor'
- tile_id: str = 'new_tile'
- to_dict() dict
Serialize the TileData instance to a dictionary.
- Returns:
Dictionary representation of the TileData instance.
- Return type:
dict
- user_label: str | None = None
- class models.tiles.tile_data.TileTag(value)
Bases:
Enum
Enum for different tags that can be associated with a tile.
- BLOCKS_MOVEMENT
Tile blocks movement.
- Type:
str
- BLOCKS_VISION
Tile blocks vision.
- Type:
str
- START_ZONE
Tile is a start zone.
- Type:
str
- TRAP_ZONE
Tile is a trap zone.
- Type:
str
- BLOCKS_MOVEMENT = 'blocks_movement'
- BLOCKS_VISION = 'blocks_vision'
- START_ZONE = 'start_zone'
- TRAP_ZONE = 'trap_zone'