world package

Submodules

models.world.world module

class models.world.world.World(world_version, width, height, tile_type, description, map_data, time_of_day, weather_conditions)

Bases: object

The World class combines tile management with world lore.

can_see(from_pos, to_pos, max_range)

Determine if an entity at from_pos can see a tile at to_pos.

Visibility is blocked if: - Manhattan distance > max_range - Any intermediate tile has TileTag.BLOCKS_VISION

Parameters:
  • from_pos (tuple) – (x, y) tuple of the observer’s position.

  • to_pos (tuple) – (x, y) tuple of the target position.

  • max_range (int) – Maximum vision range.

Returns:

True if visible, False otherwise.

Return type:

bool

describe_world()

Get a description of the world.

Returns:

Description string.

Return type:

str

get_adjacent_tiles(x, y)

Get tiles adjacent to the specified coordinates.

Parameters:
  • x (int) – X-coordinate.

  • y (int) – Y-coordinate.

Returns:

List of adjacent tiles.

Return type:

list

get_entities_at(x, y)

Get all entities at the specified coordinates.

Parameters:
  • x (int) – X-coordinate.

  • y (int) – Y-coordinate.

Returns:

List of entities at the given position.

Return type:

list

move_entity(entity, new_x, new_y)

Move an entity to a new position.

Parameters:
  • entity (Any) – The entity to move.

  • new_x (int) – New X-coordinate.

  • new_y (int) – New Y-coordinate.

place_entity(entity, x, y)

Place an entity at the specified coordinates.

Parameters:
  • entity (Any) – The entity to place.

  • x (int) – X-coordinate.

  • y (int) – Y-coordinate.

save_to_db(db_conn)

Save the world’s lore to the database.

Parameters:

db_conn (Any) – Database connection object.

update_time_of_day(new_time)

Update the world’s time of day.

Parameters:

new_time (str) – New time of day.

update_weather(new_weather)

Update the world’s weather conditions.

Parameters:

new_weather (str) – New weather conditions.

models.world.world_lore module

class models.world.world_lore.WorldLore(description, map_data, time_of_day, weather_conditions)

Bases: object

Represents the lore and environmental state of the world, including description, map data, time of day, and weather conditions.

Parameters:
  • description (str) – String description of the world.

  • map_data (dict or bytes) – JSON-serializable or binary data representing the world map.

  • time_of_day (str) – String indicating the time of day (e.g., “morning”, “afternoon”).

  • weather_conditions (str) – String describing the current weather conditions (e.g., “sunny”, “rainy”).

describe_world()

Provide a textual description of the world.

Returns:

A string summarizing the world’s description, time of day, and weather conditions.

Return type:

str

save_to_db(db_conn)

Save the world lore data to a database.

Parameters:

db_conn (sqlite3.Connection) – An open database connection object supporting the SQLite interface.

update_time_of_day(new_time)

Update the time of day (morning, afternoon, evening, etc.).

Parameters:

new_time (str) – The new time of day to set (e.g., “evening”, “night”).

update_weather(new_weather)

Update the weather in the world.

Parameters:

new_weather (str) – The new weather condition to set (e.g., “cloudy”, “stormy”).

models.world.world_tile_manager module

class models.world.world_tile_manager.WorldTileManager(width, height, tile_type)

Bases: object

Manages the tiles and entities in the world grid.

display_world()

Display a simple debug view of the world grid.

generate_tiles()

Generate the tiles for the world grid.

Returns:

Dictionary mapping (x, y) to TileData.

Return type:

dict

get_adjacent_tiles(x, y)

Get adjacent tiles based on the tile_type (“square” or “hex”).

Parameters:
  • x (int) – X-coordinate of the tile.

  • y (int) – Y-coordinate of the tile.

Returns:

List of adjacent tile coordinates.

Return type:

list

get_entities_at(x, y)

Get a list of entities at the specified tile.

Parameters:
  • x (int) – X-coordinate of the tile.

  • y (int) – Y-coordinate of the tile.

Returns:

List of entities at the tile.

Return type:

list

is_valid_tile(x, y)

Check if a tile is within the grid boundaries.

Parameters:
  • x (int) – X-coordinate of the tile.

  • y (int) – Y-coordinate of the tile.

Returns:

True if the tile is valid, False otherwise.

Return type:

bool

move_entity(entity, new_x, new_y)

Move an entity to a new tile if the tile is valid.

Parameters:
  • entity (GameEntity) – The entity to move.

  • new_x (int) – New X-coordinate.

  • new_y (int) – New Y-coordinate.

place_entity(entity, x, y)

Place an entity at the specified tile.

Parameters:
  • entity (GameEntity) – The entity to place.

  • x (int) – X-coordinate of the tile.

  • y (int) – Y-coordinate of the tile.

Raises:

ValueError – If the tile is invalid.