KodEngine.engine package

Submodules

KodEngine.engine.ErrorHandler module

class KodEngine.engine.ErrorHandler.ErrorHandler[source]

Bases: object

Centralized error and status message dispatcher for the engine.

The handler can either forward messages directly to an editor console callback or queue them while editor mode is enabled but no callback is attached yet.

COLORS = {'ERROR': (255, 50, 50), 'INFO': (200, 200, 200), 'SUCCESS': (50, 255, 100), 'WARNING': (255, 200, 50)}
classmethod clear_console_callback()[source]

Detach the editor console callback and disable editor mode.

classmethod is_editor_mode() → bool[source]

Return whether the handler is currently buffering editor output.

Returns

bool

True when editor mode is enabled, otherwise False.

classmethod set_console_callback(callback: Callable[[str, str], None])[source]

Register the editor console callback used for log output.

Parameters

callback:

Callable that receives the message type and formatted message. Any messages queued while editor mode was active are flushed to this callback immediately.

classmethod set_editor_mode(enabled: bool = True)[source]

Enable or disable editor mode.

Parameters

enabled:

When True, messages are queued until a console callback is registered. When False, messages are not buffered.

classmethod throw_error(message: str)[source]

Log an error message.

classmethod throw_info(message: str)[source]

Log an informational message.

classmethod throw_success(message: str)[source]

Log a success message.

classmethod throw_warning(message: str)[source]

Log a warning message.

KodEngine.engine.ExportingServer module

class KodEngine.engine.ExportingServer.Exporter(project_dir: str, project_settings: dict[str, Any])[source]

Bases: object

Package a project into a distributable build.

export(*, output_dir: str, output_name: str, platform_name: str, build_mode: str, one_file: bool, include_assets: bool, include_runtime: bool) → bool[source]

Export the project to disk.

Returns

bool

True when the export completes successfully.

export_async(*, output_dir: str, output_name: str, platform_name: str, build_mode: str, one_file: bool, include_assets: bool, include_runtime: bool) → Thread[source]

Run an export in a background thread and return the worker.

KodEngine.engine.Globals module

KodEngine.engine.Kod module

class KodEngine.engine.Kod.App(_configuration: Settings, editor_mode=False)[source]

Bases: object

Main application runner for the engine runtime and editor.

calculate_delta(last_frame_time)[source]

Compute frame delta time from the previous tick timestamp.

distribute_node_buckets()[source]

Split the current scene into rendering, physics, and UI buckets.

Returns

dict[str, list]

Node buckets keyed by rendering, physics, and ui.

find_camera_in_scene(node)[source]

Recursively search a node tree for the active camera.

handle_resize(size, persist_project_resolution=True)[source]

Update the runtime viewport and optionally persist it to settings.

Parameters

size:

New window size.

persist_project_resolution:

When True, store the updated size in project settings.

kill()[source]

Request shutdown of the main application loop.

resolve_camera()[source]

Return the active camera or the fallback camera.

resolve_editor_events(events)[source]

Handle editor-level events and forward them to the current scene.

run()[source]

Run the main application loop until the app is stopped.

set_camera(camera: Camera2D)[source]

Set the active camera used for rendering.

set_scene(scene)[source]

Swap the active scene and run enter/ready hooks as needed.

class KodEngine.engine.Kod.Settings[source]

Bases: object

Default project and editor configuration container.

KodEngine.engine.Nodes module

class KodEngine.engine.Nodes.AnimatedSprite2D[source]

Bases: Sprite2D

Sprite node that advances through a resource-backed animation.

add_animation(animation: SpriteAnimation)[source]

Register an animation resource on the sprite.

property current_animation
editor_update(delta)[source]

Advance the active animation while running in the editor.

property image

Return the current animation frame as a surface.

load_data(data: dict)[source]

Restore animated sprite state from serialized data.

play(name: str)[source]

Activate an animation by name and rewind it.

save_data() → dict[source]

Serialize the sprite and current animation state.

class KodEngine.engine.Nodes.Area2D[source]

Bases: CollisionObject2D

Collision area node that tracks overlapping bodies and areas.

get_overlapping_areas() → list[Area2D][source]

Return areas currently overlapping the area.

get_overlapping_bodies() → list[CollisionObject2D][source]

Return bodies currently overlapping the area.

class KodEngine.engine.Nodes.AudioPlayer[source]

Bases: Node

Node that plays an audio resource through pygame mixer.

property audio
load_data(data: dict)[source]

Restore the audio player state from serialized data.

on_exit()[source]

Stop audio playback before the node leaves the scene tree.

play()[source]

Play the assigned audio resource if one is loaded.

save_data() → dict[source]

Serialize the audio player state.

property volume
class KodEngine.engine.Nodes.Button[source]

Bases: Control

Clickable text button control.

process_ui(viewport_size=None, parent_rect=None, apply_anchor=True)[source]

Size the button from text content and then lay it out.

class KodEngine.engine.Nodes.Camera2D[source]

Bases: Node2D

2D camera node used by the renderer.

class KodEngine.engine.Nodes.CollisionObject2D[source]

Bases: Node2D, ABC

Base node for 2D collision bodies and areas.

class KodEngine.engine.Nodes.CollisionShape2D[source]

Bases: Node2D, ABC

Base node for collision shape components.

class KodEngine.engine.Nodes.ColorRect2D[source]

Bases: Control

Solid-color rectangle control.

class KodEngine.engine.Nodes.Control[source]

Bases: Node

Base UI node with anchoring, layout, and font settings.

class AnchorType(*values)[source]

Bases: Enum

BOTTOM_CENTER = 'BOTTOM_CENTER'
BOTTOM_LEFT = 'BOTTOM_LEFT'
BOTTOM_RIGHT = 'BOTTOM_RIGHT'
CENTER = 'CENTER'
CENTER_LEFT = 'CENTER_LEFT'
CENTER_RIGHT = 'CENTER_RIGHT'
FULL_RECT = 'FULL_RECT'
NONE = 'NONE'
TOP_CENTER = 'TOP_CENTER'
TOP_LEFT = 'TOP_LEFT'
TOP_RIGHT = 'TOP_RIGHT'
DEFAULT_BG_COLOR = (58, 62, 72, 255)
DEFAULT_FONT_COLOR = (245, 245, 245, 255)
DEFAULT_FONT_SIZE = 14
DEFAULT_GAP = 4
DEFAULT_PADDING = (4, 4, 4, 4)
property global_position

Return the control’s global position including anchor offset.

load_data(data: dict)[source]

Restore control-specific state from serialized data.

process_ui(viewport_size=None, parent_rect=None, apply_anchor=True)[source]

Resolve anchors and lay out child controls.

class KodEngine.engine.Nodes.DynamicBody2D[source]

Bases: CollisionObject2D

Physics body that integrates velocity each frame.

class KodEngine.engine.Nodes.HBoxContainer[source]

Bases: Control

Horizontal container that stacks child controls.

process_ui(viewport_size=None, parent_rect=None, apply_anchor=True)[source]

Lay out child controls horizontally.

class KodEngine.engine.Nodes.KinematicBody2D[source]

Bases: CollisionObject2D

Collision body that moves explicitly via script or solver.

move_and_slide()[source]

Apply the stored velocity directly to the global position.

class KodEngine.engine.Nodes.Label[source]

Bases: Control

Text label control.

class TextAlignType(*values)[source]

Bases: Enum

CENTER = 'CENTER'
LEFT = 'LEFT'
RIGHT = 'RIGHT'
load_data(data: dict)[source]

Restore label-specific state from serialized data.

class KodEngine.engine.Nodes.Node[source]

Bases: object

Base node for the engine scene tree.

add_child(_node)[source]

Attach a child node to this node.

change_scene_to(scene_path)[source]

Load a scene and make it the active scene.

Parameters

scene_path:

Path to the scene file.

Returns

bool

True when the scene switch succeeds.

clone()[source]

Create a serialized copy of the node tree.

connect(signal, callback=None, target=None, method=None, oneshot=False, allow_duplicate=False)[source]

Connect a signal to a callback or method.

Parameters

signal:

Signal name to connect.

callback:

Callable or method name to invoke.

target:

Optional explicit target object for method callbacks.

method:

Optional method name override.

oneshot:

When True, remove the connection after the first emit.

allow_duplicate:

When True, permit duplicate connections.

Returns

int | None

Connection id when successful, otherwise None.

disconnect(connection_id: int)[source]

Remove a signal connection by id.

Returns

bool

True when the connection was removed.

disconnect_signal(signal, callback=None, target=None, method=None)[source]

Remove all matching connections for a signal.

Returns

int

Number of removed connections.

editor_update(delta)[source]

Editor-only update hook for subclasses.

emit_signal(signal, *args, **kwargs)[source]

Emit a signal and invoke all matching connections.

Returns

int

Number of callbacks that were successfully called.

get_child(index: int)[source]

Return the child at index or None when out of range.

get_node(_path_to_child: str)[source]

Resolve a descendant by slash-separated path.

get_nodes_by_type(node_type)[source]

Return all direct children that match node_type.

get_signal_connections(signal=None)[source]

Return signal connection metadata.

Parameters

signal:

Optional signal name to filter by.

Returns

list | dict

Connections for one signal or all connections grouped by signal.

instantiate(scene)[source]

Return the root node of a loaded scene.

load_data(data: dict)[source]

Load node state from serialized data.

on_exit()[source]

Propagate exit notifications to child nodes.

preload(scene_path: str)[source]

Load a scene without making it the active scene.

queue_free()[source]

Mark the node for deferred deletion.

quit()[source]

Request application shutdown.

Returns

bool

True when an active app was found and marked for exit.

remove_child(_node)[source]

Detach a child node from this node.

reparent_to(new_parent: Node)[source]

Move the node under a new parent.

runtime_script: object | None
save_data() → dict[source]

Serialize node state into a dictionary.

property script
set_script(module_name: str)[source]

Assign a script resource or script path to the node.

class KodEngine.engine.Nodes.Node2D[source]

Bases: Node

Base node type with 2D transform state.

property global_position
property global_rotation: float
property global_scale
property global_visible: bool
load_data(data: dict)[source]

Load transform state from serialized data.

position: tuple[float, float]
rotation: float
scale: tuple[float, float]
class KodEngine.engine.Nodes.RectangleCollisionShape2D[source]

Bases: CollisionShape2D

Axis-aligned rectangle collision shape node.

class KodEngine.engine.Nodes.Sprite2D[source]

Bases: Node2D

Renderable 2D sprite node.

property image

Return the rendered sprite surface or None.

load_data(data: dict)[source]

Load sprite-specific properties from serialized data.

save_data() → dict[source]

Serialize sprite-specific properties.

property texture
class KodEngine.engine.Nodes.StaticBody2D[source]

Bases: CollisionObject2D

Non-moving collision body.

class KodEngine.engine.Nodes.TextureProgress[source]

Bases: Control

Progress bar control with separate background and fill textures.

property fill_texture

Return the fill texture resource.

load_data(data: dict)[source]

Restore control-specific state from serialized data.

save_data() → dict[source]

Serialize node state into a dictionary.

property under_texture

Return the background texture resource.

class KodEngine.engine.Nodes.TextureRect2D[source]

Bases: Control

UI control that displays a texture resource.

property image

Return the loaded texture surface or None.

load_data(data: dict)[source]

Restore texture rect state from serialized data.

save_data() → dict[source]

Serialize the texture rect state.

property texture
class KodEngine.engine.Nodes.TileMap2D[source]

Bases: Node2D

Node that stores and renders layered tile data.

property bounds

Return the tilemap bounds in tile coordinates.

property chunk_size
ensure_layer(layer: int, fill_value: int = -1)[source]

Ensure a layer grid exists and return it.

get_layer_indices() → list[int][source]

Return the sorted list of layer indices in the tilemap.

get_tile_id(tile_pos: tuple[int, int], layer: int = 0) → int[source]

Return the tile id at a coordinate for the requested layer.

load_data(data: dict)[source]

Restore tilemap state from serialized data.

preprocess_tile_data()[source]

Convert layer grids into chunked tile data for rendering.

save_data() → dict[source]

Serialize the tilemap state.

set_bounds(bounds, preserve: bool = True, fill_value: int = -1)[source]

Resize the tilemap bounds, optionally preserving existing tiles.

set_tile_id(tile_pos: tuple[int, int], tile_id: int, layer: int = 0)[source]

Set a tile id and grow the tilemap bounds when needed.

Returns

bool

Always returns True after the tile is written.

shrink_to_fit(fill_value: int = -1)[source]

Trim tile bounds to the smallest rectangle that contains tiles.

property tile_layers

Return the internal tile layer mapping.

tile_to_world(tile_pos: tuple[int, int]) → tuple[int, int][source]

Convert tile coordinates into world coordinates.

property tileset

Return the active tileset resource.

property world_bounds: tuple[tuple[int, int], tuple[int, int]]

Return world-space bounds for the tilemap.

world_to_tile(world_pos: tuple[int, int]) → tuple[int, int][source]

Convert world coordinates into tile coordinates.

class KodEngine.engine.Nodes.VBoxContainer[source]

Bases: Control

Vertical container that stacks child controls.

process_ui(viewport_size=None, parent_rect=None, apply_anchor=True)[source]

Lay out child controls vertically.

class KodEngine.engine.Nodes.YSort2D[source]

Bases: Node2D

Marker node that causes descendants to render sorted by Y value.

KodEngine.engine.PhysicsServer module

class KodEngine.engine.PhysicsServer.PhysicsSolver2D(configuration)[source]

Bases: object

check_collision_pair(body1, shape1, body2, shape2)[source]

Return whether two rectangle collision shapes overlap.

physics_process(physics_bodies, delta)[source]

Advance physics for a frame using substep resolution.

Parameters

physics_bodies:

Sequence of bodies to simulate.

delta:

Frame delta time in seconds.

resolve_area_overlaps()[source]

Update area overlap caches and emit transition signals.

resolve_physics_step_x(body)[source]

Resolve horizontal movement and collisions for a body.

resolve_physics_step_y(body)[source]

Resolve vertical movement and collisions for a body.

KodEngine.engine.RenderingServer module

class KodEngine.engine.RenderingServer.Renderer2D(_configuration, _pygame, _screen, _debug_renderer=None)[source]

Bases: object

2D renderer responsible for world and UI drawing.

create_node_structure(node, nodes_array=None)[source]

Collect renderable nodes from a subtree into a flat list.

Parameters

node:

Root node to traverse.

nodes_array:

Existing list to append to.

Returns

list

Flat list of renderable nodes.

is_inside_viewport(object, camera, project_settings)[source]

Return whether a sprite-like object intersects the camera frustum.

is_tile_inside_viewport(tile_world_x, tile_world_y, tile_width, tile_height, camera, project_settings)[source]

Return whether a tile rectangle intersects the camera frustum.

render_frame(scene, _camera, renderable_nodes, physics_nodes=None)[source]

Render a world frame, including optional collision debug overlays.

render_node(node)[source]

Render a single world node according to its type.

render_tilemap(node)[source]

Render a tiled world node using cached tile surfaces.

render_ui_frame(ui_nodes, viewport_size=None, target_surface=None, source_size=None)[source]

Render the current frame’s UI nodes onto the target surface.

render_ui_node(node, scale_x, scale_y, surface)[source]

Render a single UI node onto a surface.

KodEngine.engine.ResourceServer module

class KodEngine.engine.ResourceServer.ResourceLoader[source]

Bases: object

Load, resolve, and cache resource files for the engine.

static load(path: str)[source]

Load a resource from disk and cache the loaded instance.

Parameters

path:

Path to the resource file.

Returns

object | None

Loaded resource instance, or None when the file cannot be resolved or decoded.

static resolve_path(path: str)[source]

Resolve a possibly project-relative path to an absolute path.

Parameters

path:

Path to resolve.

Returns

str

Absolute path when the file can be resolved, otherwise the input path unchanged.

static set_project_root(path: str)[source]

Set the root directory used to resolve project-relative paths.

Parameters

path:

Absolute or relative path to the project root.

class KodEngine.engine.ResourceServer.SceneLoader[source]

Bases: object

Serialize and deserialize scene trees to the on-disk JSON format.

RESOURCE_KEY = '__resource__'
static deserialize_node(node_data)[source]

Rebuild a node tree from serialized node data.

static deserialize_scene(scene)[source]

Rebuild a scene object from serialized scene data.

json = <module 'json' from '/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/__init__.py'>
static load(file_path)[source]

Load a scene from a JSON file.

Parameters

file_path:

Scene file to load.

Returns

Scene | Node | None

Loaded scene object, root node, or None on failure.

static save(save_data, file_path)[source]

Serialize a scene object and write it to disk.

Parameters

save_data:

Scene-like object with a root attribute.

file_path:

Output file path.

Returns

bool

True when saving succeeds, otherwise False.

static serialize_node(node)[source]

Convert a node tree into a serializable dictionary.

static serialize_scene(scene)[source]

Convert a scene object into a serializable dictionary.

KodEngine.engine.Resources module

class KodEngine.engine.Resources.AudioStream(name: str = 'Audio', resource_path: str | None = None)[source]

Bases: Resource

Audio resource backed by a pygame mixer sound object.

extensions: tuple[str, ...] = ('.mp3', '.wav', '.ogg')
classmethod from_dict(data: dict)[source]

Deserialize an audio resource from a dictionary payload.

classmethod from_path(path: str)[source]

Load an audio resource from a file path.

get_sound()[source]

Return the loaded pygame.mixer.Sound instance, if available.

load_audio(path: str)[source]

Load audio from the given path into the internal sound cache.

load_data(data: dict)[source]

Restore audio resource state from serialized data.

save_data() → dict[source]

Serialize audio resource state.

type_id = 'AudioStream'
class KodEngine.engine.Resources.CollisionRectangleShape(size: tuple[float, float] = (32, 32), resource_path: str | None = None)[source]

Bases: CollisionShape

Axis-aligned rectangle collision shape resource.

classmethod from_dict(data: dict)[source]

Deserialize a rectangle collision shape from a dictionary.

load_data(data: dict)[source]

Restore the rectangle collision shape from serialized data.

save_data()[source]

Serialize the rectangle collision shape state.

type_id = 'CollisionRectangleShape'
class KodEngine.engine.Resources.CollisionShape(name='CollisionShape', resource_path=None)[source]

Bases: Resource

Base resource for collision shape definitions.

type_id = 'CollisionShape'
class KodEngine.engine.Resources.Font(name='Font', size: int = 14, resource_path: str | None = None)[source]

Bases: Resource

Font resource used by UI rendering.

color: tuple[int, int, int, int]
extensions: tuple[str, ...] = ('.font', '.json')
classmethod from_dict(data: dict)[source]

Deserialize a font resource from a dictionary payload.

classmethod from_path(path: str)[source]

Load a font resource from a file path.

load_data(data: dict)[source]

Restore font state from serialized data.

save_data() → dict[source]

Serialize the font resource state.

size: int
type_id = 'Font'
class KodEngine.engine.Resources.Resource(name: str = 'Resource', resource_path: str | None = None)[source]

Bases: object

Base serializable resource type used by the engine.

classmethod class_for_extension(extension: str)[source]

Look up a registered resource class for a file extension.

classmethod class_for_type(type_name: str)[source]

Look up a registered resource class for a serialized type name.

classmethod decode_value(value)[source]

Decode a previously encoded resource value.

classmethod encode_value(value)[source]

Encode nested resource values for serialization.

extensions: tuple[str, ...] = ()
classmethod from_dict(data: dict)[source]

Deserialize a resource from a dictionary payload.

Parameters

data:

Serialized resource data.

Returns

Resource | None

Deserialized resource instance, or None for invalid input.

classmethod from_path(path: str)[source]

Construct a resource instance from a file path.

load_data(data: dict)[source]

Load resource state from serialized data.

save(path: str | None = None)[source]

Write the resource to disk as JSON.

save_data() → dict[source]

Return the serializable state for the resource.

to_dict() → dict[source]

Serialize the resource into a dictionary payload.

type_id = 'Resource'
class KodEngine.engine.Resources.Script(name='Script', resource_path: str | None = None)[source]

Bases: Resource

Resource describing a Python script attached to a node.

extensions: tuple[str, ...] = ('.py',)
classmethod from_dict(data: dict)[source]

Deserialize a script resource from a dictionary payload.

classmethod from_path(path: str)[source]

Create a script resource from a file path.

load_data(data: dict)[source]

Restore the script resource state from serialized data.

save_data() → dict[source]

Serialize the script resource state.

type_id = 'Script'
class KodEngine.engine.Resources.ScriptProxy(node, script_path: str)[source]

Bases: object

Lightweight wrapper that forwards runtime callbacks into a module.

class KodEngine.engine.Resources.SpriteAnimation(name='Animation', spritesheet=None, frame_size: tuple[int, int] = (0, 0), frames: int = 0, _loop: bool = True, fps: int = 12, resource_path: str | None = None)[source]

Bases: Resource

Animation resource that slices frames from a sprite sheet.

extensions: tuple[str, ...] = ('.anim', '.json')
frame_regions: list[tuple[tuple[int, int], tuple[int, int]]]
classmethod from_dict(data: dict)[source]

Deserialize an animation resource from a dictionary payload.

classmethod from_path(path: str)[source]

Load animation data from a file path.

get_current_frame_rect() → Rect[source]

Return the current frame rectangle on the sprite sheet.

load_data(data: dict)[source]

Restore animation state from serialized data.

reload()[source]

Rebuild cached frame surfaces from the current sprite sheet.

save_data() → dict[source]

Serialize the animation resource state.

type_id = 'SpriteAnimation'
update(delta: float)[source]

Advance the animation timer.

Parameters

delta:

Frame delta time in seconds.

class KodEngine.engine.Resources.Texture2D(name='Texture', resource_path: str | None = None)[source]

Bases: Resource

Image resource that loads textures with alpha support.

extensions: tuple[str, ...] = ('.png', '.jpg', '.jpeg', '.bmp')
classmethod from_dict(data: dict)[source]

Deserialize a texture resource from a dictionary payload.

classmethod from_path(path: str)[source]

Create a texture resource from a file path.

get_height()[source]

Return the texture height in pixels.

get_texture()[source]

Return the loaded pygame.Surface instance, if available.

get_width()[source]

Return the texture width in pixels.

load_data(data: dict)[source]

Restore texture state from serialized data.

load_texture(path: str)[source]

Load texture data from a file path.

save_data() → dict[source]

Serialize the texture resource state.

type_id = 'Texture2D'
class KodEngine.engine.Resources.Tile2D(id: int, name='Tile', resource_path: str | None = None)[source]

Bases: Resource

Individual tile definition stored inside a tileset.

collision_shape: CollisionShape | None
classmethod from_dict(data: dict)[source]

Deserialize a tile definition from a dictionary payload.

load_data(data: dict)[source]

Restore tile data from serialized input.

save_data() → dict[source]

Serialize the tile definition.

texture_region: tuple[tuple[int, int], tuple[int, int]]
type_id = 'Tile'
class KodEngine.engine.Resources.Tileset2D(name='Tileset', resource_path: str | None = None)[source]

Bases: Resource

Tileset resource used by TileMap2D nodes.

add_tile(tile=None)[source]

Add a tile to the tileset and return it.

Parameters

tile:

Optional tile instance to append. When omitted, a default tile is created automatically.

Returns

Tile2D | None

Added tile, or None when the input is invalid.

clear_runtime_cache()[source]

Clear cached tile surfaces built at runtime.

ensure_default_tile()[source]

Ensure the tileset always contains at least one valid tile.

extensions: tuple[str, ...] = ('.tileset', '.json')
classmethod from_dict(data: dict)[source]

Deserialize a tileset resource from a dictionary payload.

classmethod from_path(path: str)[source]

Load a tileset from disk.

get_tile_by_id(tile_id: int)[source]

Return a tile by id or None when it does not exist.

get_tile_surface(tile_id: int)[source]

Return a cached surface for a tile region when available.

load_data(data: dict)[source]

Restore tileset state from serialized data.

next_available_tile_id() → int[source]

Return the next unused tile identifier.

remove_tile(tile_id: int)[source]

Remove a tile by id and keep the default tile fallback in place.

save_data() → dict[source]

Serialize the tileset resource state.

tilesheet: Texture2D | None
type_id = 'Tileset'
KodEngine.engine.Resources.get_script_path(script) → str | None[source]

Return the originating script path for a script instance when known.

KodEngine.engine.Resources.load_script(script_path: str, node)[source]

Load a script module and return a ready-to-use script instance.

KodEngine.engine.Scenes module

class KodEngine.engine.Scenes.Scene(name, root, path=None)[source]

Bases: object

Runtime scene container that owns the root node and frame queues.