Add in-game level editor with auto-discovered tile/entity palettes

Implements a full level editor that runs inside the game engine as an
alternative mode, accessible via --edit flag or E key during gameplay.
The editor auto-discovers available tiles from the tileset texture and
entities from a new central registry, so adding new game content
automatically appears in the editor without any editor-specific changes.

Editor features: tile painting (pencil/eraser/flood fill) across 3
layers, entity placement with drag-to-move, player spawn point tool,
camera pan/zoom, grid overlay, .lvl save/load, map resize, and test
play (P to play, ESC to return to editor).

Supporting changes:
- Entity registry centralizes spawn functions (replaces strcmp chain)
- Mouse input + raw keyboard access added to input system
- Camera zoom support for editor overview
- Zoom-aware rendering in tilemap, renderer, and sprite systems
- Powerup and drone sprites/animations wired up (were defined but unused)
- Bitmap font renderer for editor UI (4x6 pixel glyphs, no dependencies)
This commit is contained in:
Thomas
2026-02-28 20:24:43 +00:00
parent c66c12ae68
commit ea6e16358f
30 changed files with 4959 additions and 51 deletions

View File

@@ -0,0 +1,52 @@
#ifndef JNR_ENTITY_REGISTRY_H
#define JNR_ENTITY_REGISTRY_H
#include "engine/entity.h"
#include <SDL2/SDL.h>
/* ═══════════════════════════════════════════════════
* Entity Registry
*
* Central table that maps entity type name strings
* to their spawn functions and metadata. Used by:
* - Level loader (to spawn entities from .lvl files)
* - Level editor (to discover available entity types)
*
* When adding a new entity type to the game, add one
* entry here and it will appear in the editor palette
* automatically.
* ═══════════════════════════════════════════════════ */
#define MAX_REGISTRY_ENTRIES 32
/* Spawn function: creates an entity at position, returns it */
typedef Entity *(*EntitySpawnFn)(EntityManager *em, Vec2 pos);
typedef struct EntityRegEntry {
const char *name; /* .lvl file name, e.g. "grunt" */
const char *display; /* human-readable, e.g. "Grunt" */
EntitySpawnFn spawn_fn; /* function that creates the entity */
SDL_Color color; /* editor palette color for preview */
int width; /* hitbox width (for editor preview) */
int height; /* hitbox height (for editor preview) */
} EntityRegEntry;
typedef struct EntityRegistry {
EntityRegEntry entries[MAX_REGISTRY_ENTRIES];
int count;
} EntityRegistry;
/* Global registry instance */
extern EntityRegistry g_entity_registry;
/* Call once at startup to populate the registry.
* Also registers entity behaviors with the given EntityManager. */
void entity_registry_init(EntityManager *em);
/* Look up a registry entry by name (returns NULL if not found) */
const EntityRegEntry *entity_registry_find(const char *name);
/* Spawn an entity by registry name. Returns NULL if name unknown. */
Entity *entity_registry_spawn(EntityManager *em, const char *name, Vec2 pos);
#endif /* JNR_ENTITY_REGISTRY_H */